From: Julius Bairaktaris <julius@bairaktaris.de>
To: Andrew Lunn <andrew@lunn.ch>, Vladimir Oltean <olteanv@gmail.com>,
netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@kernel.org>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Willem de Bruijn" <willemb@google.com>,
"Simon Horman" <horms@kernel.org>,
"Alvin Šipraga" <alvin.sipraga@analog.com>,
"Linus Walleij" <linusw@kernel.org>,
"Florian Fainelli" <florian.fainelli@broadcom.com>,
"Pawel Dembicki" <paweldembicki@gmail.com>,
"Tobias Waldekranz" <tobias@waldekranz.com>,
"Daniel Golle" <daniel@makrotopia.org>,
"Russell King" <linux@armlinux.org.uk>,
linux-kernel@vger.kernel.org
Subject: [PATCH net 2/6] net: dsa: tag_sja1105, tag_vsc73xx_8021q: read the bridge once in xmit
Date: Sat, 28 Nov 2026 17:52:01 +0100 [thread overview]
Message-ID: <20261128165206.3248835-3-julius@bairaktaris.de> (raw)
In-Reply-To: <20261128165206.3248835-1-julius@bairaktaris.de>
A frame received on a port that offloads a bridge carries
offload_fwd_mark (dsa_default_offload_fwd_mark()). A tc mirred redirect
or mirror, or an nft netdev fwd or dup, from that port to a standalone
port of the same switch keeps the mark, and vsc73xx_xmit() and
sja1105_imprecise_xmit() then look up the bridge of the standalone port:
dsa_port_bridge_dev_get() returns NULL and br_vlan_enabled() dereferences
it, in softirq, for every such frame. The same happens when a port leaves
its bridge while a frame that the bridge marked is still queued for it.
Both taggers also read dp->bridge twice, once for the device and once
for the number.
Read dp->bridge once. When the port is not in a bridge, it is a
standalone port, so send the frame in its standalone VLAN, to the port
alone, with the PCP of its TX queue, as for a frame without
offload_fwd_mark.
Both drivers are fixed in one commit because they share the mechanism.
Found by an LLM review (Claude), and reproduced in QEMU with dsa_loop.
Fixes: b6ad86e6ad6c ("net: dsa: sja1105: add bridge TX data plane offload based on tag_8021q")
Fixes: 6c87e1a47928 ("net: dsa: vsc73xx: introduce tag 8021q for vsc73xx")
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
net/dsa/tag_sja1105.c | 21 ++++++++++++++-------
net/dsa/tag_vsc73xx_8021q.c | 14 +++++++++-----
2 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c
index bfe1f746f55..6c267a2a232 100644
--- a/net/dsa/tag_sja1105.c
+++ b/net/dsa/tag_sja1105.c
@@ -209,27 +209,34 @@ static u16 sja1105_xmit_tpid(struct dsa_port *dp)
}
static struct sk_buff *sja1105_imprecise_xmit(struct sk_buff *skb,
- struct net_device *netdev)
+ struct net_device *netdev, u8 pcp)
{
struct dsa_port *dp = dsa_user_to_port(netdev);
- unsigned int bridge_num = dsa_port_bridge_num_get(dp);
- struct net_device *br = dsa_port_bridge_dev_get(dp);
+ const struct dsa_bridge *bridge = READ_ONCE(dp->bridge);
u16 tx_vid;
+ /* The bridge marked the frame, then the port left it: the port is
+ * standalone now, send the frame to it alone.
+ */
+ if (unlikely(!bridge))
+ return dsa_8021q_xmit(skb, netdev, sja1105_xmit_tpid(dp),
+ (pcp << VLAN_PRIO_SHIFT) |
+ dsa_tag_8021q_standalone_vid(dp));
+
/* If the port is under a VLAN-aware bridge, just slide the
* VLAN-tagged packet into the FDB and hope for the best.
* This works because we support a single VLAN-aware bridge
* across the entire dst, and its VLANs cannot be shared with
* any standalone port.
*/
- if (br_vlan_enabled(br))
+ if (br_vlan_enabled(bridge->dev))
return skb;
/* If the port is under a VLAN-unaware bridge, use an imprecise
* TX VLAN that targets the bridge's entire broadcast domain,
* instead of just the specific port.
*/
- tx_vid = dsa_tag_8021q_bridge_vid(bridge_num);
+ tx_vid = dsa_tag_8021q_bridge_vid(bridge->num);
return dsa_8021q_xmit(skb, netdev, sja1105_xmit_tpid(dp), tx_vid);
}
@@ -273,7 +280,7 @@ static struct sk_buff *sja1105_xmit(struct sk_buff *skb,
u16 tx_vid = dsa_tag_8021q_standalone_vid(dp);
if (skb->offload_fwd_mark)
- return sja1105_imprecise_xmit(skb, netdev);
+ return sja1105_imprecise_xmit(skb, netdev, pcp);
/* Transmitting management traffic does not rely upon switch tagging,
* but instead SPI-installed management routes. Part 2 of this
@@ -304,7 +311,7 @@ static struct sk_buff *sja1110_xmit(struct sk_buff *skb,
int trailer_pos;
if (skb->offload_fwd_mark)
- return sja1105_imprecise_xmit(skb, netdev);
+ return sja1105_imprecise_xmit(skb, netdev, pcp);
/* Transmitting control packets is done using in-band control
* extensions, while data packets are transmitted using
diff --git a/net/dsa/tag_vsc73xx_8021q.c b/net/dsa/tag_vsc73xx_8021q.c
index f4736a1a7a0..d65e5ddaa8c 100644
--- a/net/dsa/tag_vsc73xx_8021q.c
+++ b/net/dsa/tag_vsc73xx_8021q.c
@@ -17,13 +17,17 @@ vsc73xx_xmit(struct sk_buff *skb, struct net_device *netdev)
u8 pcp;
if (skb->offload_fwd_mark) {
- unsigned int bridge_num = dsa_port_bridge_num_get(dp);
- struct net_device *br = dsa_port_bridge_dev_get(dp);
+ const struct dsa_bridge *bridge = READ_ONCE(dp->bridge);
- if (br_vlan_enabled(br))
- return skb;
+ /* The port may have left the bridge since the bridge marked
+ * the frame: then it goes to the port alone.
+ */
+ if (bridge) {
+ if (br_vlan_enabled(bridge->dev))
+ return skb;
- tx_vid = dsa_tag_8021q_bridge_vid(bridge_num);
+ tx_vid = dsa_tag_8021q_bridge_vid(bridge->num);
+ }
}
pcp = netdev_txq_to_tc(netdev, queue_mapping);
--
2.53.0
next prev parent reply other threads:[~2026-11-28 16:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 16:51 [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 1/6] net: dsa: free struct dsa_bridge after an RCU grace period Julius Bairaktaris
2026-11-28 16:52 ` Julius Bairaktaris [this message]
2026-12-06 3:54 ` [PATCH net 2/6] net: dsa: tag_sja1105, tag_vsc73xx_8021q: read the bridge once in xmit willemb
2026-11-28 16:52 ` [PATCH net 3/6] net: dsa: tag_dsa: send a marked frame of an unbridged port from the CPU Julius Bairaktaris
2026-12-06 3:55 ` willemb
2026-11-28 16:52 ` [PATCH net 4/6] net: dsa: do not hand a switch a bridge number above its limit Julius Bairaktaris
2026-12-06 3:55 ` willemb
2026-11-28 16:52 ` [PATCH net 5/6] net: dsa: do not take a bridge number past the end of the bitmap Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 6/6] net: dsa: keep a bridge number while another tree uses it Julius Bairaktaris
2026-12-06 3:57 ` willemb
2026-12-06 3:54 ` [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches willemb
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261128165206.3248835-3-julius@bairaktaris.de \
--to=julius@bairaktaris.de \
--cc=alvin.sipraga@analog.com \
--cc=andrew@lunn.ch \
--cc=daniel@makrotopia.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=florian.fainelli@broadcom.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=paweldembicki@gmail.com \
--cc=tobias@waldekranz.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox