Skip to contentSkip to conversation

bpf: Issue with bpf_fentry_test7 call

RFC In review Jiri Olsa 3 participants 6 messages Dec 15, 2023

Subsystems (4)
lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

RFC 1/1 bpf: Issue with bpf_fentry_test7 call

hi,
The bpf CI is broken due to clang emitting 2 functions for bpf_fentry_test7:

  # cat available_filter_functions | grep bpf_fentry_test7
  bpf_fentry_test7
  bpf_fentry_test7.specialized.1

The tests attach to 'bpf_fentry_test7' while the function with '.specialized.1' suffix is executed in bpf_prog_test_run_tracing.

It looks like clang optimalization that comes from passing 0 as argument and returning it directly in bpf_fentry_test7.

I'm not sure there's a way to disable this, so far I came up with solution below that passes real pointer, but I think that was not the original intention for the test.

We had issue with this function back in august:
32337c0a2824 bpf: Prevent inlining of bpf_fentry_test7()

I'm not sure why it started to show now? was clang updated for CI?

I'll try to find out more, but any clang ideas are welcome ;-)

thanks,
jirka

---

net/bpf/test_run.c +2 -2
index c9fdcc5cdce1..33208eec9361 100644
@@ -543,7 +543,7 @@ struct bpf_fentry_test_t {
 int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
 {
 	asm volatile ("");
-	return (long)arg;
+	return 0;
 }
 
 int noinline bpf_fentry_test8(struct bpf_fentry_test_t *arg)
@@ -668,7 +668,7 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
 		    bpf_fentry_test4((void *)7, 8, 9, 10) != 34 ||
 		    bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 ||
 		    bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 ||
-		    bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 ||
+		    bpf_fentry_test7(&arg) != 0 ||
 		    bpf_fentry_test8(&arg) != 0 ||
 		    bpf_fentry_test9(&retval) != 0)
 			goto out;
tools/testing/selftests/bpf/progs/fentry_test.c +1 -1
index 52a550d281d9..95c5c34ccaa8 100644
@@ -64,7 +64,7 @@ __u64 test7_result = 0;
 SEC("fentry/bpf_fentry_test7")
 int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
 {
-	if (!arg)
+	if (arg)
 		test7_result = 1;
 	return 0;
 }
tools/testing/selftests/bpf/progs/fexit_test.c +1 -1
index 8f1ccb7302e1..ffb30236ca02 100644
@@ -65,7 +65,7 @@ __u64 test7_result = 0;
 SEC("fexit/bpf_fentry_test7")
 int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
 {
-	if (!arg)
+	if (arg)
 		test7_result = 1;
 	return 0;
 }
author
#1 lore raw
Quoted 18 lines · Jiri Olsa

hi,
The bpf CI is broken due to clang emitting 2 functions for bpf_fentry_test7:

  # cat available_filter_functions | grep bpf_fentry_test7
  bpf_fentry_test7
  bpf_fentry_test7.specialized.1

The tests attach to 'bpf_fentry_test7' while the function with '.specialized.1' suffix is executed in bpf_prog_test_run_tracing.

It looks like clang optimalization that comes from passing 0 as argument and returning it directly in bpf_fentry_test7.

I'm not sure there's a way to disable this, so far I came up with solution below that passes real pointer, but I think that was not the original intention for the test.

Quoted 6 lines

We had issue with this function back in august:
32337c0a2824 bpf: Prevent inlining of bpf_fentry_test7()

I'm not sure why it started to show now? was clang updated for CI?

I'll try to find out more, but any clang ideas are welcome ;-)

fyi also there's probably another related usse in global_func17 test:

	run_subtest:FAIL:unexpected_load_success unexpected success: 0
	#290/17  test_global_funcs/global_func17:FAIL

looks like clang optimized the call out and returns the value directly:

	Disassembly of section .text:

	0000000000000000 <foo>:
	       0:       b4 00 00 00 00 00 00 00 w0 = 0x0
	       1:       15 01 02 00 00 00 00 00 if r1 == 0x0 goto +0x2 <LBB0_2>
	       2:       b4 00 00 00 2a 00 00 00 w0 = 0x2a
	       3:       63 01 00 00 00 00 00 00 *(u32 *)(r1 + 0x0) = r0

	0000000000000020 <LBB0_2>:
	       4:       95 00 00 00 00 00 00 00 exit

	Disassembly of section tc:

	0000000000000000 <global_func17>:
	       0:       b4 00 00 00 2a 00 00 00 w0 = 0x2a
	       1:       95 00 00 00 00 00 00 00 exit

