Skip to content

Commit

Permalink
bpf: Prevent inlining of bpf_fentry_test7()
Browse files Browse the repository at this point in the history
With latest clang18, I hit test_progs failures for the following test:
  torvalds#13/2    bpf_cookie/multi_kprobe_link_api:FAIL
  torvalds#13/3    bpf_cookie/multi_kprobe_attach_api:FAIL
  torvalds#13      bpf_cookie:FAIL
  torvalds#75      fentry_fexit:FAIL
  torvalds#76/1    fentry_test/fentry:FAIL
  torvalds#76      fentry_test:FAIL
  torvalds#80/1    fexit_test/fexit:FAIL
  torvalds#80      fexit_test:FAIL
  torvalds#110/1   kprobe_multi_test/skel_api:FAIL
  torvalds#110/2   kprobe_multi_test/link_api_addrs:FAIL
  torvalds#110/3   kprobe_multi_test/link_api_syms:FAIL
  torvalds#110/4   kprobe_multi_test/attach_api_pattern:FAIL
  torvalds#110/5   kprobe_multi_test/attach_api_addrs:FAIL
  torvalds#110/6   kprobe_multi_test/attach_api_syms:FAIL
  torvalds#110     kprobe_multi_test:FAIL

For example, for torvalds#13/2, the error messages are
  ...
  kprobe_multi_test_run:FAIL:kprobe_test7_result unexpected kprobe_test7_result: actual 0 != expected 1
  ...
  kprobe_multi_test_run:FAIL:kretprobe_test7_result unexpected kretprobe_test7_result: actual 0 != expected 1

clang17 does not have this issue.

Further investigation shows that kernel func bpf_fentry_test7(), used
in the above tests, is inlined by the compiler although it is
marked as noinline.

  int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
  {
        return (long)arg;
  }

It is known that for simple functions like the above (e.g. just returning
a constant or an input argument), the clang compiler may still do inlining
for a noinline function. Adding 'asm volatile ("")' in the beginning of the
bpf_fentry_test7() can prevent inlining.

Signed-off-by: Yonghong Song <[email protected]>
  • Loading branch information
Yonghong Song authored and intel-lab-lkp committed Aug 26, 2023
1 parent ec0ded2 commit d406580
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions net/bpf/test_run.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ struct bpf_fentry_test_t {

int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
{
asm volatile ("");
return (long)arg;
}

Expand Down

0 comments on commit d406580

Please sign in to comment.