mlxsw: A dedicated notifier block for router code
Subsystems (5)
Ido Schimmel
maintainercover mlxsw: A dedicated notifier block for router code
Petr says:
Currently all netdevice events are handled in the centralized notifier handler maintained by spectrum.c. Since a number of events are involving router code, spectrum.c needs to dispatch them to spectrum_router.c. The spectrum module therefore needs to know more about the router code than it should have, and there is are several API points through which the two modules communicate.
In this patchset, move bulk of the router-related event handling to the router code. Some of the knowledge has to stay: spectrum.c cannot veto events that the router supports, and vice versa. But beyond that, the two can ignore each other's details, which leads to more focused and simpler code.
As a side effect, this fixes L3 HW stats support on tunnel netdevices.
The patch set progresses as follows:
- In patch #1, change spectrum code to not bounce L3 enslavement, which the router code supports.
- In patch #2, add a new do-nothing notifier block to the router code.
- In patches #3-#6, move router-specific event handling to the router module. In patch #7, clean up a comment.
- In patch #8, use the advantage that all router event handling is in the router code and clean up taking router lock.
- mlxsw supports L3 HW stats on tunnels as of this patchset. Patches #9 and #10 therefore add a selftest for L3 HW stats support on tunnels.
Petr Machata (10):
mlxsw: spectrum: Tolerate enslaving of various devices to VRF
mlxsw: spectrum_router: Add a dedicated notifier block
mlxsw: spectrum: Move handling of VRF events to router code
mlxsw: spectrum: Move handling of HW stats events to router code
mlxsw: spectrum: Move handling of router events to router code
mlxsw: spectrum: Move handling of tunnel events to router code
mlxsw: spectrum: Update a comment
mlxsw: spectrum_router: Take router lock in router notifier handler
selftests: lib: Add a generic helper for obtaining HW stats
selftests: forwarding: Add a tunnel-based test for L3 HW stats
.../net/ethernet/mellanox/mlxsw/spectrum.c | 66 ++------ .../net/ethernet/mellanox/mlxsw/spectrum.h | 17 -- .../ethernet/mellanox/mlxsw/spectrum_router.c | 160 +++++++++++++----- .../ethernet/mellanox/mlxsw/spectrum_router.h | 1 + .../testing/selftests/net/forwarding/Makefile | 1 + .../selftests/net/forwarding/hw_stats_l3.sh | 16 +- .../net/forwarding/hw_stats_l3_gre.sh | 109 ++++++++++++ tools/testing/selftests/net/forwarding/lib.sh | 11 ++ 8 files changed, 259 insertions(+), 122 deletions(-) create mode 100755 tools/testing/selftests/net/forwarding/hw_stats_l3_gre.sh
Signature · 1 line
2.35.1
Ido Schimmel
maintainerPATCH 1/10 mlxsw: spectrum: Tolerate enslaving of various devices to VRF
From: Petr Machata <[email protected]>
Enslaving netdevices to VRF is currently handled through an mlxsw_sp_is_vrf_event() conditional in mlxsw_sp_netdevice_event(). In the following patch sets, VRF enslavement will be handled purely in the router code. Therefore make handlers of NETDEV_PRECHANGEUPPER tolerant of enslaving to VRF, so that they do not bounce the change.
For NETDEV_CHANGEUPPER, drop the WARN_ON(1) and bounce from mlxsw_sp_netdevice_port_vlan_event(). This is the only handler that warned and bounces even in the CHANGEUPPER code, other handler quietly do nothing when they encounter an unfamiliar upper.
--- .../net/ethernet/mellanox/mlxsw/spectrum.c | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +16 -10
@@ -4525,7 +4525,8 @@ static int mlxsw_sp_netdevice_port_upper_event(struct net_device *lower_dev, !netif_is_lag_master(upper_dev) && !netif_is_bridge_master(upper_dev) && !netif_is_ovs_master(upper_dev) && - !netif_is_macvlan(upper_dev)) { + !netif_is_macvlan(upper_dev) && + !netif_is_l3_master(upper_dev)) {NL_SET_ERR_MSG_MOD (extack,"Unknown upper device type" );return -EINVAL ; }
@@ -4724,7 +4725,8 @@ static int mlxsw_sp_netdevice_port_vlan_event(struct net_device *vlan_dev,case NETDEV_PRECHANGEUPPER : upper_dev = info->upper_dev;if (!netif_is_bridge_master (upper_dev) && - !netif_is_macvlan (upper_dev)) { + !netif_is_macvlan (upper_dev) && + !netif_is_l3_master (upper_dev)) {NL_SET_ERR_MSG_MOD (extack,"Unknown upper device type" );return -EINVAL ; }
@@ -4763,9 +4765,6 @@ static int mlxsw_sp_netdevice_port_vlan_event(struct net_device *vlan_dev, }else if (netif_is_macvlan (upper_dev)) {if (!info->linking)mlxsw_sp_rif_macvlan_del (mlxsw_sp, upper_dev); - }else { - err = -EINVAL ; -WARN_ON (1 ); }break ; }
@@ -4813,7 +4812,8 @@ static int mlxsw_sp_netdevice_bridge_vlan_event(struct net_device *vlan_dev,switch (event) {case NETDEV_PRECHANGEUPPER : upper_dev = info->upper_dev; -if (!netif_is_macvlan (upper_dev)) { +if (!netif_is_macvlan (upper_dev) && + !netif_is_l3_master (upper_dev)) {NL_SET_ERR_MSG_MOD (extack,"Unknown upper device type" );return -EOPNOTSUPP ; }
@@ -4874,7 +4874,9 @@ static int mlxsw_sp_netdevice_bridge_event(struct net_device *br_dev,switch (event) {case NETDEV_PRECHANGEUPPER : upper_dev = info->upper_dev; -if (!is_vlan_dev (upper_dev) && !netif_is_macvlan (upper_dev)) { +if (!is_vlan_dev (upper_dev) && + !netif_is_macvlan (upper_dev) && + !netif_is_l3_master (upper_dev)) {NL_SET_ERR_MSG_MOD (extack,"Unknown upper device type" );return -EOPNOTSUPP ; }
@@ -4918,16 +4920,20 @@ static int mlxsw_sp_netdevice_macvlan_event(struct net_device *macvlan_dev,struct mlxsw_sp *mlxsw_sp =mlxsw_sp_lower_get (macvlan_dev);struct netdev_notifier_changeupper_info *info = ptr;struct netlink_ext_ack *extack; +struct net_device *upper_dev;if (!mlxsw_sp || event !=NETDEV_PRECHANGEUPPER )return 0 ; extack =netdev_notifier_info_to_extack (&info->info); + upper_dev = info->upper_dev; -/* VRF enslavement is handled in mlxsw_sp_netdevice_vrf_event() */ -NL_SET_ERR_MSG_MOD (extack,"Unknown upper device type" ); +if (!netif_is_l3_master (upper_dev)) { +NL_SET_ERR_MSG_MOD (extack,"Unknown upper device type" ); +return -EOPNOTSUPP ; + } -return -EOPNOTSUPP ; +return 0 ; }static bool mlxsw_sp_is_vrf_event (unsigned long event,void *ptr)
Signature · 1 line
2.35.1
Ido Schimmel
maintainerPATCH 2/10 mlxsw: spectrum_router: Add a dedicated notifier block
In reply to Ido SchimmelFrom: Petr Machata <[email protected]>
Currently all netdevice events are handled in the centralized notifier handler maintained by spectrum.c. Since a number of events are involving router code, spectrum.c needs to dispatch them to spectrum_router.c. The spectrum module therefore needs to know more about the router code than it should have, and there is are several API points through which the two modules communicate.
To simplify the notifier handlers, introduce a new notifier into the router module.
--- .../ethernet/mellanox/mlxsw/spectrum_router.c | 20 +++++++++++++++++++ .../ethernet/mellanox/mlxsw/spectrum_router.h | 1 + 2 files changed, 21 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +20 -0
@@ -9508,6 +9508,14 @@ int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,return err; } +static int mlxsw_sp_router_netdevice_event (struct notifier_block *nb, +unsigned long event,void *ptr) +{ +int err =0 ; + +return notifier_from_errno (err); +} +static int __mlxsw_sp_rif_macvlan_flush (struct net_device *dev,struct netdev_nested_priv *priv) {
@@ -10692,8 +10700,18 @@ int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp,if (err) goto err_register_fib_notifier; + mlxsw_sp->router->netdevice_nb.notifier_call = + mlxsw_sp_router_netdevice_event; + err =register_netdevice_notifier_net (mlxsw_sp_net (mlxsw_sp), + &mlxsw_sp->router->netdevice_nb); +if (err) + goto err_register_netdev_notifier; +return 0 ; +err_register_netdev_notifier: +unregister_fib_notifier (mlxsw_sp_net (mlxsw_sp), + &mlxsw_sp->router->fib_nb); err_register_fib_notifier:unregister_nexthop_notifier (mlxsw_sp_net (mlxsw_sp), &mlxsw_sp->router->nexthop_nb);
@@ -10741,6 +10759,8 @@ int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp,void mlxsw_sp_router_fini (struct mlxsw_sp *mlxsw_sp) { +unregister_netdevice_notifier_net (mlxsw_sp_net (mlxsw_sp), + &mlxsw_sp->router->netdevice_nb);unregister_fib_notifier (mlxsw_sp_net (mlxsw_sp), &mlxsw_sp->router->fib_nb); unregister_nexthop_notifier(mlxsw_sp_net(mlxsw_sp),
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.h +1 -0
@@ -67,6 +67,7 @@ struct mlxsw_sp_router {struct notifier_block netevent_nb;struct notifier_block inetaddr_nb;struct notifier_block inet6addr_nb; +struct notifier_block netdevice_nb;const struct mlxsw_sp_rif_ops **rif_ops_arr;const struct mlxsw_sp_ipip_ops **ipip_ops_arr;struct mlxsw_sp_router_nve_decap nve_decap_config;
Signature · 1 line
2.35.1
Ido Schimmel
maintainerPATCH 3/10 mlxsw: spectrum: Move handling of VRF events to router code
In reply to Ido SchimmelFrom: Petr Machata <[email protected]>
Events involving VRF, as L3 concern, are handled in the router code, by the helper mlxsw_sp_netdevice_vrf_event(). The handler is currently invoked from the centralized dispatcher in spectrum.c. Instead, move the call to the newly-introduced router-specific notifier handler.
--- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 11 ----------- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 2 -- .../ethernet/mellanox/mlxsw/spectrum_router.c | 18 ++++++++++++++++-- 3 files changed, 16 insertions(+), 15 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +0 -11
@@ -4936,15 +4936,6 @@ static int mlxsw_sp_netdevice_macvlan_event(struct net_device *macvlan_dev,return 0 ; } -static bool mlxsw_sp_is_vrf_event (unsigned long event,void *ptr) -{ -struct netdev_notifier_changeupper_info *info = ptr; - -if (event !=NETDEV_PRECHANGEUPPER && event !=NETDEV_CHANGEUPPER ) -return false; -return netif_is_l3_master (info->upper_dev); -} -static int mlxsw_sp_netdevice_vxlan_event (struct mlxsw_sp *mlxsw_sp,struct net_device *dev,unsigned long event,void *ptr)
@@ -5055,8 +5046,6 @@ static int mlxsw_sp_netdevice_event(struct notifier_block *nb, event, ptr); else if (mlxsw_sp_netdevice_event_is_router(event)) err =mlxsw_sp_netdevice_router_port_event (dev, event, ptr); - else if (mlxsw_sp_is_vrf_event(event, ptr)) - err =mlxsw_sp_netdevice_vrf_event (dev, event, ptr); else if (mlxsw_sp_port_dev_check(dev)) err =mlxsw_sp_netdevice_port_event (dev, dev, event, ptr); else if (netif_is_lag_master(dev))
drivers/net/ethernet/mellanox/mlxsw/spectrum.h +0 -2
@@ -726,8 +726,6 @@ int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused, unsigned long event, void *ptr);int mlxsw_sp_inet6addr_valid_event (struct notifier_block *unused,unsigned long event,void *ptr); -int mlxsw_sp_netdevice_vrf_event (struct net_device *l3_dev,unsigned long event, -struct netdev_notifier_changeupper_info *info);bool mlxsw_sp_netdev_is_ipip_ol (const struct mlxsw_sp *mlxsw_sp,const struct net_device *dev); bool mlxsw_sp_netdev_is_ipip_ul(struct mlxsw_sp *mlxsw_sp,
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +16 -2
@@ -9476,8 +9476,18 @@ static void mlxsw_sp_port_vrf_leave(struct mlxsw_sp *mlxsw_sp,__mlxsw_sp_inetaddr_event (mlxsw_sp, l3_dev,NETDEV_DOWN ,NULL ); } -int mlxsw_sp_netdevice_vrf_event (struct net_device *l3_dev,unsigned long event, -struct netdev_notifier_changeupper_info *info) +static bool mlxsw_sp_is_vrf_event (unsigned long event,void *ptr) +{ +struct netdev_notifier_changeupper_info *info = ptr; + +if (event !=NETDEV_PRECHANGEUPPER && event !=NETDEV_CHANGEUPPER ) +return false; +return netif_is_l3_master (info->upper_dev); +} + +static int +mlxsw_sp_netdevice_vrf_event (struct net_device *l3_dev,unsigned long event, +struct netdev_notifier_changeupper_info *info) {struct mlxsw_sp *mlxsw_sp =mlxsw_sp_lower_get (l3_dev);int err =0 ;
@@ -9511,8 +9521,12 @@ int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,static int mlxsw_sp_router_netdevice_event (struct notifier_block *nb,unsigned long event,void *ptr) { +struct net_device *dev =netdev_notifier_info_to_dev (ptr);int err =0 ; +if (mlxsw_sp_is_vrf_event (event, ptr)) + err =mlxsw_sp_netdevice_vrf_event (dev, event, ptr); +return notifier_from_errno (err); }
Signature · 1 line
2.35.1
Ido Schimmel
maintainerPATCH 4/10 mlxsw: spectrum: Move handling of HW stats events to router code
In reply to Ido SchimmelFrom: Petr Machata <[email protected]>
L3 HW stats are implemented in mlxsw as RIF counters, and therefore the code resides in spectrum_router. Exclude the offload xstats events from the mlxsw_sp_netdevice_event_is_router() predicate, and instead recreate the glue code in the router module.
Previously, the order of dispatch was that for events on tunnels, a dedicated handler was called, which however did not handle HW stats events. But there is nothing special about tunnel devices as far as HW stats: there is a RIF associated with the tunnel netdevice, and that RIF is where the counter should be installed. Therefore now, HW stats events are tested first, independent of netdevice type. The upshot is that as of this commit, mlxsw supports L3 HW stats work on GRE tunnels.
--- .../net/ethernet/mellanox/mlxsw/spectrum.c | 4 -- .../ethernet/mellanox/mlxsw/spectrum_router.c | 47 ++++++++++++++++--- 2 files changed, 40 insertions(+), 11 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +0 -4
@@ -5010,10 +5010,6 @@ static bool mlxsw_sp_netdevice_event_is_router(unsigned long event)case NETDEV_PRE_CHANGEADDR :case NETDEV_CHANGEADDR :case NETDEV_CHANGEMTU : -case NETDEV_OFFLOAD_XSTATS_ENABLE : -case NETDEV_OFFLOAD_XSTATS_DISABLE : -case NETDEV_OFFLOAD_XSTATS_REPORT_USED : -case NETDEV_OFFLOAD_XSTATS_REPORT_DELTA :return true;default :return false;
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +40 -7
73 lines not on this page · raw message
Signature · 1 line
2.35.1
Ido Schimmel
maintainerPATCH 5/10 mlxsw: spectrum: Move handling of router events to router code
In reply to Ido SchimmelFrom: Petr Machata <[email protected]>
The events NETDEV_PRE_CHANGEADDR, NETDEV_CHANGEADDR and NETDEV_CHANGEMTU have implications for in-ASIC router interface objects, and as such are handled in the router module. Move the handling from the central dispatcher in spectrum.c to the new notifier handler in the router module.
--- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 14 -------------- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 2 -- .../ethernet/mellanox/mlxsw/spectrum_router.c | 18 ++++++++++++++++-- 3 files changed, 16 insertions(+), 18 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +0 -14
@@ -5004,18 +5004,6 @@ static int mlxsw_sp_netdevice_vxlan_event(struct mlxsw_sp *mlxsw_sp,return 0 ; } -static bool mlxsw_sp_netdevice_event_is_router (unsigned long event) -{ -switch (event) { -case NETDEV_PRE_CHANGEADDR : -case NETDEV_CHANGEADDR : -case NETDEV_CHANGEMTU : -return true; -default : -return false; - } -} -static int mlxsw_sp_netdevice_event (struct notifier_block *nb,unsigned long event,void *ptr) {
@@ -5040,8 +5028,6 @@ static int mlxsw_sp_netdevice_event(struct notifier_block *nb,else if (mlxsw_sp_netdev_is_ipip_ul (mlxsw_sp, dev)) err =mlxsw_sp_netdevice_ipip_ul_event (mlxsw_sp, dev, event, ptr); -else if (mlxsw_sp_netdevice_event_is_router (event)) - err =mlxsw_sp_netdevice_router_port_event (dev, event, ptr);else if (mlxsw_sp_port_dev_check (dev)) err =mlxsw_sp_netdevice_port_event (dev, dev, event, ptr);else if (netif_is_lag_master (dev))
drivers/net/ethernet/mellanox/mlxsw/spectrum.h +0 -2
@@ -718,8 +718,6 @@ union mlxsw_sp_l3addr {int mlxsw_sp_router_init (struct mlxsw_sp *mlxsw_sp,struct netlink_ext_ack *extack);void mlxsw_sp_router_fini (struct mlxsw_sp *mlxsw_sp); -int mlxsw_sp_netdevice_router_port_event (struct net_device *dev, -unsigned long event,void *ptr);void mlxsw_sp_rif_macvlan_del (struct mlxsw_sp *mlxsw_sp,const struct net_device *macvlan_dev); int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused,
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +16 -2
@@ -9438,8 +9438,20 @@ mlxsw_sp_netdevice_offload_xstats_cmd(struct mlxsw_sp *mlxsw_sp,return err; } -int mlxsw_sp_netdevice_router_port_event (struct net_device *dev, -unsigned long event,void *ptr) +static bool mlxsw_sp_is_router_event (unsigned long event) +{ +switch (event) { +case NETDEV_PRE_CHANGEADDR : +case NETDEV_CHANGEADDR : +case NETDEV_CHANGEMTU : +return true; +default : +return false; + } +} + +static int mlxsw_sp_netdevice_router_port_event (struct net_device *dev, +unsigned long event,void *ptr) {struct netlink_ext_ack *extack =netdev_notifier_info_to_extack (ptr);struct mlxsw_sp *mlxsw_sp;
@@ -9557,6 +9569,8 @@ static int mlxsw_sp_router_netdevice_event(struct notifier_block *nb,if (mlxsw_sp_is_offload_xstats_event (event)) err =mlxsw_sp_netdevice_offload_xstats_cmd (mlxsw_sp, dev, event, ptr); +else if (mlxsw_sp_is_router_event (event)) + err =mlxsw_sp_netdevice_router_port_event (dev, event, ptr);else if (mlxsw_sp_is_vrf_event (event, ptr)) err =mlxsw_sp_netdevice_vrf_event (dev, event, ptr);
Signature · 1 line
2.35.1
Ido Schimmel
maintainerPATCH 6/10 mlxsw: spectrum: Move handling of tunnel events to router code
In reply to Ido SchimmelFrom: Petr Machata <[email protected]>
The events related to IPIP tunnels are handled by the router code. Move the handling from the central dispatcher in spectrum.c to the new notifier handler in the router module.
--- .../net/ethernet/mellanox/mlxsw/spectrum.c | 6 ----- .../net/ethernet/mellanox/mlxsw/spectrum.h | 13 ---------- .../ethernet/mellanox/mlxsw/spectrum_router.c | 24 ++++++++++++------- 3 files changed, 15 insertions(+), 28 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +0 -6
@@ -5022,12 +5022,6 @@ static int mlxsw_sp_netdevice_event(struct notifier_block *nb,if (netif_is_vxlan (dev)) err =mlxsw_sp_netdevice_vxlan_event (mlxsw_sp, dev, event, ptr); -if (mlxsw_sp_netdev_is_ipip_ol (mlxsw_sp, dev)) - err =mlxsw_sp_netdevice_ipip_ol_event (mlxsw_sp, dev, - event, ptr); -else if (mlxsw_sp_netdev_is_ipip_ul (mlxsw_sp, dev)) - err =mlxsw_sp_netdevice_ipip_ul_event (mlxsw_sp, dev, - event, ptr);else if (mlxsw_sp_port_dev_check (dev)) err =mlxsw_sp_netdevice_port_event (dev, dev, event, ptr);else if (netif_is_lag_master (dev))
drivers/net/ethernet/mellanox/mlxsw/spectrum.h +0 -13
@@ -724,19 +724,6 @@ int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused, unsigned long event, void *ptr);int mlxsw_sp_inet6addr_valid_event (struct notifier_block *unused,unsigned long event,void *ptr); -bool mlxsw_sp_netdev_is_ipip_ol (const struct mlxsw_sp *mlxsw_sp, -const struct net_device *dev); -bool mlxsw_sp_netdev_is_ipip_ul (struct mlxsw_sp *mlxsw_sp, -const struct net_device *dev); -int mlxsw_sp_netdevice_ipip_ol_event (struct mlxsw_sp *mlxsw_sp, -struct net_device *l3_dev, -unsigned long event, -struct netdev_notifier_info *info); -int -mlxsw_sp_netdevice_ipip_ul_event (struct mlxsw_sp *mlxsw_sp, -struct net_device *l3_dev, -unsigned long event, -struct netdev_notifier_info *info); int mlxsw_sp_port_vlan_router_join(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan, struct net_device *l3_dev,
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +15 -9
@@ -1530,8 +1530,8 @@ static bool mlxsw_sp_netdev_ipip_type(const struct mlxsw_sp *mlxsw_sp,return false; } -bool mlxsw_sp_netdev_is_ipip_ol (const struct mlxsw_sp *mlxsw_sp, -const struct net_device *dev) +static bool mlxsw_sp_netdev_is_ipip_ol (const struct mlxsw_sp *mlxsw_sp, +const struct net_device *dev) {return mlxsw_sp_netdev_ipip_type (mlxsw_sp, dev,NULL ); }
@@ -1575,8 +1575,8 @@ mlxsw_sp_ipip_entry_find_by_ul_dev(const struct mlxsw_sp *mlxsw_sp,return NULL ; } -bool mlxsw_sp_netdev_is_ipip_ul (struct mlxsw_sp *mlxsw_sp, -const struct net_device *dev) +static bool mlxsw_sp_netdev_is_ipip_ul (struct mlxsw_sp *mlxsw_sp, +const struct net_device *dev) {bool is_ipip_ul;
@@ -1960,10 +1960,10 @@ static void mlxsw_sp_ipip_demote_tunnel_by_ul_netdev(struct mlxsw_sp *mlxsw_sp, } } -int mlxsw_sp_netdevice_ipip_ol_event (struct mlxsw_sp *mlxsw_sp, -struct net_device *ol_dev, -unsigned long event, -struct netdev_notifier_info *info) +static int mlxsw_sp_netdevice_ipip_ol_event (struct mlxsw_sp *mlxsw_sp, +struct net_device *ol_dev, +unsigned long event, +struct netdev_notifier_info *info) {struct netdev_notifier_changeupper_info *chup;struct netlink_ext_ack *extack;
@@ -2038,7 +2038,7 @@ __mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp,return 0 ; } -int +static int mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp, struct net_device *ul_dev, unsigned long event,
@@ -9569,6 +9569,12 @@ static int mlxsw_sp_router_netdevice_event(struct notifier_block *nb,if (mlxsw_sp_is_offload_xstats_event (event)) err =mlxsw_sp_netdevice_offload_xstats_cmd (mlxsw_sp, dev, event, ptr); +else if (mlxsw_sp_netdev_is_ipip_ol (mlxsw_sp, dev)) + err =mlxsw_sp_netdevice_ipip_ol_event (mlxsw_sp, dev, + event, ptr); +else if (mlxsw_sp_netdev_is_ipip_ul (mlxsw_sp, dev)) + err =mlxsw_sp_netdevice_ipip_ul_event (mlxsw_sp, dev, + event, ptr);else if (mlxsw_sp_is_router_event (event)) err =mlxsw_sp_netdevice_router_port_event (dev, event, ptr);else if (mlxsw_sp_is_vrf_event (event, ptr))
Signature · 1 line
2.35.1
Ido Schimmel
maintainerPATCH 7/10 mlxsw: spectrum: Update a comment
In reply to Ido SchimmelFrom: Petr Machata <[email protected]>
The position of netdevice notifier registration no longer depends on the router initialization, because the event handler no longer dispatches to the router code. Update the comment at the registration to that effect.
--- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +2 -3
@@ -3122,9 +3122,8 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core, } } -/* Initialize netdevice notifier after router and SPAN is initialized, -* so that the event handler can use router structures and call SPAN -* respin. +/* Initialize netdevice notifier after SPAN is initialized, so that the +* event handler can call SPAN respin. */ mlxsw_sp->netdevice_nb.notifier_call = mlxsw_sp_netdevice_event; err = register_netdevice_notifier_net(mlxsw_sp_net(mlxsw_sp),
Signature · 1 line
2.35.1
Ido Schimmel
maintainerPATCH 8/10 mlxsw: spectrum_router: Take router lock in router notifier handler
In reply to Ido SchimmelFrom: Petr Machata <[email protected]>
For notifications that the router needs to handle, router lock is taken. Further, at least to determine whether an event is related to a tunnel underlay, router lock also needs to be taken. Due to this, the router lock is always taken for each unhandled event, and also for some handled events, even if they are not related to underlay. Thus each event implies at least one router lock, sometimes two.
Instead of deferring the locking to the leaf handlers, take the lock in the router notifier handler always. This simplifies thinking about the locking state, and in some cases saves one lock cycle.
--- .../ethernet/mellanox/mlxsw/spectrum_router.c | 47 ++++++------------- 1 file changed, 15 insertions(+), 32 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +15 -32
@@ -1578,13 +1578,7 @@ mlxsw_sp_ipip_entry_find_by_ul_dev(const struct mlxsw_sp *mlxsw_sp,static bool mlxsw_sp_netdev_is_ipip_ul (struct mlxsw_sp *mlxsw_sp,const struct net_device *dev) { -bool is_ipip_ul; - -mutex_lock (&mlxsw_sp->router->lock); - is_ipip_ul =mlxsw_sp_ipip_entry_find_by_ul_dev (mlxsw_sp, dev,NULL ); -mutex_unlock (&mlxsw_sp->router->lock); - -return is_ipip_ul; +return mlxsw_sp_ipip_entry_find_by_ul_dev (mlxsw_sp, dev,NULL ); } static bool mlxsw_sp_netdevice_ipip_can_offload(struct mlxsw_sp *mlxsw_sp,
@@ -1969,7 +1963,6 @@ static int mlxsw_sp_netdevice_ipip_ol_event(struct mlxsw_sp *mlxsw_sp,struct netlink_ext_ack *extack;int err =0 ; -mutex_lock (&mlxsw_sp->router->lock);switch (event) {case NETDEV_REGISTER : err =mlxsw_sp_netdevice_ipip_ol_reg_event (mlxsw_sp, ol_dev);
@@ -2000,7 +1993,6 @@ static int mlxsw_sp_netdevice_ipip_ol_event(struct mlxsw_sp *mlxsw_sp, err =mlxsw_sp_netdevice_ipip_ol_update_mtu (mlxsw_sp, ol_dev);break ; } -mutex_unlock (&mlxsw_sp->router->lock);return err; }
@@ -2045,9 +2037,8 @@ mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp, struct netdev_notifier_info *info) {struct mlxsw_sp_ipip_entry *ipip_entry =NULL ; -int err =0 ; +int err; -mutex_lock (&mlxsw_sp->router->lock);while ((ipip_entry =mlxsw_sp_ipip_entry_find_by_ul_dev (mlxsw_sp, ul_dev, ipip_entry))) {
@@ -2060,7 +2051,7 @@ mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp,if (err) {mlxsw_sp_ipip_demote_tunnel_by_ul_netdev (mlxsw_sp, ul_dev); -break ; +return err; }if (demote_this) {
@@ -2077,9 +2068,8 @@ mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp, ipip_entry = prev; } } -mutex_unlock (&mlxsw_sp->router->lock); -return err; +return 0 ; } int mlxsw_sp_router_nve_promote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
@@ -9427,15 +9417,12 @@ mlxsw_sp_netdevice_offload_xstats_cmd(struct mlxsw_sp *mlxsw_sp, struct netdev_notifier_offload_xstats_info *info) {struct mlxsw_sp_rif *rif; -int err =0 ; -mutex_lock (&mlxsw_sp->router->lock); rif =mlxsw_sp_rif_find_by_dev (mlxsw_sp, dev); -if (rif) - err =mlxsw_sp_router_port_offload_xstats_cmd (rif, event, info); -mutex_unlock (&mlxsw_sp->router->lock); +if (!rif) +return 0 ; -return err; +return mlxsw_sp_router_port_offload_xstats_cmd (rif, event, info); }static bool mlxsw_sp_is_router_event (unsigned long event)
@@ -9456,33 +9443,27 @@ static int mlxsw_sp_netdevice_router_port_event(struct net_device *dev,struct netlink_ext_ack *extack =netdev_notifier_info_to_extack (ptr);struct mlxsw_sp *mlxsw_sp;struct mlxsw_sp_rif *rif; -int err =0 ; mlxsw_sp =mlxsw_sp_lower_get (dev);if (!mlxsw_sp)return 0 ; -mutex_lock (&mlxsw_sp->router->lock); rif =mlxsw_sp_rif_find_by_dev (mlxsw_sp, dev);if (!rif) - goto out; +return 0 ;switch (event) {case NETDEV_CHANGEMTU :case NETDEV_CHANGEADDR : - err =mlxsw_sp_router_port_change_event (mlxsw_sp, rif, extack); -break ; +return mlxsw_sp_router_port_change_event (mlxsw_sp, rif, extack);case NETDEV_PRE_CHANGEADDR : - err =mlxsw_sp_router_port_pre_changeaddr_event (rif, ptr); -break ; +return mlxsw_sp_router_port_pre_changeaddr_event (rif, ptr);default :WARN_ON_ONCE (1 );break ; } -out: -mutex_unlock (&mlxsw_sp->router->lock); -return err; +return 0 ; } static int mlxsw_sp_port_vrf_join(struct mlxsw_sp *mlxsw_sp,
@@ -9535,7 +9516,6 @@ mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,if (!mlxsw_sp ||netif_is_macvlan (l3_dev))return 0 ; -mutex_lock (&mlxsw_sp->router->lock);switch (event) {case NETDEV_PRECHANGEUPPER :break ;
@@ -9550,7 +9530,6 @@ mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event, }break ; } -mutex_unlock (&mlxsw_sp->router->lock);return err; }
@@ -9566,6 +9545,8 @@ static int mlxsw_sp_router_netdevice_event(struct notifier_block *nb, router = container_of(nb, struct mlxsw_sp_router, netdevice_nb); mlxsw_sp = router->mlxsw_sp; +mutex_lock (&mlxsw_sp->router->lock); +if (mlxsw_sp_is_offload_xstats_event (event)) err =mlxsw_sp_netdevice_offload_xstats_cmd (mlxsw_sp, dev, event, ptr);
@@ -9580,6 +9561,8 @@ static int mlxsw_sp_router_netdevice_event(struct notifier_block *nb,else if (mlxsw_sp_is_vrf_event (event, ptr)) err =mlxsw_sp_netdevice_vrf_event (dev, event, ptr); +mutex_unlock (&mlxsw_sp->router->lock); +return notifier_from_errno (err); }
Signature · 1 line
2.35.1
Ido Schimmel
maintainerPATCH 9/10 selftests: lib: Add a generic helper for obtaining HW stats
In reply to Ido SchimmelFrom: Petr Machata <[email protected]>
The function get_l3_stats() from the test hw_stats_l3.sh will be useful for any test that wishes to work with L3 stats. Furthermore, it is easy to generalize to other HW stats suites (for when such are added). Therefore, move the code to lib.sh, rewrite it to have the same interface as the other stats-collecting functions, and generalize to take the name of the HW stats suite to collect as an argument.
--- .../selftests/net/forwarding/hw_stats_l3.sh | 16 ++++------------ tools/testing/selftests/net/forwarding/lib.sh | 11 +++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-)
tools/testing/selftests/net/forwarding/hw_stats_l3.sh +4 -12
@@ -162,14 +162,6 @@ ping_ipv6() ping_test $h1.200 2001:db8:2::1 " IPv6" } -get_l3_stat() -{ - local selector=$1; shift - - ip -j stats show dev $rp1.200 group offload subgroup l3_stats | - jq '.[0].stats64.'$selector -} - send_packets_rx_ipv4() { # Send 21 packets instead of 20, because the first one might trap and go
@@ -208,11 +200,11 @@ ___test_stats() local a local b - a=$(get_l3_stat ${dir}.packets) + a=$(hw_stats_get l3_stats $rp1.200 ${dir} packets) send_packets_${dir}_${prot} "$@" b=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= $a + 20" \ - get_l3_stat ${dir}.packets) + hw_stats_get l3_stats $rp1.200 ${dir} packets) check_err $? "Traffic not reflected in the counter: $a -> $b" }
@@ -281,11 +273,11 @@ __test_stats_report() RET=0 - a=$(get_l3_stat ${dir}.packets) + a=$(hw_stats_get l3_stats $rp1.200 ${dir} packets) send_packets_${dir}_${prot} ip address flush dev $rp1.200 b=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= $a + 20" \ - get_l3_stat ${dir}.packets) + hw_stats_get l3_stats $rp1.200 ${dir} packets) check_err $? "Traffic not reflected in the counter: $a -> $b" log_test "Test ${dir} packets: stats pushed on loss of L3"
tools/testing/selftests/net/forwarding/lib.sh +11 -0
@@ -828,6 +828,17 @@ ipv6_stats_get() cat /proc/net/dev_snmp6/$dev | grep "^$stat" | cut -f2 } +hw_stats_get() +{ + local suite=$1; shift + local if_name=$1; shift + local dir=$1; shift + local stat=$1; shift + + ip -j stats show dev $if_name group offload subgroup $suite | + jq ".[0].stats64.$dir.$stat" +} + humanize() { local speed=$1; shift
Signature · 1 line
2.35.1
Ido Schimmel
maintainerPATCH 10/10 selftests: forwarding: Add a tunnel-based test for L3 HW stats
In reply to Ido SchimmelFrom: Petr Machata <[email protected]>
Add a selftest that uses an IPIP topology and tests that L3 HW stats reflect the traffic in the tunnel.
--- .../testing/selftests/net/forwarding/Makefile | 1 + .../net/forwarding/hw_stats_l3_gre.sh | 109 ++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100755 tools/testing/selftests/net/forwarding/hw_stats_l3_gre.sh
tools/testing/selftests/net/forwarding/Makefile +1 -0
@@ -20,6 +20,7 @@ TEST_PROGS = bridge_igmp.sh \ gre_multipath_nh.sh \ gre_multipath.sh \ hw_stats_l3.sh \ + hw_stats_l3_gre.sh \ ip6_forward_instats_vrf.sh \ ip6gre_custom_multipath_hash.sh \ ip6gre_flat_key.sh \
tools/testing/selftests/net/forwarding/hw_stats_l3_gre.sh new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
2.35.1
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 10 lines · On Sun, 8 May 2022 11:08:13 +0300 you wrote:
Petr says:
Currently all netdevice events are handled in the centralized notifier handler maintained by
spectrum.c. Since a number of events are involving router code,spectrum.cneeds to dispatch them tospectrum_router.c. The spectrum module therefore needs to know more about the router code than it should have, and there is are several API points through which the two modules communicate.[...]
Here is the summary with links:
- [net-next,01/10] mlxsw: spectrum: Tolerate enslaving of various devices to VRF
https://git.kernel.org/netdev/net-next/c/7cf0f96df1d8 - [net-next,02/10] mlxsw: spectrum_router: Add a dedicated notifier block https://git.kernel.org/netdev/net-next/c/0a27cb1692de - [net-next,03/10] mlxsw: spectrum: Move handling of VRF events to router code https://git.kernel.org/netdev/net-next/c/4f8afb680f13 - [net-next,04/10] mlxsw: spectrum: Move handling of HW stats events to router code https://git.kernel.org/netdev/net-next/c/f40e600b369e - [net-next,05/10] mlxsw: spectrum: Move handling of router events to router code https://git.kernel.org/netdev/net-next/c/ba81954cd526 - [net-next,06/10] mlxsw: spectrum: Move handling of tunnel events to router code https://git.kernel.org/netdev/net-next/c/75ef4342282a - [net-next,07/10] mlxsw: spectrum: Update a comment https://git.kernel.org/netdev/net-next/c/05a8d7d4fadf - [net-next,08/10] mlxsw: spectrum_router: Take router lock in router notifier handler https://git.kernel.org/netdev/net-next/c/c353fb0d4c93 - [net-next,09/10] selftests: lib: Add a generic helper for obtaining HW stats https://git.kernel.org/netdev/net-next/c/32fb67a3e7a6 - [net-next,10/10] selftests: forwarding: Add a tunnel-based test for L3 HW stats https://git.kernel.org/netdev/net-next/c/813f97a26860
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html