History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf

Daniel Borkmann says: ==================== pull-request: bpf 2019-12-02 The following pull-request contains BPF updates for your *net* tree. We've added 10 non-merge commits during the last 6 day(s) which contain a total of 10 files changed, 60 insertions(+), 51 deletions(-). The main changes are: 1) Fix vmlinux BTF generation for binutils pre v2.25, from Stanislav Fomichev. 2) Fix libbpf global variable relocation to take symbol's st_value offset into account, from Andrii Nakryiko. 3) Fix libbpf build on powerpc where check_abi target fails due to different readelf output format, from Aurelien Jarno. 4) Don't set BPF insns RO for the case when they are JITed in order to avoid fragmenting the direct map, from Daniel Borkmann. 5) Fix static checker warning in btf_distill_func_proto() as well as a build error due to empty enum when BPF is compiled out, from Alexei Starovoitov. 6) Fix up generation of bpf_helper_defs.h for perf, from Arnaldo Carvalho de Melo. ====================

David S. Miller committed 6 years ago

Commit 734c7022 parents 596cf45 3464afd10 files · +60 −51Browse files

Unified · Split

10 files
  1. include/linux/filter.h +6 −2
  2. kernel/bpf/btf.c +4 −1
  3. scripts/link-vmlinux.sh +7 −1
  4. tools/lib/bpf/Makefile +5 −5
  5. tools/lib/bpf/libbpf.c +20 −25
  6. tools/perf/MANIFEST +1 −0
  7. tools/testing/selftests/bpf/progs/fentry_test.c +6 −6
  8. tools/testing/selftests/bpf/progs/fexit_bpf2bpf.c +3 −3
  9. tools/testing/selftests/bpf/progs/fexit_test.c +6 −6
  10. tools/testing/selftests/bpf/progs/test_mmap.c +2 −2
include/linux/filter.h+6−2
@@ -776,8 +776,12 @@ bpf_ctx_narrow_access_offset(u32 off, u32 size, u32 size_default) · 775 unmodified lines
776776
777777 static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
778778 {
779− set_vm_flush_reset_perms(fp);
780− set_memory_ro((unsigned long)fp, fp->pages);
779+#ifndef CONFIG_BPF_JIT_ALWAYS_ON
780+ if (!fp->jited) {
781+ set_vm_flush_reset_perms(fp);
782+ set_memory_ro((unsigned long)fp, fp->pages);
783+ }
784+#endif
781785 }
782786
783787 static inline void bpf_jit_binary_lock_ro(struct bpf_binary_header *hdr)
kernel/bpf/btf.c+4−1
@@ -3463,6 +3463,7 @@ enum { · 3462 unmodified lines
34633463 __ctx_convert##_id,
34643464 #include <linux/bpf_types.h>
34653465 #undef BPF_PROG_TYPE
3466+ __ctx_convert_unused, /* to avoid empty enum in extreme .config */
34663467 };
34673468 static u8 bpf_ctx_convert_map[] = {
34683469 #define BPF_PROG_TYPE(_id, _name, prog_ctx_type, kern_ctx_type) \
@@ -3976,8 +3977,10 @@ static int __get_type_size(struct btf *btf, u32 btf_id, · 507 unmodified lines
39763977 t = btf_type_by_id(btf, btf_id);
39773978 while (t && btf_type_is_modifier(t))
39783979 t = btf_type_by_id(btf, t->type);
3979− if (!t)
3980+ if (!t) {
3981+ *bad_type = btf->types[0];
39803982 return -EINVAL;
3983+ }
39813984 if (btf_type_is_ptr(t))
39823985 /* kernel size of pointer. Not BPF's size of pointer*/
39833986 return sizeof(void *);
scripts/link-vmlinux.sh+7−1
@@ -127,7 +127,9 @@ gen_btf() · 126 unmodified lines
127127 cut -d, -f1 | cut -d' ' -f2)
128128 bin_format=$(LANG=C ${OBJDUMP} -f ${1} | grep 'file format' | \
129129 awk '{print $4}')
130− ${OBJCOPY} --dump-section .BTF=.btf.vmlinux.bin ${1} 2>/dev/null
130+ ${OBJCOPY} --change-section-address .BTF=0 \
131+ --set-section-flags .BTF=alloc -O binary \
132+ --only-section=.BTF ${1} .btf.vmlinux.bin
131133 ${OBJCOPY} -I binary -O ${bin_format} -B ${bin_arch} \
132134 --rename-section .data=.BTF .btf.vmlinux.bin ${2}
133135 }
@@ -253,6 +255,10 @@ btf_vmlinux_bin_o="" · 119 unmodified lines
253255 if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then
254256 if gen_btf .tmp_vmlinux.btf .btf.vmlinux.bin.o ; then
255257 btf_vmlinux_bin_o=.btf.vmlinux.bin.o
258+ else
259+ echo >&2 "Failed to generate BTF for vmlinux"
260+ echo >&2 "Try to disable CONFIG_DEBUG_INFO_BTF"
261+ exit 1
256262 fi
257263 fi
258264
tools/lib/bpf/Makefile+5−5
@@ -147,7 +147,7 @@ TAGS_PROG := $(if $(shell which etags 2>/dev/null),etags,ctags) · 146 unmodified lines
147147
148148 GLOBAL_SYM_COUNT = $(shell readelf -s --wide $(BPF_IN_SHARED) | \
149149 cut -d "@" -f1 | sed 's/_v[0-9]_[0-9]_[0-9].*//' | \
150− awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$8}' | \
150+ awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}' | \
151151 sort -u | wc -l)
152152 VERSIONED_SYM_COUNT = $(shell readelf -s --wide $(OUTPUT)libbpf.so | \
153153 grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | sort -u | wc -l)
@@ -180,9 +180,9 @@ $(BPF_IN_SHARED): force elfdep bpfdep bpf_helper_defs.h · 26 unmodified lines
180180 $(BPF_IN_STATIC): force elfdep bpfdep bpf_helper_defs.h
181181 $(Q)$(MAKE) $(build)=libbpf OUTPUT=$(STATIC_OBJDIR)
182182
183−bpf_helper_defs.h: $(srctree)/include/uapi/linux/bpf.h
183+bpf_helper_defs.h: $(srctree)/tools/include/uapi/linux/bpf.h
184184 $(Q)$(srctree)/scripts/bpf_helpers_doc.py --header \
185− --file $(srctree)/include/uapi/linux/bpf.h > bpf_helper_defs.h
185+ --file $(srctree)/tools/include/uapi/linux/bpf.h > bpf_helper_defs.h
186186
187187 $(OUTPUT)libbpf.so: $(OUTPUT)libbpf.so.$(LIBBPF_VERSION)
188188
@@ -214,9 +214,9 @@ check_abi: $(OUTPUT)libbpf.so · 25 unmodified lines
214214 "versioned symbols in $^ ($(VERSIONED_SYM_COUNT))." \
215215 "Please make sure all LIBBPF_API symbols are" \
216216 "versioned in $(VERSION_SCRIPT)." >&2; \
217− readelf -s --wide $(OUTPUT)libbpf-in.o | \
217+ readelf -s --wide $(BPF_IN_SHARED) | \
218218 cut -d "@" -f1 | sed 's/_v[0-9]_[0-9]_[0-9].*//' | \
219− awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$8}'| \
219+ awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}'| \
220220 sort -u > $(OUTPUT)libbpf_global_syms.tmp; \
221221 readelf -s --wide $(OUTPUT)libbpf.so | \
222222 grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | \
tools/lib/bpf/libbpf.c+20−25
@@ -171,10 +171,8 @@ struct bpf_program { · 170 unmodified lines
171171 RELO_DATA,
172172 } type;
173173 int insn_idx;
174− union {
175− int map_idx;
176− int text_off;
177− };
174+ int map_idx;
175+ int sym_off;
178176 } *reloc_desc;
179177 int nr_reloc;
180178 int log_level;
@@ -1819,12 +1817,12 @@ static int bpf_program__record_reloc(struct bpf_program *prog, · 1638 unmodified lines
18191817 return -LIBBPF_ERRNO__RELOC;
18201818 }
18211819 if (sym->st_value % 8) {
1822− pr_warn("bad call relo offset: %lu\n", sym->st_value);
1820+ pr_warn("bad call relo offset: %llu\n", (__u64)sym->st_value);
18231821 return -LIBBPF_ERRNO__RELOC;
18241822 }
18251823 reloc_desc->type = RELO_CALL;
18261824 reloc_desc->insn_idx = insn_idx;
1827− reloc_desc->text_off = sym->st_value / 8;
1825+ reloc_desc->sym_off = sym->st_value;
18281826 obj->has_pseudo_calls = true;
18291827 return 0;
18301828 }
@@ -1868,6 +1866,7 @@ static int bpf_program__record_reloc(struct bpf_program *prog, · 37 unmodified lines
18681866 reloc_desc->type = RELO_LD64;
18691867 reloc_desc->insn_idx = insn_idx;
18701868 reloc_desc->map_idx = map_idx;
1869+ reloc_desc->sym_off = 0; /* sym->st_value determines map_idx */
18711870 return 0;
18721871 }
18731872
@@ -1899,6 +1898,7 @@ static int bpf_program__record_reloc(struct bpf_program *prog, · 25 unmodified lines
18991898 reloc_desc->type = RELO_DATA;
19001899 reloc_desc->insn_idx = insn_idx;
19011900 reloc_desc->map_idx = map_idx;
1901+ reloc_desc->sym_off = sym->st_value;
19021902 return 0;
19031903 }
19041904
@@ -3563,8 +3563,8 @@ bpf_program__reloc_text(struct bpf_program *prog, struct bpf_object *obj, · 1658 unmodified lines
35633563 return -LIBBPF_ERRNO__RELOC;
35643564
35653565 if (prog->idx == obj->efile.text_shndx) {
3566− pr_warn("relo in .text insn %d into off %d\n",
3567− relo->insn_idx, relo->text_off);
3566+ pr_warn("relo in .text insn %d into off %d (insn #%d)\n",
3567+ relo->insn_idx, relo->sym_off, relo->sym_off / 8);
35683568 return -LIBBPF_ERRNO__RELOC;
35693569 }
35703570
@@ -3599,7 +3599,7 @@ bpf_program__reloc_text(struct bpf_program *prog, struct bpf_object *obj, · 28 unmodified lines
35993599 prog->section_name);
36003600 }
36013601 insn = &prog->insns[relo->insn_idx];
3602− insn->imm += relo->text_off + prog->main_prog_cnt - relo->insn_idx;
3602+ insn->imm += relo->sym_off / 8 + prog->main_prog_cnt - relo->insn_idx;
36033603 return 0;
36043604 }
36053605
@@ -3622,31 +3622,26 @@ bpf_program__relocate(struct bpf_program *prog, struct bpf_object *obj) · 16 unmodified lines
36223622 return 0;
36233623
36243624 for (i = 0; i < prog->nr_reloc; i++) {
3625− if (prog->reloc_desc[i].type == RELO_LD64 ||
3626− prog->reloc_desc[i].type == RELO_DATA) {
3627− bool relo_data = prog->reloc_desc[i].type == RELO_DATA;
3628− struct bpf_insn *insns = prog->insns;
3629− int insn_idx, map_idx;
3625+ struct reloc_desc *relo = &prog->reloc_desc[i];
36303626
3631− insn_idx = prog->reloc_desc[i].insn_idx;
3632− map_idx = prog->reloc_desc[i].map_idx;
3627+ if (relo->type == RELO_LD64 || relo->type == RELO_DATA) {
3628+ struct bpf_insn *insn = &prog->insns[relo->insn_idx];
36333629
3634− if (insn_idx + 1 >= (int)prog->insns_cnt) {
3630+ if (relo->insn_idx + 1 >= (int)prog->insns_cnt) {
36353631 pr_warn("relocation out of range: '%s'\n",
36363632 prog->section_name);
36373633 return -LIBBPF_ERRNO__RELOC;
36383634 }
36393635
3640− if (!relo_data) {
3641− insns[insn_idx].src_reg = BPF_PSEUDO_MAP_FD;
3636+ if (relo->type != RELO_DATA) {
3637+ insn[0].src_reg = BPF_PSEUDO_MAP_FD;
36423638 } else {
3643− insns[insn_idx].src_reg = BPF_PSEUDO_MAP_VALUE;
3644− insns[insn_idx + 1].imm = insns[insn_idx].imm;
3639+ insn[0].src_reg = BPF_PSEUDO_MAP_VALUE;
3640+ insn[1].imm = insn[0].imm + relo->sym_off;
36453641 }
3646− insns[insn_idx].imm = obj->maps[map_idx].fd;
3647− } else if (prog->reloc_desc[i].type == RELO_CALL) {
3648− err = bpf_program__reloc_text(prog, obj,
3649− &prog->reloc_desc[i]);
3642+ insn[0].imm = obj->maps[relo->map_idx].fd;
3643+ } else if (relo->type == RELO_CALL) {
3644+ err = bpf_program__reloc_text(prog, obj, relo);
36503645 if (err)
36513646 return err;
36523647 }
tools/perf/MANIFEST+1−0
@@ -19,3 +19,4 @@ tools/lib/bitmap.c · 18 unmodified lines
1919 tools/lib/str_error_r.c
2020 tools/lib/vsprintf.c
2121 tools/lib/zalloc.c
22+scripts/bpf_helpers_doc.py
tools/testing/selftests/bpf/progs/fentry_test.c+6−6
@@ -6,28 +6,28 @@ · 5 unmodified lines
66
77 char _license[] SEC("license") = "GPL";
88
9−static volatile __u64 test1_result;
9+__u64 test1_result = 0;
1010 BPF_TRACE_1("fentry/bpf_fentry_test1", test1, int, a)
1111 {
1212 test1_result = a == 1;
1313 return 0;
1414 }
1515
16−static volatile __u64 test2_result;
16+__u64 test2_result = 0;
1717 BPF_TRACE_2("fentry/bpf_fentry_test2", test2, int, a, __u64, b)
1818 {
1919 test2_result = a == 2 && b == 3;
2020 return 0;
2121 }
2222
23−static volatile __u64 test3_result;
23+__u64 test3_result = 0;
2424 BPF_TRACE_3("fentry/bpf_fentry_test3", test3, char, a, int, b, __u64, c)
2525 {
2626 test3_result = a == 4 && b == 5 && c == 6;
2727 return 0;
2828 }
2929
30−static volatile __u64 test4_result;
30+__u64 test4_result = 0;
3131 BPF_TRACE_4("fentry/bpf_fentry_test4", test4,
3232 void *, a, char, b, int, c, __u64, d)
3333 {
@@ -35,7 +35,7 @@ BPF_TRACE_4("fentry/bpf_fentry_test4", test4, · 1 unmodified line
3535 return 0;
3636 }
3737
38−static volatile __u64 test5_result;
38+__u64 test5_result = 0;
3939 BPF_TRACE_5("fentry/bpf_fentry_test5", test5,
4040 __u64, a, void *, b, short, c, int, d, __u64, e)
4141 {
@@ -44,7 +44,7 @@ BPF_TRACE_5("fentry/bpf_fentry_test5", test5, · 2 unmodified lines
4444 return 0;
4545 }
4646
47−static volatile __u64 test6_result;
47+__u64 test6_result = 0;
4848 BPF_TRACE_6("fentry/bpf_fentry_test6", test6,
4949 __u64, a, void *, b, short, c, int, d, void *, e, __u64, f)
5050 {
tools/testing/selftests/bpf/progs/fexit_bpf2bpf.c+3−3
@@ -8,7 +8,7 @@ struct sk_buff { · 7 unmodified lines
88 unsigned int len;
99 };
1010
11−static volatile __u64 test_result;
11+__u64 test_result = 0;
1212 BPF_TRACE_2("fexit/test_pkt_access", test_main,
1313 struct sk_buff *, skb, int, ret)
1414 {
@@ -23,7 +23,7 @@ BPF_TRACE_2("fexit/test_pkt_access", test_main, · 8 unmodified lines
2323 return 0;
2424 }
2525
26−static volatile __u64 test_result_subprog1;
26+__u64 test_result_subprog1 = 0;
2727 BPF_TRACE_2("fexit/test_pkt_access_subprog1", test_subprog1,
2828 struct sk_buff *, skb, int, ret)
2929 {
@@ -56,7 +56,7 @@ struct args_subprog2 { · 26 unmodified lines
5656 __u64 args[5];
5757 __u64 ret;
5858 };
59−static volatile __u64 test_result_subprog2;
59+__u64 test_result_subprog2 = 0;
6060 SEC("fexit/test_pkt_access_subprog2")
6161 int test_subprog2(struct args_subprog2 *ctx)
6262 {
tools/testing/selftests/bpf/progs/fexit_test.c+6−6
@@ -6,28 +6,28 @@ · 5 unmodified lines
66
77 char _license[] SEC("license") = "GPL";
88
9−static volatile __u64 test1_result;
9+__u64 test1_result = 0;
1010 BPF_TRACE_2("fexit/bpf_fentry_test1", test1, int, a, int, ret)
1111 {
1212 test1_result = a == 1 && ret == 2;
1313 return 0;
1414 }
1515
16−static volatile __u64 test2_result;
16+__u64 test2_result = 0;
1717 BPF_TRACE_3("fexit/bpf_fentry_test2", test2, int, a, __u64, b, int, ret)
1818 {
1919 test2_result = a == 2 && b == 3 && ret == 5;
2020 return 0;
2121 }
2222
23−static volatile __u64 test3_result;
23+__u64 test3_result = 0;
2424 BPF_TRACE_4("fexit/bpf_fentry_test3", test3, char, a, int, b, __u64, c, int, ret)
2525 {
2626 test3_result = a == 4 && b == 5 && c == 6 && ret == 15;
2727 return 0;
2828 }
2929
30−static volatile __u64 test4_result;
30+__u64 test4_result = 0;
3131 BPF_TRACE_5("fexit/bpf_fentry_test4", test4,
3232 void *, a, char, b, int, c, __u64, d, int, ret)
3333 {
@@ -37,7 +37,7 @@ BPF_TRACE_5("fexit/bpf_fentry_test4", test4, · 3 unmodified lines
3737 return 0;
3838 }
3939
40−static volatile __u64 test5_result;
40+__u64 test5_result = 0;
4141 BPF_TRACE_6("fexit/bpf_fentry_test5", test5,
4242 __u64, a, void *, b, short, c, int, d, __u64, e, int, ret)
4343 {
@@ -46,7 +46,7 @@ BPF_TRACE_6("fexit/bpf_fentry_test5", test5, · 2 unmodified lines
4646 return 0;
4747 }
4848
49−static volatile __u64 test6_result;
49+__u64 test6_result = 0;
5050 BPF_TRACE_7("fexit/bpf_fentry_test6", test6,
5151 __u64, a, void *, b, short, c, int, d, void *, e, __u64, f,
5252 int, ret)
tools/testing/selftests/bpf/progs/test_mmap.c+2−2
@@ -15,8 +15,8 @@ struct { · 14 unmodified lines
1515 __type(value, __u64);
1616 } data_map SEC(".maps");
1717
18−static volatile __u64 in_val;
19−static volatile __u64 out_val;
18+__u64 in_val = 0;
19+__u64 out_val = 0;
2020
2121 SEC("raw_tracepoint/sys_enter")
2222 int test_mmap(void *ctx)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t