Commit 5c0418ed authored by Leon Romanovsky's avatar Leon Romanovsky Committed by David S. Miller
Browse files

netdevsim: Protect both reload_down and reload_up paths



Don't progress with adding and deleting ports as long as devlink
reload is running.

Fixes: 23809a72 ("netdevsim: Forbid devlink reload when adding or deleting ports")
Signed-off-by: default avatarLeon Romanovsky <leonro@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a5516053
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -196,6 +196,11 @@ new_port_store(struct device *dev, struct device_attribute *attr,
	if (!mutex_trylock(&nsim_bus_dev->nsim_bus_reload_lock))
		return -EBUSY;

	if (nsim_bus_dev->in_reload) {
		mutex_unlock(&nsim_bus_dev->nsim_bus_reload_lock);
		return -EBUSY;
	}

	ret = nsim_dev_port_add(nsim_bus_dev, NSIM_DEV_PORT_TYPE_PF, port_index);
	mutex_unlock(&nsim_bus_dev->nsim_bus_reload_lock);
	return ret ? ret : count;
@@ -221,6 +226,11 @@ del_port_store(struct device *dev, struct device_attribute *attr,
	if (!mutex_trylock(&nsim_bus_dev->nsim_bus_reload_lock))
		return -EBUSY;

	if (nsim_bus_dev->in_reload) {
		mutex_unlock(&nsim_bus_dev->nsim_bus_reload_lock);
		return -EBUSY;
	}

	ret = nsim_dev_port_del(nsim_bus_dev, NSIM_DEV_PORT_TYPE_PF, port_index);
	mutex_unlock(&nsim_bus_dev->nsim_bus_reload_lock);
	return ret ? ret : count;
+11 −1
Original line number Diff line number Diff line
@@ -878,6 +878,7 @@ static int nsim_dev_reload_down(struct devlink *devlink, bool netns_change,
		mutex_unlock(&nsim_bus_dev->nsim_bus_reload_lock);
		return -EOPNOTSUPP;
	}
	nsim_bus_dev->in_reload = true;

	nsim_dev_reload_destroy(nsim_dev);
	mutex_unlock(&nsim_bus_dev->nsim_bus_reload_lock);
@@ -889,17 +890,26 @@ static int nsim_dev_reload_up(struct devlink *devlink, enum devlink_reload_actio
			      struct netlink_ext_ack *extack)
{
	struct nsim_dev *nsim_dev = devlink_priv(devlink);
	struct nsim_bus_dev *nsim_bus_dev;
	int ret;

	nsim_bus_dev = nsim_dev->nsim_bus_dev;
	mutex_lock(&nsim_bus_dev->nsim_bus_reload_lock);
	nsim_bus_dev->in_reload = false;

	if (nsim_dev->fail_reload) {
		/* For testing purposes, user set debugfs fail_reload
		 * value to true. Fail right away.
		 */
		NL_SET_ERR_MSG_MOD(extack, "User setup the reload to fail for testing purposes");
		mutex_unlock(&nsim_bus_dev->nsim_bus_reload_lock);
		return -EINVAL;
	}

	*actions_performed = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT);
	return nsim_dev_reload_create(nsim_dev, extack);
	ret = nsim_dev_reload_create(nsim_dev, extack);
	mutex_unlock(&nsim_bus_dev->nsim_bus_reload_lock);
	return ret;
}

static int nsim_dev_info_get(struct devlink *devlink,
+1 −0
Original line number Diff line number Diff line
@@ -362,6 +362,7 @@ struct nsim_bus_dev {
	struct nsim_vf_config *vfconfigs;
	/* Lock for devlink->reload_enabled in netdevsim module */
	struct mutex nsim_bus_reload_lock;
	bool in_reload;
	bool init;
};