selftests/bpf: Fix task_local_data failure with 64K page
Subsystems (4)
Yonghong Song
reviewerPATCH v4 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[]; };
field 'cnt' 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. To accommodate 64K page, '_Atomic __u8 cnt' becomes '_Atomic __u16 cnt'. A few other places are adjusted accordingly.
In test_task_local_data.c, the value for TLD_DYN_DATA_SIZE is changed from 4096 to (getpagesize() - 8) since the maximum buffer size for TLD_DYN_DATA_SIZE is (getpagesize() - 8).
--- tools/testing/selftests/bpf/prog_tests/task_local_data.h | 4 ++-- tools/testing/selftests/bpf/prog_tests/test_task_local_data.c | 2 +- tools/testing/selftests/bpf/progs/task_local_data.bpf.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
Changelog:
v1 -> v4:
- v1: https://lore.kernel.org/bpf/[email protected]/
- Restore '__u16 size' with adjusted TLD_DYN_DATA_SIZE (smaller than getpagesize())
tools/testing/selftests/bpf/prog_tests/task_local_data.h +2 -2
@@ -94,7 +94,7 @@ struct tld_metadata { };struct tld_meta_u { - _Atomic__u8 cnt; + _Atomic__u16 cnt;__u16 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() - 8)#include "task_local_data.h" struct test_tld_struct {
tools/testing/selftests/bpf/progs/task_local_data.bpf.h +1 -1
@@ -80,7 +80,7 @@ struct tld_metadata { };struct tld_meta_u { -__u8 cnt; +__u16 cnt;__u16 size;struct tld_metadata metadata[TLD_MAX_DATA_CNT ]; };
Signature · 1 line
2.47.3
Yonghong Song
reviewerPATCH v4 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
Re: [PATCH bpf-next v4 2/2] selftests/bpf: Fix xdp_pull_data failure with 64K page
Quoted 7 lines · Yonghong Song
If the argument '
pull_len' ofrun_test()is 'PULL_MAX' or 'PULL_MAX|PULL_PLUS_ONE', the eventualpull_lensize will close to the page size. On arm64 systems with 64K pages, thepull_lensize will be close to 64K. But the existing buffer will be close to 9000 which is not enough to pull.
Quoted 8 lines
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.Tested-by Alan Maguire <[email protected]>Cc Amery Hung <[email protected]>Signed-off-by Yonghong Song <[email protected]>
Quoted 75 lines
--- .../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]/
- Reducebuff_lensize and cover the remaining two run_test()'s withPULL_MAX.
v1 -> v2:
- v1: https://lore.kernel.org/bpf/[email protected]/
- Usepg_szto simplifybuff_lencalculation.tools/testing/selftests/bpf/prog_tests/xdp_pull_data.c +9
-8@@ -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: --2.47.3
Quoted 28 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[];};
field 'cnt' 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. To accommodate 64K page, '_Atomic__u8cnt' becomes '_Atomic__u16cnt'. A few other places are adjusted accordingly.
Quoted 8 lines
In
test_task_local_data.c, the value forTLD_DYN_DATA_SIZEis changed from 4096 to (getpagesize()- 8) since the maximum buffer size forTLD_DYN_DATA_SIZEis (getpagesize()- 8).Reviewed-by Alan Maguire <[email protected]>Tested-by Alan Maguire <[email protected]>Cc Amery Hung <[email protected]>Signed-off-by Yonghong Song <[email protected]>
Quoted 63 lines
--- tools/testing/selftests/bpf/prog_tests/task_local_data.h | 4 ++-- tools/testing/selftests/bpf/prog_tests/test_task_local_data.c | 2 +- tools/testing/selftests/bpf/progs/task_local_data.bpf.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)Changelog:
v1 -> v4:
- v1: https://lore.kernel.org/bpf/[email protected]/
- Restore '__u16size' with adjustedTLD_DYN_DATA_SIZE(smaller thangetpagesize())tools/testing/selftests/bpf/prog_tests/task_local_data.h +2
-2@@ -94,7 +94,7 @@ struct tld_metadata { };struct tld_meta_u { - _Atomic__u8 cnt; + _Atomic__u16 cnt;__u16 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() - 8)#include "task_local_data.h" struct test_tld_struct {tools/testing/selftests/bpf/progs/task_local_data.bpf.h +1
-2@@ -80,7 +80,7 @@ struct tld_metadata { };struct tld_meta_u { -__u8 cnt; +__u16 cnt;__u16 size;struct tld_metadata metadata[TLD_MAX_DATA_CNT ]; }; --2.47.3
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 15 lines · On Thu, 22 Jan 2026 21:51:22 -0800 you wrote:
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:FAIL
Quoted 1 line
[...]
Here is the summary with links:
- [bpf-next,v4,1/2] selftests/bpf: Fix task_local_data failure with 64K page
https://git.kernel.org/bpf/bpf-next/c/d8df87814050 - [bpf-next,v4,2/2] selftests/bpf: Fix xdp_pull_data failure with 64K page https://git.kernel.org/bpf/bpf-next/c/c7900f225a10
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html