net: allow per-net notifier to follow netdev into namespace
v2 cover net: allow per-net notifier to follow netdev into namespace
From: Jiri Pirko <[email protected]>
Currently we have per-net notifier, which allows to get only notifications relevant to particular network namespace. That is enough for drivers that have netdevs local in a particular namespace (cannot move elsewhere).
However if netdev can change namespace, per-net notifier cannot be used. Introduce dev_net variant that is basically per-net notifier with an extension that re-registers the per-net notifier upon netdev namespace change. Basically the per-net notifier follows the netdev into namespace.
Jiri Pirko (4):
net: call call_netdevice_unregister_net_notifiers from unregister
net: push code from net notifier reg/unreg into helpers
net: introduce dev_net notifier register/unregister variants
mlx5: Use dev_net netdevice notifier registrations
.../net/ethernet/mellanox/mlx5/core/en/fs.h | 1 + .../net/ethernet/mellanox/mlx5/core/en_main.c | 3 +- .../net/ethernet/mellanox/mlx5/core/en_rep.c | 13 +- .../net/ethernet/mellanox/mlx5/core/en_rep.h | 1 + .../net/ethernet/mellanox/mlx5/core/en_tc.c | 9 +- drivers/net/ethernet/mellanox/mlx5/core/lag.c | 8 +- drivers/net/ethernet/mellanox/mlx5/core/lag.h | 1 + .../ethernet/mellanox/mlx5/core/mlx5_core.h | 2 +- include/linux/netdevice.h | 17 +++ net/core/dev.c | 118 +++++++++++++----- 10 files changed, 131 insertions(+), 42 deletions(-)
Signature · 1 line
2.21.0
PATCH v2 1/4 net: call call_netdevice_unregister_net_notifiers from unregister
From: Jiri Pirko <[email protected]>
The function does the same thing as the existing code, so rather call call_netdevice_unregister_net_notifiers() instead of code duplication.
--- net/core/dev.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
net/core/dev.c +3 -11
@@ -1764,7 +1764,6 @@ EXPORT_SYMBOL(register_netdevice_notifier);int unregister_netdevice_notifier (struct notifier_block *nb) { -struct net_device *dev;struct net *net;int err;
@@ -1775,16 +1774,9 @@ int unregister_netdevice_notifier(struct notifier_block *nb)if (err) goto unlock; -for_each_net (net) { -for_each_netdev (net, dev) { -if (dev->flags &IFF_UP ) { -call_netdevice_notifier (nb,NETDEV_GOING_DOWN , - dev); -call_netdevice_notifier (nb,NETDEV_DOWN , dev); - } -call_netdevice_notifier (nb,NETDEV_UNREGISTER , dev); - } - } +for_each_net (net) +call_netdevice_unregister_net_notifiers (nb, net); + unlock:rtnl_unlock ();up_write (&pernet_ops_rwsem);
Signature · 1 line
2.21.0
PATCH v2 2/4 net: push code from net notifier reg/unreg into helpers
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Push the code which is done under rtnl lock in net notifier register and unregister function into separate helpers.
---v1->v2:
- fixed error path of __register_netdevice_notifier_net()
--- net/core/dev.c | 60 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 22 deletions(-)
net/core/dev.c +38 -22
@@ -1784,6 +1784,42 @@ int unregister_netdevice_notifier(struct notifier_block *nb) }EXPORT_SYMBOL (unregister_netdevice_notifier); +static int __register_netdevice_notifier_net (struct net *net, +struct notifier_block *nb, +bool ignore_call_fail) +{ +int err; + + err =raw_notifier_chain_register (&net->netdev_chain, nb); +if (err) +return err; +if (dev_boot_phase) +return 0 ; + + err =call_netdevice_register_net_notifiers (nb, net); +if (err && !ignore_call_fail) + goto chain_unregister; + +return 0 ; + +chain_unregister: +raw_notifier_chain_unregister (&net->netdev_chain, nb); +return err; +} + +static int __unregister_netdevice_notifier_net (struct net *net, +struct notifier_block *nb) +{ +int err; + + err =raw_notifier_chain_unregister (&net->netdev_chain, nb); +if (err) +return err; + +call_netdevice_unregister_net_notifiers (nb, net); +return 0 ; +} +/** * register_netdevice_notifier_net - register a per-netns network notifier block * @net: network namespace
@@ -1804,23 +1840,9 @@ int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb)int err;rtnl_lock (); - err =raw_notifier_chain_register (&net->netdev_chain, nb); -if (err) - goto unlock; -if (dev_boot_phase) - goto unlock; - - err =call_netdevice_register_net_notifiers (nb, net); -if (err) - goto chain_unregister; - -unlock: + err =__register_netdevice_notifier_net (net, nb, false);rtnl_unlock ();return err; - -chain_unregister: -raw_notifier_chain_unregister (&netdev_chain, nb); - goto unlock; }EXPORT_SYMBOL (register_netdevice_notifier_net);
@@ -1846,13 +1868,7 @@ int unregister_netdevice_notifier_net(struct net *net,int err;rtnl_lock (); - err =raw_notifier_chain_unregister (&net->netdev_chain, nb); -if (err) - goto unlock; - -call_netdevice_unregister_net_notifiers (nb, net); - -unlock: + err =__unregister_netdevice_notifier_net (net, nb);rtnl_unlock ();return err; }
Signature · 1 line
2.21.0
PATCH v2 3/4 net: introduce dev_net notifier register/unregister variants
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Introduce dev_net variants of netdev notifier register/unregister functions and allow per-net notifier to follow the netdevice into the namespace it is moved to.
--- include/linux/netdevice.h | 17 +++++++++++++++ net/core/dev.c | 46 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+)
include/linux/netdevice.h +17 -0
@@ -938,6 +938,11 @@ struct netdev_name_node {int netdev_name_node_alt_create (struct net_device *dev,const char *name);int netdev_name_node_alt_destroy (struct net_device *dev,const char *name); +struct netdev_net_notifier { +struct list_head list; +struct notifier_block *nb; +}; +/* * This structure defines the management hooks for network devices. * The following hooks can be defined; unless noted otherwise, they are
@@ -1792,6 +1797,10 @@ enum netdev_priv_flags {* * @wol_enabled: Wake-on-LAN is enabled * +* @net_notifier_list: List of per-net netdev notifier block +* that follow this device when it is moved +* to another network namespace. +* * FIXME: cleanup struct net_device such that network protocol info * moves out. */
@@ -2084,6 +2093,8 @@ struct net_device {struct lock_class_key addr_list_lock_key;bool proto_down; unsigned wol_enabled:1; + +struct list_head net_notifier_list; };#define to_net_dev (d) container_of(d, struct net_device, dev)
@@ -2527,6 +2538,12 @@ int unregister_netdevice_notifier(struct notifier_block *nb);int register_netdevice_notifier_net (struct net *net,struct notifier_block *nb);int unregister_netdevice_notifier_net (struct net *net,struct notifier_block *nb); +int register_netdevice_notifier_dev_net (struct net_device *dev, +struct notifier_block *nb, +struct netdev_net_notifier *nn); +int unregister_netdevice_notifier_dev_net (struct net_device *dev, +struct notifier_block *nb, +struct netdev_net_notifier *nn);struct netdev_notifier_info {struct net_device *dev;
net/core/dev.c +46 -0
64 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v2 4/4 mlx5: Use dev_net netdevice notifier registrations
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Register the dev_net notifier and allow the per-net notifier to follow the device into different namespace.
---v1->v2:
- Rebased on top of recent changes
--- drivers/net/ethernet/mellanox/mlx5/core/en/fs.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 3 ++- drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 13 ++++++++++--- drivers/net/ethernet/mellanox/mlx5/core/en_rep.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 9 +++++++-- drivers/net/ethernet/mellanox/mlx5/core/lag.c | 8 +++++--- drivers/net/ethernet/mellanox/mlx5/core/lag.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h | 2 +- 8 files changed, 28 insertions(+), 10 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +1 -0
@@ -21,6 +21,7 @@ struct mlx5e_tc_table {DECLARE_HASHTABLE (hairpin_tbl,8 );struct notifier_block netdevice_nb; +struct netdev_net_notifier netdevice_nn; };struct mlx5e_flow_table {
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +2 -1
@@ -5144,6 +5144,7 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)static void mlx5e_nic_disable (struct mlx5e_priv *priv) { +struct net_device *netdev = priv->netdev;struct mlx5_core_dev *mdev = priv->mdev;#ifdef CONFIG_MLX5_CORE_EN_DCB
@@ -5164,7 +5165,7 @@ static void mlx5e_nic_disable(struct mlx5e_priv *priv)mlx5e_monitor_counter_cleanup (priv);mlx5e_disable_async_events (priv); -mlx5_lag_remove (mdev); +mlx5_lag_remove (mdev, netdev); }int mlx5e_update_nic_rx (struct mlx5e_priv *priv)
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +10 -3
@@ -1731,7 +1731,9 @@ static int mlx5e_init_uplink_rep_tx(struct mlx5e_rep_priv *rpriv)/* init indirect block notifications */ INIT_LIST_HEAD (&uplink_priv->tc_indr_block_priv_list); uplink_priv->netdevice_nb.notifier_call = mlx5e_nic_rep_netdevice_event; - err =register_netdevice_notifier (&uplink_priv->netdevice_nb); + err =register_netdevice_notifier_dev_net (rpriv->netdev, + &uplink_priv->netdevice_nb, + &uplink_priv->netdevice_nn);if (err) {mlx5_core_err (priv->mdev,"Failed to register netdev notifier\n" ); goto tc_esw_cleanup;
@@ -1770,8 +1772,12 @@ static int mlx5e_init_rep_tx(struct mlx5e_priv *priv)static void mlx5e_cleanup_uplink_rep_tx (struct mlx5e_rep_priv *rpriv) { +struct mlx5_rep_uplink_priv *uplink_priv = &rpriv->uplink_priv; +/* clean indirect TC block notifications */ -unregister_netdevice_notifier (&rpriv->uplink_priv.netdevice_nb); +unregister_netdevice_notifier_dev_net (rpriv->netdev, + &uplink_priv->netdevice_nb, + &uplink_priv->netdevice_nn);mlx5e_rep_indr_clean_block_privs (rpriv);/* delete shared tc flow table */
@@ -1855,6 +1861,7 @@ static void mlx5e_uplink_rep_enable(struct mlx5e_priv *priv)static void mlx5e_uplink_rep_disable (struct mlx5e_priv *priv) { +struct net_device *netdev = priv->netdev;struct mlx5_core_dev *mdev = priv->mdev;struct mlx5e_rep_priv *rpriv = priv->ppriv;
@@ -1863,7 +1870,7 @@ static void mlx5e_uplink_rep_disable(struct mlx5e_priv *priv)#endif mlx5_notifier_unregister (mdev, &priv->events_nb);cancel_work_sync (&rpriv->uplink_priv.reoffload_flows_work); -mlx5_lag_remove (mdev); +mlx5_lag_remove (mdev, netdev); } static MLX5E_DEFINE_STATS_GRP(sw_rep, 0);
drivers/net/ethernet/mellanox/mlx5/core/en_rep.h +1 -0
@@ -73,6 +73,7 @@ struct mlx5_rep_uplink_priv {*/ struct list_head tc_indr_block_priv_list;struct notifier_block netdevice_nb; +struct netdev_net_notifier netdevice_nn;struct mlx5_tun_entropy tun_entropy;
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +7 -2
@@ -4246,7 +4246,10 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv)return err; tc->netdevice_nb.notifier_call = mlx5e_tc_netdev_event; -if (register_netdevice_notifier (&tc->netdevice_nb)) { + err =register_netdevice_notifier_dev_net (priv->netdev, + &tc->netdevice_nb, + &tc->netdevice_nn); +if (err) { tc->netdevice_nb.notifier_call =NULL ;mlx5_core_warn (priv->mdev,"Failed to register netdev notifier\n" ); }
@@ -4268,7 +4271,9 @@ void mlx5e_tc_nic_cleanup(struct mlx5e_priv *priv)struct mlx5e_tc_table *tc = &priv->fs.tc;if (tc->netdevice_nb.notifier_call) -unregister_netdevice_notifier (&tc->netdevice_nb); +unregister_netdevice_notifier_dev_net (priv->netdev, + &tc->netdevice_nb, + &tc->netdevice_nn);mutex_destroy (&tc->mod_hdr.lock);mutex_destroy (&tc->hairpin_tbl_lock);
drivers/net/ethernet/mellanox/mlx5/core/lag.c +5 -3
@@ -586,7 +586,8 @@ void mlx5_lag_add(struct mlx5_core_dev *dev, struct net_device *netdev)if (!ldev->nb.notifier_call) { ldev->nb.notifier_call = mlx5_lag_netdev_event; -if (register_netdevice_notifier (&ldev->nb)) { +if (register_netdevice_notifier_dev_net (netdev, &ldev->nb, + &ldev->nn)) { ldev->nb.notifier_call =NULL ;mlx5_core_err (dev,"Failed to register LAG netdev notifier\n" ); }
@@ -599,7 +600,7 @@ void mlx5_lag_add(struct mlx5_core_dev *dev, struct net_device *netdev) }/* Must be called with intf_mutex held */ -void mlx5_lag_remove (struct mlx5_core_dev *dev) +void mlx5_lag_remove (struct mlx5_core_dev *dev,struct net_device *netdev) {struct mlx5_lag *ldev;int i;
@@ -619,7 +620,8 @@ void mlx5_lag_remove(struct mlx5_core_dev *dev)if (i ==MLX5_MAX_PORTS ) {if (ldev->nb.notifier_call) -unregister_netdevice_notifier (&ldev->nb); +unregister_netdevice_notifier_dev_net (netdev, &ldev->nb, + &ldev->nn);mlx5_lag_mp_cleanup (ldev);cancel_delayed_work_sync (&ldev->bond_work);mlx5_lag_dev_free (ldev);
drivers/net/ethernet/mellanox/mlx5/core/lag.h +1 -0
@@ -44,6 +44,7 @@ struct mlx5_lag {struct workqueue_struct *wq;struct delayed_work bond_work;struct notifier_block nb; +struct netdev_net_notifier nn;struct lag_mp lag_mp; };
drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h +1 -1
@@ -157,7 +157,7 @@ int mlx5_query_qcam_reg(struct mlx5_core_dev *mdev, u32 *qcam, u8 feature_group, u8 access_reg_group);void mlx5_lag_add (struct mlx5_core_dev *dev,struct net_device *netdev); -void mlx5_lag_remove (struct mlx5_core_dev *dev); +void mlx5_lag_remove (struct mlx5_core_dev *dev,struct net_device *netdev);int mlx5_irq_table_init (struct mlx5_core_dev *dev);void mlx5_irq_table_cleanup (struct mlx5_core_dev *dev);
Signature · 1 line
2.21.0
David Miller
maintainerFrom: Jiri Pirko <[email protected]>
Date: Sat, 25 Jan 2020 12:17:05 +0100
Quoted 7 lines
From: Jiri Pirko <[email protected]>
Currently we have per-net notifier, which allows to get only notifications relevant to particular network namespace. That is enough for drivers that have netdevs local in a particular namespace (cannot move elsewhere).
Quoted 5 lines
However if netdev can change namespace, per-net notifier cannot be used. Introduce
dev_netvariant that is basically per-net notifier with an extension that re-registers the per-net notifier upon netdev namespace change. Basically the per-net notifier follows the netdev into namespace.
Series applied, thanks Jiri.