public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Laurent Vivier <lvivier@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH v2 01/10] tap: Convert packet pools to per-queue-pair arrays for multiqueue
Date: Mon, 3 Aug 2026 15:41:58 +1000	[thread overview]
Message-ID: <anAqGF-yMUxE7BeO@zatzit> (raw)
In-Reply-To: <20260731162329.3552800-2-lvivier@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 9823 bytes --]

On Fri, Jul 31, 2026 at 06:23:20PM +0200, Laurent Vivier wrote:
> Convert the global pool_tap4 and pool_tap6 packet pools from single
> pools to arrays of pools, one for each queue pair. This change is
> necessary to support multiqueue operation in vhost-user mode, where
> multiple queue pairs may be processing packets concurrently.
> 
> The pool storage structures (pool_tap4_storage and pool_tap6_storage)
> are now arrays of VHOST_USER_MAX_VQS/2 elements, with corresponding
> pointer arrays (pool_tap4 and pool_tap6) for accessing them.
> 
> Add a qpair parameter to tap_flush_pools() so it flushes the correct
> pool.  tap4_handler() and tap6_handler() now use the qpair they
> already receive to index into the pool arrays.  Add bounds checking
> assertions in tap_handler() and tap_add_packet().
> 
> In passt and pasta modes, all operations use QPAIR_DEFAULT. In
> vhost-user mode, the queue pair is derived from the virtqueue index
> via QPAIR_FROM_QUEUE().
> 
> All pools within the array share the same buffer pointer:
> - In vhost-user mode: Points to the vhost-user memory structure, which
>   is safe as packet data remains in guest memory and pools only track
>   iovecs
> - In passt/pasta mode: Points to pkt_buf, which is safe as only queue
>   pair 0 is used
> 
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  tap.c       | 77 ++++++++++++++++++++++++++++++-----------------------
>  tap.h       |  2 +-
>  vu_common.c |  2 +-
>  3 files changed, 46 insertions(+), 35 deletions(-)
> 
> diff --git a/tap.c b/tap.c
> index 029888e32db5..6bba436f148f 100644
> --- a/tap.c
> +++ b/tap.c
> @@ -94,9 +94,13 @@ CHECK_FRAME_LEN(L2_MAX_LEN_VU);
>  	DIV_ROUND_UP(sizeof(pkt_buf),					\
>  		     ETH_HLEN + sizeof(struct ipv6hdr) + sizeof(struct udphdr))
>  
> -/* IPv4 (plus ARP) and IPv6 message batches from tap/guest to IP handlers */
> -static PACKET_POOL_NOINIT(pool_tap4, TAP_MSGS_IP4);
> -static PACKET_POOL_NOINIT(pool_tap6, TAP_MSGS_IP6);
> +/* IPv4 (plus ARP) and IPv6 message batches from tap/guest to IP handlers
> + * One pool per queue pair for multiqueue support
> + */
> +static PACKET_POOL_DECL(pool_tap4, TAP_MSGS_IP4) pool_tap4_storage[VHOST_USER_MAX_VQS / 2];
> +static struct pool *pool_tap4[VHOST_USER_MAX_VQS / 2];
> +static PACKET_POOL_DECL(pool_tap6, TAP_MSGS_IP6) pool_tap6_storage[VHOST_USER_MAX_VQS / 2];
> +static struct pool *pool_tap6[VHOST_USER_MAX_VQS / 2];
>  
>  #define TAP_SEQS		128 /* Different L4 tuples in one batch */
>  
> @@ -702,12 +706,12 @@ static int tap4_handler(struct ctx *c, unsigned int qpair,
>  	unsigned int i, j, seq_count;
>  	struct tap4_l4_t *seq;
>  
> -	if (!c->ifi4 || !pool_tap4->count)
> -		return pool_tap4->count;
> +	if (!c->ifi4 || !pool_tap4[qpair]->count)
> +		return pool_tap4[qpair]->count;
>  
>  	i = 0;
>  resume:
> -	for (seq_count = 0, seq = NULL; i < pool_tap4->count; i++) {
> +	for (seq_count = 0, seq = NULL; i < pool_tap4[qpair]->count; i++) {
>  		struct iovec trim_iov[UIO_MAXIOV];
>  		size_t l3len, hlen, l4len, check;
>  		struct ethhdr eh_storage;
> @@ -718,7 +722,7 @@ resume:
>  		struct iov_tail data;
>  		struct iphdr *iph;
>  
> -		if (!packet_get(pool_tap4, i, &data))
> +		if (!packet_get(pool_tap4[qpair], i, &data))
>  			continue;
>  
>  		eh = IOV_PEEK_HEADER(&data, eh_storage);
> @@ -801,7 +805,7 @@ resume:
>  		if (iph->protocol == IPPROTO_UDP) {
>  			struct iov_tail eh_data;
>  
> -			packet_get(pool_tap4, i, &eh_data);
> +			packet_get(pool_tap4[qpair], i, &eh_data);
>  			if (dhcp(c, qpair, &eh_data))
>  				continue;
>  		}
> @@ -832,7 +836,7 @@ resume:
>  			goto append;
>  
>  		if (seq_count == TAP_SEQS)
> -			break;	/* Resume after flushing if i < pool_tap4->count */
> +			break;	/* Resume after flushing if i < pool_tap4[qpair]->count */
>  
>  		for (seq = tap4_l4 + seq_count - 1; seq >= tap4_l4; seq--) {
>  			if (L4_MATCH(iph, uh, seq)) {
> @@ -878,10 +882,10 @@ append:
>  		}
>  	}
>  
> -	if (i < pool_tap4->count)
> +	if (i < pool_tap4[qpair]->count)
>  		goto resume;
>  
> -	return pool_tap4->count;
> +	return pool_tap4[qpair]->count;
>  }
>  
>  #define IPV6_NH_OPT(nh)							\
> @@ -950,12 +954,12 @@ static int tap6_handler(struct ctx *c, unsigned int qpair,
>  	unsigned int i, j, seq_count = 0;
>  	struct tap6_l4_t *seq;
>  
> -	if (!c->ifi6 || !pool_tap6->count)
> -		return pool_tap6->count;
> +	if (!c->ifi6 || !pool_tap6[qpair]->count)
> +		return pool_tap6[qpair]->count;
>  
>  	i = 0;
>  resume:
> -	for (seq_count = 0, seq = NULL; i < pool_tap6->count; i++) {
> +	for (seq_count = 0, seq = NULL; i < pool_tap6[qpair]->count; i++) {
>  		size_t l4len, plen, check;
>  		struct in6_addr *saddr, *daddr;
>  		struct ipv6hdr ip6h_storage;
> @@ -967,7 +971,7 @@ resume:
>  		struct ipv6hdr *ip6h;
>  		uint8_t proto;
>  
> -		if (!packet_get(pool_tap6, i, &data))
> +		if (!packet_get(pool_tap6[qpair], i, &data))
>  			return -1;
>  
>  		eh = IOV_REMOVE_HEADER(&data, eh_storage);
> @@ -1082,7 +1086,7 @@ resume:
>  			goto append;
>  
>  		if (seq_count == TAP_SEQS)
> -			break;	/* Resume after flushing if i < pool_tap6->count */
> +			break;	/* Resume after flushing if i < pool_tap6[qpair]->count */
>  
>  		for (seq = tap6_l4 + seq_count - 1; seq >= tap6_l4; seq--) {
>  			if (L4_MATCH(ip6h, proto, uh, seq)) {
> @@ -1129,19 +1133,19 @@ append:
>  		}
>  	}
>  
> -	if (i < pool_tap6->count)
> +	if (i < pool_tap6[qpair]->count)
>  		goto resume;
>  
> -	return pool_tap6->count;
> +	return pool_tap6[qpair]->count;
>  }
>  
>  /**
> - * tap_flush_pools() - Flush both IPv4 and IPv6 packet pools
> + * tap_flush_pools() - Flush both IPv4 and IPv6 packet pools for a given qpair
>   */
> -void tap_flush_pools(void)
> +void tap_flush_pools(unsigned int qpair)
>  {
> -	pool_flush(pool_tap4);
> -	pool_flush(pool_tap6);
> +	pool_flush(pool_tap4[qpair]);
> +	pool_flush(pool_tap6[qpair]);
>  }
>  
>  /**
> @@ -1152,6 +1156,7 @@ void tap_flush_pools(void)
>   */
>  void tap_handler(struct ctx *c, unsigned int qpair, const struct timespec *now)
>  {
> +	assert(qpair < VHOST_USER_MAX_VQS / 2);
>  	tap4_handler(c, qpair, now);
>  	tap6_handler(c, qpair, now);
>  }
> @@ -1186,21 +1191,23 @@ void tap_add_packet(struct ctx *c, unsigned int qpair, struct iov_tail *data,
>  		proto_update_l2_buf(c->guest_mac);
>  	}
>  
> +	assert(qpair < VHOST_USER_MAX_VQS / 2);
> +
>  	switch (ntohs(eh->h_proto)) {
>  	case ETH_P_ARP:
>  	case ETH_P_IP:
> -		if (!pool_can_fit(pool_tap4, data)) {
> +		if (!pool_can_fit(pool_tap4[qpair], data)) {
>  			tap4_handler(c, qpair, now);
> -			pool_flush(pool_tap4);
> +			pool_flush(pool_tap4[qpair]);
>  		}
> -		packet_add(pool_tap4, data);
> +		packet_add(pool_tap4[qpair], data);
>  		break;
>  	case ETH_P_IPV6:
> -		if (!pool_can_fit(pool_tap6, data)) {
> +		if (!pool_can_fit(pool_tap6[qpair], data)) {
>  			tap6_handler(c, qpair, now);
> -			pool_flush(pool_tap6);
> +			pool_flush(pool_tap6[qpair]);
>  		}
> -		packet_add(pool_tap6, data);
> +		packet_add(pool_tap6[qpair], data);
>  		break;
>  	default:
>  		break;
> @@ -1238,7 +1245,7 @@ static void tap_passt_input(struct ctx *c, const struct timespec *now)
>  	ssize_t n;
>  	char *p;
>  
> -	tap_flush_pools();
> +	tap_flush_pools(QPAIR_DEFAULT);
>  
>  	if (partial_len) {
>  		/* We have a partial frame from an earlier pass.  Move it to the
> @@ -1321,7 +1328,7 @@ static void tap_pasta_input(struct ctx *c, const struct timespec *now)
>  {
>  	ssize_t n, len;
>  
> -	tap_flush_pools();
> +	tap_flush_pools(QPAIR_DEFAULT);
>  
>  	for (n = 0;
>  	     n <= (ssize_t)(sizeof(pkt_buf) - L2_MAX_LEN_PASTA);
> @@ -1586,10 +1593,14 @@ static void tap_sock_tun_init(struct ctx *c)
>   */
>  static void tap_sock_update_pool(void *base, size_t size)
>  {
> -	int i;
> +	unsigned int i;
>  
> -	pool_tap4_storage = PACKET_INIT(pool_tap4, TAP_MSGS_IP4, base, size);
> -	pool_tap6_storage = PACKET_INIT(pool_tap6, TAP_MSGS_IP6, base, size);
> +	for (i = 0; i < VHOST_USER_MAX_VQS / 2; i++) {
> +		pool_tap4_storage[i] = PACKET_INIT(pool_tap4, TAP_MSGS_IP4, base, size);
> +		pool_tap4[i] = (struct pool *)&pool_tap4_storage[i];
> +		pool_tap6_storage[i] = PACKET_INIT(pool_tap6, TAP_MSGS_IP6, base, size);
> +		pool_tap6[i] = (struct pool *)&pool_tap6_storage[i];
> +	}
>  
>  	for (i = 0; i < TAP_SEQS; i++) {
>  		tap4_l4[i].p = PACKET_INIT(pool_l4, UIO_MAXIOV, base, size);
> diff --git a/tap.h b/tap.h
> index 0f8e98fc5f84..7d77e071ba49 100644
> --- a/tap.h
> +++ b/tap.h
> @@ -121,7 +121,7 @@ void tap_handler_passt(struct ctx *c, uint32_t events,
>  int tap_sock_unix_open(char *sock_path);
>  void tap_sock_reset(struct ctx *c);
>  void tap_backend_init(struct ctx *c);
> -void tap_flush_pools(void);
> +void tap_flush_pools(unsigned int qpair);
>  void tap_handler(struct ctx *c, unsigned int qpair, const struct timespec *now);
>  void tap_add_packet(struct ctx *c, unsigned int qpair, struct iov_tail *data,
>  		    const struct timespec *now);
> diff --git a/vu_common.c b/vu_common.c
> index 7239cb42f38b..0cd19b36737d 100644
> --- a/vu_common.c
> +++ b/vu_common.c
> @@ -177,7 +177,7 @@ static void vu_handle_tx(struct vu_dev *vdev, int index,
>  
>  	assert(QPAIR_IS_FROMGUEST(index));
>  
> -	tap_flush_pools();
> +	tap_flush_pools(QPAIR_DEFAULT);
>  
>  	count = 0;
>  	out_sg_count = 0;
> -- 
> 2.54.0
> 

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2026-08-03  5:43 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-31 16:23 [PATCH v2 00/10] multithreading: Prepare data structures for concurrent queue pair workers Laurent Vivier
2026-07-31 16:23 ` [PATCH v2 01/10] tap: Convert packet pools to per-queue-pair arrays for multiqueue Laurent Vivier
2026-08-03  5:41   ` David Gibson [this message]
2026-07-31 16:23 ` [PATCH v2 02/10] tap: Make L4 sequence pools per-qpair for thread safety Laurent Vivier
2026-08-03  5:43   ` David Gibson
2026-08-03  5:55     ` David Gibson
2026-07-31 16:23 ` [PATCH v2 03/10] tcp: Make static buffers stack-local " Laurent Vivier
2026-08-03  5:59   ` David Gibson
2026-07-31 16:23 ` [PATCH v2 04/10] udp_vu: Make virtqueue " Laurent Vivier
2026-08-03  6:00   ` David Gibson
2026-07-31 16:23 ` [PATCH v2 05/10] flow: Make flow timer per-caller " Laurent Vivier
2026-08-03  6:11   ` David Gibson
2026-08-03  6:35     ` David Gibson
2026-07-31 16:23 ` [PATCH v2 06/10] tcp: Make TCP timer state per-caller and guard global tasks Laurent Vivier
2026-08-03  6:40   ` David Gibson
2026-07-31 16:23 ` [PATCH v2 07/10] tcp: Protect init socket pools with mutex for thread safety Laurent Vivier
2026-08-03  6:53   ` David Gibson
2026-07-31 16:23 ` [PATCH v2 08/10] tcp: Extract tcp_timer_epoll_add() helper Laurent Vivier
2026-08-03  6:54   ` David Gibson
2026-07-31 16:23 ` [PATCH v2 09/10] flow: Add locking, per-qpair filtering, and intermediate state handling Laurent Vivier
2026-08-03  9:58   ` David Gibson
2026-07-31 16:23 ` [PATCH v2 10/10] flow: Add lazy, lock-free flow migration between queue pairs Laurent Vivier

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=anAqGF-yMUxE7BeO@zatzit \
    --to=david@gibson.dropbear.id.au \
    --cc=lvivier@redhat.com \
    --cc=passt-dev@passt.top \
    /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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).