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 D9350606A333 for ; Fri, 4 Dec 2026 16:02:12 +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=YIRorU5F Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9A4A340DD8; Fri, 4 Dec 2026 17:01:40 +0100 (CET) Received: from mail-dl1-f44.google.com (mail-dl1-f44.google.com [74.125.82.44]) by mails.dpdk.org (Postfix) with ESMTPS id 6E96040B8D for ; Fri, 4 Dec 2026 17:01:38 +0100 (CET) Received: by mail-dl1-f44.google.com with SMTP id a92af1059eb24-15ea896ddc8so1459910c88.0 for ; Fri, 04 Dec 2026 08:01:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796400097; x=1797004897; 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=Oohp/XNSD0JwH/11qxUEkGuKEhZ82j9H5rv7WWCdKH4=; b=YIRorU5F/y9t8xO/itOzCGXMGqoENmzJWHV+LZyIlorC+/zxTzNQLZrpXmXYIM0uwj AVOmOD+Uy0UVtryvC6EpHJNq/VAZ2a9pYMiXUweSQAB3mlxcoqv7y0BPLRwzybjzupW+ KGXSl2SNOtwCWD/fFasKtMub1XOmKDJ6MvyyNWGdWdxGEDR6QIErwARIvSsN8xz0qJL2 emmurMSTAzZFxlIeUkj0jQWEyyaLjE/uA1ZuM7P6w85xDIXYEdODSWuCqPJVFFBUo9Hy 4AKbyM1LqtCTBsg9SefixrPmEQAkocYp2DWWsBbNElka3ejtGUcHLf77gpYr74KhJMo3 yF/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796400097; x=1797004897; 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=Oohp/XNSD0JwH/11qxUEkGuKEhZ82j9H5rv7WWCdKH4=; b=XIXOfMCilgWzKFwfkg49QxTmvvll0skZ2HPQb8gIpoGfdWRrMRDXsCllfkxKqM1BaB PSm4uScP5rW7snI/2ZxbIJGooALNJrzKB2AiJNvUP8v9NExTf+I/mlCX6tsVZfcJufhG zMUj2Nmx0y6bGU7JeCG6oZ0LZDyLeU9RGsje9buoeHdfc53aBx/i4/tuLWrmMRK9hk8K wyZ1FqslR8aazgoXnQh+yJNXp51rPcTMXHo6+CwArsIL2+Wj+hwf+j/Wjmv8dslcPztG 1TWXh0iaatpL2GNHm4Lx/deLUoipss3eXXdr7lpfiv67LUnKCQ6nv9j1g9lAa6mYc+ih G3/w== X-Gm-Message-State: APuU4Z+RLsi3MaDxTbM/oYPQ0b+ChvHOWxKfSSYLJtNEdp/OQStqvi4a +Gin27SnxoEzdJt+k5XAcHgm0cGxNYgdI8LCpXF4MDT4wedFTw7bCWgBGsJnvQ== X-Gm-Gg: AZFdTZf9GlTxPntTsINJNBn631UsD9ScIuGuDY73kEAE/mmWZKU2DJX8tewcNpfpN3H mm61gd4I3FboktX77yMnZF5xwgsnVh5M/TILOUaFsw5bjr/ZiqcL8V/JVhrKQstxQ94ZKdshAWB ZBypXwn+T7UH1Zh3h518IoyebL3QPNOW3aL+zYF+L7cdtvPRbxmfHbJuNUI+ll4yr3pF80i44Nq vtJ/Gg/vNsdnXHCG0LZXV+Qfa/gO6UYwp/XPo5lwQbGgL8BuIKqn9+2cgWpELHv0suQZYmVYs7s xPx9Iy8mupuytn1g/i+2za+9DE6CRJDTy67LX05zGahsD7ri87gHfz/DPByg24HBSgxVfW8jb0O 0jtp4ZyD8Bv2DjrpXUYxcj6EZBLU/q8ekMovdzjLMYjq5Oxk2EagTo1hgtjWOUZq4jS8J0YnCTa om+b7T0yqCraeUiqmUbfwR7gZQddxO6rN/i4DVcsMsXqQeSOKsi9mwB8h/hn1uUTKWTXYugDLuk gwTDGNTwzXjow9VO91mff9qLN3KKQBxit6Wb/uJf9BbGnfUhZQDztyZENs0SbP5o79N9zltlhd7 tltzAwvgZ97rUncVNbdGFHajeXVFvSX8+CpoXFdWYmEzQCNpjUNoiYiHO93L8F72n2//279a8fO TI675ZZSWOU4TDvfgb6Ld/0HShP5j/RA= X-Received: by 2002:a05:701b:220b:b0:144:fa57:c617 with SMTP id a92af1059eb24-1b5d710fcdemr2238335c88.34.1796400096618; Fri, 04 Dec 2026 08:01:36 -0800 (PST) Received: from mac.com ([136.24.82.250]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d642de41sm7687604c88.3.2026.12.04.08.01.35 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 04 Dec 2026 08:01:36 -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 v10 5/8] net/af_packet: reject invalid ring parameters at probe Date: Fri, 4 Dec 2026 08:01:25 -0800 Message-ID: <20261204160128.17277-6-scott.k.mitch1@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261204160128.17277-1-scott.k.mitch1@gmail.com> References: <20261203164211.48531-1-scott.k.mitch1@gmail.com> <20261204160128.17277-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=-16.0 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, together with the minimum frame size for Rx, 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 | 20 +++++------ 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/app/test/test_pmd_af_packet.c b/app/test/test_pmd_af_packet.c index 6a4806acc7..986bb094df 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, 64, 0 }, /* framesz too small for a minimum Rx frame */ + { 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..10ba325e81 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 144B); +* ``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 2e75175aad..344d09eea6 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,19 +1372,18 @@ rte_eth_from_packet(struct rte_vdev_device *dev, return -1; } - /* A frame must hold a minimum Ethernet frame after the Rx offset */ - if (framesize < ETH_AF_PACKET_RX_FRAME_OVERHEAD + RTE_ETHER_MIN_LEN) { - PMD_LOG(ERR, "%s: framesz %u below minimum %zu", name, framesize, - ETH_AF_PACKET_RX_FRAME_OVERHEAD + RTE_ETHER_MIN_LEN); - return -1; - } - - blockcount = framecount / (blocksize / framesize); - if (!blockcount) { + /* Constraints the kernel enforces in packet_set_ring(), and room for a minimum Rx frame */ + frames_per_block = blocksize / framesize; + if (blocksize % getpagesize() != 0 || blocksize > (unsigned int)INT_MAX || + framesize < ETH_AF_PACKET_RX_FRAME_OVERHEAD + RTE_ETHER_MIN_LEN || + 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)