From: Isaac Boukris <iboukris@gmail.com>
To: Maxime Coquelin <maxime.coquelin@redhat.com>,
Chenbo Xia <chenbox@nvidia.com>
Cc: dev@dpdk.org, David Marchand <david.marchand@redhat.com>,
Aman Singh <aman.deep.singh@intel.com>,
Luca Vizzarro <luca.vizzarro@arm.com>,
Patrick Robb <patrickrobb1997@gmail.com>,
Isaac Boukris <iboukris@gmail.com>,
stable@dpdk.org
Subject: [PATCH v4 2/8] net/virtio-user: fix packet loss with unused queue pairs
Date: Wed, 18 Nov 2026 10:27:46 +0200 [thread overview]
Message-ID: <20261118082752.1043794-3-iboukris@gmail.com> (raw)
In-Reply-To: <20261118082752.1043794-1-iboukris@gmail.com>
A virtio-user port on vhost-net loses received packets when the
application configures fewer Rx queues than the port has queue pairs
(the queues devarg). With queues=2 and one Rx queue, testpmd receives
22 of the 64 flows that the kernel sends on the TAP interface.
The TAP interface has one queue per queue pair, and the kernel picks
a packet's queue by a hash of its flow. The driver unsets the vhost
backend of a disabled queue pair but leaves its TAP queue attached,
so the kernel still sends flows to it and nothing reads them.
The driver detached such a queue with TUNSETQUEUE until the commit
below, which opens all the TAP queues at initialization.
Attach the TAP queue of a queue pair when the pair is enabled, and
detach it when the pair is disabled or when a later step of the
enable fails. Detach the queues after the first when they are opened.
The first one stays attached, because the interface needs a queue.
TUNSETQUEUE fails on a queue that is already in the requested state.
The existing check of qp_enabled prevents that, because the state of
the TAP queue now follows it.
A memory table change disables the active queue pairs for a moment,
so their TAP queues are detached and attached again.
Fixes: b72099be7f27 ("net/virtio-user: fix init when using existing tap")
Cc: stable@dpdk.org
Signed-off-by: Isaac Boukris <iboukris@gmail.com>
---
v4: detach the queue again when a later step of the enable fails. One comment says the rule.
v3: new patch.
drivers/net/virtio/virtio_user/vhost_kernel.c | 24 +++++++++++++++++--
.../net/virtio/virtio_user/vhost_kernel_tap.c | 14 +++++++++++
.../net/virtio/virtio_user/vhost_kernel_tap.h | 4 ++++
3 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c
index 7914b517cd..e3b0583232 100644
--- a/drivers/net/virtio/virtio_user/vhost_kernel.c
+++ b/drivers/net/virtio/virtio_user/vhost_kernel.c
@@ -455,6 +455,9 @@ vhost_kernel_setup(struct virtio_user_dev *dev)
data->tapfds[i] = vhost_tap_open(dev->ifname, r_flags, true);
if (data->tapfds[i] < 0)
goto err_tapfds;
+ /* The queue stays detached until its queue pair is enabled. */
+ if (vhost_tap_set_queue(data->tapfds[i], false) < 0)
+ goto err_tapfds;
}
dev->backend_data = data;
@@ -541,11 +544,20 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev *dev,
vhostfd = data->vhostfds[pair_idx];
tapfd = data->tapfds[pair_idx];
+ /*
+ * A queue pair's TAP queue is attached only while the pair is enabled,
+ * so the kernel sends packets only to queues in use. The first queue
+ * stays attached, because the interface needs one. TUNSETQUEUE fails
+ * on a queue already in the requested state, which the check above
+ * prevents.
+ */
if (!enable) {
if (vhost_kernel_set_backend(vhostfd, -1) < 0) {
PMD_DRV_LOG(ERR, "fail to set backend for vhost kernel");
return -1;
}
+ if (pair_idx > 0 && vhost_tap_set_queue(tapfd, false) < 0)
+ return -1;
dev->qp_enabled[pair_idx] = false;
return 0;
}
@@ -561,18 +573,26 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev *dev,
vhost_tap_set_mac(data->tapfds[pair_idx], dev->mac_addr) < 0)
return -1;
+ if (pair_idx > 0 && vhost_tap_set_queue(tapfd, true) < 0)
+ return -1;
+
if (vhost_kernel_tap_setup(tapfd, hdr_size, dev->features) < 0) {
PMD_DRV_LOG(ERR, "fail to setup tap for vhost kernel");
- return -1;
+ goto err_detach;
}
if (vhost_kernel_set_backend(vhostfd, tapfd) < 0) {
PMD_DRV_LOG(ERR, "fail to set backend for vhost kernel");
- return -1;
+ goto err_detach;
}
dev->qp_enabled[pair_idx] = true;
return 0;
+
+err_detach:
+ if (pair_idx > 0)
+ vhost_tap_set_queue(tapfd, false);
+ return -1;
}
static int
diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c
index da55aba505..bfdc6f46c0 100644
--- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c
+++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c
@@ -126,6 +126,20 @@ vhost_tap_set_mac(int tapfd, uint8_t *mac)
return 0;
}
+int
+vhost_tap_set_queue(int tapfd, bool attach)
+{
+ struct ifreq ifr;
+
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_flags = attach ? IFF_ATTACH_QUEUE : IFF_DETACH_QUEUE;
+ if (ioctl(tapfd, TUNSETQUEUE, (void *)&ifr) == -1) {
+ PMD_DRV_LOG(ERR, "TUNSETQUEUE failed: %s", strerror(errno));
+ return -1;
+ }
+ return 0;
+}
+
static int
vhost_kernel_tap_set_offload(int fd, uint64_t features)
{
diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.h b/drivers/net/virtio/virtio_user/vhost_kernel_tap.h
index 1e026d7488..05fa8a9244 100644
--- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.h
+++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.h
@@ -16,12 +16,15 @@
#define TUNSETSNDBUF _IOW('T', 212, int)
#define TUNGETVNETHDRSZ _IOR('T', 215, int)
#define TUNSETVNETHDRSZ _IOW('T', 216, int)
+#define TUNSETQUEUE _IOW('T', 217, int)
/* TUNSETIFF ifr flags */
#define IFF_TAP 0x0002
#define IFF_NO_PI 0x1000
#define IFF_VNET_HDR 0x4000
#define IFF_MULTI_QUEUE 0x0100
+#define IFF_ATTACH_QUEUE 0x0200
+#define IFF_DETACH_QUEUE 0x0400
#define IFF_NAPI 0x0010
/* Features for GSO (TUNSETOFFLOAD). */
@@ -41,5 +44,6 @@ int vhost_tap_open(const char *ifname, unsigned int r_flags, bool multi_queue);
int vhost_tap_get_name(int tapfd, char **ifname);
int vhost_tap_get_flags(int tapfd, unsigned int *tap_flags);
int vhost_tap_set_mac(int tapfd, uint8_t *mac);
+int vhost_tap_set_queue(int tapfd, bool attach);
#endif
--
2.56.1
next prev parent reply other threads:[~2026-11-18 8:28 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 12:43 [PATCH 0/1] net/virtio: fix Rx interrupts with MSI-X Isaac Boukris
2026-11-17 12:43 ` [PATCH 1/1] net/virtio: fix Rx interrupt setup " Isaac Boukris
2026-11-17 14:29 ` David Marchand
2026-11-17 19:51 ` Isaac Boukris
2026-11-17 21:59 ` [PATCH v2 0/5] net/virtio: fix Rx interrupts " Isaac Boukris
2026-11-17 21:59 ` [PATCH v2 1/5] net/virtio: fix Rx interrupt setup " Isaac Boukris
2026-11-17 21:59 ` [PATCH v2 2/5] test/virtio_user: add unit test of Rx interrupts Isaac Boukris
2026-11-17 21:59 ` [PATCH v2 3/5] app/testpmd: add Rx queue interrupts option Isaac Boukris
2026-11-17 22:00 ` [PATCH v2 4/5] dts: support virtio PCI ports Isaac Boukris
2026-11-17 22:00 ` [PATCH v2 5/5] dts: add Rx interrupt test suite Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 0/7] net/virtio: fix Rx interrupts with MSI-X Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 1/7] net/virtio: fix Rx interrupt setup " Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 2/7] net/virtio-user: fix packet loss with unused queue pairs Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 3/7] test/virtio_user: add unit test of " Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 4/7] test/virtio_user: add unit test of Rx interrupts Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 5/7] app/testpmd: add Rx queue interrupts option Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 6/7] dts: support virtio PCI ports Isaac Boukris
2026-11-18 0:19 ` [PATCH v3 7/7] dts: add Rx interrupt test suite Isaac Boukris
2026-11-18 8:27 ` [PATCH v4 0/8] net/virtio: fix Rx interrupts with MSI-X Isaac Boukris
2026-11-18 8:27 ` [PATCH v4 1/8] net/virtio: fix Rx interrupt setup " Isaac Boukris
2026-11-18 8:27 ` Isaac Boukris [this message]
2026-11-18 8:27 ` [PATCH v4 3/8] net/virtio-user: fix unaligned reads of control commands Isaac Boukris
2026-11-18 8:27 ` [PATCH v4 4/8] test/virtio_user: add unit test of unused queue pairs Isaac Boukris
2026-11-18 8:27 ` [PATCH v4 5/8] test/virtio_user: add unit test of Rx interrupts Isaac Boukris
2026-11-18 8:27 ` [PATCH v4 6/8] app/testpmd: add Rx queue interrupts option Isaac Boukris
2026-11-18 8:27 ` [PATCH v4 7/8] dts: support virtio PCI ports Isaac Boukris
2026-11-18 8:27 ` [PATCH v4 8/8] dts: add Rx interrupt test suite Isaac Boukris
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118082752.1043794-3-iboukris@gmail.com \
--to=iboukris@gmail.com \
--cc=aman.deep.singh@intel.com \
--cc=chenbox@nvidia.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=luca.vizzarro@arm.com \
--cc=maxime.coquelin@redhat.com \
--cc=patrickrobb1997@gmail.com \
--cc=stable@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.