Skip to content

Commit

Permalink
net, xdp: move XDP metadata helpers into new xdp_meta.h
Browse files Browse the repository at this point in the history
<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>
  • Loading branch information
alobakin committed Jun 28, 2022
1 parent 2a065c7 commit 62a8828
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 24 deletions.
1 change: 1 addition & 0 deletions MAINTAINERS
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.c
Expand Up @@ -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>

Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/netronome/nfp/nfd3/xsk.c
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/tun.c
Expand Up @@ -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>
Expand Down
20 changes: 0 additions & 20 deletions include/net/xdp.h
Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions 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__ */
2 changes: 1 addition & 1 deletion net/bpf/core.c
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions net/bpf/prog_ops.c
Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion net/bpf/test_run.c
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion net/xdp/xsk.c
Expand Up @@ -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"
Expand Down

0 comments on commit 62a8828

Please sign in to comment.