diff mbox series

[RFC,net-next,2/9] xdp: add XDP_FLAGS_GRO_DISABLED flag

Message ID 39f5cbdfaa67e3319bce64ee8e4e5585b9e0c11e.1718919473.git.yan@cloudflare.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series xdp: allow disable GRO per packet by XDP | expand

Checks

Context Check Description
netdev/series_format warning Series does not have a cover letter
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 846 this patch: 846
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 855 this patch: 855
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1155 this patch: 1155
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 61 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Yan Zhai June 20, 2024, 10:19 p.m. UTC
Allow XDP program to set XDP_FLAGS_GRO_DISABLED flag in xdp_buff and
xdp_frame, and disable GRO when building an sk_buff if this flag is set.

Signed-off-by: Yan Zhai <yan@cloudflare.com>
---
 include/net/xdp.h | 38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

Comments

Alexander Lobakin June 21, 2024, 9:15 a.m. UTC | #1
From: Yan Zhai <yan@cloudflare.com>
Date: Thu, 20 Jun 2024 15:19:13 -0700

> Allow XDP program to set XDP_FLAGS_GRO_DISABLED flag in xdp_buff and
> xdp_frame, and disable GRO when building an sk_buff if this flag is set.
> 
> Signed-off-by: Yan Zhai <yan@cloudflare.com>
> ---
>  include/net/xdp.h | 38 +++++++++++++++++++++++++++++++++++++-
>  1 file changed, 37 insertions(+), 1 deletion(-)
> 
> diff --git a/include/net/xdp.h b/include/net/xdp.h
> index e6770dd40c91..cc3bce8817b0 100644
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h
> @@ -75,6 +75,7 @@ enum xdp_buff_flags {
>  	XDP_FLAGS_FRAGS_PF_MEMALLOC	= BIT(1), /* xdp paged memory is under
>  						   * pressure
>  						   */
> +	XDP_FLAGS_GRO_DISABLED          = BIT(2), /* GRO disabled */

There should be tabs, not spaces.

>  };
>  
>  struct xdp_buff {
> @@ -113,12 +114,35 @@ static __always_inline void xdp_buff_set_frag_pfmemalloc(struct xdp_buff *xdp)
>  	xdp->flags |= XDP_FLAGS_FRAGS_PF_MEMALLOC;
>  }
>  
> +static __always_inline void xdp_buff_disable_gro(struct xdp_buff *xdp)
> +{
> +	xdp->flags |= XDP_FLAGS_GRO_DISABLED;
> +}
> +
> +static __always_inline bool xdp_buff_gro_disabled(struct xdp_buff *xdp)
> +{
> +	return !!(xdp->flags & XDP_FLAGS_GRO_DISABLED);
> +}
> +
> +static __always_inline void
> +xdp_buff_fixup_skb_offloading(struct xdp_buff *xdp, struct sk_buff *skb)
> +{
> +	if (xdp_buff_gro_disabled(xdp))
> +		skb_disable_gro(skb);
> +}

I don't think this should be named "fixup". "propagate", "update",
"promote", ...?

Maybe `if` is not needed here?

	skb->gro_disabled = xdp_buff_gro_disabled(xdp)

?

> +
> +static __always_inline void
> +xdp_init_buff_minimal(struct xdp_buff *xdp)
> +{
> +	xdp->flags = 0;
> +}

"xdp_buff_clear_flags"?

> +
>  static __always_inline void
>  xdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq)
>  {
>  	xdp->frame_sz = frame_sz;
>  	xdp->rxq = rxq;
> -	xdp->flags = 0;
> +	xdp_init_buff_minimal(xdp);
>  }
>  
>  static __always_inline void
> @@ -187,6 +211,18 @@ static __always_inline bool xdp_frame_is_frag_pfmemalloc(struct xdp_frame *frame
>  	return !!(frame->flags & XDP_FLAGS_FRAGS_PF_MEMALLOC);
>  }
>  
> +static __always_inline bool xdp_frame_gro_disabled(struct xdp_frame *frame)
> +{
> +	return !!(frame->flags & XDP_FLAGS_GRO_DISABLED);
> +}
> +
> +static __always_inline void
> +xdp_frame_fixup_skb_offloading(struct xdp_frame *frame, struct sk_buff *skb)
> +{
> +	if (xdp_frame_gro_disabled(frame))
> +		skb_disable_gro(skb);
> +}

