[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d34c7552-70b4-72f5-98d2-78db7b5fea41@gmail.com>
Date: Thu, 19 Dec 2019 10:47:13 +0900
From: Prashant Bhole <prashantbhole.linux@...il.com>
To: Jesper Dangaard Brouer <jbrouer@...hat.com>
Cc: "David S . Miller" <davem@...emloft.net>,
"Michael S . Tsirkin" <mst@...hat.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Jesper Dangaard Brouer <hawk@...nel.org>,
Jason Wang <jasowang@...hat.com>,
David Ahern <dsahern@...il.com>,
Jakub Kicinski <jakub.kicinski@...ronome.com>,
John Fastabend <john.fastabend@...il.com>,
Toshiaki Makita <toshiaki.makita1@...il.com>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
Andrii Nakryiko <andriin@...com>, netdev@...r.kernel.org,
Ilias Apalodimas <ilias.apalodimas@...aro.org>
Subject: Re: [RFC net-next 11/14] tun: run XDP program in tx path
On 12/18/19 7:07 PM, Jesper Dangaard Brouer wrote:
> On Wed, 18 Dec 2019 17:10:47 +0900
> Prashant Bhole <prashantbhole.linux@...il.com> wrote:
>
>> +static u32 tun_do_xdp_tx(struct tun_struct *tun, struct tun_file *tfile,
>> + struct xdp_frame *frame)
>> +{
>> + struct bpf_prog *xdp_prog;
>> + struct tun_page tpage;
>> + struct xdp_buff xdp;
>> + u32 act = XDP_PASS;
>> + int flush = 0;
>> +
>> + xdp_prog = rcu_dereference(tun->xdp_tx_prog);
>> + if (xdp_prog) {
>> + xdp.data_hard_start = frame->data - frame->headroom;
>> + xdp.data = frame->data;
>> + xdp.data_end = xdp.data + frame->len;
>> + xdp.data_meta = xdp.data - frame->metasize;
>
> You have not configured xdp.rxq, thus a BPF-prog accessing this will crash.
>
> For an XDP TX hook, I want us to provide/give BPF-prog access to some
> more information about e.g. the current tx-queue length, or TC-q number.
>
> Question to Daniel or Alexei, can we do this and still keep BPF_PROG_TYPE_XDP?
> Or is it better to introduce a new BPF prog type (enum bpf_prog_type)
> for XDP TX-hook ?
>
> To Prashant, look at net/core/filter.c in xdp_convert_ctx_access() on
> how the BPF instruction rewrites are done, when accessing xdp_rxq_info.
Got it. I will take care of it next time.
>
>
>> + act = bpf_prog_run_xdp(xdp_prog, &xdp);
>> + switch (act) {
>> + case XDP_PASS:
>> + break;
>> + case XDP_TX:
>> + /* fall through */
>> + case XDP_REDIRECT:
>> + /* fall through */
>> + default:
>> + bpf_warn_invalid_xdp_action(act);
>> + /* fall through */
>> + case XDP_ABORTED:
>> + trace_xdp_exception(tun->dev, xdp_prog, act);
>> + /* fall through */
>> + case XDP_DROP:
>> + xdp_return_frame_rx_napi(frame);
>
> I'm not sure that it is safe to use "napi" variant here, as you have to
> be under same RX-NAPI processing loop for this to be safe.
>
> Notice the "rx" part of the name "xdp_return_frame_rx_napi".
You are right, I will fix it next time.
Thanks!
>
>
>> + break;
>> + }
>> + }
>> +
>> + return act;
>> +}
>
>
Powered by blists - more mailing lists