[PATCH net 2/6] net: dsa: tag_sja1105, tag_vsc73xx_8021q: read the bridge once in xmit
From: Julius Bairaktaris
Date: Sat Nov 28 2026 - 11:52:28 EST
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@xxxxxxxxxxxxxx>
---
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