(same)

> +
>  #define XDP_BULK_QUEUE_SIZE	16
>  struct xdp_frame_bulk {
>  	int count;

Thanks,
Olek
Yan Zhai June 21, 2024, 4:12 p.m. UTC | #2
On Fri, Jun 21, 2024 at 4:17 AM Alexander Lobakin
<aleksander.lobakin@intel.com> wrote:
>
> From: Yan Zhai <yan@cloudflare.com>
> Date: Thu, 20 Jun 2024 15:19:13 -0700
>
> > Allow XDP program to set XDP_FLAGS_GRO_DISABLED flag in xdp_buff and
> > xdp_frame, and disable GRO when building an sk_buff if this flag is set.
> >
> > Signed-off-by: Yan Zhai <yan@cloudflare.com>
> > ---
> >  include/net/xdp.h | 38 +++++++++++++++++++++++++++++++++++++-
> >  1 file changed, 37 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/net/xdp.h b/include/net/xdp.h
> > index e6770dd40c91..cc3bce8817b0 100644
> > --- a/include/net/xdp.h
> > +++ b/include/net/xdp.h
> > @@ -75,6 +75,7 @@ enum xdp_buff_flags {
> >       XDP_FLAGS_FRAGS_PF_MEMALLOC     = BIT(1), /* xdp paged memory is under
> >                                                  * pressure
> >                                                  */
> > +     XDP_FLAGS_GRO_DISABLED          = BIT(2), /* GRO disabled */
>
> There should be tabs, not spaces.
>
> >  };
> >
> >  struct xdp_buff {
> > @@ -113,12 +114,35 @@ static __always_inline void xdp_buff_set_frag_pfmemalloc(struct xdp_buff *xdp)
> >       xdp->flags |= XDP_FLAGS_FRAGS_PF_MEMALLOC;
> >  }
> >
> > +static __always_inline void xdp_buff_disable_gro(struct xdp_buff *xdp)
> > +{
> > +     xdp->flags |= XDP_FLAGS_GRO_DISABLED;
> > +}
> > +
> > +static __always_inline bool xdp_buff_gro_disabled(struct xdp_buff *xdp)
> > +{
> > +     return !!(xdp->flags & XDP_FLAGS_GRO_DISABLED);
> > +}
> > +
> > +static __always_inline void
> > +xdp_buff_fixup_skb_offloading(struct xdp_buff *xdp, struct sk_buff *skb)
> > +{
> > +     if (xdp_buff_gro_disabled(xdp))
> > +             skb_disable_gro(skb);
> > +}
>
> I don't think this should be named "fixup". "propagate", "update",
> "promote", ...?
>
> Maybe `if` is not needed here?
>
>         skb->gro_disabled = xdp_buff_gro_disabled(xdp)
>
> ?
>
I called it fixup mainly considering current skb fields could be set
incorrectly (or maybe not?) For example when XDP load balances
traffic, it could encap and send from server A to server B, but that
means HW on B may have no good way to calculate the actual flow
hash/csum. The original values could be read from A and sent within
the encapsulation header, so that B can use this value to "fixup" the
things.

But tbh, I am never good at naming, it's too hard for a non-native
speaker sometimes... So I am very open on what to use if majority of
the participants like it :D

The if is still needed since I added a control config to wrap that bit.

best
Yan

> > +
> > +static __always_inline void
> > +xdp_init_buff_minimal(struct xdp_buff *xdp)
> > +{
> > +     xdp->flags = 0;
> > +}
>
> "xdp_buff_clear_flags"?
>
> > +
> >  static __always_inline void
> >  xdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq)
> >  {
> >       xdp->frame_sz = frame_sz;
> >       xdp->rxq = rxq;
> > -     xdp->flags = 0;
> > +     xdp_init_buff_minimal(xdp);
> >  }
> >
> >  static __always_inline void
> > @@ -187,6 +211,18 @@ static __always_inline bool xdp_frame_is_frag_pfmemalloc(struct xdp_frame *frame
> >       return !!(frame->flags & XDP_FLAGS_FRAGS_PF_MEMALLOC);
> >  }
> >
> > +static __always_inline bool xdp_frame_gro_disabled(struct xdp_frame *frame)
> > +{
> > +     return !!(frame->flags & XDP_FLAGS_GRO_DISABLED);
> > +}
> > +
> > +static __always_inline void
> > +xdp_frame_fixup_skb_offloading(struct xdp_frame *frame, struct sk_buff *skb)
> > +{
> > +     if (xdp_frame_gro_disabled(frame))
> > +             skb_disable_gro(skb);
> > +}
>
> (same)
>
> > +
> >  #define XDP_BULK_QUEUE_SIZE  16
> >  struct xdp_frame_bulk {
> >       int count;
>
> Thanks,
> Olek
diff mbox series

Patch

diff --git a/include/net/xdp.h b/include/net/xdp.h
index e6770dd40c91..cc3bce8817b0 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -75,6 +75,7 @@  enum xdp_buff_flags {
 	XDP_FLAGS_FRAGS_PF_MEMALLOC	= BIT(1), /* xdp paged memory is under
 						   * pressure
 						   */
+	XDP_FLAGS_GRO_DISABLED          = BIT(2), /* GRO disabled */
 };
 
 struct xdp_buff {
@@ -113,12 +114,35 @@  static __always_inline void xdp_buff_set_frag_pfmemalloc(struct xdp_buff *xdp)
 	xdp->flags |= XDP_FLAGS_FRAGS_PF_MEMALLOC;
 }
 
+static __always_inline void xdp_buff_disable_gro(struct xdp_buff *xdp)
+{
+	xdp->flags |= XDP_FLAGS_GRO_DISABLED;
+}
+
+static __always_inline bool xdp_buff_gro_disabled(struct xdp_buff *xdp)
+{
+	return !!(xdp->flags & XDP_FLAGS_GRO_DISABLED);
+}
+
+static __always_inline void
+xdp_buff_fixup_skb_offloading(struct xdp_buff *xdp, struct sk_buff *skb)
+{
+	if (xdp_buff_gro_disabled(xdp))
+		skb_disable_gro(skb);
+}
+
+static __always_inline void
+xdp_init_buff_minimal(struct xdp_buff *xdp)
+{
+	xdp->flags = 0;
+}
+
 static __always_inline void
 xdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq)
 {
 	xdp->frame_sz = frame_sz;
 	xdp->rxq = rxq;
-	xdp->flags = 0;
+	xdp_init_buff_minimal(xdp);
 }
 
 static __always_inline void
@@ -187,6 +211,18 @@  static __always_inline bool xdp_frame_is_frag_pfmemalloc(struct xdp_frame *frame
 	return !!(frame->flags & XDP_FLAGS_FRAGS_PF_MEMALLOC);
 }
 
+static __always_inline bool xdp_frame_gro_disabled(struct xdp_frame *frame)
+{
+	return !!(frame->flags & XDP_FLAGS_GRO_DISABLED);
+}
+
+static __always_inline void
+xdp_frame_fixup_skb_offloading(struct xdp_frame *frame, struct sk_buff *skb)
+{
+	if (xdp_frame_gro_disabled(frame))
+		skb_disable_gro(skb);
+}
+
 #define XDP_BULK_QUEUE_SIZE	16
 struct xdp_frame_bulk {
 	int count;