From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202512 header.b=HmwDm4LS; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id AF19D5A004E for ; Tue, 06 Jan 2026 00:32:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1767655918; bh=vlD5kOM6V4WxjZ+Clb8I/QVa6fx+2nlHvQvDpYxXeiI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HmwDm4LSRJkWkwEvFFAtLW+0qrC99pV2nO+DQg1x+EwjZ7uL0DVK2p5gdL9RGDxVn vGtZPOBeWUWdHPO3dYY+WARoG5GgTNcvs02kGhbMXdp4n06uec8VDNEmvHmV+6+7zu SFWqgUNVXPTb++MSnIoWV1+AC9bXiJngkJcGGcxpyGQaUD9DE1Cf51g+nqKx71jd/x YB4jXAI2G/rWxPFF6WhtrnZ9zuk2ccc6qNP3bdqUi/e3m5TtbTA9LXALCcxULSKB+q dT/enOWydQGRvxPSUxS9LdHDFwcKj05sQxySpWUfKDBrrJazRHbAh+1XAU4GKKBOEn dsCcgf+ZkKvXQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4dlVv23fNPz4wH2; Tue, 06 Jan 2026 10:31:58 +1100 (AEDT) Date: Tue, 6 Jan 2026 10:28:58 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH] udp_vu: Discard datagrams when RX virtqueue is not usable Message-ID: References: <20260105145016.394828-1-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="PQdzeMO6NKow+s4E" Content-Disposition: inline In-Reply-To: <20260105145016.394828-1-lvivier@redhat.com> Message-ID-Hash: JTNDLADC63KLJUP2TO623ZEYSTIRR4YF X-Message-ID-Hash: JTNDLADC63KLJUP2TO623ZEYSTIRR4YF X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --PQdzeMO6NKow+s4E Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jan 05, 2026 at 03:50:16PM +0100, Laurent Vivier wrote: > During vhost-user device initialization, UDP datagrams may arrive on > listening sockets before the guest has enabled the RX virtqueue. >=20 > When this happens, udp_vu_sock_recv() returns 0 without consuming > the datagram from the socket. The caller, udp_sock_fwd(), uses a > while loop with udp_peek_addr() to process pending datagrams. Since > the datagram remains in the socket buffer, udp_peek_addr() keeps > returning data available, causing a busy loop with 100% CPU usage. >=20 > Add an early check for virtqueue readiness in udp_vu_sock_to_tap(), > mirroring tcp_vu_data_from_sock(). When the queue is not enabled or > not started, explicitly discard the datagram with recvmsg() and > return. The caller will drain remaining datagrams through repeated > calls. >=20 > Fixes: 28997fcb29b5 ("vhost-user: add vhost-user") > Link: https://bugs.passt.top/show_bug.cgi?id=3D185 > Signed-off-by: Laurent Vivier My only concern here is that this will only consume a single datagram, whereas it looks like the loop could consume multiple datagrams. I'm guessing something higher up will keep calling this until the queue is empty, but I'm not certain. Otherwise LGTM. > --- > udp_vu.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) >=20 > diff --git a/udp_vu.c b/udp_vu.c > index c30dcf97698f..67f4ee619bfb 100644 > --- a/udp_vu.c > +++ b/udp_vu.c > @@ -211,6 +211,17 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s, = int n, flow_sidx_t tosidx) > struct vu_virtq *vq =3D &vdev->vq[VHOST_USER_RX_QUEUE]; > int i; > =20 > + if (!vu_queue_enabled(vq) || !vu_queue_started(vq)) { > + struct msghdr msg =3D { 0 }; > + > + debug("Got UDP packet, but RX virtqueue not usable yet"); > + > + if (recvmsg(s, &msg, MSG_DONTWAIT) < 0) > + debug_perror("Failed to discard datagram"); > + > + return; > + } > + > for (i =3D 0; i < n; i++) { > ssize_t dlen; > int iov_used; > --=20 > 2.52.0 >=20 --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --PQdzeMO6NKow+s4E Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmlcSI8ACgkQzQJF27ox 2GfHaQ//WR+lRep+rddJHnZD6vxoQEhASZTsVjuZ6V2LPqaETLzW9+Y0jtAf+lzH sGjweGiBqms2XgMvPFUP9Utf7dQtWYiJXiMJus7QeoVd8mfw7YO3oDLRjsVlpLYu k4pLdCYAqFrrPQURHaMVEeVKwNI6EkXxWkOSs64R8Pi1wuv8RKVsBkHdPLjfi8EM vmE7lP+gnID0+u6ofqnR5jvTOn0TDj2qRMHf6bd3tBnqHUZ/yyEtGYr49/w1I74N 6wSlBoy2uAaBNMes7HbyfmLIuHCVG2ve+mXoMWDG3zLov3p30I6YYt1Ka5557CTJ yJbzL1Q6g802KnxbcrtK64W5WqTBuNFsbgcAeSBOCUi617lapL8CCK+7HM2+3AGz fTUys4aM+rBZtngKgUhl2ywIoCeJx/89/5rtxJahKmmyfCYBJE9w0SfomlmJp/hg q3KEdF1DaiUAkMNyl6V7R0FAMk1Mo61qYtSiTjZa6bphIwMxYN9H1h6C455xbUBZ euIoNbkzTqR3uMnt7b8tkdY8x8Bobvkh6xK3tZZRTReZ+wnXigYbzNICWtGm97KN BLkuvYq/3ZpoLatqhslUp2uV3z4A7KAUvcAfjxBeYOHja/MkEtEjx7vb7e7cSWht fBr9p8+Cvst7Lnj8YX5odX/zY7Q0hkH67JEkKMvBWZn6sWbAv+o= =ibIM -----END PGP SIGNATURE----- --PQdzeMO6NKow+s4E--