From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=McOzgJwz; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 500145A0272 for ; Tue, 16 Jun 2026 19:11:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781629859; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oi4IoqJc8LIcopBXPiOtJ5+bZyD7QvAehBBDMNiqCO8=; b=McOzgJwz3MujKVkrHQeUUOyUBKk1p0eC6TE1rew664gCqPh64AklLhQx3DmfMR7t6i+7L9 DwLppjfN4pPpccqn8s02ZxW/rv9Cfy2rHuRtFaa4XWvsNAXF8fuqOnXr7WGm240G6UCrJn goUWb3mIgd729jjEsmWUvuDCgDzoN3A= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-202-OI4VF9E_N5SFGOV5oQ9BRw-1; Tue, 16 Jun 2026 13:10:57 -0400 X-MC-Unique: OI4VF9E_N5SFGOV5oQ9BRw-1 X-Mimecast-MFC-AGG-ID: OI4VF9E_N5SFGOV5oQ9BRw_1781629857 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EB71F19560B1 for ; Tue, 16 Jun 2026 17:10:56 +0000 (UTC) Received: from lenovo-t14s.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 24103195419F; Tue, 16 Jun 2026 17:10:55 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 2/8] tap: Make L4 sequence pools per-qpair for thread safety Date: Tue, 16 Jun 2026 19:10:46 +0200 Message-ID: <20260616171052.3785909-3-lvivier@redhat.com> In-Reply-To: <20260616171052.3785909-1-lvivier@redhat.com> References: <20260616171052.3785909-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: bKEqL6G1WKF5xODp6UYO5YIDSg8Hyk2S8ZkHMyOxXxw_1781629857 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: ZE2KWFCO6FB5BY2JI54OEOFWGL553BK3 X-Message-ID-Hash: ZE2KWFCO6FB5BY2JI54OEOFWGL553BK3 X-MailFrom: lvivier@redhat.com 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: Laurent Vivier 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: The L4 sequence arrays tap4_l4[] and tap6_l4[] are used to batch packets with the same L4 tuple within a single tap_handler() call. They are global, but tap_handler() can be called concurrently from different worker threads with different qpairs in vhost-user mode. Make these arrays per-qpair by adding a VHOST_USER_MAX_VQS/2 first dimension, indexed by the qpair parameter already available in tap4_handler() and tap6_handler(). Update tap_sock_update_pool() to initialize all qpair*seq entries. Signed-off-by: Laurent Vivier --- tap.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/tap.c b/tap.c index 80912372e216..659df9d560d3 100644 --- a/tap.c +++ b/tap.c @@ -606,7 +606,7 @@ static struct tap4_l4_t { struct in_addr daddr; struct pool_l4_t p; -} tap4_l4[TAP_SEQS /* Arbitrary: TAP_MSGS in theory, so limit in users */]; +} tap4_l4[VHOST_USER_MAX_VQS / 2][TAP_SEQS /* Arbitrary: TAP_MSGS in theory, so limit in users */]; /** * struct l4_seq6_t - Message sequence for one protocol handler call, IPv6 @@ -633,7 +633,7 @@ static struct tap6_l4_t { uint8_t hop_limit; struct pool_l4_t p; -} tap6_l4[TAP_SEQS /* Arbitrary: TAP_MSGS in theory, so limit in users */]; +} tap6_l4[VHOST_USER_MAX_VQS / 2][TAP_SEQS /* Arbitrary: TAP_MSGS in theory, so limit in users */]; /** * tap_packet_debug() - Print debug message for packet(s) from guest/tap @@ -841,7 +841,7 @@ resume: if (seq_count == TAP_SEQS) break; /* Resume after flushing if i < pool_tap4[qpair]->count */ - for (seq = tap4_l4 + seq_count - 1; seq >= tap4_l4; seq--) { + for (seq = tap4_l4[qpair] + seq_count - 1; seq >= tap4_l4[qpair]; seq--) { if (L4_MATCH(iph, uh, seq)) { if (seq->p.count >= UIO_MAXIOV) seq = NULL; @@ -849,8 +849,8 @@ resume: } } - if (!seq || seq < tap4_l4) { - seq = tap4_l4 + seq_count++; + if (!seq || seq < tap4_l4[qpair]) { + seq = tap4_l4[qpair] + seq_count++; L4_SET(iph, uh, seq); pool_flush((struct pool *)&seq->p); } @@ -862,7 +862,7 @@ append: packet_add((struct pool *)&seq->p, &data); } - for (j = 0, seq = tap4_l4; j < seq_count; j++, seq++) { + for (j = 0, seq = tap4_l4[qpair]; j < seq_count; j++, seq++) { const struct pool *p = (const struct pool *)&seq->p; size_t k; @@ -1089,7 +1089,7 @@ resume: if (seq_count == TAP_SEQS) break; /* Resume after flushing if i < pool_tap6[qpair]->count */ - for (seq = tap6_l4 + seq_count - 1; seq >= tap6_l4; seq--) { + for (seq = tap6_l4[qpair] + seq_count - 1; seq >= tap6_l4[qpair]; seq--) { if (L4_MATCH(ip6h, proto, uh, seq)) { if (seq->p.count >= UIO_MAXIOV) seq = NULL; @@ -1097,8 +1097,8 @@ resume: } } - if (!seq || seq < tap6_l4) { - seq = tap6_l4 + seq_count++; + if (!seq || seq < tap6_l4[qpair]) { + seq = tap6_l4[qpair] + seq_count++; L4_SET(ip6h, proto, uh, seq); pool_flush((struct pool *)&seq->p); } @@ -1110,7 +1110,7 @@ append: packet_add((struct pool *)&seq->p, &data); } - for (j = 0, seq = tap6_l4; j < seq_count; j++, seq++) { + for (j = 0, seq = tap6_l4[qpair]; j < seq_count; j++, seq++) { const struct pool *p = (const struct pool *)&seq->p; size_t k; @@ -1607,9 +1607,15 @@ static void tap_sock_update_pool(void *base, size_t 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); - tap6_l4[i].p = PACKET_INIT(pool_l4, UIO_MAXIOV, base, size); + for (i = 0; i < VHOST_USER_MAX_VQS / 2; i++) { + unsigned int j; + + for (j = 0; j < TAP_SEQS; j++) { + tap4_l4[i][j].p = PACKET_INIT(pool_l4, UIO_MAXIOV, + base, size); + tap6_l4[i][j].p = PACKET_INIT(pool_l4, UIO_MAXIOV, + base, size); + } } } -- 2.54.0