On Fri, Nov 20, 2026 at 4:39 AM raoxu <[email protected]> wrote: > > From: Xu Rao <[email protected]> > > 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: [email protected]
Acked-by: Eugenio Pérez <[email protected]> > Signed-off-by: Xu Rao <[email protected]> > --- > 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/[email protected]/ > > 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 >
