Skip to content

Commit f89b775

Browse files
Alexei Starovoitovdavem330
authored andcommitted
bpf: split eBPF out of NET
introduce two configs: - hidden CONFIG_BPF to select eBPF interpreter that classic socket filters depend on - visible CONFIG_BPF_SYSCALL (default off) that tracing and sockets can use that solves several problems: - tracing and others that wish to use eBPF don't need to depend on NET. They can use BPF_SYSCALL to allow loading from userspace or select BPF to use it directly from kernel in NET-less configs. - in 3.18 programs cannot be attached to events yet, so don't force it on - when the rest of eBPF infra is there in 3.19+, it's still useful to switch it off to minimize kernel size bloat-o-meter on x64 shows: add/remove: 0/60 grow/shrink: 0/2 up/down: 0/-15601 (-15601) tested with many different config combinations. Hopefully didn't miss anything. Signed-off-by: Alexei Starovoitov <ast@plumgrid.com> Acked-by: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8ae3c91 commit f89b775

5 files changed

Lines changed: 28 additions & 5 deletions

File tree

‎init/Kconfig‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,10 @@ config SYSCTL_ARCH_UNALIGN_ALLOW
13411341
config HAVE_PCSPKR_PLATFORM
13421342
bool
13431343

1344+
# interpreter that classic socket filters depend on
1345+
config BPF
1346+
bool
1347+
13441348
menuconfig EXPERT
13451349
bool "Configure standard kernel features (expert users)"
13461350
# Unhide debug options, to make the on-by-default options visible
@@ -1521,6 +1525,16 @@ config EVENTFD
15211525

15221526
If unsure, say Y.
15231527

1528+
# syscall, maps, verifier
1529+
config BPF_SYSCALL
1530+
bool "Enable bpf() system call" if EXPERT
1531+
select ANON_INODES
1532+
select BPF
1533+
default n
1534+
help
1535+
Enable the bpf() system call that allows to manipulate eBPF
1536+
programs and maps via file descriptors.
1537+
15241538
config SHMEM
15251539
bool "Use full shmem filesystem" if EXPERT
15261540
default y

‎kernel/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ obj-$(CONFIG_RING_BUFFER) += trace/
8686
obj-$(CONFIG_TRACEPOINTS) += trace/
8787
obj-$(CONFIG_IRQ_WORK) += irq_work.o
8888
obj-$(CONFIG_CPU_PM) += cpu_pm.o
89-
obj-$(CONFIG_NET) += bpf/
89+
obj-$(CONFIG_BPF) += bpf/
9090

9191
obj-$(CONFIG_PERF_EVENTS) += events/
9292

‎kernel/bpf/Makefile‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
obj-y := core.o syscall.o verifier.o
2-
1+
obj-y := core.o
2+
obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o
33
ifdef CONFIG_TEST_BPF
4-
obj-y += test_stub.o
4+
obj-$(CONFIG_BPF_SYSCALL) += test_stub.o
55
endif

‎kernel/bpf/core.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,3 +655,12 @@ void bpf_prog_free(struct bpf_prog *fp)
655655
schedule_work(&aux->work);
656656
}
657657
EXPORT_SYMBOL_GPL(bpf_prog_free);
658+
659+
/* To execute LD_ABS/LD_IND instructions __bpf_prog_run() may call
660+
* skb_copy_bits(), so provide a weak definition of it for NET-less config.
661+
*/
662+
int __weak skb_copy_bits(const struct sk_buff *skb, int offset, void *to,
663+
int len)
664+
{
665+
return -EFAULT;
666+
}

‎net/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ menuconfig NET
66
bool "Networking support"
77
select NLATTR
88
select GENERIC_NET_UTILS
9-
select ANON_INODES
9+
select BPF
1010
---help---
1111
Unless you really know what you are doing, you should say Y here.
1212
The reason is that some programs need kernel networking support even

0 commit comments

Comments
 (0)