Skip to contentSkip to conversation

selftests/bpf: Fix task_local_data failure with 64K page

PATCH Superseded Yonghong Song 2 participants 5 messages Jan 20 – Jan 22

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Yonghong Song

author reviewer
#0 lore raw

PATCH 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
index 2de38776a2d4..4c38f9a7bc90 100644
@@ -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
index 9fd6306b455c..cc4d49222d9d 100644
@@ -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
index 432fff2af844..e13f239b46b0 100644
@@ -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
author reviewer
#1 lore raw

PATCH 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
index efa350d04ec5..32ac99406d28 100644
@@ -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
Tested-by on v1 2/2
#2 lore raw

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' 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.

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.

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
index efa350d04ec5..32ac99406d28 100644
@@ -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 -0
 	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;
 

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 -5
 	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:
author reviewer
#3 lore raw

Re: [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' 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.

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.

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
index efa350d04ec5..32ac99406d28 100644
@@ -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 -0
  	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;
 

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 -5
  	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:
Reviewed-by Tested-by on v1 1/2
#4 lore raw
In reply to Yonghong Song
Quoted 27 lines · Yonghong Song

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'.

Quoted 6 lines

To accommodate 64K page, '_Atomic __u8 cnt' becomes '_Atomic __u16 cnt' and '__u16 size' becomes '__u32 size'. A few other places are adjusted accordingly.

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
index 2de38776a2d4..4c38f9a7bc90 100644
@@ -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
index 9fd6306b455c..cc4d49222d9d 100644
@@ -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
index 432fff2af844..e13f239b46b0 100644
@@ -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];
 };