Skip to contentSkip to conversation

selftests/bpf: skip lsm_cgroup when don't have trampolines

PATCH Applied Stanislav Fomichev 4 participants 7 messages Jun 30, 2022 – Jul 1, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/bpf: skip lsm_cgroup when don't have trampolines

With arch_prepare_bpf_trampoline removed on x86:

#98/1 lsm_cgroup/functional:SKIP
#98 lsm_cgroup:SKIP
Summary: 1/0 PASSED, 1 SKIPPED, 0 FAILED

Fixes dca85aac8895 ("selftests/bpf: lsm_cgroup functional test")
---
 tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c +8 -0
index d40810a742fa..c542d7e80a5b 100644
@@ -9,6 +9,10 @@
 #include "cgroup_helpers.h"
 #include "network_helpers.h"
 
+#ifndef ENOTSUPP
+#define ENOTSUPP 524
+#endif
+
 static struct btf *btf;
 
 static __u32 query_prog_cnt(int cgroup_fd, const char *attach_func)
@@ -100,6 +104,10 @@ static void test_lsm_cgroup_functional(void)
 	ASSERT_EQ(query_prog_cnt(cgroup_fd, "bpf_lsm_sk_alloc_security"), 0, "prog count");
 	ASSERT_EQ(query_prog_cnt(cgroup_fd, NULL), 0, "total prog count");
 	err = bpf_prog_attach(alloc_prog_fd, cgroup_fd, BPF_LSM_CGROUP, 0);
+	if (err == -ENOTSUPP) {
+		test__skip();
+		goto close_cgroup;
+	}
 	if (!ASSERT_OK(err, "attach alloc_prog_fd"))
 		goto detach_cgroup;
 	ASSERT_EQ(query_prog_cnt(cgroup_fd, "bpf_lsm_sk_alloc_security"), 1, "prog count");
Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
Acked-by on v1 1/1
#1 lore raw

Hi Stan,

Quoted 29 lines · Stanislav Fomichev

With arch_prepare_bpf_trampoline removed on x86:

#98/1 lsm_cgroup/functional:SKIP
#98 lsm_cgroup:SKIP
Summary: 1/0 PASSED, 1 SKIPPED, 0 FAILED

Fixes dca85aac8895 ("selftests/bpf: lsm_cgroup functional test")
---
 tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c +4 -0
index d40810a742fa..c542d7e80a5b 100644
@@ -9,6 +9,10 @@
 #include "cgroup_helpers.h"
 #include "network_helpers.h"
 
+#ifndef ENOTSUPP
+#define ENOTSUPP 524
+#endif
+
 static struct btf *btf;
 
 static __u32 query_prog_cnt(int cgroup_fd, const char *attach_func)

tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c static void test_lsm_cgroup_functional(void) · line 110

Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c +4 -0
@@ -100,6 +104,10 @@ static void test_lsm_cgroup_functional(void)
        ASSERT_EQ(query_prog_cnt(cgroup_fd, "bpf_lsm_sk_alloc_security"), 0, "prog count");
        ASSERT_EQ(query_prog_cnt(cgroup_fd, NULL), 0, "total prog count");
        err = bpf_prog_attach(alloc_prog_fd, cgroup_fd, BPF_LSM_CGROUP, 0);
+       if (err == -ENOTSUPP) {
+               test__skip();
+               goto close_cgroup;
+       }

It seems ENOTSUPP is only used in the kernel. I wonder whether we should let libbpf map ENOTSUPP to ENOTSUP, which is the errno used in userspace and has been used in libbpf.

Maybe the right thing is having bpf syscall return EOPNOTSUPP.

But, anyway, this fix looks good to me.

Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c +0 -1
        if (!ASSERT_OK(err, "attach alloc_prog_fd"))
                goto detach_cgroup;
        ASSERT_EQ(query_prog_cnt(cgroup_fd, "bpf_lsm_sk_alloc_security"), 1, "prog count");
--

2.37.0.rc0.161.g10f37bed90-goog

#2 lore raw
Quoted 31 lines · Hao Luo

Hi Stan,

Quoted 27 lines · Stanislav Fomichev

With arch_prepare_bpf_trampoline removed on x86:

#98/1 lsm_cgroup/functional:SKIP
#98 lsm_cgroup:SKIP
Summary: 1/0 PASSED, 1 SKIPPED, 0 FAILED

