Commit e1cebd84 authored by Stanislav Fomichev's avatar Stanislav Fomichev Committed by Alexei Starovoitov

selftests/bpf: Fix a couple of broken test_btf cases

Commit 51c39bb1 ("bpf: Introduce function-by-function verification")
introduced function linkage flag and changed the error message from
"vlen != 0" to "Invalid func linkage" and broke some fake BPF programs.

Adjust the test accordingly.

AFACT, the programs don't really need any arguments and only look
at BTF for maps, so let's drop the args altogether.

Before:
BTF raw test[103] (func (Non zero vlen)): do_test_raw:3703:FAIL expected
err_str:vlen != 0
magic: 0xeb9f
version: 1
flags: 0x0
hdr_len: 24
type_off: 0
type_len: 72
str_off: 72
str_len: 10
btf_total_size: 106
[1] INT (anon) size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
[2] INT (anon) size=4 bits_offset=0 nr_bits=32 encoding=(none)
[3] FUNC_PROTO (anon) return=0 args=(1 a, 2 b)
[4] FUNC func type_id=3 Invalid func linkage

BTF libbpf test[1] (test_btf_haskv.o): libbpf: load bpf program failed:
Invalid argument
libbpf: -- BEGIN DUMP LOG ---
libbpf:
Validating test_long_fname_2() func#1...
Arg#0 type PTR in test_long_fname_2() is not supported yet.
processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0
peak_states 0 mark_read 0

libbpf: -- END LOG --
libbpf: failed to load program 'dummy_tracepoint'
libbpf: failed to load object 'test_btf_haskv.o'
do_test_file:4201:FAIL bpf_object__load: -4007
BTF libbpf test[2] (test_btf_newkv.o): libbpf: load bpf program failed:
Invalid argument
libbpf: -- BEGIN DUMP LOG ---
libbpf:
Validating test_long_fname_2() func#1...
Arg#0 type PTR in test_long_fname_2() is not supported yet.
processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0
peak_states 0 mark_read 0

libbpf: -- END LOG --
libbpf: failed to load program 'dummy_tracepoint'
libbpf: failed to load object 'test_btf_newkv.o'
do_test_file:4201:FAIL bpf_object__load: -4007
BTF libbpf test[3] (test_btf_nokv.o): libbpf: load bpf program failed:
Invalid argument
libbpf: -- BEGIN DUMP LOG ---
libbpf:
Validating test_long_fname_2() func#1...
Arg#0 type PTR in test_long_fname_2() is not supported yet.
processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0
peak_states 0 mark_read 0

libbpf: -- END LOG --
libbpf: failed to load program 'dummy_tracepoint'
libbpf: failed to load object 'test_btf_nokv.o'
do_test_file:4201:FAIL bpf_object__load: -4007

