selftests/bpf: Add arena invalid node id test
Subsystems (3)
PATCH 1/1 selftests/bpf: Add arena invalid node id test
Commit 2845989f2eba ("bpf: Validate node_id in arena_alloc_pages()") added validation for invalid or offline NUMA node ids in arena_alloc_pages(), but there is no selftest covering invalid node id allocation failure.
Add a verifier_arena test that calls bpf_arena_alloc_pages() with an invalid node id and checks that allocation fails.
Tested with:
./test_progs -t verifier_arena/alloc_pages_invalid_node
--- .../testing/selftests/bpf/progs/verifier_arena.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
tools/testing/selftests/bpf/progs/verifier_arena.c +15 -0
@@ -11,6 +11,7 @@#include "bpf_arena_common.h" #define private (name) SEC(".bss." #name) __hidden __attribute__((aligned(8))) +#define INVALID_NODE_ID 0x7fffffffstruct { __uint(type, BPF_MAP_TYPE_ARENA);
@@ -199,6 +200,20 @@ int basic_alloc3(void *ctx)return 0 ; } +SEC("syscall") +__success __retval(0) +int alloc_pages_invalid_node(void *ctx) +{ +#if defined(__BPF_FEATURE_ADDR_SPACE_CAST) + void __arena *page; + + page =bpf_arena_alloc_pages (&arena,NULL ,1 ,INVALID_NODE_ID ,0 ); +if (page) +return 1 ; +#endif +return 0 ; +} + SEC("socket") __success __retval(0) int basic_reserve1_nosleep(void *ctx)
Signature · 1 line
2.54.0
Quoted 35 lines · Woojin Ji
Commit
2845989f2eba("bpf: Validatenode_idinarena_alloc_pages()") added validation for invalid or offline NUMA node ids inarena_alloc_pages(), but there is no selftest covering invalid node id allocation failure.Add a
verifier_arenatest that callsbpf_arena_alloc_pages()with an invalid node id and checks that allocation fails.Tested with:
./test_progs -t verifier_arena/alloc_pages_invalid_nodeSigned-off-by Woojin Ji <[email protected]>--- .../testing/selftests/bpf/progs/verifier_arena.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)tools/testing/selftests/bpf/progs/verifier_arena.c +3
-0@@ -11,6 +11,7 @@#include "bpf_arena_common.h" #define private (name) SEC(".bss." #name) __hidden __attribute__((aligned(8))) +#define INVALID_NODE_ID 0x7fffffffstruct { __uint(type, BPF_MAP_TYPE_ARENA);@@ -199,6 +200,20 @@ int basic_alloc3(void *ctx)return 0 ; } +SEC("syscall") +__success __retval(0)
tools/testing/selftests/bpf/progs/verifier_arena.c int basic_alloc3(void *ctx) · line 214
Quoted 10 lines
tools/testing/selftests/bpf/progs/verifier_arena.c +10
-0+int alloc_pages_invalid_node (void *ctx) +{ +#if defined(__BPF_FEATURE_ADDR_SPACE_CAST) + void __arena *page; + + page =bpf_arena_alloc_pages (&arena,NULL ,1 ,INVALID_NODE_ID ,0 ); +if (page) +return 1 ; +#endif +return 0 ;
I don't think we need a selftest for every little fix. This will take more CI time for things that are unlikely to break.
pw-bot: cr
Agreed, the extra coverage here is probably not worth the additional CI cost for such a small fix.
I'll drop this patch.
Thanks for the review.