Fixes dca85aac8895 ("selftests/bpf: lsm_cgroup functional test")
---
 tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c +4 -0
index d40810a742fa..c542d7e80a5b 100644
@@ -9,6 +9,10 @@
 #include "cgroup_helpers.h"
 #include "network_helpers.h"
 
+#ifndef ENOTSUPP
+#define ENOTSUPP 524
+#endif
+
 static struct btf *btf;
 
Quoted 13 lines

tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c static void test_lsm_cgroup_functional(void) · line 110

Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c +4 -0
 static __u32 query_prog_cnt(int cgroup_fd, const char *attach_func)
@@ -100,6 +104,10 @@ static void test_lsm_cgroup_functional(void)
        ASSERT_EQ(query_prog_cnt(cgroup_fd, "bpf_lsm_sk_alloc_security"), 0, "prog count");
        ASSERT_EQ(query_prog_cnt(cgroup_fd, NULL), 0, "total prog count");
        err = bpf_prog_attach(alloc_prog_fd, cgroup_fd, BPF_LSM_CGROUP, 0);
+       if (err == -ENOTSUPP) {
+               test__skip();
+               goto close_cgroup;
+       }

It seems ENOTSUPP is only used in the kernel. I wonder whether we should let libbpf map ENOTSUPP to ENOTSUP, which is the errno used in userspace and has been used in libbpf.

