Skip to contentSkip to conversation

vhost-net regression fixes

PATCH In review Michael S. Tsirkin 3 participants 6 messages Sep 15, 2025 – Sep 16, 2025

Subsystems (6)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

v3 cover vhost-net regression fixes

Two regressions were reported in vhost-net. This is based on a patchset by Jason, but with patch 2 from his series split up and made simpler.

Lightly tested.
Jason, Jon could you pls test this as well, and report?

Jason Wang (2):
vhost-net: unbreak busy polling

Michael S. Tsirkin (1):
Revert "vhost/net: Defer TX queue re-enable until after sendmsg"
vhost-net: flush batched before enabling notifications

 drivers/vhost/net.c | 44 ++++++++++++++++++++------------------------
 1 file changed, 20 insertions(+), 24 deletions(-)
Signature · 1 line
MST
author maintainer
#1 lore raw

PATCH v3 1/3 vhost-net: unbreak busy polling

From: Jason Wang <[email protected]>

Commit 67a873df0c41 ("vhost: basic in order support") pass the number of used elem to vhost_net_rx_peek_head_len() to make sure it can signal the used correctly before trying to do busy polling. But it forgets to clear the count, this would cause the count run out of sync with handle_rx() and break the busy polling.

Fixing this by passing the pointer of the count and clearing it after the signaling the used.

Fixes 67a873df0c41 ("vhost: basic in order support")

Message-Id: <[email protected]>

---
 drivers/vhost/net.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/vhost/net.c +4 -3
index c6508fe0d5c8..16e39f3ab956 100644
@@ -1014,7 +1014,7 @@ static int peek_head_len(struct vhost_net_virtqueue *rvq, struct sock *sk)
 }
 
 static int vhost_net_rx_peek_head_len(struct vhost_net *net, struct sock *sk,
-				      bool *busyloop_intr, unsigned int count)
+				      bool *busyloop_intr, unsigned int *count)
 {
 	struct vhost_net_virtqueue *rnvq = &net->vqs[VHOST_NET_VQ_RX];
 	struct vhost_net_virtqueue *tnvq = &net->vqs[VHOST_NET_VQ_TX];
@@ -1024,7 +1024,8 @@ static int vhost_net_rx_peek_head_len(struct vhost_net *net, struct sock *sk,
 
 	if (!len && rvq->busyloop_timeout) {
 		/* Flush batched heads first */
-		vhost_net_signal_used(rnvq, count);
+		vhost_net_signal_used(rnvq, *count);
+		*count = 0;
 		/* Both tx vq and rx socket were polled here */
 		vhost_net_busy_poll(net, rvq, tvq, busyloop_intr, true);
 
@@ -1180,7 +1181,7 @@ static void handle_rx(struct vhost_net *net)
 
 	do {
 		sock_len = vhost_net_rx_peek_head_len(net, sock->sk,
-						      &busyloop_intr, count);
+						      &busyloop_intr, &count);
 		if (!sock_len)
 			break;
 		sock_len += sock_hlen;
Signature · 1 line
MST
author maintainer
#2 lore raw

PATCH v3 2/3 Revert "vhost/net: Defer TX queue re-enable until after sendmsg"

Commit 8c2e6b26ffe2 ("vhost/net: Defer TX queue re-enable until after sendmsg") tries to defer the notification enabling by moving the logic out of the loop after the vhost_tx_batch() when nothing new is spotted. This will bring side effects as the new logic would be reused for several other error conditions.

One example is the IOTLB: when there's an IOTLB miss, get_tx_bufs() might return -EAGAIN and exit the loop and see there's still available buffers, so it will queue the tx work again until userspace feed the IOTLB entry correctly. This will slowdown the tx processing and trigger the TX watchdog in the guest as reported in
https://lkml.org/lkml/2025/9/10/1596.

To fix, revert the change. A follow up patch will being the performance back in a safe way.

Fixes 8c2e6b26ffe2 ("vhost/net: Defer TX queue re-enable until after sendmsg")
---
 drivers/vhost/net.c | 30 +++++++++---------------------
 1 file changed, 9 insertions(+), 21 deletions(-)
drivers/vhost/net.c +9 -21
index 16e39f3ab956..57efd5c55f89 100644
@@ -765,11 +765,11 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock)
 	int err;
 	int sent_pkts = 0;
 	bool sock_can_batch = (sock->sk->sk_sndbuf == INT_MAX);
-	bool busyloop_intr;
 	bool in_order = vhost_has_feature(vq, VIRTIO_F_IN_ORDER);
 
 	do {
-		busyloop_intr = false;
+		bool busyloop_intr = false;
+
 		if (nvq->done_idx == VHOST_NET_BATCH)
 			vhost_tx_batch(net, nvq, sock, &msg);
 
@@ -780,10 +780,13 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock)
 			break;
 		/* Nothing new?  Wait for eventfd to tell us they refilled. */
 		if (head == vq->num) {
-			/* Kicks are disabled at this point, break loop and
-			 * process any remaining batched packets. Queue will
-			 * be re-enabled afterwards.
-			 */
+			if (unlikely(busyloop_intr)) {
+				vhost_poll_queue(&vq->poll);
+			} else if (unlikely(vhost_enable_notify(&net->dev,
+								vq))) {
+				vhost_disable_notify(&net->dev, vq);
+				continue;
+			}
 			break;
 		}
 
@@ -839,22 +842,7 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock)
 		++nvq->done_idx;
 	} while (likely(!vhost_exceeds_weight(vq, ++sent_pkts, total_len)));
 