Fixes: 51c39bb1 ("bpf: Introduce function-by-function verification")
Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200422003753.124921-1-sdf@google.com
parent dfc55ace
...@@ -20,20 +20,12 @@ struct bpf_map_def SEC("maps") btf_map = { ...@@ -20,20 +20,12 @@ struct bpf_map_def SEC("maps") btf_map = {
BPF_ANNOTATE_KV_PAIR(btf_map, int, struct ipv_counts); BPF_ANNOTATE_KV_PAIR(btf_map, int, struct ipv_counts);
struct dummy_tracepoint_args {
unsigned long long pad;
struct sock *sock;
};
__attribute__((noinline)) __attribute__((noinline))
int test_long_fname_2(struct dummy_tracepoint_args *arg) int test_long_fname_2(void)
{ {
struct ipv_counts *counts; struct ipv_counts *counts;
int key = 0; int key = 0;
if (!arg->sock)
return 0;
counts = bpf_map_lookup_elem(&btf_map, &key); counts = bpf_map_lookup_elem(&btf_map, &key);
if (!counts) if (!counts)
return 0; return 0;
...@@ -44,15 +36,15 @@ int test_long_fname_2(struct dummy_tracepoint_args *arg) ...@@ -44,15 +36,15 @@ int test_long_fname_2(struct dummy_tracepoint_args *arg)
} }
__attribute__((noinline)) __attribute__((noinline))
int test_long_fname_1(struct dummy_tracepoint_args *arg) int test_long_fname_1(void)
{ {
return test_long_fname_2(arg); return test_long_fname_2();
} }
SEC("dummy_tracepoint") SEC("dummy_tracepoint")
int _dummy_tracepoint(struct dummy_tracepoint_args *arg) int _dummy_tracepoint(void *arg)
{ {
return test_long_fname_1(arg); return test_long_fname_1();
} }
char _license[] SEC("license") = "GPL"; char _license[] SEC("license") = "GPL";
...@@ -28,20 +28,12 @@ struct { ...@@ -28,20 +28,12 @@ struct {
__type(value, struct ipv_counts); __type(value, struct ipv_counts);
} btf_map SEC(".maps"); } btf_map SEC(".maps");
struct dummy_tracepoint_args {
unsigned long long pad;
struct sock *sock;
};
__attribute__((noinline)) __attribute__((noinline))
int test_long_fname_2(struct dummy_tracepoint_args *arg) int test_long_fname_2(void)
{ {
struct ipv_counts *counts; struct ipv_counts *counts;
int key = 0; int key = 0;
if (!arg->sock)
return 0;
counts = bpf_map_lookup_elem(&btf_map, &key); counts = bpf_map_lookup_elem(&btf_map, &key);
if (!counts) if (!counts)
return 0; return 0;
...@@ -57,15 +49,15 @@ int test_long_fname_2(struct dummy_tracepoint_args *arg) ...@@ -57,15 +49,15 @@ int test_long_fname_2(struct dummy_tracepoint_args *arg)
} }
__attribute__((noinline)) __attribute__((noinline))
int test_long_fname_1(struct dummy_tracepoint_args *arg) int test_long_fname_1(void)
{ {
return test_long_fname_2(arg); return test_long_fname_2();
} }
SEC("dummy_tracepoint") SEC("dummy_tracepoint")
int _dummy_tracepoint(struct dummy_tracepoint_args *arg) int _dummy_tracepoint(void *arg)
{ {
return test_long_fname_1(arg); return test_long_fname_1();
} }
char _license[] SEC("license") = "GPL"; char _license[] SEC("license") = "GPL";
...@@ -17,20 +17,12 @@ struct bpf_map_def SEC("maps") btf_map = { ...@@ -17,20 +17,12 @@ struct bpf_map_def SEC("maps") btf_map = {
.max_entries = 4, .max_entries = 4,
}; };
struct dummy_tracepoint_args {
unsigned long long pad;
struct sock *sock;
};
__attribute__((noinline)) __attribute__((noinline))
int test_long_fname_2(struct dummy_tracepoint_args *arg) int test_long_fname_2(void)
{ {
struct ipv_counts *counts; struct ipv_counts *counts;
int key = 0; int key = 0;
if (!arg->sock)
return 0;
counts = bpf_map_lookup_elem(&btf_map, &key); counts = bpf_map_lookup_elem(&btf_map, &key);
if (!counts) if (!counts)
return 0; return 0;
...@@ -41,15 +33,15 @@ int test_long_fname_2(struct dummy_tracepoint_args *arg) ...@@ -41,15 +33,15 @@ int test_long_fname_2(struct dummy_tracepoint_args *arg)
} }
__attribute__((noinline)) __attribute__((noinline))
int test_long_fname_1(struct dummy_tracepoint_args *arg) int test_long_fname_1(void)
{ {
return test_long_fname_2(arg); return test_long_fname_2();
} }
SEC("dummy_tracepoint") SEC("dummy_tracepoint")
int _dummy_tracepoint(struct dummy_tracepoint_args *arg) int _dummy_tracepoint(void *arg)
{ {
return test_long_fname_1(arg); return test_long_fname_1();
} }
char _license[] SEC("license") = "GPL"; char _license[] SEC("license") = "GPL";
...@@ -2854,7 +2854,7 @@ static struct btf_raw_test raw_tests[] = { ...@@ -2854,7 +2854,7 @@ static struct btf_raw_test raw_tests[] = {
.value_type_id = 1, .value_type_id = 1,
.max_entries = 4, .max_entries = 4,
.btf_load_err = true, .btf_load_err = true,
.err_str = "vlen != 0", .err_str = "Invalid func linkage",
}, },
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment