Skip to content

Commit

Permalink
bpf: split eBPF out of NET
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Daniel Borkmann <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Alexei Starovoitov authored and davem330 committed Oct 27, 2014
1 parent 8ae3c91 commit f89b775
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
14 changes: 14 additions & 0 deletions init/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,10 @@ config SYSCTL_ARCH_UNALIGN_ALLOW
config HAVE_PCSPKR_PLATFORM
bool

# interpreter that classic socket filters depend on
config BPF
bool

menuconfig EXPERT
bool "Configure standard kernel features (expert users)"
# Unhide debug options, to make the on-by-default options visible
Expand Down Expand Up @@ -1521,6 +1525,16 @@ config EVENTFD

If unsure, say Y.

# syscall, maps, verifier
config BPF_SYSCALL
bool "Enable bpf() system call" if EXPERT
select ANON_INODES
select BPF
default n
help
Enable the bpf() system call that allows to manipulate eBPF
programs and maps via file descriptors.

config SHMEM
bool "Use full shmem filesystem" if EXPERT
default y
Expand Down
2 changes: 1 addition & 1 deletion kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ obj-$(CONFIG_RING_BUFFER) += trace/
obj-$(CONFIG_TRACEPOINTS) += trace/
obj-$(CONFIG_IRQ_WORK) += irq_work.o
obj-$(CONFIG_CPU_PM) += cpu_pm.o
obj-$(CONFIG_NET) += bpf/
obj-$(CONFIG_BPF) += bpf/

obj-$(CONFIG_PERF_EVENTS) += events/

Expand Down
6 changes: 3 additions & 3 deletions kernel/bpf/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
obj-y := core.o syscall.o verifier.o

obj-y := core.o
obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o
ifdef CONFIG_TEST_BPF
obj-y += test_stub.o
obj-$(CONFIG_BPF_SYSCALL) += test_stub.o
endif
9 changes: 9 additions & 0 deletions kernel/bpf/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,12 @@ void bpf_prog_free(struct bpf_prog *fp)
schedule_work(&aux->work);
}
EXPORT_SYMBOL_GPL(bpf_prog_free);

/* To execute LD_ABS/LD_IND instructions __bpf_prog_run() may call
* skb_copy_bits(), so provide a weak definition of it for NET-less config.
*/
int __weak skb_copy_bits(const struct sk_buff *skb, int offset, void *to,
int len)
{
return -EFAULT;
}
2 changes: 1 addition & 1 deletion net/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ menuconfig NET
bool "Networking support"
select NLATTR
select GENERIC_NET_UTILS
select ANON_INODES
select BPF
---help---
Unless you really know what you are doing, you should say Y here.
The reason is that some programs need kernel networking support even
Expand Down

0 comments on commit f89b775

Please sign in to comment.