jirka

Quoted 54 lines

thanks,
jirka

---

net/bpf/test_run.c +2 -2
index c9fdcc5cdce1..33208eec9361 100644
@@ -543,7 +543,7 @@ struct bpf_fentry_test_t {
 int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
 {
 	asm volatile ("");
-	return (long)arg;
+	return 0;
 }
 
 int noinline bpf_fentry_test8(struct bpf_fentry_test_t *arg)
@@ -668,7 +668,7 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
 		    bpf_fentry_test4((void *)7, 8, 9, 10) != 34 ||
 		    bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 ||
 		    bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 ||
-		    bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 ||
+		    bpf_fentry_test7(&arg) != 0 ||
 		    bpf_fentry_test8(&arg) != 0 ||
 		    bpf_fentry_test9(&retval) != 0)
 			goto out;
tools/testing/selftests/bpf/progs/fentry_test.c +1 -1
index 52a550d281d9..95c5c34ccaa8 100644
@@ -64,7 +64,7 @@ __u64 test7_result = 0;
 SEC("fentry/bpf_fentry_test7")
 int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
 {
-	if (!arg)
+	if (arg)
 		test7_result = 1;
 	return 0;
 }
tools/testing/selftests/bpf/progs/fexit_test.c +1 -1
index 8f1ccb7302e1..ffb30236ca02 100644
@@ -65,7 +65,7 @@ __u64 test7_result = 0;
 SEC("fexit/bpf_fentry_test7")
 int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
 {
-	if (!arg)
+	if (arg)
 		test7_result = 1;
 	return 0;
 }
author
#2 lore raw
In reply to Jiri Olsa
Quoted 21 lines · Jiri Olsa

hi,
The bpf CI is broken due to clang emitting 2 functions for bpf_fentry_test7:

  # cat available_filter_functions | grep bpf_fentry_test7
  bpf_fentry_test7
  bpf_fentry_test7.specialized.1

The tests attach to 'bpf_fentry_test7' while the function with '.specialized.1' suffix is executed in bpf_prog_test_run_tracing.

It looks like clang optimalization that comes from passing 0 as argument and returning it directly in bpf_fentry_test7.

I'm not sure there's a way to disable this, so far I came up with solution below that passes real pointer, but I think that was not the original intention for the test.

We had issue with this function back in august:
32337c0a2824 bpf: Prevent inlining of bpf_fentry_test7()

Quoted 6 lines

I'm not sure why it started to show now? was clang updated for CI?

I'll try to find out more, but any clang ideas are welcome ;-)

thanks,
jirka

hm, there seems to be fix in bpf-next for this one:

b16904fd9f01 bpf: Fix a few selftest failures due to llvm18 change

jirka

Quoted 51 lines

---

net/bpf/test_run.c +2 -2
index c9fdcc5cdce1..33208eec9361 100644
@@ -543,7 +543,7 @@ struct bpf_fentry_test_t {
 int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
 {
 	asm volatile ("");
-	return (long)arg;
+	return 0;
 }
 
 int noinline bpf_fentry_test8(struct bpf_fentry_test_t *arg)
@@ -668,7 +668,7 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
 		    bpf_fentry_test4((void *)7, 8, 9, 10) != 34 ||
 		    bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 ||
 		    bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 ||
-		    bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 ||
+		    bpf_fentry_test7(&arg) != 0 ||
 		    bpf_fentry_test8(&arg) != 0 ||
 		    bpf_fentry_test9(&retval) != 0)
 			goto out;
tools/testing/selftests/bpf/progs/fentry_test.c +1 -1
index 52a550d281d9..95c5c34ccaa8 100644
@@ -64,7 +64,7 @@ __u64 test7_result = 0;
 SEC("fentry/bpf_fentry_test7")
 int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
 {
-	if (!arg)
+	if (arg)
 		test7_result = 1;
 	return 0;
 }
tools/testing/selftests/bpf/progs/fexit_test.c +1 -1
index 8f1ccb7302e1..ffb30236ca02 100644
@@ -65,7 +65,7 @@ __u64 test7_result = 0;
 SEC("fexit/bpf_fentry_test7")
 int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
 {
-	if (!arg)
+	if (arg)
 		test7_result = 1;
 	return 0;
 }
reviewer
#3 lore raw
Quoted 24 lines · Jiri Olsa
Quoted 23 lines · Jiri Olsa

hi,
The bpf CI is broken due to clang emitting 2 functions for bpf_fentry_test7:

   # cat available_filter_functions | grep bpf_fentry_test7
   bpf_fentry_test7
   bpf_fentry_test7.specialized.1

