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=MhSfxA0l; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 200035A0280 for ; Fri, 08 Aug 2025 16:03:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754661782; 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=3BBj54DuTQ9RFYnZiqd7juY3vrreugT7fNCvuLIzOxg=; b=MhSfxA0lqPddYn6GO/BckD76M41CVVX2jtG7laaCxa0YJ6n8A4f0RQ1D2iTJiTKPqgGGha MJ44RbPGkCHFoVVMuUtyf5ohmdGp3eoGEspddtq2vkk90ONqHb+5BlHtAEAvvZra5jlxZ8 RvdHdg3XIheypd/o/dop/0IlpL3hxKI= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-457-lE4DV1TjO-iiE2Ei65bkxg-1; Fri, 08 Aug 2025 10:03:01 -0400 X-MC-Unique: lE4DV1TjO-iiE2Ei65bkxg-1 X-Mimecast-MFC-AGG-ID: lE4DV1TjO-iiE2Ei65bkxg_1754661780 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 16A5D180136A for ; Fri, 8 Aug 2025 14:02:50 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.45.225.81]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F3C82195419E; Fri, 8 Aug 2025 14:02:48 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v9 30/30] packet: Add support for multi-vector packets Date: Fri, 8 Aug 2025 16:01:42 +0200 Message-ID: <20250808140142.3404325-31-lvivier@redhat.com> In-Reply-To: <20250808140142.3404325-1-lvivier@redhat.com> References: <20250808140142.3404325-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: 82Xb3wObHlMMqaF5HqL977JKUtJO7QhqoXrJJcnUDvY_1754661780 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: BGOKIAQGMGHW5STZZEYOVA6VDPDTNDFT X-Message-ID-Hash: BGOKIAQGMGHW5STZZEYOVA6VDPDTNDFT 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 packet pool was previously limited to handling packets contained within a single buffer. This patch extends the packet pool to support iovec array, allowing a single logical packet to be composed of multiple iovec. To accommodate this, the storage format within the pool is modified. For a multi-vector packet, a header entry is now stored first with iov_base = NULL and iov_len holding the number of subsequent vectors. The actual data vectors are then stored in the following pool slots. The packet_add_do() and packet_get_do() functions are updated to manage this new format for storing and retrieving packets. The pool_full() check is also adjusted to ensure there is enough space for all vectors of a new packet before adding it. Signed-off-by: Laurent Vivier --- packet.c | 50 +++++++++++++++++++++++++++++++++----------------- packet.h | 2 +- tap.c | 4 ++-- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/packet.c b/packet.c index 27693c55a138..919a6b931904 100644 --- a/packet.c +++ b/packet.c @@ -93,12 +93,13 @@ static int packet_check_range(const struct pool *p, const char *ptr, size_t len, /** * pool_full() - Is a packet pool full? * @p: Pointer to packet pool + * @data: check data can fit in the pool * - * Return: true if the pool is full, false if more packets can be added + * Return: true if the pool is full, false if data can be added */ -bool pool_full(const struct pool *p) +bool pool_full(const struct pool *p, const struct iov_tail *data) { - return p->count >= p->size; + return p->count + data->cnt + (data->cnt > 1) >= p->size; } /** @@ -111,11 +112,9 @@ bool pool_full(const struct pool *p) void packet_add_do(struct pool *p, struct iov_tail *data, const char *func, int line) { - size_t idx = p->count; - const char *start; - size_t len; + size_t idx = p->count, i, offset; - if (pool_full(p)) { + if (pool_full(p, data)) { debug("add packet index %zu to pool with size %zu, %s:%i", idx, p->size, func, line); return; @@ -124,18 +123,30 @@ void packet_add_do(struct pool *p, struct iov_tail *data, if (!iov_tail_prune(data)) return; - ASSERT(data->cnt == 1); /* we don't support iovec */ + if (data->cnt > 1) { + p->pkt[idx].iov_base = NULL; + p->pkt[idx].iov_len = data->cnt; + idx++; + } - len = data->iov[0].iov_len - data->off; - start = (char *)data->iov[0].iov_base + data->off; + offset = data->off; + for (i = 0; i < data->cnt; i++) { + const char *start; + size_t len; - if (packet_check_range(p, start, len, func, line)) - return; + len = data->iov[i].iov_len - offset; + start = (char *)data->iov[i].iov_base + offset; + offset = 0; - p->pkt[idx].iov_base = (void *)start; - p->pkt[idx].iov_len = len; + if (packet_check_range(p, start, len, func, line)) + return; - p->count++; + p->pkt[idx].iov_base = (void *)start; + p->pkt[idx].iov_len = len; + idx++; + } + + p->count = idx; } /** @@ -165,9 +176,14 @@ bool packet_get_do(const struct pool *p, size_t idx, return false; } - data->cnt = 1; + if (p->pkt[idx].iov_base) { + data->cnt = 1; + data->iov = &p->pkt[idx]; + } else { + data->cnt = p->pkt[idx].iov_len; + data->iov = &p->pkt[idx + 1]; + } data->off = 0; - data->iov = &p->pkt[idx]; for (i = 0; i < data->cnt; i++) { ASSERT_WITH_MSG(!packet_check_range(p, data->iov[i].iov_base, diff --git a/packet.h b/packet.h index e51cbd19fdc4..67dc7deb17db 100644 --- a/packet.h +++ b/packet.h @@ -37,7 +37,7 @@ void packet_add_do(struct pool *p, struct iov_tail *data, const char *func, int line); bool packet_get_do(const struct pool *p, const size_t idx, struct iov_tail *data, const char *func, int line); -bool pool_full(const struct pool *p); +bool pool_full(const struct pool *p, const struct iov_tail *data); void pool_flush(struct pool *p); #define packet_add(p, data) \ diff --git a/tap.c b/tap.c index 9fd00915bb01..95688b22fcb7 100644 --- a/tap.c +++ b/tap.c @@ -1103,14 +1103,14 @@ void tap_add_packet(struct ctx *c, struct iov_tail *data, switch (ntohs(eh->h_proto)) { case ETH_P_ARP: case ETH_P_IP: - if (pool_full(pool_tap4)) { + if (pool_full(pool_tap4, data)) { tap4_handler(c, pool_tap4, now); pool_flush(pool_tap4); } packet_add(pool_tap4, data); break; case ETH_P_IPV6: - if (pool_full(pool_tap6)) { + if (pool_full(pool_tap6, data)) { tap6_handler(c, pool_tap6, now); pool_flush(pool_tap6); } -- 2.49.0