πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by Lorenzo Bianconi Thu, 12 Nov 2026 16:34
[PATCH net-next v10 1/4] net: xdp: add __xdp_build_skb_from_buff() helper
#15287
Author: Lorenzo Bianconi
Date: Thu, 12 Nov 2026 16:34
93 lines
18195 bytes
xdp_build_skb_from_buff() always calls eth_type_trans() on the skb it
builds, which consumes the Ethernet header and advances skb->data.
Drivers that still need to process the L2 header before protocol parsing
therefore cannot use the helper.

stmmac is such a driver: its software VLAN path (stmmac_rx_vlan()) reads
the tag at skb->data and shifts the MAC addresses, so it has to run
before eth_type_trans().

Split the implementation into __xdp_build_skb_from_buff(), which builds
the skb (including the recycle mark, the Rx queue index and the frags
info) but leaves protocol parsing to the caller, and make
xdp_build_skb_from_buff() an inline wrapper that still calls
eth_type_trans() as before. There is no functional change for existing
users; a follow-up patch will let stmmac use the underscore variant.

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
---
 include/net/xdp.h | 17 ++++++++++++++++-
 net/core/xdp.c    | 11 +++++------
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/include/net/xdp.h b/include/net/xdp.h
index 07231adfb5f8..3a25307e1d67 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -379,7 +379,22 @@ xdp_update_skb_frags_info(struct sk_buff *skb, u8 nr_frags,
 void xdp_warn(const char *msg, const char *func, const int line);
 #define XDP_WARN(msg) xdp_warn(msg, __func__, __LINE__)
 
-struct sk_buff *xdp_build_skb_from_buff(const struct xdp_buff *xdp);
+struct sk_buff *__xdp_build_skb_from_buff(const struct xdp_buff *xdp);
+static inline
+struct sk_buff *xdp_build_skb_from_buff(const struct xdp_buff *xdp)
+{
+	const struct xdp_rxq_info *rxq = xdp->rxq;
+	struct sk_buff *skb;
+
+	skb = __xdp_build_skb_from_buff(xdp);
+	if (!skb)
+		return NULL;
+
+	skb->protocol = eth_type_trans(skb, rxq->dev);
+
+	return skb;
+}
+
 struct sk_buff *xdp_build_skb_from_zc(struct xdp_buff *xdp);
 struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp);
 struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 1d679e8fd649..470bf90d93ef 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -620,17 +620,18 @@ void xdp_warn(const char *msg, const char *func, const int line)
 EXPORT_SYMBOL_GPL(xdp_warn);
 
 /**
- * xdp_build_skb_from_buff - create an skb from &xdp_buff
+ * __xdp_build_skb_from_buff - create an skb from &xdp_buff
  * @xdp: &xdp_buff to convert to an skb
  *
  * Perform common operations to create a new skb to pass up the stack from
  * &xdp_buff: allocate an skb head from the NAPI percpu cache, initialize
  * skb data pointers and offsets, set the recycle bit if the buff is
- * PP-backed, Rx queue index, protocol and update frags info.
+ * PP-backed, record the Rx queue index and update frags info. Protocol
+ * parsing is left to the caller.
  *
  * Return: new &sk_buff on success, %NULL on error.
  */
-struct sk_buff *xdp_build_skb_from_buff(const struct xdp_buff *xdp)
+struct sk_buff *__xdp_build_skb_from_buff(const struct xdp_buff *xdp)
 {
 	const struct xdp_rxq_info *rxq = xdp->rxq;
 	const struct skb_shared_info *sinfo;
@@ -667,11 +668,9 @@ struct sk_buff *xdp_build_skb_from_buff(const struct xdp_buff *xdp)
 					  tsize, xdp_buff_get_skb_flags(xdp));
 	}
 
-	skb->protocol = eth_type_trans(skb, rxq->dev);
-
 	return skb;
 }
