[PATCH net 3/6] net: dsa: tag_dsa: send a marked frame of an unbridged port from the CPU

From: Julius Bairaktaris

Date: Sat Nov 28 2026 - 11:52:34 EST


dsa_xmit_ll() sends a frame with offload_fwd_mark as a FORWARD frame on
behalf of the port's bridge, with the bridge number taken from
dsa_port_bridge_num_get(). The port need not be in a bridge: a frame
received on a bridged port keeps the mark through a tc mirred redirect
or an nft netdev fwd to a standalone port of the same switch, and a
frame that the bridge marked can still be queued for a port that has
left the bridge. The bridge number is 0 then, and the frame goes out as
FORWARD from device dst->last_switch, port 0, instead of FROM_CPU to the
port. The function also reads dp->bridge twice, once for the number and
once for the device.

Read dp->bridge once, and send FORWARD only while the port is in a
bridge; otherwise the frame goes FROM_CPU to the port, as a frame
without the mark does.

Found by an LLM review (Claude), and reproduced in QEMU with dsa_loop.

Fixes: d82f8ab0d874 ("net: dsa: tag_dsa: offload the bridge forwarding process")
Signed-off-by: Julius Bairaktaris <julius@xxxxxxxxxxxxxx>
---
net/dsa/tag_dsa.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index d5ffee35fbb..9a89508e451 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -130,13 +130,17 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
u8 extra)
{
struct dsa_port *dp = dsa_user_to_port(dev);
- struct net_device *br_dev;
+ const struct dsa_bridge *bridge = READ_ONCE(dp->bridge);
+ struct net_device *br_dev = bridge ? bridge->dev : NULL;
u8 tag_dev, tag_port;
enum dsa_cmd cmd;
u8 *dsa_header;

- if (skb->offload_fwd_mark) {
- unsigned int bridge_num = dsa_port_bridge_num_get(dp);
+ /* A frame keeps offload_fwd_mark through a redirect to a standalone
+ * port, and the port may have left its bridge since the bridge marked
+ * the frame: only a bridged port forwards for its bridge.
+ */
+ if (skb->offload_fwd_mark && bridge) {
struct dsa_switch_tree *dst = dp->ds->dst;

cmd = DSA_CMD_FORWARD;
@@ -145,7 +149,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
* packets on behalf of a virtual switch device with an index
* past the physical switches.
*/
- tag_dev = dst->last_switch + bridge_num;
+ tag_dev = dst->last_switch + bridge->num;
tag_port = 0;
} else {
cmd = DSA_CMD_FROM_CPU;
@@ -153,8 +157,6 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
tag_port = dp->index;
}

- br_dev = dsa_port_bridge_dev_get(dp);
-
/* If frame is already 802.1Q tagged, we can convert it to a DSA
* tag (avoiding a memmove), but only if the port is standalone
* (in which case we always send FROM_CPU) or if the port's
--
2.53.0