All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] net: xdp: introduce XDP_PACKET_HEADROOM_MIN for veth and generic-xdp
@ 2022-03-18 19:19 Lorenzo Bianconi
  2022-03-18 19:33 ` Jakub Kicinski
  0 siblings, 1 reply; 6+ messages in thread
From: Lorenzo Bianconi @ 2022-03-18 19:19 UTC (permalink / raw)
  To: bpf, netdev
  Cc: davem, kuba, ast, daniel, brouer, pabeni, toke, lorenzo.bianconi,
	andrii, nbd

Reduce mandatory xdp headroom for generic-xdp and veth driver to 192B
(instead of 256B) in order to reduce unnecessary skb re-allocations in
both veth and generic-xdp code.
This patch has been tested running the xdp_redirect_map sample in
skb-mode on a ixgbe NIC and redirecting received traffic on a veth pair
where a simple XDP_DROP program is used to discard received packets:

  bpf-next master:
  ----------------
  xdp_redirect (ixgbe): ~ 1.38Mpps
  xdp_drop (veth):      ~ 1.38Mpps

  bpf-next master + reduced xdp headroom:
  ---------------------------------------
  xdp_redirect (ixgbe): ~ 2.82Mpps
  xdp_drop (veth):      ~ 2.82Mpps

  bpf-next master:
  ----------------
  5.16%  ksoftirqd/1   [kernel.vmlinux]   [k] page_frag_free
  4.42%  ksoftirqd/1   [kernel.vmlinux]   [k] ixgbe_poll
  4.19%  ksoftirqd/1   [kernel.vmlinux]   [k] check_preemption_disabled
  3.74%  ksoftirqd/1   [kernel.vmlinux]   [k] kmem_cache_free
  3.69%  ksoftirqd/1   [kernel.vmlinux]   [k] get_page_from_freelist
  3.36%  ksoftirqd/1   [kernel.vmlinux]   [k] veth_xdp_rcv_skb
  3.06%  ksoftirqd/1   [kernel.vmlinux]   [k] memcpy_erms
  3.01%  ksoftirqd/1   [kernel.vmlinux]   [k] pskb_expand_head
  2.80%  ksoftirqd/1   [kernel.vmlinux]   [k] __copy_skb_header
  2.50%  ksoftirqd/1   [kernel.vmlinux]   [k] bpf_prog_run_generic_xdp
  2.15%  ksoftirqd/1   [kernel.vmlinux]   [k] memcg_slab_free_hook
  2.03%  ksoftirqd/1   [kernel.vmlinux]   [k] __slab_free
  2.01%  ksoftirqd/1   [kernel.vmlinux]   [k] xdp_do_generic_redirect

  bpf-next master + reduced xdp headroom:
  ---------------------------------------
  8.24%  ksoftirqd/5   [ixgbe]            [k] ixgbe_poll
  5.65%  ksoftirqd/5   [kernel.vmlinux]   [k] check_preemption_disabled
  4.93%  ksoftirqd/5   [kernel.vmlinux]   [k] napi_build_skb
  4.16%  ksoftirqd/5   [kernel.vmlinux]   [k] xdp_do_generic_redirect
  3.69%  ksoftirqd/5   [veth]             [k] veth_xdp_rcv_skb
  3.48%  ksoftirqd/5   [veth]             [k] veth_xmit
  3.15%  ksoftirqd/5   [kernel.vmlinux]   [k] kmem_cache_free
  3.05%  ksoftirqd/5   [kernel.vmlinux]   [k] __dev_forward_skb2
  3.01%  ksoftirqd/5   [kernel.vmlinux]   [k] eth_type_trans
  2.96%  ksoftirqd/5   [kernel.vmlinux]   [k] bpf_prog_run_generic_xdp
  2.65%  ksoftirqd/5   [kernel.vmlinux]   [k] __netif_receive_skb_core
  2.32%  ksoftirqd/5   [veth]             [k] veth_xdp_rcv
  1.94%  ksoftirqd/5   [kernel.vmlinux]   [k] napi_gro_receive

Co-developed-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/veth.c             | 2 +-
 include/uapi/linux/bpf.h       | 3 ++-
 net/core/dev.c                 | 2 +-
 tools/include/uapi/linux/bpf.h | 3 ++-
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 1b5714926d81..c6ec57891708 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -766,7 +766,7 @@ static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq,
 
 		consume_skb(skb);
 		skb = nskb;
-	} else if (skb_headroom(skb) < XDP_PACKET_HEADROOM &&
+	} else if (skb_headroom(skb) < XDP_PACKET_HEADROOM_MIN &&
 		   pskb_expand_head(skb, VETH_XDP_HEADROOM, 0, GFP_ATOMIC)) {
 		goto drop;
 	}
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 7604e7d5438f..29fd4991cbcb 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -5717,7 +5717,8 @@ struct bpf_xdp_sock {
 	__u32 queue_id;
 };
 
-#define XDP_PACKET_HEADROOM 256
+#define XDP_PACKET_HEADROOM	256
+#define XDP_PACKET_HEADROOM_MIN	192
 
 /* User return codes for XDP prog type.
  * A valid XDP program must return one of these defined values. All other
diff --git a/net/core/dev.c b/net/core/dev.c
index ba69ddf85af6..92d560e648ab 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4737,7 +4737,7 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,
 	 * native XDP provides, thus we need to do it here as well.
 	 */
 	if (skb_cloned(skb) || skb_is_nonlinear(skb) ||
-	    skb_headroom(skb) < XDP_PACKET_HEADROOM) {
+	    skb_headroom(skb) < XDP_PACKET_HEADROOM_MIN) {
 		int hroom = XDP_PACKET_HEADROOM - skb_headroom(skb);
 		int troom = skb->tail + skb->data_len - skb->end;
 
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 7604e7d5438f..29fd4991cbcb 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -5717,7 +5717,8 @@ struct bpf_xdp_sock {
 	__u32 queue_id;
 };
 
-#define XDP_PACKET_HEADROOM 256
+#define XDP_PACKET_HEADROOM	256
+#define XDP_PACKET_HEADROOM_MIN	192
 
 /* User return codes for XDP prog type.
  * A valid XDP program must return one of these defined values. All other
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf-next] net: xdp: introduce XDP_PACKET_HEADROOM_MIN for veth and generic-xdp
  2022-03-18 19:19 [PATCH bpf-next] net: xdp: introduce XDP_PACKET_HEADROOM_MIN for veth and generic-xdp Lorenzo Bianconi
@ 2022-03-18 19:33 ` Jakub Kicinski
  2022-03-18 19:54   ` Lorenzo Bianconi
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2022-03-18 19:33 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: bpf, netdev, davem, ast, daniel, brouer, pabeni, toke,
	lorenzo.bianconi, andrii, nbd

On Fri, 18 Mar 2022 20:19:29 +0100 Lorenzo Bianconi wrote:
> diff --git a/net/core/dev.c b/net/core/dev.c
> index ba69ddf85af6..92d560e648ab 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -4737,7 +4737,7 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,
>  	 * native XDP provides, thus we need to do it here as well.
>  	 */
>  	if (skb_cloned(skb) || skb_is_nonlinear(skb) ||
> -	    skb_headroom(skb) < XDP_PACKET_HEADROOM) {
> +	    skb_headroom(skb) < XDP_PACKET_HEADROOM_MIN) {
>  		int hroom = XDP_PACKET_HEADROOM - skb_headroom(skb);
>  		int troom = skb->tail + skb->data_len - skb->end;
>  

IIUC the initial purpose of SKB mode was to be able to test or
experiment with XDP "until drivers add support". If that's still
the case the semantics of XDP SKB should be as close to ideal
XDP implementation as possible.

We had a knob for specifying needed headroom, is that thing not 
working / not a potentially cleaner direction?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf-next] net: xdp: introduce XDP_PACKET_HEADROOM_MIN for veth and generic-xdp
  2022-03-18 19:33 ` Jakub Kicinski
