Article View: linux.kernel.netdev
Article #4412[PATCH 6.6 1019/1674] bpf: make it easier to add new metadata kfunc
From: Greg Kroah-Hartman
Date: Sat, 17 Oct 2026 15:54
Date: Sat, 17 Oct 2026 15:54
107 lines
9111 bytes
9111 bytes
6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanislav Fomichev <sdf@google.com>
[ Upstream commit fc45c5b642dbcac3bb10f4f904e4b863233e5369 ]
No functional changes.
Instead of having hand-crafted code in bpf_dev_bound_resolve_kfunc,
move kfunc <> xmo handler relationship into XDP_METADATA_KFUNC_xxx.
This way, any time new kfunc is added, we don't have to touch
bpf_dev_bound_resolve_kfunc.
Also document XDP_METADATA_KFUNC_xxx arguments since we now have
more than two and it might be confusing what is what.
Cc: netdev@vger.kernel.org
Cc: Willem de Bruijn <willemb@google.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/r/20230913171350.369987-2-sdf@google.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Stable-dep-of: b69004f5a6ad ("net/mlx5e: xsk: Fix DMA and xdp_frame leak on XDP_TX xmit failure")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
include/net/xdp.h | 16 ++++++++++++----
kernel/bpf/offload.c | 9 +++++----
net/core/xdp.c | 4 ++--
3 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 3d8989096b5d2..59c12ca580396 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -388,14 +388,22 @@ void xdp_attachment_setup(struct xdp_attachment_info *info,
#define DEV_MAP_BULK_SIZE XDP_BULK_QUEUE_SIZE
+/* Define the relationship between xdp-rx-metadata kfunc and
+ * various other entities:
+ * - xdp_rx_metadata enum
+ * - kfunc name
+ * - xdp_metadata_ops field
+ */
#define XDP_METADATA_KFUNC_xxx \
XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_TIMESTAMP, \
- bpf_xdp_metadata_rx_timestamp) \
+ bpf_xdp_metadata_rx_timestamp, \
+ xmo_rx_timestamp) \
XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_HASH, \
- bpf_xdp_metadata_rx_hash) \
+ bpf_xdp_metadata_rx_hash, \
+ xmo_rx_hash) \
-enum {
-#define XDP_METADATA_KFUNC(name, _) name,
+enum xdp_rx_metadata {
+#define XDP_METADATA_KFUNC(name, _, __) name,
XDP_METADATA_KFUNC_xxx
#undef XDP_METADATA_KFUNC
MAX_XDP_METADATA_KFUNC,
diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c
index 3345de2da15dd..ae0c8e7894586 100644
--- a/kernel/bpf/offload.c
+++ b/kernel/bpf/offload.c
@@ -847,10 +847,11 @@ void *bpf_dev_bound_resolve_kfunc(struct bpf_prog *prog, u32 func_id)
if (!ops)
goto out;
- if (func_id == bpf_xdp_metadata_kfunc_id(XDP_METADATA_KFUNC_RX_TIMESTAMP))
- p = ops->xmo_rx_timestamp;
- else if (func_id == bpf_xdp_metadata_kfunc_id(XDP_METADATA_KFUNC_RX_HASH))
- p = ops->xmo_rx_hash;
+#define XDP_METADATA_KFUNC(name, _, xmo) \
+ if (func_id == bpf_xdp_metadata_kfunc_id(name)) p = ops->xmo;
+ XDP_METADATA_KFUNC_xxx
+#undef XDP_METADATA_KFUNC
+
out:
up_read(&bpf_devs_lock);
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 672d971ce4eac..0b312aa7adf5e 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -737,7 +737,7 @@ __bpf_kfunc int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, u32 *hash,
__diag_pop();
BTF_SET8_START(xdp_metadata_kfunc_ids)
-#define XDP_METADATA_KFUNC(_, name) BTF_ID_FLAGS(func, name, KF_TRUSTED_ARGS)
+#define XDP_METADATA_KFUNC(_, name, __) BTF_ID_FLAGS(func, name, KF_TRUSTED_ARGS)
XDP_METADATA_KFUNC_xxx
#undef XDP_METADATA_KFUNC
BTF_SET8_END(xdp_metadata_kfunc_ids)
@@ -748,7 +748,7 @@ static const struct btf_kfunc_id_set xdp_metadata_kfunc_set = {
};
BTF_ID_LIST(xdp_metadata_kfunc_ids_unsorted)
-#define XDP_METADATA_KFUNC(name, str) BTF_ID(func, str)
+#define XDP_METADATA_KFUNC(name, str, _) BTF_ID(func, str)
XDP_METADATA_KFUNC_xxx
#undef XDP_METADATA_KFUNC
--
2.53.0
Technical Details
Message-ID:
<20261017160457.287623687@linuxfoundation.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-347842-linux-kernel-netdev=dewy.ruReferences:
<20261017160431.119607952@linuxfoundation.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-347842-linux-kernel-netdev=dewy.ru From: gregkh@linuxfoundation.org (Greg Kroah-Hartman) Newsgroups: linux.kernel.netdev Subject: [PATCH 6.6 1019/1674] bpf: make it easier to add new metadata kfunc Date: Sat, 17 Oct 2026 17:54:51 +0200 Organization: Usenet Network Message-ID: <20261017160457.287623687@linuxfoundation.org> References: <20261017160431.119607952@linuxfoundation.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3102314"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:Y04jD5FkVaBK4yPaFH1qYh0zdII= sha256:fikDGugr8ego31wXYeYBNU/s20vlApNXRrzS4s5hviM= sha1:tq6zGqO5uAqNSGxTua1ZjbATQnw= sha256:5AcyKbQtIzk0o07+xahDsn/C8BmRtPXyb5ODGSKsuiU= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 0DCCD11074E; Sat, 17 Oct 2026 20:57:39 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.289 X-Spam-Status: No, score=-3.289 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=linuxfoundation.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8lStd3oUH64q; Sat, 17 Oct 2026 20:57:35 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-347842-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linuxfoundation.org X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 410C011072A; Sat, 17 Oct 2026 20:57:26 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sin.lore.kernel.org (Postfix) with ESMTP id 28CF82EF93; Sat, 17 Oct 2026 17:42:55 +0000 (UTC) X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 215373BF699; Sat, 17 Oct 2026 17:42:54 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="pCyduE1c" X-Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 084DA3B9616; Sat, 17 Oct 2026 17:42:53 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792258974; cv=none; b=kkM19zU2zIHbfNqc7rasd+X6/l/939sOBZBHdINWJuXJn08uQNWjrs8BSW2IOOWqRkq084NByH6pl9jOjXMqfrGIcDxVtPjOnBDVmEB5vZHuMzAicytOhB+ywcB8zMe3TfTKEVePuveIi/oCoi+PtmbQA+cf3WFXUxbWNHoLBAE= X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792258974; c=relaxed/simple; bh=zAcNSF9NXfYRdVLYuA651wLj1YveIAbUesA3p0dzfkM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pZi2NvZ2+UShxdkdBSRJtIT4MzoZoT/TqJS4Kow/NwONKs4OlzgxF0zEX9z3Syp197jpxFFFIa/bb4HFU+EmcgQRqgJKQzXWsO9aXp1Q43HgLzHc0Gi2qawePhsSAAK0NCuvioTPeTEYAY7ZCDBjmTzEkKrGysyo1rdHdfPHnXc= X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=pCyduE1c; arc=none smtp.client-ip=100.103.45.18 X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 606181F000C4; Sat, 17 Oct 2026 17:42:52 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792258972; bh=L7ZW1L3kMLvIXx2XJ3hJ+1FddkEVjq+j2WIovfWvCug=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pCyduE1c11x1PW20nVICJ1pq3tEgd7MbpsfudILMmDGgHvLo2BU3xEiWvJ1vQk1YV S9KGjJ7rlXBVIxN2uhRXsByRr5ibjHIsGpOi5KfARZPuABprONwmdaw1hoIhHLNMt+ LQHRNuvGtnTktvQOxTdLkXvudZ0wfTktsKMUolQc= X-Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, patches@lists.linux.dev, netdev@vger.kernel.org, Willem de Bruijn <willemb@google.com>, Stanislav Fomichev <sdf@google.com>, Martin KaFai Lau <martin.lau@kernel.org>, Sasha Levin <sashal@kernel.org> X-Mailer: git-send-email 2.56.0 X-In-Reply-To: <20261017160431.119607952@linuxfoundation.org> X-User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Precedence: bulk X-Mailing-List: netdev@vger.kernel.org X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>