Skip to content

Commit

Permalink
net, xdp: decouple XDP code from the core networking code
Browse files Browse the repository at this point in the history
Currently, there are a couple of rather big pieces of purely XDP
code residing in `net/core/dev.c` and `net/core/filter.c`, and they
won't get smaller any time soon.
To make it more scalable, move them to the new separate files inside
`net/bpf/`, which is almost empty now, along with `net/core/xdp.c`.
This goes so well so that we only had to make 3 functions global
which were static previously (+1 static key). The only mentions of
XDP left in `filter.c` are helpers which share code with the skb
variants and it would cost much more to make the shared code global
instead.

Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
  • Loading branch information
alobakin committed Jun 28, 2022
1 parent ed5f418 commit 40ce0c8
Show file tree
Hide file tree
Showing 11 changed files with 1,705 additions and 1,660 deletions.
4 changes: 3 additions & 1 deletion MAINTAINERS
Expand Up @@ -21726,7 +21726,9 @@ F: include/net/xdp_priv.h
F: include/trace/events/xdp.h
F: kernel/bpf/cpumap.c
F: kernel/bpf/devmap.c
F: net/core/xdp.c
F: net/bpf/core.c
F: net/bpf/dev.c
F: net/bpf/prog_ops.c
F: samples/bpf/xdp*
F: tools/testing/selftests/bpf/*xdp*
F: tools/testing/selftests/bpf/*/*xdp*
Expand Down
2 changes: 2 additions & 0 deletions include/linux/filter.h
Expand Up @@ -992,6 +992,8 @@ void xdp_do_flush(void);
#define xdp_do_flush_map xdp_do_flush

void bpf_warn_invalid_xdp_action(struct net_device *dev, struct bpf_prog *prog, u32 act);
const struct bpf_func_proto *xdp_inet_func_proto(enum bpf_func_id func_id);
bool xdp_helper_changes_pkt_data(const void *func);

#ifdef CONFIG_INET
struct sock *bpf_run_sk_reuseport(struct sock_reuseport *reuse, struct sock *sk,
Expand Down
5 changes: 5 additions & 0 deletions include/linux/netdevice.h
Expand Up @@ -3848,7 +3848,12 @@ struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *d
struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
struct netdev_queue *txq, int *ret);

DECLARE_STATIC_KEY_FALSE(generic_xdp_needed_key);

int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
int fd, int expected_fd, u32 flags);
void dev_xdp_uninstall(struct net_device *dev);
u8 dev_xdp_prog_count(struct net_device *dev);
u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode);

Expand Down
5 changes: 4 additions & 1 deletion net/bpf/Makefile
@@ -1,5 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_BPF_SYSCALL) := test_run.o

obj-y := core.o dev.o prog_ops.o

obj-$(CONFIG_BPF_SYSCALL) += test_run.o
ifeq ($(CONFIG_BPF_JIT),y)
obj-$(CONFIG_BPF_SYSCALL) += bpf_dummy_struct_ops.o
endif
2 changes: 1 addition & 1 deletion net/core/xdp.c → net/bpf/core.c
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only
/* net/core/xdp.c
/* net/bpf/core.c
*
* Copyright (c) 2017 Jesper Dangaard Brouer, Red Hat Inc.
*/
Expand Down

0 comments on commit 40ce0c8

Please sign in to comment.