net: dsa: fix handling brentry vlans with flags
Subsystems (4)
cover net: dsa: fix handling brentry vlans with flags
While trying to figure out the hardware behavior of a DSA supported switch chip and printing various internal vlan state changes, I noticed that some flows never triggered adding the cpu port to vlans, preventing it from receiving any of the VLANs traffic.
E.g. the following sequence would cause the cpu port not being member of the vlan, despite the bridge vlan output looking correct:
$ ip link add swbridge type bridge vlan_filtering 1 vlan_default_pvid 1 $ ip link set lan1 master swbridge $ bridge vlan add dev lan1 vid 1 pvid untagged $ bridge vlan add dev swbridge vid 1 pvid untagged self
Adding more printk debugging, I traced it br_vlan_add_existing() setting changed to true (since the vlan "gained" the pvid untagged flags), and then the dsa code ignoring the vlan notification, since it is a vlan for the cpu port that is updated.
Then I noticed that deleting that vlan didn't work either:
$ bridge vlan port vlan-id lan1 1 PVID Egress Untagged swbridge 1 PVID Egress Untagged $ bridge vlan del dev swbridge vid 1 self $ bridge vlan port vlan-id lan1 1 PVID Egress Untagged swbridge 1 Egress Untagged
which is caused by the same issue, because from the dsa standpoint I am now trying to delete a non-existing vlan.
After fixing that, both were now correctly working, but the configured vlan on the cpu port would be stuck with whatever the initial add set.
E.g.:
$ bridge vlan add dev swbridge vid 1 pvid untagged self $ bridge vlan add dev swbridge vid 1 self
would change the flags in the vlandb, but the hardware configured vlan would still untag at egress to the cpu port.
Patch two fixes this by allowing changed = true vlan add notifications for the cpu port, but skip the refcounting. Presumably with the patch there should never be a vlan add notification for the brentry with changed set to true anymore.
In case my reasoning is wrong, I added a WARN_ON(), but I didn't get to trigger it so far.
I did a check of all handlers of switchdev port vlan add notifications, but DSA seems to be the only one that even looks at the changed flag.
Sent as RFC as I am not too familiar with the dsa/vlan code, so I might very well have overlooked something.
Jonas Gorski (2):
net: bridge: switchdev: do not notify new brentries as changed
net: dsa: propagate brentry flag changes
net/bridge/br_vlan.c | 4 +++- net/dsa/switch.c | 22 ++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-)
Signature · 1 line
2.43.0
RFC PATCH 1/2 net: bridge: switchdev: do not notify new brentries as changed
When adding a bridge vlan that is pvid or untagged after the vlan has already been added to any other switchdev backed port, the vlan change will be propagated as changed, since the flags change.
This causes the vlan to not be added to the hardware for DSA switches, since the DSA handler ignores any vlans for the CPU or DSA ports that are changed.
E.g. the following order of operations would work:
$ ip link add swbridge type bridge vlan_filtering 1 vlan_default_pvid 1 $ ip link set lan1 master swbridge $ bridge vlan add dev swbridge vid 1 pvid untagged self $ bridge vlan add dev lan1 vid 1 pvid untagged
but this order would brake:
$ ip link add swbridge type bridge vlan_filtering 1 vlan_default_pvid 1 $ ip link set lan1 master swbridge $ bridge vlan add dev lan1 vid 1 pvid untagged $ bridge vlan add dev swbridge vid 1 pvid untagged self
Additionally, the vlan on the bridge itself would become undeletable:
$ bridge vlan port vlan-id lan1 1 PVID Egress Untagged swbridge 1 PVID Egress Untagged $ bridge vlan del dev swbridge vid 1 self $ bridge vlan port vlan-id lan1 1 PVID Egress Untagged swbridge 1 Egress Untagged
since the vlan was never added to DSA's vlan list, so deleting it will cause an error, causing the bridge code to not remove it.
Fix this by checking if flags changed only for vlans that are already brentry and pass changed as false for those that become brentries, as these are a new vlan (member) from the switchdev point of view.
--- net/bridge/br_vlan.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/bridge/br_vlan.c +3 -1
@@ -715,8 +715,8 @@ static int br_vlan_add_existing(struct net_bridge *br, u16 flags, bool *changed, struct netlink_ext_ack *extack) { - bool would_change = __vlan_flags_would_change(vlan, flags); bool becomes_brentry = false; +bool would_change = false;int err;if (!br_vlan_is_brentry (vlan)) {
@@ -725,6 +725,8 @@ static int br_vlan_add_existing(struct net_bridge *br,return -EINVAL ; becomes_brentry = true; + }else { + would_change =__vlan_flags_would_change (vlan, flags); }/* Master VLANs that aren't brentries weren't notified before,
Signature · 1 line
2.43.0
Re: [PATCH RFC net 1/2] net: bridge: switchdev: do not notify new brentries as changed
Quoted 8 lines · Jonas Gorski
When adding a bridge vlan that is pvid or untagged after the vlan has already been added to any other switchdev backed port, the vlan change will be propagated as changed, since the flags change.
This causes the vlan to not be added to the hardware for DSA switches, since the DSA handler ignores any vlans for the CPU or DSA ports that are changed.
Quoted 8 lines
E.g. the following order of operations would work:
$ ip link add swbridge type bridge vlan_filtering 1 vlan_default_pvid 1 $ ip link set lan1 master swbridge $ bridge vlan add dev swbridge vid 1 pvid untagged self $ bridge vlan add dev lan1 vid 1 pvid untaggedbut this order would brake:
nitpick: s/brake/break/
Quoted 57 lines
$ ip link add swbridge type bridge vlan_filtering 1 vlan_default_pvid 1 $ ip link set lan1 master swbridge $ bridge vlan add dev lan1 vid 1 pvid untagged $ bridge vlan add dev swbridge vid 1 pvid untagged selfAdditionally, the vlan on the bridge itself would become undeletable:
$ bridge vlan port vlan-id lan1 1 PVID Egress Untagged swbridge 1 PVID Egress Untagged $ bridge vlan del dev swbridge vid 1 self $ bridge vlan port vlan-id lan1 1 PVID Egress Untagged swbridge 1 Egress Untaggedsince the vlan was never added to DSA's vlan list, so deleting it will cause an error, causing the bridge code to not remove it.
Fix this by checking if flags changed only for vlans that are already brentry and pass changed as false for those that become brentries, as these are a new vlan (member) from the switchdev point of view.
Fixes 8d23a54f5bee ("net: bridge: switchdev: differentiate new VLANs from changed ones")Signed-off-by Jonas Gorski <[email protected]>--- net/bridge/br_vlan.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/bridge/br_vlan.c +3
-1@@ -715,8 +715,8 @@ static int br_vlan_add_existing(struct net_bridge *br, u16 flags, bool *changed, struct netlink_ext_ack *extack) { - bool would_change = __vlan_flags_would_change(vlan, flags); bool becomes_brentry = false; +bool would_change = false;int err;if (!br_vlan_is_brentry (vlan)) {@@ -725,6 +725,8 @@ static int br_vlan_add_existing(struct net_bridge *br,return -EINVAL ; becomes_brentry = true; + }else { + would_change =__vlan_flags_would_change (vlan, flags); }/* Master VLANs that aren't brentries weren't notified before, Signature · 1 line
2.43.0
You might want to mention that "bool *changed" is used later in br_process_vlan_info() to make a decision whether to call br_vlan_notify(RTM_NEWVLAN) or not. We want to notify switchdev with changed=false, but we want to keep notifying the change to rtnetlink.
The rtnetlink notification still happens even if we don't set would_change here, because it depends on this code snippet:
if (becomes_brentry) {
...
*changed = true;
...
}and not on this one:
if (would_change) *changed = true;
That was my only concern with this change (I had missed the first snippet when initially reading the code), and I didn't see in the commit log some sort of attention paid to this detail.
With that:
Re: [PATCH RFC net 1/2] net: bridge: switchdev: do not notify new brentries as changed
Quoted 6 lines · Vladimir Oltean
Quoted 4 lines · Jonas Gorski
When adding a bridge vlan that is pvid or untagged after the vlan has already been added to any other switchdev backed port, the vlan change will be propagated as changed, since the flags change.
Quoted 7 lines
Quoted 7 lines
This causes the vlan to not be added to the hardware for DSA switches, since the DSA handler ignores any vlans for the CPU or DSA ports that are changed.
E.g. the following order of operations would work:
$ ip link add swbridge type bridge vlan_filtering 1 vlan_default_pvid 1
as mentioned for the cover letter, I will fix the example to use default_pvid 0 to have a "working" example.
Quoted 7 lines
Quoted 5 lines
$ ip link set lan1 master swbridge $ bridge vlan add dev swbridge vid 1 pvid untagged self $ bridge vlan add dev lan1 vid 1 pvid untaggedbut this order would brake:
nitpick: s/brake/break/
Thanks, :set spell clearly didn't help here.
Quoted 71 lines
Quoted 54 lines
$ ip link add swbridge type bridge vlan_filtering 1 vlan_default_pvid 1 $ ip link set lan1 master swbridge $ bridge vlan add dev lan1 vid 1 pvid untagged $ bridge vlan add dev swbridge vid 1 pvid untagged selfAdditionally, the vlan on the bridge itself would become undeletable:
$ bridge vlan port vlan-id lan1 1 PVID Egress Untagged swbridge 1 PVID Egress Untagged $ bridge vlan del dev swbridge vid 1 self $ bridge vlan port vlan-id lan1 1 PVID Egress Untagged swbridge 1 Egress Untaggedsince the vlan was never added to DSA's vlan list, so deleting it will cause an error, causing the bridge code to not remove it.
Fix this by checking if flags changed only for vlans that are already brentry and pass changed as false for those that become brentries, as these are a new vlan (member) from the switchdev point of view.
Fixes 8d23a54f5bee ("net: bridge: switchdev: differentiate new VLANs from changed ones")Signed-off-by Jonas Gorski <[email protected]>--- net/bridge/br_vlan.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/bridge/br_vlan.c +3
-2@@ -715,8 +715,8 @@ static int br_vlan_add_existing(struct net_bridge *br, u16 flags, bool *changed, struct netlink_ext_ack *extack) { - bool would_change = __vlan_flags_would_change(vlan, flags); bool becomes_brentry = false; +bool would_change = false;int err;if (!br_vlan_is_brentry (vlan)) {@@ -725,6 +725,8 @@ static int br_vlan_add_existing(struct net_bridge *br,return -EINVAL ; becomes_brentry = true; + }else { + would_change =__vlan_flags_would_change (vlan, flags); }/* Master VLANs that aren't brentries weren't notified before, -- Quoted 2 lines
2.43.0
You might want to mention that "bool *changed" is used later in
br_process_vlan_info()to make a decision whether to callbr_vlan_notify(RTM_NEWVLAN)or not. We want to notify switchdev with changed=false, but we want to keep notifying the change to rtnetlink.The rtnetlink notification still happens even if we don't set
would_changehere, because it depends on this code snippet:if (becomes_brentry) { ... *changed = true; ... }
Quoted 8 lines
and not on this one:
if (would_change) *changed = true;That was my only concern with this change (I had missed the first snippet when initially reading the code), and I didn't see in the commit log some sort of attention paid to this detail.
Will add it. And I did check that, even considered shortly to merge this to
if (becomes_brentry || would_change)
*changed = true;but then considered that a refactoring too much.
Quoted 4 lines
With that:
Reviewed-by Vladimir Oltean <[email protected]>
Thank you!
Re: [PATCH RFC net 1/2] net: bridge: switchdev: do not notify new brentries as changed
Quoted 5 lines · Jonas Gorski
Quoted 1 line · On Mon, Apr 14, 2025 at 1:39 PM Vladimir Oltean <[email protected]>…
Quoted 1 line
$ ip link add swbridge type bridge vlan_filtering 1 vlan_default_pvid 1as mentioned for the cover letter, I will fix the example to use
default_pvid0 to have a "working" example.
Please do so. You have consistently given examples with vlan_default_pvid 1 throughout the patch set.
Quoted 6 lines
Will add it. And I did check that, even considered shortly to merge this to
if (becomes_brentry || would_change) *changed = true;but then considered that a refactoring too much.
I agree that it would be an unnecessary change for 'net'. You can send a refactoring patch for net-next after Thursday, though.
RFC PATCH 2/2 net: dsa: propagate brentry flag changes
In reply to Jonas GorskiCurrently any flag changes for brentry vlans are ignored, so the configured cpu port vlan will get stuck at whatever the original flags were.
E.g.
$ bridge vlan add dev swbridge vid 10 self pvid untagged $ bridge vlan add dev swbridge vid 10 self
Would cause the vlan to get "stuck" at pvid untagged in the hardware, despite now being configured as tagged on the bridge.
Fix this by passing on changed vlans to drivers, but do not increase the refcount for updates.
Since we should never get an update for a non-existing VLAN, add a WARN_ON() in case it happens.
--- net/dsa/switch.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
net/dsa/switch.c +12 -10
@@ -702,23 +702,25 @@ static int dsa_port_do_vlan_add(struct dsa_port *dp,return err; } -/* No need to propagate on shared ports the existing VLANs that were -* re-notified after just the flags have changed. This would cause a -* refcount bump which we need to avoid, since it unbalances the -* additions with the deletions. -*/ -if (vlan->changed) -return 0 ; -mutex_lock (&dp->vlans_lock); v =dsa_vlan_find (&dp->vlans, vlan);if (v) { -refcount_inc (&v->refcount); -trace_dsa_vlan_add_bump (dp, vlan, &v->refcount); +/* Do not update the refcount for updated VLANs. This would +* cause an imbalance with deletions. +*/ +if (vlan->changed) { + err = ds->ops->port_vlan_add (ds, port, vlan, extack); +trace_dsa_vlan_add_hw (dp, vlan, err); + }else { +refcount_inc (&v->refcount); +trace_dsa_vlan_add_bump (dp, vlan, &v->refcount); + } goto out; } +WARN_ON (vlan->changed); + v =kzalloc (sizeof (*v),GFP_KERNEL );if (!v) { err = -ENOMEM ;
Signature · 1 line
2.43.0
Re: [PATCH RFC net 2/2] net: dsa: propagate brentry flag changes
Quoted 15 lines · Jonas Gorski
Currently any flag changes for brentry vlans are ignored, so the configured cpu port vlan will get stuck at whatever the original flags were.
E.g.
$ bridge vlan add dev swbridge vid 10 self pvid untagged $ bridge vlan add dev swbridge vid 10 selfWould cause the vlan to get "stuck" at pvid untagged in the hardware, despite now being configured as tagged on the bridge.
Fix this by passing on changed vlans to drivers, but do not increase the refcount for updates.
Quoted 6 lines
Since we should never get an update for a non-existing VLAN, add a
WARN_ON()in case it happens.Fixes 134ef2388e7f ("net: dsa: add explicit support for host bridge VLANs")Signed-off-by Jonas Gorski <[email protected]>---
I think it's important to realize that the meaning of the "flags" of VLANs offloaded to the CPU port is not completely defined. "egress-untagged" from the perspective of the hardware CPU port is the opposite direction compared to "egress-untagged" from the perspective of the bridge device (one is Linux RX, the other is Linux TX).
Additionally, we install in DSA as host VLANs also those bridge port VLANs which were configured by the user on foreign interfaces. It's not exactly clear how to reconcile the "flags" of a VLAN installed on the bridge itself with the "flags" of a VLAN installed on a foreign bridge port.
Example:
ip link add br0 type bridge vlan_filtering 1 vlan_default_pvid 0
ip link set veth0 master br0 # foreign interface, unrelated to DSA
ip link set swp0 master br0 # DSA interface
bridge vlan add dev br0 vid 1 self pvid untagged # leads to an "dsa_vlan_add_hw: cpu port N vid 1 untagged" trace event bridge vlan add dev veth0 vid 1 # still leads to an "dsa_vlan_add_bump: cpu port N vid 1 refcount 2" trace event after your change
Depending on your expectations, you might think that host VID 1 would also need to become egress-tagged in this case, although from the bridge's perspective, it hasn't "changed", because it is a VLAN from a different VLAN group (port veth0 vs bridge br0).
The reverse is true as well. Because the user can toggle the "pvid" flag of the bridge VLAN, that will make the switchdev object be notified with changed=true. But since DSA clears BRIDGE_VLAN_INFO_PVID, the host VLAN, as programmed to hardware, would be identical, yet we reprogram it anyway.
Both would seem to indicate that "changed" from the bridge perspective is not what matters for calling the driver, but a different "changed" flag, calculated by DSA from its own perspective.
I was a bit reluctant to add such complexity in dsa_port_do_vlan_add(), considering that many drivers treat the VLANs on the CPU port as always-tagged towards software (not b53 though, except for b53_vlan_port_needs_forced_tagged() which is only for DSA_TAG_PROTO_NONE). In fact, what is not entirely clear to me is what happens if they _don't_ treat the CPU port in a special way. Because software needs to know in which VLAN did the hardware begin to process a packet: if the software bridge needs to continue the processing of that packet, it needs to do so _in the same VLAN_. If the accelerator sends packets as VLAN-untagged to software, that information is lost and VLAN hopping might take place. So I was hoping that nobody would notice that the change of flags on host VLANs isn't propagated to drivers, because none of the flags should be of particular relevance in the first place.
I would like to understand better, in terms of user-visible impact, what is the problem that you see?
Re: [PATCH RFC net 2/2] net: dsa: propagate brentry flag changes
+Jonas, whom I've mistakenly removed from To: :-/
Quoted 71 lines · Vladimir Oltean
Quoted 15 lines · Jonas Gorski
Currently any flag changes for brentry vlans are ignored, so the configured cpu port vlan will get stuck at whatever the original flags were.
E.g.
$ bridge vlan add dev swbridge vid 10 self pvid untagged $ bridge vlan add dev swbridge vid 10 selfWould cause the vlan to get "stuck" at pvid untagged in the hardware, despite now being configured as tagged on the bridge.
Fix this by passing on changed vlans to drivers, but do not increase the refcount for updates.
Quoted 6 lines
Since we should never get an update for a non-existing VLAN, add a
WARN_ON()in case it happens.Fixes 134ef2388e7f ("net: dsa: add explicit support for host bridge VLANs")Signed-off-by Jonas Gorski <[email protected]>---
I think it's important to realize that the meaning of the "flags" of VLANs offloaded to the CPU port is not completely defined. "egress-untagged" from the perspective of the hardware CPU port is the opposite direction compared to "egress-untagged" from the perspective of the bridge device (one is Linux RX, the other is Linux TX).
Additionally, we install in DSA as host VLANs also those bridge port VLANs which were configured by the user on foreign interfaces. It's not exactly clear how to reconcile the "flags" of a VLAN installed on the bridge itself with the "flags" of a VLAN installed on a foreign bridge port.
Example:
ip link add br0 type bridgevlan_filtering1vlan_default_pvid0
ip link set veth0 master br0 # foreign interface, unrelated to DSA
ip link set swp0 master br0 # DSA interface
bridge vlan add dev br0 vid 1 self pvid untagged # leads to an "dsa_vlan_add_hw: cpu port N vid 1 untagged" trace event bridge vlan add dev veth0 vid 1 # still leads to an "dsa_vlan_add_bump: cpu port N vid 1 refcount 2" trace event after your changeDepending on your expectations, you might think that host VID 1 would also need to become egress-tagged in this case, although from the bridge's perspective, it hasn't "changed", because it is a VLAN from a different VLAN group (port veth0 vs bridge br0).
The reverse is true as well. Because the user can toggle the "pvid" flag of the bridge VLAN, that will make the switchdev object be notified with changed=true. But since DSA clears
BRIDGE_VLAN_INFO_PVID, the host VLAN, as programmed to hardware, would be identical, yet we reprogram it anyway.Both would seem to indicate that "changed" from the bridge perspective is not what matters for calling the driver, but a different "changed" flag, calculated by DSA from its own perspective.
I was a bit reluctant to add such complexity in
dsa_port_do_vlan_add(), considering that many drivers treat the VLANs on the CPU port as always-tagged towards software (not b53 though, except forb53_vlan_port_needs_forced_tagged()which is only forDSA_TAG_PROTO_NONE). In fact, what is not entirely clear to me is what happens if they _don't_ treat the CPU port in a special way. Because software needs to know in which VLAN did the hardware begin to process a packet: if the software bridge needs to continue the processing of that packet, it needs to do so_inthe sameVLAN_. If the accelerator sends packets as VLAN-untagged to software, that information is lost and VLAN hopping might take place. So I was hoping that nobody would notice that the change of flags on host VLANs isn't propagated to drivers, because none of the flags should be of particular relevance in the first place.I would like to understand better, in terms of user-visible impact, what is the problem that you see?
Re: [PATCH RFC net 2/2] net: dsa: propagate brentry flag changes
Quoted 75 lines · Vladimir Oltean
+Jonas, whom I've mistakenly removed from To: :-/
Quoted 71 lines · Vladimir Oltean
Quoted 15 lines · Jonas Gorski
Currently any flag changes for brentry vlans are ignored, so the configured cpu port vlan will get stuck at whatever the original flags were.
E.g.
$ bridge vlan add dev swbridge vid 10 self pvid untagged $ bridge vlan add dev swbridge vid 10 selfWould cause the vlan to get "stuck" at pvid untagged in the hardware, despite now being configured as tagged on the bridge.
Fix this by passing on changed vlans to drivers, but do not increase the refcount for updates.
Quoted 6 lines
Since we should never get an update for a non-existing VLAN, add a
WARN_ON()in case it happens.Fixes 134ef2388e7f ("net: dsa: add explicit support for host bridge VLANs")Signed-off-by Jonas Gorski <[email protected]>---
I think it's important to realize that the meaning of the "flags" of VLANs offloaded to the CPU port is not completely defined. "egress-untagged" from the perspective of the hardware CPU port is the opposite direction compared to "egress-untagged" from the perspective of the bridge device (one is Linux RX, the other is Linux TX).
Additionally, we install in DSA as host VLANs also those bridge port VLANs which were configured by the user on foreign interfaces. It's not exactly clear how to reconcile the "flags" of a VLAN installed on the bridge itself with the "flags" of a VLAN installed on a foreign bridge port.
Example:
ip link add br0 type bridgevlan_filtering1vlan_default_pvid0
ip link set veth0 master br0 # foreign interface, unrelated to DSA
ip link set swp0 master br0 # DSA interface
bridge vlan add dev br0 vid 1 self pvid untagged # leads to an "dsa_vlan_add_hw: cpu port N vid 1 untagged" trace event bridge vlan add dev veth0 vid 1 # still leads to an "dsa_vlan_add_bump: cpu port N vid 1 refcount 2" trace event after your changeDepending on your expectations, you might think that host VID 1 would also need to become egress-tagged in this case, although from the bridge's perspective, it hasn't "changed", because it is a VLAN from a different VLAN group (port veth0 vs bridge br0).
The reverse is true as well. Because the user can toggle the "pvid" flag of the bridge VLAN, that will make the switchdev object be notified with changed=true. But since DSA clears
BRIDGE_VLAN_INFO_PVID, the host VLAN, as programmed to hardware, would be identical, yet we reprogram it anyway.Both would seem to indicate that "changed" from the bridge perspective is not what matters for calling the driver, but a different "changed" flag, calculated by DSA from its own perspective.
I was a bit reluctant to add such complexity in
dsa_port_do_vlan_add(), considering that many drivers treat the VLANs on the CPU port as always-tagged towards software (not b53 though, except forb53_vlan_port_needs_forced_tagged()which is only forDSA_TAG_PROTO_NONE). In fact, what is not entirely clear to me is what happens if they _don't_ treat the CPU port in a special way. Because software needs to know in which VLAN did the hardware begin to process a packet: if the software bridge needs to continue the processing of that packet, it needs to do so_inthe sameVLAN_. If the accelerator sends packets as VLAN-untagged to software, that information is lost and VLAN hopping might take place. So I was hoping that nobody would notice that the change of flags on host VLANs isn't propagated to drivers, because none of the flags should be of particular relevance in the first place.I would like to understand better, in terms of user-visible impact, what is the problem that you see?
I was just in the progress of writing down some thoughts myself I had while thinking about this.
So to me passing on the original flags but then no updates of these flags feels wrong. I would expect them to be either never passed on, or always sync it (and let the driver choose to handle or ignore them).
Having the cpu port as egress untagged I can easily find one case where this breaks stuff (at least with b53):
With lan1, lan2 being dsa ports of the same switch:
# bridge with lan1 $ ip link add swbridge type bridge vlan_filtering 1 $ ip link set lan1 master swbridge $ bridge vlan add dev swbridge vid 10 self pvid untagged
# lan2 stand alone $ ip link add lan2.10 link lan2 type vlan id 10
as then lan2.10 would never receive any packets, as the VLAN 10 packets received by the CPU ports never carry any vlan tags.
The core issue here is that b53 switches do not provide any way of knowing the original tagged state of received packets, as the dsa header has no field for that (bcm56* switches do, but these are a different beast).
I guess the proper fix for b53 is probably to always have a vlan tag on the cpu port (except for the special vlan 0 for untagged traffic on ports with no PVID), and enable untag_vlan_aware_bridge_pvid.
To continue the stream of consciousness, it probably does not make sense to pass on the untagged flag for the bridge/cpu port, because it will affect all ports of the switch, regardless of them being member of the bridge. Looking through drivers in net/drivers/dsa, I don't see anyone checking if egress untag is applied to the cpu port, so I wonder if not most, maybe even all (dsa) switch drivers have the same issue and would actually need to keep the cpu port always tagged. And looking through the tag_* handlers, only ocelot looks like it may have the information available whether a packet was originally tagged or not, so would also need to have untag_vlan_aware_bridge_pvid enabled.
Makes the think the cpu port always tagged should be the default behavior. It's easy to strip a vlan tag that shouldn't be there, but hard to add one that's missing, especially since in contrast to PVID you can have more than one vlan as egress untagged.
Jonas
Re: [PATCH RFC net 2/2] net: dsa: propagate brentry flag changes
Quoted 7 lines · Jonas Gorski
I was just in the progress of writing down some thoughts myself I had while thinking about this.
So to me passing on the original flags but then no updates of these flags feels wrong. I would expect them to be either never passed on, or always sync it (and let the driver choose to handle or ignore them).
Maybe, but right now it seems like the wrong problem to tackle, and it is probably so for every driver for which the VLAN information in the receive traffic depends on the bridge VLAN configuration, and is not statically configured by the driver.
Quoted 13 lines
Having the cpu port as egress untagged I can easily find one case where this breaks stuff (at least with b53):
With lan1, lan2 being dsa ports of the same switch:
# bridge with lan1 $ ip link add swbridge type bridge vlan_filtering 1 $ ip link set lan1 master swbridge $ bridge vlan add dev swbridge vid 10 self pvid untagged# lan2 stand alone $ ip link add lan2.10 link lan2 type vlan id 10
Quoted 7 lines
as then lan2.10 would never receive any packets, as the VLAN 10 packets received by the CPU ports never carry any vlan tags.
The core issue here is that b53 switches do not provide any way of knowing the original tagged state of received packets, as the dsa header has no field for that (bcm56* switches do, but these are a different beast).
I see, and indeed, this is yet another angle. The flags of the host bridge VLAN do not match with the flags of the flags of the RX filtering VLAN, the latter having this comment: "This API only allows programming tagged, non-PVID VIDs". The update of flags would not be propagated to the driver, neither with your patch nor without it, because VID=10 already exists on the CPU port, and this isn't a "changed" VLAN (because it is an artificial switchdev event emitted by DSA, unbeknownst to the bridge). So DSA would still decide to bump the refcount rather than notify the driver.
You'd have to ask yourself how do you even expect DSA to react and sort this out, between the bridge direction wanting the VLAN untagged and the 8021q direction wanting it tagged.
Quoted 3 lines
I guess the proper fix for b53 is probably to always have a vlan tag on the cpu port (except for the special vlan 0 for untagged traffic on ports with no PVID), and enable
untag_vlan_aware_bridge_pvid.
What's the story with the ports with no PVID, and VID 0?
In Documentation/networking/switchdev.rst, it is said that VLAN filtering bridge ports should drop untagged and VID 0 tagged RX packets when there is no pvid.
Quoted 4 lines
To continue the stream of consciousness, it probably does not make sense to pass on the untagged flag for the bridge/cpu port, because it will affect all ports of the switch, regardless of them being member of the bridge.
Though it needs to be said, usually standalone ports are VLAN-unaware, thus, the VLAN ID on RX from their direction is a discardable quantity.
b53 is one of the special drivers, for setting ds->vlan_filtering_is_global = true. That makes standalone ports become VLAN filtering even when not under a bridge, and is what ultimately causes DSA to program RX filtering VLANs to hardware in the first place. Normally, 8021q uppers aren't programmed to hardware - see the comments above dsa_user_manage_vlan_filtering().
Quoted 4 lines
Looking through drivers in
net/drivers/dsa, I don't see anyone checking if egress untag is applied to the cpu port, so I wonder if not most, maybe even all (dsa) switch drivers have the same issue and would actually need to keep the cpu port always tagged.
What check do you expect to see exactly? Many drivers treat VLANs on the CPU port in special ways, sja1105, felix/ocelot, mv88e6xxx, mt7530, ksz8, maybe others. Some of them are subtle and not easy to spot, because they are not from the .port_vlan_add() call path (like felix_update_tag_8021q_rx_rule()).
Quoted 3 lines
And looking through the tag_* handlers, only ocelot looks like it may have the information available whether a packet was originally tagged or not, so would also need to have
untag_vlan_aware_bridge_pvidenabled.
ocelot can select between 2 different tagging protocols, "ocelot" (which leaves the VLAN header unmodified) and "ocelot-8021q" (which does not), and the latter indeed does set untag_vlan_aware_bridge_pvid. It's an option from which more than one driver could benefit, though, for sure.
mv88e6xxx uses MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIED which provides essentially that information, neither "tag" nor "untag", but "keep".
Quoted 4 lines
Makes the think the cpu port always tagged should be the default behavior. It's easy to strip a vlan tag that shouldn't be there, but hard to add one that's missing, especially since in contrast to PVID you can have more than one vlan as egress untagged.
I agree and I would like to see b53 converge towards that. But changing the default by unsetting this flag in DSA could be a breaking change, we should be careful, and definitely only consider that for net-next.
b53 already sets a form (the deprecated form) of ds->untag_bridge_pvid, someone with hardware should compare its behavior to the issues documented in dsa_software_untag_vlan_unaware_bridge(), and, if necessary, transition it to ds->untag_vlan_aware_bridge_pvid or perhaps something else.
There is a relevant selftest at tools/testing/selftests/net/forwarding/local_termination.sh which captures many (though not all) gotchas, it might be interesting to
run it.
Re: [PATCH RFC net 2/2] net: dsa: propagate brentry flag changes
Quoted 46 lines · Vladimir Oltean
Quoted 7 lines · Jonas Gorski
I was just in the progress of writing down some thoughts myself I had while thinking about this.
So to me passing on the original flags but then no updates of these flags feels wrong. I would expect them to be either never passed on, or always sync it (and let the driver choose to handle or ignore them).
Maybe, but right now it seems like the wrong problem to tackle, and it is probably so for every driver for which the VLAN information in the receive traffic depends on the bridge VLAN configuration, and is not statically configured by the driver.
Quoted 13 lines
Having the cpu port as egress untagged I can easily find one case where this breaks stuff (at least with b53):
With lan1, lan2 being dsa ports of the same switch:
# bridge with lan1 $ ip link add swbridge type bridge vlan_filtering 1 $ ip link set lan1 master swbridge $ bridge vlan add dev swbridge vid 10 self pvid untagged# lan2 stand alone $ ip link add lan2.10 link lan2 type vlan id 10Quoted 7 lines
as then lan2.10 would never receive any packets, as the VLAN 10 packets received by the CPU ports never carry any vlan tags.
The core issue here is that b53 switches do not provide any way of knowing the original tagged state of received packets, as the dsa header has no field for that (bcm56* switches do, but these are a different beast).
I see, and indeed, this is yet another angle. The flags of the host bridge VLAN do not match with the flags of the flags of the RX filtering VLAN, the latter having this comment: "This API only allows programming tagged, non-PVID VIDs". The update of flags would not be propagated to the driver, neither with your patch nor without it, because VID=10 already exists on the CPU port, and this isn't a "changed" VLAN (because it is an artificial switchdev event emitted by DSA, unbeknownst to the bridge). So DSA would still decide to bump the refcount rather than notify the driver.
Quoted 3 lines
You'd have to ask yourself how do you even expect DSA to react and sort this out, between the bridge direction wanting the VLAN untagged and the 8021q direction wanting it tagged.
Unless the switch chip supports passing frames as is to the cpu port (and only there), the only winning move is likely to keep the cpu port tagged in all cases, and untag in software as needed. I guess this is what untag_vlan_aware_bridge_pvid is for.
As a side note, b53 datasheets state that all vlans are always tagged on egress and ignore the untag map for the management port, but that is clearly not the case for most devices lol.
I am still a bit confused by untag_bridge_pvid, or more specifically dsa_software_untag_vlan_unaware_bridge(). I would have expected a non vlan_filtering bridge to ignore any vlan configuration, including PVID. Or rather the PVID is implicit by a port being bridged with vlan uppers of a certain vid (e.g. port1.10 + port2 => port2 has PVID 10), but not explicitly via the bridge vlan configuration.
Quoted 8 lines
Quoted 3 lines
I guess the proper fix for b53 is probably to always have a vlan tag on the cpu port (except for the special vlan 0 for untagged traffic on ports with no PVID), and enable
untag_vlan_aware_bridge_pvid.What's the story with the ports with no PVID, and VID 0?
InDocumentation/networking/switchdev.rst, it is said that VLAN filtering bridge ports should drop untagged and VID 0 tagged RX packets when there is no pvid.
Hm, that's not what the code does:
With a vlan_filtering bridge VID 0 always gets added to bridge ports if they get set up:
The order is:
1. filtering is enabled on the port => NETIF_F_HW_VLAN_CTAG_FILTER is set
2. on if up, vlan_device_event() sees that NETIF_F_HW_VLAN_CTAG_FILTER is enabled and calls vlan_vid_add(dev, .., 0)
3. switchdev/dsa passes this on to the dsa driver via port_vlan_add()
4. all bridge ports being up are now members of vlan 0/have vlan 0 enabled.
Not sure if this is intended/expected behavior, but this enables untagged rx at least with b53. And since b53 can't restrict forwarding on a per-vlan base, likely enables forwarding between all bridge ports for untagged traffic (until a PVID vlan is configured on the bridge, then the untagged traffic is moved to a different port). This part is likely not intended.
My first guess was that this is intentional to allow STP & co to work regardless if there is a PVID/egress untagged VLAN configured. Though this will likely also require preventing of forwarding unless this is a configured bridge vlan. Currently trying to read 802.1Q-2022 to see if I find anything clearly stating how this should (not) work ... .
Quoted 5 lines
Quoted 4 lines
To continue the stream of consciousness, it probably does not make sense to pass on the untagged flag for the bridge/cpu port, because it will affect all ports of the switch, regardless of them being member of the bridge.
Quoted 8 lines
Though it needs to be said, usually standalone ports are VLAN-unaware, thus, the VLAN ID on RX from their direction is a discardable quantity.
b53 is one of the special drivers, for setting
ds->vlan_filtering_is_global= true. That makes standalone ports become VLAN filtering even when not under a bridge, and is what ultimately causes DSA to program RX filtering VLANs to hardware in the first place. Normally, 8021q uppers aren't programmed to hardware - see the comments abovedsa_user_manage_vlan_filtering().
That's unfortunately how the switch chip works, either you have filtering on all ports, or on none. Can't toggle it on a per-port base. The only exception is the CPU port, where you can at least allow it to send to any VLAN/port.
Quoted 9 lines
Quoted 4 lines
Looking through drivers in
net/drivers/dsa, I don't see anyone checking if egress untag is applied to the cpu port, so I wonder if not most, maybe even all (dsa) switch drivers have the same issue and would actually need to keep the cpu port always tagged.What check do you expect to see exactly? Many drivers treat VLANs on the CPU port in special ways, sja1105, felix/ocelot, mv88e6xxx, mt7530, ksz8, maybe others. Some of them are subtle and not easy to spot, because they are not from the .port_vlan_add() call path (like
felix_update_tag_8021q_rx_rule()).
I was mostly looking if .port_vlan_add() has some special handling for the cpu port as it gets called for vlans configured on the bridge port, and I didn't see anyone ignoring the untagged flag if programming the cpu port. Didn't look too deeply though.
Quoted 4 lines
Quoted 3 lines
And looking through the tag_* handlers, only ocelot looks like it may have the information available whether a packet was originally tagged or not, so would also need to have
untag_vlan_aware_bridge_pvidenabled.
Quoted 8 lines
ocelot can select between 2 different tagging protocols, "ocelot" (which leaves the VLAN header unmodified) and "ocelot-8021q" (which does not), and the latter indeed does set
untag_vlan_aware_bridge_pvid. It's an option from which more than one driver could benefit, though, for sure.mv88e6xxx uses
MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_UNMODIFIEDwhich provides essentially that information, neither "tag" nor "untag", but "keep".
Ah, I see, just checked the datasheet.
b53 also has a "keep unmodified" mode, but that is global and applies
to all ports, so an untagged at ingress frame then can never become egress tagged. Completely useless when also having a vlan filtering bridge.
Quoted 9 lines
Quoted 4 lines
Makes the think the cpu port always tagged should be the default behavior. It's easy to strip a vlan tag that shouldn't be there, but hard to add one that's missing, especially since in contrast to PVID you can have more than one vlan as egress untagged.
I agree and I would like to see b53 converge towards that. But changing the default by unsetting this flag in DSA could be a breaking change, we should be careful, and definitely only consider that for net-next.
Quoted 5 lines
b53 already sets a form (the deprecated form) of
ds->untag_bridge_pvid, someone with hardware should compare its behavior to the issues documented indsa_software_untag_vlan_unaware_bridge(), and, if necessary, transition it tods->untag_vlan_aware_bridge_pvidor perhaps something else.
This is for the case when you have a b53 switch behind a b53 switch, e.g.
sw0.port1..4 user ports
sw0.cpu -> sw1.port1
sw1.port2..4 user ports
sw1.cpu -> eth0
and you have user ports on both switches. Due to the way the broadcom tag works, if sw0 would be brcm tagged, then sw1 wouldn't see the vlan tag anymore on rx (since there will now be the brcm tag), and all traffic would go to the pvid of sw1.port1, thus any forwarding between ports of sw0 and sw1 would have to be done in software.
In this case, sw0 needs to have its traffic always tagged. Also sw1 needs to keep all vlans on port1 egress tagged, not sure if we actually take care of that ... (maybe the dsa code does that for us, didn't check).
Although forwarding works between user ports of sw0 and sw1, from the linux perspective we would never receive any traffic from sw0's ports, since we only have sw1's tag, and that one will say sw1.port1.
So while you may be able to configure vlans and forwarding, probably everything else won't work as expected. Like when you want to send out a packet on a certain port.
Though I assume this isn't a special issue for b53, and rather a common issue of chained switch chips, and b53 just acknowledges it / tries to work around it. I know that marvell (E)DSA can handle this, but I wouldn't be surprised if many others can't.
Looking at devices in OpenWrt that are affected by this, these device have exactly one user port on sw1, and that one is mostly used as a wan port, so as a stand-alone port, not a bridge port. One could argue here that proper functioning of the "outer" switch's ports is more important than being able to forward frames in hardware to the wan port.
Unfortunately I do not have a device at hand, might need to figure out if I can get my hands on one ... .
Best regards,
Jonas
Re: [PATCH RFC net 2/2] net: dsa: propagate brentry flag changes
Quoted 5 lines · Jonas Gorski
Quoted 3 lines · On Mon, Apr 14, 2025 at 5:07 PM Vladimir Oltean <[email protected]>…
You'd have to ask yourself how do you even expect DSA to react and sort this out, between the bridge direction wanting the VLAN untagged and the 8021q direction wanting it tagged.
Quoted 8 lines
Unless the switch chip supports passing frames as is to the cpu port (and only there), the only winning move is likely to keep the cpu port tagged in all cases, and untag in software as needed. I guess this is what
untag_vlan_aware_bridge_pvidis for.As a side note, b53 datasheets state that all vlans are always tagged on egress and ignore the untag map for the management port, but that is clearly not the case for most devices lol.
So it's in fact not a problem, am I reading this right?
Quoted 6 lines
I am still a bit confused by
untag_bridge_pvid, or more specificallydsa_software_untag_vlan_unaware_bridge(). I would have expected a nonvlan_filteringbridge to ignore any vlan configuration, including PVID. Or rather the PVID is implicit by a port being bridged with vlan uppers of a certain vid (e.g. port1.10 + port2 => port2 has PVID 10), but not explicitly via the bridge vlan configuration.
I think dsa_software_untag_vlan_unaware_bridge() exists in this form only as a result of the misunderstanding that the bridge PVID must not be committed to hardware in vlan_filtering=0 mode. Otherwise, it is a coincidence that the bridge PVID == the VID added by hardware to packets in VLAN-unaware bridging mode.
See the reference to ds->ops->get_private_vid() if you need to pop a driver-specific VID from packets received from VLAN-unaware bridge ports, VID which is not necessarily equal to the bridge PVID.
Quoted 29 lines
Quoted 8 lines
Quoted 3 lines
I guess the proper fix for b53 is probably to always have a vlan tag on the cpu port (except for the special vlan 0 for untagged traffic on ports with no PVID), and enable
untag_vlan_aware_bridge_pvid.What's the story with the ports with no PVID, and VID 0?
InDocumentation/networking/switchdev.rst, it is said that VLAN filtering bridge ports should drop untagged and VID 0 tagged RX packets when there is no pvid.Hm, that's not what the code does:
With a
vlan_filteringbridge VID 0 always gets added to bridge ports if they get set up:The order is:
1. filtering is enabled on the port =>
NETIF_F_HW_VLAN_CTAG_FILTERis set
2. on if up,vlan_device_event()sees thatNETIF_F_HW_VLAN_CTAG_FILTERis enabled and callsvlan_vid_add(dev, .., 0)
3. switchdev/dsa passes this on to the dsa driver viaport_vlan_add()
4. all bridge ports being up are now members of vlan 0/have vlan 0 enabled.Not sure if this is intended/expected behavior, but this enables untagged rx at least with b53. And since b53 can't restrict forwarding on a per-vlan base, likely enables forwarding between all bridge ports for untagged traffic (until a PVID vlan is configured on the bridge, then the untagged traffic is moved to a different port). This part is likely not intended.
Quoted 5 lines
My first guess was that this is intentional to allow STP & co to work regardless if there is a PVID/egress untagged VLAN configured. Though this will likely also require preventing of forwarding unless this is a configured bridge vlan. Currently trying to read 802.1Q-2022 to see if I find anything clearly stating how this should (not) work ... .
Not replying to this, as this discussion continued in the other thread.
Quoted 22 lines
Quoted 9 lines
Quoted 4 lines
Makes the think the cpu port always tagged should be the default behavior. It's easy to strip a vlan tag that shouldn't be there, but hard to add one that's missing, especially since in contrast to PVID you can have more than one vlan as egress untagged.
I agree and I would like to see b53 converge towards that. But changing the default by unsetting this flag in DSA could be a breaking change, we should be careful, and definitely only consider that for net-next.
Quoted 5 lines
b53 already sets a form (the deprecated form) of
ds->untag_bridge_pvid, someone with hardware should compare its behavior to the issues documented indsa_software_untag_vlan_unaware_bridge(), and, if necessary, transition it tods->untag_vlan_aware_bridge_pvidor perhaps something else.This is for the case when you have a b53 switch behind a b53 switch, e.g.
sw0.port1..4 user ports
sw0.cpu -> sw1.port1
sw1.port2..4 user ports
sw1.cpu -> eth0
Quoted 5 lines
and you have user ports on both switches. Due to the way the broadcom tag works, if sw0 would be brcm tagged, then sw1 wouldn't see the vlan tag anymore on rx (since there will now be the brcm tag), and all traffic would go to the pvid of sw1.port1, thus any forwarding between ports of sw0 and sw1 would have to be done in software.
Can sw0 be brcm-tagged in another way that allows sw1 to see VLAN tags? Like with brcm-legacy perhaps?
Quoted 4 lines
In this case, sw0 needs to have its traffic always tagged. Also sw1 needs to keep all vlans on port1 egress tagged, not sure if we actually take care of that ... (maybe the dsa code does that for us, didn't check).
No, this would be driver-level configuration. DSA doesn't alter the egress-tagged flag of bridge VLANs.
Quoted 4 lines
Although forwarding works between user ports of sw0 and sw1, from the linux perspective we would never receive any traffic from sw0's ports, since we only have sw1's tag, and that one will say sw1.port1.
Quoted 8 lines
So while you may be able to configure vlans and forwarding, probably everything else won't work as expected. Like when you want to send out a packet on a certain port.
Though I assume this isn't a special issue for b53, and rather a common issue of chained switch chips, and b53 just acknowledges it / tries to work around it. I know that marvell (E)DSA can handle this, but I wouldn't be surprised if many others can't.
For the record, we have a non-proprietary DSA tagging infrastructure (tag_8021q.c) which supports cross-chip bridging, used for 3 drivers already. I know Florian has looked at it in the past, but due to various reasons couldn't immediately find a way to make use of it for b53. It could be interesting though.
Quoted 9 lines
Looking at devices in OpenWrt that are affected by this, these device have exactly one user port on sw1, and that one is mostly used as a wan port, so as a stand-alone port, not a bridge port. One could argue here that proper functioning of the "outer" switch's ports is more important than being able to forward frames in hardware to the wan port.
Unfortunately I do not have a device at hand, might need to figure out if I can get my hands on one ... .
Generally, switches which support a cascading topology have the necessary prerequisites taken care of at the tagging protocol level. Two switches from the same vendor which are connected together are more likely to form a single switch tree, and the switch ID from the packet indicates which device from the tree does the packet belong to. There's a single DSA tag in this situation.
On the other hand you have tag stacking, where a DSA user port is the conduit of a downstream DSA switch. There are 2 single-switch trees in that case. That also tends to work, usually, though you wouldn't expect hardware-accelerated forwarding between the top and bottom switch (software needs to perform tag adaptation for the general case). There are recorded cases of tagging protocols "ocelot" and "ocelot-8021q" working just fine as DSA conduits for "sja1105".
For the stacked b53 case, it looks like due to hardware limitations, the tag stacking solution was partially adopted, but with b53 specificities. You have hardware-accelerated cross-chip bridging (which you wouldn't normally expect) and one of the switches has tagging protocol "none" (which again you wouldn't expect). See if maybe a single tree with a custom "brcm-8021q" tagging protocol is something feasible.
Vladimir Oltean
maintainerQuoted 10 lines · Jonas Gorski
While trying to figure out the hardware behavior of a DSA supported switch chip and printing various internal vlan state changes, I noticed that some flows never triggered adding the cpu port to vlans, preventing it from receiving any of the VLANs traffic.
E.g. the following sequence would cause the cpu port not being member of the vlan, despite the bridge vlan output looking correct:
$ ip link add swbridge type bridge vlan_filtering 1 vlan_default_pvid 1 $ ip link set lan1 master swbridge
At this step, dsa_port_bridge_join() -> switchdev_bridge_port_offload() -> ... -> br_switchdev_port_offload() -> nbp_switchdev_sync_objs() -> br_switchdev_vlan_replay() -> br_switchdev_vlan_replay_group(br_vlan_group(br)) -> br_switchdev_vlan_replay_one() should have notified DSA, with changed=false. It should be processed by dsa_user_host_vlan_add() -> dsa_port_host_vlan_add().
You make it sound like that doesn't happen.
I notice you didn't mention which "DSA supported chip" you are using.
By any chance, does its driver set ds->configure_vlan_while_not_filtering = false? That would be my prime suspect, making dsa_port_skip_vlan_configuration() ignore the code path above, because the bridge port is not yet VLAN filtering.
It becomes VLAN filtering only a bit later in dsa_port_bridge_join(),
with the dsa_port_switchdev_sync_attrs() -> dsa_port_vlan_filtering(br_vlan_enabled(br)) call.
If that is the case, the only thing that is slightly confusing to me is why you haven't seen the "skipping configuration of VLAN" extack message. But anyway, if the theory above is true, you should instead be looking at adding proper VLAN support to said driver, and drop this set instead, because VLAN replay isn't working properly.
Quoted 7 lines
$ bridge vlan add dev lan1 vid 1 pvid untagged $ bridge vlan add dev swbridge vid 1 pvid untagged selfAdding more printk debugging, I traced it
br_vlan_add_existing()setting changed to true (since the vlan "gained" the pvid untagged flags), and then the dsa code ignoring the vlan notification, since it is a vlan for the cpu port that is updated.
Yes, this part and everything that follows should be correct.
Quoted 13 lines · Vladimir Oltean
Quoted 10 lines · Jonas Gorski
While trying to figure out the hardware behavior of a DSA supported switch chip and printing various internal vlan state changes, I noticed that some flows never triggered adding the cpu port to vlans, preventing it from receiving any of the VLANs traffic.
E.g. the following sequence would cause the cpu port not being member of the vlan, despite the bridge vlan output looking correct:
$ ip link add swbridge type bridge vlan_filtering 1 vlan_default_pvid 1 $ ip link set lan1 master swbridge
Quoted 7 lines
At this step,
dsa_port_bridge_join()->switchdev_bridge_port_offload()-> ... ->br_switchdev_port_offload()->nbp_switchdev_sync_objs()->br_switchdev_vlan_replay()-> br_switchdev_vlan_replay_group(br_vlan_group(br)) ->br_switchdev_vlan_replay_one()should have notified DSA, with changed=false. It should be processed bydsa_user_host_vlan_add()->dsa_port_host_vlan_add().You make it sound like that doesn't happen.
Yes, because I messed up writing down what I did. That should have been vlan_default_pvid 0 so there are no VLANs configured by default.
Quoted 9 lines
I notice you didn't mention which "DSA supported chip" you are using.
By any chance, does its driver setds->configure_vlan_while_not_filtering= false? That would be my prime suspect, makingdsa_port_skip_vlan_configuration()ignore the code path above, because the bridge port is not yet VLAN filtering.
It becomes VLAN filtering only a bit later indsa_port_bridge_join(),
with thedsa_port_switchdev_sync_attrs()-> dsa_port_vlan_filtering(br_vlan_enabled(br)) call.
Quoted 5 lines
If that is the case, the only thing that is slightly confusing to me is why you haven't seen the "skipping configuration of VLAN" extack message. But anyway, if the theory above is true, you should instead be looking at adding proper VLAN support to said driver, and drop this set instead, because VLAN replay isn't working properly.
It's b53, and on first glance it does not set it. But as I just noticed, I messed up the example.
So adding the lan1 vid is supposed to be the very first vlan that is configured.
Quoted 10 lines
Quoted 8 lines
$ bridge vlan add dev lan1 vid 1 pvid untagged $ bridge vlan add dev swbridge vid 1 pvid untagged selfAdding more printk debugging, I traced it
br_vlan_add_existing()setting changed to true (since the vlan "gained" the pvid untagged flags), and then the dsa code ignoring the vlan notification, since it is a vlan for the cpu port that is updated.Yes, this part and everything that follows should be correct.
Sorry for the mistake. I did it correctly while testing though!
Best regards,
Jonas
Quoted 34 lines · Jonas Gorski
Quoted 13 lines · Vladimir Oltean
Quoted 10 lines · Jonas Gorski
While trying to figure out the hardware behavior of a DSA supported switch chip and printing various internal vlan state changes, I noticed that some flows never triggered adding the cpu port to vlans, preventing it from receiving any of the VLANs traffic.
E.g. the following sequence would cause the cpu port not being member of the vlan, despite the bridge vlan output looking correct:
$ ip link add swbridge type bridge vlan_filtering 1 vlan_default_pvid 1 $ ip link set lan1 master swbridgeQuoted 7 lines
At this step,
dsa_port_bridge_join()->switchdev_bridge_port_offload()-> ... ->br_switchdev_port_offload()->nbp_switchdev_sync_objs()->br_switchdev_vlan_replay()-> br_switchdev_vlan_replay_group(br_vlan_group(br)) ->br_switchdev_vlan_replay_one()should have notified DSA, with changed=false. It should be processed bydsa_user_host_vlan_add()->dsa_port_host_vlan_add().You make it sound like that doesn't happen.
Yes, because I messed up writing down what I did. That should have been
vlan_default_pvid0 so there are no VLANs configured by default.Quoted 9 lines
I notice you didn't mention which "DSA supported chip" you are using.
By any chance, does its driver setds->configure_vlan_while_not_filtering= false? That would be my prime suspect, makingdsa_port_skip_vlan_configuration()ignore the code path above, because the bridge port is not yet VLAN filtering.
It becomes VLAN filtering only a bit later indsa_port_bridge_join(),
with thedsa_port_switchdev_sync_attrs()-> dsa_port_vlan_filtering(br_vlan_enabled(br)) call.
Quoted 8 lines
Quoted 5 lines
If that is the case, the only thing that is slightly confusing to me is why you haven't seen the "skipping configuration of VLAN" extack message. But anyway, if the theory above is true, you should instead be looking at adding proper VLAN support to said driver, and drop this set instead, because VLAN replay isn't working properly.
It's b53, and on first glance it does not set it. But as I just noticed, I messed up the example.
So I had the chance to properly check and b53 does not unset it, so it should be true.
Quoted 12 lines
So adding the lan1 vid is supposed to be the very first vlan that is configured.
Quoted 10 lines
Quoted 8 lines
$ bridge vlan add dev lan1 vid 1 pvid untagged $ bridge vlan add dev swbridge vid 1 pvid untagged selfAdding more printk debugging, I traced it
br_vlan_add_existing()setting changed to true (since the vlan "gained" the pvid untagged flags), and then the dsa code ignoring the vlan notification, since it is a vlan for the cpu port that is updated.Yes, this part and everything that follows should be correct.
So as an addendum that I probably should have included in the cover letter and commit message:
Starting with no vlans configured on the bridge:
$ bridge vlan add dev lan1 vid 1 pvid untagged $ bridge vlan add dev swbridge vid 1 pvid untagged self
does not work, but
$ bridge vlan add dev lan1 vid 1 pvid untagged $ bridge vlan add dev swbridge vid 1 self
does properly trigger a configuration of the vlan on the cpu port.
And the difference is that in the former, would_change => vlan->changed is true (due to "pvid untagged"), and in the latter it is not.
Best regards,
Jonas