selftests/bpf: Fix task_local_data failure with 64K page
Subsystems (4)
Yonghong Song
reviewerPATCH v3 1/2 selftests/bpf: Fix task_local_data failure with 64K page
On arm64 systems with 64K pages, the selftest task_local_data has the following
failures:
...
test_task_local_data_basic:PASS:tld_create_key 0 nsec test_task_local_data_basic:FAIL:tld_create_key unexpected tld_create_key: actual 0 != expected -28
...
test_task_local_data_basic_thread:PASS:run task_main 0 nsec test_task_local_data_basic_thread:FAIL:task_main retval unexpected error: 2 (errno 0) test_task_local_data_basic_thread:FAIL:tld_get_data value0 unexpected tld_get_data value0: actual 0 != expected 6268
...
#447/1 task_local_data/task_local_data_basic:FAIL
...
#447/2 task_local_data/task_local_data_race:FAIL
#447 task_local_data:FAIL
When TLD_DYN_DATA_SIZE is 64K page size, for
struct tld_meta_u {
_Atomic __u8 cnt;
__u16 size;
struct tld_metadata metadata[]; };
fields 'cnt' and 'size' would overflow. For example, for 4K page, 'cnt' will be 4096/64 = 64. But for 64K page, 'cnt' will be 65536/64 = 1024 and 'cnt' is not enough for 1024. For field 'size', it is okay for value 4K, but it is not enough for 64K as maximum 'size' value is '64K - 1'.
To accommodate 64K page, '_Atomic __u8 cnt' becomes '_Atomic __u16 cnt' and '__u16 size' becomes '__u32 size'. A few other places are adjusted accordingly.
--- tools/testing/selftests/bpf/prog_tests/task_local_data.h | 6 +++--- .../testing/selftests/bpf/prog_tests/test_task_local_data.c | 2 +- tools/testing/selftests/bpf/progs/task_local_data.bpf.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
tools/testing/selftests/bpf/prog_tests/task_local_data.h +3 -3
@@ -94,8 +94,8 @@ struct tld_metadata { };struct tld_meta_u { - _Atomic__u8 cnt; -__u16 size; + _Atomic__u16 cnt; +__u32 size;struct tld_metadata metadata[]; };
@@ -217,7 +217,7 @@ static int __tld_init_data_p(int map_fd)static tld_key_t __tld_create_key (const char *name,size_t size,bool dyn_data) {int err, i, sz, off =0 ; -__u8 cnt; +__u16 cnt;if (!TLD_READ_ONCE (tld_meta_p)) { err =__tld_init_meta_p ();
tools/testing/selftests/bpf/prog_tests/test_task_local_data.c +1 -1
@@ -4,7 +4,7 @@#include <test_progs.h> #define TLD_FREE_DATA_ON_THREAD_EXIT -#define TLD_DYN_DATA_SIZE 4096 +#define TLD_DYN_DATA_SIZE getpagesize()#include "task_local_data.h" struct test_tld_struct {
tools/testing/selftests/bpf/progs/task_local_data.bpf.h +2 -2
@@ -80,8 +80,8 @@ struct tld_metadata { };struct tld_meta_u { -__u8 cnt; -__u16 size; +__u16 cnt; +__u32 size;struct tld_metadata metadata[TLD_MAX_DATA_CNT ]; };
Signature · 1 line
2.47.3
Yonghong Song
reviewerPATCH v3 2/2 selftests/bpf: Fix xdp_pull_data failure with 64K page
If the argument 'pull_len' of run_test() is 'PULL_MAX' or 'PULL_MAX | PULL_PLUS_ONE', the eventual pull_len size will close to the page size. On arm64 systems with 64K pages, the pull_len size will be close to 64K. But the existing buffer will be close to 9000 which is not enough to pull.
For those failed run_tests(), make buff size to
pg_sz + (pg_sz / 2)
This way, there will be enough buffer space to pull regardless of page size.
--- .../selftests/bpf/prog_tests/xdp_pull_data.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
Changelog:
v2 -> v3:
- v2: https://lore.kernel.org/bpf/[email protected]/
- Reduce buff_len size and cover the remaining two run_test()'s with PULL_MAX.
v1 -> v2:
- v1: https://lore.kernel.org/bpf/[email protected]/
- Use pg_sz to simplify buff_len calculation.
tools/testing/selftests/bpf/prog_tests/xdp_pull_data.c +9 -7
@@ -114,12 +114,14 @@ static void test_xdp_pull_data_basic(void) {u32 pg_sz, max_meta_len, max_data_len;struct test_xdp_pull_data *skel; +int buff_len; skel =test_xdp_pull_data__open_and_load ();if (!ASSERT_OK_PTR (skel,"test_xdp_pull_data__open_and_load" ))return ; pg_sz =sysconf (_SC_PAGE_SIZE); + buff_len = pg_sz + pg_sz /2 ;if (find_xdp_sizes (skel, pg_sz)) goto out;
@@ -140,13 +142,13 @@ static void test_xdp_pull_data_basic(void)run_test (skel,XDP_PASS , pg_sz,9000 ,0 ,1025 ,1025 );/* multi-buf pkt, empty linear data area, pull requires memmove */ -run_test (skel,XDP_PASS , pg_sz,9000 ,0 ,0 ,PULL_MAX ); +run_test (skel,XDP_PASS , pg_sz, buff_len,0 ,0 ,PULL_MAX );/* multi-buf pkt, no headroom */ -run_test (skel,XDP_PASS , pg_sz,9000 , max_meta_len,1024 ,PULL_MAX ); +run_test (skel,XDP_PASS , pg_sz, buff_len, max_meta_len,1024 ,PULL_MAX );/* multi-buf pkt, no tailroom, pull requires memmove */ -run_test (skel,XDP_PASS , pg_sz,9000 ,0 , max_data_len,PULL_MAX ); +run_test (skel,XDP_PASS , pg_sz, buff_len,0 , max_data_len,PULL_MAX );/* Test cases with invalid pull length */
@@ -154,18 +156,18 @@ static void test_xdp_pull_data_basic(void)run_test (skel,XDP_DROP , pg_sz,2048 ,0 ,2048 ,2049 );/* multi-buf pkt with no space left in linear data area */ -run_test (skel,XDP_DROP , pg_sz,9000 , max_meta_len, max_data_len, +run_test (skel,XDP_DROP , pg_sz, buff_len, max_meta_len, max_data_len,PULL_MAX |PULL_PLUS_ONE );/* multi-buf pkt, empty linear data area */ -run_test (skel,XDP_DROP , pg_sz,9000 ,0 ,0 ,PULL_MAX |PULL_PLUS_ONE ); +run_test (skel,XDP_DROP , pg_sz, buff_len,0 ,0 ,PULL_MAX |PULL_PLUS_ONE );/* multi-buf pkt, no headroom */ -run_test (skel,XDP_DROP , pg_sz,9000 , max_meta_len,1024 , +run_test (skel,XDP_DROP , pg_sz, buff_len, max_meta_len,1024 ,PULL_MAX |PULL_PLUS_ONE );/* multi-buf pkt, no tailroom */ -run_test (skel,XDP_DROP , pg_sz,9000 ,0 , max_data_len, +run_test (skel,XDP_DROP , pg_sz, buff_len,0 , max_data_len,PULL_MAX |PULL_PLUS_ONE ); out:
Signature · 1 line
2.47.3
Quoted 47 lines · Yonghong Song
On arm64 systems with 64K pages, the selftest
task_local_datahas the following
failures:
...
test_task_local_data_basic:PASS:tld_create_key 0 nsec test_task_local_data_basic:FAIL:tld_create_key unexpectedtld_create_key: actual 0 != expected -28
...
test_task_local_data_basic_thread:PASS:runtask_main0 nsec test_task_local_data_basic_thread:FAIL:task_main retval unexpected error: 2 (errno 0) test_task_local_data_basic_thread:FAIL:tld_get_data value0 unexpectedtld_get_datavalue0: actual 0 != expected 6268
...
#447/1 task_local_data/task_local_data_basic:FAIL
...
#447/2 task_local_data/task_local_data_race:FAIL
#447 task_local_data:FAILWhen
TLD_DYN_DATA_SIZEis 64K page size, forstruct tld_meta_u { _Atomic __u8 cnt; __u16 size; struct tld_metadata metadata[];};
fields 'cnt' and 'size' would overflow. For example, for 4K page, 'cnt' will be 4096/64 = 64. But for 64K page, 'cnt' will be 65536/64 = 1024 and 'cnt' is not enough for 1024. For field 'size', it is okay for value 4K, but it is not enough for 64K as maximum 'size' value is '64K - 1'.To accommodate 64K page, '
_Atomic__u8cnt' becomes '_Atomic__u16cnt' and '__u16size' becomes '__u32size'. A few other places are adjusted accordingly.Reviewed-by Alan Maguire <[email protected]>Tested-by Alan Maguire <[email protected]>Cc Amery Hung <[email protected]>Signed-off-by Yonghong Song <[email protected]>--- tools/testing/selftests/bpf/prog_tests/task_local_data.h | 6 +++--- .../testing/selftests/bpf/prog_tests/test_task_local_data.c | 2 +- tools/testing/selftests/bpf/progs/task_local_data.bpf.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)tools/testing/selftests/bpf/prog_tests/task_local_data.h +0
-0
tools/testing/selftests/bpf/prog_tests/task_local_data.h struct tld_metadata { · line 98
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/task_local_data.h +2
-2@@ -94,8 +94,8 @@ struct tld_metadata { };struct tld_meta_u { - _Atomic__u8 cnt; -__u16 size; + _Atomic__u16 cnt; +__u32 size;
pending discussion in the other thread...
this can be _u16.