selftests/bpf: Fix task_local_data failure with 64K page
Subsystems (4)
Yonghong Song
reviewerPATCH 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 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.
So for 64K page size and selective run_tests(), increase buff size from 9000 to 90000 to ensure enough buffer space to pull.
--- .../selftests/bpf/prog_tests/xdp_pull_data.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
tools/testing/selftests/bpf/prog_tests/xdp_pull_data.c +11 -5
@@ -8,6 +8,7 @@#define PULL_PLUS_ONE (1 << 30)#define XDP_PACKET_HEADROOM 256 +#define PAGE_SIZE_64K 65536/* Find headroom and tailroom occupied by struct xdp_frame and struct * skb_shared_info so that we can calculate the maximum pull lengths for
@@ -114,12 +115,17 @@ 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); +if (pg_sz ==PAGE_SIZE_64K ) + buff_len =90000 ; +else + buff_len =9000 ;if (find_xdp_sizes (skel, pg_sz)) goto out;
@@ -140,13 +146,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,7 +160,7 @@ 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 */
@@ -165,7 +171,7 @@ static void test_xdp_pull_data_basic(void) 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 2/2] selftests/bpf: Fix xdp_pull_data failure with 64K page
Quoted 6 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 6 lines
So for 64K page size and selective
run_tests(), increase buff size from 9000 to 90000 to ensure enough buffer space to pull.Cc Amery Hung <[email protected]>Signed-off-by Yonghong Song <[email protected]>
one optional suggestion below..
Quoted 22 lines
--- .../selftests/bpf/prog_tests/xdp_pull_data.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)tools/testing/selftests/bpf/prog_tests/xdp_pull_data.c +2
-0@@ -8,6 +8,7 @@#define PULL_PLUS_ONE (1 << 30)#define XDP_PACKET_HEADROOM 256 +#define PAGE_SIZE_64K 65536/* Find headroom and tailroom occupied by struct xdp_frame and struct * skb_shared_info so that we can calculate the maximum pull lengths for @@ -114,12 +115,17 @@ 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;
tools/testing/selftests/bpf/prog_tests/xdp_pull_data.c static void test_xdp_pull_data_basic(void) · line 129
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/xdp_pull_data.c +4
-0skel =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); +if (pg_sz ==PAGE_SIZE_64K ) + buff_len =90000 ; +else + buff_len =9000 ;
nit: should we generalize here and just use 1.5 * pg_sz; i.e.
buff_len = pg_sz + (pg_sz/2);
that would eliminate the need for the 64k page size #define.
Quoted 37 lines
tools/testing/selftests/bpf/prog_tests/xdp_pull_data.c +5
-5if (find_xdp_sizes (skel, pg_sz)) goto out;@@ -140,13 +146,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,7 +160,7 @@ 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 */ @@ -165,7 +171,7 @@ static void test_xdp_pull_data_basic(void) 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:
Yonghong Song
reviewerRe: [PATCH bpf-next 2/2] selftests/bpf: Fix xdp_pull_data failure with 64K page
Quoted 52 lines · Alan Maguire
Quoted 6 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 6 lines
So for 64K page size and selective
run_tests(), increase buff size from 9000 to 90000 to ensure enough buffer space to pull.Cc Amery Hung <[email protected]>Signed-off-by Yonghong Song <[email protected]>Tested-by Alan Maguire <[email protected]>one optional suggestion below..
Quoted 22 lines
--- .../selftests/bpf/prog_tests/xdp_pull_data.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)tools/testing/selftests/bpf/prog_tests/xdp_pull_data.c +2
-0@@ -8,6 +8,7 @@#define PULL_PLUS_ONE (1 << 30)#define XDP_PACKET_HEADROOM 256 +#define PAGE_SIZE_64K 65536/* Find headroom and tailroom occupied by struct xdp_frame and struct * skb_shared_info so that we can calculate the maximum pull lengths for @@ -114,12 +115,17 @@ 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;tools/testing/selftests/bpf/prog_tests/xdp_pull_data.c static void test_xdp_pull_data_basic(void) · line 129
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/xdp_pull_data.c +4
-0skel =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); +if (pg_sz ==PAGE_SIZE_64K ) + buff_len =90000 ; +else + buff_len =9000 ;nit: should we generalize here and just use 1.5 *
pg_sz; i.e.
Quoted 3 lines
buff_len = pg_sz + (pg_sz/2);that would eliminate the need for the 64k page size #define.
Thanks for suggestion! This indeed simpler. Will make the change in v2.
Quoted 38 lines
Quoted 38 lines
tools/testing/selftests/bpf/prog_tests/xdp_pull_data.c +5
-5if (find_xdp_sizes (skel, pg_sz)) goto out;@@ -140,13 +146,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,7 +160,7 @@ 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 */ @@ -165,7 +171,7 @@ static void test_xdp_pull_data_basic(void) 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:
Quoted 27 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'.
Quoted 6 lines
To accommodate 64K page, '
_Atomic__u8cnt' becomes '_Atomic__u16cnt' and '__u16size' becomes '__u32size'. A few other places are adjusted accordingly.Cc Amery Hung <[email protected]>Signed-off-by Yonghong Song <[email protected]>
Quoted 58 lines
--- 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 ]; };