DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
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 v3 2/7] net/virtio-user: fix packet loss with unused queue pairs
Date: Wed, 18 Nov 2026 02:19:13 +0200	[thread overview]
Message-ID: <20261118001918.990884-3-iboukris@gmail.com> (raw)
In-Reply-To: <20261118001918.990884-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). For example, with queues=2 and one Rx queue,
testpmd receives 22 of 64 flows that the kernel sends on the TAP
interface.

The TAP interface has one queue per queue pair, and the kernel picks
the queue of a packet by a hash of its flow. The driver unsets the
vhost backend of a disabled queue pair, but the TAP queue stays
attached. So the kernel still sends flows to it, and nothing reads
them.

The driver used to detach such a queue with TUNSETQUEUE. The commit
below removed that when it moved the opening of the TAP queues to
the initialization.

Detach the TAP queue of a queue pair when it is disabled, and attach
it when it is enabled. The queues after the first one are detached
when they are opened, because a queue pair is disabled until the
driver enables it. The first queue is never detached, because the
interface needs a queue.

A queue pair is also disabled for a moment when the memory table
changes. Its TAP queue is then 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>
---
v3: new patch.

 drivers/net/virtio/virtio_user/vhost_kernel.c     | 12 ++++++++++++
 drivers/net/virtio/virtio_user/vhost_kernel_tap.c | 14 ++++++++++++++
 drivers/net/virtio/virtio_user/vhost_kernel_tap.h |  4 ++++
 3 files changed, 30 insertions(+)

diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c
index 7914b517cd..5b70999393 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;
@@ -546,6 +549,12 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev *dev,
 			PMD_DRV_LOG(ERR, "fail to set backend for vhost kernel");
 			return -1;
 		}
+		/*
+		 * Detach the queue, so that the kernel sends its packets to the
+		 * other queues. The interface keeps its first queue.
+		 */
+		if (pair_idx > 0 && vhost_tap_set_queue(tapfd, false) < 0)
+			return -1;
 		dev->qp_enabled[pair_idx] = false;
 		return 0;
 	}
@@ -561,6 +570,9 @@ 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;
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


  parent reply	other threads:[~2026-11-18  0:19 UTC|newest]

Thread overview: 18+ 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   ` Isaac Boukris [this message]
2026-11-18  0:19   ` [PATCH v3 3/7] test/virtio_user: add unit test of unused queue pairs 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

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=20261118001918.990884-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox