From nobody Fri Oct 3 00:00:54 2025 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2050.outbound.protection.outlook.com [40.107.93.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACBD3274650; Tue, 9 Sep 2025 08:53:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757407995; cv=fail; b=HFiB1oY6AEJE/KBRuu+R9y5PEhzptE1HSclSPgl2B68UlzrirIhFzmODY+l1iUC87jlUTmOY73AlPyJnw2QD7g8on25IHOaNPqkhTfuA4gUTBv4pJWicP7pwUcO1sOZyd/C2PBuZSEL2eGbQgUKDPwCBt+MZdNjERrlR9R74xSQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757407995; c=relaxed/simple; bh=uuoEH3fBCbWrBNdr0SLD063RoKCHF6RZ5pnWJAbXtX4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WI5C/UijBdPv0Dr1IKI73B28upk8BWNcGuJYMxFP2Ggs9+mUwlBzdxuLj14S0mnDc4kWTE9WsY2Ps+hajFxTZOhdKRD5DFJ1NgZX0Oix2PkHjjhHt1vo2P145GrgewkNdTU+dse+ssnfT3rvZ8LIKKGRlh0g4wT8sHRQItAYS9s= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=U7VX1ij6; arc=fail smtp.client-ip=40.107.93.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="U7VX1ij6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xJ1xTXyw00WOd6ZPfPrwvgdhpdtgSlqyj/wPgOAsNw34S2SiC+06pIdllmxdypfdtcQ0/N7IGyvvudv4IGh/FUd79uDS21WJmJ2hlPGhoSVQUrRMB7CxEV3xR6FPOPH4YHT9PBtfHTmlF00d3TwiG1QxM5X+Q8HR7xwApX0S0MMlhrS118jOWj7kLwskSqj6VxuUIRV3i5nKxCRWSaaSnO3YJpTAdwPeUoOgxu3jnEa27e6PxLLqWecJyiRzQERO+Zet92QiUtb4DZdV1QRsiDWdYyxAlamGogJcp1ZIATd2UrNvfYDSTaS0CLA8N067SeIT1oLYoAaxmMlUFz7PRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=onx+GB/cBKe33y1ZbnqjlvsjuipDC54kT76cqiNQ6+4=; b=g5iQ/ruXYqMZ/URz0Zd+KwMBZAdUAiSWxvsOIfCmRN/O+DgvN/Cx6l5Dqy7tfpuSQ3RYye1+se6S68ZowpYhbindqq8j1Q4WvIpnK2ipkth0C4WcMAiTvHp3pkhyJCEU9fLbbFZuhud5glD5zzKacZERoSBZu41AGMi/pRcDKlwQfw4uaxIMkwHgpGDd97E29odcDKN5S60V6yY+yi3U8W1gpAF83oEXrQUUud9jddGgygM4MRTcKn6dbIQOB9D6qLs68B5ODwHti2wMEtuznZ6eZbyUWQNIzcBl1gCcyafx+g8rOgrmYcj9+hrvzHtiLmpX2kJ1yHr/Pk/AEW1xKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=onx+GB/cBKe33y1ZbnqjlvsjuipDC54kT76cqiNQ6+4=; b=U7VX1ij6bNsm9NPVsxjq8iGW9c7QOADHpsxW6cnvPi6WDClXS2yssyT/iC/kKRaBaezCr365n9GpnEF9GTPNUA3mu0K/TSpD41o+Yeh1Ye1GymyBWSpe4cV/7myVG5K6mUJ1XHlA374SsDTD8OPAvk5G4lp9mobQ3oi87PmvpOGJA/bLebhBWb0TlEprP/TU40l1hCQJeX1/Ipoegl8Vvl19dhE02ZhcklorQY57Mw+Pq25BD8CE1JrQyYv85JfJQuLU67qdfzY8Sdj4W5BK8LrrBEv5t5zsN0vYF4OWaBeO4imm++TgALU3nzw3NoYQOXfx7ESpO+c7Pvo2GeWupQ== Received: from BN9PR03CA0095.namprd03.prod.outlook.com (2603:10b6:408:fd::10) by SJ5PPFDDE56F72B.namprd12.prod.outlook.com (2603:10b6:a0f:fc02::9a5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9094.19; Tue, 9 Sep 2025 08:53:07 +0000 Received: from BN1PEPF0000468A.namprd05.prod.outlook.com (2603:10b6:408:fd:cafe::60) by BN9PR03CA0095.outlook.office365.com (2603:10b6:408:fd::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9094.22 via Frontend Transport; Tue, 9 Sep 2025 08:52:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BN1PEPF0000468A.mail.protection.outlook.com (10.167.243.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.13 via Frontend Transport; Tue, 9 Sep 2025 08:53:06 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Tue, 9 Sep 2025 01:52:54 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Tue, 9 Sep 2025 01:52:54 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Tue, 9 Sep 2025 01:52:49 -0700 From: Nimrod Oren To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , "John Fastabend" , Stanislav Fomichev , Mohsin Bashir CC: Dragos Tatulea , Tariq Toukan , Carolina Jubran , , , , , Nimrod Oren Subject: [PATCH RFC net-next 1/5] selftests: drv-net: Test XDP_TX with bpf_dynptr Date: Tue, 9 Sep 2025 11:52:32 +0300 Message-ID: <20250909085236.2234306-2-noren@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20250909085236.2234306-1-noren@nvidia.com> References: <20250909085236.2234306-1-noren@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000468A:EE_|SJ5PPFDDE56F72B:EE_ X-MS-Office365-Filtering-Correlation-Id: bd1dd518-69ea-4e30-3669-08ddef7e4b59 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|36860700013|1800799024|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?WoPKSSH9Rx/5Kv2xV0dH+Ip16n9jpny8uSnyZqvo3LoygwihJ+TIN+oz+hOd?= =?us-ascii?Q?sVd6ihOHVoB/WuRZOSNLRyPphYUxga/NBLz7XrcuAR7wNuX3TtsYxrHAzc0h?= =?us-ascii?Q?9Gos4vcW2OqPCqvhmWTdccbsFFBTrZOgHSgSN1xe73YKrRXcDd0//YsdjRL4?= =?us-ascii?Q?h+cWy47Cz8e8uhf9GAFM5kmex95iK+LcGQKz+FnqLOJgRl4T6ncC0p3XpMRo?= =?us-ascii?Q?pXram6QzeQbwHx8lc1DH1lRSwA7fxspgoPp6qJMD+8gAM84DoY/yJpYARPrG?= =?us-ascii?Q?yD2LjZJsWlsBjLxxEBX2tjAfX2uQJLFL9vDzcGJFxBOLNzoNjud65gGL9Ao1?= =?us-ascii?Q?7SbUN9jtRVKADecFoLlH7ZKwFNScYkSMDseDsfAfi0e8ZVBa1+wHZDvlOyfi?= =?us-ascii?Q?jvnbAmMQEnfyENvF0F1wGQHG1sY4s7GQvJjdbGFMG7SCyzy9cIuOTGF3Bfu/?= =?us-ascii?Q?qSco11PrDbRxjflR3CCcGxj+ypf+xf1g2ztz+/8evKkKb5QJs4smAVPwjzIj?= =?us-ascii?Q?IxJQAbXoAT8U3FqQUbCBNuVOzbtGLj/Cn91eLGrmILVF8nvpG8xLOnnO1tg3?= =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LRmb92M1CLKiX14yehXePEYcRjL?= =?us-ascii?Q?SA7jpMT0QwnxlOsgyEKDRkKkoqrLAt9i4AdrJ7+Yiq85pN++Maee+y79eg?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(36860700013)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2025 08:53:06.3718 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bd1dd518-69ea-4e30-3669-08ddef7e4b59 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF0000468A.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ5PPFDDE56F72B Content-Type: text/plain; charset="utf-8" Update xdp_mode_tx_handler to use bpf_dynptr_slice_rdwr instead of accessing the packet data directly. This makes the test viable for drivers that do not store any packet data in the linear part when in multi-buffer mode. While here, remove the unused local min() helper. Signed-off-by: Nimrod Oren Reviewed-by: Carolina Jubran Reviewed-by: Dragos Tatulea --- .../selftests/net/lib/xdp_native.bpf.c | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/net/lib/xdp_native.bpf.c b/tools/testi= ng/selftests/net/lib/xdp_native.bpf.c index 521ba38f2ddd..346cbba9afec 100644 --- a/tools/testing/selftests/net/lib/xdp_native.bpf.c +++ b/tools/testing/selftests/net/lib/xdp_native.bpf.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 =20 #include +#include #include #include #include @@ -9,6 +10,7 @@ #include #include #include +#include "../../bpf/bpf_kfuncs.h" =20 #define MAX_ADJST_OFFSET 256 #define MAX_PAYLOAD_LEN 5000 @@ -51,11 +53,6 @@ struct { __type(value, __u64); } map_xdp_stats SEC(".maps"); =20 -static __u32 min(__u32 a, __u32 b) -{ - return a < b ? a : b; -} - static void record_stats(struct xdp_md *ctx, __u32 stat_type) { __u64 *count; @@ -145,32 +142,33 @@ static void swap_machdr(void *data) =20 static int xdp_mode_tx_handler(struct xdp_md *ctx, __u16 port) { - void *data_end =3D (void *)(long)ctx->data_end; - void *data =3D (void *)(long)ctx->data; struct udphdr *udph =3D NULL; - struct ethhdr *eth =3D data; + struct ethhdr *eth =3D NULL; + struct bpf_dynptr ptr; =20 - if (data + sizeof(*eth) > data_end) + bpf_dynptr_from_xdp(ctx, 0, &ptr); + eth =3D bpf_dynptr_slice_rdwr(&ptr, 0, NULL, sizeof(*eth)); + if (!eth) return XDP_PASS; =20 if (eth->h_proto =3D=3D bpf_htons(ETH_P_IP)) { - struct iphdr *iph =3D data + sizeof(*eth); - __be32 tmp_ip =3D iph->saddr; + struct iphdr *iph =3D NULL; + __be32 tmp_ip; =20 - if (iph + 1 > (struct iphdr *)data_end || - iph->protocol !=3D IPPROTO_UDP) + iph =3D bpf_dynptr_slice_rdwr(&ptr, sizeof(*eth), NULL, + sizeof(*iph)); + if (!iph || iph->protocol !=3D IPPROTO_UDP) return XDP_PASS; =20 - udph =3D data + sizeof(*iph) + sizeof(*eth); - - if (udph + 1 > (struct udphdr *)data_end) - return XDP_PASS; - if (udph->dest !=3D bpf_htons(port)) + udph =3D bpf_dynptr_slice(&ptr, sizeof(*iph) + sizeof(*eth), NULL, + sizeof(*udph)); + if (!udph || udph->dest !=3D bpf_htons(port)) return XDP_PASS; =20 record_stats(ctx, STATS_RX); swap_machdr((void *)eth); =20 + tmp_ip =3D iph->saddr; iph->saddr =3D iph->daddr; iph->daddr =3D tmp_ip; =20 @@ -179,18 +177,17 @@ static int xdp_mode_tx_handler(struct xdp_md *ctx, __= u16 port) return XDP_TX; =20 } else if (eth->h_proto =3D=3D bpf_htons(ETH_P_IPV6)) { - struct ipv6hdr *ipv6h =3D data + sizeof(*eth); + struct ipv6hdr *ipv6h =3D NULL; struct in6_addr tmp_ipv6; =20 - if (ipv6h + 1 > (struct ipv6hdr *)data_end || - ipv6h->nexthdr !=3D IPPROTO_UDP) + ipv6h =3D bpf_dynptr_slice_rdwr(&ptr, sizeof(*eth), NULL, + sizeof(*ipv6h)); + if (!ipv6h || ipv6h->nexthdr !=3D IPPROTO_UDP) return XDP_PASS; =20 - udph =3D data + sizeof(*ipv6h) + sizeof(*eth); - - if (udph + 1 > (struct udphdr *)data_end) - return XDP_PASS; - if (udph->dest !=3D bpf_htons(port)) + udph =3D bpf_dynptr_slice(&ptr, sizeof(*ipv6h) + sizeof(*eth), + NULL, sizeof(*udph)); + if (!udph || udph->dest !=3D bpf_htons(port)) return XDP_PASS; =20 record_stats(ctx, STATS_RX); --=20 2.45.0 From nobody Fri Oct 3 00:00:54 2025 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2087.outbound.protection.outlook.com [40.107.92.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 554232773D8; Tue, 9 Sep 2025 08:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757407999; cv=fail; b=HYwoMmVpRo9C6uixwDQYDmzNbGyFfiIkbP/+x1BKjqzuOKVQu/bVk7n1BAUOiMg5SsyvXVdZvdNhmoEohc0DufI7lXppSYhvuCuUVGVG9OXgH9Lz10z7NGLJ6H33IZIOvGfgWjSdqNs9TT2fsWqALmXOyy5yzANBSheNPTbudJQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757407999; c=relaxed/simple; bh=gq/khDIlMhd0OyYU/8UyzI/2W/URMKVCXwLJdcrp+zI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=b87U/Fn1mNeN/6vo+6RmU2j36fd94fjfO2HgJZ1Wo8alJd9yXNeNppnyN1tTSnWIjuvxjxdMhDb75kD1ZYzbVTEPedaQk/KFMtGB5lRVUJMoyB8gVPmArtM+u0pVXBH+V5Iv6UCUR4HAbg9AWtv8r9SdFh/E79WZj+Kr4IYcEtA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=ladnPKlO; arc=fail smtp.client-ip=40.107.92.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="ladnPKlO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mXYMS6526rxRbu1dLglVhNZNgy+VT76xP7G4vUzyBNO4puVHlvOpui9/9dMeJkvZgkdCd2C/kXlQ9doTvTyXfJCtG3U8cxg/oMoMImqByuTRGy7rstrv9mP/Vmq6QXVgoTo5GtU1CniMiEiUOnzMDP+2f03iHvpm4njFQZXRw7kTuUGJl/vxzVTUf75N6cSfTRxuiZYKYOsrcqyqdSBImhqj7mJcub/qHnFzdiepMFW3+ToSSM5WIvjWt2wWd0ku0XXo81mzp9sGpyDFo/wHcq2FuLJOd84MRTR8yvWg7SIbWtEG0X/CwGHJCteYpol9hr9iiCGKRiGdTqraYPGcZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7uINVeQA8C8TebQin5XTqWjOxOtcEKAjG2SOTBBqhuk=; b=e73fz0CW3ztNh1pvHYFx77gTnoLy7kOE7ad2UZRSpNo/9w4y2k60QR5d84LXxTiOwxdxlWIKnJBwabtPwTN7aEBcNzGCumhHV807JhTycNWOhOuUa3SE3Ui3fbQqfR/Ji6+yh0C7OpW84UrPh7bRcrLl1zL9rvJfzAvhslLDUwqGq92nNuInPasHXKEQgo2kH3a61erjPXOGTE9/wG3CCoBdlcE6fQY5qwDCOcjNExxFJM4uDwPhan451f6dvjzfhBT51G+HrnmlQxex7J6EaUT5arH4vqaygM/iycqQ24hqqOti9KK8FHqBB/THOj631+4b726/V3PD3tY0LDc8YA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7uINVeQA8C8TebQin5XTqWjOxOtcEKAjG2SOTBBqhuk=; b=ladnPKlOoqf7ygGPmYR/qiR0MrRKDU7faT9T1u3rkv1H0cbi39TY6Q5FH5NGrvnNaxCb2GG5T2lkU1esml5vNhDORGba+yVxyQ5s33PYeJfftCdmPsD4237nCWVWv1DY+6IkV9aAE7xva0pV/hyUxEMleDzc8Habd5KtPp9/J0HsGILolDVzmHLfMrBb2Ho1DnRL11PClkszbvOiENfwn3saCbhZrJGZmwED8LjCQ6G+0Xgyj8eYUpUcY56dpN0pn5/Edm3fmvuLrTr00YXBnqSiNejyAznUaqTblVRSnLYjzaDElgm81ho6/KZZ35wJ2cQJ3Giilon8nsgIpt/o+A== Received: from BN9PR03CA0118.namprd03.prod.outlook.com (2603:10b6:408:fd::33) by DM4PR12MB7744.namprd12.prod.outlook.com (2603:10b6:8:100::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9094.22; Tue, 9 Sep 2025 08:53:13 +0000 Received: from BN1PEPF0000468A.namprd05.prod.outlook.com (2603:10b6:408:fd:cafe::48) by BN9PR03CA0118.outlook.office365.com (2603:10b6:408:fd::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9094.22 via Frontend Transport; Tue, 9 Sep 2025 08:53:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BN1PEPF0000468A.mail.protection.outlook.com (10.167.243.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.13 via Frontend Transport; Tue, 9 Sep 2025 08:53:12 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Tue, 9 Sep 2025 01:53:00 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Tue, 9 Sep 2025 01:53:00 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Tue, 9 Sep 2025 01:52:56 -0700 From: Nimrod Oren To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , "John Fastabend" , Stanislav Fomichev , Mohsin Bashir CC: Dragos Tatulea , Tariq Toukan , Carolina Jubran , , , , , Nimrod Oren Subject: [PATCH RFC net-next 2/5] selftests: drv-net: Test XDP tail adjustment with bpf_dynptr Date: Tue, 9 Sep 2025 11:52:33 +0300 Message-ID: <20250909085236.2234306-3-noren@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20250909085236.2234306-1-noren@nvidia.com> References: <20250909085236.2234306-1-noren@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000468A:EE_|DM4PR12MB7744:EE_ X-MS-Office365-Filtering-Correlation-Id: 74a5c633-0732-4399-cbfa-08ddef7e4f12 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|36860700013|82310400026|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?BwQwYoO9gurI4Cf/Cj8i/fpUbX3KYCNTtPDXcf2LzMP1icZ/LRhqaX2GG99/?= =?us-ascii?Q?6IazlPIFmzsMABYqTTmjDfpzejbe6rsqFeALeTVCY+vgchf2/Kyp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w9rqKhW4g9zKqE8M3gsmhgqyhd1RvjzuoLKM5YUJAcHrx37Lz?= =?us-ascii?Q?ljBwgtQpiAKaDjx4uKF/JYrKRo0NW0BmdiWUlFSUjMM698c25ow1xg7xFM/f?= =?us-ascii?Q?+bAOJ+kbfxd+P87aYb7nRTaRU7x6TTo42darevAyulJxdn6WL5QkyscCfSDf?= =?us-ascii?Q?LJs4MQr1IdKQ0oZfO6L1TPq+/S6sty76KvVa6lmabW6BHbPbcST9CzyIoAs5?= =?us-ascii?Q?UvIeEO+TSaTNbcbZ6sc08E46eKJad2o7QDACnxaL5oJLteCpjOPHXY/y4cxg?= =?us-ascii?Q?JTalI1LmP6BeXzHv5mMyDPfMaBwWUcQPPXqXTUHgyK7J5n9zu3MUZTf1nJ9a?= =?us-ascii?Q?Nz7JHH/545OONQlmHQACkcZc2ym0LLJTz31vOCXpHalq5czn6nEJOzfxtFc5?= =?us-ascii?Q?RlUnMluXuYIOQtwWUgGJpVRYnjOjOnpiUBYdtwQREP9HstP5F/83x+/X74HI?= =?us-ascii?Q?HFHT4EvvvdADL1AGoS9TE8xViPt+doGyXWk3ODZIwKP2GzMgK3TVn0E/1dfC?= =?us-ascii?Q?AMLatVLJoRQK1lPQxqKiiRigAQflXeTNRHjHVgqb4XquMokm+vafw2qVPQ?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(36860700013)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2025 08:53:12.6144 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 74a5c633-0732-4399-cbfa-08ddef7e4f12 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF0000468A.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7744 Content-Type: text/plain; charset="utf-8" Update xdp_adjst_tail_shrnk_data to use bpf_dynptr_slice to read the data at the end of the packet, instead of bpf_xdp_load_bytes. This may avoid a copy by returning a direct pointer to the dynptr data. Note: since bpf_dynptr_slice() does not support variable lengths, we use MAX_ADJST_OFFSET as the slice size, and update both the size check and the UDP checksum calculation accordingly. Signed-off-by: Nimrod Oren Reviewed-by: Carolina Jubran Reviewed-by: Dragos Tatulea --- .../selftests/net/lib/xdp_native.bpf.c | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/net/lib/xdp_native.bpf.c b/tools/testi= ng/selftests/net/lib/xdp_native.bpf.c index 346cbba9afec..ff768fbc8606 100644 --- a/tools/testing/selftests/net/lib/xdp_native.bpf.c +++ b/tools/testing/selftests/net/lib/xdp_native.bpf.c @@ -272,10 +272,11 @@ static __u16 csum_fold_helper(__u32 csum) static int xdp_adjst_tail_shrnk_data(struct xdp_md *ctx, __u16 offset, __u32 hdr_len) { - char tmp_buff[MAX_ADJST_OFFSET]; - __u32 buff_pos, udp_csum =3D 0; + char tmp_buff[MAX_ADJST_OFFSET] =3D {0}; + __u32 buff_len, udp_csum =3D 0; struct udphdr *udph =3D NULL; - __u32 buff_len; + struct bpf_dynptr ptr; + void *data =3D NULL; =20 udph =3D update_pkt(ctx, 0 - offset, &udp_csum); if (!udph) @@ -285,18 +286,19 @@ static int xdp_adjst_tail_shrnk_data(struct xdp_md *c= tx, __u16 offset, =20 offset =3D (offset & 0x1ff) >=3D MAX_ADJST_OFFSET ? MAX_ADJST_OFFSET : offset & 0xff; - if (offset =3D=3D 0) - return -1; =20 /* Make sure we have enough data to avoid eating the header */ - if (buff_len - offset < hdr_len) + if (buff_len - sizeof(tmp_buff) < hdr_len) return -1; =20 - buff_pos =3D buff_len - offset; - if (bpf_xdp_load_bytes(ctx, buff_pos, tmp_buff, offset) < 0) + bpf_dynptr_from_xdp(ctx, 0, &ptr); + data =3D bpf_dynptr_slice(&ptr, buff_len - sizeof(tmp_buff), tmp_buff, + sizeof(tmp_buff)); + if (!data) return -1; =20 - udp_csum =3D bpf_csum_diff((__be32 *)tmp_buff, offset, 0, 0, udp_csum); + udp_csum =3D bpf_csum_diff(data, sizeof(tmp_buff), data, + sizeof(tmp_buff) - offset, udp_csum); udph->check =3D (__u16)csum_fold_helper(udp_csum); =20 if (bpf_xdp_adjust_tail(ctx, 0 - offset) < 0) --=20 2.45.0 From nobody Fri Oct 3 00:00:54 2025 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2081.outbound.protection.outlook.com [40.107.92.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC9582459CF; Tue, 9 Sep 2025 08:53:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757408012; cv=fail; b=Q5rE27Q5orp7eJXuoqAc0IdvxrpvumTr1aw9Mr1hu05c7AhW69DT5h4kErmPtt1IdIr/8PAed1LEgERba/r2xzd2IJpG6reJNQeZaVeghTTkrTF548bxpmICehlQzIrSV7Sq6nt+GaadwovTDqFTASiYQBeJrjjCCL7VFzayLfI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757408012; c=relaxed/simple; bh=KtibvBy2Pjm99zA8yO57lnUZHBlChy+pb83ZiB97hi8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TaRoSaFB2wQub28ZW95j6skOsESHDfqUxfQkZrZf/mlNl+aZmyt8pbpHYSXGMBuou1VQKROQVhi5lLrlRcvmQybgu3OetPEzmiId3kjX9NF4N3/3a/N6UNUJP/xgX/sVHWaoctKaxdWiYme3nBMwFTUpDD3Mi5P5SKgWxHGc7Gw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=lJAbYhcp; arc=fail smtp.client-ip=40.107.92.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="lJAbYhcp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mczcpiZTEH4MS9FKqawiYt0kVLPkvrpjgiroQrfBnSKE5jt3IWU+A1RissDYj45gO0vmD+0+GmLyY8da7BUJBpbR8AepfbuLhxHvPhlnxNP8XzZzmrB4WrZCLhrrDKAnlSBaZIH/h+W7VgiToBdPIGaz2N5blhz9QMoWuU//grGXBqOGRW4Gvot3KuFiu8ohBzbJwZTLKaqavNyC3LvfbfSXviMAaHs7R259lHmY2/yijac1wv69VDgWn/sqHsct8ugCBkIKX7nevv0wxfbOWFcokM7PXYaRtELganq0//6tF8XPGeEaV6rVQTJN9DIusykY/fvVpINWBhDxbuPYMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oCfMsUVYPwoQbtFuQ1Rl7bwxzhDON4xa+JrT23RgrTk=; b=aq5uAPjTXAmkuq4s35bvss0tLiUa4AUP43dECDky6mAxvvbD30bJ5m/5ua1jE4qgZ8KAB4y1GTpAeozVNqzi3XDseS4BVqiOqu656KENp4qHuOvO7+S1swdYv1ksDJxW7jTOJcxFiHnrMMwLYBCQC4JhR3whXoYev6eMBrvJnh1ASJw8rf9K2uXWmWQ9+PIZV//zCAJ8otIBrvqN21YGpfszIlZMiOBo9Qy+yiBfBmWu50nE9szqJWLuNGpW6U9w4dK1uL/+T6ODPutObYRYBDNYcc9ZZo5ApehB7vsNIaaQpZJNm6ZpGOry3DthoLwRl0phDMm9k9/QiVRakRVxjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oCfMsUVYPwoQbtFuQ1Rl7bwxzhDON4xa+JrT23RgrTk=; b=lJAbYhcpReXY6/8sqFVS8l862gwNvEApX6cyCPv3JFClmgdvg1XVUUixfSzmV/bYmwRczYhvg0+XYSLwtI1pveyEJrg01QlN6f7WWkdy5oBywAIbmzgZF4BQ5Istq2NaqMiMS2N9ienwgOYLqKCaHUsBh/Ijear4x0GsiuVUb40Jm3U7T2pvlRQNi1Tq7GUukyGezONZiLYRkxcRdqk27epLz47FiAU83rhorYYnOVgqeJVOWrK+iuR4XHZQ73beCm7mUO5FlCmZHwerejBZikiR49jzddEYD8dv10co+vPHmNWD/bEWJY4C/6U7wt/YZ6both+LvrmepuboMLQgNw== Received: from BN9PR03CA0297.namprd03.prod.outlook.com (2603:10b6:408:f5::32) by SA0PR12MB4431.namprd12.prod.outlook.com (2603:10b6:806:95::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9094.22; Tue, 9 Sep 2025 08:53:26 +0000 Received: from BN1PEPF0000468D.namprd05.prod.outlook.com (2603:10b6:408:f5:cafe::97) by BN9PR03CA0297.outlook.office365.com (2603:10b6:408:f5::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9094.22 via Frontend Transport; Tue, 9 Sep 2025 08:53:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BN1PEPF0000468D.mail.protection.outlook.com (10.167.243.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.13 via Frontend Transport; Tue, 9 Sep 2025 08:53:24 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Tue, 9 Sep 2025 01:53:07 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Tue, 9 Sep 2025 01:53:07 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Tue, 9 Sep 2025 01:53:03 -0700 From: Nimrod Oren To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , "John Fastabend" , Stanislav Fomichev , Mohsin Bashir CC: Dragos Tatulea , Tariq Toukan , Carolina Jubran , , , , , Nimrod Oren Subject: [PATCH RFC net-next 3/5] selftests: drv-net: Test XDP head adjustment with bpf_dynptr Date: Tue, 9 Sep 2025 11:52:34 +0300 Message-ID: <20250909085236.2234306-4-noren@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20250909085236.2234306-1-noren@nvidia.com> References: <20250909085236.2234306-1-noren@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000468D:EE_|SA0PR12MB4431:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d1ab70e-47b1-4f34-1339-08ddef7e565d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|1800799024|82310400026|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?r+0gjEPMCu4sU7OApkqrGdCQSG27old3MxwbUi+PFA3L0kP4GUnDqQszNU88?= =?us-ascii?Q?8jKKzhe8lG/Ugp8q/0HQWh1w6ppxNrx8gk+H3hMsrFv8Tp09GnfsFhUOQ7qA?= =?us-ascii?Q?OCAF7vLTMXBZljOqpngQG+IDfvmRU3A8sCrkh9woNUcRjwi+FM2StfUekrXV?= =?us-ascii?Q?T73++gGp5DQIwfC0DY+mgy8W9n0KjVGVTUIlMI1dkOo6hQZCPptgVx0uUWCZ?= =?us-ascii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u53S77vLq2yAkvt75hC1qG9?= =?us-ascii?Q?WsJtLMQMQeHtFxMzgW6wdRBJ5vnVe7/Ux+JoXrBCLFJsjhOgBHAEAFB/lG0C?= =?us-ascii?Q?+oCmkdpzh3UP3xd4oLO+AaqrIkOFhuUNsyYN66TC2ClU5Igt9aAyUFroRdK7?= =?us-ascii?Q?7W0KR6f0Puqz01mV044NvvqvT8oQAVu0rnJ6iFmJltJS+eEvNLxUKOF2U0rc?= =?us-ascii?Q?NghQ2XMN2QZgx4/sjoK6IPiD0ke5YdWkeUkamt+h+QOD+rtmyyiqyi9hXzTA?= =?us-ascii?Q?uzbXkQzrZHGc4RS02DG+PkXVMKj/uS4z62wAR76WKQ+C998t9Yoa0cGDkMbp?= =?us-ascii?Q?myIYGO9rsuGHOsG4OJViO5JP5BbL+RG194ETG56sX0ZKEBRVgy7UHOETTSkM?= =?us-ascii?Q?pTHzaXHcXfEf1k1QlpAFfMKFoUXLMs7meT35zq9zIjTjfB4uKjylQ08yhg?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(7416014)(376014)(1800799024)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2025 08:53:24.8578 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1d1ab70e-47b1-4f34-1339-08ddef7e565d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF0000468D.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4431 Content-Type: text/plain; charset="utf-8" Update xdp_adjst_head_shrnk_data to use bpf_dynptr_slice to read the data right after the headers, instead of bpf_xdp_load_bytes. This may avoid a copy by returning a direct pointer to the dynptr data. Also, use bpf_dynptr_read and bpf_dynptr_write to move the headers, instead of bpf_xdp_load_bytes and bpf_xdp_store_bytes. Signed-off-by: Nimrod Oren Reviewed-by: Carolina Jubran Reviewed-by: Dragos Tatulea --- .../selftests/net/lib/xdp_native.bpf.c | 35 +++++++------------ 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/net/lib/xdp_native.bpf.c b/tools/testi= ng/selftests/net/lib/xdp_native.bpf.c index ff768fbc8606..71172d32c529 100644 --- a/tools/testing/selftests/net/lib/xdp_native.bpf.c +++ b/tools/testing/selftests/net/lib/xdp_native.bpf.c @@ -398,10 +398,11 @@ static int xdp_adjst_tail(struct xdp_md *ctx, __u16 p= ort) static int xdp_adjst_head_shrnk_data(struct xdp_md *ctx, __u64 hdr_len, __u32 offset) { - char tmp_buff[MAX_ADJST_OFFSET]; + char tmp_buff[MAX_ADJST_OFFSET] =3D {0}; + struct bpf_dynptr ptr; struct udphdr *udph; - void *offset_ptr; __u32 udp_csum =3D 0; + void *data =3D NULL; =20 /* Update the length information in the IP and UDP headers before * adjusting the headroom. This simplifies accessing the relevant @@ -414,37 +415,25 @@ static int xdp_adjst_head_shrnk_data(struct xdp_md *c= tx, __u64 hdr_len, if (!udph) return -1; =20 - offset =3D (offset & 0x1ff) >=3D MAX_ADJST_OFFSET ? MAX_ADJST_OFFSET : - offset & 0xff; - if (offset =3D=3D 0) - return -1; - - if (bpf_xdp_load_bytes(ctx, hdr_len, tmp_buff, offset) < 0) + bpf_dynptr_from_xdp(ctx, 0, &ptr); + data =3D bpf_dynptr_slice(&ptr, hdr_len, tmp_buff, sizeof(tmp_buff)); + if (!data) return -1; =20 - udp_csum =3D bpf_csum_diff((__be32 *)tmp_buff, offset, 0, 0, udp_csum); + udp_csum =3D bpf_csum_diff(data, offset, 0, 0, udp_csum); =20 udph->check =3D (__u16)csum_fold_helper(udp_csum); =20 - if (bpf_xdp_load_bytes(ctx, 0, tmp_buff, MAX_ADJST_OFFSET) < 0) - return -1; - - if (bpf_xdp_adjust_head(ctx, offset) < 0) - return -1; - - if (offset > MAX_ADJST_OFFSET) - return -1; - - if (hdr_len > MAX_ADJST_OFFSET || hdr_len =3D=3D 0) - return -1; - /* Added here to handle clang complain about negative value */ hdr_len =3D hdr_len & 0xff; =20 - if (hdr_len =3D=3D 0) + if (bpf_dynptr_read(tmp_buff, hdr_len, &ptr, 0, 0) < 0) return -1; =20 - if (bpf_xdp_store_bytes(ctx, 0, tmp_buff, hdr_len) < 0) + if (bpf_dynptr_write(&ptr, offset, tmp_buff, hdr_len, 0) < 0) + return -1; + + if (bpf_xdp_adjust_head(ctx, offset) < 0) return -1; =20 return 0; --=20 2.45.0 From nobody Fri Oct 3 00:00:54 2025 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2070.outbound.protection.outlook.com [40.107.101.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E0942459CF; Tue, 9 Sep 2025 08:53:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.70 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757408020; cv=fail; b=JWUTztph0R+DO6QRxcTU8/fxSSA0f9pKDddOTAWg5SL1GhdfIkCtUKEP2wQ+m9MTX7BVyu9/uUCoxrelQhxm0s4EOz6BClQO9MM9q7GZ+JF/wTwFX8z/O9hdltphIu7or4N2ndKgpFXfOWwaWY0/Z+X9RlnOFm06y8LRAaEF40o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757408020; c=relaxed/simple; bh=eUOgDrk80J8xQLXPDHhJXezMCTA3j3aOqquEt6xEIuM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eGn+P7yJ7Sr11Ck9gPjEL7PwWJaqrG8PeL/maQ317YejZRL3VL72IJr167lnVbc8g9wc5KDIdCZL1ekn4gUw+3QNgWJoyrUKAEWrZN+gGuA8vx/5alzHTs4SNbyybYxAl1mkLp7SJiWBjvH3kPNRDY6pdrIMST/mr1OhOT+sbio= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=haitldel; arc=fail smtp.client-ip=40.107.101.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="haitldel" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PngBm89B0wivL+RSqECXcRtbJgMRxWP19jVFt5MGijqEqQto8YVo8kezzWJKs6sS71DmRktXrKmt7UxNgPMTfUNf8Se1KQ5p0kv7vikYA+55PUbzS0J43km0QJMMTZoxGgtHBqVhfTMF/634uZvvJ/Pu3O8OwEQi54D44+Nj+7mSm6ouSnsF2Moims16+9G1jlX0rMtlugVbRBHTSNJGADuAKyIVmVlt0WOFg9SOHhSNG5J3lY1hSAhszjqHnBqnppOk93iQVJj9IRakawnS1Ub1MaJl58niSajv/8D/GqYUQXUV5Gy+kd4BmsD6KLnteAw5FNsLn3We1B/Gh9w9pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=y+d/OAsXExzGowwEYzypzydUaqzGi4KtXFN1QH6AdqI=; b=qGKShNseyH8E6bjfIGcPUhV9tG80+SZDQj2TOav9RFg2WwF6mwIDBl8dWafxA6hTDbaW0XyNfEnvJTW3aMu0j+RctcwpY1UvKmFWZWVcE7S6QAvwT1ts51oMMjquDKhHuk+OORP/iTPw+qwWBcmT6QNZnWg5G+EWfhyQhDeDNeNFZ68FB80Rw9FkdfHJDmY0Lf1fV2QZu/DeiifoG4H7kQWgA/SXRntxuMYnxIDVU50xsheQcsI1OAPNZflzGAaXzQQ/rR63PW0JB8zIigog3x4wCP7d5ZLQpaDLhSGMI1m9/ZFXVDG3R6Ey8t4aEV/WuhcMezns/cqQUCROYeO7UA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y+d/OAsXExzGowwEYzypzydUaqzGi4KtXFN1QH6AdqI=; b=haitldel1wxWt6JgYGCIH9Gd0hBc9ndi+SCC8XSbCSrvx5egGkRL+s2sHap2vlOGL0uQqOOfNb3ioA1eRecH9iwh/zDn88D4I7Go91lhCZykppVBhF6J7Nu795SLE49Cpz/96tckyifuK+3Vy4F6MKaaHP6vqU20nqmmMw3G6pr87Ifc8pj4gCCJK031hzJA30MIOGasigO+NWJF0aDbg4sHJYCbXOrf/1An/EaLQuprZmNNSkBd3UjUeN8yhbJm2aldml1lIrt6o28vibfu5qpgt58JNo+tJtMZC99r4H+mF3F6TyxjTxg8kRXNqbgxT85fV5qCCVCsJH24axfE4A== Received: from BN9PR03CA0343.namprd03.prod.outlook.com (2603:10b6:408:f6::18) by DS0PR12MB7874.namprd12.prod.outlook.com (2603:10b6:8:141::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9094.22; Tue, 9 Sep 2025 08:53:32 +0000 Received: from BN1PEPF00004688.namprd05.prod.outlook.com (2603:10b6:408:f6:cafe::c4) by BN9PR03CA0343.outlook.office365.com (2603:10b6:408:f6::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9094.22 via Frontend Transport; Tue, 9 Sep 2025 08:53:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BN1PEPF00004688.mail.protection.outlook.com (10.167.243.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.13 via Frontend Transport; Tue, 9 Sep 2025 08:53:31 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Tue, 9 Sep 2025 01:53:14 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Tue, 9 Sep 2025 01:53:13 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Tue, 9 Sep 2025 01:53:09 -0700 From: Nimrod Oren To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , "John Fastabend" , Stanislav Fomichev , Mohsin Bashir CC: Dragos Tatulea , Tariq Toukan , Carolina Jubran , , , , , Nimrod Oren Subject: [PATCH RFC net-next 4/5] selftests: drv-net: Adjust XDP header data with bpf_dynptr Date: Tue, 9 Sep 2025 11:52:35 +0300 Message-ID: <20250909085236.2234306-5-noren@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20250909085236.2234306-1-noren@nvidia.com> References: <20250909085236.2234306-1-noren@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004688:EE_|DS0PR12MB7874:EE_ X-MS-Office365-Filtering-Correlation-Id: ccd66cff-9763-4de6-cccb-08ddef7e5a4e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|36860700013|376014|82310400026|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?bjfWSAgYPs9P7Qe6e52j/kr/bXZrx1a2rQELHNnvbzUj9CXSdFINfwsddNZQ?= =?us-ascii?Q?+wKFHCTuoJQp4clt4L5aM152p/VSUcArieTcQgpjjXSVIuoTfuNxocKzugkR?= =?us-ascii?Q?fm/3bXQx4YR4rmDhh40/qKLgHlF3hohZc/PdCHEFNayJObLPgwVsQcLCN/e1?= =?us-ascii?Q?N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4XbzTlAvlJwSN50ggTdMALp?= =?us-ascii?Q?9DJF/LRrTEd2C1tLSX2UA99saenhdaz3ixrwCYvin0e3oTd0XiG/vh4TZJkV?= =?us-ascii?Q?aUpI71iyX8CyJm9gs/BAvDI0UKEtxtT0t38mmJB4q0AAZNrdjtWQ/Y79xLRc?= =?us-ascii?Q?TxknPxMBOUcTtUOmxAZ5BWmWGuU3gZAVXpXeGPT1A0PQNxZvYI5UrXtRw6N1?= =?us-ascii?Q?3PHbx70nCElbQJXsh5RNT7wqtrMPA9Rof6ohvmjFyRJXgKe6zb0eLyGEZQLt?= =?us-ascii?Q?CiQOfkAjEtbh/mlWXsEAb1j9k3bCAhH+NCalKkc43ibn26MQQyeO6X+RyUZC?= =?us-ascii?Q?G5McJgYPdlEESY1aqJRvXBas/BzAwZo1BqVt+LMMQfjKqJtlBXO6P80oAiLN?= =?us-ascii?Q?Jled7Wxt3szQBw0TRs9rv34tLz+gbX2gv7MpQxjv0ZrO4H1f48gdFP4E3xCC?= =?us-ascii?Q?NMUt+nsYS1T4O/bAPsa38XRmSaRD4+EUHw/mj9f2q8ryXI7lyJHbXO3Qtg?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(36860700013)(376014)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2025 08:53:31.4634 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ccd66cff-9763-4de6-cccb-08ddef7e5a4e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF00004688.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7874 Content-Type: text/plain; charset="utf-8" Update update_pkt to use bpf_dynptr_slice_rdwr instead of accessing the packet data directly. This makes the test viable for drivers that do not store any packet data in the linear part when in multi-buffer mode. Signed-off-by: Nimrod Oren Reviewed-by: Carolina Jubran Reviewed-by: Dragos Tatulea --- .../selftests/net/lib/xdp_native.bpf.c | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/net/lib/xdp_native.bpf.c b/tools/testi= ng/selftests/net/lib/xdp_native.bpf.c index 71172d32c529..ff63f572552b 100644 --- a/tools/testing/selftests/net/lib/xdp_native.bpf.c +++ b/tools/testing/selftests/net/lib/xdp_native.bpf.c @@ -208,38 +208,41 @@ static int xdp_mode_tx_handler(struct xdp_md *ctx, __= u16 port) =20 static void *update_pkt(struct xdp_md *ctx, __s16 offset, __u32 *udp_csum) { - void *data_end =3D (void *)(long)ctx->data_end; - void *data =3D (void *)(long)ctx->data; struct udphdr *udph =3D NULL; - struct ethhdr *eth =3D data; + struct ethhdr *eth =3D NULL; + struct bpf_dynptr ptr; __u32 len, len_new; =20 - if (data + sizeof(*eth) > data_end) + bpf_dynptr_from_xdp(ctx, 0, &ptr); + eth =3D bpf_dynptr_slice(&ptr, 0, NULL, sizeof(*eth)); + if (!eth) return NULL; =20 if (eth->h_proto =3D=3D bpf_htons(ETH_P_IP)) { - struct iphdr *iph =3D data + sizeof(*eth); - __u16 total_len; - - if (iph + 1 > (struct iphdr *)data_end) + struct iphdr *iph =3D bpf_dynptr_slice_rdwr(&ptr, sizeof(*eth), + NULL, sizeof(*iph)); + if (!iph) return NULL; =20 iph->tot_len =3D bpf_htons(bpf_ntohs(iph->tot_len) + offset); =20 - udph =3D (void *)eth + sizeof(*iph) + sizeof(*eth); - if (!udph || udph + 1 > (struct udphdr *)data_end) + udph =3D bpf_dynptr_slice_rdwr(&ptr, sizeof(*iph) + sizeof(*eth), + NULL, sizeof(*udph)); + if (!udph) return NULL; =20 len_new =3D bpf_htons(bpf_ntohs(udph->len) + offset); } else if (eth->h_proto =3D=3D bpf_htons(ETH_P_IPV6)) { - struct ipv6hdr *ipv6h =3D data + sizeof(*eth); - __u16 payload_len; - - if (ipv6h + 1 > (struct ipv6hdr *)data_end) + struct ipv6hdr *ipv6h =3D + bpf_dynptr_slice_rdwr(&ptr, sizeof(*eth), + NULL, sizeof(*ipv6h)); + if (!ipv6h) return NULL; =20 - udph =3D (void *)eth + sizeof(*ipv6h) + sizeof(*eth); - if (!udph || udph + 1 > (struct udphdr *)data_end) + udph =3D bpf_dynptr_slice_rdwr(&ptr, + sizeof(*ipv6h) + sizeof(*eth), + NULL, sizeof(*udph)); + if (!udph) return NULL; =20 *udp_csum =3D ~((__u32)udph->check); --=20 2.45.0 From nobody Fri Oct 3 00:00:54 2025 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2077.outbound.protection.outlook.com [40.107.243.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9ACC12765DD; Tue, 9 Sep 2025 08:53:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757408022; cv=fail; b=s3VOYQeNHGGfA39+YFZuPqHFTsgoZ3BPMt+RWfzoS/sZ/1YnkkBt84ZOrKumlagrkURBjOfreyv+sVcfEby4ER/y0oMmTnQYJJaB5USmhe+AnHWRCypPqInSjMVU1AprQ+RPwEoLneVK2lqAU6ShrqmWxq9zHEQyybevuN6nECA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757408022; c=relaxed/simple; bh=aL97GVxM//EIu5XcWNXoEz5L11oBOT8ulClsSSRe1Xc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eLvzgRtXQIFds6ml14AsUpC5iv/dBaWjh8nUXgyV61t6KjGW1AJSrHeVCMC19cmEt8lZeYjZnaw7v3AVx0uXCexbT9DYQdZLQkiUW5ZM2n8mlkV1jGqxt4ze8bntH+nbcrTT2gikdF0eV0D7zz7shql47BELFFxRFdQiOW1VRSg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=k7+NoyFG; arc=fail smtp.client-ip=40.107.243.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="k7+NoyFG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NT+9KIv1PJKRxKcDScD+8dk+Ac9fGSt8bC1/G/9WpGvOq6ta70XeT8tWavCU4ov4Q9YxKG8LqrT6D0t63hfecoazuuDZidb7NmSkY5RR1Sgk2bsFhQ+Z3Wk0tJizfTBf64G+j9m46T1vuMyBilgHn+BCB8sShqCup3onYgRN/g2RLyKY9GwvKgMaGLLjE1lDjDD/Rb0P5X/5DBM0ijv2NUi/Kg3C3kWhyua7P02OwFf4UzGiqJIfl001NnGU64ZKhExK4CSD7s+k59sLT+0Ql6bj5u3O52vL3JvU0mgAoatkFVR/a7b5b9c/r9z9D4vmeLJgyXl6y23mnfP2abv3BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yBQBw2IiweZKwkwCJ4XjCwgaNzKFpnWNkz2w1FLLSgk=; b=PSXLX+fL/xCWsbQOpx1NDU9H4ILBEJKN7VFDta+aMwn4nRilG7j/YgEPcHDhXcVuzLf8ShlXlP10SfMylagZmC5Xq5PX/lO/e3cUtCs3NBrHWq8+FowUGKGZr6hVipInKQgCE1ghN08lEtK/hFD6BAv+Ld9LqGfWo1cf0NJ8z6+6XJFV61w7HSFIK5c+azbrBIE7mSizwWsWTZy9CD/UrbnUSQf1FjP6SQPUNeGEW4AKnEbsyEga/QnOob0RoFPMceXSeFehyIukIs2JAv2Nssm2jIT7tYpbrF2j803l7VL3nkUyKLl8XDI+SqUGt1kUV6Ywh1qPnkEJdDUAcfgUlA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yBQBw2IiweZKwkwCJ4XjCwgaNzKFpnWNkz2w1FLLSgk=; b=k7+NoyFGw/l1TBXLDUmigYyZTcNB3gbRXdpmC2gOpoKoTyCWFcPRD320ohEXevx6H8pQ7fO8tcqzDG1awf3Gy0ue1R591kYbMyz2KrlfnoN6/Bz6+hnSHPCJYeCunV4G/3j1182AuNO/EmQ8Tp/IlRCVjsVXEkPxi0NcN+DSt6oLgfrarrz8qEOCIEEcEzw6appsFEVaZ0sNdraFvC/8DaIpK94kZJ7gSJAS20ndYF/5PF6lR515gNudCb8dd5XR64XTsQIcyLFcWEba6n/vNHPLxhsQOQJ/d3VyAXfAt7OzFJ/3GRBaoVHqHDhVHNsEX9AsAGUQQf6kp2535yQ+Pw== Received: from BN9P223CA0007.NAMP223.PROD.OUTLOOK.COM (2603:10b6:408:10b::12) by DM4PR12MB7574.namprd12.prod.outlook.com (2603:10b6:8:10e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9094.22; Tue, 9 Sep 2025 08:53:37 +0000 Received: from BN1PEPF0000468D.namprd05.prod.outlook.com (2603:10b6:408:10b:cafe::df) by BN9P223CA0007.outlook.office365.com (2603:10b6:408:10b::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9115.15 via Frontend Transport; Tue, 9 Sep 2025 08:53:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BN1PEPF0000468D.mail.protection.outlook.com (10.167.243.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.13 via Frontend Transport; Tue, 9 Sep 2025 08:53:36 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Tue, 9 Sep 2025 01:53:21 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Tue, 9 Sep 2025 01:53:20 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Tue, 9 Sep 2025 01:53:16 -0700 From: Nimrod Oren To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , "John Fastabend" , Stanislav Fomichev , Mohsin Bashir CC: Dragos Tatulea , Tariq Toukan , Carolina Jubran , , , , , Nimrod Oren Subject: [PATCH RFC net-next 5/5] selftests: drv-net: Check XDP header data with bpf_dynptr Date: Tue, 9 Sep 2025 11:52:36 +0300 Message-ID: <20250909085236.2234306-6-noren@nvidia.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20250909085236.2234306-1-noren@nvidia.com> References: <20250909085236.2234306-1-noren@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000468D:EE_|DM4PR12MB7574:EE_ X-MS-Office365-Filtering-Correlation-Id: 31d56a85-0b92-418f-c40d-08ddef7e5d25 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|7416014|376014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?gUGzcn9bF00whcncEgZZ2X6bQPbcbBfOCHRDYU3jkoB/CIkctwNl1XYRnvkx?= =?us-ascii?Q?Ker9rX4eveyny3OcFmjBM572IogebtnYvSRMzuaBoFQpQz/13gWAuv0Ar2zd?= =?us-ascii?Q?ltq0pJuFGDEAkVxReG9RjiLNFjCQ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/iJGk/QJFj5ZBuoQ2JtbMqwh4gHYAtw81yfDUWIB1a+5HErNna13Fu9r8?= =?us-ascii?Q?yCV4eBx441gdhLGacZL6lTMh6H3NM7q3gteguLwVVgb8WgHkjFNykd987PLr?= =?us-ascii?Q?Qt7TCZfVXBt7+04CZreN8DlWXACo+wPsyHl458PkVkUmJXUTNH+JCITV1VuI?= =?us-ascii?Q?63OnylajTr/jl8MptnyIcve8s6yKEBccja9l8Hx3DpyPB2RFuQ7k+Tetyyop?= =?us-ascii?Q?QGAMOAOk8kjhwtAF8blIqToc4fiomHHd9KCSnBlQuIOdLSj6JhmvtPjrzpSK?= =?us-ascii?Q?s10HtXzC4uFTiZpn0n/h+Pz58lQLgakTGhDXczgSNtTdvLBzbVGtZ2p+r0VA?= =?us-ascii?Q?JLfGpNO56dYrROa6jzHOYLOh8gX2DeIJm7jmlA3ne51/+gW4YYQKnUa7RmsT?= =?us-ascii?Q?M4rxI2LBlE4annOF0D60p6WinOUGSYivhFSqMTjcyCZfzjFexI2Jx85soPpt?= =?us-ascii?Q?3EZHahVUu0GZwAwkJZvbCse4aU+rTKLCmGJGkridm6g8mXms/m4PI0jE3g?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(82310400026)(7416014)(376014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2025 08:53:36.2367 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 31d56a85-0b92-418f-c40d-08ddef7e5d25 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF0000468D.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7574 Content-Type: text/plain; charset="utf-8" Update filter_udphdr to use bpf_dynptr_slice to read the packet headers instead of accessing them directly. The function previously returned a pointer to the UDP header, which was then used to calculate Ethernet and IP header lengths by subtracting xdp->data. Since this only works when the UDP header is in the linear region, rework the function to return the total header length instead of a pointer. Rename filter_udphdr() to check_udphdr() to reflect the new behavior. This makes the test viable for drivers that do not store any packet data in the linear part when in multi-buffer mode. Signed-off-by: Nimrod Oren Reviewed-by: Carolina Jubran Reviewed-by: Dragos Tatulea --- .../selftests/net/lib/xdp_native.bpf.c | 80 +++++++------------ 1 file changed, 31 insertions(+), 49 deletions(-) diff --git a/tools/testing/selftests/net/lib/xdp_native.bpf.c b/tools/testi= ng/selftests/net/lib/xdp_native.bpf.c index ff63f572552b..6df5164e3791 100644 --- a/tools/testing/selftests/net/lib/xdp_native.bpf.c +++ b/tools/testing/selftests/net/lib/xdp_native.bpf.c @@ -63,53 +63,49 @@ static void record_stats(struct xdp_md *ctx, __u32 stat= _type) __sync_fetch_and_add(count, 1); } =20 -static struct udphdr *filter_udphdr(struct xdp_md *ctx, __u16 port) +static __u32 check_udphdr(struct xdp_md *ctx, __u16 port) { - void *data_end =3D (void *)(long)ctx->data_end; - void *data =3D (void *)(long)ctx->data; struct udphdr *udph =3D NULL; - struct ethhdr *eth =3D data; + struct ethhdr *eth =3D NULL; + struct bpf_dynptr ptr; =20 - if (data + sizeof(*eth) > data_end) - return NULL; + bpf_dynptr_from_xdp(ctx, 0, &ptr); + eth =3D bpf_dynptr_slice(&ptr, 0, NULL, sizeof(*eth)); + if (!eth) + return 0; =20 if (eth->h_proto =3D=3D bpf_htons(ETH_P_IP)) { - struct iphdr *iph =3D data + sizeof(*eth); + struct iphdr *iph =3D bpf_dynptr_slice(&ptr, sizeof(*eth), + NULL, sizeof(*iph)); =20 - if (iph + 1 > (struct iphdr *)data_end || - iph->protocol !=3D IPPROTO_UDP) - return NULL; + if (!iph || iph->protocol !=3D IPPROTO_UDP) + return 0; =20 - udph =3D (void *)eth + sizeof(*iph) + sizeof(*eth); - } else if (eth->h_proto =3D=3D bpf_htons(ETH_P_IPV6)) { - struct ipv6hdr *ipv6h =3D data + sizeof(*eth); + udph =3D bpf_dynptr_slice(&ptr, sizeof(*iph) + sizeof(*eth), + NULL, sizeof(*udph)); + } else if (eth->h_proto =3D=3D bpf_htons(ETH_P_IPV6)) { + struct ipv6hdr *ipv6h =3D bpf_dynptr_slice(&ptr, sizeof(*eth), + NULL, sizeof(*ipv6h)); =20 - if (ipv6h + 1 > (struct ipv6hdr *)data_end || - ipv6h->nexthdr !=3D IPPROTO_UDP) - return NULL; + if (!ipv6h || ipv6h->nexthdr !=3D IPPROTO_UDP) + return 0; =20 - udph =3D (void *)eth + sizeof(*ipv6h) + sizeof(*eth); + udph =3D bpf_dynptr_slice(&ptr, sizeof(*ipv6h) + sizeof(*eth), + NULL, sizeof(*udph)); } else { - return NULL; + return 0; } =20 - if (udph + 1 > (struct udphdr *)data_end) - return NULL; - - if (udph->dest !=3D bpf_htons(port)) - return NULL; + if (!udph || udph->dest !=3D bpf_htons(port)) + return 0; =20 record_stats(ctx, STATS_RX); - - return udph; + return (void *)udph - (void *)eth + sizeof(*udph); } =20 static int xdp_mode_pass(struct xdp_md *ctx, __u16 port) { - struct udphdr *udph =3D NULL; - - udph =3D filter_udphdr(ctx, port); - if (!udph) + if (!check_udphdr(ctx, port)) return XDP_PASS; =20 record_stats(ctx, STATS_PASS); @@ -119,10 +115,7 @@ static int xdp_mode_pass(struct xdp_md *ctx, __u16 por= t) =20 static int xdp_mode_drop_handler(struct xdp_md *ctx, __u16 port) { - struct udphdr *udph =3D NULL; - - udph =3D filter_udphdr(ctx, port); - if (!udph) + if (!check_udphdr(ctx, port)) return XDP_PASS; =20 record_stats(ctx, STATS_DROP); @@ -363,19 +356,14 @@ static int xdp_adjst_tail_grow_data(struct xdp_md *ct= x, __u16 offset) =20 static int xdp_adjst_tail(struct xdp_md *ctx, __u16 port) { - void *data =3D (void *)(long)ctx->data; - struct udphdr *udph =3D NULL; - __s32 *adjust_offset, *val; + __s32 *adjust_offset; __u32 key, hdr_len; - void *offset_ptr; - __u8 tag; int ret; =20 - udph =3D filter_udphdr(ctx, port); - if (!udph) + hdr_len =3D check_udphdr(ctx, port); + if (!hdr_len) return XDP_PASS; =20 - hdr_len =3D (void *)udph - data + sizeof(struct udphdr); key =3D XDP_ADJST_OFFSET; adjust_offset =3D bpf_map_lookup_elem(&map_xdp_setup, &key); if (!adjust_offset) @@ -504,20 +492,14 @@ static int xdp_adjst_head_grow_data(struct xdp_md *ct= x, __u64 hdr_len, =20 static int xdp_head_adjst(struct xdp_md *ctx, __u16 port) { - void *data_end =3D (void *)(long)ctx->data_end; - void *data =3D (void *)(long)ctx->data; - struct udphdr *udph_ptr =3D NULL; __u32 key, size, hdr_len; __s32 *val; int res; =20 - /* Filter packets based on UDP port */ - udph_ptr =3D filter_udphdr(ctx, port); - if (!udph_ptr) + hdr_len =3D check_udphdr(ctx, port); + if (!hdr_len) return XDP_PASS; =20 - hdr_len =3D (void *)udph_ptr - data + sizeof(struct udphdr); - key =3D XDP_ADJST_OFFSET; val =3D bpf_map_lookup_elem(&map_xdp_setup, &key); if (!val) --=20 2.45.0