Skip to content

Commit 26c37d8

Browse files
kuba-moodavem330
authored andcommitted
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: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1adc58e commit 26c37d8

File tree

1 file changed

+11
-3
lines changed
  • drivers/net/netdevsim

1 file changed

+11
-3
lines changed

drivers/net/netdevsim/bus.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ static struct nsim_bus_dev *to_nsim_bus_dev(struct device *dev)
2424
return container_of(dev, struct nsim_bus_dev, dev);
2525
}
2626

27+
static void
28+
nsim_bus_dev_set_vfs(struct nsim_bus_dev *nsim_bus_dev, unsigned int num_vfs)
29+
{
30+
rtnl_lock();
31+
nsim_bus_dev->num_vfs = num_vfs;
32+
rtnl_unlock();
33+
}
34+
2735
static int nsim_bus_dev_vfs_enable(struct nsim_bus_dev *nsim_bus_dev,
2836
unsigned int num_vfs)
2937
{
@@ -35,13 +43,13 @@ static int nsim_bus_dev_vfs_enable(struct nsim_bus_dev *nsim_bus_dev,
3543

3644
if (!nsim_bus_dev->vfconfigs)
3745
return -ENOMEM;
38-
nsim_bus_dev->num_vfs = num_vfs;
46+
nsim_bus_dev_set_vfs(nsim_bus_dev, num_vfs);
3947

4048
nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev);
4149
if (nsim_esw_mode_is_switchdev(nsim_dev)) {
4250
err = nsim_esw_switchdev_enable(nsim_dev, NULL);
4351
if (err)
44-
nsim_bus_dev->num_vfs = 0;
52+
nsim_bus_dev_set_vfs(nsim_bus_dev, 0);
4553
}
4654

4755
return err;
@@ -51,7 +59,7 @@ void nsim_bus_dev_vfs_disable(struct nsim_bus_dev *nsim_bus_dev)
5159
{
5260
struct nsim_dev *nsim_dev;
5361

54-
nsim_bus_dev->num_vfs = 0;
62+
nsim_bus_dev_set_vfs(nsim_bus_dev, 0);
5563
nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev);
5664
if (nsim_esw_mode_is_switchdev(nsim_dev))
5765
nsim_esw_legacy_enable(nsim_dev, NULL);

0 commit comments

Comments
 (0)