diff mbox series

[RFC,bpf-next,20/52] net, xdp: move XDP metadata helpers into new xdp_meta.h

Message ID 20220628194812.1453059-21-alexandr.lobakin@intel.com (mailing list archive)
State RFC
Delegated to: BPF
Headers show
Series bpf, xdp: introduce and use Generic Hints/metadata | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-1 fail Logs for Kernel LATEST on ubuntu-latest with gcc
bpf/vmtest-bpf-next-VM_Test-2 fail Logs for Kernel LATEST on ubuntu-latest with llvm-15
bpf/vmtest-bpf-next-VM_Test-3 fail Logs for Kernel LATEST on z15 with gcc
netdev/tree_selection success Clearly marked for bpf-next, async
netdev/apply fail Patch does not apply to bpf-next

Commit Message

Alexander Lobakin June 28, 2022, 7:47 p.m. UTC
<net/xdp.h> gets included indirectly into tons of different files
across the kernel. To not make them dependent on the header files
needed for the XDP metadata definitions, which will be used only
by several driver and XDP core files, and have the metadata code
logically separated, create a new header file, <net/xdp_meta.h>,
and move several already existing metadata helpers to it.

Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
---
 MAINTAINERS                                   |  1 +
 .../ethernet/mellanox/mlx5/core/en/xsk/rx.c   |  1 +
 drivers/net/ethernet/netronome/nfp/nfd3/xsk.c |  1 +
 drivers/net/tun.c                             |  2 +-
 include/net/xdp.h                             | 20 -------------
 include/net/xdp_meta.h                        | 29 +++++++++++++++++++
 net/bpf/core.c                                |  2 +-
 net/bpf/prog_ops.c                            |  1 +
 net/bpf/test_run.c                            |  2 +-
 net/xdp/xsk.c                                 |  2 +-
 10 files changed, 37 insertions(+), 24 deletions(-)
 create mode 100644 include/net/xdp_meta.h
diff mbox series

Patch

diff --git a/MAINTAINERS b/MAINTAINERS
index 91190e12a157..24a640c8a306 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -21722,6 +21722,7 @@  L:	netdev@vger.kernel.org
 L:	bpf@vger.kernel.org
 S:	Supported
 F:	include/net/xdp.h
+F:	include/net/xdp_meta.h
 F:	include/net/xdp_priv.h
 F:	include/trace/events/xdp.h
 F:	kernel/bpf/cpumap.c
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.c
index 9a1553598a7c..c1fc5c79d90f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.c
@@ -3,6 +3,7 @@ 
 
 #include "rx.h"
 #include "en/xdp.h"
+#include <net/xdp_meta.h>
 #include <net/xdp_sock_drv.h>
 #include <linux/filter.h>
 
diff --git a/drivers/net/ethernet/netronome/nfp/nfd3/xsk.c b/drivers/net/ethernet/netronome/nfp/nfd3/xsk.c
index 454fea4c8be2..0957e866799b 100644
--- a/drivers/net/ethernet/netronome/nfp/nfd3/xsk.c
+++ b/drivers/net/ethernet/netronome/nfp/nfd3/xsk.c
@@ -4,6 +4,7 @@ 
 
 #include <linux/bpf_trace.h>
 #include <linux/netdevice.h>
+#include <net/xdp_meta.h>
 
 #include "../nfp_app.h"
 #include "../nfp_net.h"
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 87a635aac008..0eb0cc6966e4 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -61,7 +61,7 @@ 
 #include <net/netns/generic.h>
 #include <net/rtnetlink.h>
 #include <net/sock.h>
-#include <net/xdp.h>
+#include <net/xdp_meta.h>
 #include <net/ip_tunnels.h>
 #include <linux/seq_file.h>
 #include <linux/uio.h>
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 7b8ba068d28a..1663d0b3a05a 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -378,26 +378,6 @@  int xdp_reg_mem_model(struct xdp_mem_info *mem,
 		      enum xdp_mem_type type, void *allocator);
 void xdp_unreg_mem_model(struct xdp_mem_info *mem);
 
-/* Drivers not supporting XDP metadata can use this helper, which
- * rejects any room expansion for metadata as a result.
- */
-static __always_inline void
-xdp_set_data_meta_invalid(struct xdp_buff *xdp)
-{
-	xdp->data_meta = xdp->data + 1;
-}
-
-static __always_inline bool
-xdp_data_meta_unsupported(const struct xdp_buff *xdp)
-{
-	return unlikely(xdp->data_meta > xdp->data);
-}
-
-static inline bool xdp_metalen_invalid(unsigned long metalen)
-{
-	return (metalen & (sizeof(__u32) - 1)) || (metalen > 32);
-}
-
 struct xdp_attachment_info {
 	struct bpf_prog *prog;
 	u64 btf_id;
diff --git a/include/net/xdp_meta.h b/include/net/xdp_meta.h
new file mode 100644
index 000000000000..e1f3df9ceb93
--- /dev/null
+++ b/include/net/xdp_meta.h
@@ -0,0 +1,29 @@ 
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2022, Intel Corporation. */
+
+#ifndef __LINUX_NET_XDP_META_H__
+#define __LINUX_NET_XDP_META_H__
+
+#include <net/xdp.h>
+
+/* Drivers not supporting XDP metadata can use this helper, which
+ * rejects any room expansion for metadata as a result.
+ */
+static __always_inline void
+xdp_set_data_meta_invalid(struct xdp_buff *xdp)
+{
+	xdp->data_meta = xdp->data + 1;
+}
+
+static __always_inline bool
+xdp_data_meta_unsupported(const struct xdp_buff *xdp)
+{
+	return unlikely(xdp->data_meta > xdp->data);
+}
+
+static inline bool xdp_metalen_invalid(unsigned long metalen)
+{
+	return (metalen & (sizeof(__u32) - 1)) || (metalen > 32);
+}
+
+#endif /* __LINUX_NET_XDP_META_H__ */
diff --git a/net/bpf/core.c b/net/bpf/core.c
index dcd3b6ae86b7..18174d6d8687 100644
--- a/net/bpf/core.c
+++ b/net/bpf/core.c
@@ -14,7 +14,7 @@ 
 #include <linux/bug.h>
 #include <net/page_pool.h>
 
-#include <net/xdp.h>
+#include <net/xdp_meta.h>
 #include <net/xdp_priv.h> /* struct xdp_mem_allocator */
 #include <trace/events/xdp.h>
 #include <net/xdp_sock_drv.h>
diff --git a/net/bpf/prog_ops.c b/net/bpf/prog_ops.c
index 33f02842e715..bf174b8d8a36 100644
--- a/net/bpf/prog_ops.c
+++ b/net/bpf/prog_ops.c
@@ -2,6 +2,7 @@ 
 
 #include <linux/btf.h>
 #include <linux/btf_ids.h>
+#include <net/xdp_meta.h>
 #include <net/xdp_sock.h>
 #include <trace/events/xdp.h>
 
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 2ca96acbc50a..596b523ccced 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -19,7 +19,7 @@ 
 #include <linux/error-injection.h>
 #include <linux/smp.h>
 #include <linux/sock_diag.h>
-#include <net/xdp.h>
+#include <net/xdp_meta.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/bpf_test_run.h>
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 19ac872a6624..ebf6a67424cd 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -24,7 +24,7 @@ 
 #include <linux/rculist.h>
 #include <net/xdp_sock_drv.h>
 #include <net/busy_poll.h>
-#include <net/xdp.h>
+#include <net/xdp_meta.h>
 
 #include "xsk_queue.h"
 #include "xdp_umem.h"