License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2018-05-15 13:35:04 +08:00
|
|
|
|
|
|
|
BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src))
|
|
|
|
TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools
|
|
|
|
|
bpf: mini eBPF library, test stubs and verifier testsuite
1.
the library includes a trivial set of BPF syscall wrappers:
int bpf_create_map(int key_size, int value_size, int max_entries);
int bpf_update_elem(int fd, void *key, void *value);
int bpf_lookup_elem(int fd, void *key, void *value);
int bpf_delete_elem(int fd, void *key);
int bpf_get_next_key(int fd, void *key, void *next_key);
int bpf_prog_load(enum bpf_prog_type prog_type,
const struct sock_filter_int *insns, int insn_len,
const char *license);
bpf_prog_load() stores verifier log into global bpf_log_buf[] array
and BPF_*() macros to build instructions
2.
test stubs configure eBPF infra with 'unspec' map and program types.
These are fake types used by user space testsuite only.
3.
verifier tests valid and invalid programs and expects predefined
error log messages from kernel.
40 tests so far.
$ sudo ./test_verifier
#0 add+sub+mul OK
#1 unreachable OK
#2 unreachable2 OK
#3 out of range jump OK
#4 out of range jump2 OK
#5 test1 ld_imm64 OK
...
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-09-26 15:17:07 +08:00
|
|
|
# List of programs to build
|
2019-10-11 08:28:01 +08:00
|
|
|
tprogs-y := test_lru_dist
|
|
|
|
tprogs-y += sock_example
|
|
|
|
tprogs-y += fds_example
|
|
|
|
tprogs-y += sockex1
|
|
|
|
tprogs-y += sockex2
|
|
|
|
tprogs-y += sockex3
|
|
|
|
tprogs-y += tracex1
|
|
|
|
tprogs-y += tracex2
|
|
|
|
tprogs-y += tracex3
|
|
|
|
tprogs-y += tracex4
|
|
|
|
tprogs-y += tracex5
|
|
|
|
tprogs-y += tracex6
|
|
|
|
tprogs-y += tracex7
|
|
|
|
tprogs-y += test_probe_write_user
|
|
|
|
tprogs-y += trace_output
|
|
|
|
tprogs-y += lathist
|
|
|
|
tprogs-y += offwaketime
|
|
|
|
tprogs-y += spintest
|
|
|
|
tprogs-y += map_perf_test
|
|
|
|
tprogs-y += test_overhead
|
|
|
|
tprogs-y += test_cgrp2_array_pin
|
|
|
|
tprogs-y += test_cgrp2_attach
|
|
|
|
tprogs-y += test_cgrp2_sock
|
|
|
|
tprogs-y += test_cgrp2_sock2
|
|
|
|
tprogs-y += xdp1
|
|
|
|
tprogs-y += xdp2
|
|
|
|
tprogs-y += xdp_router_ipv4
|
|
|
|
tprogs-y += test_current_task_under_cgroup
|
|
|
|
tprogs-y += trace_event
|
|
|
|
tprogs-y += sampleip
|
|
|
|
tprogs-y += tc_l2_redirect
|
|
|
|
tprogs-y += lwt_len_hist
|
|
|
|
tprogs-y += xdp_tx_iptunnel
|
|
|
|
tprogs-y += test_map_in_map
|
2019-12-16 15:16:19 +08:00
|
|
|
tprogs-y += per_socket_stats_example
|
2019-10-11 08:28:01 +08:00
|
|
|
tprogs-y += xdp_rxq_info
|
|
|
|
tprogs-y += syscall_tp
|
|
|
|
tprogs-y += cpustat
|
|
|
|
tprogs-y += xdp_adjust_tail
|
|
|
|
tprogs-y += xdpsock
|
2020-12-03 17:05:46 +08:00
|
|
|
tprogs-y += xdpsock_ctrl_proc
|
2020-08-28 16:26:28 +08:00
|
|
|
tprogs-y += xsk_fwd
|
2019-10-11 08:28:01 +08:00
|
|
|
tprogs-y += xdp_fwd
|
|
|
|
tprogs-y += task_fd_query
|
|
|
|
tprogs-y += xdp_sample_pkts
|
|
|
|
tprogs-y += ibumad
|
|
|
|
tprogs-y += hbm
|
bpf: mini eBPF library, test stubs and verifier testsuite
1.
the library includes a trivial set of BPF syscall wrappers:
int bpf_create_map(int key_size, int value_size, int max_entries);
int bpf_update_elem(int fd, void *key, void *value);
int bpf_lookup_elem(int fd, void *key, void *value);
int bpf_delete_elem(int fd, void *key);
int bpf_get_next_key(int fd, void *key, void *next_key);
int bpf_prog_load(enum bpf_prog_type prog_type,
const struct sock_filter_int *insns, int insn_len,
const char *license);
bpf_prog_load() stores verifier log into global bpf_log_buf[] array
and BPF_*() macros to build instructions
2.
test stubs configure eBPF infra with 'unspec' map and program types.
These are fake types used by user space testsuite only.
3.
verifier tests valid and invalid programs and expects predefined
error log messages from kernel.
40 tests so far.
$ sudo ./test_verifier
#0 add+sub+mul OK
#1 unreachable OK
#2 unreachable2 OK
#3 out of range jump OK
#4 out of range jump2 OK
#5 test1 ld_imm64 OK
...
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-09-26 15:17:07 +08:00
|
|
|
|
2021-08-21 08:20:06 +08:00
|
|
|
tprogs-y += xdp_redirect_cpu
|
2021-08-21 08:20:10 +08:00
|
|
|
tprogs-y += xdp_redirect_map_multi
|
2021-08-21 08:20:08 +08:00
|
|
|
tprogs-y += xdp_redirect_map
|
2021-08-21 08:20:04 +08:00
|
|
|
tprogs-y += xdp_redirect
|
2021-08-21 08:20:02 +08:00
|
|
|
tprogs-y += xdp_monitor
|
|
|
|
|
samples/bpf: Switch over to libbpf
Now that libbpf under tools/lib/bpf/* is synced with the version from
samples/bpf, we can get rid most of the libbpf library here.
Committer notes:
Built it in a docker fedora rawhide container and ran it in the f25 host, seems
to work just like it did before this patch, i.e. the switch to tools/lib/bpf/
doesn't seem to have introduced problems and Joe said he tested it with
all the entries in samples/bpf/ and other code he found:
[root@f5065a7d6272 linux]# make -j4 O=/tmp/build/linux headers_install
<SNIP>
[root@f5065a7d6272 linux]# rm -rf /tmp/build/linux/samples/bpf/
[root@f5065a7d6272 linux]# make -j4 O=/tmp/build/linux samples/bpf/
make[1]: Entering directory '/tmp/build/linux'
CHK include/config/kernel.release
HOSTCC scripts/basic/fixdep
GEN ./Makefile
CHK include/generated/uapi/linux/version.h
Using /git/linux as source for kernel
CHK include/generated/utsrelease.h
HOSTCC scripts/basic/bin2c
HOSTCC arch/x86/tools/relocs_32.o
HOSTCC arch/x86/tools/relocs_64.o
LD samples/bpf/built-in.o
<SNIP>
HOSTCC samples/bpf/fds_example.o
HOSTCC samples/bpf/sockex1_user.o
/git/linux/samples/bpf/fds_example.c: In function 'bpf_prog_create':
/git/linux/samples/bpf/fds_example.c:63:6: warning: passing argument 2 of 'bpf_load_program' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
insns, insns_cnt, "GPL", 0,
^~~~~
In file included from /git/linux/samples/bpf/libbpf.h:5:0,
from /git/linux/samples/bpf/bpf_load.h:4,
from /git/linux/samples/bpf/fds_example.c:15:
/git/linux/tools/lib/bpf/bpf.h:31:5: note: expected 'struct bpf_insn *' but argument is of type 'const struct bpf_insn *'
int bpf_load_program(enum bpf_prog_type type, struct bpf_insn *insns,
^~~~~~~~~~~~~~~~
HOSTCC samples/bpf/sockex2_user.o
<SNIP>
HOSTCC samples/bpf/xdp_tx_iptunnel_user.o
clang -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/6.2.1/include -I/git/linux/arch/x86/include -I./arch/x86/include/generated/uapi -I./arch/x86/include/generated -I/git/linux/include -I./include -I/git/linux/arch/x86/include/uapi -I/git/linux/include/uapi -I./include/generated/uapi -include /git/linux/include/linux/kconfig.h \
-D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
-Wno-compare-distinct-pointer-types \
-Wno-gnu-variable-sized-type-not-at-end \
-Wno-address-of-packed-member -Wno-tautological-compare \
-O2 -emit-llvm -c /git/linux/samples/bpf/sockex1_kern.c -o -| llc -march=bpf -filetype=obj -o samples/bpf/sockex1_kern.o
HOSTLD samples/bpf/tc_l2_redirect
<SNIP>
HOSTLD samples/bpf/lwt_len_hist
HOSTLD samples/bpf/xdp_tx_iptunnel
make[1]: Leaving directory '/tmp/build/linux'
[root@f5065a7d6272 linux]#
And then, in the host:
[root@jouet bpf]# mount | grep "docker.*devicemapper\/"
/dev/mapper/docker-253:0-1705076-9bd8aa1e0af33adce89ff42090847868ca676932878942be53941a06ec5923f9 on /var/lib/docker/devicemapper/mnt/9bd8aa1e0af33adce89ff42090847868ca676932878942be53941a06ec5923f9 type xfs (rw,relatime,context="system_u:object_r:container_file_t:s0:c73,c276",nouuid,attr2,inode64,sunit=1024,swidth=1024,noquota)
[root@jouet bpf]# cd /var/lib/docker/devicemapper/mnt/9bd8aa1e0af33adce89ff42090847868ca676932878942be53941a06ec5923f9/rootfs/tmp/build/linux/samples/bpf/
[root@jouet bpf]# file offwaketime
offwaketime: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=f423d171e0487b2f802b6a792657f0f3c8f6d155, not stripped
[root@jouet bpf]# readelf -SW offwaketime
offwaketime offwaketime_kern.o offwaketime_user.o
[root@jouet bpf]# readelf -SW offwaketime_kern.o
There are 11 section headers, starting at offset 0x700:
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000 000000 00 0 0 0
[ 1] .strtab STRTAB 0000000000000000 000658 0000a8 00 0 0 1
[ 2] .text PROGBITS 0000000000000000 000040 000000 00 AX 0 0 4
[ 3] kprobe/try_to_wake_up PROGBITS 0000000000000000 000040 0000d8 00 AX 0 0 8
[ 4] .relkprobe/try_to_wake_up REL 0000000000000000 0005a8 000020 10 10 3 8
[ 5] tracepoint/sched/sched_switch PROGBITS 0000000000000000 000118 000318 00 AX 0 0 8
[ 6] .reltracepoint/sched/sched_switch REL 0000000000000000 0005c8 000090 10 10 5 8
[ 7] maps PROGBITS 0000000000000000 000430 000050 00 WA 0 0 4
[ 8] license PROGBITS 0000000000000000 000480 000004 00 WA 0 0 1
[ 9] version PROGBITS 0000000000000000 000484 000004 00 WA 0 0 4
[10] .symtab SYMTAB 0000000000000000 000488 000120 18 1 4 8
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
[root@jouet bpf]# ./offwaketime | head -3
qemu-system-x86;entry_SYSCALL_64_fastpath;sys_ppoll;do_sys_poll;poll_schedule_timeout;schedule_hrtimeout_range;schedule_hrtimeout_range_clock;schedule;__schedule;-;try_to_wake_up;hrtimer_wakeup;__hrtimer_run_queues;hrtimer_interrupt;local_apic_timer_interrupt;smp_apic_timer_interrupt;__irqentry_text_start;cpuidle_enter_state;cpuidle_enter;call_cpuidle;cpu_startup_entry;rest_init;start_kernel;x86_64_start_reservations;x86_64_start_kernel;start_cpu;;swapper/0 4
firefox;entry_SYSCALL_64_fastpath;sys_poll;do_sys_poll;poll_schedule_timeout;schedule_hrtimeout_range;schedule_hrtimeout_range_clock;schedule;__schedule;-;try_to_wake_up;pollwake;__wake_up_common;__wake_up_sync_key;pipe_write;__vfs_write;vfs_write;sys_write;entry_SYSCALL_64_fastpath;;Timer 1
swapper/2;start_cpu;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule;__schedule;-;---;; 61
[root@jouet bpf]#
Signed-off-by: Joe Stringer <joe@ovn.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: netdev@vger.kernel.org
Link: https://github.com/joestringer/linux/commit/5c40f54a52b1f437123c81e21873f4b4b1f9bd55.patch
Link: http://lkml.kernel.org/n/tip-xr8twtx7sjh5821g8qw47yxk@git.kernel.org
[ Use -I$(srctree)/tools/lib/ to support out of source code tree builds, as noticed by Wang Nan ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-12-15 06:43:39 +08:00
|
|
|
# Libbpf dependencies
|
2018-05-15 13:35:04 +08:00
|
|
|
LIBBPF = $(TOOLS_PATH)/lib/bpf/libbpf.a
|
|
|
|
|
2017-11-05 21:15:33 +08:00
|
|
|
CGROUP_HELPERS := ../../tools/testing/selftests/bpf/cgroup_helpers.o
|
2018-04-29 13:28:13 +08:00
|
|
|
TRACE_HELPERS := ../../tools/testing/selftests/bpf/trace_helpers.o
|
2021-08-21 08:20:02 +08:00
|
|
|
XDP_SAMPLE := xdp_sample_user.o
|
samples/bpf: Switch over to libbpf
Now that libbpf under tools/lib/bpf/* is synced with the version from
samples/bpf, we can get rid most of the libbpf library here.
Committer notes:
Built it in a docker fedora rawhide container and ran it in the f25 host, seems
to work just like it did before this patch, i.e. the switch to tools/lib/bpf/
doesn't seem to have introduced problems and Joe said he tested it with
all the entries in samples/bpf/ and other code he found:
[root@f5065a7d6272 linux]# make -j4 O=/tmp/build/linux headers_install
<SNIP>
[root@f5065a7d6272 linux]# rm -rf /tmp/build/linux/samples/bpf/
[root@f5065a7d6272 linux]# make -j4 O=/tmp/build/linux samples/bpf/
make[1]: Entering directory '/tmp/build/linux'
CHK include/config/kernel.release
HOSTCC scripts/basic/fixdep
GEN ./Makefile
CHK include/generated/uapi/linux/version.h
Using /git/linux as source for kernel
CHK include/generated/utsrelease.h
HOSTCC scripts/basic/bin2c
HOSTCC arch/x86/tools/relocs_32.o
HOSTCC arch/x86/tools/relocs_64.o
LD samples/bpf/built-in.o
<SNIP>
HOSTCC samples/bpf/fds_example.o
HOSTCC samples/bpf/sockex1_user.o
/git/linux/samples/bpf/fds_example.c: In function 'bpf_prog_create':
/git/linux/samples/bpf/fds_example.c:63:6: warning: passing argument 2 of 'bpf_load_program' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
insns, insns_cnt, "GPL", 0,
^~~~~
In file included from /git/linux/samples/bpf/libbpf.h:5:0,
from /git/linux/samples/bpf/bpf_load.h:4,
from /git/linux/samples/bpf/fds_example.c:15:
/git/linux/tools/lib/bpf/bpf.h:31:5: note: expected 'struct bpf_insn *' but argument is of type 'const struct bpf_insn *'
int bpf_load_program(enum bpf_prog_type type, struct bpf_insn *insns,
^~~~~~~~~~~~~~~~
HOSTCC samples/bpf/sockex2_user.o
<SNIP>
HOSTCC samples/bpf/xdp_tx_iptunnel_user.o
clang -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/6.2.1/include -I/git/linux/arch/x86/include -I./arch/x86/include/generated/uapi -I./arch/x86/include/generated -I/git/linux/include -I./include -I/git/linux/arch/x86/include/uapi -I/git/linux/include/uapi -I./include/generated/uapi -include /git/linux/include/linux/kconfig.h \
-D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
-Wno-compare-distinct-pointer-types \
-Wno-gnu-variable-sized-type-not-at-end \
-Wno-address-of-packed-member -Wno-tautological-compare \
-O2 -emit-llvm -c /git/linux/samples/bpf/sockex1_kern.c -o -| llc -march=bpf -filetype=obj -o samples/bpf/sockex1_kern.o
HOSTLD samples/bpf/tc_l2_redirect
<SNIP>
HOSTLD samples/bpf/lwt_len_hist
HOSTLD samples/bpf/xdp_tx_iptunnel
make[1]: Leaving directory '/tmp/build/linux'
[root@f5065a7d6272 linux]#
And then, in the host:
[root@jouet bpf]# mount | grep "docker.*devicemapper\/"
/dev/mapper/docker-253:0-1705076-9bd8aa1e0af33adce89ff42090847868ca676932878942be53941a06ec5923f9 on /var/lib/docker/devicemapper/mnt/9bd8aa1e0af33adce89ff42090847868ca676932878942be53941a06ec5923f9 type xfs (rw,relatime,context="system_u:object_r:container_file_t:s0:c73,c276",nouuid,attr2,inode64,sunit=1024,swidth=1024,noquota)
[root@jouet bpf]# cd /var/lib/docker/devicemapper/mnt/9bd8aa1e0af33adce89ff42090847868ca676932878942be53941a06ec5923f9/rootfs/tmp/build/linux/samples/bpf/
[root@jouet bpf]# file offwaketime
offwaketime: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=f423d171e0487b2f802b6a792657f0f3c8f6d155, not stripped
[root@jouet bpf]# readelf -SW offwaketime
offwaketime offwaketime_kern.o offwaketime_user.o
[root@jouet bpf]# readelf -SW offwaketime_kern.o
There are 11 section headers, starting at offset 0x700:
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000 000000 00 0 0 0
[ 1] .strtab STRTAB 0000000000000000 000658 0000a8 00 0 0 1
[ 2] .text PROGBITS 0000000000000000 000040 000000 00 AX 0 0 4
[ 3] kprobe/try_to_wake_up PROGBITS 0000000000000000 000040 0000d8 00 AX 0 0 8
[ 4] .relkprobe/try_to_wake_up REL 0000000000000000 0005a8 000020 10 10 3 8
[ 5] tracepoint/sched/sched_switch PROGBITS 0000000000000000 000118 000318 00 AX 0 0 8
[ 6] .reltracepoint/sched/sched_switch REL 0000000000000000 0005c8 000090 10 10 5 8
[ 7] maps PROGBITS 0000000000000000 000430 000050 00 WA 0 0 4
[ 8] license PROGBITS 0000000000000000 000480 000004 00 WA 0 0 1
[ 9] version PROGBITS 0000000000000000 000484 000004 00 WA 0 0 4
[10] .symtab SYMTAB 0000000000000000 000488 000120 18 1 4 8
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
[root@jouet bpf]# ./offwaketime | head -3
qemu-system-x86;entry_SYSCALL_64_fastpath;sys_ppoll;do_sys_poll;poll_schedule_timeout;schedule_hrtimeout_range;schedule_hrtimeout_range_clock;schedule;__schedule;-;try_to_wake_up;hrtimer_wakeup;__hrtimer_run_queues;hrtimer_interrupt;local_apic_timer_interrupt;smp_apic_timer_interrupt;__irqentry_text_start;cpuidle_enter_state;cpuidle_enter;call_cpuidle;cpu_startup_entry;rest_init;start_kernel;x86_64_start_reservations;x86_64_start_kernel;start_cpu;;swapper/0 4
firefox;entry_SYSCALL_64_fastpath;sys_poll;do_sys_poll;poll_schedule_timeout;schedule_hrtimeout_range;schedule_hrtimeout_range_clock;schedule;__schedule;-;try_to_wake_up;pollwake;__wake_up_common;__wake_up_sync_key;pipe_write;__vfs_write;vfs_write;sys_write;entry_SYSCALL_64_fastpath;;Timer 1
swapper/2;start_cpu;start_secondary;cpu_startup_entry;schedule_preempt_disabled;schedule;__schedule;-;---;; 61
[root@jouet bpf]#
Signed-off-by: Joe Stringer <joe@ovn.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: netdev@vger.kernel.org
Link: https://github.com/joestringer/linux/commit/5c40f54a52b1f437123c81e21873f4b4b1f9bd55.patch
Link: http://lkml.kernel.org/n/tip-xr8twtx7sjh5821g8qw47yxk@git.kernel.org
[ Use -I$(srctree)/tools/lib/ to support out of source code tree builds, as noticed by Wang Nan ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-12-15 06:43:39 +08:00
|
|
|
|
2019-02-28 11:04:13 +08:00
|
|
|
fds_example-objs := fds_example.o
|
|
|
|
sockex1-objs := sockex1_user.o
|
|
|
|
sockex2-objs := sockex2_user.o
|
2020-05-16 12:06:06 +08:00
|
|
|
sockex3-objs := sockex3_user.o
|
2020-05-16 12:06:05 +08:00
|
|
|
tracex1-objs := tracex1_user.o $(TRACE_HELPERS)
|
|
|
|
tracex2-objs := tracex2_user.o
|
|
|
|
tracex3-objs := tracex3_user.o
|
|
|
|
tracex4-objs := tracex4_user.o
|
2020-05-16 12:06:06 +08:00
|
|
|
tracex5-objs := tracex5_user.o $(TRACE_HELPERS)
|
2020-05-16 12:06:05 +08:00
|
|
|
tracex6-objs := tracex6_user.o
|
|
|
|
tracex7-objs := tracex7_user.o
|
2020-08-23 16:53:33 +08:00
|
|
|
test_probe_write_user-objs := test_probe_write_user_user.o
|
2020-11-24 17:03:10 +08:00
|
|
|
trace_output-objs := trace_output_user.o
|
2020-08-23 16:53:33 +08:00
|
|
|
lathist-objs := lathist_user.o
|
2020-08-23 16:53:34 +08:00
|
|
|
offwaketime-objs := offwaketime_user.o $(TRACE_HELPERS)
|
2020-08-23 16:53:33 +08:00
|
|
|
spintest-objs := spintest_user.o $(TRACE_HELPERS)
|
2020-08-23 16:53:32 +08:00
|
|
|
map_perf_test-objs := map_perf_test_user.o
|
2020-11-24 17:03:08 +08:00
|
|
|
test_overhead-objs := test_overhead_user.o
|
2018-05-15 13:35:05 +08:00
|
|
|
test_cgrp2_array_pin-objs := test_cgrp2_array_pin.o
|
|
|
|
test_cgrp2_attach-objs := test_cgrp2_attach.o
|
|
|
|
test_cgrp2_sock-objs := test_cgrp2_sock.o
|
2020-11-24 17:03:05 +08:00
|
|
|
test_cgrp2_sock2-objs := test_cgrp2_sock2.o
|
2018-05-15 13:35:05 +08:00
|
|
|
xdp1-objs := xdp1_user.o
|
2016-07-20 03:16:57 +08:00
|
|
|
# reuse xdp1 source intentionally
|
2018-05-15 13:35:05 +08:00
|
|
|
xdp2-objs := xdp1_user.o
|
2019-02-02 05:42:25 +08:00
|
|
|
xdp_router_ipv4-objs := xdp_router_ipv4_user.o
|
2020-08-23 16:53:33 +08:00
|
|
|
test_current_task_under_cgroup-objs := $(CGROUP_HELPERS) \
|
2016-08-12 23:57:04 +08:00
|
|
|
test_current_task_under_cgroup_user.o
|
2020-03-21 18:04:24 +08:00
|
|
|
trace_event-objs := trace_event_user.o $(TRACE_HELPERS)
|
|
|
|
sampleip-objs := sampleip_user.o $(TRACE_HELPERS)
|
2020-11-24 17:03:10 +08:00
|
|
|
tc_l2_redirect-objs := tc_l2_redirect_user.o
|
|
|
|
lwt_len_hist-objs := lwt_len_hist_user.o
|
2019-02-02 05:42:25 +08:00
|
|
|
xdp_tx_iptunnel-objs := xdp_tx_iptunnel_user.o
|
2020-07-08 02:48:53 +08:00
|
|
|
test_map_in_map-objs := test_map_in_map_user.o
|
2018-05-15 13:35:05 +08:00
|
|
|
per_socket_stats_example-objs := cookie_uid_helper_example.o
|
|
|
|
xdp_rxq_info-objs := xdp_rxq_info_user.o
|
2020-08-23 16:53:34 +08:00
|
|
|
syscall_tp-objs := syscall_tp_user.o
|
|
|
|
cpustat-objs := cpustat_user.o
|
2018-05-15 13:35:05 +08:00
|
|
|
xdp_adjust_tail-objs := xdp_adjust_tail_user.o
|
2018-07-27 05:32:21 +08:00
|
|
|
xdpsock-objs := xdpsock_user.o
|
2020-12-03 17:05:46 +08:00
|
|
|
xdpsock_ctrl_proc-objs := xdpsock_ctrl_proc.o
|
2020-08-28 16:26:28 +08:00
|
|
|
xsk_fwd-objs := xsk_fwd.o
|
2018-07-27 05:32:20 +08:00
|
|
|
xdp_fwd-objs := xdp_fwd_user.o
|
2020-11-24 17:03:06 +08:00
|
|
|
task_fd_query-objs := task_fd_query_user.o $(TRACE_HELPERS)
|
2020-11-24 17:03:10 +08:00
|
|
|
xdp_sample_pkts-objs := xdp_sample_pkts_user.o
|
2020-11-24 17:03:07 +08:00
|
|
|
ibumad-objs := ibumad_user.o
|
2020-11-24 17:03:04 +08:00
|
|
|
hbm-objs := hbm.o $(CGROUP_HELPERS)
|
bpf: mini eBPF library, test stubs and verifier testsuite
1.
the library includes a trivial set of BPF syscall wrappers:
int bpf_create_map(int key_size, int value_size, int max_entries);
int bpf_update_elem(int fd, void *key, void *value);
int bpf_lookup_elem(int fd, void *key, void *value);
int bpf_delete_elem(int fd, void *key);
int bpf_get_next_key(int fd, void *key, void *next_key);
int bpf_prog_load(enum bpf_prog_type prog_type,
const struct sock_filter_int *insns, int insn_len,
const char *license);
bpf_prog_load() stores verifier log into global bpf_log_buf[] array
and BPF_*() macros to build instructions
2.
test stubs configure eBPF infra with 'unspec' map and program types.
These are fake types used by user space testsuite only.
3.
verifier tests valid and invalid programs and expects predefined
error log messages from kernel.
40 tests so far.
$ sudo ./test_verifier
#0 add+sub+mul OK
#1 unreachable OK
#2 unreachable2 OK
#3 out of range jump OK
#4 out of range jump2 OK
#5 test1 ld_imm64 OK
...
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-09-26 15:17:07 +08:00
|
|
|
|
2021-08-21 08:20:10 +08:00
|
|
|
xdp_redirect_map_multi-objs := xdp_redirect_map_multi_user.o $(XDP_SAMPLE)
|
2021-08-21 08:20:06 +08:00
|
|
|
xdp_redirect_cpu-objs := xdp_redirect_cpu_user.o $(XDP_SAMPLE)
|
2021-08-21 08:20:08 +08:00
|
|
|
xdp_redirect_map-objs := xdp_redirect_map_user.o $(XDP_SAMPLE)
|
2021-08-21 08:20:04 +08:00
|
|
|
xdp_redirect-objs := xdp_redirect_user.o $(XDP_SAMPLE)
|
2021-08-21 08:20:02 +08:00
|
|
|
xdp_monitor-objs := xdp_monitor_user.o $(XDP_SAMPLE)
|
|
|
|
|
bpf: mini eBPF library, test stubs and verifier testsuite
1.
the library includes a trivial set of BPF syscall wrappers:
int bpf_create_map(int key_size, int value_size, int max_entries);
int bpf_update_elem(int fd, void *key, void *value);
int bpf_lookup_elem(int fd, void *key, void *value);
int bpf_delete_elem(int fd, void *key);
int bpf_get_next_key(int fd, void *key, void *next_key);
int bpf_prog_load(enum bpf_prog_type prog_type,
const struct sock_filter_int *insns, int insn_len,
const char *license);
bpf_prog_load() stores verifier log into global bpf_log_buf[] array
and BPF_*() macros to build instructions
2.
test stubs configure eBPF infra with 'unspec' map and program types.
These are fake types used by user space testsuite only.
3.
verifier tests valid and invalid programs and expects predefined
error log messages from kernel.
40 tests so far.
$ sudo ./test_verifier
#0 add+sub+mul OK
#1 unreachable OK
#2 unreachable2 OK
#3 out of range jump OK
#4 out of range jump2 OK
#5 test1 ld_imm64 OK
...
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-09-26 15:17:07 +08:00
|
|
|
# Tell kbuild to always build the programs
|
2020-02-02 00:49:24 +08:00
|
|
|
always-y := $(tprogs-y)
|
|
|
|
always-y += sockex1_kern.o
|
|
|
|
always-y += sockex2_kern.o
|
|
|
|
always-y += sockex3_kern.o
|
|
|
|
always-y += tracex1_kern.o
|
|
|
|
always-y += tracex2_kern.o
|
|
|
|
always-y += tracex3_kern.o
|
|
|
|
always-y += tracex4_kern.o
|
|
|
|
always-y += tracex5_kern.o
|
|
|
|
always-y += tracex6_kern.o
|
|
|
|
always-y += tracex7_kern.o
|
|
|
|
always-y += sock_flags_kern.o
|
|
|
|
always-y += test_probe_write_user_kern.o
|
|
|
|
always-y += trace_output_kern.o
|
|
|
|
always-y += tcbpf1_kern.o
|
|
|
|
always-y += tc_l2_redirect_kern.o
|
|
|
|
always-y += lathist_kern.o
|
|
|
|
always-y += offwaketime_kern.o
|
|
|
|
always-y += spintest_kern.o
|
|
|
|
always-y += map_perf_test_kern.o
|
|
|
|
always-y += test_overhead_tp_kern.o
|
|
|
|
always-y += test_overhead_raw_tp_kern.o
|
|
|
|
always-y += test_overhead_kprobe_kern.o
|
|
|
|
always-y += parse_varlen.o parse_simple.o parse_ldabs.o
|
|
|
|
always-y += test_cgrp2_tc_kern.o
|
|
|
|
always-y += xdp1_kern.o
|
|
|
|
always-y += xdp2_kern.o
|
|
|
|
always-y += xdp_router_ipv4_kern.o
|
|
|
|
always-y += test_current_task_under_cgroup_kern.o
|
|
|
|
always-y += trace_event_kern.o
|
|
|
|
always-y += sampleip_kern.o
|
|
|
|
always-y += lwt_len_hist_kern.o
|
|
|
|
always-y += xdp_tx_iptunnel_kern.o
|
|
|
|
always-y += test_map_in_map_kern.o
|
|
|
|
always-y += tcp_synrto_kern.o
|
|
|
|
always-y += tcp_rwnd_kern.o
|
|
|
|
always-y += tcp_bufs_kern.o
|
|
|
|
always-y += tcp_cong_kern.o
|
|
|
|
always-y += tcp_iw_kern.o
|
|
|
|
always-y += tcp_clamp_kern.o
|
|
|
|
always-y += tcp_basertt_kern.o
|
|
|
|
always-y += tcp_tos_reflect_kern.o
|
|
|
|
always-y += tcp_dumpstats_kern.o
|
|
|
|
always-y += xdp_rxq_info_kern.o
|
|
|
|
always-y += xdp2skb_meta_kern.o
|
|
|
|
always-y += syscall_tp_kern.o
|
|
|
|
always-y += cpustat_kern.o
|
|
|
|
always-y += xdp_adjust_tail_kern.o
|
|
|
|
always-y += xdp_fwd_kern.o
|
|
|
|
always-y += task_fd_query_kern.o
|
|
|
|
always-y += xdp_sample_pkts_kern.o
|
|
|
|
always-y += ibumad_kern.o
|
|
|
|
always-y += hbm_out_kern.o
|
|
|
|
always-y += hbm_edt_kern.o
|
|
|
|
always-y += xdpsock_kern.o
|
bpf: mini eBPF library, test stubs and verifier testsuite
1.
the library includes a trivial set of BPF syscall wrappers:
int bpf_create_map(int key_size, int value_size, int max_entries);
int bpf_update_elem(int fd, void *key, void *value);
int bpf_lookup_elem(int fd, void *key, void *value);
int bpf_delete_elem(int fd, void *key);
int bpf_get_next_key(int fd, void *key, void *next_key);
int bpf_prog_load(enum bpf_prog_type prog_type,
const struct sock_filter_int *insns, int insn_len,
const char *license);
bpf_prog_load() stores verifier log into global bpf_log_buf[] array
and BPF_*() macros to build instructions
2.
test stubs configure eBPF infra with 'unspec' map and program types.
These are fake types used by user space testsuite only.
3.
verifier tests valid and invalid programs and expects predefined
error log messages from kernel.
40 tests so far.
$ sudo ./test_verifier
#0 add+sub+mul OK
#1 unreachable OK
#2 unreachable2 OK
#3 out of range jump OK
#4 out of range jump2 OK
#5 test1 ld_imm64 OK
...
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-09-26 15:17:07 +08:00
|
|
|
|
2019-10-11 08:27:58 +08:00
|
|
|
ifeq ($(ARCH), arm)
|
|
|
|
# Strip all except -D__LINUX_ARM_ARCH__ option needed to handle linux
|
|
|
|
# headers when arm instruction set identification is requested.
|
|
|
|
ARM_ARCH_SELECTOR := $(filter -D__LINUX_ARM_ARCH__%, $(KBUILD_CFLAGS))
|
|
|
|
BPF_EXTRA_CFLAGS := $(ARM_ARCH_SELECTOR)
|
2019-10-11 08:28:01 +08:00
|
|
|
TPROGS_CFLAGS += $(ARM_ARCH_SELECTOR)
|
2019-10-11 08:27:58 +08:00
|
|
|
endif
|
|
|
|
|
samples/bpf: Set flag __SANE_USERSPACE_TYPES__ for MIPS to fix build warnings
There exists many build warnings when make M=samples/bpf on the Loongson
platform, this issue is MIPS related, x86 compiles just fine.
Here are some warnings:
CC samples/bpf/ibumad_user.o
samples/bpf/ibumad_user.c: In function ‘dump_counts’:
samples/bpf/ibumad_user.c:46:24: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘__u64’ {aka ‘long unsigned int’} [-Wformat=]
printf("0x%02x : %llu\n", key, value);
~~~^ ~~~~~
%lu
CC samples/bpf/offwaketime_user.o
samples/bpf/offwaketime_user.c: In function ‘print_ksym’:
samples/bpf/offwaketime_user.c:34:17: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘__u64’ {aka ‘long unsigned int’} [-Wformat=]
printf("%s/%llx;", sym->name, addr);
~~~^ ~~~~
%lx
samples/bpf/offwaketime_user.c: In function ‘print_stack’:
samples/bpf/offwaketime_user.c:68:17: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘__u64’ {aka ‘long unsigned int’} [-Wformat=]
printf(";%s %lld\n", key->waker, count);
~~~^ ~~~~~
%ld
MIPS needs __SANE_USERSPACE_TYPES__ before <linux/types.h> to select
'int-ll64.h' in arch/mips/include/uapi/asm/types.h, then it can avoid
build warnings when printing __u64 with %llu, %llx or %lld.
The header tools/include/linux/types.h defines __SANE_USERSPACE_TYPES__,
it seems that we can include <linux/types.h> in the source files which
have build warnings, but it has no effect due to actually it includes
usr/include/linux/types.h instead of tools/include/linux/types.h, the
problem is that "usr/include" is preferred first than "tools/include"
in samples/bpf/Makefile, that sounds like a ugly hack to -Itools/include
before -Iusr/include.
So define __SANE_USERSPACE_TYPES__ for MIPS in samples/bpf/Makefile
is proper, if add "TPROGS_CFLAGS += -D__SANE_USERSPACE_TYPES__" in
samples/bpf/Makefile, it appears the following error:
Auto-detecting system features:
... libelf: [ on ]
... zlib: [ on ]
... bpf: [ OFF ]
BPF API too old
make[3]: *** [Makefile:293: bpfdep] Error 1
make[2]: *** [Makefile:156: all] Error 2
With #ifndef __SANE_USERSPACE_TYPES__ in tools/include/linux/types.h,
the above error has gone and this ifndef change does not hurt other
compilations.
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/1611551146-14052-1-git-send-email-yangtiezhu@loongson.cn
2021-01-25 13:05:46 +08:00
|
|
|
ifeq ($(ARCH), mips)
|
|
|
|
TPROGS_CFLAGS += -D__SANE_USERSPACE_TYPES__
|
2021-01-26 22:05:25 +08:00
|
|
|
ifdef CONFIG_MACH_LOONGSON64
|
|
|
|
BPF_EXTRA_CFLAGS += -I$(srctree)/arch/mips/include/asm/mach-loongson64
|
|
|
|
BPF_EXTRA_CFLAGS += -I$(srctree)/arch/mips/include/asm/mach-generic
|
|
|
|
endif
|
samples/bpf: Set flag __SANE_USERSPACE_TYPES__ for MIPS to fix build warnings
There exists many build warnings when make M=samples/bpf on the Loongson
platform, this issue is MIPS related, x86 compiles just fine.
Here are some warnings:
CC samples/bpf/ibumad_user.o
samples/bpf/ibumad_user.c: In function ‘dump_counts’:
samples/bpf/ibumad_user.c:46:24: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘__u64’ {aka ‘long unsigned int’} [-Wformat=]
printf("0x%02x : %llu\n", key, value);
~~~^ ~~~~~
%lu
CC samples/bpf/offwaketime_user.o
samples/bpf/offwaketime_user.c: In function ‘print_ksym’:
samples/bpf/offwaketime_user.c:34:17: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘__u64’ {aka ‘long unsigned int’} [-Wformat=]
printf("%s/%llx;", sym->name, addr);
~~~^ ~~~~
%lx
samples/bpf/offwaketime_user.c: In function ‘print_stack’:
samples/bpf/offwaketime_user.c:68:17: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘__u64’ {aka ‘long unsigned int’} [-Wformat=]
printf(";%s %lld\n", key->waker, count);
~~~^ ~~~~~
%ld
MIPS needs __SANE_USERSPACE_TYPES__ before <linux/types.h> to select
'int-ll64.h' in arch/mips/include/uapi/asm/types.h, then it can avoid
build warnings when printing __u64 with %llu, %llx or %lld.
The header tools/include/linux/types.h defines __SANE_USERSPACE_TYPES__,
it seems that we can include <linux/types.h> in the source files which
have build warnings, but it has no effect due to actually it includes
usr/include/linux/types.h instead of tools/include/linux/types.h, the
problem is that "usr/include" is preferred first than "tools/include"
in samples/bpf/Makefile, that sounds like a ugly hack to -Itools/include
before -Iusr/include.
So define __SANE_USERSPACE_TYPES__ for MIPS in samples/bpf/Makefile
is proper, if add "TPROGS_CFLAGS += -D__SANE_USERSPACE_TYPES__" in
samples/bpf/Makefile, it appears the following error:
Auto-detecting system features:
... libelf: [ on ]
... zlib: [ on ]
... bpf: [ OFF ]
BPF API too old
make[3]: *** [Makefile:293: bpfdep] Error 1
make[2]: *** [Makefile:156: all] Error 2
With #ifndef __SANE_USERSPACE_TYPES__ in tools/include/linux/types.h,
the above error has gone and this ifndef change does not hurt other
compilations.
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/1611551146-14052-1-git-send-email-yangtiezhu@loongson.cn
2021-01-25 13:05:46 +08:00
|
|
|
endif
|
|
|
|
|
2019-10-11 08:28:02 +08:00
|
|
|
TPROGS_CFLAGS += -Wall -O2
|
|
|
|
TPROGS_CFLAGS += -Wmissing-prototypes
|
|
|
|
TPROGS_CFLAGS += -Wstrict-prototypes
|
|
|
|
|
2019-10-11 08:28:01 +08:00
|
|
|
TPROGS_CFLAGS += -I$(objtree)/usr/include
|
|
|
|
TPROGS_CFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
|
|
|
|
TPROGS_CFLAGS += -I$(srctree)/tools/lib/
|
|
|
|
TPROGS_CFLAGS += -I$(srctree)/tools/include
|
|
|
|
TPROGS_CFLAGS += -I$(srctree)/tools/perf
|
2019-11-10 03:04:37 +08:00
|
|
|
TPROGS_CFLAGS += -DHAVE_ATTR_TEST=0
|
2019-10-11 08:28:01 +08:00
|
|
|
|
2019-10-11 08:28:07 +08:00
|
|
|
ifdef SYSROOT
|
|
|
|
TPROGS_CFLAGS += --sysroot=$(SYSROOT)
|
|
|
|
TPROGS_LDFLAGS := -L$(SYSROOT)/usr/lib
|
|
|
|
endif
|
|
|
|
|
2019-12-16 18:24:05 +08:00
|
|
|
TPROGS_LDLIBS += $(LIBBPF) -lelf -lz
|
2019-10-11 08:28:01 +08:00
|
|
|
TPROGLDLIBS_tracex4 += -lrt
|
|
|
|
TPROGLDLIBS_trace_output += -lrt
|
|
|
|
TPROGLDLIBS_map_perf_test += -lrt
|
|
|
|
TPROGLDLIBS_test_overhead += -lrt
|
2020-12-03 17:05:46 +08:00
|
|
|
TPROGLDLIBS_xdpsock += -pthread -lcap
|
2020-08-28 16:26:28 +08:00
|
|
|
TPROGLDLIBS_xsk_fwd += -pthread
|
2019-10-11 08:28:01 +08:00
|
|
|
|
2016-04-28 20:21:14 +08:00
|
|
|
# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
|
bpf, docs: Update build procedure for manually compiling LLVM and Clang
The current LLVM and Clang build procedure in samples/bpf/README.rst is
out of date. See below that the links are not accessible any more.
$ git clone http://llvm.org/git/llvm.git
Cloning into 'llvm'...
fatal: unable to access 'http://llvm.org/git/llvm.git/': Maximum (20) redirects followed
$ git clone --depth 1 http://llvm.org/git/clang.git
Cloning into 'clang'...
fatal: unable to access 'http://llvm.org/git/clang.git/': Maximum (20) redirects followed
The LLVM community has adopted new ways to build the compiler. There are
different ways to build LLVM and Clang, the Clang Getting Started page [1]
has one way. As Yonghong said, it is better to copy the build procedure
in Documentation/bpf/bpf_devel_QA.rst to keep consistent.
I verified the procedure and it is proved to be feasible, so we should
update README.rst to reflect the reality. At the same time, update the
related comment in Makefile.
Additionally, as Fangrui said, the dir llvm-project/llvm/build/install is
not used, BUILD_SHARED_LIBS=OFF is the default option [2], so also change
Documentation/bpf/bpf_devel_QA.rst together.
At last, we recommend that developers who want the fastest incremental
builds use the Ninja build system [1], you can find it in your system's
package manager, usually the package is ninja or ninja-build [3], so add
ninja to build dependencies suggested by Nathan.
[1] https://clang.llvm.org/get_started.html
[2] https://www.llvm.org/docs/CMake.html
[3] https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Acked-by: Yonghong Song <yhs@fb.com>
Cc: Fangrui Song <maskray@google.com>
Link: https://lore.kernel.org/bpf/1611279584-26047-1-git-send-email-yangtiezhu@loongson.cn
2021-01-22 09:39:44 +08:00
|
|
|
# make M=samples/bpf LLC=~/git/llvm-project/llvm/build/bin/llc CLANG=~/git/llvm-project/llvm/build/bin/clang
|
2016-04-28 20:20:53 +08:00
|
|
|
LLC ?= llc
|
2016-04-28 20:21:14 +08:00
|
|
|
CLANG ?= clang
|
samples/bpf: Change Makefile to cope with latest llvm
With latest llvm trunk, bpf programs under samples/bpf
directory, if using CORE, may experience the following
errors:
LLVM ERROR: Cannot select: intrinsic %llvm.preserve.struct.access.index
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. Program arguments: llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o
1. Running pass 'Function Pass Manager' on module '<stdin>'.
2. Running pass 'BPF DAG->DAG Pattern Instruction Selection' on function '@bpf_prog1'
#0 0x000000000183c26c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x183c26c)
...
#7 0x00000000017c375e (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x17c375e)
#8 0x00000000016a75c5 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*)
(/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16a75c5)
#9 0x00000000016ab4f8 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*,
unsigned int) (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16ab4f8)
...
Aborted (core dumped) | llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o
The reason is due to llvm change https://reviews.llvm.org/D87153
where the CORE relocation global generation is moved from the beginning
of target dependent optimization (llc) to the beginning
of target independent optimization (opt).
Since samples/bpf programs did not use vmlinux.h and its clang compilation
uses native architecture, we need to adjust arch triple at opt level
to do CORE relocation global generation properly. Otherwise, the above
error will appear.
This patch fixed the issue by introduce opt and llvm-dis to compilation chain,
which will do proper CORE relocation global generation as well as O2 level
optimization. Tested with llvm10, llvm11 and trunk/llvm12.
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20201006043427.1891742-1-yhs@fb.com
2020-10-06 12:34:26 +08:00
|
|
|
OPT ?= opt
|
|
|
|
LLVM_DIS ?= llvm-dis
|
2018-07-26 18:13:44 +08:00
|
|
|
LLVM_OBJCOPY ?= llvm-objcopy
|
|
|
|
BTF_PAHOLE ?= pahole
|
2016-04-28 20:20:53 +08:00
|
|
|
|
2017-09-21 00:11:57 +08:00
|
|
|
# Detect that we're cross compiling and use the cross compiler
|
|
|
|
ifdef CROSS_COMPILE
|
2019-10-11 08:27:56 +08:00
|
|
|
CLANG_ARCH_ARGS = --target=$(notdir $(CROSS_COMPILE:%-=%))
|
2017-09-21 00:11:57 +08:00
|
|
|
endif
|
|
|
|
|
2019-06-08 01:11:16 +08:00
|
|
|
# Don't evaluate probes and warnings if we need to run make recursively
|
|
|
|
ifneq ($(src),)
|
2019-10-11 08:27:54 +08:00
|
|
|
HDR_PROBE := $(shell printf "\#include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \
|
2019-10-11 08:28:03 +08:00
|
|
|
$(CC) $(TPROGS_CFLAGS) $(TPROGS_LDFLAGS) -x c - \
|
|
|
|
-o /dev/null 2>/dev/null && echo okay)
|
2019-06-06 07:47:22 +08:00
|
|
|
|
|
|
|
ifeq ($(HDR_PROBE),)
|
|
|
|
$(warning WARNING: Detected possible issues with include path.)
|
|
|
|
$(warning WARNING: Please install kernel headers locally (make headers_install).)
|
|
|
|
endif
|
|
|
|
|
2018-07-26 18:13:44 +08:00
|
|
|
BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris)
|
|
|
|
BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF)
|
|
|
|
BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --help 2>&1 | grep -i 'usage.*llvm')
|
2018-11-20 07:29:17 +08:00
|
|
|
BTF_LLVM_PROBE := $(shell echo "int main() { return 0; }" | \
|
|
|
|
$(CLANG) -target bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \
|
|
|
|
readelf -S ./llvm_btf_verify.o | grep BTF; \
|
|
|
|
/bin/rm -f ./llvm_btf_verify.o)
|
2018-07-26 18:13:44 +08:00
|
|
|
|
2019-12-16 18:38:19 +08:00
|
|
|
BPF_EXTRA_CFLAGS += -fno-stack-protector
|
2018-11-20 07:29:17 +08:00
|
|
|
ifneq ($(BTF_LLVM_PROBE),)
|
2019-10-11 08:27:57 +08:00
|
|
|
BPF_EXTRA_CFLAGS += -g
|
2018-11-20 07:29:17 +08:00
|
|
|
else
|
2018-07-26 18:13:44 +08:00
|
|
|
ifneq ($(and $(BTF_LLC_PROBE),$(BTF_PAHOLE_PROBE),$(BTF_OBJCOPY_PROBE)),)
|
2019-10-11 08:27:57 +08:00
|
|
|
BPF_EXTRA_CFLAGS += -g
|
2018-07-26 18:13:44 +08:00
|
|
|
LLC_FLAGS += -mattr=dwarfris
|
|
|
|
DWARF2BTF = y
|
|
|
|
endif
|
2018-11-20 07:29:17 +08:00
|
|
|
endif
|
2019-06-08 01:11:16 +08:00
|
|
|
endif
|
2018-07-26 18:13:44 +08:00
|
|
|
|
2016-04-28 20:21:09 +08:00
|
|
|
# Trick to allow make to be run from this directory
|
2018-05-15 13:35:04 +08:00
|
|
|
all:
|
2019-11-11 00:31:16 +08:00
|
|
|
$(MAKE) -C ../../ M=$(CURDIR) BPF_SAMPLES_PATH=$(CURDIR)
|
2016-04-28 20:21:09 +08:00
|
|
|
|
|
|
|
clean:
|
2016-11-22 16:30:26 +08:00
|
|
|
$(MAKE) -C ../../ M=$(CURDIR) clean
|
2020-01-20 21:06:41 +08:00
|
|
|
@find $(CURDIR) -type f -name '*~' -delete
|
2016-04-28 20:21:09 +08:00
|
|
|
|
2018-01-26 08:39:30 +08:00
|
|
|
$(LIBBPF): FORCE
|
2018-05-15 13:35:04 +08:00
|
|
|
# Fix up variables inherited from Kbuild that tools/ build system won't like
|
2019-10-11 08:28:06 +08:00
|
|
|
$(MAKE) -C $(dir $@) RM='rm -rf' EXTRA_CFLAGS="$(TPROGS_CFLAGS)" \
|
|
|
|
LDFLAGS=$(TPROGS_LDFLAGS) srctree=$(BPF_SAMPLES_PATH)/../../ O=
|
2018-01-26 08:39:30 +08:00
|
|
|
|
2021-08-21 08:20:00 +08:00
|
|
|
BPFTOOLDIR := $(TOOLS_PATH)/bpf/bpftool
|
|
|
|
BPFTOOL := $(BPFTOOLDIR)/bpftool
|
|
|
|
$(BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile)
|
|
|
|
$(MAKE) -C $(BPFTOOLDIR) srctree=$(BPF_SAMPLES_PATH)/../../
|
|
|
|
|
2017-06-14 07:49:38 +08:00
|
|
|
$(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE
|
|
|
|
$(call filechk,offsets,__SYSCALL_NRS_H__)
|
|
|
|
|
2018-12-22 17:50:34 +08:00
|
|
|
targets += syscall_nrs.s
|
2017-06-14 07:49:38 +08:00
|
|
|
clean-files += syscall_nrs.h
|
|
|
|
|
|
|
|
FORCE:
|
|
|
|
|
|
|
|
|
2016-04-28 20:21:14 +08:00
|
|
|
# Verify LLVM compiler tools are available and bpf target is supported by llc
|
|
|
|
.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
|
2016-04-28 20:20:58 +08:00
|
|
|
|
2016-04-28 20:21:14 +08:00
|
|
|
verify_cmds: $(CLANG) $(LLC)
|
|
|
|
@for TOOL in $^ ; do \
|
|
|
|
if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
|
|
|
|
echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
|
|
|
|
exit 1; \
|
|
|
|
else true; fi; \
|
|
|
|
done
|
2016-04-28 20:20:58 +08:00
|
|
|
|
2016-04-28 20:21:14 +08:00
|
|
|
verify_target_bpf: verify_cmds
|
2016-04-28 20:20:58 +08:00
|
|
|
@if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
|
|
|
|
echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
|
|
|
|
echo " NOTICE: LLVM version >= 3.7.1 required" ;\
|
|
|
|
exit 2; \
|
|
|
|
else true; fi
|
|
|
|
|
2018-05-15 13:35:04 +08:00
|
|
|
$(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF)
|
|
|
|
$(src)/*.c: verify_target_bpf $(LIBBPF)
|
2016-04-28 20:20:58 +08:00
|
|
|
|
2021-08-21 08:20:06 +08:00
|
|
|
$(obj)/xdp_redirect_cpu_user.o: $(obj)/xdp_redirect_cpu.skel.h
|
2021-08-21 08:20:10 +08:00
|
|
|
$(obj)/xdp_redirect_map_multi_user.o: $(obj)/xdp_redirect_map_multi.skel.h
|
2021-08-21 08:20:08 +08:00
|
|
|
$(obj)/xdp_redirect_map_user.o: $(obj)/xdp_redirect_map.skel.h
|
2021-08-21 08:20:04 +08:00
|
|
|
$(obj)/xdp_redirect_user.o: $(obj)/xdp_redirect.skel.h
|
2021-08-21 08:20:02 +08:00
|
|
|
$(obj)/xdp_monitor_user.o: $(obj)/xdp_monitor.skel.h
|
|
|
|
|
2017-06-14 07:49:38 +08:00
|
|
|
$(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
|
bpf: Sample HBM BPF program to limit egress bw
A cgroup skb BPF program to limit cgroup output bandwidth.
It uses a modified virtual token bucket queue to limit average
egress bandwidth. The implementation uses credits instead of tokens.
Negative credits imply that queueing would have happened (this is
a virtual queue, so no queueing is done by it. However, queueing may
occur at the actual qdisc (which is not used for rate limiting).
This implementation uses 3 thresholds, one to start marking packets and
the other two to drop packets:
CREDIT
- <--------------------------|------------------------> +
| | | 0
| Large pkt |
| drop thresh |
Small pkt drop Mark threshold
thresh
The effect of marking depends on the type of packet:
a) If the packet is ECN enabled, then the packet is ECN ce marked.
The current mark threshold is tuned for DCTCP.
c) Else, it is dropped if it is a large packet.
If the credit is below the drop threshold, the packet is dropped.
Note that dropping a packet through the BPF program does not trigger CWR
(Congestion Window Reduction) in TCP packets. A future patch will add
support for triggering CWR.
This BPF program actually uses 2 drop thresholds, one threshold
for larger packets (>= 120 bytes) and another for smaller packets. This
protects smaller packets such as SYNs, ACKs, etc.
The default bandwidth limit is set at 1Gbps but this can be changed by
a user program through a shared BPF map. In addition, by default this BPF
program does not limit connections using loopback. This behavior can be
overwritten by the user program. There is also an option to calculate
some statistics, such as percent of packets marked or dropped, which
the user program can access.
A latter patch provides such a program (hbm.c)
Signed-off-by: Lawrence Brakmo <brakmo@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-03-02 04:38:48 +08:00
|
|
|
$(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
|
2019-03-02 04:38:49 +08:00
|
|
|
$(obj)/hbm.o: $(src)/hbm.h
|
bpf: Add support for fq's EDT to HBM
Adds support for fq's Earliest Departure Time to HBM (Host Bandwidth
Manager). Includes a new BPF program supporting EDT, and also updates
corresponding programs.
It will drop packets with an EDT of more than 500us in the future
unless the packet belongs to a flow with less than 2 packets in flight.
This is done so each flow has at least 2 packets in flight, so they
will not starve, and also to help prevent delayed ACK timeouts.
It will also work with ECN enabled traffic, where the packets will be
CE marked if their EDT is more than 50us in the future.
The table below shows some performance numbers. The flows are back to
back RPCS. One server sending to another, either 2 or 4 flows.
One flow is a 10KB RPC, the rest are 1MB RPCs. When there are more
than one flow of a given RPC size, the numbers represent averages.
The rate limit applies to all flows (they are in the same cgroup).
Tests ending with "-edt" ran with the new BPF program supporting EDT.
Tests ending with "-hbt" ran on top HBT qdisc with the specified rate
(i.e. no HBM). The other tests ran with the HBM BPF program included
in the HBM patch-set.
EDT has limited value when using DCTCP, but it helps in many cases when
using Cubic. It usually achieves larger link utilization and lower
99% latencies for the 1MB RPCs.
HBM ends up queueing a lot of packets with its default parameter values,
reducing the goodput of the 10KB RPCs and increasing their latency. Also,
the RTTs seen by the flows are quite large.
Aggr 10K 10K 10K 1MB 1MB 1MB
Limit rate drops RTT rate P90 P99 rate P90 P99
Test rate Flows Mbps % us Mbps us us Mbps ms ms
-------- ---- ----- ---- ----- --- ---- ---- ---- ---- ---- ----
cubic 1G 2 904 0.02 108 257 511 539 647 13.4 24.5
cubic-edt 1G 2 982 0.01 156 239 656 967 743 14.0 17.2
dctcp 1G 2 977 0.00 105 324 408 744 653 14.5 15.9
dctcp-edt 1G 2 981 0.01 142 321 417 811 660 15.7 17.0
cubic-htb 1G 2 919 0.00 1825 40 2822 4140 879 9.7 9.9
cubic 200M 2 155 0.30 220 81 532 655 74 283 450
cubic-edt 200M 2 188 0.02 222 87 1035 1095 101 84 85
dctcp 200M 2 188 0.03 111 77 912 939 111 76 325
dctcp-edt 200M 2 188 0.03 217 74 1416 1738 114 76 79
cubic-htb 200M 2 188 0.00 5015 8 14ms 15ms 180 48 50
cubic 1G 4 952 0.03 110 165 516 546 262 38 154
cubic-edt 1G 4 973 0.01 190 111 1034 1314 287 65 79
dctcp 1G 4 951 0.00 103 180 617 905 257 37 38
dctcp-edt 1G 4 967 0.00 163 151 732 1126 272 43 55
cubic-htb 1G 4 914 0.00 3249 13 7ms 8ms 300 29 34
cubic 5G 4 4236 0.00 134 305 490 624 1310 10 17
cubic-edt 5G 4 4865 0.00 156 306 425 759 1520 10 16
dctcp 5G 4 4936 0.00 128 485 221 409 1484 7 9
dctcp-edt 5G 4 4924 0.00 148 390 392 623 1508 11 26
v1 -> v2: Incorporated Andrii's suggestions
v2 -> v3: Incorporated Yonghong's suggestions
v3 -> v4: Removed credit update that is not needed
Signed-off-by: Lawrence Brakmo <brakmo@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-07-03 06:09:52 +08:00
|
|
|
$(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
|
2017-06-14 07:49:38 +08:00
|
|
|
|
2019-10-11 08:28:01 +08:00
|
|
|
-include $(BPF_SAMPLES_PATH)/Makefile.target
|
|
|
|
|
2021-09-28 13:46:08 +08:00
|
|
|
VMLINUX_BTF_PATHS ?= $(abspath $(if $(O),$(O)/vmlinux)) \
|
|
|
|
$(abspath $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux)) \
|
|
|
|
$(abspath ./vmlinux)
|
2021-08-21 08:20:00 +08:00
|
|
|
VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS))))
|
|
|
|
|
|
|
|
$(obj)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL)
|
|
|
|
ifeq ($(VMLINUX_H),)
|
|
|
|
$(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@
|
|
|
|
else
|
|
|
|
$(Q)cp "$(VMLINUX_H)" $@
|
|
|
|
endif
|
|
|
|
|
2021-09-28 13:46:08 +08:00
|
|
|
ifeq ($(VMLINUX_BTF),)
|
|
|
|
$(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)",\
|
|
|
|
build the kernel or set VMLINUX_BTF variable)
|
|
|
|
endif
|
|
|
|
|
2021-08-21 08:20:00 +08:00
|
|
|
clean-files += vmlinux.h
|
|
|
|
|
2021-08-21 08:20:01 +08:00
|
|
|
# Get Clang's default includes on this system, as opposed to those seen by
|
|
|
|
# '-target bpf'. This fixes "missing" files on some architectures/distros,
|
|
|
|
# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
|
|
|
|
#
|
|
|
|
# Use '-idirafter': Don't interfere with include mechanics except where the
|
|
|
|
# build would have failed anyways.
|
|
|
|
define get_sys_includes
|
|
|
|
$(shell $(1) -v -E - </dev/null 2>&1 \
|
|
|
|
| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
|
|
|
|
$(shell $(1) -dM -E - </dev/null | grep '#define __riscv_xlen ' | sed 's/#define /-D/' | sed 's/ /=/')
|
|
|
|
endef
|
|
|
|
|
|
|
|
CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG))
|
|
|
|
|
2021-08-21 08:20:05 +08:00
|
|
|
$(obj)/xdp_redirect_cpu.bpf.o: $(obj)/xdp_sample.bpf.o
|
2021-08-21 08:20:09 +08:00
|
|
|
$(obj)/xdp_redirect_map_multi.bpf.o: $(obj)/xdp_sample.bpf.o
|
2021-08-21 08:20:07 +08:00
|
|
|
$(obj)/xdp_redirect_map.bpf.o: $(obj)/xdp_sample.bpf.o
|
2021-08-21 08:20:03 +08:00
|
|
|
$(obj)/xdp_redirect.bpf.o: $(obj)/xdp_sample.bpf.o
|
2021-08-21 08:20:01 +08:00
|
|
|
$(obj)/xdp_monitor.bpf.o: $(obj)/xdp_sample.bpf.o
|
|
|
|
|
|
|
|
$(obj)/%.bpf.o: $(src)/%.bpf.c $(obj)/vmlinux.h $(src)/xdp_sample.bpf.h $(src)/xdp_sample_shared.h
|
|
|
|
@echo " CLANG-BPF " $@
|
|
|
|
$(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(SRCARCH) \
|
|
|
|
-Wno-compare-distinct-pointer-types -I$(srctree)/include \
|
|
|
|
-I$(srctree)/samples/bpf -I$(srctree)/tools/include \
|
|
|
|
-I$(srctree)/tools/lib $(CLANG_SYS_INCLUDES) \
|
|
|
|
-c $(filter %.bpf.c,$^) -o $@
|
|
|
|
|
2021-08-21 08:20:09 +08:00
|
|
|
LINKED_SKELS := xdp_redirect_cpu.skel.h xdp_redirect_map_multi.skel.h \
|
|
|
|
xdp_redirect_map.skel.h xdp_redirect.skel.h xdp_monitor.skel.h
|
2021-08-21 08:20:01 +08:00
|
|
|
clean-files += $(LINKED_SKELS)
|
|
|
|
|
2021-08-21 08:20:05 +08:00
|
|
|
xdp_redirect_cpu.skel.h-deps := xdp_redirect_cpu.bpf.o xdp_sample.bpf.o
|
2021-08-21 08:20:09 +08:00
|
|
|
xdp_redirect_map_multi.skel.h-deps := xdp_redirect_map_multi.bpf.o xdp_sample.bpf.o
|
2021-08-21 08:20:07 +08:00
|
|
|
xdp_redirect_map.skel.h-deps := xdp_redirect_map.bpf.o xdp_sample.bpf.o
|
2021-08-21 08:20:03 +08:00
|
|
|
xdp_redirect.skel.h-deps := xdp_redirect.bpf.o xdp_sample.bpf.o
|
2021-08-21 08:20:01 +08:00
|
|
|
xdp_monitor.skel.h-deps := xdp_monitor.bpf.o xdp_sample.bpf.o
|
|
|
|
|
|
|
|
LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.bpf.c,$(foreach skel,$(LINKED_SKELS),$($(skel)-deps)))
|
|
|
|
|
|
|
|
BPF_SRCS_LINKED := $(notdir $(wildcard $(src)/*.bpf.c))
|
|
|
|
BPF_OBJS_LINKED := $(patsubst %.bpf.c,$(obj)/%.bpf.o, $(BPF_SRCS_LINKED))
|
|
|
|
BPF_SKELS_LINKED := $(addprefix $(obj)/,$(LINKED_SKELS))
|
|
|
|
|
|
|
|
$(BPF_SKELS_LINKED): $(BPF_OBJS_LINKED) $(BPFTOOL)
|
|
|
|
@echo " BPF GEN-OBJ " $(@:.skel.h=)
|
|
|
|
$(Q)$(BPFTOOL) gen object $(@:.skel.h=.lbpf.o) $(addprefix $(obj)/,$($(@F)-deps))
|
|
|
|
@echo " BPF GEN-SKEL" $(@:.skel.h=)
|
|
|
|
$(Q)$(BPFTOOL) gen skeleton $(@:.skel.h=.lbpf.o) name $(notdir $(@:.skel.h=)) > $@
|
|
|
|
|
2016-04-05 01:01:33 +08:00
|
|
|
# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
|
|
|
|
# But, there is no easy way to fix it, so just exclude it since it is
|
2015-11-13 06:07:46 +08:00
|
|
|
# useless for BPF samples.
|
samples/bpf: Change Makefile to cope with latest llvm
With latest llvm trunk, bpf programs under samples/bpf
directory, if using CORE, may experience the following
errors:
LLVM ERROR: Cannot select: intrinsic %llvm.preserve.struct.access.index
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. Program arguments: llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o
1. Running pass 'Function Pass Manager' on module '<stdin>'.
2. Running pass 'BPF DAG->DAG Pattern Instruction Selection' on function '@bpf_prog1'
#0 0x000000000183c26c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x183c26c)
...
#7 0x00000000017c375e (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x17c375e)
#8 0x00000000016a75c5 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*)
(/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16a75c5)
#9 0x00000000016ab4f8 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*,
unsigned int) (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16ab4f8)
...
Aborted (core dumped) | llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o
The reason is due to llvm change https://reviews.llvm.org/D87153
where the CORE relocation global generation is moved from the beginning
of target dependent optimization (llc) to the beginning
of target independent optimization (opt).
Since samples/bpf programs did not use vmlinux.h and its clang compilation
uses native architecture, we need to adjust arch triple at opt level
to do CORE relocation global generation properly. Otherwise, the above
error will appear.
This patch fixed the issue by introduce opt and llvm-dis to compilation chain,
which will do proper CORE relocation global generation as well as O2 level
optimization. Tested with llvm10, llvm11 and trunk/llvm12.
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20201006043427.1891742-1-yhs@fb.com
2020-10-06 12:34:26 +08:00
|
|
|
# below we use long chain of commands, clang | opt | llvm-dis | llc,
|
|
|
|
# to generate final object file. 'clang' compiles the source into IR
|
|
|
|
# with native target, e.g., x64, arm64, etc. 'opt' does bpf CORE IR builtin
|
|
|
|
# processing (llvm12) and IR optimizations. 'llvm-dis' converts
|
|
|
|
# 'opt' output to IR, and finally 'llc' generates bpf byte code.
|
2015-05-12 12:25:51 +08:00
|
|
|
$(obj)/%.o: $(src)/%.c
|
2018-05-15 13:35:06 +08:00
|
|
|
@echo " CLANG-bpf " $@
|
2019-10-11 08:27:57 +08:00
|
|
|
$(Q)$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(BPF_EXTRA_CFLAGS) \
|
|
|
|
-I$(obj) -I$(srctree)/tools/testing/selftests/bpf/ \
|
2020-01-20 21:06:49 +08:00
|
|
|
-I$(srctree)/tools/lib/ \
|
2018-05-14 03:32:22 +08:00
|
|
|
-D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign \
|
2019-07-15 17:11:03 +08:00
|
|
|
-D__TARGET_ARCH_$(SRCARCH) -Wno-compare-distinct-pointer-types \
|
2016-12-02 10:31:12 +08:00
|
|
|
-Wno-gnu-variable-sized-type-not-at-end \
|
|
|
|
-Wno-address-of-packed-member -Wno-tautological-compare \
|
2017-10-14 03:24:06 +08:00
|
|
|
-Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
|
2021-07-05 18:38:41 +08:00
|
|
|
-fno-asynchronous-unwind-tables \
|
samples/bpf: workaround clang asm goto compilation errors
x86 compilation has required asm goto support since 4.17.
Since clang does not support asm goto, at 4.17,
Commit b1ae32dbab50 ("x86/cpufeature: Guard asm_volatile_goto usage
for BPF compilation") worked around the issue by permitting an
alternative implementation without asm goto for clang.
At 5.0, more asm goto usages appeared.
[yhs@148 x86]$ egrep -r asm_volatile_goto
include/asm/cpufeature.h: asm_volatile_goto("1: jmp 6f\n"
include/asm/jump_label.h: asm_volatile_goto("1:"
include/asm/jump_label.h: asm_volatile_goto("1:"
include/asm/rmwcc.h: asm_volatile_goto (fullop "; j" #cc " %l[cc_label]" \
include/asm/uaccess.h: asm_volatile_goto("\n" \
include/asm/uaccess.h: asm_volatile_goto("\n" \
[yhs@148 x86]$
Compiling samples/bpf directories, most bpf programs failed
compilation with error messages like:
In file included from /home/yhs/work/bpf-next/samples/bpf/xdp_sample_pkts_kern.c:2:
In file included from /home/yhs/work/bpf-next/include/linux/ptrace.h:6:
In file included from /home/yhs/work/bpf-next/include/linux/sched.h:15:
In file included from /home/yhs/work/bpf-next/include/linux/sem.h:5:
In file included from /home/yhs/work/bpf-next/include/uapi/linux/sem.h:5:
In file included from /home/yhs/work/bpf-next/include/linux/ipc.h:9:
In file included from /home/yhs/work/bpf-next/include/linux/refcount.h:72:
/home/yhs/work/bpf-next/arch/x86/include/asm/refcount.h:70:9: error: 'asm goto' constructs are not supported yet
return GEN_BINARY_SUFFIXED_RMWcc(LOCK_PREFIX "subl",
^
/home/yhs/work/bpf-next/arch/x86/include/asm/rmwcc.h:67:2: note: expanded from macro 'GEN_BINARY_SUFFIXED_RMWcc'
__GEN_RMWcc(op " %[val], %[var]\n\t" suffix, var, cc, \
^
/home/yhs/work/bpf-next/arch/x86/include/asm/rmwcc.h:21:2: note: expanded from macro '__GEN_RMWcc'
asm_volatile_goto (fullop "; j" #cc " %l[cc_label]" \
^
/home/yhs/work/bpf-next/include/linux/compiler_types.h:188:37: note: expanded from macro 'asm_volatile_goto'
#define asm_volatile_goto(x...) asm goto(x)
Most implementation does not even provide an alternative
implementation. And it is also not practical to make changes
for each call site.
This patch workarounded the asm goto issue by redefining the macro like below:
#define asm_volatile_goto(x...) asm volatile("invalid use of asm_volatile_goto")
If asm_volatile_goto is not used by bpf programs, which is typically the case, nothing bad
will happen. If asm_volatile_goto is used by bpf programs, which is incorrect, the compiler
will issue an error since "invalid use of asm_volatile_goto" is not valid assembly codes.
With this patch, all bpf programs under samples/bpf can pass compilation.
Note that bpf programs under tools/testing/selftests/bpf/ compiled fine as
they do not access kernel internal headers.
Fixes: e769742d3584 ("Revert "x86/jump-labels: Macrofy inline assembly code to work around GCC inlining bugs"")
Fixes: 18fe58229d80 ("x86, asm: change the GEN_*_RMWcc() macros to not quote the condition")
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-01-13 07:04:30 +08:00
|
|
|
-I$(srctree)/samples/bpf/ -include asm_goto_workaround.h \
|
samples/bpf: Change Makefile to cope with latest llvm
With latest llvm trunk, bpf programs under samples/bpf
directory, if using CORE, may experience the following
errors:
LLVM ERROR: Cannot select: intrinsic %llvm.preserve.struct.access.index
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. Program arguments: llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o
1. Running pass 'Function Pass Manager' on module '<stdin>'.
2. Running pass 'BPF DAG->DAG Pattern Instruction Selection' on function '@bpf_prog1'
#0 0x000000000183c26c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x183c26c)
...
#7 0x00000000017c375e (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x17c375e)
#8 0x00000000016a75c5 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*)
(/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16a75c5)
#9 0x00000000016ab4f8 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*,
unsigned int) (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16ab4f8)
...
Aborted (core dumped) | llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o
The reason is due to llvm change https://reviews.llvm.org/D87153
where the CORE relocation global generation is moved from the beginning
of target dependent optimization (llc) to the beginning
of target independent optimization (opt).
Since samples/bpf programs did not use vmlinux.h and its clang compilation
uses native architecture, we need to adjust arch triple at opt level
to do CORE relocation global generation properly. Otherwise, the above
error will appear.
This patch fixed the issue by introduce opt and llvm-dis to compilation chain,
which will do proper CORE relocation global generation as well as O2 level
optimization. Tested with llvm10, llvm11 and trunk/llvm12.
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20201006043427.1891742-1-yhs@fb.com
2020-10-06 12:34:26 +08:00
|
|
|
-O2 -emit-llvm -Xclang -disable-llvm-passes -c $< -o - | \
|
|
|
|
$(OPT) -O2 -mtriple=bpf-pc-linux | $(LLVM_DIS) | \
|
|
|
|
$(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@
|
2018-07-26 18:13:44 +08:00
|
|
|
ifeq ($(DWARF2BTF),y)
|
|
|
|
$(BTF_PAHOLE) -J $@
|
|
|
|
endif
|