-	/* Kicks are still disabled, dispatch any remaining batched msgs. */
 	vhost_tx_batch(net, nvq, sock, &msg);
-
-	if (unlikely(busyloop_intr))
-		/* If interrupted while doing busy polling, requeue the
-		 * handler to be fair handle_rx as well as other tasks
-		 * waiting on cpu.
-		 */
-		vhost_poll_queue(&vq->poll);
-	else
-		/* All of our work has been completed; however, before
-		 * leaving the TX handler, do one last check for work,
-		 * and requeue handler if necessary. If there is no work,
-		 * queue will be reenabled.
-		 */
-		vhost_net_busy_poll_try_queue(net, vq);
 }
 
 static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock)
Signature · 1 line
MST
author maintainer
#3 lore raw

PATCH v3 3/3 vhost-net: flush batched before enabling notifications

In reply to Michael S. Tsirkin

Commit 8c2e6b26ffe2 ("vhost/net: Defer TX queue re-enable until after sendmsg") tries to defer the notification enabling by moving the logic out of the loop after the vhost_tx_batch() when nothing new is spotted. This caused unexpected side effects as the new logic is reused for several other error conditions.

A previous patch reverted 8c2e6b26ffe2. Now, bring the performance back up by flushing batched buffers before enabling notifications.

Fixes 8c2e6b26ffe2 ("vhost/net: Defer TX queue re-enable until after sendmsg")
---
 drivers/vhost/net.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/vhost/net.c +12 -5
index 57efd5c55f89..72ecb8691275 100644
@@ -782,11 +782,18 @@ static void handle_tx_copy(struct vhost_net *net, struct socket *sock)
 		if (head == vq->num) {
 			if (unlikely(busyloop_intr)) {
 				vhost_poll_queue(&vq->poll);
-			} else if (unlikely(vhost_enable_notify(&net->dev,
-								vq))) {
-				vhost_disable_notify(&net->dev, vq);
-				continue;
-			}
+			} else {
+				/* Flush batched packets before enabling
+				 * virtqueue notifications to reduce
+				 * unnecessary virtqueue kicks.
+				 */
+				vhost_tx_batch(net, nvq, sock, &msg);
+
+				if (unlikely(vhost_enable_notify(&net->dev,
+								 vq))) {
+					vhost_disable_notify(&net->dev, vq);
+					continue;
+				}
 			break;
 		}
 
Signature · 1 line
MST
Tested-by on the v3 series
#4 lore raw
In reply to Michael S. Tsirkin
Quoted 10 lines · Michael S. Tsirkin

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

Quoted 6 lines

Two regressions were reported in vhost-net. This is based on a patchset by Jason, but with patch 2 from his series split up and made simpler.

Lightly tested.
Jason, Jon could you pls test this as well, and report?

For the iotlb bit (patch 2/3):
Tried this out on a 6.16 host / guest that locked up with iotlb miss loop, applied this patch and all was well.

Quoted 15 lines

Jason Wang (2):
vhost-net: unbreak busy polling

Michael S. Tsirkin (1):
Revert "vhost/net: Defer TX queue re-enable until after sendmsg"
vhost-net: flush batched before enabling notifications

drivers/vhost/net.c | 44 ++++++++++++++++++++------------------------

1 file changed, 20 insertions(+), 24 deletions(-)
Signature · 1 line
MST
Tested-by
#5 lore raw

Tested this series of patches with virtio-net regression tests, everything works fine. Please feel free to let me know if these patches need me to do more tests.

Quoted 40 lines · Jon Kohler
Quoted 11 lines · Michael S. Tsirkin

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

Quoted 6 lines

Two regressions were reported in vhost-net. This is based on a patchset by Jason, but with patch 2 from his series split up and made simpler.

Lightly tested.
Jason, Jon could you pls test this as well, and report?

For the iotlb bit (patch 2/3):
Tried this out on a 6.16 host / guest that locked up with iotlb miss loop, applied this patch and all was well.

Quoted 15 lines

Jason Wang (2):
vhost-net: unbreak busy polling

Michael S. Tsirkin (1):
Revert "vhost/net: Defer TX queue re-enable until after sendmsg"
vhost-net: flush batched before enabling notifications

drivers/vhost/net.c | 44 ++++++++++++++++++++------------------------

1 file changed, 20 insertions(+), 24 deletions(-)

--
MST