Skip to content

Commit 23f8bea

Browse files
jdikegregkh
authored andcommitted
virtio_net: Fix recursive call to cpus_read_lock()
[ Upstream commit de33212 ] virtnet_set_channels can recursively call cpus_read_lock if CONFIG_XPS and CONFIG_HOTPLUG are enabled. The path is: virtnet_set_channels - calls get_online_cpus(), which is a trivial wrapper around cpus_read_lock() netif_set_real_num_tx_queues netif_reset_xps_queues_gt netif_reset_xps_queues - calls cpus_read_lock() This call chain and potential deadlock happens when the number of TX queues is reduced. This commit the removes netif_set_real_num_[tr]x_queues calls from inside the get/put_online_cpus section, as they don't require that it be held. Fixes: 47be247 ("virtio-net: fix the set affinity bug when CPU IDs are not consecutive") Signed-off-by: Jeff Dike <[email protected]> Acked-by: Jason Wang <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 087cfc7 commit 23f8bea

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

drivers/net/virtio_net.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -2093,14 +2093,16 @@ static int virtnet_set_channels(struct net_device *dev,
20932093

20942094
get_online_cpus();
20952095
err = _virtnet_set_queues(vi, queue_pairs);
2096-
if (!err) {
2097-
netif_set_real_num_tx_queues(dev, queue_pairs);
2098-
netif_set_real_num_rx_queues(dev, queue_pairs);
2099-
2100-
virtnet_set_affinity(vi);
2096+
if (err) {
2097+
put_online_cpus();
2098+
goto err;
21012099
}
2100+
virtnet_set_affinity(vi);
21022101
put_online_cpus();
21032102

2103+
netif_set_real_num_tx_queues(dev, queue_pairs);
2104+
netif_set_real_num_rx_queues(dev, queue_pairs);
2105+
err:
21042106
return err;
21052107
}
21062108

0 commit comments

Comments
 (0)