Yeah, this comes up occasionally, I don't think we've agreed on some kind of general policy about what to do with these :-( Thanks for the review!

Quoted 14 lines

Maybe the right thing is having bpf syscall return EOPNOTSUPP.

But, anyway, this fix looks good to me.

Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c +0 -1
        if (!ASSERT_OK(err, "attach alloc_prog_fd"))
                goto detach_cgroup;
        ASSERT_EQ(query_prog_cnt(cgroup_fd, "bpf_lsm_sk_alloc_security"), 1, "prog count");
--

2.37.0.rc0.161.g10f37bed90-goog

maintainer
#3 lore raw
Quoted 2 lines · Stanislav Fomichev
Quoted 1 line · Hao Luo

On Thu, Jun 30, 2022 at 3:42 PM Stanislav Fomichev <[email protected]> wrote:

[...]

Quoted 40 lines
Quoted 26 lines
Quoted 26 lines

With arch_prepare_bpf_trampoline removed on x86:

#98/1 lsm_cgroup/functional:SKIP
#98 lsm_cgroup:SKIP
Summary: 1/0 PASSED, 1 SKIPPED, 0 FAILED

Fixes dca85aac8895 ("selftests/bpf: lsm_cgroup functional test")
---
  tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c | 8 ++++++++
  1 file changed, 8 insertions(+)
tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c +4 -0
index d40810a742fa..c542d7e80a5b 100644
@@ -9,6 +9,10 @@
  #include "cgroup_helpers.h"
  #include "network_helpers.h"
 
+#ifndef ENOTSUPP
+#define ENOTSUPP 524
+#endif
+
  static struct btf *btf;
 
Quoted 13 lines

tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c static void test_lsm_cgroup_functional(void) · line 110

Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c +4 -0
  static __u32 query_prog_cnt(int cgroup_fd, const char *attach_func)
@@ -100,6 +104,10 @@ static void test_lsm_cgroup_functional(void)
         ASSERT_EQ(query_prog_cnt(cgroup_fd, "bpf_lsm_sk_alloc_security"), 0, "prog count");
         ASSERT_EQ(query_prog_cnt(cgroup_fd, NULL), 0, "total prog count");
         err = bpf_prog_attach(alloc_prog_fd, cgroup_fd, BPF_LSM_CGROUP, 0);
+       if (err == -ENOTSUPP) {
+               test__skip();
+               goto close_cgroup;
+       }

It seems ENOTSUPP is only used in the kernel. I wonder whether we should let libbpf map ENOTSUPP to ENOTSUP, which is the errno used in userspace and has been used in libbpf.

Quoted 3 lines

Yeah, this comes up occasionally, I don't think we've agreed on some kind of general policy about what to do with these :-( Thanks for the review!

Consensus was that for existing code, the ship has sailed to change it given applications could one way or another depend on this error code, but it should be avoided for new APIs (e.g. [0]).

Thanks,
Daniel

[0] https://lore.kernel.org/bpf/20211209182349.038ac2b8@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com/

#4 lore raw
Quoted 45 lines · Daniel Borkmann
Quoted 2 lines · Stanislav Fomichev
Quoted 1 line · Hao Luo

On Thu, Jun 30, 2022 at 3:42 PM Stanislav Fomichev <[email protected]> wrote:

[...]

Quoted 40 lines
Quoted 39 lines
Quoted 28 lines

With arch_prepare_bpf_trampoline removed on x86:

#98/1 lsm_cgroup/functional:SKIP
#98 lsm_cgroup:SKIP
Summary: 1/0 PASSED, 1 SKIPPED, 0 FAILED

Fixes dca85aac8895 ("selftests/bpf: lsm_cgroup functional test")
---
  tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c | 8 ++++++++
  1 file changed, 8 insertions(+)
tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c +4 -0
index d40810a742fa..c542d7e80a5b 100644
@@ -9,6 +9,10 @@
  #include "cgroup_helpers.h"
  #include "network_helpers.h"
 
+#ifndef ENOTSUPP
+#define ENOTSUPP 524
+#endif
+
  static struct btf *btf;
 
  static __u32 query_prog_cnt(int cgroup_fd, const char *attach_func)

tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c static void test_lsm_cgroup_functional(void) · line 110

Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c +4 -0
@@ -100,6 +104,10 @@ static void test_lsm_cgroup_functional(void)
         ASSERT_EQ(query_prog_cnt(cgroup_fd, "bpf_lsm_sk_alloc_security"), 0, "prog count");
         ASSERT_EQ(query_prog_cnt(cgroup_fd, NULL), 0, "total prog count");
         err = bpf_prog_attach(alloc_prog_fd, cgroup_fd, BPF_LSM_CGROUP, 0);
+       if (err == -ENOTSUPP) {
+               test__skip();
+               goto close_cgroup;
+       }

It seems ENOTSUPP is only used in the kernel. I wonder whether we should let libbpf map ENOTSUPP to ENOTSUP, which is the errno used in userspace and has been used in libbpf.

Quoted 7 lines
Quoted 3 lines

Yeah, this comes up occasionally, I don't think we've agreed on some kind of general policy about what to do with these :-( Thanks for the review!

Consensus was that for existing code, the ship has sailed to change it given applications could one way or another depend on this error code, but it should be avoided for new APIs (e.g. [0]).

Ah, great, thanks Daniel!

Quoted 4 lines

Thanks,
Daniel

   [0] https://lore.kernel.org/bpf/20211209182349.038ac2b8@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com/
#5 lore raw
In reply to Daniel Borkmann
Quoted 4 lines · Daniel Borkmann
Quoted 2 lines · Stanislav Fomichev
Quoted 1 line · Hao Luo

On Thu, Jun 30, 2022 at 3:42 PM Stanislav Fomichev <[email protected]> wrote:

[...]

Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

It seems ENOTSUPP is only used in the kernel. I wonder whether we should let libbpf map ENOTSUPP to ENOTSUP, which is the errno used in userspace and has been used in libbpf.

Yeah, this comes up occasionally, I don't think we've agreed on some kind of general policy about what to do with these :-( Thanks for the review!

Quoted 8 lines

Consensus was that for existing code, the ship has sailed to change it given applications could one way or another depend on this error code, but it should be avoided for new APIs (e.g. [0]).

Thanks,
Daniel

   [0] https://lore.kernel.org/bpf/20211209182349.038ac2b8@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com/

Thanks for the reference!

#6 lore raw
In reply to Stanislav Fomichev
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 10 lines · On Thu, 30 Jun 2022 15:42:03 -0700 you wrote:

With arch_prepare_bpf_trampoline removed on x86:

#98/1 lsm_cgroup/functional:SKIP
#98 lsm_cgroup:SKIP
Summary: 1/0 PASSED, 1 SKIPPED, 0 FAILED

Fixes dca85aac8895 ("selftests/bpf: lsm_cgroup functional test")

[...]

Here is the summary with links:
- [bpf-next] selftests/bpf: skip lsm_cgroup when don't have trampolines

    https://git.kernel.org/bpf/bpf-next/c/b0d93b44641a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html