@ 2022-03-18 19:54   ` Lorenzo Bianconi
  2022-03-18 21:01     ` Jakub Kicinski
  0 siblings, 1 reply; 6+ messages in thread
From: Lorenzo Bianconi @ 2022-03-18 19:54 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Lorenzo Bianconi, bpf, netdev, davem, ast, daniel, brouer,
	pabeni, toke, andrii, nbd

[-- Attachment #1: Type: text/plain, Size: 1283 bytes --]

On Mar 18, Jakub Kicinski wrote:
> On Fri, 18 Mar 2022 20:19:29 +0100 Lorenzo Bianconi wrote:
> > diff --git a/net/core/dev.c b/net/core/dev.c
> > index ba69ddf85af6..92d560e648ab 100644
> > --- a/net/core/dev.c
> > +++ b/net/core/dev.c
> > @@ -4737,7 +4737,7 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,
> >  	 * native XDP provides, thus we need to do it here as well.
> >  	 */
> >  	if (skb_cloned(skb) || skb_is_nonlinear(skb) ||
> > -	    skb_headroom(skb) < XDP_PACKET_HEADROOM) {
> > +	    skb_headroom(skb) < XDP_PACKET_HEADROOM_MIN) {
> >  		int hroom = XDP_PACKET_HEADROOM - skb_headroom(skb);
> >  		int troom = skb->tail + skb->data_len - skb->end;
> >  
> 
> IIUC the initial purpose of SKB mode was to be able to test or
> experiment with XDP "until drivers add support". If that's still
> the case the semantics of XDP SKB should be as close to ideal
> XDP implementation as possible.

XDP in skb-mode is useful if we want to perform a XDP_REDIRECT from
an ethernet driver into a wlan device since mac80211 requires a skb.

> 
> We had a knob for specifying needed headroom, is that thing not 
> working / not a potentially cleaner direction?
> 

which one do you mean? I guess it would be useful :)

Regards,
Lorenzo

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf-next] net: xdp: introduce XDP_PACKET_HEADROOM_MIN for veth and generic-xdp
  2022-03-18 19:54   ` Lorenzo Bianconi
@ 2022-03-18 21:01     ` Jakub Kicinski
  2022-03-21 12:17       ` Lorenzo Bianconi
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2022-03-18 21:01 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: Lorenzo Bianconi, bpf, netdev, davem, ast, daniel, brouer,
	pabeni, toke, andrii, nbd

On Fri, 18 Mar 2022 20:54:51 +0100 Lorenzo Bianconi wrote:
> > IIUC the initial purpose of SKB mode was to be able to test or
> > experiment with XDP "until drivers add support". If that's still
> > the case the semantics of XDP SKB should be as close to ideal
> > XDP implementation as possible.
> 
> XDP in skb-mode is useful if we want to perform a XDP_REDIRECT from
> an ethernet driver into a wlan device since mac80211 requires a skb.

Ack, I understand the use case is real, but given that the TC
alternative exists we can apply more scrutiny to the trade offs.
IMO production use of XDP skb mode would be a mistake, the thing 
is a layering violation by nature. Our time is better spent making
TC / XDP code portability effortless.

> > We had a knob for specifying needed headroom, is that thing not
> > working / not a potentially cleaner direction?
> >
>
> which one do you mean? I guess it would be useful :)

We have ndo_set_rx_headroom and dev->needed_headroom.
Sorry for brevity, I'm on the move today, referring to things 
from memory :)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf-next] net: xdp: introduce XDP_PACKET_HEADROOM_MIN for veth and generic-xdp
  2022-03-18 21:01     ` Jakub Kicinski
