From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202502 header.b=kMtnEfIN; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 4A87D5A0272 for ; Wed, 12 Mar 2025 04:07:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202502; t=1741748820; bh=4R2qohKGzdDRRsv3gDzcAgBnvj8yX5zCmaCmb07J4lM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kMtnEfINoYNJnaFZRjugj7mddGG6RzKU4FDzCKdPOxeFqvt6BUFF0BdilPZrSGs7C UXHqB7oUluzetf4aPE9zLeFlgJthQOssrhj5os6xcDVzweeAigesbJ3giNUDBqXfwZ Rettsq/8YLB4yDHUfQwUw1hn+llZ9YNiKoZ77cc/hJCw9uShVfpz7mRjz+TVzjnJSp /fOtnUshK/lT8fqqiT5CvrmFHn9n/Ba6fNdG7Gk5UL+Y4YewePrvngtxSlJG+3lZEk tdnmMA2JGbpalKHzMNIGiqnBR98FmIs20UQoyTkqQqSm+6FRtc5QecDCWYOjZbvhbM T6rWLnP8vriUw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ZCFsc5Vyxz4xGR; Wed, 12 Mar 2025 14:07:00 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v2 5/9] packet: Remove redundant TAP_BUF_BYTES define Date: Wed, 12 Mar 2025 13:18:35 +1100 Message-ID: <20250312021839.2405877-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250312021839.2405877-1-david@gibson.dropbear.id.au> References: <20250312021839.2405877-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: P3DPY2PNHUJJ2RP5CN7LRHD7KC4KPCYV X-Message-ID-Hash: P3DPY2PNHUJJ2RP5CN7LRHD7KC4KPCYV X-MailFrom: dgibson@gandalf.ozlabs.org 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: David Gibson 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: Currently we define both TAP_BUF_BYTES and PKT_BUF_BYTES as essentially the same thing. They'll be different only if TAP_BUF_BYTES is negative, which makes no sense. So, remove TAP_BUF_BYTES and just use PKT_BUF_BYTES. In addition, most places we use this to just mean the size of the main packet buffer (pkt_buf) for which we can just directly use sizeof. Signed-off-by: David Gibson --- passt.c | 2 +- passt.h | 5 ++--- tap.c | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/passt.c b/passt.c index 0bd2a292..cd067728 100644 --- a/passt.c +++ b/passt.c @@ -223,7 +223,7 @@ int main(int argc, char **argv) if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) die_perror("Couldn't set disposition for SIGPIPE"); - madvise(pkt_buf, TAP_BUF_BYTES, MADV_HUGEPAGE); + madvise(pkt_buf, sizeof(pkt_buf), MADV_HUGEPAGE); c.epollfd = epoll_create1(EPOLL_CLOEXEC); if (c.epollfd == -1) diff --git a/passt.h b/passt.h index 28d13892..6b248051 100644 --- a/passt.h +++ b/passt.h @@ -69,12 +69,11 @@ union epoll_ref { static_assert(sizeof(union epoll_ref) <= sizeof(union epoll_data), "epoll_ref must have same size as epoll_data"); -#define TAP_BUF_BYTES \ +#define PKT_BUF_BYTES \ ROUND_DOWN(((ETH_MAX_MTU + sizeof(uint32_t)) * 128), PAGE_SIZE) #define TAP_MSGS \ - DIV_ROUND_UP(TAP_BUF_BYTES, ETH_ZLEN - 2 * ETH_ALEN + sizeof(uint32_t)) + DIV_ROUND_UP(PKT_BUF_BYTES, ETH_ZLEN - 2 * ETH_ALEN + sizeof(uint32_t)) -#define PKT_BUF_BYTES MAX(TAP_BUF_BYTES, 0) extern char pkt_buf [PKT_BUF_BYTES]; extern char *epoll_type_str[]; diff --git a/tap.c b/tap.c index 4541f51d..fb306e75 100644 --- a/tap.c +++ b/tap.c @@ -1080,7 +1080,7 @@ static void tap_passt_input(struct ctx *c, const struct timespec *now) do { n = recv(c->fd_tap, pkt_buf + partial_len, - TAP_BUF_BYTES - partial_len, MSG_DONTWAIT); + sizeof(pkt_buf) - partial_len, MSG_DONTWAIT); } while ((n < 0) && errno == EINTR); if (n < 0) { @@ -1151,7 +1151,7 @@ static void tap_pasta_input(struct ctx *c, const struct timespec *now) tap_flush_pools(); - for (n = 0; n <= (ssize_t)(TAP_BUF_BYTES - ETH_MAX_MTU); n += len) { + for (n = 0; n <= (ssize_t)(sizeof(pkt_buf) - ETH_MAX_MTU); n += len) { len = read(c->fd_tap, pkt_buf + n, ETH_MAX_MTU); if (len == 0) { -- 2.48.1