From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81891606A32F for ; Thu, 3 Dec 2026 16:44:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ARaoYRUp Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F0A39427AF; Thu, 3 Dec 2026 17:43:39 +0100 (CET) Received: from mail-dy1-f181.google.com (mail-dy1-f181.google.com [74.125.82.181]) by mails.dpdk.org (Postfix) with ESMTPS id 8091940E17 for ; Thu, 3 Dec 2026 17:43:37 +0100 (CET) Received: by mail-dy1-f181.google.com with SMTP id 5a478bee46e88-33bf40b0c8bso12382787eec.0 for ; Thu, 03 Dec 2026 08:43:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796316216; x=1796921016; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FVfa1FolHwkm3mG294C+Be5ifWAkI8dh+ySuUtTMez4=; b=ARaoYRUprcXarg7tmMxVUy/2pqLzdYSo73AJ+55yAxVXcHizhm07NhSmeWktE7wTfA HiHj8l2i7+XxdJi8KdtlDsg0tS5dn7KHhz/jjnpRj1+4Q1KFBbnsenFhK/wvUkAaWNeL FUxBq3qzeSQ92UQX/Q2BjjI+V/VSdC4+2iJEBi3i6KJ8ScscFvu7EBzi/wwA7gPa2P8w 1r8PQmrBSQ+vNGp1+46qs2OpL7YIrHOPyiO95gHx3CfVcVlPz0evpbZGNfC+MPRoZsp2 wBuy+CN9FnpzQdDD/htL9UfAbsnTQyamIKjF0f7nGtP0hdM2oNCJJIY+lbZeVG31wM2n nMmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796316216; x=1796921016; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=FVfa1FolHwkm3mG294C+Be5ifWAkI8dh+ySuUtTMez4=; b=EhxFEmUwJuz9KBNz/M+Ujo8fe4cUOh4SgI0CicY7Q+OKu1zmjZxSwy0/ju7euIY6nc lkupS6sl1YeGMFgZOY9fxozH42GuB4IA+/HDDqqY6c/NNZG6ybXed23VbSP+B93H+Iqi OycPEotl+aPFRy/NBZUcODiltCRB4rxrfH7/zMLxizUoa2N9ecz7AKO3ukwSbp0t+IEa cUfURhHn36L9K8e+CkxHCgfkEpd1bJ19rl7Zk4IC1P3bOb4KzbGqIdGQtRo+NHqC4LY0 mQc1o47IrEMjEaGGDBpokhGRnh0SdVN/4IuDEl87g6EGdPYYsdIxpb67PBKFNNtXNgzV Z4Xw== X-Gm-Message-State: APuU4Z8/d3DmYTvhq3IzTK4e6+jnruFgb58cHQw8DKNfhnY3m6hZxFjr +43WAEQe/2Ld4dNLMlpxmxnvItncYA4cmNSoYQppk0hhkXPOKO3b1+mSu80ypg== X-Gm-Gg: AZFdTZf0gcLmFiXOuAOwgO7tbtxQqG5+53p0wZRah4D91hFxZd1PTLiKq4v5Bts9T0y lBPRzfW1TUEhcfurQOwXAslGYBbrKFDI/18MV6zPoyC1iBqgLxNfcEsTviR1H9DZe1mkohorw3v iMQtWMicxMurXAJNvefuI2U5tj9uZ3G+7sGB2Lfp3JTTuTJt9TjmoQCHW9WnPlUDVpogSo7Z5BS HIEE2v6AdgIbc3qFrpWD48sHGGtgRvg10TB73waaSF7bZb4pI7piNJz4ubMgtU2HCiU1Es9o6Dg ggiLpj4tIk8JwmY3KuiK7j+dLFv/i/i0uILxjJAs2pgfcESU4g+OqRTVmQzuQlaZUrsZIcvQzx6 CBe5+rb0/6oarjsYlQ97BHvW0d8F+hgAcpkKKJH8XazL0eQWhX21VYFrAqW6t3KkaEjcHtin2wI YM7/IhNH3sthH3PsvHI4dYL7GMmySzH7aTtCwCxeWErJkf1iNNyz9QUujUUI0uO0oLY0KnOmKkM CIRyqFnZBQgwEwAebSfYHmaLHzSUkcsZ32N7iPWfh8MBfXBOzF4OmwrhV8UHsu56tEpB5S0XCCS qvrZdfjGWj1Ofry9KbRTzNLAOOkXCGll5WX5ZN5JuUbHyNQbnxUyvg9W/+08z3YFiUx0qT6fL2n iy7tmE6qHi6SPfMPPmMq5uqq0MZSSVEzLnkCuiXIDNYkC3wwYQmAjX50bXhe4z/QNs67g1rB5w9 CzPE6P X-Received: by 2002:a05:7301:4710:b0:378:314:4042 with SMTP id 5a478bee46e88-385702587c5mr38978129eec.14.1796316215799; Thu, 03 Dec 2026 08:43:35 -0800 (PST) Received: from mr55p01nt-relayp03.apple.com ([17.199.97.123]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385677c0c1dsm146280665eec.21.2026.12.03.08.43.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 03 Dec 2026 08:43:35 -0800 (PST) From: Scott Mitchell To: dev@dpdk.org Cc: stephen@networkplumber.org, thomas@monjalon.net, david.marchand@redhat.com, mb@smartsharesystems.com, Scott Mitchell Subject: [PATCH v9 5/8] net/af_packet: reject invalid ring parameters at probe Date: Thu, 3 Dec 2026 08:42:08 -0800 Message-ID: <20261203164211.48531-6-scott.k.mitch1@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261203164211.48531-1-scott.k.mitch1@gmail.com> References: <20261202171804.50287-1-scott.k.mitch1@gmail.com> <20261203164211.48531-1-scott.k.mitch1@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The kernel rejects a ring whose block size is not a multiple of the page size or exceeds INT_MAX, whose frame size is smaller than TPACKET2_HDRLEN or not a multiple of TPACKET_ALIGNMENT, or whose frame count is not a multiple of frames per block. Probe accepted these and failed later in setsockopt(PACKET_RX_RING) with only EINVAL. Check them at probe next to the existing frame size test, and document the constraints. Signed-off-by: Scott Mitchell --- app/test/test_pmd_af_packet.c | 41 +++++++++++++++++++++++ doc/guides/nics/af_packet.rst | 8 +++-- drivers/net/af_packet/rte_eth_af_packet.c | 12 +++++-- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/app/test/test_pmd_af_packet.c b/app/test/test_pmd_af_packet.c index 6a4806acc7..6a72829b6a 100644 --- a/app/test/test_pmd_af_packet.c +++ b/app/test/test_pmd_af_packet.c @@ -1256,6 +1256,46 @@ test_af_packet_frame_config(void) return TEST_SUCCESS; } +/* + * Test: Ring geometry the kernel would reject is refused at probe + */ +static int +test_af_packet_invalid_frame_config(void) +{ + const unsigned int pagesize = getpagesize(); + /* framecnt 0 means one block, so only the named constraint is broken */ + const struct { + unsigned int blocksz, framesz, framecnt; + } bad[] = { + { pagesize + 2048, 2048, 0 }, /* blocksz not a multiple of the page size */ + { 1u << 31, 2048, 0 }, /* blocksz above INT_MAX */ + { pagesize, 48, 0 }, /* framesz below TPACKET2_HDRLEN */ + { pagesize, 2040, 0 }, /* framesz not a multiple of TPACKET_ALIGNMENT */ + { pagesize, 2048, pagesize / 2048 + 1 }, /* framecnt not a block multiple */ + }; + char devargs[128]; + unsigned int i, framecnt; + int ret; + + if (!tap_created) { + printf("SKIPPED: TAP interface not available (need root)\n"); + return TEST_SKIPPED; + } + + for (i = 0; i < RTE_DIM(bad); i++) { + framecnt = bad[i].framecnt != 0 ? bad[i].framecnt : + bad[i].blocksz / bad[i].framesz; + snprintf(devargs, sizeof(devargs), "iface=%s,blocksz=%u,framesz=%u,framecnt=%u", + TAP_DEV_NAME, bad[i].blocksz, bad[i].framesz, framecnt); + ret = rte_vdev_init("net_af_packet_bad_frame", devargs); + if (ret == 0) + rte_vdev_uninit("net_af_packet_bad_frame"); + TEST_ASSERT(ret != 0, "Expected failure with %s", devargs); + } + + return TEST_SUCCESS; +} + /* * Test: Qdisc bypass configuration */ @@ -1791,6 +1831,7 @@ static struct unit_test_suite af_packet_test_suite = { TEST_CASE(test_af_packet_invalid_bad_iface), TEST_CASE(test_af_packet_invalid_qpairs), TEST_CASE(test_af_packet_frame_config), + TEST_CASE(test_af_packet_invalid_frame_config), TEST_CASE(test_af_packet_frame_layout), TEST_CASE(test_af_packet_frame_max_size), TEST_CASE(test_af_packet_qdisc_bypass), diff --git a/doc/guides/nics/af_packet.rst b/doc/guides/nics/af_packet.rst index d7fb4162fd..09c0be9c58 100644 --- a/doc/guides/nics/af_packet.rst +++ b/doc/guides/nics/af_packet.rst @@ -27,10 +27,12 @@ Some of these, in turn, will be used to configure the PACKET_MMAP settings. Possible choices: hash, lb, cpu, rollover, rnd, qm (optional, default hash); * ``ignore_outgoing`` - ``rte_eth_rx_burst()`` returns only incoming packets (optional, disabled by default); -* ``blocksz`` - PACKET_MMAP block size (optional, default 4096); +* ``blocksz`` - PACKET_MMAP block size (optional, default page size; Note: + multiple of page size, less than 2GB); * ``framesz`` - PACKET_MMAP frame size (optional, default 2048B; Note: multiple - of 16B); -* ``framecnt`` - PACKET_MMAP frame count (optional, default 512). + of 16B, at least 64B); +* ``framecnt`` - PACKET_MMAP frame count (optional, default 512; Note: multiple + of ``blocksz`` / ``framesz``). For details regarding ``fanout_mode`` argument, you can consult the `PACKET_FANOUT documentation `_. diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index d0d19dc34b..5ca8b6b81c 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -1285,6 +1285,7 @@ rte_eth_from_packet(struct rte_vdev_device *dev, unsigned k_idx; unsigned int blockcount; unsigned int blocksize; + unsigned int frames_per_block; unsigned int framesize = DFLT_FRAME_SIZE; unsigned int framecount = DFLT_FRAME_COUNT; unsigned int qpairs = 1; @@ -1371,12 +1372,17 @@ rte_eth_from_packet(struct rte_vdev_device *dev, return -1; } - blockcount = framecount / (blocksize / framesize); - if (!blockcount) { + /* Constraints the kernel enforces in packet_set_ring() */ + frames_per_block = blocksize / framesize; + if (blocksize % getpagesize() != 0 || blocksize > (unsigned int)INT_MAX || + framesize < TPACKET2_HDRLEN || framesize % TPACKET_ALIGNMENT != 0 || + framecount % frames_per_block != 0) { PMD_LOG(ERR, - "%s: invalid AF_PACKET MMAP parameters", name); + "%s: invalid AF_PACKET MMAP parameters: blocksz=%u framesz=%u framecnt=%u", + name, blocksize, framesize, framecount); return -1; } + blockcount = framecount / frames_per_block; PMD_LOG(DEBUG, "%s: AF_PACKET MMAP parameters:", name); PMD_LOG(DEBUG, "%s:\tblock size %d", name, blocksize); -- 2.54.0 (Apple Git-157)