Skip to content

Commit 032afbe

Browse files
kuba-moosmb49
authored andcommitted
virtio-net: don't re-enable refill work too early when NAPI is disabled
BugLink: https://bugs.launchpad.net/bugs/2115252 [ Upstream commit 1e20324 ] Commit 4bc1281 ("virtio-net: disable delayed refill when pausing rx") fixed a deadlock between reconfig paths and refill work trying to disable the same NAPI instance. The refill work can't run in parallel with reconfig because trying to double-disable a NAPI instance causes a stall under the instance lock, which the reconfig path needs to re-enable the NAPI and therefore unblock the stalled thread. There are two cases where we re-enable refill too early. One is in the virtnet_set_queues() handler. We call it when installing XDP: virtnet_rx_pause_all(vi); ... virtnet_napi_tx_disable(..); ... virtnet_set_queues(..); ... virtnet_rx_resume_all(..); We want the work to be disabled until we call virtnet_rx_resume_all(), but virtnet_set_queues() kicks it before NAPIs were re-enabled. The other case is a more trivial case of mis-ordering in __virtnet_rx_resume() found by code inspection. Taking the spin lock in virtnet_set_queues() (requested during review) may be unnecessary as we are under rtnl_lock and so are all paths writing to ->refill_enabled. Acked-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Bui Quang Minh <[email protected]> Fixes: 4bc1281 ("virtio-net: disable delayed refill when pausing rx") Fixes: 413f027 ("net: protect NAPI enablement with netdev_lock()") Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Manuel Diewald <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent 4745fbf commit 032afbe

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/net/virtio_net.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3359,12 +3359,15 @@ static void __virtnet_rx_resume(struct virtnet_info *vi,
33593359
bool refill)
33603360
{
33613361
bool running = netif_running(vi->dev);
3362+
bool schedule_refill = false;
33623363

33633364
if (refill && !try_fill_recv(vi, rq, GFP_KERNEL))
3364-
schedule_delayed_work(&vi->refill, 0);
3365-
3365+
schedule_refill = true;
33663366
if (running)
33673367
virtnet_napi_enable(rq);
3368+
3369+
if (schedule_refill)
3370+
schedule_delayed_work(&vi->refill, 0);
33683371
}
33693372

33703373
static void virtnet_rx_resume_all(struct virtnet_info *vi)
@@ -3699,8 +3702,10 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
36993702
succ:
37003703
vi->curr_queue_pairs = queue_pairs;
37013704
/* virtnet_open() will refill when device is going to up. */
3702-
if (dev->flags & IFF_UP)
3705+
spin_lock_bh(&vi->refill_lock);
3706+
if (dev->flags & IFF_UP && vi->refill_enabled)
37033707
schedule_delayed_work(&vi->refill, 0);
3708+
spin_unlock_bh(&vi->refill_lock);
37043709

37053710
return 0;
37063711
}

0 commit comments

Comments
 (0)