@ 2022-03-21 12:17       ` Lorenzo Bianconi
  2022-03-21 18:39         ` Jakub Kicinski
  0 siblings, 1 reply; 6+ messages in thread
From: Lorenzo Bianconi @ 2022-03-21 12:17 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Lorenzo Bianconi, bpf, netdev, davem, ast, daniel, brouer,
	pabeni, toke, andrii, nbd

[-- Attachment #1: Type: text/plain, Size: 1568 bytes --]

> On Fri, 18 Mar 2022 20:54:51 +0100 Lorenzo Bianconi wrote:
> > > IIUC the initial purpose of SKB mode was to be able to test or
> > > experiment with XDP "until drivers add support". If that's still
> > > the case the semantics of XDP SKB should be as close to ideal
> > > XDP implementation as possible.
> > 
> > XDP in skb-mode is useful if we want to perform a XDP_REDIRECT from
> > an ethernet driver into a wlan device since mac80211 requires a skb.
> 
> Ack, I understand the use case is real, but given that the TC
> alternative exists we can apply more scrutiny to the trade offs.
> IMO production use of XDP skb mode would be a mistake, the thing 
> is a layering violation by nature. Our time is better spent making
> TC / XDP code portability effortless.

ack, got your point, but I guess there is still a value running the same xdp
program instead of switching to a tc one if the driver does not support
native xdp. Anyway I am fine dropping this patch.

> 
> > > We had a knob for specifying needed headroom, is that thing not
> > > working / not a potentially cleaner direction?
> > >
> >
> > which one do you mean? I guess it would be useful :)
> 
> We have ndo_set_rx_headroom and dev->needed_headroom.
> Sorry for brevity, I'm on the move today, referring to things 
> from memory :)
:)

Do you mean set dev->needed_headroom based on XDP_HEADROOM if the device is
running in xdp mode, right? I guess this is doable for veth, but what is
the right value for generic-xdp? Am I missing something?

Regards,
Lorenzo

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf-next] net: xdp: introduce XDP_PACKET_HEADROOM_MIN for veth and generic-xdp
  2022-03-21 12:17       ` Lorenzo Bianconi
@ 2022-03-21 18:39         ` Jakub Kicinski
  0 siblings, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2022-03-21 18:39 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: Lorenzo Bianconi, bpf, netdev, davem, ast, daniel, brouer,
	pabeni, toke, andrii, nbd

On Mon, 21 Mar 2022 13:17:51 +0100 Lorenzo Bianconi wrote:
> Do you mean set dev->needed_headroom based on XDP_HEADROOM if the device is
> running in xdp mode, right? I guess this is doable for veth, but what is
> the right value for generic-xdp?

#define XDP_PACKET_HEADROOM	256

What am I missing? :)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-03-21 18:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-18 19:19 [PATCH bpf-next] net: xdp: introduce XDP_PACKET_HEADROOM_MIN for veth and generic-xdp Lorenzo Bianconi
2022-03-18 19:33 ` Jakub Kicinski
2022-03-18 19:54   ` Lorenzo Bianconi
2022-03-18 21:01     ` Jakub Kicinski
2022-03-21 12:17       ` Lorenzo Bianconi
2022-03-21 18:39         ` Jakub Kicinski

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.