* [PATCH net-next v14 1/5] net: stmmac: selftests: Prevent RXC from being disabled in LPI
2026-12-04 10:44 [PATCH net-next v14 0/5] net: stmmac: introduce XDP rx multi-buff support Lorenzo Bianconi
@ 2026-12-04 10:44 ` Lorenzo Bianconi
2026-12-04 10:44 ` [PATCH net-next v14 2/5] net: stmmac: remove software VLAN tag stripping Lorenzo Bianconi
` (3 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2026-12-04 10:44 UTC (permalink / raw)
To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Jose Abreu, Ong Boon Leong,
Simon Horman, Andrii Nakryiko, Eduard Zingerman,
Kumar Kartikeya Dwivedi, Martin KaFai Lau, Song Liu,
Yonghong Song, Jiri Olsa, Emil Tsalapatis, Ihor Solodrai,
Matthew Gerlach, Boon Khai Ng, Russell King, Willem de Bruijn
Cc: netdev, linux-arm-kernel, bpf, Peilin He
From: Maxime Chevallier <maxime.chevallier@bootlin.com>
RXC is critical to the RX path and some register banks in stmmac, so
it is blocked from being disabled in LPI when we know we're going
to need that clock.
During selftests, we're in MAC loopback so the PHY may enter LPI and
stop its RXC. This will prevent the RX path from properly receiving
the looped-back packets, hence failing the selftests.
As NETIF_F_VLAN_FEATURES may be empty on some platforms once the
software VLAN stripping is removed, the phylink config attribute
'eee_rx_clk_stop_enable' may no longer be unconditionally set to
false, hence allowing RXC to be disabled during LPI on platforms
that don't have any VLAN features. This is already the case for
CONFIG_VLAN_8021Q=n builds.
Fixes: 091810dbded9 ("net: stmmac: Introduce selftests support")
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: Peilin He <he.peilin@zte.com.cn>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index df696e2c1528..41a8493cf9dd 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -1940,12 +1940,14 @@ void stmmac_selftest_run(struct net_device *dev,
return;
}
+ phylink_rx_clk_stop_block(priv->phylink);
for (i = 0; i < count; i++) {
ret = stmmac_selftests[i].fn(priv);
if (ret && (ret != -EOPNOTSUPP))
etest->flags |= ETH_TEST_FL_FAILED;
buf[i] = ret;
}
+ phylink_rx_clk_stop_unblock(priv->phylink);
stmmac_set_mac_loopback(priv, priv->ioaddr, false);
}
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH net-next v14 2/5] net: stmmac: remove software VLAN tag stripping
2026-12-04 10:44 [PATCH net-next v14 0/5] net: stmmac: introduce XDP rx multi-buff support Lorenzo Bianconi
2026-12-04 10:44 ` [PATCH net-next v14 1/5] net: stmmac: selftests: Prevent RXC from being disabled in LPI Lorenzo Bianconi
@ 2026-12-04 10:44 ` Lorenzo Bianconi
2026-12-05 10:45 ` sashiko-bot
2026-12-05 10:51 ` netdev-bot+sashiko
2026-12-04 10:44 ` [PATCH net-next v14 3/5] net: xdp: add xdp_buff_shrink_tail() helper Lorenzo Bianconi
` (2 subsequent siblings)
4 siblings, 2 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2026-12-04 10:44 UTC (permalink / raw)
To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Jose Abreu, Ong Boon Leong,
Simon Horman, Andrii Nakryiko, Eduard Zingerman,
Kumar Kartikeya Dwivedi, Martin KaFai Lau, Song Liu,
Yonghong Song, Jiri Olsa, Emil Tsalapatis, Ihor Solodrai,
Matthew Gerlach, Boon Khai Ng, Russell King, Willem de Bruijn
Cc: netdev, linux-arm-kernel, bpf, Peilin He, Lorenzo Bianconi
The software VLAN stripping logic in stmmac_rx_vlan() was originally
introduced in 2014 by 'commit b93819854d6e ("stmmac: Add vlan rx for
better GRO performance.")' as a workaround to improve GRO performance,
since at that time GRO could not handle frames with VLAN tags. However,
this limitation was resolved in 2015 by 'commit 66e5133f19e9 ("vlan: Add
GRO support for non hardware accelerated vlan")', which added GRO support
for non-hardware-accelerated VLAN frames. Keeping a software fallback
path for VLAN stripping is no longer necessary and only adds complexity.
After removing it, VLAN tags remain in the packet, so
stmmac_has_ip_ethertype() has to keep recognising IPv4/IPv6 behind a
single in-payload VLAN tag. On RX the helper runs after eth_type_trans(),
which has already pulled the Ethernet header, so walk the tag chain with
skb_mac_offset() instead of __vlan_get_protocol(), which assumes the MAC
header still sits at skb->data. On TX the helper still runs before the
header is pulled.
Make the tolerated L2 depth explicit:
- on RX allow a single in-payload C-tag while the MAC is not stripping
tags (VLAN_ETH_HLEN); when HW stripping is active the payload must be
tag-free, so keep the ETH_HLEN limit and reject any tag that is still
there;
- in-payload S-tags are always rejected, as only an S-tag that the
hardware stripped (and whose type is reported through
get_rx_vlan_proto) is known to have been parsed by the checksum engine;
- on TX keep the old ETH_HLEN limit, so DSA-tagged frames that the
checksum engine ignores (see commit c2945c435c99 ("net: stmmac:
Prevent DSA tags from breaking COE")) remain excluded from hardware
checksum and TSO.
This intentionally changes the advertised features:
- dwmac100/dwmac1000 no longer advertise NETIF_F_HW_VLAN_CTAG_RX;
they have no hardware VLAN stripping.
- On xmac cores NETIF_F_HW_VLAN_CTAG_RX is advertised only when the
VLAN ops provide .set_hw_vlan_mode and .rx_hw_vlan, so DWXLGMAC no
longer falsely advertises RX VLAN offload.
- NETIF_F_HW_VLAN_STAG_RX is advertised only on cores that provide
hardware RX VLAN offload and whose descriptor ops report the stripped
tag protocol (get_rx_vlan_proto), i.e. DWXGMAC. DWXLGMAC loses it
because it has no RX VLAN offload, while cores without
get_rx_vlan_proto report stripped S-tags as C-tags.
The DWXLGMAC mis-advertisement was introduced by 'commit 534df0c1724b
("net: stmmac: dwxgmac2: Add support for HW-accelerated VLAN stripping"),
which widened the RX VLAN offload gate from GMAC4 to all xmac cores but
only added .rx_hw_vlan to dwxgmac210_vlan_ops. DWXLGMAC is also
DWMAC_CORE_XGMAC, and dwxlgmac2_vlan_ops has no .rx_hw_vlan, so it ended
up advertising RX VLAN offload while neither hardware nor software
stripped the tag. Tag the fix accordingly.
With NETIF_F_VLAN_FEATURES possibly empty, stmmac_phylink_setup() may
now allow the PHY to stop the RX clock in LPI on cores that no longer
advertise any VLAN feature, for example dwmac1000 with EEE and DWXLGMAC
without vlhash/vlins. The MAC needs RXC running for some register
accesses, including the MAC address and filter registers written by
stmmac_set_rx_mode(). That callback runs with bottom halves disabled and
cannot use phylink_rx_clk_stop_block(), so a multicast, unicast or
promiscuous update could be lost while the clock is stopped.
This is not a new failure mode: the same window already exists with
CONFIG_VLAN_8021Q=n and existed before 'commit c171e679ee66 ("net: stmmac:
Disable EEE RX clock stop when VLAN is enabled"), whose VLAN feature
check only guarded it incidentally. dwmac100 is unaffected because it
has no EEE.
This will be addressed by a dedicated follow-up patch that decouples the
EEE RX clock-stop policy from the advertised VLAN features and makes the
atomic register accesses safe. The preceding selftests patch already
blocks RX clock stop while the ethtool selftests run.
This depends on the preceding selftests fix.
Fixes: 534df0c1724b ("net: stmmac: dwxgmac2: Add support for HW-accelerated VLAN stripping")
Suggested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Co-developed-by: Peilin He <he.peilin@zte.com.cn>
Signed-off-by: Peilin He <he.peilin@zte.com.cn>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
---
drivers/net/ethernet/stmicro/stmmac/stmmac.h | 12 ++++
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 87 ++++++++---------------
2 files changed, 42 insertions(+), 57 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index fcc395321816..fa9ef4212982 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -478,4 +478,16 @@ static inline int stmmac_selftest_get_count(struct stmmac_priv *priv)
}
#endif /* CONFIG_STMMAC_SELFTESTS */
+static inline bool stmmac_rx_8021q_offload(struct stmmac_priv *priv)
+{
+ return priv->hw->vlan && priv->hw->vlan->set_hw_vlan_mode &&
+ priv->hw->vlan->rx_hw_vlan;
+}
+
+static inline bool stmmac_rx_8021ad_offload(struct stmmac_priv *priv)
+{
+ return stmmac_rx_8021q_offload(priv) &&
+ priv->hw->desc->get_rx_vlan_proto;
+}
+
#endif /* __STMMAC_H__ */
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index b3524d46863d..c429cb9e1ccb 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -4885,7 +4885,9 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
/**
* stmmac_has_ip_ethertype() - Check if packet has IP ethertype
+ * @priv: driver private structure
* @skb: socket buffer to check
+ * @xmit: transmit path
*
* Check if a packet has an ethertype that will trigger the IP header checks
* and IP/TCP checksum engine of the stmmac core.
@@ -4893,16 +4895,25 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
* Return: true if the ethertype can trigger the checksum engine, false
* otherwise
*/
-static bool stmmac_has_ip_ethertype(struct sk_buff *skb)
+static bool stmmac_has_ip_ethertype(struct stmmac_priv *priv,
+ struct sk_buff *skb, bool xmit)
{
- int depth = 0;
- __be16 proto;
+ __be16 proto, h_proto = eth_header_parse_protocol(skb);
+ int max_l2_hlen, depth = 0;
+
+ /* An S-tag still in the payload may not have been parsed by the
+ * checksum engine; only trust it when the hardware stripped it, in
+ * which case h_proto is no longer ETH_P_8021AD.
+ */
+ if (h_proto == htons(ETH_P_8021AD))
+ return false;
- proto = __vlan_get_protocol(skb, eth_header_parse_protocol(skb),
- &depth);
+ proto = vlan_get_protocol_offset_inline(skb, h_proto,
+ skb_mac_offset(skb), &depth);
- return (depth <= ETH_HLEN) &&
- (proto == htons(ETH_P_IP) || proto == htons(ETH_P_IPV6));
+ max_l2_hlen = xmit || priv->hw->hw_vlan_en ? ETH_HLEN : VLAN_ETH_HLEN;
+ return depth <= max_l2_hlen &&
+ (proto == htons(ETH_P_IP) || proto == htons(ETH_P_IPV6));
}
/**
@@ -5159,7 +5170,7 @@ static netdev_features_t stmmac_features_check(struct sk_buff *skb,
* harmonize_features() in net/core/dev.c
*/
if (priv->plat->tx_queues_cfg[queue].coe_unsupported ||
- !stmmac_has_ip_ethertype(skb))
+ !stmmac_has_ip_ethertype(priv, skb, true))
features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
if (skb_is_gso(skb)) {
@@ -5181,37 +5192,6 @@ static netdev_features_t stmmac_features_check(struct sk_buff *skb,
return vlan_features_check(skb, features);
}
-static int stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb)
-{
- struct vlan_ethhdr *veth;
-
- if (!pskb_may_pull(skb, ETH_HLEN))
- return -EINVAL;
-
- veth = skb_vlan_eth_hdr(skb);
- if ((veth->h_vlan_proto == htons(ETH_P_8021Q) &&
- dev->features & NETIF_F_HW_VLAN_CTAG_RX) ||
- (veth->h_vlan_proto == htons(ETH_P_8021AD) &&
- dev->features & NETIF_F_HW_VLAN_STAG_RX)) {
- __be16 vlan_proto = veth->h_vlan_proto;
- u8 meta_len = skb_metadata_len(skb);
- u16 vlanid;
-
- /* pop the vlan tag */
- if (!pskb_may_pull(skb, VLAN_ETH_HLEN))
- return -EINVAL;
-
- veth = skb_vlan_eth_hdr(skb);
- vlanid = ntohs(veth->h_vlan_TCI);
- memmove(skb->data - meta_len + VLAN_HLEN,
- skb->data - meta_len, meta_len + ETH_ALEN * 2);
- skb_pull(skb, VLAN_HLEN);
- __vlan_hwaccel_put_tag(skb, vlan_proto, vlanid);
- }
-
- return 0;
-}
-
static bool stmmac_rx_need_ic(struct stmmac_priv *priv,
struct stmmac_rx_queue *rx_q, u32 queue)
{
@@ -5632,15 +5612,11 @@ static void stmmac_dispatch_skb_zc(struct stmmac_priv *priv, u32 queue,
if (priv->hw->hw_vlan_en) {
/* MAC level stripping. */
stmmac_rx_hw_vlan(priv, priv->hw, p, skb);
- } else if (stmmac_rx_vlan(priv->dev, skb)) {
- dev_kfree_skb_any(skb);
- priv->xstats.rx_dropped++;
- return;
}
skb->protocol = eth_type_trans(skb, priv->dev);
- if (unlikely(!coe) || !stmmac_has_ip_ethertype(skb) ||
+ if (unlikely(!coe) || !stmmac_has_ip_ethertype(priv, skb, false) ||
(status & csum_none))
skb_checksum_none_assert(skb);
else
@@ -6148,15 +6124,12 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
if (priv->hw->hw_vlan_en) {
/* MAC level stripping. */
stmmac_rx_hw_vlan(priv, priv->hw, p, skb);
- } else if (stmmac_rx_vlan(priv->dev, skb)) {
- dev_kfree_skb_any(skb);
- rx_dropped++;
- goto next;
}
skb->protocol = eth_type_trans(skb, priv->dev);
- if (unlikely(!coe) || !stmmac_has_ip_ethertype(skb) ||
+ if (unlikely(!coe) ||
+ !stmmac_has_ip_ethertype(priv, skb, false) ||
(status & csum_none))
skb_checksum_none_assert(skb);
else
@@ -6435,7 +6408,7 @@ static netdev_features_t stmmac_fix_features(struct net_device *dev,
if (priv->plat->bugged_jumbo && (dev->mtu > ETH_DATA_LEN))
features &= ~NETIF_F_CSUM_MASK;
- if (priv->plat->core_type == DWMAC_CORE_XGMAC) {
+ if (stmmac_rx_8021ad_offload(priv)) {
if (features & NETIF_F_HW_VLAN_CTAG_RX)
features |= NETIF_F_HW_VLAN_STAG_RX;
else
@@ -6468,7 +6441,7 @@ static int stmmac_set_features(struct net_device *netdev,
stmmac_enable_sph(priv, priv->ioaddr, sph_en, chan);
}
- if (features & NETIF_F_HW_VLAN_CTAG_RX)
+ if (features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX))
priv->hw->hw_vlan_en = true;
else
priv->hw->hw_vlan_en = false;
@@ -8282,15 +8255,15 @@ static int __stmmac_dvr_probe(struct device *device,
ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA;
ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
#ifdef STMMAC_VLAN_TAG_USED
- /* Both mac100 and gmac support receive VLAN tag detection */
- ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
- if (priv->plat->core_type == DWMAC_CORE_XGMAC)
- ndev->features |= NETIF_F_HW_VLAN_STAG_RX;
-
- if (dwmac_is_xmac(priv->plat->core_type)) {
+ if (stmmac_rx_8021q_offload(priv)) {
+ ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
ndev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
priv->hw->hw_vlan_en = true;
}
+
+ if (stmmac_rx_8021ad_offload(priv))
+ ndev->features |= NETIF_F_HW_VLAN_STAG_RX;
+
if (priv->dma_cap.vlhash) {
ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
if (priv->plat->core_type == DWMAC_CORE_XGMAC)
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH net-next v14 2/5] net: stmmac: remove software VLAN tag stripping
2026-12-04 10:44 ` [PATCH net-next v14 2/5] net: stmmac: remove software VLAN tag stripping Lorenzo Bianconi
@ 2026-12-05 10:45 ` sashiko-bot
2026-12-05 10:51 ` netdev-bot+sashiko
1 sibling, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-05 10:45 UTC (permalink / raw)
To: Lorenzo Bianconi; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] net: stmmac: data race and TOCTOU on hw_vlan_en in
stmmac_set_features()
- [Medium] net: stmmac: VLAN feature gating enables EEE RXC stop on
dwmac1000/DWXLGMAC
- [Low] net: stmmac: Fixes tag queues broad non-backportable VLAN
cleanup to stable
--
commit 5b78ea93f852617d0df5a6496b17b18f659bcb2d
Author: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
> net: stmmac: remove software VLAN tag stripping
>
> The software VLAN stripping logic in stmmac_rx_vlan() was originally
> introduced in 2014 by 'commit b93819854d6e ("stmmac: Add vlan rx for
> better GRO performance.")' as a workaround to improve GRO performance,
> since at that time GRO could not handle frames with VLAN tags. However,
> this limitation was resolved in 2015 by 'commit 66e5133f19e9 ("vlan: Add
> GRO support for non hardware accelerated vlan")', which added GRO support
> for non-hardware-accelerated VLAN frames. Keeping a software fallback
> path for VLAN stripping is no longer necessary and only adds complexity.
>
> After removing it, VLAN tags remain in the packet, so
> stmmac_has_ip_ethertype() has to keep recognising IPv4/IPv6 behind a
> single in-payload VLAN tag. On RX the helper runs after eth_type_trans(),
> which has already pulled the Ethernet header, so walk the tag chain with
> skb_mac_offset() instead of __vlan_get_protocol(), which assumes the MAC
> header still sits at skb->data. On TX the helper still runs before the
> header is pulled.
>
> Make the tolerated L2 depth explicit:
> - on RX allow a single in-payload C-tag while the MAC is not stripping
> tags (VLAN_ETH_HLEN); when HW stripping is active the payload must be
> tag-free, so keep the ETH_HLEN limit and reject any tag that is still
> there;
> - in-payload S-tags are always rejected, as only an S-tag that the
> hardware stripped (and whose type is reported through
> get_rx_vlan_proto) is known to have been parsed by the checksum engine;
> - on TX keep the old ETH_HLEN limit, so DSA-tagged frames that the
> checksum engine ignores (see commit c2945c435c99 ("net: stmmac:
> Prevent DSA tags from breaking COE")) remain excluded from hardware
> checksum and TSO.
>
> This intentionally changes the advertised features:
> - dwmac100/dwmac1000 no longer advertise NETIF_F_HW_VLAN_CTAG_RX;
> they have no hardware VLAN stripping.
> - On xmac cores NETIF_F_HW_VLAN_CTAG_RX is advertised only when the
> VLAN ops provide .set_hw_vlan_mode and .rx_hw_vlan, so DWXLGMAC no
> longer falsely advertises RX VLAN offload.
> - NETIF_F_HW_VLAN_STAG_RX is advertised only on cores that provide
> hardware RX VLAN offload and whose descriptor ops report the stripped
> tag protocol (get_rx_vlan_proto), i.e. DWXGMAC. DWXLGMAC loses it
> because it has no RX VLAN offload, while cores without
> get_rx_vlan_proto report stripped S-tags as C-tags.
>
> The DWXLGMAC mis-advertisement was introduced by 'commit 534df0c1724b
> ("net: stmmac: dwxgmac2: Add support for HW-accelerated VLAN stripping"),
> which widened the RX VLAN offload gate from GMAC4 to all xmac cores but
> only added .rx_hw_vlan to dwxgmac210_vlan_ops. DWXLGMAC is also
> DWMAC_CORE_XGMAC, and dwxlgmac2_vlan_ops has no .rx_hw_vlan, so it ended
> up advertising RX VLAN offload while neither hardware nor software
> stripped the tag. Tag the fix accordingly.
>
> With NETIF_F_VLAN_FEATURES possibly empty, stmmac_phylink_setup() may
> now allow the PHY to stop the RX clock in LPI on cores that no longer
> advertise any VLAN feature, for example dwmac1000 with EEE and DWXLGMAC
> without vlhash/vlins. The MAC needs RXC running for some register
> accesses, including the MAC address and filter registers written by
> stmmac_set_rx_mode(). That callback runs with bottom halves disabled and
> cannot use phylink_rx_clk_stop_block(), so a multicast, unicast or
> promiscuous update could be lost while the clock is stopped.
>
> This is not a new failure mode: the same window already exists with
> CONFIG_VLAN_8021Q=n and existed before 'commit c171e679ee66 ("net: stmmac:
> Disable EEE RX clock stop when VLAN is enabled"), whose VLAN feature
> check only guarded it incidentally. dwmac100 is unaffected because it
> has no EEE.
>
> This will be addressed by a dedicated follow-up patch that decouples the
> EEE RX clock-stop policy from the advertised VLAN features and makes the
> atomic register accesses safe. The preceding selftests patch already
> blocks RX clock stop while the ethtool selftests run.
>
> This depends on the preceding selftests fix.
>
> Fixes: 534df0c1724b ("net: stmmac: dwxgmac2: Add support for HW-accelerated VLAN stripping")
> Suggested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> Co-developed-by: Peilin He <he.peilin@zte.com.cn>
> Signed-off-by: Peilin He <he.peilin@zte.com.cn>
> Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
[Severity: Low]
Should this patch carry Fixes: 534df0c1724b ("net: stmmac: dwxgmac2: Add
support for HW-accelerated VLAN stripping")?
In netdev, a Fixes: tag queues the commit for automated stable backporting,
but this change cannot be backported standalone to stable trees carrying
534df0c1724b: stmmac_has_ip_ethertype() calls
vlan_get_protocol_offset_inline() from 7a4cd71fa451 ("net: add
vlan_get_protocol_offset_inline() helper"), and the patch depends on commit
"net: stmmac: selftests: Prevent RXC from being disabled in LPI".
It also bundles the narrow DWXLGMAC fix with removing stmmac_rx_vlan(),
dropping NETIF_F_HW_VLAN_CTAG_RX on dwmac100/dwmac1000, and exposing the
EEE RX clock-stop window noted above. Splitting out the DWXLGMAC
advertisement fix for net/stable, or dropping the Fixes: tag here, would
avoid broken backports.
[ ... ]
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index b3524d46863da..c429cb9e1ccbe 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -4893,16 +4895,25 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
> * Return: true if the ethertype can trigger the checksum engine, false
> * otherwise
> */
> -static bool stmmac_has_ip_ethertype(struct sk_buff *skb)
> +static bool stmmac_has_ip_ethertype(struct stmmac_priv *priv,
> + struct sk_buff *skb, bool xmit)
> {
> - int depth = 0;
> - __be16 proto;
> + __be16 proto, h_proto = eth_header_parse_protocol(skb);
> + int max_l2_hlen, depth = 0;
> +
> + /* An S-tag still in the payload may not have been parsed by the
> + * checksum engine; only trust it when the hardware stripped it, in
> + * which case h_proto is no longer ETH_P_8021AD.
> + */
> + if (h_proto == htons(ETH_P_8021AD))
> + return false;
>
> - proto = __vlan_get_protocol(skb, eth_header_parse_protocol(skb),
> - &depth);
> + proto = vlan_get_protocol_offset_inline(skb, h_proto,
> + skb_mac_offset(skb), &depth);
>
> - return (depth <= ETH_HLEN) &&
> - (proto == htons(ETH_P_IP) || proto == htons(ETH_P_IPV6));
> + max_l2_hlen = xmit || priv->hw->hw_vlan_en ? ETH_HLEN : VLAN_ETH_HLEN;
> + return depth <= max_l2_hlen &&
> + (proto == htons(ETH_P_IP) || proto == htons(ETH_P_IPV6));
> }
[Severity: Medium]
Can concurrent ethtool -K rxvlan toggling race with RX polling on
priv->hw->hw_vlan_en?
stmmac_set_features() writes priv->hw->hw_vlan_en under rtnl_lock()
without stopping NAPI or using WRITE_ONCE(), while stmmac_rx() and
stmmac_dispatch_skb_zc() now read it twice per packet without locking:
once before stmmac_rx_hw_vlan() and again inside stmmac_has_ip_ethertype().
CPU0 CPU1
stmmac_set_features() stmmac_rx()
(ethtool -K rxvlan off) if (priv->hw->hw_vlan_en) /* true */
stmmac_rx_hw_vlan(...)
eth_type_trans(...)
priv->hw->hw_vlan_en = false;
phylink_rx_clk_stop_block(...)
stmmac_has_ip_ethertype(...)
priv->hw->hw_vlan_en /* false */
max_l2_hlen = VLAN_ETH_HLEN
<-- inner C-tag marked UNNECESSARY
On a double-tagged frame whose outer tag hardware already stripped,
reading true then false lets stmmac_has_ip_ethertype() accept the
remaining inner C-tag and mark the frame CHECKSUM_UNNECESSARY. This also
compounds the window where stmmac_set_features() flips hw_vlan_en before
sleeping in phylink_rx_clk_stop_block() and before
stmmac_set_hw_vlan_mode() updates the hardware register: toggling rxvlan
on can duplicate an unstripped tag, while toggling it off can drop a
stripped tag.
Passing a single READ_ONCE(priv->hw->hw_vlan_en) snapshot into
stmmac_has_ip_ethertype() avoids the per-packet mismatch, and
synchronizing the flag update with NAPI/RX programming avoids the
hardware/software window.
[ ... ]
> @@ -8282,15 +8255,15 @@ static int __stmmac_dvr_probe(struct device *device,
> ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA;
> ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
> #ifdef STMMAC_VLAN_TAG_USED
> - /* Both mac100 and gmac support receive VLAN tag detection */
> - ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
> - if (priv->plat->core_type == DWMAC_CORE_XGMAC)
> - ndev->features |= NETIF_F_HW_VLAN_STAG_RX;
> -
> - if (dwmac_is_xmac(priv->plat->core_type)) {
> + if (stmmac_rx_8021q_offload(priv)) {
> + ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
> ndev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
> priv->hw->hw_vlan_en = true;
> }
> +
> + if (stmmac_rx_8021ad_offload(priv))
> + ndev->features |= NETIF_F_HW_VLAN_STAG_RX;
> +
> if (priv->dma_cap.vlhash) {
> ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
> if (priv->plat->core_type == DWMAC_CORE_XGMAC)
[Severity: Medium]
Can gating NETIF_F_HW_VLAN_CTAG_RX here cause stmmac_set_rx_mode()
register writes to be lost on dwmac1000 and DWXLGMAC?
Previously, with CONFIG_VLAN_8021Q enabled, __stmmac_dvr_probe() always
set NETIF_F_HW_VLAN_CTAG_RX, keeping NETIF_F_VLAN_FEATURES non-empty so
stmmac_phylink_setup() left config->eee_rx_clk_stop_enable false. Now
dwmac1000 (which has no vlan ops and no vlhash/vlins, but supports EEE)
and DWXLGMAC without vlhash/vlins leave NETIF_F_VLAN_FEATURES empty,
enabling PHY RX clock stop in LPI.
Because stmmac_set_rx_mode() runs with bottom halves disabled and cannot
call phylink_rx_clk_stop_block(), multicast, unicast, or promiscuous
filter updates can be silently dropped while RXC is stopped. The commit
message defers decoupling EEE RX clock stop from NETIF_F_VLAN_FEATURES to
a future patch outside this series; should that fix land before gating
NETIF_F_HW_VLAN_CTAG_RX here?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-stmmac-rx-mb-v14-0-5506796fd39e@oss.qualcomm.com?part=2
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH net-next v14 2/5] net: stmmac: remove software VLAN tag stripping
2026-12-04 10:44 ` [PATCH net-next v14 2/5] net: stmmac: remove software VLAN tag stripping Lorenzo Bianconi
2026-12-05 10:45 ` sashiko-bot
@ 2026-12-05 10:51 ` netdev-bot+sashiko
2026-12-05 11:48 ` Lorenzo Bianconi
1 sibling, 1 reply; 11+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 10:51 UTC (permalink / raw)
To: lorenzo.bianconi
Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
mcoquelin.stm32, alexandre.torgue, ast, daniel, hawk,
john.fastabend, sdf, Jose.Abreu, boon.leong.ong, horms, andrii,
eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil,
ihor.solodrai, matthew.gerlach, boon.khai.ng, linux, willemb,
netdev, linux-arm-kernel, bpf, nb
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] With this patch, the PHY is allowed to stop RXC in LPI on
dwmac100/dwmac1000 and on DWXLGMAC builds that have no vlhash/vlins.
--
net: stmmac: remove software VLAN tag stripping
This removes the software VLAN stripping fallback in stmmac_rx_vlan().
stmmac_has_ip_ethertype() is reworked so it still recognises IPv4/IPv6
behind a single in-payload C-tag on RX. NETIF_F_HW_VLAN_CTAG_RX and
NETIF_F_HW_VLAN_STAG_RX are now advertised only on cores that actually
provide hardware RX VLAN offload.
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index b3524d46863da..c429cb9e1ccbe 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
[ ... ]
> @@ -8282,15 +8255,15 @@ static int __stmmac_dvr_probe(struct device *device,
> ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA;
> ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
> #ifdef STMMAC_VLAN_TAG_USED
> - /* Both mac100 and gmac support receive VLAN tag detection */
> - ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
> - if (priv->plat->core_type == DWMAC_CORE_XGMAC)
> - ndev->features |= NETIF_F_HW_VLAN_STAG_RX;
> -
> - if (dwmac_is_xmac(priv->plat->core_type)) {
> + if (stmmac_rx_8021q_offload(priv)) {
> + ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
> ndev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
> priv->hw->hw_vlan_en = true;
> }
> +
> + if (stmmac_rx_8021ad_offload(priv))
> + ndev->features |= NETIF_F_HW_VLAN_STAG_RX;
> +
[Severity: Medium]
Can this change let the PHY stop RXC in LPI on cores where it never could
before, with CONFIG_VLAN_8021Q=y?
Before this patch, NETIF_F_HW_VLAN_CTAG_RX was set on every core. Now
dwmac100/dwmac1000 have no .vlan ops, and dwxlgmac2_vlan_ops has no
.rx_hw_vlan. On those cores without vlhash/vlins, NETIF_F_VLAN_FEATURES
is therefore empty by the time stmmac_phylink_setup() runs:
stmmac_phylink_setup() {
...
if (!(priv->plat->flags & STMMAC_FLAG_RX_CLK_RUNS_IN_LPI) &&
!(priv->dev->features & NETIF_F_VLAN_FEATURES))
config->eee_rx_clk_stop_enable = true;
...
}
Because of that, RX clock stop is now on by default for dwmac1000 with EEE
and for DWXLGMAC without vlhash/vlins.
stmmac_set_rx_mode() still writes the MAC address, hash and frame filter
registers through stmmac_set_filter() with BH disabled. It does not call
phylink_rx_clk_stop_block():
* FIXME: This may need RXC to be running, but it may be called with BH
* disabled, which means we can't call phylink_rx_clk_stop*().
*/
static void stmmac_set_rx_mode(struct net_device *dev)
If a multicast join, unicast address change or promisc toggle arrives
while the link is idle in LPI and RXC is stopped, can the hardware filter
end up out of sync with the software lists? One example is a missed IPv6
solicited-node multicast address, which would break ND until the next
set_rx_mode call.
The commit message acknowledges this window and says a dedicated
follow-up will fix it. That follow-up does not seem to be part of this
series. At the last commit of the series ("net: stmmac: rework stmmac_rx
to support XDP rx multi-buff"), stmmac_phylink_setup() still uses the
same NETIF_F_VLAN_FEATURES gate.
The patch also carries "Fixes: 534df0c1724b", so stable could pick it up
without the decoupling change. Could eee_rx_clk_stop_enable be decoupled
from NETIF_F_VLAN_FEATURES before this patch, or in the same series?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-stmmac-rx-mb-v14-0-5506796fd39e%40oss.qualcomm.com
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH net-next v14 2/5] net: stmmac: remove software VLAN tag stripping
2026-12-05 10:51 ` netdev-bot+sashiko
@ 2026-12-05 11:48 ` Lorenzo Bianconi
0 siblings, 0 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2026-12-05 11:48 UTC (permalink / raw)
To: netdev-bot+sashiko
Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
mcoquelin.stm32, alexandre.torgue, ast, daniel, hawk,
john.fastabend, sdf, Jose.Abreu, boon.leong.ong, horms, andrii,
eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil,
ihor.solodrai, matthew.gerlach, boon.khai.ng, linux, willemb,
netdev, linux-arm-kernel, bpf, nb
[-- Attachment #1: Type: text/plain, Size: 4600 bytes --]
On Dec 05, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · Low: 0
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [Medium] With this patch, the PHY is allowed to stop RXC in LPI on
> dwmac100/dwmac1000 and on DWXLGMAC builds that have no vlhash/vlins.
>
> --
>
> net: stmmac: remove software VLAN tag stripping
>
> This removes the software VLAN stripping fallback in stmmac_rx_vlan().
> stmmac_has_ip_ethertype() is reworked so it still recognises IPv4/IPv6
> behind a single in-payload C-tag on RX. NETIF_F_HW_VLAN_CTAG_RX and
> NETIF_F_HW_VLAN_STAG_RX are now advertised only on cores that actually
> provide hardware RX VLAN offload.
>
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > index b3524d46863da..c429cb9e1ccbe 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>
> [ ... ]
>
> > @@ -8282,15 +8255,15 @@ static int __stmmac_dvr_probe(struct device *device,
> > ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA;
> > ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
> > #ifdef STMMAC_VLAN_TAG_USED
> > - /* Both mac100 and gmac support receive VLAN tag detection */
> > - ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
> > - if (priv->plat->core_type == DWMAC_CORE_XGMAC)
> > - ndev->features |= NETIF_F_HW_VLAN_STAG_RX;
> > -
> > - if (dwmac_is_xmac(priv->plat->core_type)) {
> > + if (stmmac_rx_8021q_offload(priv)) {
> > + ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
> > ndev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
> > priv->hw->hw_vlan_en = true;
> > }
> > +
> > + if (stmmac_rx_8021ad_offload(priv))
> > + ndev->features |= NETIF_F_HW_VLAN_STAG_RX;
> > +
>
> [Severity: Medium]
> Can this change let the PHY stop RXC in LPI on cores where it never could
> before, with CONFIG_VLAN_8021Q=y?
>
> Before this patch, NETIF_F_HW_VLAN_CTAG_RX was set on every core. Now
> dwmac100/dwmac1000 have no .vlan ops, and dwxlgmac2_vlan_ops has no
> .rx_hw_vlan. On those cores without vlhash/vlins, NETIF_F_VLAN_FEATURES
> is therefore empty by the time stmmac_phylink_setup() runs:
>
> stmmac_phylink_setup() {
> ...
> if (!(priv->plat->flags & STMMAC_FLAG_RX_CLK_RUNS_IN_LPI) &&
> !(priv->dev->features & NETIF_F_VLAN_FEATURES))
> config->eee_rx_clk_stop_enable = true;
> ...
> }
>
> Because of that, RX clock stop is now on by default for dwmac1000 with EEE
> and for DWXLGMAC without vlhash/vlins.
>
> stmmac_set_rx_mode() still writes the MAC address, hash and frame filter
> registers through stmmac_set_filter() with BH disabled. It does not call
> phylink_rx_clk_stop_block():
>
> * FIXME: This may need RXC to be running, but it may be called with BH
> * disabled, which means we can't call phylink_rx_clk_stop*().
> */
> static void stmmac_set_rx_mode(struct net_device *dev)
>
> If a multicast join, unicast address change or promisc toggle arrives
> while the link is idle in LPI and RXC is stopped, can the hardware filter
> end up out of sync with the software lists? One example is a missed IPv6
> solicited-node multicast address, which would break ND until the next
> set_rx_mode call.
>
> The commit message acknowledges this window and says a dedicated
> follow-up will fix it. That follow-up does not seem to be part of this
> series. At the last commit of the series ("net: stmmac: rework stmmac_rx
> to support XDP rx multi-buff"), stmmac_phylink_setup() still uses the
> same NETIF_F_VLAN_FEATURES gate.
>
> The patch also carries "Fixes: 534df0c1724b", so stable could pick it up
> without the decoupling change. Could eee_rx_clk_stop_enable be decoupled
> from NETIF_F_VLAN_FEATURES before this patch, or in the same series?
As previously pointed out this issue is not introduced by this patch
(CONFIG_VLAN_8021Q=n) so I think it should be fixed with a dedicated patch.
Regards,
Lorenzo
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-stmmac-rx-mb-v14-0-5506796fd39e%40oss.qualcomm.com
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH net-next v14 3/5] net: xdp: add xdp_buff_shrink_tail() helper
2026-12-04 10:44 [PATCH net-next v14 0/5] net: stmmac: introduce XDP rx multi-buff support Lorenzo Bianconi
2026-12-04 10:44 ` [PATCH net-next v14 1/5] net: stmmac: selftests: Prevent RXC from being disabled in LPI Lorenzo Bianconi
2026-12-04 10:44 ` [PATCH net-next v14 2/5] net: stmmac: remove software VLAN tag stripping Lorenzo Bianconi
@ 2026-12-04 10:44 ` Lorenzo Bianconi
2026-12-04 10:44 ` [PATCH net-next v14 4/5] net: xdp: add __xdp_return_buff() helper Lorenzo Bianconi
2026-12-04 10:44 ` [PATCH net-next v14 5/5] net: stmmac: rework stmmac_rx to support XDP rx multi-buff Lorenzo Bianconi
4 siblings, 0 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2026-12-04 10:44 UTC (permalink / raw)
To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Jose Abreu, Ong Boon Leong,
Simon Horman, Andrii Nakryiko, Eduard Zingerman,
Kumar Kartikeya Dwivedi, Martin KaFai Lau, Song Liu,
Yonghong Song, Jiri Olsa, Emil Tsalapatis, Ihor Solodrai,
Matthew Gerlach, Boon Khai Ng, Russell King, Willem de Bruijn
Cc: netdev, linux-arm-kernel, bpf, Lorenzo Bianconi
Move the XDP tail-shrink logic out of bpf_xdp_adjust_tail() into
net/core/xdp.c so it can be shared with drivers. The frag helpers
(bpf_xdp_shrink_data_zc(), bpf_xdp_shrink_data() and
bpf_xdp_frags_shrink_tail()) move along with it and are renamed to
xdp_buff_shrink_data_zc(), xdp_buff_shrink_data() and
xdp_frags_shrink_tail().
Add xdp_buff_shrink_tail(), which handles the linear case too and is
exported with EXPORT_SYMBOL_GPL() for driver use. Unlike
bpf_xdp_adjust_tail(), it takes the number of bytes to remove as a
positive value; bpf_xdp_adjust_tail() keeps its signed offset ABI and
passes -offset for the shrink case. Negative offsets are rejected.
bpf_xdp_pull_data() keeps using the frag helper under its new name.
Behavior for valid offsets is unchanged.
This lets stmmac use the common helper to strip the Ethernet FCS from
the xdp_buff it accumulates for a multi-descriptor frame.
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
---
include/net/xdp.h | 3 ++
net/core/filter.c | 80 +++----------------------------------------------
net/core/xdp.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 96 insertions(+), 76 deletions(-)
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 07231adfb5f8..02289028044c 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -388,6 +388,9 @@ struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,
struct sk_buff *xdp_build_skb_from_frame(struct xdp_frame *xdpf,
struct net_device *dev);
struct xdp_frame *xdpf_clone(struct xdp_frame *xdpf);
+int xdp_buff_shrink_tail(struct xdp_buff *xdp, int offset);
+bool xdp_buff_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,
+ int shrink, bool tail);
static inline
void xdp_convert_frame_to_buff(const struct xdp_frame *frame,
diff --git a/net/core/filter.c b/net/core/filter.c
index 88b8604133da..979a6b452fd2 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4439,88 +4439,16 @@ static int bpf_xdp_frags_increase_tail(struct xdp_buff *xdp, int offset)
return 0;
}
-static struct xdp_buff *bpf_xdp_shrink_data_zc(struct xdp_buff *xdp, int shrink,
- bool tail, bool release)
-{
- struct xdp_buff *zc_frag = tail ? xsk_buff_get_tail(xdp) :
- xsk_buff_get_head(xdp);
-
- if (release) {
- xsk_buff_del_frag(zc_frag);
- } else {
- if (tail)
- zc_frag->data_end -= shrink;
- else
- zc_frag->data += shrink;
- }
-
- return zc_frag;
-}
-
-static bool bpf_xdp_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,
- int shrink, bool tail)
-{
- enum xdp_mem_type mem_type = xdp->rxq->mem.type;
- bool release = skb_frag_size(frag) == shrink;
- netmem_ref netmem = skb_frag_netmem(frag);
- struct xdp_buff *zc_frag = NULL;
-
- if (mem_type == MEM_TYPE_XSK_BUFF_POOL) {
- netmem = 0;
- zc_frag = bpf_xdp_shrink_data_zc(xdp, shrink, tail, release);
- }
-
- if (release) {
- __xdp_return(netmem, mem_type, false, zc_frag);
- } else {
- if (!tail)
- skb_frag_off_add(frag, shrink);
- skb_frag_size_sub(frag, shrink);
- }
-
- return release;
-}
-
-static int bpf_xdp_frags_shrink_tail(struct xdp_buff *xdp, int offset)
-{
- struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
- int i, n_frags_free = 0, len_free = 0;
-
- if (unlikely(offset > (int)xdp_get_buff_len(xdp) - ETH_HLEN))
- return -EINVAL;
-
- for (i = sinfo->nr_frags - 1; i >= 0 && offset > 0; i--) {
- skb_frag_t *frag = &sinfo->frags[i];
- int shrink = min_t(int, offset, skb_frag_size(frag));
-
- len_free += shrink;
- offset -= shrink;
- if (bpf_xdp_shrink_data(xdp, frag, shrink, true))
- n_frags_free++;
- }
- sinfo->nr_frags -= n_frags_free;
- sinfo->xdp_frags_size -= len_free;
-
- if (unlikely(!sinfo->nr_frags)) {
- xdp_buff_clear_frags_flag(xdp);
- xdp_buff_clear_frag_pfmemalloc(xdp);
- xdp->data_end -= offset;
- }
-
- return 0;
-}
-
BPF_CALL_2(bpf_xdp_adjust_tail, struct xdp_buff *, xdp, int, offset)
{
void *data_hard_end = xdp_data_hard_end(xdp); /* use xdp->frame_sz */
void *data_end = xdp->data_end + offset;
- if (unlikely(xdp_buff_has_frags(xdp))) { /* non-linear xdp buff */
- if (offset < 0)
- return bpf_xdp_frags_shrink_tail(xdp, -offset);
+ if (offset < 0)
+ return xdp_buff_shrink_tail(xdp, -offset);
+ if (unlikely(xdp_buff_has_frags(xdp))) /* non-linear xdp buff */
return bpf_xdp_frags_increase_tail(xdp, offset);
- }
/* Notice that xdp_data_hard_end have reserved some tailroom */
if (unlikely(data_end > data_hard_end))
@@ -12851,7 +12779,7 @@ __bpf_kfunc int bpf_xdp_pull_data(struct xdp_md *x, u32 len)
xdp->data_end += shrink;
sinfo->xdp_frags_size -= shrink;
delta -= shrink;
- if (bpf_xdp_shrink_data(xdp, frag, shrink, false))
+ if (xdp_buff_shrink_data(xdp, frag, shrink, false))
n_frags_free++;
}
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 1d679e8fd649..055931263413 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -673,6 +673,95 @@ struct sk_buff *xdp_build_skb_from_buff(const struct xdp_buff *xdp)
}
EXPORT_SYMBOL_GPL(xdp_build_skb_from_buff);
+static struct xdp_buff *xdp_buff_shrink_data_zc(struct xdp_buff *xdp,
+ int shrink, bool tail,
+ bool release)
+{
+ struct xdp_buff *zc_frag = tail ? xsk_buff_get_tail(xdp) :
+ xsk_buff_get_head(xdp);
+
+ if (release) {
+ xsk_buff_del_frag(zc_frag);
+ } else {
+ if (tail)
+ zc_frag->data_end -= shrink;
+ else
+ zc_frag->data += shrink;
+ }
+
+ return zc_frag;
+}
+
+bool xdp_buff_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,
+ int shrink, bool tail)
+{
+ enum xdp_mem_type mem_type = xdp->rxq->mem.type;
+ bool release = skb_frag_size(frag) == shrink;
+ netmem_ref netmem = skb_frag_netmem(frag);
+ struct xdp_buff *zc_frag = NULL;
+
+ if (mem_type == MEM_TYPE_XSK_BUFF_POOL) {
+ netmem = 0;
+ zc_frag = xdp_buff_shrink_data_zc(xdp, shrink, tail, release);
+ }
+
+ if (release) {
+ __xdp_return(netmem, mem_type, false, zc_frag);
+ } else {
+ if (!tail)
+ skb_frag_off_add(frag, shrink);
+ skb_frag_size_sub(frag, shrink);
+ }
+
+ return release;
+}
+
+static int xdp_frags_shrink_tail(struct xdp_buff *xdp, int offset)
+{
+ struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
+ int i, n_frags_free = 0, len_free = 0;
+
+ if (unlikely(offset > (int)xdp_get_buff_len(xdp) - ETH_HLEN))
+ return -EINVAL;
+
+ for (i = sinfo->nr_frags - 1; i >= 0 && offset > 0; i--) {
+ skb_frag_t *frag = &sinfo->frags[i];
+ int shrink = min_t(int, offset, skb_frag_size(frag));
+
+ len_free += shrink;
+ offset -= shrink;
+ if (xdp_buff_shrink_data(xdp, frag, shrink, true))
+ n_frags_free++;
+ }
+ sinfo->nr_frags -= n_frags_free;
+ sinfo->xdp_frags_size -= len_free;
+
+ if (unlikely(!sinfo->nr_frags)) {
+ xdp_buff_clear_frags_flag(xdp);
+ xdp_buff_clear_frag_pfmemalloc(xdp);
+ xdp->data_end -= offset;
+ }
+
+ return 0;
+}
+
+int xdp_buff_shrink_tail(struct xdp_buff *xdp, int offset)
+{
+ if (unlikely(offset < 0))
+ return -EINVAL;
+
+ if (unlikely(xdp_buff_has_frags(xdp))) /* non-linear xdp buff */
+ return xdp_frags_shrink_tail(xdp, offset);
+
+ if (unlikely(offset > xdp->data_end - xdp->data - ETH_HLEN))
+ return -EINVAL;
+
+ xdp->data_end = xdp->data_end - offset;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(xdp_buff_shrink_tail);
+
/**
* xdp_copy_frags_from_zc - copy frags from XSk buff to skb
* @skb: skb to copy frags to
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH net-next v14 4/5] net: xdp: add __xdp_return_buff() helper
2026-12-04 10:44 [PATCH net-next v14 0/5] net: stmmac: introduce XDP rx multi-buff support Lorenzo Bianconi
` (2 preceding siblings ...)
2026-12-04 10:44 ` [PATCH net-next v14 3/5] net: xdp: add xdp_buff_shrink_tail() helper Lorenzo Bianconi
@ 2026-12-04 10:44 ` Lorenzo Bianconi
2026-12-04 10:44 ` [PATCH net-next v14 5/5] net: stmmac: rework stmmac_rx to support XDP rx multi-buff Lorenzo Bianconi
4 siblings, 0 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2026-12-04 10:44 UTC (permalink / raw)
To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Jose Abreu, Ong Boon Leong,
Simon Horman, Andrii Nakryiko, Eduard Zingerman,
Kumar Kartikeya Dwivedi, Martin KaFai Lau, Song Liu,
Yonghong Song, Jiri Olsa, Emil Tsalapatis, Ihor Solodrai,
Matthew Gerlach, Boon Khai Ng, Russell King, Willem de Bruijn
Cc: netdev, linux-arm-kernel, bpf, Lorenzo Bianconi
xdp_return_buff() always releases the fragments and the head with
napi_direct = true, which is only valid when the caller runs in the NAPI
context that owns the page pool. Drivers also need to release an
xdp_buff while tearing down or resetting a queue, where NAPI is not
running and direct recycling must be disabled.
Split the implementation into __xdp_return_buff(), which takes the
napi_direct argument and is exported for drivers, and keep
xdp_return_buff() as an inline wrapper that passes true, preserving the
behavior of the existing callers.
This lets stmmac use the common helper with napi_direct = false on the
teardown paths.
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
---
include/net/xdp.h | 7 ++++++-
net/core/xdp.c | 9 +++++----
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 02289028044c..f0946500c487 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -457,7 +457,12 @@ void __xdp_return(netmem_ref netmem, enum xdp_mem_type mem_type,
bool napi_direct, struct xdp_buff *xdp);
void xdp_return_frame(struct xdp_frame *xdpf);
void xdp_return_frame_rx_napi(struct xdp_frame *xdpf);
-void xdp_return_buff(struct xdp_buff *xdp);
+void __xdp_return_buff(struct xdp_buff *xdp, bool napi_direct);
+static inline void xdp_return_buff(struct xdp_buff *xdp)
+{
+ __xdp_return_buff(xdp, true);
+}
+
void xdp_return_frame_bulk(struct xdp_frame *xdpf,
struct xdp_frame_bulk *bq);
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 055931263413..f35ae7e118f5 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -546,7 +546,7 @@ void xdp_return_frag(netmem_ref netmem, const struct xdp_buff *xdp)
}
EXPORT_SYMBOL_GPL(xdp_return_frag);
-void xdp_return_buff(struct xdp_buff *xdp)
+void __xdp_return_buff(struct xdp_buff *xdp, bool napi_direct)
{
struct skb_shared_info *sinfo;
@@ -556,12 +556,13 @@ void xdp_return_buff(struct xdp_buff *xdp)
sinfo = xdp_get_shared_info_from_buff(xdp);
for (u32 i = 0; i < sinfo->nr_frags; i++)
__xdp_return(skb_frag_netmem(&sinfo->frags[i]),
- xdp->rxq->mem.type, true, xdp);
+ xdp->rxq->mem.type, napi_direct, xdp);
out:
- __xdp_return(virt_to_netmem(xdp->data), xdp->rxq->mem.type, true, xdp);
+ __xdp_return(virt_to_netmem(xdp->data), xdp->rxq->mem.type,
+ napi_direct, xdp);
}
-EXPORT_SYMBOL_GPL(xdp_return_buff);
+EXPORT_SYMBOL_GPL(__xdp_return_buff);
void xdp_attachment_setup(struct xdp_attachment_info *info,
struct netdev_bpf *bpf)
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH net-next v14 5/5] net: stmmac: rework stmmac_rx to support XDP rx multi-buff
2026-12-04 10:44 [PATCH net-next v14 0/5] net: stmmac: introduce XDP rx multi-buff support Lorenzo Bianconi
` (3 preceding siblings ...)
2026-12-04 10:44 ` [PATCH net-next v14 4/5] net: xdp: add __xdp_return_buff() helper Lorenzo Bianconi
@ 2026-12-04 10:44 ` Lorenzo Bianconi
2026-12-05 10:45 ` sashiko-bot
2026-12-05 10:51 ` netdev-bot+sashiko
4 siblings, 2 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2026-12-04 10:44 UTC (permalink / raw)
To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Jose Abreu, Ong Boon Leong,
Simon Horman, Andrii Nakryiko, Eduard Zingerman,
Kumar Kartikeya Dwivedi, Martin KaFai Lau, Song Liu,
Yonghong Song, Jiri Olsa, Emil Tsalapatis, Ihor Solodrai,
Matthew Gerlach, Boon Khai Ng, Russell King, Willem de Bruijn
Cc: netdev, linux-arm-kernel, bpf, Nicolai Buchwitz, Lorenzo Bianconi
An earlier commit dropped frames split across multiple descriptors, or
using a second buffer, while XDP was enabled. This prevented the
per-descriptor XDP path from re-parsing frame tails and from applying FCS
handling to truncated buffers.
Rework stmmac_rx() to accumulate all the descriptors that make up a frame
in an xdp_buff, so the XDP program runs on the full (possibly fragmented)
packet instead of just the first buffer. Frames split across descriptors
or buffers are now passed to programs loaded with BPF_F_XDP_HAS_FRAGS;
programs without that capability continue to drop fragmented frames. When
the frame is not consumed by the program, assemble the skb from the head
buffer and the collected fragments with xdp_build_skb_from_buff().
Note that XDP still rejects an MTU larger than ETH_DATA_LEN
(stmmac_xdp_set_prog(), stmmac_change_mtu()) and disables SPH, so an
ordinary frame fits in a single buffer. This path is therefore exercised
by frames that do span several descriptors (for example jumbo frames the
MAC admits through its jumbo-enable bit) and is groundwork for extending
XDP to jumbo/SPH; it does not enable XDP jumbo support by itself.
For the same reason, NETDEV_XDP_ACT_RX_SG is not advertised yet, so
userspace does not attempt multi-buffer XDP setups that the MTU and
program checks above would reject.
To do so, store the in-progress xdp_buff in rx_q->state instead of the
partially built skb, so the accumulated head and fragments survive a NAPI
poll boundary (mid-frame dma_own or dirty_rx break). The state is saved
only while a frame is in progress and cleared once it completes, leaving
it untouched when the poll does not process anything (e.g. netpoll invoked
with a zero budget).
In addition:
- register the xdp_rxq with the fragment allocation size, so
bpf_xdp_adjust_tail() can grow the tail of fragmented frames;
- build the skb with xdp_build_skb_from_buff(), which passes
xdp->frame_sz to napi_build_skb(), so skb_shinfo() lands on the same
shared_info the fragments were accumulated into. xdp->frame_sz is the
page_pool order-N allocation size (PAGE_SIZE << order, with
order_base_2() rounding num_pages up), so the head truesize grows from
num_pages * PAGE_SIZE: on 4K pages 12K -> 16K for an 8K buffer and
20K -> 32K for a 16K buffer. This is more accurate but also affects
non-XDP traffic and reduces the effective socket receive buffer for
jumbo MTU users;
- carry the XDP metadata written with bpf_xdp_adjust_meta() into the skb
from the accumulated xdp_buff via skb_metadata_set(), preserving the
existing linear PASS path behavior and extending it to fragmented frames,
so TC/BPF programs can read it through data_meta;
- attach fragments with xdp_buff_add_frag(), which initializes all the
shared_info fields and takes care of the pfmemalloc bit;
- charge fragments the whole page_pool page size (xdp->frame_sz) as
truesize instead of the old dma_buf_sz; with SPH/buf2 most frames carry
a fragment, so skb->truesize grows by roughly 1.5x on 4K pages and 2x on
64K pages, which reduces the effective socket receive buffer. The new
value is more accurate now that a fragment is a full page_pool page, but
it is a behavior change;
- release the buffers collected in the xdp_buff with __xdp_return_buff()
when a frame is dropped on RX errors, instead of relying on
dev_kfree_skb() recycling the skb frags; the latter no longer applies
now that the head and fragments live in an xdp_buff rather than a
partially built skb;
- drop the whole frame when it would exceed MAX_SKB_FRAGS, where the
previous skb_add_rx_frag() calls were unbounded;
- strip the Ethernet FCS from the accumulated xdp_buff with the common
xdp_buff_shrink_tail() helper for both linear and fragmented frames,
instead of trimming the skb or the first descriptor length.
Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
---
drivers/net/ethernet/stmicro/stmmac/stmmac.h | 3 +-
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 230 ++++++++++------------
2 files changed, 108 insertions(+), 125 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index fa9ef4212982..d77e442249ab 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -133,7 +133,8 @@ struct stmmac_rx_queue {
dma_addr_t dma_rx_phy;
unsigned int state_saved;
struct {
- struct sk_buff *skb;
+ struct xdp_buff xdp;
+ unsigned int n_descs;
unsigned int len;
unsigned int error;
} state;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index c429cb9e1ccb..0edc92d5fb30 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -2195,8 +2195,10 @@ static void __free_dma_rx_desc_resources(struct stmmac_priv *priv,
else
dma_free_rx_skbufs(priv, dma_conf, queue);
- dev_kfree_skb_any(rx_q->state.skb);
- rx_q->state.skb = NULL;
+ if (rx_q->state.n_descs && !rx_q->xsk_pool) {
+ __xdp_return_buff(&rx_q->state.xdp, false);
+ rx_q->state.n_descs = 0;
+ }
rx_q->state_saved = false;
rx_q->buf_alloc_num = 0;
rx_q->xsk_pool = NULL;
@@ -2316,10 +2318,6 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
num_pages = DIV_ROUND_UP(dma_buf_sz_pad, PAGE_SIZE);
- rx_q->queue_index = queue;
- rx_q->priv_data = priv;
- rx_q->napi_skb_frag_size = num_pages * PAGE_SIZE;
-
pp_params.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV;
pp_params.pool_size = dma_conf->dma_rx_size;
pp_params.order = order_base_2(num_pages);
@@ -2351,6 +2349,10 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
goto err_free_buf_pool;
}
+ rx_q->queue_index = queue;
+ rx_q->priv_data = priv;
+ rx_q->napi_skb_frag_size = PAGE_SIZE << pp_params.order;
+
if (priv->extend_desc)
rx_q->dma_erx = addr;
else
@@ -2362,7 +2364,8 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
else
napi_id = ch->rx_napi.napi_id;
- ret = xdp_rxq_info_reg(&rx_q->xdp_rxq, priv->dev, queue, napi_id);
+ ret = __xdp_rxq_info_reg(&rx_q->xdp_rxq, priv->dev, queue, napi_id,
+ rx_q->napi_skb_frag_size);
if (ret) {
netdev_err(priv->dev, "Failed to register xdp rxq info\n");
goto err_free_dma;
@@ -5540,8 +5543,8 @@ static int __stmmac_xdp_run_prog(struct stmmac_priv *priv,
static struct sk_buff *stmmac_xdp_run_prog(struct stmmac_priv *priv,
struct xdp_buff *xdp)
{
+ int res = STMMAC_XDP_CONSUMED;
struct bpf_prog *prog;
- int res;
prog = READ_ONCE(priv->xdp_prog);
if (!prog) {
@@ -5549,7 +5552,8 @@ static struct sk_buff *stmmac_xdp_run_prog(struct stmmac_priv *priv,
goto out;
}
- res = __stmmac_xdp_run_prog(priv, prog, xdp);
+ if (likely(!xdp_buff_has_frags(xdp) || prog->aux->xdp_has_frags))
+ res = __stmmac_xdp_run_prog(priv, prog, xdp);
out:
return ERR_PTR(-res);
}
@@ -5879,6 +5883,25 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
return failure ? limit : (int)count;
}
+static bool stmmac_build_xdp_frags(struct stmmac_priv *priv,
+ struct stmmac_rx_queue *rx_q,
+ unsigned int len, struct page *page,
+ unsigned int offset,
+ enum dma_data_direction dma_dir,
+ struct xdp_buff *xdp)
+{
+ dma_addr_t dma_addr = page_pool_get_dma_addr(page) + offset;
+
+ dma_sync_single_for_cpu(priv->device, dma_addr, len, dma_dir);
+ if (!xdp_buff_add_frag(xdp, page_to_netmem(page), offset, len,
+ xdp->frame_sz)) {
+ page_pool_put_full_page(rx_q->page_pool, page, true);
+ return false;
+ }
+
+ return true;
+}
+
/**
* stmmac_rx - manage the receive process
* @priv: driver private structure
@@ -5892,21 +5915,20 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
u32 rx_errors = 0, rx_dropped = 0, rx_bytes = 0, rx_packets = 0;
struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[queue];
struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
+ unsigned int n_descs = 0, next_entry = rx_q->cur_rx;
struct stmmac_channel *ch = &priv->channel[queue];
unsigned int count = 0, error = 0, len = 0;
- unsigned int next_entry = rx_q->cur_rx;
bool in_progress = rx_q->state_saved;
enum dma_data_direction dma_dir;
int coe = priv->hw->rx_csum;
- unsigned int desc_size;
- struct sk_buff *skb = NULL;
struct stmmac_xdp_buff ctx;
- bool fcs_stripped = false;
+ unsigned int desc_size;
int xdp_status = 0;
int bufsz;
dma_dir = page_pool_get_dma_dir(rx_q->page_pool);
- bufsz = DIV_ROUND_UP(priv->dma_conf.dma_buf_sz, PAGE_SIZE) * PAGE_SIZE;
+ bufsz = rx_q->napi_skb_frag_size;
+ ctx.priv = priv;
if (netif_msg_rx_status(priv)) {
void *rx_head = stmmac_get_rx_desc(priv, rx_q, 0);
@@ -5919,11 +5941,12 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
}
if (rx_q->state_saved) {
- skb = rx_q->state.skb;
+ ctx.xdp = rx_q->state.xdp;
error = rx_q->state.error;
+ n_descs = rx_q->state.n_descs;
len = rx_q->state.len;
- rx_q->state.skb = NULL;
rx_q->state_saved = false;
+ rx_q->state.n_descs = 0;
}
while (count < limit) {
@@ -5931,11 +5954,11 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
enum pkt_hash_types hash_type;
struct stmmac_rx_buffer *buf;
struct dma_desc *np, *p;
+ struct sk_buff *skb;
int entry, status;
u32 hash;
if (!in_progress) {
- skb = NULL;
error = 0;
len = 0;
}
@@ -5983,19 +6006,11 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
rx_errors++;
}
- /* We do not support SG in XDP mode */
- if (unlikely(!error && (status & rx_not_ls) &&
- stmmac_xdp_is_enabled(priv))) {
- rx_dropped++;
- error = 1;
- }
-
if (unlikely(error)) {
if (status & rx_not_ls)
goto read_again;
- dev_kfree_skb(skb);
- goto next;
+ goto error_free_frag;
}
/* Buffer is good. Go on. */
@@ -6005,120 +6020,79 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
buf2_len = stmmac_rx_buf2_len(priv, p, status, len);
len += buf2_len;
- /* Drop the packet if it is split over buf1 and buf2 on a
- * single descriptor if the interface is running in XDP mode.
- */
- if (unlikely(stmmac_xdp_is_enabled(priv) && buf2_len)) {
- rx_dropped++;
- goto next;
- }
-
- /* ACS is disabled; strip manually. */
- if (likely(!(status & rx_not_ls)))
- len -= ETH_FCS_LEN;
-
- if (!skb) {
- /* Each frame starts here: reset the FCS handling */
- fcs_stripped = false;
-
+ if (!n_descs) {
dma_sync_single_for_cpu(priv->device, buf->addr,
buf1_len, dma_dir);
net_prefetch(page_address(buf->page) +
buf->page_offset);
- if (stmmac_xdp_is_enabled(priv) && !buf2_len) {
- buf1_len -= ETH_FCS_LEN;
- fcs_stripped = true;
- }
-
xdp_init_buff(&ctx.xdp, bufsz, &rx_q->xdp_rxq);
xdp_prepare_buff(&ctx.xdp, page_address(buf->page),
buf->page_offset, buf1_len, true);
-
- ctx.priv = priv;
- ctx.desc = p;
- ctx.ndesc = np;
-
- skb = stmmac_xdp_run_prog(priv, &ctx.xdp);
- /* For Not XDP_PASS verdict */
- if (IS_ERR(skb)) {
- unsigned int xdp_res = -PTR_ERR(skb);
-
- if (xdp_res & STMMAC_XDP_CONSUMED) {
- page_pool_recycle_direct(rx_q->page_pool,
- virt_to_head_page(ctx.xdp.data));
- buf->page = NULL;
+ buf->page = NULL;
+ } else if (buf1_len) {
+ if (!stmmac_build_xdp_frags(priv, rx_q, buf1_len,
+ buf->page,
+ buf->page_offset,
+ dma_dir, &ctx.xdp)) {
+ if (!error)
rx_dropped++;
- goto next;
- } else if (xdp_res & (STMMAC_XDP_TX |
- STMMAC_XDP_REDIRECT)) {
- xdp_status |= xdp_res;
- buf->page = NULL;
- goto next;
- }
- }
- }
-
- if (!skb) {
- unsigned int metasize;
-
- /* XDP program may expand or reduce tail */
- buf1_len = ctx.xdp.data_end - ctx.xdp.data;
-
- skb = napi_build_skb(page_address(buf->page),
- rx_q->napi_skb_frag_size);
- if (!skb) {
- page_pool_recycle_direct(rx_q->page_pool,
- buf->page);
- buf->page = NULL;
- rx_dropped++;
error = 1;
- goto drain_data;
}
-
- /* XDP program may adjust header */
- skb_reserve(skb,
- ctx.xdp.data - ctx.xdp.data_hard_start);
- skb_put(skb, buf1_len);
- skb_mark_for_recycle(skb);
-
- metasize = ctx.xdp.data - ctx.xdp.data_meta;
- if (metasize)
- skb_metadata_set(skb, metasize);
- buf->page = NULL;
- } else if (buf1_len) {
- dma_sync_single_for_cpu(priv->device, buf->addr,
- buf1_len, dma_dir);
- skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
- buf->page, buf->page_offset, buf1_len,
- priv->dma_conf.dma_buf_sz);
buf->page = NULL;
}
if (buf2_len) {
- dma_sync_single_for_cpu(priv->device, buf->sec_addr,
- buf2_len, dma_dir);
- skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
- buf->sec_page, 0, buf2_len,
- priv->dma_conf.dma_buf_sz);
+ if (!stmmac_build_xdp_frags(priv, rx_q, buf2_len,
+ buf->sec_page, 0,
+ dma_dir, &ctx.xdp)) {
+ if (!error)
+ rx_dropped++;
+ error = 1;
+ }
buf->sec_page = NULL;
}
+ n_descs++;
-drain_data:
if (likely(status & rx_not_ls))
goto read_again;
- if (!skb)
- goto next;
- /* Got entire packet into SKB. Finish it. */
+ /* ACS is disabled; strip manually. */
+ len -= ETH_FCS_LEN;
+ if (xdp_buff_shrink_tail(&ctx.xdp, ETH_FCS_LEN)) {
+ if (!error)
+ rx_dropped++;
+ error = 1;
+ }
- /* Remove FCS if needed */
- if (!fcs_stripped && pskb_trim(skb, len)) {
- dev_kfree_skb_any(skb);
- rx_dropped++;
+ if (unlikely(error))
+ goto error_free_frag;
+
+ ctx.desc = p;
+ ctx.ndesc = np;
+
+ skb = stmmac_xdp_run_prog(priv, &ctx.xdp);
+ /* For Not XDP_PASS verdict */
+ if (IS_ERR(skb)) {
+ unsigned int xdp_res = -PTR_ERR(skb);
+
+ if (xdp_res & STMMAC_XDP_CONSUMED) {
+ __xdp_return_buff(&ctx.xdp, true);
+ rx_dropped++;
+ } else if (xdp_res & (STMMAC_XDP_TX |
+ STMMAC_XDP_REDIRECT)) {
+ xdp_status |= xdp_res;
+ }
goto next;
}
+ skb = xdp_build_skb_from_buff(&ctx.xdp);
+ if (!skb) {
+ rx_dropped++;
+ goto error_free_frag;
+ }
+
+ /* Got entire packet into SKB. Finish it. */
stmmac_get_rx_hwtstamp(priv, p, np, skb);
if (priv->hw->hw_vlan_en) {
@@ -6126,8 +6100,6 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
stmmac_rx_hw_vlan(priv, priv->hw, p, skb);
}
- skb->protocol = eth_type_trans(skb, priv->dev);
-
if (unlikely(!coe) ||
!stmmac_has_ip_ethertype(priv, skb, false) ||
(status & csum_none))
@@ -6138,21 +6110,28 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
if (!stmmac_get_rx_hash(priv, p, &hash, &hash_type))
skb_set_hash(skb, hash, hash_type);
- skb_record_rx_queue(skb, queue);
napi_gro_receive(&ch->rx_napi, skb);
rx_packets++;
rx_bytes += len;
next:
in_progress = false;
- skb = NULL;
+ n_descs = 0;
+ count++;
+ continue;
+error_free_frag:
+ if (n_descs)
+ __xdp_return_buff(&ctx.xdp, true);
+ in_progress = false;
+ n_descs = 0;
count++;
}
- if (in_progress || skb) {
- rx_q->state_saved = true;
- rx_q->state.skb = skb;
+ if (in_progress || n_descs) {
+ rx_q->state.xdp = ctx.xdp;
+ rx_q->state.n_descs = n_descs;
rx_q->state.error = error;
rx_q->state.len = len;
+ rx_q->state_saved = true;
}
stmmac_finalize_xdp_rx(priv, xdp_status);
@@ -8524,9 +8503,12 @@ static void stmmac_reset_rx_queue(struct stmmac_priv *priv, u32 queue)
{
struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
- dev_kfree_skb_any(rx_q->state.skb);
- rx_q->state.skb = NULL;
+ if (rx_q->state.n_descs && !rx_q->xsk_pool) {
+ __xdp_return_buff(&rx_q->state.xdp, false);
+ rx_q->state.n_descs = 0;
+ }
rx_q->state_saved = false;
+
rx_q->cur_rx = 0;
rx_q->dirty_rx = 0;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH net-next v14 5/5] net: stmmac: rework stmmac_rx to support XDP rx multi-buff
2026-12-04 10:44 ` [PATCH net-next v14 5/5] net: stmmac: rework stmmac_rx to support XDP rx multi-buff Lorenzo Bianconi
@ 2026-12-05 10:45 ` sashiko-bot
2026-12-05 10:51 ` netdev-bot+sashiko
1 sibling, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-05 10:45 UTC (permalink / raw)
To: Lorenzo Bianconi; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] net: stmmac: stmmac_rx() copies uninitialized ctx.xdp to
state.xdp
- [Low] net: stmmac: stale xdp_frags_truesize after
xdp_buff_shrink_tail()
--
commit 60febdab2a5f659e2de10ff9559c6cfd968ef63a
Author: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
net: stmmac: rework stmmac_rx to support XDP rx multi-buff
This commit reworks stmmac_rx() to accumulate multi-descriptor and
second-buffer frames into an xdp_buff before running the XDP program and
building the skb with xdp_build_skb_from_buff(). It also stores the
in-progress xdp_buff in rx_q->state across NAPI poll boundaries.
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index c429cb9e1ccbe..0edc92d5fb306 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
[ ... ]
> @@ -5879,6 +5883,25 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
> return failure ? limit : (int)count;
> }
>
> +static bool stmmac_build_xdp_frags(struct stmmac_priv *priv,
> + struct stmmac_rx_queue *rx_q,
> + unsigned int len, struct page *page,
> + unsigned int offset,
> + enum dma_data_direction dma_dir,
> + struct xdp_buff *xdp)
> +{
> + dma_addr_t dma_addr = page_pool_get_dma_addr(page) + offset;
> +
> + dma_sync_single_for_cpu(priv->device, dma_addr, len, dma_dir);
> + if (!xdp_buff_add_frag(xdp, page_to_netmem(page), offset, len,
> + xdp->frame_sz)) {
> + page_pool_put_full_page(rx_q->page_pool, page, true);
> + return false;
> + }
> +
> + return true;
> +}
[Severity: Low]
Can passing xdp->frame_sz to xdp_buff_add_frag() leave skb->truesize
overstated after FCS stripping?
xdp_buff_add_frag() accumulates xdp->frame_sz into sinfo->xdp_frags_truesize
for every attached fragment. When a frame with two or more fragments has 1
to 4 trailing FCS bytes in its final fragment, stmmac_rx() calls
xdp_buff_shrink_tail(&ctx.xdp, ETH_FCS_LEN) -> xdp_frags_shrink_tail(),
which frees that fragment and updates sinfo->nr_frags and
sinfo->xdp_frags_size, but leaves sinfo->xdp_frags_truesize unchanged.
xdp_build_skb_from_buff() then prefers the stale non-zero
sinfo->xdp_frags_truesize over nr_frags * xdp->frame_sz, overcharging
skb->truesize by a full xdp->frame_sz allocation and slightly reducing
effective socket receive buffer accounting. Passing 0 for truesize here
would let xdp_build_skb_from_buff() compute nr_frags * xdp->frame_sz from
the post-shrink fragment count, or xdp_frags_shrink_tail() could adjust
sinfo->xdp_frags_truesize.
[ ... ]
> @@ -6138,21 +6110,28 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
> if (!stmmac_get_rx_hash(priv, p, &hash, &hash_type))
> skb_set_hash(skb, hash, hash_type);
>
> - skb_record_rx_queue(skb, queue);
> napi_gro_receive(&ch->rx_napi, skb);
> rx_packets++;
> rx_bytes += len;
> next:
> in_progress = false;
> - skb = NULL;
> + n_descs = 0;
> + count++;
> + continue;
> +error_free_frag:
> + if (n_descs)
> + __xdp_return_buff(&ctx.xdp, true);
> + in_progress = false;
> + n_descs = 0;
> count++;
> }
>
> - if (in_progress || skb) {
> - rx_q->state_saved = true;
> - rx_q->state.skb = skb;
> + if (in_progress || n_descs) {
> + rx_q->state.xdp = ctx.xdp;
> + rx_q->state.n_descs = n_descs;
> rx_q->state.error = error;
> rx_q->state.len = len;
> + rx_q->state_saved = true;
> }
[Severity: Low]
Can this copy uninitialized stack memory from ctx.xdp into rx_q->state.xdp?
ctx is declared uninitialized on the stack in stmmac_rx(). On cores using
enh_desc_get_rx_status() or ndesc_get_rx_status(), a first descriptor
without RDES0_LAST_DESCRIPTOR returns discard_frame | rx_not_ls, so
stmmac_rx() sets in_progress and error and jumps to read_again without
initializing ctx.xdp, leaving n_descs at 0. If the next descriptor is still
owned by DMA and the loop breaks, rx_q->state.xdp = ctx.xdp copies the
uninitialized struct (and the next poll copies it back).
Even when n_descs is non-zero, xdp_init_buff() and xdp_prepare_buff() leave
ctx.xdp.txq uninitialized, so copying ctx.xdp by value still reads an
uninitialized field. This can trigger KMSAN uninit-value reports or
-Wmaybe-uninitialized warnings. Guarding the xdp save and restore with
n_descs and zero-initializing ctx (or ctx.xdp.txq) would avoid both.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-stmmac-rx-mb-v14-0-5506796fd39e@oss.qualcomm.com?part=5
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH net-next v14 5/5] net: stmmac: rework stmmac_rx to support XDP rx multi-buff
2026-12-04 10:44 ` [PATCH net-next v14 5/5] net: stmmac: rework stmmac_rx to support XDP rx multi-buff Lorenzo Bianconi
2026-12-05 10:45 ` sashiko-bot
@ 2026-12-05 10:51 ` netdev-bot+sashiko
1 sibling, 0 replies; 11+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 10:51 UTC (permalink / raw)
To: lorenzo.bianconi
Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
mcoquelin.stm32, alexandre.torgue, ast, daniel, hawk,
john.fastabend, sdf, Jose.Abreu, boon.leong.ong, horms, andrii,
eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil,
ihor.solodrai, matthew.gerlach, boon.khai.ng, linux, willemb,
netdev, linux-arm-kernel, bpf, nb
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 (1) · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] TX descriptor buffer-length field overflow on XDP_TX of a
tail-grown fragment.
- [Low] net: stmmac: stale xdp_frags_truesize after
xdp_buff_shrink_tail()
Pre-existing issues:
- [High] Concurrent lockless page_pool direct recycling from a different
NAPI context.
--
net: stmmac: rework stmmac_rx to support XDP rx multi-buff
This commit reworks stmmac_rx() to collect every descriptor of a frame
in an xdp_buff kept in rx_q->state, so the XDP program sees the whole
frame, including any fragments. Fragmented frames only go to programs
loaded with BPF_F_XDP_HAS_FRAGS, and the skb is built with
xdp_build_skb_from_buff(). The xdp_rxq is now registered with the
page_pool page size as frag_size, so bpf_xdp_adjust_tail() can grow
fragments.
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index c429cb9e1ccbe..0edc92d5fb306 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
[ ... ]
> @@ -2351,6 +2349,10 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
> goto err_free_buf_pool;
> }
>
> + rx_q->queue_index = queue;
> + rx_q->priv_data = priv;
> + rx_q->napi_skb_frag_size = PAGE_SIZE << pp_params.order;
> +
> if (priv->extend_desc)
> rx_q->dma_erx = addr;
> else
> @@ -2362,7 +2364,8 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
> else
> napi_id = ch->rx_napi.napi_id;
>
> - ret = xdp_rxq_info_reg(&rx_q->xdp_rxq, priv->dev, queue, napi_id);
> + ret = __xdp_rxq_info_reg(&rx_q->xdp_rxq, priv->dev, queue, napi_id,
> + rx_q->napi_skb_frag_size);
[Severity: Medium]
Registering a frag_size here turns on bpf_xdp_frags_increase_tail() for
this rxq. Can a frags-capable program now grow a fragment beyond what a
single TX descriptor can describe?
stmmac_rx() attaches the buf2 payload as a fragment at offset 0:
if (!stmmac_build_xdp_frags(priv, rx_q, buf2_len,
buf->sec_page, 0,
dma_dir, &ctx.xdp)) {
This happens on any core with buf2 capability (GMAC4/XGMAC), not only
with SPH. GMAC4 also sets GMAC_CONFIG_JE, so frames longer than
dma_buf_sz can use buf2 or several descriptors even at MTU 1500.
With frag_size equal to PAGE_SIZE << order, bpf_xdp_adjust_tail() can
grow the last fragment to the full page_pool page. That is 16384 bytes
on 16K-page kernels and up to about 64K on 64K-page kernels.
If the program then returns XDP_TX, stmmac_xdp_xmit_xdpf() puts each
fragment into one descriptor and never checks the length:
int len = frag ? skb_frag_size(frag) : xdpf->len;
...
stmmac_prepare_tx_desc(priv, desc, !i, len, false, ...
The descriptor helpers then mask the length to 14 bits:
dwmac4_rd_prepare_tx_desc():
p->des2 |= cpu_to_le32(len & TDES2_BUFFER1_SIZE_MASK);
dwxgmac2_prepare_tx_desc():
p->des2 |= cpu_to_le32(len & XGMAC_TDES2_B1L);
Wouldn't a 16384-byte fragment be programmed as a 0-byte buffer, and
larger ones wrap modulo 16K? The descriptor would then disagree with the
mapped length and with the total frame length in TDES3. That could put
truncated or malformed frames on the wire, or cause TX DMA errors.
On 64K-page kernels the linear head could already hit this before this
patch. The fragment case is new.
Should frag_size be capped, or should stmmac_xdp_xmit_xdpf() reject
buffers over the hardware per-buffer limit?
[ ... ]
> @@ -6005,120 +6020,79 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
[ ... ]
> + ctx.desc = p;
> + ctx.ndesc = np;
> +
> + skb = stmmac_xdp_run_prog(priv, &ctx.xdp);
> + /* For Not XDP_PASS verdict */
> + if (IS_ERR(skb)) {
> + unsigned int xdp_res = -PTR_ERR(skb);
> +
> + if (xdp_res & STMMAC_XDP_CONSUMED) {
> + __xdp_return_buff(&ctx.xdp, true);
> + rx_dropped++;
> + } else if (xdp_res & (STMMAC_XDP_TX |
> + STMMAC_XDP_REDIRECT)) {
> + xdp_status |= xdp_res;
> + }
> goto next;
> }
[Severity: High]
This isn't a bug introduced by this patch. However, now that multi-buffer
frames can reach XDP_TX, the patch seems to make an existing page_pool
race worse.
When an XDP_TX frame completes, stmmac_tx_clean() frees it with direct
recycling:
if (xdpf &&
tx_q->tx_skbuff_dma[entry].buf_type == STMMAC_TXBUF_T_XDP_TX) {
xdp_return_frame_rx_napi(xdpf);
tx_q->xdpf[entry] = NULL;
}
This reaches the lockless alloc cache with allow_direct=true:
xdp_return_frame_rx_napi()
__xdp_return(..., napi_direct=true)
page_pool_put_full_netmem(pool, netmem, true)
page_pool_put_unrefed_netmem()
__page_pool_put_page()
page_pool_recycle_in_cache()
stmmac_tx_clean() runs from the TX NAPI (tx_napi or rxtx_napi) of the
queue that stmmac_xdp_xmit_back() picks:
queue = stmmac_xdp_get_tx_queue(priv, cpu);
That queue is cpu % tx_queues, so it need not be the RX queue that owns
the page_pool. Even when the queue matches, tx_napi and rx_napi are
separate napi_structs and do not exclude each other.
At the same time, the owning RX NAPI can run on another CPU. It pops
from the same alloc cache in stmmac_rx_refill(). It also pushes to it
through __xdp_return_buff(&ctx.xdp, true) and
page_pool_put_full_page(..., true). Those RX paths do not take the
netdev TX queue lock that stmmac_tx_clean() holds.
Can interleaved updates of pool->alloc.count and pool->alloc.cache[]
give the same page to two RX descriptors, or lose a page? This looks
reachable with per-channel MSI RX/TX IRQs on different CPUs, with the TX
coalesce hrtimer, or with threaded NAPI.
With this patch, each XDP_TX completion now returns 1 + nr_frags pages
through that path instead of a single page.
[ ... ]
> @@ -6005,120 +6020,79 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
> buf2_len = stmmac_rx_buf2_len(priv, p, status, len);
> len += buf2_len;
>
> - /* Drop the packet if it is split over buf1 and buf2 on a
> - * single descriptor if the interface is running in XDP mode.
> - */
> - if (unlikely(stmmac_xdp_is_enabled(priv) && buf2_len)) {
> - rx_dropped++;
> - goto next;
> - }
> -
> - /* ACS is disabled; strip manually. */
> - if (likely(!(status & rx_not_ls)))
> - len -= ETH_FCS_LEN;
> -
> - if (!skb) {
> - /* Each frame starts here: reset the FCS handling */
> - fcs_stripped = false;
> -
> + if (!n_descs) {
> dma_sync_single_for_cpu(priv->device, buf->addr,
> buf1_len, dma_dir);
> net_prefetch(page_address(buf->page) +
> buf->page_offset);
>
> - if (stmmac_xdp_is_enabled(priv) && !buf2_len) {
> - buf1_len -= ETH_FCS_LEN;
> - fcs_stripped = true;
> - }
> -
> xdp_init_buff(&ctx.xdp, bufsz, &rx_q->xdp_rxq);
> xdp_prepare_buff(&ctx.xdp, page_address(buf->page),
> buf->page_offset, buf1_len, true);
> -
> - ctx.priv = priv;
> - ctx.desc = p;
> - ctx.ndesc = np;
> -
> - skb = stmmac_xdp_run_prog(priv, &ctx.xdp);
> - /* For Not XDP_PASS verdict */
> - if (IS_ERR(skb)) {
> - unsigned int xdp_res = -PTR_ERR(skb);
> -
> - if (xdp_res & STMMAC_XDP_CONSUMED) {
> - page_pool_recycle_direct(rx_q->page_pool,
> - virt_to_head_page(ctx.xdp.data));
> - buf->page = NULL;
> + buf->page = NULL;
> + } else if (buf1_len) {
> + if (!stmmac_build_xdp_frags(priv, rx_q, buf1_len,
> + buf->page,
> + buf->page_offset,
> + dma_dir, &ctx.xdp)) {
> + if (!error)
> rx_dropped++;
> - goto next;
> - } else if (xdp_res & (STMMAC_XDP_TX |
> - STMMAC_XDP_REDIRECT)) {
> - xdp_status |= xdp_res;
> - buf->page = NULL;
> - goto next;
> - }
> - }
> - }
> -
> - if (!skb) {
> - unsigned int metasize;
> -
> - /* XDP program may expand or reduce tail */
> - buf1_len = ctx.xdp.data_end - ctx.xdp.data;
> -
> - skb = napi_build_skb(page_address(buf->page),
> - rx_q->napi_skb_frag_size);
> - if (!skb) {
> - page_pool_recycle_direct(rx_q->page_pool,
> - buf->page);
> - buf->page = NULL;
> - rx_dropped++;
> error = 1;
> - goto drain_data;
> }
> -
> - /* XDP program may adjust header */
> - skb_reserve(skb,
> - ctx.xdp.data - ctx.xdp.data_hard_start);
> - skb_put(skb, buf1_len);
> - skb_mark_for_recycle(skb);
> -
> - metasize = ctx.xdp.data - ctx.xdp.data_meta;
> - if (metasize)
> - skb_metadata_set(skb, metasize);
> - buf->page = NULL;
> - } else if (buf1_len) {
> - dma_sync_single_for_cpu(priv->device, buf->addr,
> - buf1_len, dma_dir);
> - skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
> - buf->page, buf->page_offset, buf1_len,
> - priv->dma_conf.dma_buf_sz);
> buf->page = NULL;
> }
>
> if (buf2_len) {
> - dma_sync_single_for_cpu(priv->device, buf->sec_addr,
> - buf2_len, dma_dir);
> - skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
> - buf->sec_page, 0, buf2_len,
> - priv->dma_conf.dma_buf_sz);
> + if (!stmmac_build_xdp_frags(priv, rx_q, buf2_len,
> + buf->sec_page, 0,
> + dma_dir, &ctx.xdp)) {
> + if (!error)
> + rx_dropped++;
> + error = 1;
> + }
> buf->sec_page = NULL;
> }
> + n_descs++;
>
> -drain_data:
> if (likely(status & rx_not_ls))
> goto read_again;
> - if (!skb)
> - goto next;
>
> - /* Got entire packet into SKB. Finish it. */
> + /* ACS is disabled; strip manually. */
> + len -= ETH_FCS_LEN;
> + if (xdp_buff_shrink_tail(&ctx.xdp, ETH_FCS_LEN)) {
> + if (!error)
> + rx_dropped++;
> + error = 1;
> + }
>
> - /* Remove FCS if needed */
> - if (!fcs_stripped && pskb_trim(skb, len)) {
> - dev_kfree_skb_any(skb);
> - rx_dropped++;
> + if (unlikely(error))
> + goto error_free_frag;
> +
> + ctx.desc = p;
> + ctx.ndesc = np;
> +
> + skb = stmmac_xdp_run_prog(priv, &ctx.xdp);
> + /* For Not XDP_PASS verdict */
> + if (IS_ERR(skb)) {
> + unsigned int xdp_res = -PTR_ERR(skb);
> +
> + if (xdp_res & STMMAC_XDP_CONSUMED) {
> + __xdp_return_buff(&ctx.xdp, true);
> + rx_dropped++;
> + } else if (xdp_res & (STMMAC_XDP_TX |
> + STMMAC_XDP_REDIRECT)) {
> + xdp_status |= xdp_res;
> + }
> goto next;
> }
>
> + skb = xdp_build_skb_from_buff(&ctx.xdp);
> + if (!skb) {
> + rx_dropped++;
> + goto error_free_frag;
> + }
> +
> + /* Got entire packet into SKB. Finish it. */
> stmmac_get_rx_hwtstamp(priv, p, np, skb);
>
> if (priv->hw->hw_vlan_en) {
[Severity: Low]
Does the FCS strip here leave sinfo->xdp_frags_truesize stale when it
frees a trailing fragment?
stmmac_build_xdp_frags() attaches every fragment with
xdp_buff_add_frag(..., xdp->frame_sz). That makes __xdp_buff_add_frag()
add one full page_pool allocation to sinfo->xdp_frags_truesize for each
fragment.
Sometimes the last buffer of a multi-buffer frame holds only 1 to 4 of
the FCS bytes. In that case xdp_buff_shrink_tail() goes through
xdp_frags_shrink_tail(), which returns that page to the pool and updates
sinfo->nr_frags and sinfo->xdp_frags_size. It never decrements
sinfo->xdp_frags_truesize, though.
If at least one fragment is left, xdp_build_skb_from_buff() then does:
tsize = sinfo->xdp_frags_truesize ? : nr_frags * xdp->frame_sz;
So skb->truesize is overcharged by xdp->frame_sz for a page the skb no
longer owns. That is 4K up to 64K, depending on page size and pool
order.
This path runs for every non-XSK RX frame, whether or not an XDP program
is loaded. Before this patch, the FCS was removed with pskb_trim(). That
goes through skb_condense(), which recomputed truesize whenever the
remaining frag data fit in the head tailroom. So regular stmmac RX
traffic did not see this before.
The impact is limited to socket receive buffer accounting. Nothing is
leaked or corrupted.
Every stmmac fragment has the same truesize. Would it be enough to pass
0 as truesize to xdp_buff_add_frag(), and let xdp_build_skb_from_buff()
fall back to nr_frags * xdp->frame_sz from the post-shrink nr_frags?
Or should xdp_frags_shrink_tail() subtract the truesize of the
fragments it frees? bpf_xdp_adjust_tail() shares that helper and seems
to have the same omission.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-stmmac-rx-mb-v14-0-5506796fd39e%40oss.qualcomm.com
^ permalink raw reply [flat|nested] 11+ messages in thread