-EXPORT_SYMBOL_GPL(xdp_build_skb_from_buff);
+EXPORT_SYMBOL_GPL(__xdp_build_skb_from_buff);
 
 /**
  * xdp_copy_frags_from_zc - copy frags from XSk buff to skb

-- 
2.56.0
Re: [PATCH net-next v10 1/4] net: xdp: add __xdp_build_skb_from_buff() helper
#17365
Author: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 17:20
87 lines
11593 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The kerneldoc for the newly exported __xdp_build_skb_from_buff()
  (net/core/xdp.c:622-633) says only "Protocol parsing is left to the…

--

net: xdp: add __xdp_build_skb_from_buff() helper

This patch splits xdp_build_skb_from_buff() in two. The new exported
__xdp_build_skb_from_buff() builds the skb without calling
eth_type_trans(). A static inline wrapper in include/net/xdp.h keeps the
old behaviour and still calls eth_type_trans(). The goal is to let stmmac
process the L2 header (software VLAN) before protocol parsing.

> diff --git a/net/core/xdp.c b/net/core/xdp.c
> index 1d679e8fd6493..470bf90d93ef2 100644
> --- a/net/core/xdp.c
> +++ b/net/core/xdp.c
> @@ -620,17 +620,18 @@ void xdp_warn(const char *msg, const char *func, const int line)
>  EXPORT_SYMBOL_GPL(xdp_warn);
>  
>  /**
> - * xdp_build_skb_from_buff - create an skb from &xdp_buff
> + * __xdp_build_skb_from_buff - create an skb from &xdp_buff
>   * @xdp: &xdp_buff to convert to an skb
>   *
>   * Perform common operations to create a new skb to pass up the stack from
>   * &xdp_buff: allocate an skb head from the NAPI percpu cache, initialize
>   * skb data pointers and offsets, set the recycle bit if the buff is
> - * PP-backed, Rx queue index, protocol and update frags info.
> + * PP-backed, record the Rx queue index and update frags info. Protocol
> + * parsing is left to the caller.

[Severity: Low]
Does "Protocol parsing is left to the caller" fully describe what the
caller now has to do?

Moving eth_type_trans() out of __xdp_build_skb_from_buff() also moves out
the other work it does:

net/ethernet/eth.c:eth_type_trans() {
	skb->dev = dev;
	skb_reset_mac_header(skb);

	eth = eth_skb_pull_mac(skb);
	eth_skb_pkt_type(skb, dev);
    ...
}

So the skb returned by __xdp_build_skb_from_buff() has skb->dev == NULL
and no mac header, and protocol and pkt_type are not set. This is true
even though rxq->dev is available inside the helper.

The peer helper __xdp_build_skb_from_frame() still sets these:

	/* Essential SKB info: protocol and skb->dev */
	skb->protocol = eth_type_trans(skb, dev);

As a result, the two __xdp_build_skb_* helpers now return different
minimal skb state.

Nothing breaks today. The only in-tree user of the underscore variant
later in the series is stmmac_rx(), and it calls
eth_type_trans(skb, priv->dev) before napi_gro_receive(). A future caller
that does its own L2 handling and reads "protocol parsing" as just
skb->protocol could pass an skb with no dev to napi_gro_receive() or
netif_receive_skb().

Could the kerneldoc say that the caller must also set skb->dev and reset
the mac header, for example by calling eth_type_trans()?

A smaller point: the public xdp_build_skb_from_buff() wrapper in
include/net/xdp.h no longer has any kerneldoc. The kerneldoc for
xdp_build_skb_from_zc() still refers readers to it:

 * Similar to xdp_build_skb_from_buff(), but for XSk frames. Allocate an skb

[ ... ]

-- 
Sashiko AI review Β· https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-stmmac-rx-mb-v10-0-d3d04b65c6bc%40oss.qualcomm.com
Re: [PATCH net-next v10 1/4] net: xdp: add __xdp_build_skb_from_buff() helper
#17864
Author: Lorenzo Bianconi
Date: Tue, 17 Nov 2026 12:55
119 lines
19218 bytes
--IgpR4FCbaFWOr+d8
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

