virtio_net: Fix recursive call to cpus_read_lock()
authorJeff Dike <jdike@akamai.com>
Wed, 23 Dec 2020 02:54:21 +0000 (21:54 -0500)
committerJakub Kicinski <kuba@kernel.org>
Wed, 23 Dec 2020 17:11:13 +0000 (09:11 -0800)
commitde33212f768c5d9e2fe791b008cb26f92f0aa31c
treef4162dcbcc990e5c4a452f4fdaac2d87e659103a
parente77c725a445ac07c95c666b3bfb5b4105e9b0068
virtio_net: Fix recursive call to cpus_read_lock()

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: 47be24796c13 ("virtio-net: fix the set affinity bug when CPU IDs are not consecutive")
Signed-off-by: Jeff Dike <jdike@akamai.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Link: https://lore.kernel.org/r/20201223025421.671-1-jdike@akamai.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/virtio_net.c