selftests/bpf: skip lsm_cgroup when don't have trampolines
Subsystems (3)
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
--- 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
@@ -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
Hi Stan,
Quoted 29 lines · Stanislav Fomichev
With
arch_prepare_bpf_trampolineremoved on x86:#98/1 lsm_cgroup/functional:SKIP
#98 lsm_cgroup:SKIP
Summary: 1/0 PASSED, 1 SKIPPED, 0 FAILEDFixes dca85aac8895 ("selftests/bpf: lsm_cgroup functional test")Signed-off-by Stanislav Fomichev <[email protected]>--- 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@@ -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
-1if (!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
Quoted 31 lines · Hao Luo
Hi Stan,
Quoted 27 lines · Stanislav Fomichev
With
arch_prepare_bpf_trampolineremoved on x86:#98/1 lsm_cgroup/functional:SKIP
#98 lsm_cgroup:SKIP
Summary: 1/0 PASSED, 1 SKIPPED, 0 FAILEDFixes dca85aac8895 ("selftests/bpf: lsm_cgroup functional test")Signed-off-by Stanislav Fomichev <[email protected]>--- 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@@ -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
-0static __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.
Acked-by Hao Luo <[email protected]>Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c +0
-1if (!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
Daniel Borkmann
maintainerQuoted 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_trampolineremoved on x86:#98/1 lsm_cgroup/functional:SKIP
#98 lsm_cgroup:SKIP
Summary: 1/0 PASSED, 1 SKIPPED, 0 FAILEDFixes dca85aac8895 ("selftests/bpf: lsm_cgroup functional test")Signed-off-by Stanislav Fomichev <[email protected]>--- 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@@ -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
-0static __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/
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_trampolineremoved on x86:#98/1 lsm_cgroup/functional:SKIP
#98 lsm_cgroup:SKIP
Summary: 1/0 PASSED, 1 SKIPPED, 0 FAILEDFixes dca85aac8895 ("selftests/bpf: lsm_cgroup functional test")Signed-off-by Stanislav Fomichev <[email protected]>--- 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@@ -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/
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!
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_trampolineremoved on x86:#98/1 lsm_cgroup/functional:SKIP
#98 lsm_cgroup:SKIP
Summary: 1/0 PASSED, 1 SKIPPED, 0 FAILEDFixes dca85aac8895 ("selftests/bpf: lsm_cgroup functional test")Signed-off-by Stanislav Fomichev <[email protected]>[...]
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