All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v2] vhost/net: Fix receive queue test in busy poll
@ 2026-11-20  3:38 raoxu
  2026-11-20  3:43 ` sashiko-bot
  2026-11-20 12:03 ` Eugenio Perez Martin
  0 siblings, 2 replies; 3+ messages in thread
From: raoxu @ 2026-11-20  3:38 UTC (permalink / raw)
  To: mst
  Cc: jasowangio, eperezma, davem, kvm, virtualization, netdev,
	linux-kernel, raoxu, stable

From: Xu Rao <raoxu@uniontech.com>

sock_has_rx_data() returns a positive value when receive data is
available. For sockets without a peek_len() callback, however, its
fallback returns skb_queue_empty(), which has the opposite meaning.

An AF_PACKET SOCK_RAW socket is accepted by get_raw_socket() as a
vhost-net backend, and its socket operations do not provide peek_len().
With busy polling enabled for this backend, an empty receive queue is
treated as ready and a nonempty queue as not ready. This can make
vhost_net_busy_poll() stop polling prematurely or fail to stop for
queued receive data, and invert its receive-side scheduling decision.
TUN and TAP backends provide peek_len() and are unaffected.

Negate skb_queue_empty() so the fallback matches the callback and the
readiness checks in vhost_net_busy_poll().

The issue was found during AI-assisted code review. The helper's
incorrect result was confirmed on x86_64 running 6.6.0-amd64-desktop
using a temporary diagnostic module containing the original and fixed
helpers. An AF_PACKET SOCK_RAW socket, without PACKET_RX_RING, was
bound to loopback in a private network namespace. Across three cycles
of sending and receiving a 60-byte frame, the original helper returned
1 for an empty queue and 0 for a queued frame. The fixed helper returned
0 and 1 respectively, matching socket readability in all nine checks.
This tests helper copies on real sockets, not the running vhost-net
busy-poll path; the vhost-net module was not replaced.

The patched drivers/vhost/net.o was also build-tested on the net tree
with x86_64 GCC 12.3 and W=1 under allmodconfig and allyesconfig.
No end-to-end vhost tests or kernel selftests were run.

Fixes: 1576d9860599 ("tun: switch to use skb array for tx")
Cc: stable@vger.kernel.org
Signed-off-by: Xu Rao <raoxu@uniontech.com>
---
Changes in v2:
  - Target net and add the introducing commit's Fixes tag.
  - Explain the raw packet socket backend and busy-poll decisions.
  - State the AI-assisted discovery method and document the diagnostic
    module test, its results and its helper-level coverage.
  - Document the targeted build tests.
  - Keep the code change unchanged from v1.

v1: https://lore.kernel.org/virtualization/20261110051642.249640-1-raoxu@uniontech.com/

AI assistance: OpenCode was used to inspect the history, prepare and run
the diagnostic module test, run build checks, and revise this message.
The code change is unchanged from v1. The discovery method was confirmed
by the author.

 drivers/vhost/net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 4570a4ffbab2..10ed2d55ff07 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -538,7 +538,7 @@ static int sock_has_rx_data(struct socket *sock)
 	if (sock->ops->peek_len)
 		return sock->ops->peek_len(sock);
 
-	return skb_queue_empty(&sock->sk->sk_receive_queue);
+	return !skb_queue_empty(&sock->sk->sk_receive_queue);
 }
 
 static void vhost_net_busy_poll_try_queue(struct vhost_net *net,

base-commit: 435cbdaf9b03687498dc16fe4af8d16a977e21d0
-- 
2.50.1

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

end of thread, other threads:[~2026-11-20 12:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20  3:38 [PATCH net v2] vhost/net: Fix receive queue test in busy poll raoxu
2026-11-20  3:43 ` sashiko-bot
2026-11-20 12:03 ` Eugenio Perez Martin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.