net: dsa: make a shorter bridge ageing time take effect
v3 cover net: dsa: make a shorter bridge ageing time take effect
During an STP topology change, the bridge lowers the ageing time so that stale FDB entries go away quickly. When the change is over, the bridge sets the configured value again. On DSA switches, both steps can go wrong:
- On a KSZ9893, ksz9477 does not apply a shorter value at once. Patch 1 fixes this.
- The DSA core can keep the short value after the bridge has restored the long one. Patch 2 fixes this, and patch 3 does the same for a port that has left the bridge.
In a lab test on a KSZ9893, I cut one of two redundant paths while a station sent one-way UDP or raw Ethernet traffic. Without the series, the traffic stopped for up to 56 s, long after STP had converged. With it, the traffic came back after 12 to 15 s, about as long as STP needed to converge.
The series fixes the cases I hit on a KSZ9893: the switch keeps a short ageing time after an STP topology change, or after a port leaves the bridge. Some cases are not fixed. In them, the switch keeps an ageing time that no bridge asks for. Two are known:
- The last bridged port of a switch leaves while its bridge has a short ageing time.
- The last port of one bridge leaves the switch while another bridge stays on it. The switch keeps the short value of the bridge that is gone.
There may be more such cases. I did not look for them.
The patches carry Fixes tags. They still go to net-next, because patches 2 and 3 change the DSA core and affect every driver with .set_ageing_time.
With patch 2, sja1105 reloads its static config once more when the bridge restores the ageing time.
To check patches 2 and 3 on a KSZ9477-family switch over I2C, read the ageing register from debugfs (<device> is the I2C device, for example 3-005f):
dd if=/sys/kernel/debug/regmap/<device>-32/registers bs=15 \
skip=$((0x310)) count=1 2>/dev/nullThe ageing time in seconds is bits 5:3 of the first byte times the last byte. For example, in "0310: 55450096" bits 5:3 of 0x55 give 2 and 0x96 is 150, so the ageing time is 2 x 150 s = 300 s.
Without STP, after a boot (the comments give the register value):
ip link add br0 type bridge stp_state 0
ip link set lan1 master br0
ip link set lan2 master br0
ip link set br0 up
ip link set br0 type bridge ageing_time 1000 # 10 s
# 0310: 4d45000a (1 x 10 s)
ip link set lan2 nomaster
ip link set br0 type bridge ageing_time 30000 # 300 s
# with the series: 0310: 55450096 (2 x 150 s) # without patch 2 or 3: 0310: 4d45000a (1 x 10 s)
With kernel STP, start again with a bridge that runs STP, here with forward_delay 4 s. lan1 and lan2 need a link to peers that do not run STP, so that br0 is the root bridge:
ip link del br0
ip link add br0 type bridge stp_state 1 forward_delay 400 ip link set lan1 master br0
ip link set lan2 master br0
ip link set lan1 up
ip link set lan2 up
ip link set br0 up
# wait until /sys/class/net/br0/bridge/topology_change reads 1 # 0310: 55450004 (2 x 4 s) ip link set lan2 nomaster sleep 30 # with the series: 0310: 55450096 (2 x 150 s) # without patch 2 or 3: 0310: 55450004 (2 x 4 s)
Tested on a KSZ9893.
---
Changes in v3:
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Oleksij Rempel (3):
net: dsa: microchip: ksz9477: apply a shorter ageing time at once
net: dsa: ignore the old ageing time of the port being changed
net: dsa: forget the port ageing time when the port leaves the bridge
drivers/net/dsa/microchip/ksz9477.c | 41 ++++++++++++++++++++++++++++++++----- net/dsa/port.c | 13 +++++++++--- net/dsa/switch.c | 17 +++++++++++---- net/dsa/switch.h | 1 + 4 files changed, 60 insertions(+), 12 deletions(-)
---
base-commit: 6ff4c5942a301675eb12e5b49d53a81e604624a1
change-id: 20261103-ksz-stp-ageing-705aa69829e5
Best regards,
Signature · 1 line
Oleksij Rempel <[email protected]>
PATCH v3 1/3 net: dsa: microchip: ksz9477: apply a shorter ageing time at once
Pulse Fast Aging when the programmed ageing time gets shorter or the Age Count gets smaller.
The ageing time is Age Count times Age Period. An entry stores the Age Count when it is updated, as the datasheet says. The datasheet does not say when a new Age Period applies.
Without the pulse, stale entries outlived an STP topology change. In my STP tests the switch ran at 300 s as 4 x 75 s, its reset value. With forward_delay 4 s, the bridge asks for an ageing time of 8 s. Read back right after the write, the register showed 8 s. In three tests, an entry learned before the change still stayed for more than a minute. I think the switch uses the new Age Period only after the running one ends.
The pulse is also needed when the ageing time grows but the Age Count shrinks. From 8 s (4 x 2 s) to 31 s (1 x 31 s), an entry stayed about 63 s in one test.
Fast Aging is a control for the whole switch. On a KSZ9893 the pulse removed the dynamic entries of both user ports, also entries still in use, and the new period started right away. Unicast to those addresses is flooded until the switch learns them again.
I found this in STP tests on a KSZ9893. I tested the fix there with kernel STP and with STP off. With mstpd I checked only the programmed ageing time, not the FDB.
---
Changes in v3:
- Say that Fast Aging removes the entries of all ports (Sashiko)
Changes in v2:
- Fix the tense in the comment (Andrew)
- Add new_period, and compute old_secs next to new_secs
- Rephrase the comments and the commit message
- Add a Fixes tag
--- drivers/net/dsa/microchip/ksz9477.c | 41 ++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-)
drivers/net/dsa/microchip/ksz9477.c +36 -5
@@ -1289,13 +1289,16 @@ static void ksz9477_phylink_get_caps(struct dsa_switch *ds, int port,ksz_phylink_get_caps (ds, port, config); } +/* The datasheet gives no pulse length. A 2 ms pulse worked on a KSZ9893. */ +#define KSZ9477_FAST_AGE_PULSE_US (2 * USEC_PER_MSEC) +static int ksz9477_set_ageing_time (struct dsa_switch *ds,unsigned int msecs) { +u8 data, mult, value, old_period, new_period;struct ksz_device *dev = ds->priv; +u32 old_secs, new_secs, max_val;u32 secs = msecs /1000 ; -u8 data, mult, value; -u32 max_val; -int ret; +int ret, err;#define MAX_TIMER_VAL ((1 << 8) - 1)
@@ -1314,6 +1317,10 @@ static int ksz9477_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)if (ret <0 )return ret; + ret =ksz_read8 (dev,REG_SW_LUE_CTRL_3 , &old_period); +if (ret <0 ) +return ret; +/* Check whether there is need to update the multiplier. */ mult =FIELD_GET (SW_AGE_CNT_M , value); max_val =MAX_TIMER_VAL ;
@@ -1336,8 +1343,32 @@ static int ksz9477_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)return ret; } - value =DIV_ROUND_UP (secs, data); -return ksz_write8 (dev,REG_SW_LUE_CTRL_3 , value); + new_period =DIV_ROUND_UP (secs, data); + ret =ksz_write8 (dev,REG_SW_LUE_CTRL_3 , new_period); +if (ret <0 ) +return ret; + +/* data is the new Age Count and mult is the old one. An entry +* stores the Age Count when it is updated. The datasheet does not +* say when a new Age Period applies. On a KSZ9893, entries outlived +* the new ageing time after it got shorter, and after the Age Count +* got smaller. Pulse Fast Aging in both cases. Fast Aging is a +* control for the whole switch. On a KSZ9893 the pulse removes the +* dynamic entries of all ports and starts the new period. +*/ + old_secs = mult * old_period; + new_secs = data * new_period; +if (new_secs >= old_secs && data >= mult) +return 0 ; + + ret =ksz_rmw8 (dev,REG_SW_LUE_CTRL_1 ,SW_FAST_AGING ,SW_FAST_AGING ); +if (!ret) +fsleep (KSZ9477_FAST_AGE_PULSE_US ); + +/* Clear the bit even after an error. */ + err =ksz_rmw8 (dev,REG_SW_LUE_CTRL_1 ,SW_FAST_AGING ,0 ); + +return ret ?: err; }void ksz9477_port_queue_split (struct ksz_device *dev,int port)
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v3 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The fix depends on a fixed Fast Aging pulse length (KSZ9477_FAST_AGE_PULSE_US = 2 ms, ksz9477.c:1293) that was found by…
- [Low] ksz9477_set_ageing_time() (drivers/net/dsa/microchip/ksz9477.c:1359-1371) now pulses the switch-…
--
net: dsa: microchip: ksz9477: apply a shorter ageing time at once
This patch makes ksz9477_set_ageing_time() pulse the switch-wide Fast Aging bit in REG_SW_LUE_CTRL_1 when the programmed ageing time gets shorter or the Age Count gets smaller. Without the pulse, stale FDB entries outlived an STP topology change on a KSZ9893. The bit is held for a fixed 2 ms and then cleared.
drivers/net/dsa/microchip/ksz9477.c static void ksz9477_phylink_get_caps(struct dsa_switch *ds, int port, · line 1293
Quoted 10 lines
drivers/net/dsa/microchip/ksz9477.c +2
-0@@ -1289,13 +1289,16 @@ static void ksz9477_phylink_get_caps(struct dsa_switch *ds, int port,ksz_phylink_get_caps (ds, port, config); } +/* The datasheet gives no pulse length. A 2 ms pulse worked on a KSZ9893. */ +#define KSZ9477_FAST_AGE_PULSE_US (2 * USEC_PER_MSEC)
[Severity: Medium]
Is a fixed 2 ms pulse enough on every chip in this family and for every stored Age Count?
The value was found by trial on one KSZ9893, where the entries stored Age Count 4. Each ALU entry holds a 3-bit stored age count (ALU_V_PRIO_AGE_CNT_M, decoded in ksz9477_convert_alu()). That count is copied from SW_AGE_CNT_M when the entry is learned or refreshed, so it can be as high as 7.
The pulse matters most when the old count (mult) was larger, and that is exactly when entries hold the highest counts. One example: 1785 s (7 x 255), then an STP topology change to 8 s. That gives data = 1 and triggers the pulse.
Suppose Fast Aging here speeds up ageing rather than purging the table at once. Could entries with stored counts 5 to 7 then survive a 2 ms pulse? The same question applies to the other chips that use ksz9477_switch_ops (KSZ9477, KSZ9897, KSZ9896, KSZ9567, KSZ9563, KSZ8563, LAN9646 and so on).
ksz9477_set_ageing_time() sets SW_FAST_AGING, sleeps, clears the bit and returns 0. It never checks that the dynamic entries are gone. If they survive, the stale FDB after a topology change would still happen, and nothing would report it.
The KSZ8995XA path in ksz8.c describes an "800 us fast-age cycle", which hints at sweep behaviour. It doesn't show how the KSZ9477 family behaves.
[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/ksz9477.c +4
-0+ old_secs = mult * old_period; + new_secs = data * new_period; +if (new_secs >= old_secs && data >= mult) +return 0 ;
drivers/net/dsa/microchip/ksz9477.c static int ksz9477_set_ageing_time(struct dsa_switch *ds, unsigned int msecs) · line 1372
Quoted 10 lines
drivers/net/dsa/microchip/ksz9477.c +9
-0+ + ret =ksz_rmw8 (dev,REG_SW_LUE_CTRL_1 ,SW_FAST_AGING ,SW_FAST_AGING ); +if (!ret) +fsleep (KSZ9477_FAST_AGE_PULSE_US ); + +/* Clear the bit even after an error. */ + err =ksz_rmw8 (dev,REG_SW_LUE_CTRL_1 ,SW_FAST_AGING ,0 ); + +return ret ?: err; }
[Severity: Low]
Can an ageing time change in one bridge now flush the dynamic FDB entries of every other bridge on the same switch?
The value programmed here comes from dsa_switch_fastest_ageing_time(), which takes the minimum over all ports of the switch. Before this patch, one bridge could only shorten the ageing timer for the others, and entries still in use kept being refreshed. With the pulse, entries still in use in unrelated bridges are removed too. Their unicast traffic floods until the addresses are learned again.
Nothing limits the flush to one bridge or limits how often it runs. Here are two ways to trigger it again and again.
With kernel STP, __br_set_topology_change() lowers the ageing time when received BPDUs or TCNs set TC, and restores it when TC clears:
net/bridge/br_stp.c:__br_set_topology_change() {
...
if (val) {
t = 2 * br->forward_delay;
...
} else {
t = br->bridge_ageing_time;
...
err = __set_ageing_time(br->dev, t);
...
}For example, 300 s (4 x 75) -> 30 s pulses. Going back to 300 s (2 x 150) does not. The next TC (30 s = 2 x 15) pulses again, so every TC on/off cycle causes one switch-wide flush.
DSA user ports are not netns-immutable. A CAP_NET_ADMIN holder in another netns that owns a bridged switch port could toggle IFLA_BR_AGEING_TIME. Each toggle would flush the FDB of bridges owned by the host or by other tenants. The same happens when a port joins a bridge with a shorter ageing time, since the attribute is replayed on join.
The commit message says Fast Aging is a control for the whole switch. Was the effect on other bridges sharing the switch intended?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117-ksz-stp-ageing-v3-0-135de6b9f8ad%40pengutronix.de
Re: [PATCH net-next v3 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once
Quoted 2 lines · On Thu, Nov 19, 2026 at 01:03:20AM +0000, [email protected] wrote:
Is a fixed 2 ms pulse enough on every chip in this family and for every stored Age Count?
I do not know. I tested only on a KSZ9893. 2 ms worked there, and I did not try other lengths. The datasheet only says that the bit enables fast aging. It gives no pulse length and does not say what the bit removes. The
800 us figure in ksz8.c is for the KSZ8995XA. I have no such figure for the KSZ9477 family.
I tested Age Counts 2 and 4. I write Age Count x Age Period, so 2 x 150 s is Age Count 2 and Age Period 150 s.
- From 2 x 150 s to 2 x 5 s, I read the FDB after the pulse. The entries were gone within 2 s. On an earlier build with the same code, an entry learned about 2 s after the change aged out after 5 to 10 s, so the new period applied at once.
- From 4 x 75 s to 4 x 2 s, in the kernel STP tests, a monitor read the entries of lan1 every 1 to 3 s. The entries of stations that had stopped sending were gone at the first read after the change. That run used an earlier version of this patch with the same pulse code.
The tests do not show how the pulse works. It may remove all dynamic entries at once. Or it may run a fast ageing pass, and entries with a higher Age Count could survive it. I did not test Age Counts 5 to 7. The driver does not check that the entries are gone after the pulse.
Starting from the reset value of 4 x 75 s, the driver picks Age Count 5 or more only for ageing times above 1020 s. I keep 2 ms for now. If someone can test a higher Age Count on another chip of the family, I can extend the pulse or check the table.
Quoted 2 lines
Can an ageing time change in one bridge now flush the dynamic FDB entries of every other bridge on the same switch?
Yes. On the KSZ9893 the pulse removed the entries of both user ports. Fast Aging, the Age Count and the Age Period are switch-wide, and .set_ageing_time() gets no port or bridge argument. So the pulse also hits other bridges on the switch. The commit message and the comment say that the pulse removes the entries of all ports. They do not name other bridges. IMO the cost is acceptable, see the next answer.
Quoted 3 lines
For example, 300 s (4 x 75) -> 30 s pulses. Going back to 300 s (2 x 150) does not. The next TC (30 s = 2 x 15) pulses again, so every TC on/off cycle causes one switch-wide flush.
Yes. There is no rate limit. The pulse comes only when the programmed ageing time or the Age Count gets smaller.
The cost is unicast flooding until the switch learns the addresses again. The switch learns an address from the next frame that the station sends through it.
The pulse also helps after a station moved. Without it, traffic to that station goes to the old port and is lost until the station sends a frame through the switch or the stale entry ages out. In my worst-case test without this series, one-way UDP with static ARP stopped for up to 56 s, 43 s of that after STP had converged. Such fully one-way traffic is rare. Once its entry ages out, the switch floods that traffic anyway.
On a topology change, kernel STP only shortens the ageing time. With the pulse, the switch also removes the entries, as RSTP does. For RSTP and MSTP, IEEE 802.1Q-2022, 13.19, NOTE 2 lets a bridge remove all Dynamic Filtering Entries, not only those of the given ports: "This does not result in incorrect operation, but will result in more flooding of frames with unknown destination addresses." The note speaks of a single bridge, not of several bridges on one switch. For other bridges on the switch, I think the cost is the same: extra flooding.
Quoted 2 lines
A
CAP_NET_ADMINholder in another netns that owns a bridged switch port could toggleIFLA_BR_AGEING_TIME.
Without this patch, that user can already lower the ageing time of the whole switch. With this patch, that user can also cause a flush. A flush happens when the programmed ageing time or the Age Count gets smaller. It can also happen on a raise, for example from 8 s (2 x 4) to 31 s (1 x 31). It also happens when a port joins a bridge with a shorter ageing time than the switch has now. Other bridges then flood unicast until they learn the addresses again.
Oleksij
PATCH v3 2/3 net: dsa: ignore the old ageing time of the port being changed
In reply to Oleksij RempelPass the port to the ageing time notifier. When dsa_switch_fastest_ageing_time() takes the minimum, skip the cached dp->ageing_time of that port and use the requested value instead. DSA updates the cache only after the notifier.
Without this, the minimum includes the port's old ageing time. During an STP topology change, the bridge lowers the ageing time to 2 x forward_delay (8 s with forward_delay 4 s). When it restores the configured value, DSA programs the cached 8 s again, and the switch keeps ageing at 8 s.
An automated review of the lan9645x bridge series pointed this out [1]. I reproduced it on a KSZ9893 and tested the fix there.
---
Changes in v3:
- No changes.
Changes in v2:
- Pass the port to the notifier and skip its old value, instead of updating the cache first (Andrew)
- Rephrase the subject and the commit message, and move the sja1105 note to the cover letter
- Add a Fixes tag
--- net/dsa/port.c | 7 ++++--- net/dsa/switch.c | 17 +++++++++++++---- net/dsa/switch.h | 1 + 3 files changed, 18 insertions(+), 7 deletions(-)
net/dsa/port.c +4 -3
@@ -876,11 +876,12 @@ int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock) {unsigned long ageing_jiffies =clock_t_to_jiffies (ageing_clock);unsigned int ageing_time =jiffies_to_msecs (ageing_jiffies); -struct dsa_notifier_ageing_time_info info; +struct dsa_notifier_ageing_time_info info = { + .dp = dp, + .ageing_time = ageing_time, + };int err; - info.ageing_time = ageing_time; - err =dsa_port_notify (dp,DSA_NOTIFIER_AGEING_TIME , &info);if (err)return err;
net/dsa/switch.c +13 -4
@@ -20,14 +20,23 @@#include "trace.h" #include "user.h" -static unsigned int dsa_switch_fastest_ageing_time (struct dsa_switch *ds, -unsigned int ageing_time) +static unsigned int +dsa_switch_fastest_ageing_time (struct dsa_switch *ds, +const struct dsa_notifier_ageing_time_info *info) { +unsigned int ageing_time = info->ageing_time;struct dsa_port *dp; -dsa_switch_for_each_port (dp, ds) +dsa_switch_for_each_port (dp, ds) { +/* info->dp is the port being changed. Its cached value is +* stale until the notifier returns. Skip it. +*/ +if (dp == info->dp) +continue ; +if (dp->ageing_time && dp->ageing_time < ageing_time) ageing_time = dp->ageing_time; + }return ageing_time; }
@@ -44,7 +53,7 @@ static int dsa_switch_ageing_time(struct dsa_switch *ds,return -ERANGE ;/* Program the fastest ageing time in case of multiple bridges */ - ageing_time =dsa_switch_fastest_ageing_time (ds, ageing_time); + ageing_time =dsa_switch_fastest_ageing_time (ds, info);if (ds->ops->set_ageing_time)return ds->ops->set_ageing_time (ds, ageing_time);
net/dsa/switch.h +1 -0
@@ -39,6 +39,7 @@ enum {/* DSA_NOTIFIER_AGEING_TIME */ struct dsa_notifier_ageing_time_info { +const struct dsa_port *dp;unsigned int ageing_time; };
Signature · 1 line
2.47.3
Re: [PATCH net-next v3 2/3] net: dsa: ignore the old ageing time of the port being changed
Quoted 11 lines · Oleksij Rempel
Pass the port to the ageing time notifier. When
dsa_switch_fastest_ageing_time()takes the minimum, skip the cacheddp->ageing_timeof that port and use the requested value instead. DSA updates the cache only after the notifier.Without this, the minimum includes the port's old ageing time. During an STP topology change, the bridge lowers the ageing time to 2 x
forward_delay(8 s withforward_delay4 s). When it restores the configured value, DSA programs the cached 8 s again, and the switch keeps ageing at 8 s.
Quoted 7 lines
An automated review of the lan9645x bridge series pointed this out [1]. I reproduced it on a KSZ9893 and tested the fix there.
Fixes 77b61365ecef ("net: dsa: remove the transactional logic from ageing time notifiers")Reviewed-by Andrew Lunn <[email protected]>Signed-off-by Oleksij Rempel <[email protected]>
This looks right to me, good find from Sashiko!
Yours,
Linus Walleij
PATCH v3 3/3 net: dsa: forget the port ageing time when the port leaves the bridge
In reply to Oleksij RempelClear the cached dp->ageing_time when the port leaves the bridge. Otherwise dsa_switch_fastest_ageing_time() still uses the ageing time of the port that left. If the port leaves with a shorter ageing time, for example during an STP topology change, the switch stays at the short value until that port joins a bridge again. With this change the switch goes back to the long value when the bridge restores it at the end of the topology change. The switch gets the restored value only if another port of the same bridge is still in this DSA tree.
Found by code inspection. Tested on a KSZ9893 with lan1 and lan2 in a bridge, ageing time 300 s:
- kernel STP, forward delay 4 s, lan2 removed during a topology change:
without this patch the switch stayed at 8 s (2 x 4 s). With it, the switch went back to 300 s at the end of the topology change.
- no STP: I set the ageing time to 10 s, removed lan2, then set 300 s. The switch stayed at 10 s without this patch and went to 300 s with it.
---
Changes in v3:
- No changes.
Changes in v2:
- Say how long the short ageing time stays, with an STP test (Andrew)
- Rephrase the commit message and the comment
- Move the case of the last bridge port leaving to the cover letter
- Add a Fixes tag
--- net/dsa/port.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/dsa/port.c +6 -0
@@ -415,6 +415,12 @@ static void dsa_port_switchdev_unsync_attrs(struct dsa_port *dp,/* Ageing time may be global to the switch chip, so don't change it * here because we have no good reason (or value) to change it to. */ + +/* Forget the ageing time cached for this port. +* dsa_switch_fastest_ageing_time() skips 0, so this port no longer +* counts towards the minimum. +*/ + dp->ageing_time =0 ; } static int dsa_port_bridge_create(struct dsa_port *dp,
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v3 3/3] net: dsa: forget the port ageing time when the port leaves the bridge
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The fix is incomplete because nothing reprograms the switch when the port leaves.
--
net: dsa: forget the port ageing time when the port leaves the bridge
This patch clears the cached dp->ageing_time in dsa_port_switchdev_unsync_attrs() when a port leaves a bridge. After that, dsa_switch_fastest_ageing_time() no longer counts the departed port's value when it computes the minimum. The aim is to keep the switch from staying at a short ageing time (for example one set during an STP topology change) after the port that requested it has left.
Quoted 5 lines
net/dsa/port.c +0
-0
net/dsa/port.c static void dsa_port_switchdev_unsync_attrs(struct dsa_port *dp, · line 424
Quoted 10 lines
net/dsa/port.c +6
-0@@ -415,6 +415,12 @@ static void dsa_port_switchdev_unsync_attrs(struct dsa_port *dp,/* Ageing time may be global to the switch chip, so don't change it * here because we have no good reason (or value) to change it to. */ + +/* Forget the ageing time cached for this port. +* dsa_switch_fastest_ageing_time() skips 0, so this port no longer +* counts towards the minimum. +*/ + dp->ageing_time =0 ; }
[Severity: Medium]
Can the switch still stay at the departed port's short ageing time after this change?
This only clears the cache. Nothing on the leave path reprograms the hardware. dsa_port_bridge_leave() ends right after dsa_port_switchdev_unsync_attrs(). The only code that writes the ageing register is dsa_switch_ageing_time() in net/dsa/switch.c:
net/dsa/switch.c:dsa_switch_ageing_time() {
...
ageing_time = dsa_switch_fastest_ageing_time(ds, info);
if (ds->ops->set_ageing_time)
return ds->ops->set_ageing_time(ds, ageing_time);
...
}That function runs only for DSA_NOTIFIER_AGEING_TIME. The only sender is dsa_port_ageing_time(). It is called from the sync_attrs path at bridge join, and from the SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME handler, which needs a port that still offloads the bridge.
Here is a sequence on a single chip, with br0={lan1} at 300 s and br1={lan2} with STP enabled:
topology change on br1
__set_ageing_time(br1, 2 * fwd_delay)
dsa_port_ageing_time(lan2, 8 s)
programs min(8, lan1=300) = 8 s for the whole chipip link set lan2 nomaster
dsa_port_bridge_leave()
dsa_port_switchdev_unsync_attrs()
dp->ageing_time = 0; /* no reprogram */ end of the topology change on br1
br1 restores 300 s, but br1 has no DSA lower port left, so no notifier is sent
lan1 in br0 would keep ageing at 8 s until br0's ageing time changes or some port joins a bridge again. Would it make sense to recompute the minimum of the remaining non-zero dp->ageing_time values on dp->ds and program it here when the port leaves?
The existing comment just above the new code says there is "no good reason (or value) to change it to". Once the cache is cleared, the minimum of the remaining cached values is a usable value, so that comment no longer seems accurate. The new comment also doesn't mention that the hardware value stays unchanged until the next notification.
The commit message does cover part of this:
"The switch gets the restored value only if another port of the same bridge is still in this DSA tree."
However, the problem the commit message describes, a switch stuck at the departed port's short ageing time, can still happen through this leave path when ports of a different bridge remain on the same chip.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117-ksz-stp-ageing-v3-0-135de6b9f8ad%40pengutronix.de
Re: [PATCH net-next v3 3/3] net: dsa: forget the port ageing time when the port leaves the bridge
Quoted 2 lines · On Thu, Nov 19, 2026 at 01:03:22AM +0000, [email protected] wrote:
Can the switch still stay at the departed port's short ageing time after this change?
Yes. The v3 cover letter lists this case as not fixed: "The last port of one bridge leaves the switch while another bridge stays on it."
In my reply to v2 I wrote that v3 would add a patch for this case. I dropped it, and the v3 changelog should have said so. That patch reprogrammed the switch when a port left. It did not cover the case where the last bridged port of the switch leaves.
This patch only drops a cached value and writes nothing to the switch. The dropped patch added a write to the switch, and with patch 1 sometimes a flush, to every port leave. That is new behaviour for every driver with .set_ageing_time(). I want such a change reviewed on its own, not in this series of fixes.
This patch does not make the case worse:
- Before this patch, DSA kept the ageing time of a port that left until the port joined a bridge again. Every later update included that stale value in the minimum. So the switch got the short ageing time again at each update.
- With this patch, DSA forgets that value. The switch keeps the short value until DSA computes the ageing time again. That happens when a port of this DSA tree joins a bridge, or when a bridge with a port of this tree sets its ageing time. If neither happens, the switch stays at the short value.
Quoted 2 lines
The existing comment just above the new code says there is "no good reason (or value) to change it to".
Yes, that comment is out of date. After this patch there is a value to use when another port of the switch is still bridged: the minimum of the remaining cached values. I still do not reprogram the switch on leave in this series, for the reason above.
Oleksij
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 5 lines · On Tue, 17 Nov 2026 14:02:10 +0100 you wrote:
During an STP topology change, the bridge lowers the ageing time so that stale FDB entries go away quickly. When the change is over, the bridge sets the configured value again. On DSA switches, both steps can go wrong:
Quoted 7 lines
- On a KSZ9893, ksz9477 does not apply a shorter value at once. Patch 1 fixes this.
- The DSA core can keep the short value after the bridge has restored the long one. Patch 2 fixes this, and patch 3 does the same for a port that has left the bridge.[...]
Here is the summary with links:
- [net-next,v3,1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once
https://git.kernel.org/netdev/net-next/c/bf18142882a0 - [net-next,v3,2/3] net: dsa: ignore the old ageing time of the port being changed https://git.kernel.org/netdev/net-next/c/133927a00589 - [net-next,v3,3/3] net: dsa: forget the port ageing time when the port leaves the bridge https://git.kernel.org/netdev/net-next/c/eb0431e3f3e4
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html