The tests attach to 'bpf_fentry_test7' while the function with '.specialized.1' suffix is executed in bpf_prog_test_run_tracing.

It looks like clang optimalization that comes from passing 0 as argument and returning it directly in bpf_fentry_test7.

I'm not sure there's a way to disable this, so far I came up with solution below that passes real pointer, but I think that was not the original intention for the test.

We had issue with this function back in august:

   32337c0a2824 bpf: Prevent inlining of bpf_fentry_test7()

I'm not sure why it started to show now? was clang updated for CI?

Quoted 8 lines
Quoted 4 lines

I'll try to find out more, but any clang ideas are welcome ;-)

thanks,
jirka

hm, there seems to be fix in bpf-next for this one:

b16904fd9f01 bpf: Fix a few selftest failures due to llvm18 change

Maybe submit a patch to https://github.com/kernel-patches/vmtest/tree/master/ci/diffs?
That is typically the place to have temporary patches to workaround ci failures.

Quoted 53 lines

jirka

Quoted 50 lines

---

net/bpf/test_run.c +2 -2
index c9fdcc5cdce1..33208eec9361 100644
@@ -543,7 +543,7 @@ struct bpf_fentry_test_t {
  int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
  {
  	asm volatile ("");
-	return (long)arg;
+	return 0;
  }
 
  int noinline bpf_fentry_test8(struct bpf_fentry_test_t *arg)
@@ -668,7 +668,7 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
  		    bpf_fentry_test4((void *)7, 8, 9, 10) != 34 ||
  		    bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 ||
  		    bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 ||
-		    bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 ||
+		    bpf_fentry_test7(&arg) != 0 ||
  		    bpf_fentry_test8(&arg) != 0 ||
  		    bpf_fentry_test9(&retval) != 0)
  			goto out;
tools/testing/selftests/bpf/progs/fentry_test.c +1 -1
index 52a550d281d9..95c5c34ccaa8 100644
@@ -64,7 +64,7 @@ __u64 test7_result = 0;
  SEC("fentry/bpf_fentry_test7")
  int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
  {
-	if (!arg)
+	if (arg)
  		test7_result = 1;
  	return 0;
  }
tools/testing/selftests/bpf/progs/fexit_test.c +1 -1
index 8f1ccb7302e1..ffb30236ca02 100644
@@ -65,7 +65,7 @@ __u64 test7_result = 0;
  SEC("fexit/bpf_fentry_test7")
  int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
  {
-	if (!arg)
+	if (arg)
  		test7_result = 1;
  	return 0;
  }
#4 lore raw
Quoted 32 lines · Yonghong Song
Quoted 29 lines · Jiri Olsa
Quoted 27 lines · Jiri Olsa

hi,
The bpf CI is broken due to clang emitting 2 functions for bpf_fentry_test7:

   # cat available_filter_functions | grep bpf_fentry_test7
   bpf_fentry_test7
   bpf_fentry_test7.specialized.1

The tests attach to 'bpf_fentry_test7' while the function with '.specialized.1' suffix is executed in bpf_prog_test_run_tracing.

It looks like clang optimalization that comes from passing 0 as argument and returning it directly in bpf_fentry_test7.

I'm not sure there's a way to disable this, so far I came up with solution below that passes real pointer, but I think that was not the original intention for the test.

We had issue with this function back in august:

   32337c0a2824 bpf: Prevent inlining of bpf_fentry_test7()

I'm not sure why it started to show now? was clang updated for CI?

I'll try to find out more, but any clang ideas are welcome ;-)

thanks,
jirka

Quoted 7 lines
Quoted 3 lines

hm, there seems to be fix in bpf-next for this one:

b16904fd9f01 bpf: Fix a few selftest failures due to llvm18 change

Maybe submit a patch to https://github.com/kernel-patches/vmtest/tree/master/ci/diffs?
That is typically the place to have temporary patches to workaround ci failures.

To get bpf/master back to green CI I did it meanwhile ([0]). Jiri, please check the PR to be familiar with the process for the future similar mitigations, thanks.

[0] https://github.com/kernel-patches/vmtest/pull/258

Quoted 53 lines
Quoted 53 lines

jirka

Quoted 50 lines

---

net/bpf/test_run.c +2 -2
index c9fdcc5cdce1..33208eec9361 100644
@@ -543,7 +543,7 @@ struct bpf_fentry_test_t {
  int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
  {
     asm volatile ("");
-    return (long)arg;
+    return 0;
  }
 
  int noinline bpf_fentry_test8(struct bpf_fentry_test_t *arg)
@@ -668,7 +668,7 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
                 bpf_fentry_test4((void *)7, 8, 9, 10) != 34 ||
                 bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 ||
                 bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 ||
-                bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 ||
+                bpf_fentry_test7(&arg) != 0 ||
                 bpf_fentry_test8(&arg) != 0 ||
                 bpf_fentry_test9(&retval) != 0)
                     goto out;
tools/testing/selftests/bpf/progs/fentry_test.c +1 -1
index 52a550d281d9..95c5c34ccaa8 100644
@@ -64,7 +64,7 @@ __u64 test7_result = 0;
  SEC("fentry/bpf_fentry_test7")
  int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
  {
-    if (!arg)
+    if (arg)
             test7_result = 1;
     return 0;
  }
tools/testing/selftests/bpf/progs/fexit_test.c +1 -1
index 8f1ccb7302e1..ffb30236ca02 100644
@@ -65,7 +65,7 @@ __u64 test7_result = 0;
  SEC("fexit/bpf_fentry_test7")
  int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
  {
-    if (!arg)
+    if (arg)
             test7_result = 1;
     return 0;
  }
author
#5 lore raw
Quoted 41 lines · Andrii Nakryiko
Quoted 32 lines · Yonghong Song
Quoted 29 lines · Jiri Olsa
Quoted 27 lines · Jiri Olsa

hi,
The bpf CI is broken due to clang emitting 2 functions for bpf_fentry_test7:

   # cat available_filter_functions | grep bpf_fentry_test7
   bpf_fentry_test7
   bpf_fentry_test7.specialized.1

The tests attach to 'bpf_fentry_test7' while the function with '.specialized.1' suffix is executed in bpf_prog_test_run_tracing.

It looks like clang optimalization that comes from passing 0 as argument and returning it directly in bpf_fentry_test7.

I'm not sure there's a way to disable this, so far I came up with solution below that passes real pointer, but I think that was not the original intention for the test.

We had issue with this function back in august:

   32337c0a2824 bpf: Prevent inlining of bpf_fentry_test7()

I'm not sure why it started to show now? was clang updated for CI?

I'll try to find out more, but any clang ideas are welcome ;-)

thanks,
jirka

Quoted 7 lines
Quoted 3 lines

hm, there seems to be fix in bpf-next for this one:

b16904fd9f01 bpf: Fix a few selftest failures due to llvm18 change

Maybe submit a patch to https://github.com/kernel-patches/vmtest/tree/master/ci/diffs?
That is typically the place to have temporary patches to workaround ci failures.

Quoted 5 lines

To get bpf/master back to green CI I did it meanwhile ([0]). Jiri, please check the PR to be familiar with the process for the future similar mitigations, thanks.

[0] https://github.com/kernel-patches/vmtest/pull/258

great, thanks

jirka

Quoted 54 lines
Quoted 54 lines
Quoted 54 lines

jirka

Quoted 50 lines

---

net/bpf/test_run.c +2 -2
index c9fdcc5cdce1..33208eec9361 100644
@@ -543,7 +543,7 @@ struct bpf_fentry_test_t {
  int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
  {
     asm volatile ("");
-    return (long)arg;
+    return 0;
  }
 
  int noinline bpf_fentry_test8(struct bpf_fentry_test_t *arg)
@@ -668,7 +668,7 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
                 bpf_fentry_test4((void *)7, 8, 9, 10) != 34 ||
                 bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 ||
                 bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 ||
-                bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 ||
+                bpf_fentry_test7(&arg) != 0 ||
                 bpf_fentry_test8(&arg) != 0 ||
                 bpf_fentry_test9(&retval) != 0)
                     goto out;
tools/testing/selftests/bpf/progs/fentry_test.c +1 -1
index 52a550d281d9..95c5c34ccaa8 100644
@@ -64,7 +64,7 @@ __u64 test7_result = 0;
  SEC("fentry/bpf_fentry_test7")
  int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
  {
-    if (!arg)
+    if (arg)
             test7_result = 1;
     return 0;
  }
tools/testing/selftests/bpf/progs/fexit_test.c +1 -1
index 8f1ccb7302e1..ffb30236ca02 100644
@@ -65,7 +65,7 @@ __u64 test7_result = 0;
  SEC("fexit/bpf_fentry_test7")
  int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
  {
-    if (!arg)
+    if (arg)
             test7_result = 1;
     return 0;
  }