Commit 97bfe0e0 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'devlink-allow-devlink-instances-to-change-network-namespace'



Jiri Pirko says:

====================
devlink: allow devlink instances to change network namespace

Devlink from the beginning counts with network namespaces, but the
instances has been fixed to init_net.

Implement change of network namespace as part of "devlink reload"
procedure like this:

$ ip netns add testns1
$ devlink/devlink dev reload netdevsim/netdevsim10 netns testns1

This command reloads device "netdevsim10" into network
namespace "testns1".

Note that "devlink reload" reinstantiates driver objects, effectively it
reloads the driver instance, including possible hw reset etc. Newly
created netdevices respect the network namespace of the parent devlink
instance and according to that, they are created in target network
namespace.

Driver is able to refuse to be reloaded into different namespace. That
is the case of mlx4 right now.

FIB entries and rules are replayed during FIB notifier registration
which is triggered during reload (driver instance init). FIB notifier
is also registered to the target network namespace, that allows user
to use netdevsim devlink resources to setup per-namespace limits of FIB
entries and FIB rules. In fact, with multiple netdevsim instances
in each network namespace, user might setup different limits.
This maintains and extends current netdevsim resources behaviour.

Patch 1 prepares netdevsim code for the follow-up changes in the
patchset. It does not change the behaviour, only moves pet-init_netns
accounting to netdevsim instance, which is also in init_netns.

Patches 2-5 prepare the FIB notifier making it per-netns and to behave
correctly upon error conditions.

Patch 6 just exports a devlink_net helper so it can be used in drivers.

Patches 7-9 do preparations in mlxsw driver.

Patches 10-13 do preparations in netdevsim driver, namely patch 12
implements proper devlink reload where the driver instance objects are
actually re-created as they should be.

Patch 14 actually implements the possibility to reload into a different
network namespace.

Patch 15 adds needed selftests for devlink reload into namespace for
netdevsim driver.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 9077f052 b74c37fd
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -3935,13 +3935,17 @@ static void mlx4_restart_one_down(struct pci_dev *pdev);
static int mlx4_restart_one_up(struct pci_dev *pdev, bool reload,
			       struct devlink *devlink);

