Skip to contentSkip to conversation

workaround a verifier failure for test_progs

PATCH Ma Xinjian 3 participants 3 messages Apr 28, 2020

Subsystems (3)
lore
Share & tools
lore

Ma Xinjian

author
#0 lore raw

Hi Yonghong.

During our team's test, we find a similar issue. when run test_sysctl of bpf, we met error:

```

libbpf: -- END LOG --
libbpf: failed to load program 'cgroup/sysctl'
libbpf: failed to load object './test_sysctl_prog.o'
(test_sysctl.c:1490: errno: Permission denied) >>> Loading program (./test_sysctl_prog.o) error.

```

Testing env: "Debian GNU/Linux 9 (stretch)"

kernel: 5.6 5.7-rc1 5.7-rc2 5.7-rc3

clang/llvm version: v11.0.0.

we have tested a log of commits, following commits are part of them

drwxrwxr-x 2 root root  1 Apr 28 07:01 f30416fdde922eaa655934e050026930fefbd260 drwxrwxr-x 2 root root  2 Apr 26 11:38 10bc12588dac532fad044b2851dde8e7b9121e88 drwxrwxr-x 2 root root  1 Apr 26 07:01 969e7edd88ceb4791eb1cac22828290f0ae30b3d drwxrwxr-x 2 root root  1 Apr 23 13:51 bbf386f02b05db017fda66875cc5edef70779244 drwxrwxr-x 2 root root  1 Apr 22 10:01 2de52422acf04662b45599f77c14ce1b2cec2b81 drwxrwxr-x 2 root root  1 Apr 21 07:07 a9b137f9ffba8cb25dfd7dd1fb613e8aac121b37 drwxrwxr-x 2 root root  1 Apr 17 07:01 40d139c620f83509fe18acbff5ec358298e99def

drwxrwxr-x 2 root root  1 Apr 16 07:02 bee6c234ed28ae7349cb83afa322dfd8394590ee

And I have tested, If I add following patch like you did, test_sysctl pass:

tools/testing/selftests/bpf/progs/test_sysctl_prog.c +0 -0
index 2d0b0b82a78a..8e3da8d2e7c9 100644
@@ -45,7 +45,10 @@ int sysctl_tcp_mem(struct bpf_sysctl *ctx)

        unsigned long tcp_mem[3] = {0, 0, 0}; char value[MAX_VALUE_STR_LEN];
        unsigned char i, off = 0;
-       int ret;
+      /* a workaround to prevent compiler from generating +      * codes verifier cannot handle yet.
+      */
+      volatile int ret;

        if (ctx->write)
                return 0;

root@vm-snb-15 /usr/src/perf_selftests-x86_64-rhel-7.6-kselftests-6a8b55ed4056ea5559ebe4f6a4b247f627870d4c/tools/testing/selftests/bpf# ./test_sysctl

...

 Summary: 40 PASSED, 0 FAILED

Signature · 2 lines
Best Regards.
Ma Xinjian
#1 lore raw
Quoted 40 lines · Ma Xinjian

Hi Yonghong.

During our team's test, we find a similar issue. when run test_sysctl of bpf, we met error:

```

libbpf: -- END LOG --
libbpf: failed to load program 'cgroup/sysctl'
libbpf: failed to load object './test_sysctl_prog.o'
(test_sysctl.c:1490: errno: Permission denied) >>> Loading program (./test_sysctl_prog.o) error.

```

Testing env: "Debian GNU/Linux 9 (stretch)"

kernel: 5.6 5.7-rc1 5.7-rc2 5.7-rc3

clang/llvm version: v11.0.0.

we have tested a log of commits, following commits are part of them

drwxrwxr-x 2 root root  1 Apr 28 07:01 f30416fdde922eaa655934e050026930fefbd260 drwxrwxr-x 2 root root  2 Apr 26 11:38 10bc12588dac532fad044b2851dde8e7b9121e88 drwxrwxr-x 2 root root  1 Apr 26 07:01 969e7edd88ceb4791eb1cac22828290f0ae30b3d drwxrwxr-x 2 root root  1 Apr 23 13:51 bbf386f02b05db017fda66875cc5edef70779244 drwxrwxr-x 2 root root  1 Apr 22 10:01 2de52422acf04662b45599f77c14ce1b2cec2b81 drwxrwxr-x 2 root root  1 Apr 21 07:07 a9b137f9ffba8cb25dfd7dd1fb613e8aac121b37 drwxrwxr-x 2 root root  1 Apr 17 07:01 40d139c620f83509fe18acbff5ec358298e99def

drwxrwxr-x 2 root root  1 Apr 16 07:02 bee6c234ed28ae7349cb83afa322dfd8394590ee

And I have tested, If I add following patch like you did, test_sysctl pass:

tools/testing/selftests/bpf/progs/test_sysctl_prog.c +0 -0
index 2d0b0b82a78a..8e3da8d2e7c9 100644
@@ -45,7 +45,10 @@ int sysctl_tcp_mem(struct bpf_sysctl *ctx)
         unsigned long tcp_mem[3] = {0, 0, 0};

tools/testing/selftests/bpf/progs/test_sysctl_prog.c int sysctl_tcp_mem(struct bpf_sysctl *ctx) · line 54

Quoted 10 lines
tools/testing/selftests/bpf/progs/test_sysctl_prog.c +4 -1
         char value[MAX_VALUE_STR_LEN];
         unsigned char i, off = 0;
-       int ret;
+      /* a workaround to prevent compiler from generating
+      * codes verifier cannot handle yet.
+      */
+      volatile int ret;
 
         if (ctx->write)
                 return 0;

Right. This is related to alu32 mode. The detailed description
https://lore.kernel.org/bpf/[email protected]/

We are still working on this, either a verifier solution or a compiler workaround.

Quoted 7 lines

root@vm-snb-15 /usr/src/perf_selftests-x86_64-rhel-7.6-kselftests-6a8b55ed4056ea5559ebe4f6a4b247f627870d4c/tools/testing/selftests/bpf# ./test_sysctl

...

 Summary: 40 PASSED, 0 FAILED

#2 lore raw
Quoted 6 lines · Yonghong Song
Quoted 6 lines
(quoted diff) +4 -1
-       int ret;
+      /* a workaround to prevent compiler from generating
+      * codes verifier cannot handle yet.
+      */
+      volatile int ret;
Quoted 8 lines
Quoted 2 lines
         if (ctx->write)
                 return 0;

Right. This is related to alu32 mode. The detailed description
https://lore.kernel.org/bpf/[email protected]/

We are still working on this, either a verifier solution or a compiler workaround.

Thanks for the report.
I pushed the same fix for progs/test_sysctl_prog.c into bpf-next. Now test_sysctl passes.