Skip to content

Commit

Permalink
virtio-net: fix race between set queues and probe
Browse files Browse the repository at this point in the history
A race were found where set_channels could be called after registering
but before virtnet_set_queues() in virtnet_probe(). Fixing this by
moving the virtnet_set_queues() before netdevice registering. While at
it, use _virtnet_set_queues() to avoid holding rtnl as the device is
not even registered at that time.

Cc: stable@vger.kernel.org
Fixes: a220871 ("virtio-net: correctly enable multiqueue")
Signed-off-by: Jason Wang <jasowang@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230725072049.617289-1-jasowang@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
jasowang authored and kuba-moo committed Jul 27, 2023
1 parent 6c58c88 commit 2526612
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -4219,6 +4219,8 @@ static int virtnet_probe(struct virtio_device *vdev)
if (vi->has_rss || vi->has_rss_hash_report)
virtnet_init_default_rss(vi);

_virtnet_set_queues(vi, vi->curr_queue_pairs);

/* serialize netdev register + virtio_device_ready() with ndo_open() */
rtnl_lock();

Expand Down Expand Up @@ -4257,8 +4259,6 @@ static int virtnet_probe(struct virtio_device *vdev)
goto free_unregister_netdev;
}

virtnet_set_queues(vi, vi->curr_queue_pairs);

/* Assume link up if device can't report link status,
otherwise get link status from config. */
netif_carrier_off(dev);
Expand Down

0 comments on commit 2526612

Please sign in to comment.