Do not keep the learned port when adding a static FDB entry. The ALU table of the switch keeps learned (dynamic) and static entries, one entry per address. An example: the switch has learned host H on lan1. Then a static FDB entry for H is added on lan2. The driver does not add a new entry. It finds the learned entry, makes it static and adds lan2 to its ports. The entry is now static and points to lan1 and lan2. When the FDB entry is deleted, the driver removes only lan2. The entry stays static and still points to lan1. Static entries never age out. So the switch keeps sending frames for H to lan1, even after H has moved. The bug is hit much more often once the driver sets ds->assisted_learning_on_cpu_port, which the next ksz9477 change does. DSA then adds a static entry on the CPU port for each address the bridge learns on ports outside the switch, such as Wi-Fi. If H was learned on lan1 and then moved to Wi-Fi, the entry for the CPU port still points to lan1 too. LAN937x uses the same code. Found in code review. Confirmed on a KSZ9893; with H learned on lan1, run: bridge fdb replace dev lan2 master static bridge fdb del dev lan2 master static bridge fdb show # still shows " dev lan1 self static" Tested on a KSZ9893 with the commands above and with our labgrid switch tests: with this patch, no static entry for is left. Fixes: b987e98e50ab ("dsa: add DSA switch driver for Microchip KSZ9477") Signed-off-by: Oleksij Rempel --- If bridge fdb replace moves an existing static entry to another port, the entry still keeps the old port. This patch does not change that. --- drivers/net/dsa/microchip/ksz9477.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 972703fe7454f2892b98dc507a1cba0a5c91dabd..98211d9835734c52f25dcbf7494df45166bcc8da 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -800,6 +800,13 @@ int ksz9477_fdb_add(struct dsa_switch *ds, int port, /* read ALU entry */ ksz9477_read_table(dev, alu_table); + /* The ALU table holds learned and static entries. If the entry is + * not static (learned, or none found), clear its port map, so that + * the static entry lists only this port. + */ + if (!(alu_table[0] & ALU_V_STATIC_VALID)) + alu_table[1] &= ~ALU_V_PORT_MAP; + /* update ALU entry */ alu_table[0] = ALU_V_STATIC_VALID; alu_table[1] |= BIT(port); -- 2.47.3