* [PATCH net v3 1/3] net: dsa: do not run queued FDB events after the port left the bridge
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 ` 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 ` [PATCH net v3 3/3] net: dsa: forward a marked frame only while its port is in a bridge Julius Bairaktaris
2 siblings, 0 replies; 5+ messages in thread
From: Julius Bairaktaris @ 2026-12-04 22:20 UTC (permalink / raw)
To: Andrew Lunn, Vladimir Oltean
Cc: netdev, bridge, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn, Simon Horman, Nikolay Aleksandrov,
Ido Schimmel, Alvin Šipraga, Florian Fainelli,
Tobias Waldekranz, Linus Walleij, Pawel Dembicki
FDB events reach DSA from the atomic switchdev notifier and are handled
from dsa_owq. The work builds the dsa_db from dp->bridge, which
dsa_port_bridge_destroy() clears and frees when the port leaves the
bridge or fails to join it.
When switchdev_bridge_port_offload() fails in the FDB replay of
dsa_port_bridge_join(), because dsa_user_fdb_event() could not allocate
its work item, the entries replayed before the failure are still
queued. The rollback clears dp->bridge, and the queued work dereferences
it:
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
Workqueue: dsa_ordered dsa_user_switchdev_event_work
RIP: 0010:dsa_port_bridge_host_fdb_add+0x141/0x5c0
A bridge leave has the same problem for an event that the notifier
queues after dsa_port_pre_bridge_leave() flushed the workqueue: nothing
orders the dp->bridge check in dsa_user_fdb_event() against the clear,
and on a switch unbind the work can also run after dsa_user_destroy()
freed the port's net_device. The notifier and the taggers read
dp->bridge->dev and ->num without locks while the bridge is freed.
Clear dp->bridge, wait with synchronize_net(), flush the workqueue, and
only then drop the reference and free the bridge.
Nothing in flight can take a reference meanwhile. The refcount is only
raised in dsa_port_bridge_create(), on a bridge that
dsa_tree_bridge_find() returned, and both run in the join path under
RTNL, which dsa_port_bridge_destroy() holds too. The paths without RTNL
only read dp->bridge, and all of them are RCU readers: the switchdev
notifier is called under rcu_read_lock() by
atomic_notifier_call_chain() and by the FDB replay, and the taggers run
in the RCU sections of the transmit and receive paths.
synchronize_net() waits for them. The work a notifier queued is on
dsa_owq by then, and the flush waits for it. The cost is one expedited
RCU grace period, under RTNL, each time a port leaves a bridge.
The work reads dp->bridge once and drops the event when the port has
left; the FDB helpers take the bridge from it. The join rollback
destroys the bridge before it tells the switches that the port left, as
dsa_port_bridge_leave() does, so a dropped event programs nothing after
that. dsa_port_bridge_dev_get() and dsa_port_bridge_num_get() read the
pointer once, and dsa_port_bridge_create() publishes it with
smp_store_release(), so a reader that sees it also sees its fields. The
other readers outside RTNL only test the pointer, with READ_ONCE().
Fixes: c26933639b54 ("net: dsa: request drivers to perform FDB isolation")
Fixes: d3eed0e57d5d ("net: dsa: keep the bridge_dev and bridge_num as part of the same structure")
Link: https://lore.kernel.org/all/179480421335.3136.15795220009190349154@kernel.org/ [1]
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
The rollback oops was pointed out by the hosted Sashiko review of a DSA
host FDB series [1]. In QEMU with KASAN, dsa_loop given FDB operations
that take 15 ms, 40 static FDB entries to replay and the N-th
allocation of "ip link set lan1 master br0" failing for N = 1 to 150,
net oopses as above in 3 of 3 boots, and with this change in none of 4
boots. With the change, 2 to 5 host addresses per boot stay on the CPU
port after those joins (5, 4, 5 and 2 more additions than deletions).
They were added by replayed events that ran before the allocation
failed: br_switchdev_port_offload() does not undo the part of the
replay that succeeded, and this change does not alter that.
v3:
- The message says why no in-flight notification or tagger can take a
reference to the bridge, and what the grace period costs, after Paolo
Abeni's question on v1:
https://lore.kernel.org/all/dfe749f5-83de-4802-bcff-7517ea6b7283@redhat.com/
- Code unchanged. Rebased on net e9d78fc6741a; the join sweep ran once
more on it.
v2:
- The other readers of dp->bridge outside RTNL, dsa_port_to_bridge_port(),
dsa_find_designated_bridge_port_by_vid(), dsa_default_offload_fwd_mark()
and dsa_tag_8021q_find_port_by_vbid(), use READ_ONCE() (hosted Sashiko
review of v1).
- The comment in dsa_port_bridge_destroy() speaks of a tagger that read
the bridge; a tagger that reads NULL is patch 3.
v2: https://lore.kernel.org/all/20261128133503.3887987-2-julius@bairaktaris.de/
v1: https://lore.kernel.org/all/20261121185821.1471559-1-julius@bairaktaris.de/
include/net/dsa.h | 10 ++++++---
net/dsa/port.c | 50 ++++++++++++++++++++++++++++++---------------
net/dsa/port.h | 26 ++++++++++++-----------
net/dsa/tag.h | 4 ++--
net/dsa/tag_8021q.c | 2 +-
net/dsa/user.c | 25 ++++++++++++++++-------
6 files changed, 75 insertions(+), 42 deletions(-)
diff --git a/include/net/dsa.h b/include/net/dsa.h
index 5d12191b6f6f..47e2162f1d7d 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -758,7 +758,7 @@ static inline struct net_device *dsa_port_to_conduit(const struct dsa_port *dp)
static inline
struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp)
{
- if (!dp->bridge)
+ if (!READ_ONCE(dp->bridge))
return NULL;
if (dp->lag)
@@ -772,12 +772,16 @@ struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp)
static inline struct net_device *
dsa_port_bridge_dev_get(const struct dsa_port *dp)
{
- return dp->bridge ? dp->bridge->dev : NULL;
+ const struct dsa_bridge *bridge = READ_ONCE(dp->bridge);
+
+ return bridge ? bridge->dev : NULL;
}
static inline unsigned int dsa_port_bridge_num_get(struct dsa_port *dp)
{
- return dp->bridge ? dp->bridge->num : 0;
+ const struct dsa_bridge *bridge = READ_ONCE(dp->bridge);
+
+ return bridge ? bridge->num : 0;
}
static inline bool dsa_port_bridge_same(const struct dsa_port *a,
diff --git a/net/dsa/port.c b/net/dsa/port.c
index 1f5536c0dffc..e41d3639f0f9 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -427,7 +427,8 @@ static int dsa_port_bridge_create(struct dsa_port *dp,
bridge = dsa_tree_bridge_find(ds->dst, br);
if (bridge) {
refcount_inc(&bridge->refcount);
- dp->bridge = bridge;
+ /* Read without locks, see below */
+ smp_store_release(&dp->bridge, bridge);
return 0;
}
@@ -447,7 +448,8 @@ static int dsa_port_bridge_create(struct dsa_port *dp,
return -EOPNOTSUPP;
}
- dp->bridge = bridge;
+ /* Read without locks from the switchdev notifiers and the taggers */
+ smp_store_release(&dp->bridge, bridge);
return 0;
}
@@ -457,7 +459,14 @@ static void dsa_port_bridge_destroy(struct dsa_port *dp,
{
struct dsa_bridge *bridge = dp->bridge;
- dp->bridge = NULL;
+ WRITE_ONCE(dp->bridge, NULL);
+
+ /* An FDB event from the atomic switchdev notifier that still sees the
+ * bridge can queue work for it, and a tagger that read it can still
+ * use it. Wait for them, then for the work they queued.
+ */
+ synchronize_net();
+ dsa_flush_workqueue();
if (!refcount_dec_and_test(&bridge->refcount))
return;
@@ -528,7 +537,12 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br,
&dsa_user_switchdev_blocking_notifier);
dsa_flush_workqueue();
out_rollback_unbridge:
+ /* Drop the FDB events still queued from the replay before the
+ * switches are told that the port left
+ */
+ dsa_port_bridge_destroy(dp, br);
dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info);
+ return err;
out_rollback:
dsa_port_bridge_destroy(dp, br);
return err;
@@ -973,8 +987,8 @@ int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu)
return dsa_port_notify(dp, DSA_NOTIFIER_MTU, &info);
}
-int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
- u16 vid)
+int dsa_port_fdb_add(struct dsa_port *dp, const struct dsa_bridge *bridge,
+ const unsigned char *addr, u16 vid)
{
struct dsa_notifier_fdb_info info = {
.dp = dp,
@@ -982,7 +996,7 @@ int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
.vid = vid,
.db = {
.type = DSA_DB_BRIDGE,
- .bridge = *dp->bridge,
+ .bridge = *bridge,
},
};
@@ -996,8 +1010,8 @@ int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
return dsa_port_notify(dp, DSA_NOTIFIER_FDB_ADD, &info);
}
-int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
- u16 vid)
+int dsa_port_fdb_del(struct dsa_port *dp, const struct dsa_bridge *bridge,
+ const unsigned char *addr, u16 vid)
{
struct dsa_notifier_fdb_info info = {
.dp = dp,
@@ -1005,7 +1019,7 @@ int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
.vid = vid,
.db = {
.type = DSA_DB_BRIDGE,
- .bridge = *dp->bridge,
+ .bridge = *bridge,
},
};
@@ -1041,12 +1055,13 @@ int dsa_port_standalone_host_fdb_add(struct dsa_port *dp,
}
int dsa_port_bridge_host_fdb_add(struct dsa_port *dp,
+ const struct dsa_bridge *bridge,
const unsigned char *addr, u16 vid)
{
struct net_device *conduit = dsa_port_to_conduit(dp);
struct dsa_db db = {
.type = DSA_DB_BRIDGE,
- .bridge = *dp->bridge,
+ .bridge = *bridge,
};
int err;
@@ -1092,12 +1107,13 @@ int dsa_port_standalone_host_fdb_del(struct dsa_port *dp,
}
int dsa_port_bridge_host_fdb_del(struct dsa_port *dp,
+ const struct dsa_bridge *bridge,
const unsigned char *addr, u16 vid)
{
struct net_device *conduit = dsa_port_to_conduit(dp);
struct dsa_db db = {
.type = DSA_DB_BRIDGE,
- .bridge = *dp->bridge,
+ .bridge = *bridge,
};
int err;
@@ -1113,8 +1129,8 @@ int dsa_port_bridge_host_fdb_del(struct dsa_port *dp,
return dsa_port_host_fdb_del(dp, addr, vid, db);
}
-int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr,
- u16 vid)
+int dsa_port_lag_fdb_add(struct dsa_port *dp, const struct dsa_bridge *bridge,
+ const unsigned char *addr, u16 vid)
{
struct dsa_notifier_lag_fdb_info info = {
.lag = dp->lag,
@@ -1122,7 +1138,7 @@ int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr,
.vid = vid,
.db = {
.type = DSA_DB_BRIDGE,
- .bridge = *dp->bridge,
+ .bridge = *bridge,
},
};
@@ -1132,8 +1148,8 @@ int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr,
return dsa_port_notify(dp, DSA_NOTIFIER_LAG_FDB_ADD, &info);
}
-int dsa_port_lag_fdb_del(struct dsa_port *dp, const unsigned char *addr,
- u16 vid)
+int dsa_port_lag_fdb_del(struct dsa_port *dp, const struct dsa_bridge *bridge,
+ const unsigned char *addr, u16 vid)
{
struct dsa_notifier_lag_fdb_info info = {
.lag = dp->lag,
@@ -1141,7 +1157,7 @@ int dsa_port_lag_fdb_del(struct dsa_port *dp, const unsigned char *addr,
.vid = vid,
.db = {
.type = DSA_DB_BRIDGE,
- .bridge = *dp->bridge,
+ .bridge = *bridge,
},
};
diff --git a/net/dsa/port.h b/net/dsa/port.h
index 6bc3291573c0..e665baf7454a 100644
--- a/net/dsa/port.h
+++ b/net/dsa/port.h
@@ -46,22 +46,24 @@ int dsa_port_mst_enable(struct dsa_port *dp, bool on,
int dsa_port_vlan_msti(struct dsa_port *dp,
const struct switchdev_vlan_msti *msti);
int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu);
-int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
- u16 vid);
-int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
- u16 vid);
+int dsa_port_fdb_add(struct dsa_port *dp, const struct dsa_bridge *bridge,
+ const unsigned char *addr, u16 vid);
+int dsa_port_fdb_del(struct dsa_port *dp, const struct dsa_bridge *bridge,
+ const unsigned char *addr, u16 vid);
int dsa_port_standalone_host_fdb_add(struct dsa_port *dp,
const unsigned char *addr, u16 vid);
int dsa_port_standalone_host_fdb_del(struct dsa_port *dp,
const unsigned char *addr, u16 vid);
-int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, const unsigned char *addr,
- u16 vid);
-int dsa_port_bridge_host_fdb_del(struct dsa_port *dp, const unsigned char *addr,
- u16 vid);
-int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr,
- u16 vid);
-int dsa_port_lag_fdb_del(struct dsa_port *dp, const unsigned char *addr,
- u16 vid);
+int dsa_port_bridge_host_fdb_add(struct dsa_port *dp,
+ const struct dsa_bridge *bridge,
+ const unsigned char *addr, u16 vid);
+int dsa_port_bridge_host_fdb_del(struct dsa_port *dp,
+ const struct dsa_bridge *bridge,
+ const unsigned char *addr, u16 vid);
+int dsa_port_lag_fdb_add(struct dsa_port *dp, const struct dsa_bridge *bridge,
+ const unsigned char *addr, u16 vid);
+int dsa_port_lag_fdb_del(struct dsa_port *dp, const struct dsa_bridge *bridge,
+ const unsigned char *addr, u16 vid);
int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data);
int dsa_port_mdb_add(const struct dsa_port *dp,
const struct switchdev_obj_port_mdb *mdb);
diff --git a/net/dsa/tag.h b/net/dsa/tag.h
index cf52283fe9df..0e1be1da4537 100644
--- a/net/dsa/tag.h
+++ b/net/dsa/tag.h
@@ -201,7 +201,7 @@ dsa_find_designated_bridge_port_by_vid(struct net_device *conduit, u16 vid)
if (dp->type != DSA_PORT_TYPE_USER)
continue;
- if (!dp->bridge)
+ if (!READ_ONCE(dp->bridge))
continue;
if (dp->stp_state != BR_STATE_LEARNING &&
@@ -238,7 +238,7 @@ static inline void dsa_default_offload_fwd_mark(struct sk_buff *skb)
{
struct dsa_port *dp = dsa_user_to_port(skb->dev);
- skb->offload_fwd_mark = !!(dp->bridge);
+ skb->offload_fwd_mark = !!READ_ONCE(dp->bridge);
}
/* Helper for removing DSA header tags from packets in the RX path.
diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c
index f91646e60246..de7e24f75505 100644
--- a/net/dsa/tag_8021q.c
+++ b/net/dsa/tag_8021q.c
@@ -482,7 +482,7 @@ dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, int vbid)
return NULL;
dsa_tree_for_each_user_port(dp, dst) {
- if (!dp->bridge)
+ if (!READ_ONCE(dp->bridge))
continue;
if (dp->stp_state != BR_STATE_LEARNING &&
diff --git a/net/dsa/user.c b/net/dsa/user.c
index 041f9060c8ef..81f0d3901209 100644
--- a/net/dsa/user.c
+++ b/net/dsa/user.c
@@ -3646,6 +3646,7 @@ static void dsa_user_switchdev_event_work(struct work_struct *work)
const unsigned char *addr = switchdev_work->addr;
struct net_device *dev = switchdev_work->dev;
u16 vid = switchdev_work->vid;
+ const struct dsa_bridge *bridge;
struct dsa_switch *ds;
struct dsa_port *dp;
int err;
@@ -3653,14 +3654,22 @@ static void dsa_user_switchdev_event_work(struct work_struct *work)
dp = dsa_user_to_port(dev);
ds = dp->ds;
+ /* Gone if the port left the bridge after the event was queued:
+ * dsa_port_bridge_destroy() clears it before it flushes the workqueue
+ */
+ bridge = READ_ONCE(dp->bridge);
+ if (!bridge)
+ goto out;
+
switch (switchdev_work->event) {
case SWITCHDEV_FDB_ADD_TO_DEVICE:
if (switchdev_work->host_addr)
- err = dsa_port_bridge_host_fdb_add(dp, addr, vid);
+ err = dsa_port_bridge_host_fdb_add(dp, bridge, addr,
+ vid);
else if (dp->lag)
- err = dsa_port_lag_fdb_add(dp, addr, vid);
+ err = dsa_port_lag_fdb_add(dp, bridge, addr, vid);
else
- err = dsa_port_fdb_add(dp, addr, vid);
+ err = dsa_port_fdb_add(dp, bridge, addr, vid);
if (err) {
dev_err(ds->dev,
"port %d failed to add %pM vid %d to fdb: %d\n",
@@ -3672,11 +3681,12 @@ static void dsa_user_switchdev_event_work(struct work_struct *work)
case SWITCHDEV_FDB_DEL_TO_DEVICE:
if (switchdev_work->host_addr)
- err = dsa_port_bridge_host_fdb_del(dp, addr, vid);
+ err = dsa_port_bridge_host_fdb_del(dp, bridge, addr,
+ vid);
else if (dp->lag)
- err = dsa_port_lag_fdb_del(dp, addr, vid);
+ err = dsa_port_lag_fdb_del(dp, bridge, addr, vid);
else
- err = dsa_port_fdb_del(dp, addr, vid);
+ err = dsa_port_fdb_del(dp, bridge, addr, vid);
if (err) {
dev_err(ds->dev,
"port %d failed to delete %pM vid %d from fdb: %d\n",
@@ -3686,6 +3696,7 @@ static void dsa_user_switchdev_event_work(struct work_struct *work)
break;
}
+out:
kfree(switchdev_work);
}
@@ -3718,7 +3729,7 @@ static int dsa_user_fdb_event(struct net_device *dev,
if (ctx && ctx != dp)
return 0;
- if (!dp->bridge)
+ if (!READ_ONCE(dp->bridge))
return 0;
if (switchdev_fdb_is_dynamically_learned(fdb_info)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH net v3 3/3] net: dsa: forward a marked frame only while its port is in a bridge
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
2026-12-05 22:44 ` netdev-bot+sashiko
2 siblings, 1 reply; 5+ messages in thread
From: Julius Bairaktaris @ 2026-12-04 22:20 UTC (permalink / raw)
To: Andrew Lunn, Vladimir Oltean
Cc: netdev, bridge, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn, Simon Horman, Nikolay Aleksandrov,
Ido Schimmel, Alvin Šipraga, Florian Fainelli,
Tobias Waldekranz, Linus Walleij, Pawel Dembicki
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
^ permalink raw reply related [flat|nested] 5+ messages in thread