> Thank you for your contribution! Sashiko AI review found more severe
> issue(s) in other patches of this series. This mail is only an FYI, in ca=
se
> you want to address the nit picks below when you respin.
>=20
> Low priority / nit picks for your consideration:
>=20
> - [Low] The kerneldoc for the newly exported __xdp_build_skb_from_buff()
>   (net/core/xdp.c:622-633) says only "Protocol parsing is left to the=E2=
=80=A6
>=20
> --
>=20
> net: xdp: add __xdp_build_skb_from_buff() helper
>=20
> This patch splits xdp_build_skb_from_buff() in two. The new exported
> __xdp_build_skb_from_buff() builds the skb without calling
> eth_type_trans(). A static inline wrapper in include/net/xdp.h keeps the
> old behaviour and still calls eth_type_trans(). The goal is to let stmmac
> process the L2 header (software VLAN) before protocol parsing.
>=20
> > diff --git a/net/core/xdp.c b/net/core/xdp.c
> > index 1d679e8fd6493..470bf90d93ef2 100644
> > --- a/net/core/xdp.c
> > +++ b/net/core/xdp.c
> > @@ -620,17 +620,18 @@ void xdp_warn(const char *msg, const char *func, =
const int line)
> >  EXPORT_SYMBOL_GPL(xdp_warn);
> > =20
> >  /**
> > - * xdp_build_skb_from_buff - create an skb from &xdp_buff
> > + * __xdp_build_skb_from_buff - create an skb from &xdp_buff
> >   * @xdp: &xdp_buff to convert to an skb
> >   *
> >   * Perform common operations to create a new skb to pass up the stack =
=66rom
> >   * &xdp_buff: allocate an skb head from the NAPI percpu cache, initial=
ize
> >   * skb data pointers and offsets, set the recycle bit if the buff is
> > - * PP-backed, Rx queue index, protocol and update frags info.
> > + * PP-backed, record the Rx queue index and update frags info. Protocol
> > + * parsing is left to the caller.
>=20
> [Severity: Low]
> Does "Protocol parsing is left to the caller" fully describe what the
> caller now has to do?
>=20
> Moving eth_type_trans() out of __xdp_build_skb_from_buff() also moves out
> the other work it does:
>=20
> net/ethernet/eth.c:eth_type_trans() {
> 	skb->dev =3D dev;
> 	skb_reset_mac_header(skb);
>=20
> 	eth =3D eth_skb_pull_mac(skb);
> 	eth_skb_pkt_type(skb, dev);
>     ...
> }
>=20
> So the skb returned by __xdp_build_skb_from_buff() has skb->dev =3D=3D NU=
LL
> and no mac header, and protocol and pkt_type are not set. This is true
> even though rxq->dev is available inside the helper.
>=20
> The peer helper __xdp_build_skb_from_frame() still sets these:
>=20
> 	/* Essential SKB info: protocol and skb->dev */
> 	skb->protocol =3D eth_type_trans(skb, dev);
>=20
> As a result, the two __xdp_build_skb_* helpers now return different
> minimal skb state.
>=20
> Nothing breaks today. The only in-tree user of the underscore variant
> later in the series is stmmac_rx(), and it calls
> eth_type_trans(skb, priv->dev) before napi_gro_receive(). A future caller
> that does its own L2 handling and reads "protocol parsing" as just
> skb->protocol could pass an skb with no dev to napi_gro_receive() or
> netif_receive_skb().
>=20
> Could the kerneldoc say that the caller must also set skb->dev and reset
> the mac header, for example by calling eth_type_trans()?
>=20
> A smaller point: the public xdp_build_skb_from_buff() wrapper in
> include/net/xdp.h no longer has any kerneldoc. The kerneldoc for
> xdp_build_skb_from_zc() still refers readers to it:
>=20
>  * Similar to xdp_build_skb_from_buff(), but for XSk frames. Allocate an =
skb
>=20
> [ ... ]

I will fix it in v11.

Regards,
Lorenzo

>=20
> --=20
> Sashiko AI review =C2=B7 https://netdev-ai.bots.linux.dev/sashiko/#/patch=
set/20261112-stmmac-rx-mb-v10-0-d3d04b65c6bc%40oss.qualcomm.com

--IgpR4FCbaFWOr+d8
Content-Type: application/pgp-signature; name=signature.asc

-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQTquNwa3Txd3rGGn7Y6cBh0uS2trAUCavxOxQAKCRA6cBh0uS2t
rN8KAP9n5nAt1PRZw9UtpxsfE+nfrsPd8jBTaqd/v/2xmf0JLgD+LNQ8PQVLXBEM
4iO7vZYN47HIhryG3h5wueYeqlLIewo=
=S4jk
-----END PGP SIGNATURE-----

--IgpR4FCbaFWOr+d8--
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads