virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio-net: disable delayed refill when setting up xdp
@ 2025-04-02  5:42 Bui Quang Minh
  2025-04-03  7:24 ` Paolo Abeni
  2025-04-03 10:43 ` Bui Quang Minh
  0 siblings, 2 replies; 5+ messages in thread
From: Bui Quang Minh @ 2025-04-02  5:42 UTC (permalink / raw)
  To: virtualization
  Cc: Michael S . Tsirkin, Jason Wang, Xuan Zhuo, Andrew Lunn,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
	Eugenio Pérez, David S . Miller, netdev, linux-kernel, bpf,
	Bui Quang Minh

When setting up XDP for a running interface, we call napi_disable() on
the receive queue's napi. In delayed refill_work, it also calls
napi_disable() on the receive queue's napi. This can leads to deadlock
when napi_disable() is called on an already disabled napi. This commit
fixes this by disabling future and cancelling all inflight delayed
refill works before calling napi_disabled() in virtnet_xdp_set.

Fixes: 4941d472bf95 ("virtio-net: do not reset during XDP set")
Signed-off-by: Bui Quang Minh <minhquangbui99@gmail.com>
---
 drivers/net/virtio_net.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 7e4617216a4b..33406d59efe2 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -5956,6 +5956,15 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog,
 	if (!prog && !old_prog)
 		return 0;
 
+	/*
+	 * Make sure refill_work does not run concurrently to
+	 * avoid napi_disable race which leads to deadlock.
+	 */
+	if (netif_running(dev)) {
+		disable_delayed_refill(vi);
+		cancel_delayed_work_sync(&vi->refill);
+	}
+
 	if (prog)
 		bpf_prog_add(prog, vi->max_queue_pairs - 1);
 
@@ -6004,6 +6013,8 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog,
 			virtnet_napi_tx_enable(&vi->sq[i]);
 		}
 	}
+	if (netif_running(dev))
+		enable_delayed_refill(vi);
 
 	return 0;
 
@@ -6019,6 +6030,7 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog,
 			virtnet_napi_enable(&vi->rq[i]);
 			virtnet_napi_tx_enable(&vi->sq[i]);
 		}
+		enable_delayed_refill(vi);
 	}
 	if (prog)
 		bpf_prog_sub(prog, vi->max_queue_pairs - 1);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-04-04  9:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-02  5:42 [PATCH] virtio-net: disable delayed refill when setting up xdp Bui Quang Minh
2025-04-03  7:24 ` Paolo Abeni
2025-04-03  8:10   ` Bui Quang Minh
2025-04-03 10:43 ` Bui Quang Minh
2025-04-04  9:43   ` Bui Quang Minh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).