selftests:bpf:Fix repeated initialization
Subsystems (3)
PATCH 1/1 selftests:bpf:Fix repeated initialization
In use_missing_map function, value is initialized twice.There is no connection between the two assignment. This patch could fix this bug.
--- tools/testing/selftests/bpf/progs/test_log_fixup.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
tools/testing/selftests/bpf/progs/test_log_fixup.c +2 -6
@@ -52,13 +52,9 @@ struct { SEC("?raw_tp/sys_enter")int use_missing_map (const void *ctx) { -int zero =0 , *value; +int zero =0 ; - value =bpf_map_lookup_elem (&existing_map, &zero); - - value =bpf_map_lookup_elem (&missing_map, &zero); - -return value !=NULL ; +return bpf_map_lookup_elem (&missing_map, &zero) !=NULL ; } extern int bpf_nonexistent_kfunc(void) __ksym __weak;
Signature · 1 line
2.25.1
Daniel Borkmann
maintainerQuoted 4 lines · Wang Ming
In
use_missing_mapfunction, value is initialized twice.There is no connection between the two assignment. This patch could fix this bug.
Please never submit patches where you are just speculating and did not even bother to run BPF selftests !
Otherwise you would have seen that your change is breaking it :
Error: #126 log_fixup
Error: #126/5 log_fixup/missing_map
Error: #126/5 log_fixup/missing_map
missing_map:PASS:skel_open 0 nsec
libbpf: prog 'use_missing_map': BPF program load failed: Invalid argument
libbpf: prog 'use_missing_map': failed to load: -22
libbpf: failed to load object 'test_log_fixup'
libbpf: failed to load BPF skeleton 'test_log_fixup': -22 missing_map:PASS:load_fail 0 nsec
missing_map:PASS:existing_map_autocreate 0 nsec missing_map:PASS:missing_map_autocreate 0 nsec
missing_map:FAIL:log_buf unexpected log_buf: '8: <invalid BPF map reference>
BPF map 'missing_map' is referenced but wasn't created
' is not a substring of 'reg type unsupported for arg#0 function use_missing_map#20 0: R1=ctx(off=0,imm=0) R10=fp0
; int use_missing_map(const void *ctx)
0: (b4) w1 = 0 ; R1_w=0
; int zero = 0;
1: (63) *(u32 *)(r10 -4) = r1 ; R1_w=0 R10=fp0 fp-8=0000????
2: (bf) r2 = r10 ; R2_w=fp0 R10=fp0
;
3: (07) r2 += -4 ; R2_w=fp-4
; return bpf_map_lookup_elem(&missing_map, &zero) != NULL;
4: <invalid BPF map reference>
BPF map 'missing_map' is referenced but wasn't created
processed 5 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
Quoted 26 lines
Signed-off-by Wang Ming <[email protected]>--- tools/testing/selftests/bpf/progs/test_log_fixup.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)tools/testing/selftests/bpf/progs/test_log_fixup.c +2
-6@@ -52,13 +52,9 @@ struct { SEC("?raw_tp/sys_enter")int use_missing_map (const void *ctx) { -int zero =0 , *value; +int zero =0 ; - value =bpf_map_lookup_elem (&existing_map, &zero); - - value =bpf_map_lookup_elem (&missing_map, &zero); - -return value !=NULL ; +return bpf_map_lookup_elem (&missing_map, &zero) !=NULL ; } extern int bpf_nonexistent_kfunc(void) __ksym __weak;
Thank you, but I don't understand the error.
-----邮件原件-----
发件人: Daniel Borkmann <[email protected]>
发送时间: 2023年7月5日 21:32
收件人: 王明-软件底层技术部 <[email protected]>; Alexei Starovoitov <[email protected]>; Andrii Nakryiko <[email protected]>; Martin KaFai Lau <[email protected]>; Song Liu <[email protected]>; Yonghong Song <[email protected]>; John Fastabend <[email protected]>; KP Singh <[email protected]>; Stanislav Fomichev <[email protected]>; Hao Luo <[email protected]>; Jiri Olsa <[email protected]>; Mykola Lysenko <[email protected]>; Shuah Khan <[email protected]>; [email protected]; [email protected]; [email protected] 抄送: opensource.kernel <[email protected]>
主题: Re: [PATCH v1] selftests:bpf:Fix repeated initialization
Quoted 4 lines · Wang Ming
In
use_missing_mapfunction, value is initialized twice.There is no connection between the two assignment. This patch could fix this bug.
Please never submit patches where you are just speculating and did not even bother to run BPF selftests !
Otherwise you would have seen that your change is breaking it :
Error: #126 log_fixup
Error: #126/5 log_fixup/missing_map
Error: #126/5 log_fixup/missing_map
missing_map:PASS:skel_open 0 nsec
libbpf: prog 'use_missing_map': BPF program load failed: Invalid argument
libbpf: prog 'use_missing_map': failed to load: -22
libbpf: failed to load object 'test_log_fixup'
libbpf: failed to load BPF skeleton 'test_log_fixup': -22 missing_map:PASS:load_fail 0 nsec
missing_map:PASS:existing_map_autocreate 0 nsec missing_map:PASS:missing_map_autocreate 0 nsec
missing_map:FAIL:log_buf unexpected log_buf: '8: <invalid BPF map reference>
BPF map 'missing_map' is referenced but wasn't created
' is not a substring of 'reg type unsupported for arg#0 function use_missing_map#20 0: R1=ctx(off=0,imm=0) R10=fp0
; int use_missing_map(const void *ctx)
0: (b4) w1 = 0 ; R1_w=0
; int zero = 0;
1: (63) *(u32 *)(r10 -4) = r1 ; R1_w=0 R10=fp0 fp-8=0000????
2: (bf) r2 = r10 ; R2_w=fp0 R10=fp0
;
3: (07) r2 += -4 ; R2_w=fp-4
; return bpf_map_lookup_elem(&missing_map, &zero) != NULL;
4: <invalid BPF map reference>
BPF map 'missing_map' is referenced but wasn't created
processed 5 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
Quoted 27 lines
Signed-off-by Wang Ming <[email protected]>--- tools/testing/selftests/bpf/progs/test_log_fixup.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)tools/testing/selftests/bpf/progs/test_log_fixup.c +2
-6@@ -52,13 +52,9 @@ struct { SEC("?raw_tp/sys_enter")int use_missing_map (const void *ctx) { -int zero =0 , *value; +int zero =0 ; - value =bpf_map_lookup_elem (&existing_map, &zero); - - value =bpf_map_lookup_elem (&missing_map, &zero); - -return value !=NULL ; +return bpf_map_lookup_elem (&missing_map, &zero) !=NULL ; } extern int bpf_nonexistent_kfunc(void) __ksym __weak;