net: sparx5: add router legs for L3 routing offload
Subsystems (4)
v3 cover net: sparx5: add router legs for L3 routing offload
This is the first series adding L3 unicast routing offload for IPv4 and IPv6 to Sparx5 and LAN969x. It adds the routing registers and the router legs, the hardware interfaces where routing happens. No route is offloaded yet. Routing is enabled in the chip, but with no LPM rule a routed frame misses the lookup and is redirected to the CPU, so the kernel keeps routing every frame in software.
The chips only route in VLAN aware mode. A router leg is created for a direct VLAN upper of the offloaded bridge when it gets its first address, provided the upper qualifies for hardware routing: a non-zero vid, the bridge VLAN protocol, the bridge MAC and no master. Any other configuration is routed in software as usual.
Patch 1 adds the register macros for the L3 routing blocks.
Patch 2 adds the router legs, their lifecycle on address events, the global leg base MAC and the hardware enable sequence.
Patch 3 keeps the legs in sync with the bridge. A transition that would leave the hardware and kernel routing differently drops the leg instead of being refused, and the leg is recreated once the upper qualifies. It also follows bridge MAC and vid changes and the upper going down, and recreates the legs when a switch port joins the bridge again.
The plan for future series building on this one:
2: track FIB entries and trap them to the CPU, with the LPM VCAP 3: main and local table arbitration, FIB rule refusal and neighbour
host routes
4: forwarding through a single nexthop, ECMP and blackhole routes 5: routes through nexthop objects
The Super VCAP shared-register race reported on v1 is fixed separately by commit d7a8d500d7e4 ("net: microchip: vcap: fix races on the shared Super VCAP block"), which is now in net-next.
---
Changes in v3:
- Split the series. The router code is now rebuilt as smaller series.
This series keeps the registers and the router legs. The VCAP
preparation moves to the second series.
- Tighten which device may carry a router leg: a direct VLAN upper of
the bridge whose ports are offloaded, without a master of its own,
with a non-zero vid, the bridge VLAN protocol and the bridge MAC.
- Follow the transitions that would leave the chip and kernel out of
sync: enslaving a leg to any master, changing its MAC, and disabling vlan_filtering or changing the VLAN protocol on its bridge drop the
leg, which is created again when the upper qualifies.
- Destroy a leg created from the address validator when the address add
fails afterwards, and handle IPv6 address removal from a work embedded
in the router rather than one allocated per event.
- Keep addresses when a leg cannot be created, and route that upper
in software.
- Disable a leg as an ingress router leg while its upper is down or the
bridge does not carry its vid.
- Flush the legs of a bridge when its last switch port leaves and
recreate them on rejoin.
- Program the leg base MAC from the bridge MAC when a leg is created,
not only when the bridge MAC changes.
- Enable unicast routing only on the switch ports, and restore the
routing registers when the router is torn down.
- Carry on without offload when the router cannot initialise, rather
than failing the probe, and skip the router without CONFIG_VLAN_8021Q.
- Remove the blackhole leg and the IPv6 link-local trap.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Reworked neighbour lifetime: anchor neighbours to the router leg
instead of the most-specific covering FIB entry (matching
mlxsw/prestera). Fixes a neighbour-entry leak (memory + VMID + host
VCAP rule + netdev reference) and lets the software LPM be removed
entirely.
- Fixed a heap overflow in the fib6 nexthop prune path.
- Fixed a leak on the router_init() error path.
- Hardening: netns filtering and offload-ownership checks on the global
notifiers, and a NETDEV_UNREGISTER leg-teardown backstop.
- Fixed do_div() misuse on a 32-bit value. Added the missing RCU
annotation on in_dev->ifa_list.
- Zero-initialise the actionfield data in vcap_rule_mod_action_bit().
- Updated the sparx5_router.c header comment to describe the
leg-anchored model.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Jens Emil Schulz Østergaard (3):
net: sparx5: add l3 routing registers
net: sparx5: add L3 router legs
net: sparx5: keep router legs in sync with the bridge
drivers/net/ethernet/microchip/sparx5/Makefile | 2 +- .../ethernet/microchip/sparx5/lan969x/lan969x.c | 1 + .../microchip/sparx5/lan969x/lan969x_regs.c | 11 + .../net/ethernet/microchip/sparx5/sparx5_main.c | 13 +- .../net/ethernet/microchip/sparx5/sparx5_main.h | 37 + .../ethernet/microchip/sparx5/sparx5_main_regs.h | 528 ++++++++++++ .../net/ethernet/microchip/sparx5/sparx5_regs.c | 11 + .../net/ethernet/microchip/sparx5/sparx5_regs.h | 11 + .../net/ethernet/microchip/sparx5/sparx5_router.c | 913 +++++++++++++++++++++ .../ethernet/microchip/sparx5/sparx5_switchdev.c | 30 +- .../net/ethernet/microchip/sparx5/sparx5_vlan.c | 2 + 11 files changed, 1554 insertions(+), 5 deletions(-)
---
base-commit: 6ff4c5942a301675eb12e5b49d53a81e604624a1
change-id: 20260210-sparx5_l3_routing-962458e4d3da
Best regards,
Signature · 1 line
Jens Emil Schulz Østergaard <[email protected]>
PATCH v3 1/3 net: sparx5: add l3 routing registers
Add the registers used to configure L3 routing, on both sparx5 and
lan969x: the common routing and router leg configuration of ANA_L3, its per VLAN and per VMID router leg configuration and its ARP table, the router leg MAC and per VMID router leg control of REW, the router leg MAC of EACL, and the VCAP_S2_MISC_CTRL register of ANA_ACL.
--- .../microchip/sparx5/lan969x/lan969x_regs.c | 11 + .../ethernet/microchip/sparx5/sparx5_main_regs.h | 528 +++++++++++++++++++++ .../net/ethernet/microchip/sparx5/sparx5_regs.c | 11 + .../net/ethernet/microchip/sparx5/sparx5_regs.h | 11 + 4 files changed, 561 insertions(+)
drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_regs.c +11 -0
@@ -82,12 +82,15 @@ const unsigned int lan969x_gaddr[GADDR_LAST] = { [GA_ANA_CL_COMMON] = 87040, [GA_ANA_L2_COMMON] = 561928, [GA_ANA_L3_COMMON] = 370752, + [GA_ANA_L3_VMID] = 360448, + [GA_ANA_L3_ARP] = 294912, [GA_ANA_L3_VLAN_ARP_L3MC_STICKY] = 368580, [GA_ASM_CFG] = 18304, [GA_ASM_PFC_TIMER_CFG] = 15568, [GA_ASM_LBK_WM_CFG] = 15596, [GA_ASM_LBK_MISC_CFG] = 15608, [GA_ASM_RAM_CTRL] = 15684, + [GA_EACL_COMMON] = 37408, [GA_EACL_ES2_KEY_SELECT_PROFILE] = 36864, [GA_EACL_CNT_TBL] = 30720, [GA_EACL_POL_CFG] = 38400,
@@ -111,6 +114,7 @@ const unsigned int lan969x_gaddr[GADDR_LAST] = { [GA_QSYS_RAM_CTRL] = 2204, [GA_REW_COMMON] = 98304, [GA_REW_PORT] = 49152, + [GA_REW_VMID] = 96768, [GA_REW_VOE_PORT_LM_CNT] = 90112, [GA_REW_RAM_CTRL] = 93992, [GA_VOP_RAM_CTRL] = 16368,
@@ -133,6 +137,8 @@ const unsigned int lan969x_gcnt[GCNT_LAST] = { [GC_ANA_L2_ISDX_LIMIT] = 256, [GC_ANA_L2_ISDX] = 1024, [GC_ANA_L3_VLAN] = 4608, + [GC_ANA_L3_VMID] = 127, + [GC_ANA_L3_ARP] = 1024, [GC_ASM_DEV_STATISTICS] = 30, [GC_EACL_ES2_KEY_SELECT_PROFILE] = 68, [GC_EACL_CNT_TBL] = 512,
@@ -143,6 +149,7 @@ const unsigned int lan969x_gcnt[GCNT_LAST] = { [GC_PTP_PTP_PINS] = 8, [GC_PTP_PHASE_DETECTOR_CTRL] = 8, [GC_REW_PORT] = 35, + [GC_REW_VMID] = 127, [GC_REW_VOE_PORT_LM_CNT] = 240, };
@@ -202,7 +209,10 @@ const unsigned int lan969x_fsize[FSIZE_LAST] = { [FW_ANA_L2_AUTO_LRN_CFG_AUTO_LRN_ENA] = 30, [FW_ANA_L2_DLB_CFG_DLB_IDX] = 9, [FW_ANA_L2_TSN_CFG_TSN_SFID] = 8, + [FW_ANA_L3_L3_UC_ENA_L3_UC_ENA] = 30, + [FW_ANA_L3_VMID_CFG_VMID] = 7, [FW_ANA_L3_VLAN_MASK_CFG_VLAN_PORT_MASK] = 30, + [FW_ANA_L3_ARP_CFG_0_ARP_VMID] = 7, [FW_FDMA_CH_CFG_CH_DCB_DB_CNT] = 2, [FW_GCB_HW_SGPIO_TO_SD_MAP_CFG_SGPIO_TO_SD_SEL] = 7, [FW_HSCH_SE_CFG_SE_DWRR_CNT] = 5,
@@ -234,6 +244,7 @@ const unsigned int lan969x_fsize[FSIZE_LAST] = { [FW_QSYS_ATOP_ATOP] = 11, [FW_QSYS_ATOP_TOT_CFG_ATOP_TOT] = 11, [FW_REW_RTAG_ETAG_CTRL_IPE_TBL] = 6, + [FW_REW_RLEG_CTRL_DECAP_IRLEG] = 7, [FW_XQS_STAT_CFG_STAT_VIEW] = 10, [FW_XQS_QLIMIT_SHR_TOP_CFG_QLIMIT_SHR_TOP] = 14, [FW_XQS_QLIMIT_SHR_ATOP_CFG_QLIMIT_SHR_ATOP] = 14,
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h +528 -0
564 lines not on this page · raw message
drivers/net/ethernet/microchip/sparx5/sparx5_regs.c +11 -0
@@ -82,12 +82,15 @@ const unsigned int sparx5_gaddr[GADDR_LAST] = { [GA_ANA_CL_COMMON] = 166912, [GA_ANA_L2_COMMON] = 566024, [GA_ANA_L3_COMMON] = 493632, + [GA_ANA_L3_VMID] = 458752, + [GA_ANA_L3_ARP] = 327680, [GA_ANA_L3_VLAN_ARP_L3MC_STICKY] = 491460, [GA_ASM_CFG] = 33280, [GA_ASM_PFC_TIMER_CFG] = 34716, [GA_ASM_LBK_WM_CFG] = 34744, [GA_ASM_LBK_MISC_CFG] = 34756, [GA_ASM_RAM_CTRL] = 34832, + [GA_EACL_COMMON] = 118480, [GA_EACL_ES2_KEY_SELECT_PROFILE] = 149504, [GA_EACL_CNT_TBL] = 122880, [GA_EACL_POL_CFG] = 150608,
@@ -111,6 +114,7 @@ const unsigned int sparx5_gaddr[GADDR_LAST] = { [GA_QSYS_RAM_CTRL] = 2344, [GA_REW_COMMON] = 387264, [GA_REW_PORT] = 360448, + [GA_REW_VMID] = 389120, [GA_REW_VOE_PORT_LM_CNT] = 393216, [GA_REW_RAM_CTRL] = 378696, [GA_VOP_RAM_CTRL] = 279176,
@@ -133,6 +137,8 @@ const unsigned int sparx5_gcnt[GCNT_LAST] = { [GC_ANA_L2_ISDX_LIMIT] = 1536, [GC_ANA_L2_ISDX] = 4096, [GC_ANA_L3_VLAN] = 5120, + [GC_ANA_L3_VMID] = 511, + [GC_ANA_L3_ARP] = 2048, [GC_ASM_DEV_STATISTICS] = 65, [GC_EACL_ES2_KEY_SELECT_PROFILE] = 138, [GC_EACL_CNT_TBL] = 2048,
@@ -143,6 +149,7 @@ const unsigned int sparx5_gcnt[GCNT_LAST] = { [GC_PTP_PTP_PINS] = 5, [GC_PTP_PHASE_DETECTOR_CTRL] = 5, [GC_REW_PORT] = 70, + [GC_REW_VMID] = 511, [GC_REW_VOE_PORT_LM_CNT] = 520, };
@@ -202,7 +209,10 @@ const unsigned int sparx5_fsize[FSIZE_LAST] = { [FW_ANA_L2_AUTO_LRN_CFG_AUTO_LRN_ENA] = 32, [FW_ANA_L2_DLB_CFG_DLB_IDX] = 13, [FW_ANA_L2_TSN_CFG_TSN_SFID] = 10, + [FW_ANA_L3_L3_UC_ENA_L3_UC_ENA] = 32, + [FW_ANA_L3_VMID_CFG_VMID] = 9, [FW_ANA_L3_VLAN_MASK_CFG_VLAN_PORT_MASK] = 32, + [FW_ANA_L3_ARP_CFG_0_ARP_VMID] = 9, [FW_FDMA_CH_CFG_CH_DCB_DB_CNT] = 4, [FW_GCB_HW_SGPIO_TO_SD_MAP_CFG_SGPIO_TO_SD_SEL] = 9, [FW_HSCH_SE_CFG_SE_DWRR_CNT] = 7,
@@ -234,6 +244,7 @@ const unsigned int sparx5_fsize[FSIZE_LAST] = { [FW_QSYS_ATOP_ATOP] = 12, [FW_QSYS_ATOP_TOT_CFG_ATOP_TOT] = 12, [FW_REW_RTAG_ETAG_CTRL_IPE_TBL] = 7, + [FW_REW_RLEG_CTRL_DECAP_IRLEG] = 9, [FW_XQS_STAT_CFG_STAT_VIEW] = 13, [FW_XQS_QLIMIT_SHR_TOP_CFG_QLIMIT_SHR_TOP] = 15, [FW_XQS_QLIMIT_SHR_ATOP_CFG_QLIMIT_SHR_ATOP] = 15,
drivers/net/ethernet/microchip/sparx5/sparx5_regs.h +11 -0
@@ -91,12 +91,15 @@ enum sparx5_gaddr_enum {GA_ANA_CL_COMMON ,GA_ANA_L2_COMMON ,GA_ANA_L3_COMMON , +GA_ANA_L3_VMID , +GA_ANA_L3_ARP ,GA_ANA_L3_VLAN_ARP_L3MC_STICKY ,GA_ASM_CFG ,GA_ASM_PFC_TIMER_CFG ,GA_ASM_LBK_WM_CFG ,GA_ASM_LBK_MISC_CFG ,GA_ASM_RAM_CTRL , +GA_EACL_COMMON ,GA_EACL_ES2_KEY_SELECT_PROFILE ,GA_EACL_CNT_TBL , GA_EACL_POL_CFG,
@@ -120,6 +123,7 @@ enum sparx5_gaddr_enum {GA_QSYS_RAM_CTRL ,GA_REW_COMMON ,GA_REW_PORT , +GA_REW_VMID ,GA_REW_VOE_PORT_LM_CNT ,GA_REW_RAM_CTRL , GA_VOP_RAM_CTRL,
@@ -143,6 +147,8 @@ enum sparx5_gcnt_enum {GC_ANA_L2_ISDX_LIMIT ,GC_ANA_L2_ISDX ,GC_ANA_L3_VLAN , +GC_ANA_L3_VMID , +GC_ANA_L3_ARP ,GC_ASM_DEV_STATISTICS ,GC_EACL_ES2_KEY_SELECT_PROFILE , GC_EACL_CNT_TBL,
@@ -153,6 +159,7 @@ enum sparx5_gcnt_enum {GC_PTP_PTP_PINS ,GC_PTP_PHASE_DETECTOR_CTRL ,GC_REW_PORT , +GC_REW_VMID ,GC_REW_VOE_PORT_LM_CNT , GCNT_LAST, };
@@ -215,7 +222,10 @@ enum sparx5_fsize_enum {FW_ANA_L2_AUTO_LRN_CFG_AUTO_LRN_ENA ,FW_ANA_L2_DLB_CFG_DLB_IDX ,FW_ANA_L2_TSN_CFG_TSN_SFID , +FW_ANA_L3_L3_UC_ENA_L3_UC_ENA , +FW_ANA_L3_VMID_CFG_VMID ,FW_ANA_L3_VLAN_MASK_CFG_VLAN_PORT_MASK , +FW_ANA_L3_ARP_CFG_0_ARP_VMID ,FW_FDMA_CH_CFG_CH_DCB_DB_CNT ,FW_GCB_HW_SGPIO_TO_SD_MAP_CFG_SGPIO_TO_SD_SEL , FW_HSCH_SE_CFG_SE_DWRR_CNT,
@@ -247,6 +257,7 @@ enum sparx5_fsize_enum {FW_QSYS_ATOP_ATOP ,FW_QSYS_ATOP_TOT_CFG_ATOP_TOT ,FW_REW_RTAG_ETAG_CTRL_IPE_TBL , +FW_REW_RLEG_CTRL_DECAP_IRLEG ,FW_XQS_STAT_CFG_STAT_VIEW ,FW_XQS_QLIMIT_SHR_TOP_CFG_QLIMIT_SHR_TOP , FW_XQS_QLIMIT_SHR_ATOP_CFG_QLIMIT_SHR_ATOP,
Signature · 1 line
2.52.0
PATCH v3 2/3 net: sparx5: add L3 router legs
In reply to Jens Emil Schulz ØstergaardThe chips can only route in VLAN aware mode, and routing happens between router legs (RLEG). To each direct VLAN upper of a VLAN aware bridge, we associate a router leg. The indices to the router leg table are called VMIDs in the datasheet. Leg hardware state is indexed by VLAN id, so leg vids must be unique.
A leg is created when the first address is added to such an upper, and destroyed when the last one is removed or the upper is unregistered. A bridge's legs are also torn down when its last switch port leaves, since the switch then has no datapath on it.
There is a global router leg base MAC used for MAC rewrites by the chip. Here we use the bridge MAC, programmed when a leg is created.
A router leg is offloaded only for a device that is:
1) A direct VLAN upper of the single bridge that has switch ports lowers.
2) On an 802.1Q bridge, using the bridge's VLAN protocol.
3) On a non-zero vid. Every non-bridged port classifies into vid 0, so such a leg would offer routing to frames from ports outside the bridge.
4) Carrying and inheriting the bridge MAC. ANA_L3 matches one global base MAC as the router leg MAC for every VMID.
5) Without a master. A bridge, LAG, OVS or HSR master owns the devices rx path, and an l3mdev master owns its routing table.
The conditions are evaluated when an address is added to a VLAN upper. Configurations that are not offloaded are handled in software as usual. A qualifying upper whose leg cannot be created, because the VMIDs are used up, an allocation fails or another upper already has a leg for the vid, keeps its address and is routed in software. The failure is reported as an extack warning, or in the kernel log.
Routing is enabled in the chip, but no LPM rule is programmed. A routed frame misses the LPM lookup and is redirected to the CPU on CPU_UC_FAIL_QU, so the kernel routes every frame in software.
L3 offload is optional. If the router cannot initialise, probe carries on without offload rather than failing the whole switch.
Without CONFIG_VLAN_8021Q there is no VLAN upper to attach a leg to, so sparx5_rr_router_init() returns early: no notifiers are registered and routing is not enabled in the chip.
--- drivers/net/ethernet/microchip/sparx5/Makefile | 2 +- .../ethernet/microchip/sparx5/lan969x/lan969x.c | 1 + .../net/ethernet/microchip/sparx5/sparx5_main.c | 13 +- .../net/ethernet/microchip/sparx5/sparx5_main.h | 33 + .../net/ethernet/microchip/sparx5/sparx5_router.c | 783 +++++++++++++++++++++ .../ethernet/microchip/sparx5/sparx5_switchdev.c | 5 +- .../net/ethernet/microchip/sparx5/sparx5_vlan.c | 2 + 7 files changed, 835 insertions(+), 4 deletions(-)
drivers/net/ethernet/microchip/sparx5/Makefile +1 -1
@@ -11,7 +11,7 @@ sparx5-switch-y := sparx5_main.o sparx5_packet.o \ sparx5_ptp.o sparx5_pgid.o sparx5_tc.o sparx5_qos.o \ sparx5_vcap_impl.o sparx5_vcap_ag_api.o sparx5_tc_flower.o \ sparx5_tc_matchall.o sparx5_pool.o sparx5_sdlb.o sparx5_police.o \ - sparx5_psfp.o sparx5_mirror.o sparx5_regs.o sparx5_tas.o + sparx5_psfp.o sparx5_mirror.o sparx5_regs.o sparx5_tas.o sparx5_router.o sparx5-switch-$(CONFIG_SPARX5_DCB) += sparx5_dcb.o sparx5-switch-$(CONFIG_DEBUG_FS) += sparx5_vcap_debugfs.o
drivers/net/ethernet/microchip/sparx5/lan969x/lan969x.c +1 -0
@@ -324,6 +324,7 @@ static const struct sparx5_consts lan969x_consts = { .qres_max_prio_idx = 315, .qres_max_colour_idx = 323, .tod_pin = 4, + .vmid_cnt = 127, .vcaps = lan969x_vcaps, .vcap_stats = &lan969x_vcap_stats, .vcaps_cfg = lan969x_vcap_inst_cfg,
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +11 -2
@@ -995,15 +995,22 @@ static int mchp_sparx5_probe(struct platform_device *pdev) goto cleanup_ptp; } +/* L3 offload is optional, probe carries on without it. */ + err =sparx5_rr_router_init (sparx5); +if (err) +dev_warn (sparx5->dev,"L3 routing offload unavailable: %pe\n" , +ERR_PTR (err)); + err =sparx5_register_notifier_blocks (sparx5);if (err) {dev_err (sparx5->dev,"Failed to register notifier blocks\n" ); - goto cleanup_netdevs; + goto cleanup_router; } goto cleanup_config; -cleanup_netdevs: +cleanup_router: +sparx5_rr_router_deinit (sparx5);sparx5_unregister_netdevs (sparx5); cleanup_ptp:sparx5_ptp_deinit (sparx5);
@@ -1030,6 +1037,7 @@ static void mchp_sparx5_remove(struct platform_device *pdev)debugfs_remove_recursive (sparx5->debugfs_root);sparx5_unregister_notifier_blocks (sparx5); +sparx5_rr_router_deinit (sparx5);sparx5_unregister_netdevs (sparx5);sparx5_ptp_deinit (sparx5);sparx5_frame_io_deinit (sparx5);
@@ -1070,6 +1078,7 @@ static const struct sparx5_consts sparx5_consts = { .qres_max_prio_idx = 630, .qres_max_colour_idx = 638, .tod_pin = 4, + .vmid_cnt = 511, .vcaps = sparx5_vcaps, .vcaps_cfg = sparx5_vcap_inst_cfg, .vcap_stats = &sparx5_vcap_stats,
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +33 -0
@@ -138,6 +138,11 @@ enum sparx5_feature {#define SPARX5_MAX_PTP_ID 512 +/* Must be the maximum across all L3 enabled platforms, which +* sparx5_rr_router_init() checks against the per-platform consts. +*/ +#define SPARX5_ROUTER_LEG_N_VMID 511 +struct sparx5 ;struct sparx5_calendar_data {
@@ -356,6 +361,7 @@ struct sparx5_consts {u32 qres_max_prio_idx;/* Maximum QRES prio index */ u32 qres_max_colour_idx;/* Maximum QRES colour index */ u32 tod_pin;/* PTP TOD pin */ +u32 vmid_cnt;/* Number of router leg VMID's */ const struct sparx5_vcap_inst *vcaps_cfg;const struct vcap_info *vcaps;const struct vcap_statistics *vcap_stats;
@@ -473,6 +479,8 @@ struct sparx5 {/* Common root for debugfs */ struct dentry *debugfs_root;const struct sparx5_match_data *data; +/* L3 Forwarding */ +struct sparx5_router *router; };/* sparx5_main.c */
@@ -542,6 +550,31 @@ int sparx5_vlan_vid_add(struct sparx5_port *port, u16 vid, bool pvid,int sparx5_vlan_vid_del (struct sparx5_port *port,u16 vid);void sparx5_vlan_port_apply (struct sparx5 *sparx5,struct sparx5_port *port); +/* sparx5_router.c */ +void sparx5_rr_port_fwd_update (struct sparx5 *sparx5); +int sparx5_rr_router_init (struct sparx5 *sparx5); +void sparx5_rr_router_deinit (struct sparx5 *sparx5); +void sparx5_rr_bridge_legs_flush (struct sparx5 *sparx5, +const struct net_device *bridge); + +struct sparx5_router { +struct sparx5 *sparx5; +struct notifier_block inetaddr_nb; +struct notifier_block inetaddr_valid_nb; +struct notifier_block netdevice_nb; +struct notifier_block inet6addr_nb; +struct notifier_block inet6addr_valid_nb; + +struct mutex lock;/* Global router lock for all shared data. */ + +struct workqueue_struct *sparx5_router_owq; +struct work_struct legs_work; + +struct list_head leg_list; +/* Track allocated router leg indices in hw */ + DECLARE_BITMAP(vmid_mask, SPARX5_ROUTER_LEG_N_VMID); +}; +/* sparx5_calendar.c */ int sparx5_calendar_init (struct sparx5 *sparx5); int sparx5_dsm_calendar_calc(struct sparx5 *sparx5, u32 taxi,
drivers/net/ethernet/microchip/sparx5/sparx5_router.c new file +783 -0
783 lines not on this page · raw message
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c +4 -1
@@ -227,8 +227,11 @@ static void sparx5_port_bridge_leave(struct sparx5_port *port,switchdev_bridge_port_unoffload (port->ndev,NULL ,NULL ,NULL );clear_bit (port->portno, sparx5->bridge_mask); -if (bitmap_empty (sparx5->bridge_mask,SPX5_PORTS )) +if (bitmap_empty (sparx5->bridge_mask,SPX5_PORTS )) { +/* L3 offload has no datapath left on this bridge. */ +sparx5_rr_bridge_legs_flush (sparx5, bridge); sparx5->hw_bridge_dev =NULL ; + }/* Clear bridge vlan settings before updating the port settings */ port->vlan_aware =0 ;
drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c +2 -0
@@ -199,6 +199,8 @@ void sparx5_update_fwd(struct sparx5 *sparx5)spx5_wr (mask[1 ], sparx5,ANA_L2_AUTO_LRN_CFG1 );spx5_wr (mask[2 ], sparx5,ANA_L2_AUTO_LRN_CFG2 ); } + +sparx5_rr_port_fwd_update (sparx5); } void sparx5_vlan_port_apply(struct sparx5 *sparx5,
Signature · 1 line
2.52.0
PATCH v3 3/3 net: sparx5: keep router legs in sync with the bridge
In reply to Jens Emil Schulz ØstergaardThe conditions for offloading a leg are evaluated when an address is added, but the bridge and the upper can change afterwards.
A change that would leave the chip routing differently from the kernel destroys the leg before it takes effect: disabling VLAN filtering, changing the bridge to a VLAN protocol other than 802.1Q, linking the upper to a master, and changing the upper's MAC.
The global leg base MAC follows later bridge MAC changes. When the first switch port joins a bridge again, the reconcile runs at once and creates the legs for its uppers that kept their addresses while the bridge was not offloaded.
While the upper is administratively down the leg is disabled as an ingress router leg. The same holds while the bridge itself does not carry the leg's vid, or carries it untagged, since the kernel then does not deliver that vid to the upper. A bridge vlan delete, or an add that makes the vid untagged, disables the leg at once.
A leg with an IPv4 address is kept while the upper is down, so it is available again when the interface comes back up. Unless keep_addr_on_down is set, link down removes IPv6 addresses, so an IPv6 only leg goes with its last address.
IPv6 addresses that the kernel adds without calling the validator, such as SLAAC and temporary addresses, get their leg from the reconcile, which the address notifier queues for them.
--- .../net/ethernet/microchip/sparx5/sparx5_main.h | 4 + .../net/ethernet/microchip/sparx5/sparx5_router.c | 142 ++++++++++++++++++++- .../ethernet/microchip/sparx5/sparx5_switchdev.c | 25 +++- 3 files changed, 164 insertions(+), 7 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +4 -0
@@ -556,6 +556,10 @@ int sparx5_rr_router_init(struct sparx5 *sparx5);void sparx5_rr_router_deinit (struct sparx5 *sparx5);void sparx5_rr_bridge_legs_flush (struct sparx5 *sparx5,const struct net_device *bridge); +void sparx5_rr_legs_reconcile (struct sparx5 *sparx5); +void sparx5_rr_legs_reconcile_schedule (struct sparx5 *sparx5); +void sparx5_rr_bridge_vlan_clear (struct sparx5 *sparx5, +const struct net_device *bridge,u16 vid);struct sparx5_router {struct sparx5 *sparx5;
drivers/net/ethernet/microchip/sparx5/sparx5_router.c +136 -6
226 lines not on this page · raw message
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c +24 -1
@@ -152,6 +152,11 @@ static int sparx5_port_attr_set(struct net_device *dev, const void *ctx,sparx5_port_attr_ageing_set (port, attr->u.ageing_time);break ;case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING : +/* L3 offload requires a VLAN aware bridge. */ +if (!attr->u.vlan_filtering) +sparx5_rr_bridge_legs_flush (port->sparx5, + attr->orig_dev); +sparx5_rr_legs_reconcile_schedule (port->sparx5);/* Used PVID 1 when default_pvid is 0, to avoid * collision with non-bridged ports. */
@@ -160,6 +165,13 @@ static int sparx5_port_attr_set(struct net_device *dev, const void *ctx, port->vlan_aware = attr->u.vlan_filtering;sparx5_vlan_port_apply (port->sparx5, port);break ; +case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL : +/* A leg is classified by vid alone, whatever the protocol. */ +if (attr->u.vlan_protocol !=ETH_P_8021Q ) +sparx5_rr_bridge_legs_flush (port->sparx5, + attr->orig_dev); +sparx5_rr_legs_reconcile_schedule (port->sparx5); +return -EOPNOTSUPP ;case SWITCHDEV_ATTR_ID_PORT_MROUTER : sparx5_port_attr_mrouter_set(port, attr->orig_dev,
@@ -179,9 +191,11 @@ static int sparx5_port_bridge_join(struct sparx5_port *port,struct switchdev_brport_flags flags = {0 };struct sparx5 *sparx5 = port->sparx5;struct net_device *ndev = port->ndev; +bool first;int err; -if (bitmap_empty (sparx5->bridge_mask,SPX5_PORTS )) + first =bitmap_empty (sparx5->bridge_mask,SPX5_PORTS ); +if (first)/* First bridged port */ sparx5->hw_bridge_dev = bridge;else
@@ -211,6 +225,10 @@ static int sparx5_port_bridge_join(struct sparx5_port *port, flags.val = flags.mask;sparx5_port_attr_bridge_flags (port, flags); +/* The bridge's legs were flushed when its last port left. */ +if (first) +sparx5_rr_legs_reconcile (sparx5); +return 0 ; err_switchdev_offload:
@@ -448,6 +466,10 @@ static int sparx5_handle_port_vlan_add(struct net_device *dev,/* Flood broadcast to CPU */ sparx5_mact_learn (sparx5,sparx5_get_pgid (sparx5,PGID_BCAST ), dev->broadcast, v->vid); +if (v->flags &BRIDGE_VLAN_INFO_UNTAGGED ) +sparx5_rr_bridge_vlan_clear (sparx5, dev, v->vid); +else +sparx5_rr_legs_reconcile_schedule (sparx5);return 0 ; }
@@ -683,6 +705,7 @@ static int sparx5_handle_port_vlan_del(struct net_device *dev, switchdev_blocking_nb);sparx5_mact_forget (sparx5, dev->broadcast, vid); +sparx5_rr_bridge_vlan_clear (sparx5, dev, vid);return 0 ; }
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v3 3/3] net: sparx5: keep router legs in sync with the bridge
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 1 · Low: 2
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).
- [High] sparx5_rr_legs_reconcile() now walks netdev_for_each_upper_dev_rcu(sparx5->hw_bridge_dev, ...) from the…
- [Medium] Contrary to the commit message, a router leg can be lost while its upper is down.
- [Low] In sparx5_rr_router_init() the new comment says "The exported helpers use leg_list once sparx5->router is set".
- [Low] The function comment above sparx5_rr_bridge_legs_flush() still reads "Tear down the router legs of a bridge that is no longer…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but this patch extends the affected code.
--
net: sparx5: keep router legs in sync with the bridge
This commit makes the sparx5 L3 router legs follow later changes to the bridge and the vlan upper. A leg is destroyed when vlan filtering is disabled, when the bridge moves to a non-802.1Q protocol, when the upper is linked to a master, or when the upper's MAC changes. Ingress routing on a leg is limited to when the upper is up and the bridge carries the vid tagged, and the reconcile now also creates legs for eligible uppers of the offloaded bridge.
Quoted 4 lines
drivers/net/ethernet/microchip/sparx5/sparx5_router.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/ethernet/microchip/sparx5/sparx5_router.c +0
-0@@ -568,19 +650,66 @@ static void sparx5_rr_router_legs_flush(struct sparx5 *sparx5)
[ ... ]
Quoted 11 lines
drivers/net/ethernet/microchip/sparx5/sparx5_router.c +4
-0+void sparx5_rr_legs_reconcile (struct sparx5 *sparx5) {struct sparx5_rr_router_leg *leg, *tmp; +struct net_device *bridge, *dev;struct sparx5_router *router; +struct list_head *iter;ASSERT_RTNL (); router = sparx5->router; +if (!router)
drivers/net/ethernet/microchip/sparx5/sparx5_router.c static void sparx5_rr_router_legs_flush(struct sparx5 *sparx5) · line 694
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_router.c +5
-1+return ;mutex_lock (&router->lock);list_for_each_entry_safe (leg, tmp, &router->leg_list, leg_list_node) { -if (sparx5_rr_dev_addr_list_empty (leg->dev)) +if (sparx5_rr_dev_addr_list_empty (leg->dev) || + !sparx5_rr_dev_real_is_vlan_aware (sparx5, leg->dev)) {sparx5_rr_router_leg_destroy (leg); +continue ; + }
[Severity: Medium]
The commit message says:
"A leg with an IPv4 address is kept while the upper is down, so it is available again when the interface comes back up."
Does this still hold if the bridge MAC changes while a NET_ADDR_STOLEN vlan upper is down?
When the bridge sends NETDEV_CHANGEADDR, vlan_device_event() in net/8021q/vlan.c skips uppers that are not IFF_UP. A down upper therefore keeps the old MAC, and sparx5_rr_dev_real_is_vlan_aware() then fails here:
if (dev->addr_assign_type != NET_ADDR_STOLEN || !ether_addr_equal(dev->dev_addr, vlan_rdev->dev_addr)) return false;
On the next reconcile, the new check above destroys the down upper's IPv4 leg and frees its VMID.
Unrelated events can queue that reconcile: an inet6addr UP/DOWN on any vlan device, a bridge vlan add or del, or the VLAN_FILTERING attr that is sent when a sparx5 port joins. For example, a port with a lower MAC joins the bridge. That queues the reconcile, and br_stp_recalculate_bridge_id() changes the bridge MAC before the reconcile runs.
Suppose the bridge MAC then changes back before the upper comes up, for example because the port leaves again or after ip link set br0 address <old>. What recreates the leg then? The bridge NETDEV_CHANGEADDR in sparx5_rr_netdevice_event() does not queue a reconcile, because is_vlan_dev(bridge) is false:
case NETDEV_CHANGEADDR: mutex_lock(&router->lock); if (sparx5_rr_bridge_has_legs(sparx5, dev)) sparx5_rr_leg_base_mac_set(sparx5, dev->dev_addr); mutex_unlock(&router->lock); if (is_vlan_dev(dev)) sparx5_rr_legs_reconcile_schedule(sparx5);
When the upper is later brought up, the MACs already match, so no CHANGEADDR is sent. The NETDEV_UP case only refreshes an existing leg. The IPv4 address already exists, so the validator does not run either. With IPv6 disabled on the upper (disable_ipv6, or addr_gen_mode none), no link-local NETDEV_UP arrives.
Wouldn't the upper then stay without a leg until something unrelated triggers a reconcile?
Now take the case where the upper comes up while the bridge still has the new MAC. vlan_dev_open()->vlan_dev_inherit_address() does queue a reconcile. But if another upper has taken the freed VMID in the meantime, creating the leg fails, and only a ratelimited warning is printed.
drivers/net/ethernet/microchip/sparx5/sparx5_router.c static void sparx5_rr_router_legs_flush(struct sparx5 *sparx5) · line 704
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_router.c +10
-0+ + bridge =vlan_dev_real_dev (leg->dev); + leg->vlan_present =sparx5_rr_bridge_vlan_present (bridge, + leg->vid); +sparx5_rr_leg_hw_uc_update (sparx5, leg); + } + + bridge = sparx5->hw_bridge_dev; +if (!bitmap_empty (sparx5->bridge_mask,SPX5_PORTS ) && bridge) { +netdev_for_each_upper_dev_rcu (bridge, dev, iter) {
[Severity: High]
Can this walk a bridge that has already been freed during driver removal?
The driver holds no reference on hw_bridge_dev. Only sparx5_port_bridge_leave() clears hw_bridge_dev and bridge_mask, and it runs from the main sparx5 netdevice notifier on NETDEV_CHANGEUPPER. Before this patch, the reconcile walked only leg_list, whose entries hold netdev references.
mchp_sparx5_remove() unregisters that notifier before the router notifiers:
sparx5_unregister_notifier_blocks(sparx5); sparx5_rr_router_deinit(sparx5);
Suppose ip link del br0 runs in that window. del_nbp() unlinks the ports, but hw_bridge_dev and bridge_mask stay set. The router notifiers are still registered, so addrconf_ifdown() on the bridge's vlan uppers can, for example, send inet6addr NETDEV_DOWN, and sparx5_rr_inet6addr_event() queues legs_work. After rtnl_unlock(), netdev_run_todo() frees the bridge.
legs_work can then run, including during the drain in sparx5_rr_router_deinit(), while sparx5->router is still set:
destroy_workqueue(router->sparx5_router_owq); sparx5_rr_router_legs_flush(sparx5); sparx5_rr_router_hw_deinit(sparx5); sparx5->router = NULL;
The bridge_mask/hw_bridge_dev check passes on this stale state, and netdev_for_each_upper_dev_rcu() reads the adj_list of the freed bridge. Could a garbage dev then reach __sparx5_rr_inetaddr_event(), which may call netdev_hold() on it and program hardware?
Quoted 12 lines
drivers/net/ethernet/microchip/sparx5/sparx5_router.c +8
-0+if (!is_vlan_dev (dev) || +sparx5_rr_dev_addr_list_empty (dev)) +continue ; +if (__sparx5_rr_inetaddr_event (sparx5, dev,NETDEV_UP , +NULL ) &&net_ratelimit ()) +netdev_warn (dev, +"Failed to offload L3 router leg\n" ); + } }mutex_unlock (&router->lock); }
drivers/net/ethernet/microchip/sparx5/sparx5_router.c int sparx5_rr_router_init(struct sparx5 *sparx5) · line 816
Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_router.c +1
-0@@ -681,6 +810,7 @@ int sparx5_rr_router_init(struct sparx5 *sparx5)INIT_LIST_HEAD (&r->leg_list); +/* The exported helpers use leg_list once sparx5->router is set. */ sparx5->router = r; r->sparx5_router_owq =alloc_ordered_workqueue ("sparx5_router_owq" ,0 );
[Severity: Low]
Is this comment complete? sparx5_rr_legs_reconcile_schedule() is now exported and is also called from sparx5_rr_bridge_vlan_clear(). It checks only sparx5->router, but it also uses router->sparx5_router_owq and router->legs_work, which are set up after this assignment.
Teardown has the same gap. sparx5_rr_router_deinit() and the init error path both destroy the workqueue before they clear sparx5->router.
Today this is safe only because of the call order: mchp_sparx5_probe() registers the switchdev/netdevice notifiers after router init, and mchp_sparx5_remove() unregisters them before router deinit.
Should this ordering dependency be documented? Alternatively, the pointer could be published after alloc_ordered_workqueue() and INIT_WORK().
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c static int sparx5_port_attr_set(struct net_device *dev, const void *ctx, · line 158
Quoted 12 lines
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c +4
-0@@ -152,6 +152,11 @@ static int sparx5_port_attr_set(struct net_device *dev, const void *ctx,sparx5_port_attr_ageing_set (port, attr->u.ageing_time);break ;case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING : +/* L3 offload requires a VLAN aware bridge. */ +if (!attr->u.vlan_filtering) +sparx5_rr_bridge_legs_flush (port->sparx5, + attr->orig_dev);
[Severity: Low]
This isn't a bug, but the comment above sparx5_rr_bridge_legs_flush() still reads:
/* Tear down the router legs of a bridge that is no longer offloaded. */
Here, and in the new SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL case, the function is called for a bridge that is still offloaded, with hw_bridge_dev and bridge_mask unchanged. Should that comment be updated?
[ ... ]
Quoted 11 lines
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c +4
-0@@ -448,6 +466,10 @@ static int sparx5_handle_port_vlan_add(struct net_device *dev,/* Flood broadcast to CPU */ sparx5_mact_learn (sparx5,sparx5_get_pgid (sparx5,PGID_BCAST ), dev->broadcast, v->vid); +if (v->flags &BRIDGE_VLAN_INFO_UNTAGGED ) +sparx5_rr_bridge_vlan_clear (sparx5, dev, v->vid); +else +sparx5_rr_legs_reconcile_schedule (sparx5);return 0 ; }
[ ... ]
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c static int sparx5_handle_port_vlan_del(struct net_device *dev, · line 710
Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c +1
-0@@ -683,6 +705,7 @@ static int sparx5_handle_port_vlan_del(struct net_device *dev, switchdev_blocking_nb);sparx5_mact_forget (sparx5, dev->broadcast, vid); +sparx5_rr_bridge_vlan_clear (sparx5, dev, vid);return 0 ; }
[Severity: High]
This is a pre-existing issue that this patch did not introduce, but the patch extends the affected branches. The bridge-master paths of sparx5_handle_port_vlan_add() and sparx5_handle_port_vlan_del() never check dev == sparx5->hw_bridge_dev, or the netns. The switchdev blocking notifier chain is global.
Can a software-only bridge in another namespace remove the broadcast entry here? The bridge sends master VLAN add/del notifications for every bridge. A user with CAP_NET_ADMIN only in its own user namespace can run:
ip link add br0 type bridge
bridge vlan add vid X dev br0 self
bridge vlan del vid X dev br0 self
sparx5_mact_forget() then deletes the chip-wide (ff:ff:ff:ff:ff:ff, X) entry that points at PGID_BCAST. PGID_BCAST is the only flood group that sparx5_start() sets up with CPU copy enabled. After that, broadcasts on vid X of the offloaded bridge no longer reach the CPU, so ARP fails for host interfaces and for the router legs on that vid.
The new sparx5_rr_bridge_vlan_clear() and sparx5_rr_legs_reconcile_schedule() calls are added to the same unfiltered branches. Would an early check like this be appropriate?
if (dev != sparx5->hw_bridge_dev) return 0;
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117-sparx5_l3_routing-v3-0-e680ed79c7dc%40microchip.com
Re: [PATCH net-next v3 3/3] net: sparx5: keep router legs in sync with the bridge
Quoted 115 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 1 · Low: 2
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).
- [High]
sparx5_rr_legs_reconcile()now walksnetdev_for_each_upper_dev_rcu(sparx5->hw_bridge_dev, ...)from the…
- [Medium] Contrary to the commit message, a router leg can be lost while its upper is down.
- [Low] Insparx5_rr_router_init()the new comment says "The exported helpers useleg_listoncesparx5->routeris set".
- [Low] The function comment abovesparx5_rr_bridge_legs_flush()still reads "Tear down the router legs of a bridge that is no longer…Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but this patch extends the affected code.--
net: sparx5: keep router legs in sync with the bridge
This commit makes the sparx5 L3 router legs follow later changes to the bridge and the vlan upper. A leg is destroyed when vlan filtering is disabled, when the bridge moves to a non-802.1Q protocol, when the upper is linked to a master, or when the upper's MAC changes. Ingress routing on a leg is limited to when the upper is up and the bridge carries the vid tagged, and the reconcile now also creates legs for eligible uppers of the offloaded bridge.
Quoted 4 lines
drivers/net/ethernet/microchip/sparx5/sparx5_router.c +0
-0[ ... ]
Quoted 1 line
drivers/net/ethernet/microchip/sparx5/sparx5_router.c +0
-0@@ -568,19 +650,66 @@ static void sparx5_rr_router_legs_flush(struct sparx5 *sparx5)[ ... ]
Quoted 11 lines
drivers/net/ethernet/microchip/sparx5/sparx5_router.c +4
-0+void sparx5_rr_legs_reconcile (struct sparx5 *sparx5) {struct sparx5_rr_router_leg *leg, *tmp; +struct net_device *bridge, *dev;struct sparx5_router *router; +struct list_head *iter;ASSERT_RTNL (); router = sparx5->router; +if (!router)drivers/net/ethernet/microchip/sparx5/sparx5_router.c static void sparx5_rr_router_legs_flush(struct sparx5 *sparx5) · line 694
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_router.c +5
-1+return ;mutex_lock (&router->lock);list_for_each_entry_safe (leg, tmp, &router->leg_list, leg_list_node) { -if (sparx5_rr_dev_addr_list_empty (leg->dev)) +if (sparx5_rr_dev_addr_list_empty (leg->dev) || + !sparx5_rr_dev_real_is_vlan_aware (sparx5, leg->dev)) {sparx5_rr_router_leg_destroy (leg); +continue ; + }[Severity: Medium]
The commit message says:"A leg with an IPv4 address is kept while the upper is down, so it is available again when the interface comes back up."
Does this still hold if the bridge MAC changes while a
NET_ADDR_STOLENvlan upper is down?When the bridge sends
NETDEV_CHANGEADDR,vlan_device_event()innet/8021q/vlan.cskips uppers that are notIFF_UP. A down upper therefore keeps the old MAC, andsparx5_rr_dev_real_is_vlan_aware()then fails here:if (dev->addr_assign_type != NET_ADDR_STOLEN || !ether_addr_equal(dev->dev_addr, vlan_rdev->dev_addr)) return false;On the next reconcile, the new check above destroys the down upper's IPv4 leg and frees its VMID.
Unrelated events can queue that reconcile: an inet6addr UP/DOWN on any vlan device, a bridge vlan add or del, or the
VLAN_FILTERINGattr that is sent when a sparx5 port joins. For example, a port with a lower MAC joins the bridge. That queues the reconcile, andbr_stp_recalculate_bridge_id()changes the bridge MAC before the reconcile runs.Suppose the bridge MAC then changes back before the upper comes up, for example because the port leaves again or after ip link set br0 address <old>. What recreates the leg then? The bridge
NETDEV_CHANGEADDRinsparx5_rr_netdevice_event()does not queue a reconcile, becauseis_vlan_dev(bridge)is false:case NETDEV_CHANGEADDR: mutex_lock(&router->lock); if (sparx5_rr_bridge_has_legs(sparx5, dev)) sparx5_rr_leg_base_mac_set(sparx5, dev->dev_addr); mutex_unlock(&router->lock); if (is_vlan_dev(dev)) sparx5_rr_legs_reconcile_schedule(sparx5);When the upper is later brought up, the MACs already match, so no CHANGEADDR is sent. The
NETDEV_UPcase only refreshes an existing leg. The IPv4 address already exists, so the validator does not run either. With IPv6 disabled on the upper (disable_ipv6, oraddr_gen_modenone), no link-localNETDEV_UParrives.
Quoted 8 lines
Wouldn't the upper then stay without a leg until something unrelated triggers a reconcile?
Now take the case where the upper comes up while the bridge still has the new MAC. vlan_dev_open()->vlan_dev_inherit_address() does queue a reconcile. But if another upper has taken the freed VMID in the meantime, creating the leg fails, and only a ratelimited warning is printed.
This is right. A NET_ADDR_STOLEN upper which is down keeps the old MAC when the bridge MAC changes, so a reconcile in that window destroys its leg. If the MAC is back to the old value when the upper comes up it is not requeued. v4 queues the reconcile on NETDEV_UP of a vlan upper of the offloaded bridge that has no leg.
Quoted 39 lines
drivers/net/ethernet/microchip/sparx5/sparx5_router.c static void sparx5_rr_router_legs_flush(struct sparx5 *sparx5) · line 704
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_router.c +10
-0+ + bridge =vlan_dev_real_dev (leg->dev); + leg->vlan_present =sparx5_rr_bridge_vlan_present (bridge, + leg->vid); +sparx5_rr_leg_hw_uc_update (sparx5, leg); + } + + bridge = sparx5->hw_bridge_dev; +if (!bitmap_empty (sparx5->bridge_mask,SPX5_PORTS ) && bridge) { +netdev_for_each_upper_dev_rcu (bridge, dev, iter) {[Severity: High]
Can this walk a bridge that has already been freed during driver removal?The driver holds no reference on
hw_bridge_dev. Onlysparx5_port_bridge_leave()clearshw_bridge_devandbridge_mask, and it runs from the main sparx5 netdevice notifier onNETDEV_CHANGEUPPER. Before this patch, the reconcile walked onlyleg_list, whose entries hold netdev references.
mchp_sparx5_remove()unregisters that notifier before the router notifiers:sparx5_unregister_notifier_blocks(sparx5); sparx5_rr_router_deinit(sparx5);Suppose ip link del br0 runs in that window.
del_nbp()unlinks the ports, buthw_bridge_devandbridge_maskstay set. The router notifiers are still registered, soaddrconf_ifdown()on the bridge's vlan uppers can, for example, send inet6addrNETDEV_DOWN, andsparx5_rr_inet6addr_event()queueslegs_work. Afterrtnl_unlock(),netdev_run_todo()frees the bridge.
legs_workcan then run, including during the drain insparx5_rr_router_deinit(), whilesparx5->routeris still set:destroy_workqueue(router->sparx5_router_owq); sparx5_rr_router_legs_flush(sparx5); sparx5_rr_router_hw_deinit(sparx5); sparx5->router = NULL;
Quoted 5 lines
The bridge_mask/hw_bridge_dev check passes on this stale state, and
netdev_for_each_upper_dev_rcu()reads theadj_listof the freed bridge. Could a garbage dev then reach__sparx5_rr_inetaddr_event(), which may callnetdev_hold()on it and program hardware?
I think this is correct, but it needs a bridge del racing with driver removal. mchp_sparx5_remove() unregisters the notifiers that maintain hw_bridge_dev and bridge_mask before the router stops, so router work can run on stale bridge state. The next version tears the router down before the notifier blocks: its notifiers are unregistered and the work disabled first, and sparx5->router is cleared under RTNL.
Quoted 29 lines
drivers/net/ethernet/microchip/sparx5/sparx5_router.c static int sparx5_handle_port_vlan_del(struct net_device *dev, · line 710
Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_router.c +1
-0@@ -683,6 +705,7 @@ static int sparx5_handle_port_vlan_del(struct net_device *dev, switchdev_blocking_nb);sparx5_mact_forget (sparx5, dev->broadcast, vid); +sparx5_rr_bridge_vlan_clear (sparx5, dev, vid);return 0 ; }[Severity: High]
This is a pre-existing issue that this patch did not introduce, but the patch extends the affected branches. The bridge-master paths ofsparx5_handle_port_vlan_add()andsparx5_handle_port_vlan_del()never check dev ==sparx5->hw_bridge_dev, or the netns. The switchdev blocking notifier chain is global.Can a software-only bridge in another namespace remove the broadcast entry here? The bridge sends master VLAN add/del notifications for every bridge. A user with
CAP_NET_ADMINonly in its own user namespace can run:ip link add br0 type bridge
bridge vlan add vid X dev br0 self
bridge vlan del vid X dev br0 self
sparx5_mact_forget()then deletes the chip-wide (ff:ff:ff:ff:ff:ff, X) entry that points atPGID_BCAST.PGID_BCASTis the only flood group thatsparx5_start()sets up with CPU copy enabled. After that, broadcasts on vid X of the offloaded bridge no longer reach the CPU, so ARP fails for host interfaces and for the router legs on that vid.
Quoted 6 lines
The new
sparx5_rr_bridge_vlan_clear()andsparx5_rr_legs_reconcile_schedule()calls are added to the same unfiltered branches. Would an early check like this be appropriate?if (dev != sparx5->hw_bridge_dev) return 0;
Preexisting, but correct, the bridge master vlan add and del paths act on any bridge. The calls this patch adds there only touch legs of the bridge passed in, and the reconcile is idempotent, so it does not add to this. I do not think this should be fixed in this series.
pw-bot: cr