From: David Ahern <dsahern@gmail.com>
To: "Toke Høiland-Jørgensen" <toke@redhat.com>,
"David Ahern" <dsahern@kernel.org>,
netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org,
prashantbhole.linux@gmail.com, jasowang@redhat.com,
brouer@redhat.com, toshiaki.makita1@gmail.com,
daniel@iogearbox.net, john.fastabend@gmail.com, ast@kernel.org,
kafai@fb.com, songliubraving@fb.com, yhs@fb.com, andriin@fb.com,
David Ahern <dahern@digitalocean.com>
Subject: Re: [PATCH RFC-v5 bpf-next 09/12] dev: Support xdp in the Tx path for xdp_frames
Date: Thu, 16 Apr 2020 17:50:58 -0600 [thread overview]
Message-ID: <1a15e955-7018-cb86-e090-e2024f3e0dc9@gmail.com> (raw)
In-Reply-To: <87imhzlea3.fsf@toke.dk>
On 4/16/20 8:02 AM, Toke Høiland-Jørgensen wrote:
>> diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
>> index 58bdca5d978a..bedecd07d898 100644
>> --- a/kernel/bpf/devmap.c
>> +++ b/kernel/bpf/devmap.c
>> @@ -322,24 +322,33 @@ static int bq_xmit_all(struct xdp_dev_bulk_queue *bq, u32 flags)
>> {
>> struct net_device *dev = bq->dev;
>> int sent = 0, drops = 0, err = 0;
>> + unsigned int count = bq->count;
>> int i;
>>
>> - if (unlikely(!bq->count))
>> + if (unlikely(!count))
>> return 0;
>>
>> - for (i = 0; i < bq->count; i++) {
>> + for (i = 0; i < count; i++) {
>> struct xdp_frame *xdpf = bq->q[i];
>>
>> prefetch(xdpf);
>> }
>>
>> - sent = dev->netdev_ops->ndo_xdp_xmit(dev, bq->count, bq->q, flags);
>> + if (static_branch_unlikely(&xdp_egress_needed_key)) {
>> + count = do_xdp_egress_frame(dev, bq->q, &count);
>
> nit: seems a bit odd to pass the point to count, then reassign it with
> the return value?
thanks for noticing that. leftover from the evolution of this. changed to
count = do_xdp_egress_frame(dev, bq->q, count);
>> diff --git a/net/core/dev.c b/net/core/dev.c
>> index 1bbaeb8842ed..f23dc6043329 100644
>> --- a/net/core/dev.c
>> +++ b/net/core/dev.c
>> @@ -4720,6 +4720,76 @@ u32 do_xdp_egress_skb(struct net_device *dev, struct sk_buff *skb)
>> }
>> EXPORT_SYMBOL_GPL(do_xdp_egress_skb);
>>
>> +static u32 __xdp_egress_frame(struct net_device *dev,
>> + struct bpf_prog *xdp_prog,
>> + struct xdp_frame *xdp_frame,
>> + struct xdp_txq_info *txq)
>> +{
>> + struct xdp_buff xdp;
>> + u32 act;
>> +
>> + xdp.data_hard_start = xdp_frame->data - xdp_frame->headroom;
>> + xdp.data = xdp_frame->data;
>> + xdp.data_end = xdp.data + xdp_frame->len;
>> + xdp_set_data_meta_invalid(&xdp);
>
> Why invalidate the metadata? On the contrary we'd want metadata from the
> RX side to survive, wouldn't we?
right, replaced with:
xdp.data_meta = xdp.data - metasize;
>
>> + xdp.txq = txq;
>> +
>> + act = bpf_prog_run_xdp(xdp_prog, &xdp);
>> + act = handle_xdp_egress_act(act, dev, xdp_prog);
>> +
>> + /* if not dropping frame, readjust pointers in case
>> + * program made changes to the buffer
>> + */
>> + if (act != XDP_DROP) {
>> + int headroom = xdp.data - xdp.data_hard_start;
>> + int metasize = xdp.data - xdp.data_meta;
>> +
>> + metasize = metasize > 0 ? metasize : 0;
>> + if (unlikely((headroom - metasize) < sizeof(*xdp_frame)))
>> + return XDP_DROP;
>> +
>> + xdp_frame = xdp.data_hard_start;
>> + xdp_frame->data = xdp.data;
>> + xdp_frame->len = xdp.data_end - xdp.data;
>> + xdp_frame->headroom = headroom - sizeof(*xdp_frame);
>> + xdp_frame->metasize = metasize;
>> + /* xdp_frame->mem is unchanged */
>> + }
>> +
>> + return act;
>> +}
>> +
>> +unsigned int do_xdp_egress_frame(struct net_device *dev,
>> + struct xdp_frame **frames,
>> + unsigned int *pcount)
>> +{
>> + struct bpf_prog *xdp_prog;
>> + unsigned int count = *pcount;
>> +
>> + xdp_prog = rcu_dereference(dev->xdp_egress_prog);
>> + if (xdp_prog) {
>> + struct xdp_txq_info txq = { .dev = dev };
>
> Do you have any thoughts on how to populate this for the redirect case?
not sure I understand. This is the redirect case. ie.., On rx a program
is run, XDP_REDIRECT is returned and the packet is queued. Once the
queue fills or flush is done, bq_xmit_all is called to send the frames.
> I guess using Magnus' HWQ abstraction when that lands? Or did you have
> something different in mind?
>
next prev parent reply other threads:[~2020-04-16 23:51 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-13 17:17 [PATCH RFC-v5 bpf-next 00/12] Add support for XDP in egress path David Ahern
2020-04-13 17:17 ` [PATCH RFC-v5 bpf-next 01/12] net: Add XDP setup and query commands for Tx programs David Ahern
2020-04-13 17:17 ` [PATCH RFC-v5 bpf-next 02/12] net: Add BPF_XDP_EGRESS as a bpf_attach_type David Ahern
2020-04-16 14:01 ` Toke Høiland-Jørgensen
2020-04-16 16:35 ` David Ahern
2020-04-17 9:23 ` Toke Høiland-Jørgensen
2020-04-13 17:17 ` [PATCH RFC-v5 bpf-next 03/12] xdp: Add xdp_txq_info to xdp_buff David Ahern
2020-04-13 17:17 ` [PATCH RFC-v5 bpf-next 04/12] net: Add IFLA_XDP_EGRESS for XDP programs in the egress path David Ahern
2020-04-13 17:17 ` [PATCH RFC-v5 bpf-next 05/12] net: core: rename netif_receive_generic_xdp to do_generic_xdp_core David Ahern
2020-04-16 14:00 ` Toke Høiland-Jørgensen
2020-04-13 17:17 ` [PATCH RFC-v5 bpf-next 06/12] net: core: Rename do_xdp_generic to do_xdp_generic_rx David Ahern
2020-04-13 17:17 ` [PATCH RFC-v5 bpf-next 07/12] dev: set egress XDP program David Ahern
2020-04-13 17:17 ` [PATCH RFC-v5 bpf-next 08/12] dev: Support xdp in the Tx path for packets as an skb David Ahern
2020-04-13 17:17 ` [PATCH RFC-v5 bpf-next 09/12] dev: Support xdp in the Tx path for xdp_frames David Ahern
2020-04-16 14:02 ` Toke Høiland-Jørgensen
2020-04-16 23:50 ` David Ahern [this message]
2020-04-17 9:25 ` Toke Høiland-Jørgensen
2020-04-17 20:06 ` David Ahern
2020-04-17 8:30 ` Jesper Dangaard Brouer
2020-04-17 21:29 ` David Ahern
2020-04-13 17:17 ` [PATCH RFC-v5 bpf-next 10/12] libbpf: Add egress XDP support David Ahern
2020-04-13 17:18 ` [PATCH RFC-v5 bpf-next 11/12] bpftool: Add support for XDP egress David Ahern
2020-04-13 17:18 ` [PATCH RFC-v5 bpf-next 12/12] samples/bpf: add XDP egress support to xdp1 David Ahern
2020-04-15 15:01 ` Alexei Starovoitov
2020-04-16 13:59 ` [PATCH RFC-v5 bpf-next 00/12] Add support for XDP in egress path Toke Høiland-Jørgensen
2020-04-16 23:55 ` David Ahern
2020-04-17 9:28 ` Toke Høiland-Jørgensen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1a15e955-7018-cb86-e090-e2024f3e0dc9@gmail.com \
--to=dsahern@gmail.com \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=brouer@redhat.com \
--cc=dahern@digitalocean.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=jasowang@redhat.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=prashantbhole.linux@gmail.com \
--cc=songliubraving@fb.com \
--cc=toke@redhat.com \
--cc=toshiaki.makita1@gmail.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.