Do not keep the learned port when adding a static FDB entry.
The switch keeps one ALU entry per address and FID, for learned and for
static entries. If the switch has learned host H on lan1 and a static
FDB entry for H is added on lan2, the driver makes the learned entry
static and adds lan2 to it. After the FDB entry is deleted, the static
entry still points to lan1 and never ages out.
The next patch, "do not learn addresses on the CPU port", makes this
issue more likely to trigger: DSA then adds a static CPU-port entry for
each address that the bridge learns on a port outside the switch.
This part of the code has one more issue that this patch does not
address: bridge fdb replace of a static entry. When it moves the static
entry for H from lan1 to lan2, the bridge sends no delete for lan1, so
the switch entry keeps lan1. The driver cannot drop the old port on its
own: without FDB isolation, the same ALU entry can also hold the CPU
port for a host entry of H, and that port must stay.
An AI code review agent found the bug fixed here while reviewing the
next patch. Reproduced and tested on a KSZ9893 with H learned on lan1:
bridge fdb replace <H> dev lan2 master static
bridge fdb del <H> dev lan2 master static
bridge fdb show # without this patch: "<H> dev lan1 self static"
Fixes: b987e98e50ab ("dsa: add DSA switch driver for Microchip KSZ9477")
Signed-off-by: Oleksij Rempel <o.re…@pengutronix.de>
---
Changes in v2:
- No code changes. Commit message: say that bridge fdb replace is not
covered, and why (sashiko).
---
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