* [PATCH net-next v2 0/3] net: dsa: make a shorter bridge ageing time take effect
@ 2026-11-15 10:59 Oleksij Rempel
2026-11-15 10:59 ` [PATCH net-next v2 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once Oleksij Rempel
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Oleksij Rempel @ 2026-11-15 10:59 UTC (permalink / raw)
To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Arun Ramadoss, Jiri Pirko, Linus Walleij,
Florian Fainelli, Vivien Didelot
Cc: netdev, linux-kernel, kernel, Jens Emil Schulz Østergaard,
Oleksij Rempel
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.
One case is not fixed. The last port of a bridge in its DSA tree may
leave while the bridge has a shorter ageing time, for example during a
topology change. Then the switch keeps the short value until a bridge
with ports in the same DSA tree sets its ageing time, or a port in that
tree joins a bridge.
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/null
The 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 v2:
- Link to v1: https://lore.kernel.org/r/20261104-ksz-stp-ageing-v1-0-2c2bc7217dea@pengutronix.de
---
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: 6964ff21c5d8b75649211a52dbfd92753e605649
change-id: 20261103-ksz-stp-ageing-705aa69829e5
Best regards,
--
Oleksij Rempel <o.rempel@pengutronix.de>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net-next v2 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once
2026-11-15 10:59 [PATCH net-next v2 0/3] net: dsa: make a shorter bridge ageing time take effect Oleksij Rempel
@ 2026-11-15 10:59 ` Oleksij Rempel
2026-11-15 15:38 ` Andrew Lunn
2026-11-16 11:00 ` netdev-bot+sashiko
2026-11-15 10:59 ` [PATCH net-next v2 2/3] net: dsa: ignore the old ageing time of the port being changed Oleksij Rempel
2026-11-15 10:59 ` [PATCH net-next v2 3/3] net: dsa: forget the port ageing time when the port leaves the bridge Oleksij Rempel
2 siblings, 2 replies; 9+ messages in thread
From: Oleksij Rempel @ 2026-11-15 10:59 UTC (permalink / raw)
To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Arun Ramadoss, Jiri Pirko, Linus Walleij,
Florian Fainelli, Vivien Didelot
Cc: netdev, linux-kernel, kernel, Jens Emil Schulz Østergaard,
Oleksij Rempel
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.
On a KSZ9893 the pulse removed the dynamic entries on the one user port
I tested. The new period then started right away.
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.
Fixes: 2c119d9982b1 ("net: dsa: microchip: add the support for set_ageing_time")
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
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(-)
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 8d4647e23cda153bc68255a44c44e0d1d92469f9..a9d701f0404a706e6ad2a6faa2f57dbe28d383c2 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -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. On a KSZ9893 the
+ * pulse removes the dynamic entries (checked on one user port) 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)
--
2.47.3
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net-next v2 2/3] net: dsa: ignore the old ageing time of the port being changed
2026-11-15 10:59 [PATCH net-next v2 0/3] net: dsa: make a shorter bridge ageing time take effect Oleksij Rempel
2026-11-15 10:59 ` [PATCH net-next v2 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once Oleksij Rempel
@ 2026-11-15 10:59 ` Oleksij Rempel
2026-11-15 15:40 ` Andrew Lunn
2026-11-15 10:59 ` [PATCH net-next v2 3/3] net: dsa: forget the port ageing time when the port leaves the bridge Oleksij Rempel
2 siblings, 1 reply; 9+ messages in thread
From: Oleksij Rempel @ 2026-11-15 10:59 UTC (permalink / raw)
To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Arun Ramadoss, Jiri Pirko, Linus Walleij,
Florian Fainelli, Vivien Didelot
Cc: netdev, linux-kernel, kernel, Jens Emil Schulz Østergaard,
Oleksij Rempel
Pass 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.
Fixes: 77b61365ecef ("net: dsa: remove the transactional logic from ageing time notifiers")
Link: https://lore.kernel.org/netdev/179180428624.434549.14425623884223795761@kernel.org/ [1]
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
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(-)
diff --git a/net/dsa/port.c b/net/dsa/port.c
index 1f5536c0dffc2311db24015697e0c8f5c014ac74..15e7da20b0e2f470a0ce5b763fa73b9b66b4c6f2 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -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;
diff --git a/net/dsa/switch.c b/net/dsa/switch.c
index a670a04edb7237a2606bc1959f6f2bb324c832ab..e9bef66fea3173c54fcde88da319cb8fd91195fc 100644
--- a/net/dsa/switch.c
+++ b/net/dsa/switch.c
@@ -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);
diff --git a/net/dsa/switch.h b/net/dsa/switch.h
index be0a2749cd9791e19b8f03c6f6ceafb2d0432b14..5362ee9bfb68cfb52759c108d0626c55e19bb3a3 100644
--- a/net/dsa/switch.h
+++ b/net/dsa/switch.h
@@ -39,6 +39,7 @@ enum {
/* DSA_NOTIFIER_AGEING_TIME */
struct dsa_notifier_ageing_time_info {
+ const struct dsa_port *dp;
unsigned int ageing_time;
};
--
2.47.3
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net-next v2 3/3] net: dsa: forget the port ageing time when the port leaves the bridge
2026-11-15 10:59 [PATCH net-next v2 0/3] net: dsa: make a shorter bridge ageing time take effect Oleksij Rempel
2026-11-15 10:59 ` [PATCH net-next v2 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once Oleksij Rempel
2026-11-15 10:59 ` [PATCH net-next v2 2/3] net: dsa: ignore the old ageing time of the port being changed Oleksij Rempel
@ 2026-11-15 10:59 ` Oleksij Rempel
2026-11-15 15:40 ` Andrew Lunn
2026-11-16 11:00 ` netdev-bot+sashiko
2 siblings, 2 replies; 9+ messages in thread
From: Oleksij Rempel @ 2026-11-15 10:59 UTC (permalink / raw)
To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vladimir Oltean,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Arun Ramadoss, Jiri Pirko, Linus Walleij,
Florian Fainelli, Vivien Didelot
Cc: netdev, linux-kernel, kernel, Jens Emil Schulz Østergaard,
Oleksij Rempel
Clear 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.
Fixes: 34a79f63bbe4 ("net: dsa: support switchdev ageing time attr")
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
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(+)
diff --git a/net/dsa/port.c b/net/dsa/port.c
index 15e7da20b0e2f470a0ce5b763fa73b9b66b4c6f2..54c9709840952210ecd1abdfde31f751d07ef2b6 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -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,
--
2.47.3
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next v2 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once
2026-11-15 10:59 ` [PATCH net-next v2 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once Oleksij Rempel
@ 2026-11-15 15:38 ` Andrew Lunn
2026-11-16 11:00 ` netdev-bot+sashiko
1 sibling, 0 replies; 9+ messages in thread
From: Andrew Lunn @ 2026-11-15 15:38 UTC (permalink / raw)
To: Oleksij Rempel
Cc: Woojung Huh, UNGLinuxDriver, Vladimir Oltean, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Arun Ramadoss, Jiri Pirko, Linus Walleij, Florian Fainelli,
Vivien Didelot, netdev, linux-kernel, kernel,
Jens Emil Schulz Østergaard
On Sun, Nov 15, 2026 at 11:59:51AM +0100, Oleksij Rempel wrote:
> 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.
>
> On a KSZ9893 the pulse removed the dynamic entries on the one user port
> I tested. The new period then started right away.
>
> 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.
>
> Fixes: 2c119d9982b1 ("net: dsa: microchip: add the support for set_ageing_time")
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next v2 2/3] net: dsa: ignore the old ageing time of the port being changed
2026-11-15 10:59 ` [PATCH net-next v2 2/3] net: dsa: ignore the old ageing time of the port being changed Oleksij Rempel
@ 2026-11-15 15:40 ` Andrew Lunn
0 siblings, 0 replies; 9+ messages in thread
From: Andrew Lunn @ 2026-11-15 15:40 UTC (permalink / raw)
To: Oleksij Rempel
Cc: Woojung Huh, UNGLinuxDriver, Vladimir Oltean, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Arun Ramadoss, Jiri Pirko, Linus Walleij, Florian Fainelli,
Vivien Didelot, netdev, linux-kernel, kernel,
Jens Emil Schulz Østergaard
On Sun, Nov 15, 2026 at 11:59:52AM +0100, Oleksij Rempel wrote:
> Pass 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.
>
> Fixes: 77b61365ecef ("net: dsa: remove the transactional logic from ageing time notifiers")
> Link: https://lore.kernel.org/netdev/179180428624.434549.14425623884223795761@kernel.org/ [1]
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next v2 3/3] net: dsa: forget the port ageing time when the port leaves the bridge
2026-11-15 10:59 ` [PATCH net-next v2 3/3] net: dsa: forget the port ageing time when the port leaves the bridge Oleksij Rempel
@ 2026-11-15 15:40 ` Andrew Lunn
2026-11-16 11:00 ` netdev-bot+sashiko
1 sibling, 0 replies; 9+ messages in thread
From: Andrew Lunn @ 2026-11-15 15:40 UTC (permalink / raw)
To: Oleksij Rempel
Cc: Woojung Huh, UNGLinuxDriver, Vladimir Oltean, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Arun Ramadoss, Jiri Pirko, Linus Walleij, Florian Fainelli,
Vivien Didelot, netdev, linux-kernel, kernel,
Jens Emil Schulz Østergaard
On Sun, Nov 15, 2026 at 11:59:53AM +0100, Oleksij Rempel wrote:
> Clear 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.
>
> Fixes: 34a79f63bbe4 ("net: dsa: support switchdev ageing time attr")
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next v2 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once
2026-11-15 10:59 ` [PATCH net-next v2 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once Oleksij Rempel
2026-11-15 15:38 ` Andrew Lunn
@ 2026-11-16 11:00 ` netdev-bot+sashiko
1 sibling, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 11:00 UTC (permalink / raw)
To: o.rempel
Cc: woojung.huh, UNGLinuxDriver, andrew, olteanv, davem, edumazet,
kuba, pabeni, horms, arun.ramadoss, jiri, linusw, f.fainelli,
vivien.didelot, netdev, linux-kernel, kernel,
jensemil.schulzostergaard
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] In ksz9477_set_ageing_time()
(drivers/net/dsa/microchip/ksz9477.c:1361-1371), the new Fast Aging…
- [Low] The Fast Aging pulse in ksz9477_set_ageing_time() is a fixed
blind sleep: KSZ9477_FAST_AGE_PULSE_US = 2 ms (ksz9477.c:1293),…
--
net: dsa: microchip: ksz9477: apply a shorter ageing time at once
This patch makes ksz9477_set_ageing_time() pulse the Fast Aging bit in
REG_SW_LUE_CTRL_1 for a fixed 2 ms. It does this whenever the programmed
ageing time gets shorter or the Age Count gets smaller. The goal is that
stale entries no longer outlive an STP topology change on a KSZ9893.
> diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
> index 8d4647e23cda1..a9d701f0404a7 100644
> --- a/drivers/net/dsa/microchip/ksz9477.c
> +++ b/drivers/net/dsa/microchip/ksz9477.c
[ ... ]
> @@ -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. On a KSZ9893 the
> + * pulse removes the dynamic entries (checked on one user port) 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);
[Severity: Medium]
Does this flush the dynamic FDB entries of every port on the switch?
SW_FAST_AGING is BIT(1) of REG_SW_LUE_CTRL_1 in ksz9477_reg.h. That
register holds only switch-wide lookup engine controls, next to
SW_AGING_ENABLE and SW_LINK_AUTO_AGING. Fast Aging has no port or FID
selector, so each pulse removes dynamic entries on all ports. That
includes ports in other bridges that had no topology change.
When the software bridge shortens its ageing time, it only expires
entries that were not refreshed within the new time. This pulse also
drops entries that are still in use. Unicast traffic to those addresses
then floods until the hosts transmit again, and a host that only
receives can be flooded to for a long time.
The pulse can also fire when the ageing time grows. From the reset value
of 4 x 75 s, a request for 301 s gives:
max_val = 255 (76 * 4 != 301)
data = DIV_ROUND_UP(301, 255) = 2
new_period = DIV_ROUND_UP(301, 2) = 151
data (2) < mult (4), so the switch-wide flush runs although the ageing
time went up from 300 s to 302 s.
Neither the subject nor the body says the flush covers the whole switch.
The commit message only says:
On a KSZ9893 the pulse removed the dynamic entries on the one user port
I tested.
The driver already has a per-port flush, ksz9477_flush_dyn_mac_table(),
which is wired up as .port_fast_age. Could that be used here, or could
the commit message at least say that all ports are flushed?
> + 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);
[Severity: Low]
Is a fixed 2 ms sleep long enough on all chips that use this function?
The new define comes with this comment:
/* The datasheet gives no pulse length. A 2 ms pulse worked on a KSZ9893. */
Nothing checks that the dynamic entries are gone before SW_FAST_AGING is
cleared. ksz9477_set_ageing_time() is installed through ksz9477_switch_ops.
That covers many chip_data entries in ksz_common.c, including the 7-port
KSZ9477/KSZ9897/KSZ9567 parts, but it was only tested on a KSZ9893 with
one user port.
The other Fast Aging user in this driver suggests the timing depends on
the chip:
drivers/net/dsa/microchip/ksz8.c:ksz8_flush_dyn_mac_table() {
...
if (ksz_is_ksz8995xa(dev)) {
/* Allow the 800 us fast-age cycle to finish before restoring
* normal ageing and port learning.
*/
...
}
Some untested chips may count each entry's stored Age Count down at a
fast tick, or may need more time to sweep the ALU. If so, could the pulse
end before every entry has expired, so that stale entries still outlive
the topology change?
> +
> + return ret ?: err;
> }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261115-ksz-stp-ageing-v2-0-7af27320033e%40pengutronix.de
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next v2 3/3] net: dsa: forget the port ageing time when the port leaves the bridge
2026-11-15 10:59 ` [PATCH net-next v2 3/3] net: dsa: forget the port ageing time when the port leaves the bridge Oleksij Rempel
2026-11-15 15:40 ` Andrew Lunn
@ 2026-11-16 11:00 ` netdev-bot+sashiko
1 sibling, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 11:00 UTC (permalink / raw)
To: o.rempel
Cc: woojung.huh, UNGLinuxDriver, andrew, olteanv, davem, edumazet,
kuba, pabeni, horms, arun.ramadoss, jiri, linusw, f.fainelli,
vivien.didelot, netdev, linux-kernel, kernel,
jensemil.schulzostergaard
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] In net/dsa/port.c, dsa_port_switchdev_unsync_attrs() now
clears the cached dp->ageing_time, but nothing on the bridge-leave…
--
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. The switch can then return to the bridge's long ageing time when
another port of the same bridge gets a restore.
> diff --git a/net/dsa/port.c b/net/dsa/port.c
> index 15e7da20b0e2f..54c9709840952 100644
> --- a/net/dsa/port.c
> +++ b/net/dsa/port.c
> @@ -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]
This clears the cache, but the leave path never writes the switch's ageing
register again. Can the chip still stay at the departed port's short
ageing time?
The hardware is only programmed in dsa_switch_ageing_time(), which runs
on DSA_NOTIFIER_AGEING_TIME:
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 notifier is only sent by dsa_port_ageing_time(). It is reached from
dsa_port_switchdev_sync_attrs() when a port joins, and from
dsa_user_port_attr_set(), which is gated on the port still offloading the
bridge:
net/dsa/user.c:dsa_user_port_attr_set() {
...
case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME:
if (!dsa_port_offloads_bridge_dev(dp, attr->orig_dev))
return -EOPNOTSUPP;
ret = dsa_port_ageing_time(dp, attr->u.ageing_time);
...
}
Take one switch with br0 holding lan1 and lan2 at 300 s, and br1 holding
only lan3 at 10 s (or 2 x forward_delay during an STP topology change on
br1). The chip runs at 10 s.
When lan3 leaves br1, the call chain is:
dsa_port_bridge_leave()
dsa_port_switchdev_unsync_attrs()
dp->ageing_time = 0;
br1 has no ports left in this tree to send a restore, and br0 has no
reason to send one. The chip stays at 10 s. br0's FDB entries then age
out early, which causes extra unknown-unicast flooding. This lasts until
br0's ageing time changes, a port joins a bridge, or br0 has its own
topology change.
At that point dsa_switch_fastest_ageing_time() would return the minimum
of the remaining cached values (300 s), but the hardware is never set to
it.
The comment kept just above the new code says there is "no good reason
(or value)" to change the ageing time here. In this case there is a
usable value: the minimum over the remaining bridged ports.
Could the leave path recompute the fastest ageing time over the switch's
remaining bridged ports after clearing the cache, and program it? The
register could be left alone when no bridged ports remain.
The commit message notes that "The switch gets the restored value only
if another port of the same bridge is still in this DSA tree", and the
v2 changelog moves the last-port case to the cover letter. The
multi-bridge case above would still leave the switch at the short value
this patch is meant to fix.
> }
>
> static int dsa_port_bridge_create(struct dsa_port *dp,
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261115-ksz-stp-ageing-v2-0-7af27320033e%40pengutronix.de
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-16 11:00 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-15 10:59 [PATCH net-next v2 0/3] net: dsa: make a shorter bridge ageing time take effect Oleksij Rempel
2026-11-15 10:59 ` [PATCH net-next v2 1/3] net: dsa: microchip: ksz9477: apply a shorter ageing time at once Oleksij Rempel
2026-11-15 15:38 ` Andrew Lunn
2026-11-16 11:00 ` netdev-bot+sashiko
2026-11-15 10:59 ` [PATCH net-next v2 2/3] net: dsa: ignore the old ageing time of the port being changed Oleksij Rempel
2026-11-15 15:40 ` Andrew Lunn
2026-11-15 10:59 ` [PATCH net-next v2 3/3] net: dsa: forget the port ageing time when the port leaves the bridge Oleksij Rempel
2026-11-15 15:40 ` Andrew Lunn
2026-11-16 11:00 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®