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

From: willemb

Date: Sat Dec 05 2026 - 22:55:25 EST


Julius Bairaktaris wrote:
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:143 (dsa_xmit_ll):
The new guard `if (skb->offload_fwd_mark && bridge)` only verifies that the
egress port belongs to a bridge; it fails to check bridge->tx_fwd_offload (or
bridge->num != 0). In drivers/net/dsa/mv88e6xxx/chip.c:4008-4010 and
3071-3077, mv88e6xxx_setup() only sets ds->max_num_bridges and
mv88e6xxx_port_bridge_join() only sets *tx_fwd_offload = true when
mv88e6xxx_has_pvt(chip) is true. On all 7 non-PVT mv88e6xxx chips (MV88E6020,
MV88E6071, MV88E6095, MV88E6131, MV88E6185, MV88E6220, MV88E6250), a bridged
port has dp->bridge != NULL with bridge->num == 0 and bridge->tx_fwd_offload
== false. Under the exact same tc mirred / nft netdev fwd redirect from any
bridged ingress port (where dsa_default_offload_fwd_mark() sets
skb->offload_fwd_mark = 1), dsa_xmit_ll() STILL takes the DSA_CMD_FORWARD
branch and sets tag_dev = dst->last_switch + 0 (dst->last_switch), tag_port =
0, impersonating physical switch dst->last_switch port 0. Additionally, during
dsa_port_bridge_join() on PVT chips, dp->bridge is published before
mv88e6xxx_map_virtual_bridge_to_pvt() sets dp->bridge->tx_fwd_offload = true.
dsa_xmit_ll() must check bridge && READ_ONCE(bridge->tx_fwd_offload) (and
bridge->num != 0, with WRITE_ONCE() in dsa_port_bridge_join()).

net/dsa/tag_dsa.c:139-143 (dsa_xmit_ll):
skb->offload_fwd_mark carries no bridge/hwdom identity and is overloaded
between RX ("already hardware-forwarded in ingress hwdom") and TX ("bridge
requests TX forwarding offload"). Neither tcf_mirred_to_dev()
(net/sched/act_mirred.c:254-335) nor nf_do_netdev_egress()
(net/netfilter/nf_dup_netdev.c:17-41) clears skb->offload_fwd_mark when
redirecting/mirroring to egress. Consequently, redirecting an RX frame from a
bridged port on br0 (or any other switchdev NIC) to a bridged port on br1
causes dsa_xmit_ll() to transmit DSA_CMD_FORWARD on behalf of br1 (flooding
and learning SA on br1) instead of DSA_CMD_FROM_CPU to the target port.
Clearing skb->offload_fwd_mark on egress redirect (while keeping tagger RCU
and tx_fwd_offload checks for concurrent bridge leave) fixes the root cause
rather than only standalone targets.