[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <14ef34c2-2fa6-f58c-6d63-e924d07e613f@digitalocean.com>
Date: Mon, 9 Mar 2020 21:06:31 -0600
From: David Ahern <dahern@...italocean.com>
To: Jesper Dangaard Brouer <brouer@...hat.com>,
David Ahern <dsahern@...nel.org>
Cc: netdev@...r.kernel.org, davem@...emloft.net, kuba@...nel.org,
prashantbhole.linux@...il.com, jasowang@...hat.com,
toke@...hat.com, mst@...hat.com, toshiaki.makita1@...il.com,
daniel@...earbox.net, john.fastabend@...il.com, ast@...nel.org,
kafai@...com, songliubraving@...com, yhs@...com, andriin@...com,
dsahern@...il.com
Subject: Re: [PATCH RFC v4 bpf-next 09/11] tun: Support xdp in the Tx path for
xdp_frames
On 3/3/20 3:40 AM, Jesper Dangaard Brouer wrote:
>> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
>> index dcae6521a39d..d3fc7e921c85 100644
>> --- a/drivers/net/tun.c
>> +++ b/drivers/net/tun.c
>> @@ -1359,10 +1359,50 @@ static void __tun_xdp_flush_tfile(struct tun_file *tfile)
>> tfile->socket.sk->sk_data_ready(tfile->socket.sk);
>> }
>>
>> +static u32 tun_do_xdp_tx(struct tun_struct *tun, struct tun_file *tfile,
>> + struct xdp_frame *frame, struct xdp_txq_info *txq)
>> +{
>> + struct bpf_prog *xdp_prog;
>> + u32 act = XDP_PASS;
>> +
>> + xdp_prog = rcu_dereference(tun->xdp_egress_prog);
>> + if (xdp_prog) {
>> + struct xdp_buff xdp;
>> +
>> + xdp.data_hard_start = frame->data - frame->headroom;
>
> This is correct, only because frame->headroom have been reduced with
> sizeof(*xdp_frame), as we want to avoid that the BPF-prog have access
> to xdp_frame memory. Remember that memory storing xdp_frame in located
> in the top of the payload/page.
>
>
>> + xdp.data = frame->data;
>> + xdp.data_end = xdp.data + frame->len;
>> + xdp_set_data_meta_invalid(&xdp);
>> + xdp.txq = txq;
>> +
>> + act = bpf_prog_run_xdp(xdp_prog, &xdp);
>
> The BPF-prog can change/adjust headroom and tailroom (tail only shrink,
> but I'm working on extending this). Thus, you need to adjust the
> xdp_frame accordingly afterwards.
Why do I need to make any adjustments beyond what is done by
bpf_xdp_adjust_head and bpf_xdp_adjust_tail?
The frame is on its way out, so the stack will not see the frame after
any head or tail changes. (REDIRECT is not supported, only PASS or DROP)
Powered by blists - more mailing lists