From: Julius Bairaktaris <julius@bairaktaris.de>
To: Andrew Lunn <andrew@lunn.ch>, Vladimir Oltean <olteanv@gmail.com>
Cc: netdev@vger.kernel.org, bridge@lists.linux.dev,
"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>,
"Nikolay Aleksandrov" <razor@blackwall.org>,
"Ido Schimmel" <idosch@nvidia.com>,
"Alvin Šipraga" <alvin.sipraga@analog.com>,
"Florian Fainelli" <f.fainelli@gmail.com>,
"Tobias Waldekranz" <tobias@waldekranz.com>,
"Linus Walleij" <linusw@kernel.org>,
"Pawel Dembicki" <paweldembicki@gmail.com>
Subject: [PATCH net v3 3/3] net: dsa: forward a marked frame only while its port is in a bridge
Date: Fri, 4 Dec 2026 23:20:45 +0100 [thread overview]
Message-ID: <20261204222045.214014-4-julius@bairaktaris.de> (raw)
In-Reply-To: <20261204222045.214014-1-julius@bairaktaris.de>
The tag_dsa, tag_sja1105 and tag_vsc73xx_8021q taggers build a tag that
has the switch forward a frame in the domain of the port's bridge when
skb->offload_fwd_mark is set, which the bridge does for a port with TX
forwarding offload. They read the bridge number and device with
dsa_port_bridge_num_get() and dsa_port_bridge_dev_get() and assume that
the port is in a bridge that has a number.
It need not be. A frame the bridge marked can still be in a qdisc of the
port when the port leaves the bridge, and a frame received on a bridged
port still carries the mark its tagger set on reception when tc
redirects it to another port. With no bridge, sja1105_imprecise_xmit()
and vsc73xx_xmit() pass NULL to br_vlan_enabled(), which with
CONFIG_BRIDGE_VLAN_FILTERING reads the bridge's private area:
BUG: KASAN: null-ptr-deref in br_vlan_enabled+0x21/0x60
Read of size 8 at addr 0000000000000e48 by task vinject/142
Call Trace:
br_vlan_enabled+0x21/0x60
vsc73xx_xmit+0x130/0x1c0
dsa_user_xmit+0x265/0x4c0
dev_hard_start_xmit+0xde/0x5b0
__dev_queue_xmit+0x15f3/0x34f0
tcf_mirred_to_dev+0x9cc/0x15a0
and dsa_xmit_ll() sends a FORWARD tag for bridge number 0, which names
the last physical switch instead of a virtual bridge device. It does the
same for a redirected frame on a port that is in a bridge without a
number: mv88e6xxx asks for bridge numbers only on switches with a
cross-chip port VLAN table, so on the others every bridge has number 0.
Each helper also reads dp->bridge on its own, so a port that leaves
between the two reads gives a bridge number without a bridge device.
Read dp->bridge once in each of the three taggers, and forward on
behalf of the bridge only when the frame is marked and the port is in a
bridge that has a number (dsa_xmit_fwd_offload()). Only mv88e6xxx with
a port VLAN table and the tag_8021q drivers grant TX forwarding offload,
and they get a number for each bridge, so frames the bridge marked keep
their FORWARD tag. The exception is an mv88e6xxx tree that mixes chips
with and without that table: a bridge first joined on a chip without
one has number 0, and such frames, which went out as FORWARD for bridge
0, now go to the one port the bridge chose. Otherwise the frame takes
the tagger's path for an unmarked frame, which sends it to the port the
stack chose. The bridge stays
valid while the tagger uses it: dsa_port_bridge_destroy() waits with
synchronize_net() before it frees it.
Two cases remain. A marked frame that is still queued when its port
joins another bridge is forwarded in the domain of that bridge, and a
frame received on a bridged port and redirected by tc to a port in a
bridge that has a number is forwarded in that bridge's domain instead
of only to that port. The tagger cannot tell either mark from one the
bridge set; that needs the queued frames dropped when the port's TX
forwarding offload ends, and the mark cleared where a received frame is
sent without the bridge, which this change does not do.
Fixes: d82f8ab0d874 ("net: dsa: tag_dsa: offload the bridge forwarding process")
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")
Link: https://lore.kernel.org/all/20261121185821.1471559-1-julius@bairaktaris.de/ [1]
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
Found by the hosted Sashiko reviews of v1 of "net: dsa: do not run
queued FDB events after the port left the bridge" [1] and of v2 of
this series, and the tc redirect by an LLM review (Claude) of this
change.
In QEMU with KASAN, with dsa_loop given the vsc73xx-8021q or the dsa
tagger and TX forwarding offload (test-only changes): 40 broadcasts from
the bridge held in a tbf qdisc on two user ports that then leave the
bridge oops as above with vsc73xx-8021q in 3 of 3 boots, and with dsa
go out as FORWARD tags for bridge 0 (28, 26 and 28 frames) in 3 of 3
boots; frames received on a bridged port and redirected by tc to a port
in no bridge oops as above in 3 of 3 boots. With this change, neither
oopses in 6 of 6 boots each, the frames go out with the VLAN of their
port in no bridge (vsc73xx-8021q, counted in one boot of each), and
with dsa the frames sent after the leave carry FROM_CPU tags (29, 28,
29 and 32 frames) in 4 of 4 boots. With dsa and no TX forwarding
offload, so that bridges have number 0, 10 frames received on a port of
one bridge and redirected by tc to a port of another go out as FORWARD
for bridge 0 without this change (1 boot each on net and with v2), and
as FROM_CPU to the target port with it (1 boot).
v3:
- Forward on behalf of the bridge only when it has a number, so that
dsa_xmit_ll() sends no FORWARD tag for bridge 0 from a port of a
mv88e6xxx switch without a cross-chip port VLAN table (hosted Sashiko
review of v2, High). One helper, dsa_xmit_fwd_offload(), holds the
check for the three taggers.
- The message and the helper's comment name a redirect into a port of a
bridge that has a number as a case this does not fix (hosted Sashiko
review of v2, Medium).
v2: https://lore.kernel.org/all/20261128133503.3887987-4-julius@bairaktaris.de/ (new in v2)
net/dsa/tag.h | 14 ++++++++++++++
net/dsa/tag_dsa.c | 11 ++++++-----
net/dsa/tag_sja1105.c | 19 ++++++++++---------
net/dsa/tag_vsc73xx_8021q.c | 10 ++++------
4 files changed, 34 insertions(+), 20 deletions(-)
diff --git a/net/dsa/tag.h b/net/dsa/tag.h
index 0e1be1da4537..fd543eb705c2 100644
--- a/net/dsa/tag.h
+++ b/net/dsa/tag.h
@@ -241,6 +241,20 @@ static inline void dsa_default_offload_fwd_mark(struct sk_buff *skb)
skb->offload_fwd_mark = !!READ_ONCE(dp->bridge);
}
+/* Whether the switch is to forward @skb on behalf of @bridge, the bridge of
+ * the user port as the tagger read it, once. The bridge marks a frame for TX
+ * forwarding offload only on a port whose bridge has a number. A frame can
+ * also carry a mark set before its port left the bridge, or one set on
+ * reception and kept by a redirect; it is then forwarded in a bridge only if
+ * the port is in one that has a number, and otherwise sent to the port the
+ * stack chose.
+ */
+static inline bool dsa_xmit_fwd_offload(const struct sk_buff *skb,
+ const struct dsa_bridge *bridge)
+{
+ return skb->offload_fwd_mark && bridge && bridge->num;
+}
+
/* Helper for removing DSA header tags from packets in the RX path.
* Must not be called before skb_pull(len).
* skb->data
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index d5ffee35fbb5..53f17849b4cf 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -130,13 +130,16 @@ 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);
+ const struct dsa_bridge *bridge;
struct net_device *br_dev;
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);
+ bridge = READ_ONCE(dp->bridge);
+ br_dev = bridge ? bridge->dev : NULL;
+
+ if (dsa_xmit_fwd_offload(skb, bridge)) {
struct dsa_switch_tree *dst = dp->ds->dst;
cmd = DSA_CMD_FORWARD;
@@ -145,7 +148,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 +156,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
diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c
index bfe1f746f55b..127c65199dc2 100644
--- a/net/dsa/tag_sja1105.c
+++ b/net/dsa/tag_sja1105.c
@@ -209,11 +209,10 @@ 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,
+ const struct dsa_bridge *bridge)
{
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);
u16 tx_vid;
/* If the port is under a VLAN-aware bridge, just slide the
@@ -222,14 +221,14 @@ static struct sk_buff *sja1105_imprecise_xmit(struct sk_buff *skb,
* 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);
}
@@ -268,12 +267,13 @@ static struct sk_buff *sja1105_xmit(struct sk_buff *skb,
struct net_device *netdev)
{
struct dsa_port *dp = dsa_user_to_port(netdev);
+ const struct dsa_bridge *bridge = READ_ONCE(dp->bridge);
u16 queue_mapping = skb_get_queue_mapping(skb);
u8 pcp = netdev_txq_to_tc(netdev, queue_mapping);
u16 tx_vid = dsa_tag_8021q_standalone_vid(dp);
- if (skb->offload_fwd_mark)
- return sja1105_imprecise_xmit(skb, netdev);
+ if (dsa_xmit_fwd_offload(skb, bridge))
+ return sja1105_imprecise_xmit(skb, netdev, bridge);
/* Transmitting management traffic does not rely upon switch tagging,
* but instead SPI-installed management routes. Part 2 of this
@@ -296,6 +296,7 @@ static struct sk_buff *sja1110_xmit(struct sk_buff *skb,
{
struct sk_buff *clone = SJA1105_SKB_CB(skb)->clone;
struct dsa_port *dp = dsa_user_to_port(netdev);
+ const struct dsa_bridge *bridge = READ_ONCE(dp->bridge);
u16 queue_mapping = skb_get_queue_mapping(skb);
u8 pcp = netdev_txq_to_tc(netdev, queue_mapping);
u16 tx_vid = dsa_tag_8021q_standalone_vid(dp);
@@ -303,8 +304,8 @@ static struct sk_buff *sja1110_xmit(struct sk_buff *skb,
__be16 *tx_header;
int trailer_pos;
- if (skb->offload_fwd_mark)
- return sja1105_imprecise_xmit(skb, netdev);
+ if (dsa_xmit_fwd_offload(skb, bridge))
+ return sja1105_imprecise_xmit(skb, netdev, bridge);
/* 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 f4736a1a7a0f..3a11377811aa 100644
--- a/net/dsa/tag_vsc73xx_8021q.c
+++ b/net/dsa/tag_vsc73xx_8021q.c
@@ -12,18 +12,16 @@ static struct sk_buff *
vsc73xx_xmit(struct sk_buff *skb, struct net_device *netdev)
{
struct dsa_port *dp = dsa_user_to_port(netdev);
+ const struct dsa_bridge *bridge = READ_ONCE(dp->bridge);
u16 queue_mapping = skb_get_queue_mapping(skb);
u16 tx_vid = dsa_tag_8021q_standalone_vid(dp);
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);
-
- if (br_vlan_enabled(br))
+ if (dsa_xmit_fwd_offload(skb, 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-12-04 22:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 22:20 [PATCH net v3 0/3] net: dsa: FDB events and tagging after a port left its bridge Julius Bairaktaris
2026-12-04 22:20 ` [PATCH net v3 1/3] net: dsa: do not run queued FDB events after the port left the bridge Julius Bairaktaris
2026-12-04 22:20 ` [PATCH net v3 2/3] net: dsa: hold the device a queued FDB event is reported to Julius Bairaktaris
2026-12-04 22:20 ` Julius Bairaktaris [this message]
2026-12-05 22:44 ` [PATCH net v3 3/3] net: dsa: forward a marked frame only while its port is in a bridge netdev-bot+sashiko
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=20261204222045.214014-4-julius@bairaktaris.de \
--to=julius@bairaktaris.de \
--cc=alvin.sipraga@analog.com \
--cc=andrew@lunn.ch \
--cc=bridge@lists.linux.dev \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=f.fainelli@gmail.com \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linusw@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=paweldembicki@gmail.com \
--cc=razor@blackwall.org \
--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