static int mlx4_devlink_reload_down(struct devlink *devlink,
static int mlx4_devlink_reload_down(struct devlink *devlink, bool netns_change,
				    struct netlink_ext_ack *extack)
{
	struct mlx4_priv *priv = devlink_priv(devlink);
	struct mlx4_dev *dev = &priv->dev;
	struct mlx4_dev_persistent *persist = dev->persist;

	if (netns_change) {
		NL_SET_ERR_MSG_MOD(extack, "Namespace change is not supported");
		return -EOPNOTSUPP;
	}
	if (persist->num_vfs)
		mlx4_warn(persist->dev, "Reload performed on PF, will cause reset on operating Virtual Functions\n");
	mlx4_restart_one_down(persist->pdev);
+3 −6
Original line number Diff line number Diff line
@@ -248,9 +248,6 @@ static int mlx5_lag_fib_event(struct notifier_block *nb,
	struct net_device *fib_dev;
	struct fib_info *fi;

	if (!net_eq(info->net, &init_net))
		return NOTIFY_DONE;

	if (info->family != AF_INET)
		return NOTIFY_DONE;

@@ -311,8 +308,8 @@ int mlx5_lag_mp_init(struct mlx5_lag *ldev)
		return 0;

	mp->fib_nb.notifier_call = mlx5_lag_fib_event;
	err = register_fib_notifier(&mp->fib_nb,
				    mlx5_lag_fib_event_flush);
	err = register_fib_notifier(&init_net, &mp->fib_nb,
				    mlx5_lag_fib_event_flush, NULL);
	if (err)
		mp->fib_nb.notifier_call = NULL;

@@ -326,6 +323,6 @@ void mlx5_lag_mp_cleanup(struct mlx5_lag *ldev)
	if (!mp->fib_nb.notifier_call)
		return;

	unregister_fib_notifier(&mp->fib_nb);
	unregister_fib_notifier(&init_net, &mp->fib_nb);
	mp->fib_nb.notifier_call = NULL;
}
+9 −5
Original line number Diff line number Diff line
@@ -985,6 +985,7 @@ mlxsw_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,

static int
mlxsw_devlink_core_bus_device_reload_down(struct devlink *devlink,
					  bool netns_change,
					  struct netlink_ext_ack *extack)
{
	struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
@@ -1005,7 +1006,7 @@ mlxsw_devlink_core_bus_device_reload_up(struct devlink *devlink,
	return mlxsw_core_bus_device_register(mlxsw_core->bus_info,
					      mlxsw_core->bus,
					      mlxsw_core->bus_priv, true,
					      devlink);
					      devlink, extack);
}

static int mlxsw_devlink_flash_update(struct devlink *devlink,
@@ -1098,7 +1099,8 @@ static int
__mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
				 const struct mlxsw_bus *mlxsw_bus,
				 void *bus_priv, bool reload,
				 struct devlink *devlink)
				 struct devlink *devlink,
				 struct netlink_ext_ack *extack)
{
	const char *device_kind = mlxsw_bus_info->device_kind;
	struct mlxsw_core *mlxsw_core;
@@ -1172,7 +1174,7 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
	}

	if (mlxsw_driver->init) {
		err = mlxsw_driver->init(mlxsw_core, mlxsw_bus_info);
		err = mlxsw_driver->init(mlxsw_core, mlxsw_bus_info, extack);
		if (err)
			goto err_driver_init;
	}
@@ -1223,14 +1225,16 @@ err_devlink_alloc:
int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
				   const struct mlxsw_bus *mlxsw_bus,
				   void *bus_priv, bool reload,
				   struct devlink *devlink)
				   struct devlink *devlink,
				   struct netlink_ext_ack *extack)
{
	bool called_again = false;
	int err;

again:
	err = __mlxsw_core_bus_device_register(mlxsw_bus_info, mlxsw_bus,
					       bus_priv, reload, devlink);
					       bus_priv, reload,
					       devlink, extack);
	/* -EAGAIN is returned in case the FW was updated. FW needs
	 * a reset, so lets try to call __mlxsw_core_bus_device_register()
	 * again.
+10 −2
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
#include <linux/types.h>
#include <linux/skbuff.h>
#include <linux/workqueue.h>
#include <linux/net_namespace.h>
#include <net/devlink.h>

#include "trap.h"
@@ -36,7 +37,8 @@ void mlxsw_core_driver_unregister(struct mlxsw_driver *mlxsw_driver);
int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
				   const struct mlxsw_bus *mlxsw_bus,
				   void *bus_priv, bool reload,
				   struct devlink *devlink);
				   struct devlink *devlink,
				   struct netlink_ext_ack *extack);
void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core, bool reload);

struct mlxsw_tx_info {
@@ -252,7 +254,8 @@ struct mlxsw_driver {
	const char *kind;
	size_t priv_size;
	int (*init)(struct mlxsw_core *mlxsw_core,
		    const struct mlxsw_bus_info *mlxsw_bus_info);
		    const struct mlxsw_bus_info *mlxsw_bus_info,
		    struct netlink_ext_ack *extack);
	void (*fini)(struct mlxsw_core *mlxsw_core);
	int (*basic_trap_groups_set)(struct mlxsw_core *mlxsw_core);
	int (*port_type_set)(struct mlxsw_core *mlxsw_core, u8 local_port,
@@ -350,6 +353,11 @@ u64 mlxsw_core_res_get(struct mlxsw_core *mlxsw_core,
#define MLXSW_CORE_RES_GET(mlxsw_core, short_res_id)			\
	mlxsw_core_res_get(mlxsw_core, MLXSW_RES_ID_##short_res_id)

static inline struct net *mlxsw_core_net(struct mlxsw_core *mlxsw_core)
{
	return devlink_net(priv_to_devlink(mlxsw_core));
}

#define MLXSW_BUS_F_TXRX	BIT(0)
#define MLXSW_BUS_F_RESET	BIT(1)

+1 −1
Original line number Diff line number Diff line
@@ -640,7 +640,7 @@ static int mlxsw_i2c_probe(struct i2c_client *client,

	err = mlxsw_core_bus_device_register(&mlxsw_i2c->bus_info,
					     &mlxsw_i2c_bus, mlxsw_i2c, false,
					     NULL);
					     NULL, NULL);
	if (err) {
		dev_err(&client->dev, "Fail to register core bus\n");
		return err;
Loading