Commit 26c37d89 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

netdevsim: take rtnl_lock when assigning num_vfs

Legacy VF NDOs look at num_vfs and then based on that
index into vfconfig. If we don't rtnl_lock() num_vfs
may get set to 0 and vfconfig freed/replaced while
the NDO is running.

We don't need to protect replacing vfconfig since it's
only done when num_vfs is 0.
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1adc58ea
...@@ -24,6 +24,14 @@ static struct nsim_bus_dev *to_nsim_bus_dev(struct device *dev) ...@@ -24,6 +24,14 @@ static struct nsim_bus_dev *to_nsim_bus_dev(struct device *dev)
return container_of(dev, struct nsim_bus_dev, dev); return container_of(dev, struct nsim_bus_dev, dev);
} }
static void
nsim_bus_dev_set_vfs(struct nsim_bus_dev *nsim_bus_dev, unsigned int num_vfs)
{
rtnl_lock();
nsim_bus_dev->num_vfs = num_vfs;
rtnl_unlock();
}
static int nsim_bus_dev_vfs_enable(struct nsim_bus_dev *nsim_bus_dev, static int nsim_bus_dev_vfs_enable(struct nsim_bus_dev *nsim_bus_dev,
unsigned int num_vfs) unsigned int num_vfs)
{ {
...@@ -35,13 +43,13 @@ static int nsim_bus_dev_vfs_enable(struct nsim_bus_dev *nsim_bus_dev, ...@@ -35,13 +43,13 @@ static int nsim_bus_dev_vfs_enable(struct nsim_bus_dev *nsim_bus_dev,
if (!nsim_bus_dev->vfconfigs) if (!nsim_bus_dev->vfconfigs)
return -ENOMEM; return -ENOMEM;
nsim_bus_dev->num_vfs = num_vfs; nsim_bus_dev_set_vfs(nsim_bus_dev, num_vfs);
nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev); nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev);
if (nsim_esw_mode_is_switchdev(nsim_dev)) { if (nsim_esw_mode_is_switchdev(nsim_dev)) {
err = nsim_esw_switchdev_enable(nsim_dev, NULL); err = nsim_esw_switchdev_enable(nsim_dev, NULL);
if (err) if (err)
nsim_bus_dev->num_vfs = 0; nsim_bus_dev_set_vfs(nsim_bus_dev, 0);
} }
return err; return err;
...@@ -51,7 +59,7 @@ void nsim_bus_dev_vfs_disable(struct nsim_bus_dev *nsim_bus_dev) ...@@ -51,7 +59,7 @@ void nsim_bus_dev_vfs_disable(struct nsim_bus_dev *nsim_bus_dev)
{ {
struct nsim_dev *nsim_dev; struct nsim_dev *nsim_dev;
nsim_bus_dev->num_vfs = 0; nsim_bus_dev_set_vfs(nsim_bus_dev, 0);
nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev); nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev);
if (nsim_esw_mode_is_switchdev(nsim_dev)) if (nsim_esw_mode_is_switchdev(nsim_dev))
nsim_esw_legacy_enable(nsim_dev, NULL); nsim_esw_legacy_enable(nsim_dev, NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment