Skip to content

Commit ae72555

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf
Alexei Starovoitov says: ==================== pull-request: bpf 2019-12-05 The following pull-request contains BPF updates for your *net* tree. We've added 6 non-merge commits during the last 1 day(s) which contain a total of 14 files changed, 116 insertions(+), 37 deletions(-). The main changes are: 1) three selftests fixes, from Stanislav. 2) one samples fix, from Jesper. 3) one verifier fix, from Yonghong. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 0033b34 + 8f9081c commit ae72555

File tree

14 files changed

+116
-37
lines changed

14 files changed

+116
-37
lines changed

kernel/bpf/verifier.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9636,7 +9636,10 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
96369636
ret = -EINVAL;
96379637
goto out;
96389638
}
9639-
addr = (long) tgt_prog->aux->func[subprog]->bpf_func;
9639+
if (subprog == 0)
9640+
addr = (long) tgt_prog->bpf_func;
9641+
else
9642+
addr = (long) tgt_prog->aux->func[subprog]->bpf_func;
96409643
} else {
96419644
addr = kallsyms_lookup_name(tname);
96429645
if (!addr) {

samples/bpf/xdp_rxq_info_user.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,9 @@ int main(int argc, char **argv)
489489
if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd))
490490
return EXIT_FAIL;
491491

492-
map = bpf_map__next(NULL, obj);
493-
stats_global_map = bpf_map__next(map, obj);
494-
rx_queue_index_map = bpf_map__next(stats_global_map, obj);
492+
map = bpf_object__find_map_by_name(obj, "config_map");
493+
stats_global_map = bpf_object__find_map_by_name(obj, "stats_global_map");
494+
rx_queue_index_map = bpf_object__find_map_by_name(obj, "rx_queue_index_map");
495495
if (!map || !stats_global_map || !rx_queue_index_map) {
496496
printf("finding a map in obj file failed\n");
497497
return EXIT_FAIL;

tools/lib/bpf/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
libbpf_version.h
22
libbpf.pc
33
FEATURE-DUMP.libbpf
4-
test_libbpf
54
libbpf.so.*
65
TAGS
76
tags

tools/lib/bpf/Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ GLOBAL_SYM_COUNT = $(shell readelf -s --wide $(BPF_IN_SHARED) | \
152152
VERSIONED_SYM_COUNT = $(shell readelf -s --wide $(OUTPUT)libbpf.so | \
153153
grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | sort -u | wc -l)
154154

155-
CMD_TARGETS = $(LIB_TARGET) $(PC_FILE) $(OUTPUT)test_libbpf
155+
CMD_TARGETS = $(LIB_TARGET) $(PC_FILE)
156156

157157
all: fixdep
158158
$(Q)$(MAKE) all_cmd
@@ -196,9 +196,6 @@ $(OUTPUT)libbpf.so.$(LIBBPF_VERSION): $(BPF_IN_SHARED)
196196
$(OUTPUT)libbpf.a: $(BPF_IN_STATIC)
197197
$(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
198198

199-
$(OUTPUT)test_libbpf: test_libbpf.c $(OUTPUT)libbpf.a
200-
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(INCLUDES) $^ -lelf -o $@
201-
202199
$(OUTPUT)libbpf.pc:
203200
$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
204201
-e "s|@LIBDIR@|$(libdir_SQ)|" \

tools/testing/selftests/bpf/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ libbpf.so.*
3737
test_hashmap
3838
test_btf_dump
3939
xdping
40+
test_cpp
4041
/no_alu32
4142
/bpf_gcc

tools/testing/selftests/bpf/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ TEST_PROGS_EXTENDED := with_addr.sh \
7171
# Compile but not part of 'make run_tests'
7272
TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
7373
flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \
74-
test_lirc_mode2_user xdping
74+
test_lirc_mode2_user xdping test_cpp
7575

7676
TEST_CUSTOM_PROGS = urandom_read
7777

@@ -317,6 +317,10 @@ verifier/tests.h: verifier/*.c
317317
$(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)
318318
$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
319319

320+
# Make sure we are able to include and link libbpf against c++.
321+
$(OUTPUT)/test_cpp: test_cpp.cpp $(BPFOBJ)
322+
$(CXX) $(CFLAGS) $^ $(LDLIBS) -o $@
323+
320324
EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) \
321325
prog_tests/tests.h map_tests/tests.h verifier/tests.h \
322326
feature $(OUTPUT)/*.o $(OUTPUT)/no_alu32 $(OUTPUT)/bpf_gcc

tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,36 @@
22
/* Copyright (c) 2019 Facebook */
33
#include <test_progs.h>
44

5-
#define PROG_CNT 3
6-
7-
void test_fexit_bpf2bpf(void)
5+
static void test_fexit_bpf2bpf_common(const char *obj_file,
6+
const char *target_obj_file,
7+
int prog_cnt,
8+
const char **prog_name)
89
{
9-
const char *prog_name[PROG_CNT] = {
10-
"fexit/test_pkt_access",
11-
"fexit/test_pkt_access_subprog1",
12-
"fexit/test_pkt_access_subprog2",
13-
};
1410
struct bpf_object *obj = NULL, *pkt_obj;
1511
int err, pkt_fd, i;
16-
struct bpf_link *link[PROG_CNT] = {};
17-
struct bpf_program *prog[PROG_CNT];
12+
struct bpf_link **link = NULL;
13+
struct bpf_program **prog = NULL;
1814
__u32 duration, retval;
1915
struct bpf_map *data_map;
2016
const int zero = 0;
21-
u64 result[PROG_CNT];
17+
u64 *result = NULL;
2218

23-
err = bpf_prog_load("./test_pkt_access.o", BPF_PROG_TYPE_UNSPEC,
19+
err = bpf_prog_load(target_obj_file, BPF_PROG_TYPE_UNSPEC,
2420
&pkt_obj, &pkt_fd);
2521
if (CHECK(err, "prog_load sched cls", "err %d errno %d\n", err, errno))
2622
return;
2723
DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts,
2824
.attach_prog_fd = pkt_fd,
2925
);
3026

31-
obj = bpf_object__open_file("./fexit_bpf2bpf.o", &opts);
27+
link = calloc(sizeof(struct bpf_link *), prog_cnt);
28+
prog = calloc(sizeof(struct bpf_program *), prog_cnt);
29+
result = malloc(prog_cnt * sizeof(u64));
30+
if (CHECK(!link || !prog || !result, "alloc_memory",
31+
"failed to alloc memory"))
32+
goto close_prog;
33+
34+
obj = bpf_object__open_file(obj_file, &opts);
3235
if (CHECK(IS_ERR_OR_NULL(obj), "obj_open",
3336
"failed to open fexit_bpf2bpf: %ld\n",
3437
PTR_ERR(obj)))
@@ -38,7 +41,7 @@ void test_fexit_bpf2bpf(void)
3841
if (CHECK(err, "obj_load", "err %d\n", err))
3942
goto close_prog;
4043

41-
for (i = 0; i < PROG_CNT; i++) {
44+
for (i = 0; i < prog_cnt; i++) {
4245
prog[i] = bpf_object__find_program_by_title(obj, prog_name[i]);
4346
if (CHECK(!prog[i], "find_prog", "prog %s not found\n", prog_name[i]))
4447
goto close_prog;
@@ -56,21 +59,54 @@ void test_fexit_bpf2bpf(void)
5659
"err %d errno %d retval %d duration %d\n",
5760
err, errno, retval, duration);
5861

59-
err = bpf_map_lookup_elem(bpf_map__fd(data_map), &zero, &result);
62+
err = bpf_map_lookup_elem(bpf_map__fd(data_map), &zero, result);
6063
if (CHECK(err, "get_result",
6164
"failed to get output data: %d\n", err))
6265
goto close_prog;
6366

64-
for (i = 0; i < PROG_CNT; i++)
67+
for (i = 0; i < prog_cnt; i++)
6568
if (CHECK(result[i] != 1, "result", "fexit_bpf2bpf failed err %ld\n",
6669
result[i]))
6770
goto close_prog;
6871

6972
close_prog:
70-
for (i = 0; i < PROG_CNT; i++)
73+
for (i = 0; i < prog_cnt; i++)
7174
if (!IS_ERR_OR_NULL(link[i]))
7275
bpf_link__destroy(link[i]);
7376
if (!IS_ERR_OR_NULL(obj))
7477
bpf_object__close(obj);
7578
bpf_object__close(pkt_obj);
79+
free(link);
80+
free(prog);
81+
free(result);
82+
}
83+
84+
static void test_target_no_callees(void)
85+
{
86+
const char *prog_name[] = {
87+
"fexit/test_pkt_md_access",
88+
};
89+
test_fexit_bpf2bpf_common("./fexit_bpf2bpf_simple.o",
90+
"./test_pkt_md_access.o",
91+
ARRAY_SIZE(prog_name),
92+
prog_name);
93+
}
94+
95+
static void test_target_yes_callees(void)
96+
{
97+
const char *prog_name[] = {
98+
"fexit/test_pkt_access",
99+
"fexit/test_pkt_access_subprog1",
100+
"fexit/test_pkt_access_subprog2",
101+
};
102+
test_fexit_bpf2bpf_common("./fexit_bpf2bpf.o",
103+
"./test_pkt_access.o",
104+
ARRAY_SIZE(prog_name),
105+
prog_name);
106+
}
107+
108+
void test_fexit_bpf2bpf(void)
109+
{
110+
test_target_no_callees();
111+
test_target_yes_callees();
76112
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (c) 2019 Facebook */
3+
#include <linux/bpf.h>
4+
#include "bpf_helpers.h"
5+
#include "bpf_trace_helpers.h"
6+
7+
struct sk_buff {
8+
unsigned int len;
9+
};
10+
11+
__u64 test_result = 0;
12+
BPF_TRACE_2("fexit/test_pkt_md_access", test_main2,
13+
struct sk_buff *, skb, int, ret)
14+
{
15+
int len;
16+
17+
__builtin_preserve_access_index(({
18+
len = skb->len;
19+
}));
20+
if (len != 74 || ret != 0)
21+
return 0;
22+
23+
test_result = 1;
24+
return 0;
25+
}
26+
char _license[] SEC("license") = "GPL";

tools/testing/selftests/bpf/progs/test_pkt_md_access.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ int _version SEC("version") = 1;
2727
}
2828
#endif
2929

30-
SEC("test1")
31-
int process(struct __sk_buff *skb)
30+
SEC("classifier/test_pkt_md_access")
31+
int test_pkt_md_access(struct __sk_buff *skb)
3232
{
3333
TEST_FIELD(__u8, len, 0xFF);
3434
TEST_FIELD(__u16, len, 0xFFFF);

tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ int bpf_testcb(struct bpf_sock_ops *skops)
131131
g.bytes_received = skops->bytes_received;
132132
g.bytes_acked = skops->bytes_acked;
133133
}
134+
g.num_close_events++;
134135
bpf_map_update_elem(&global_map, &key, &g,
135136
BPF_ANY);
136137
}

0 commit comments

Comments
 (0)