Skip to contentSkip to conversation

selftests/bpf: Fix a few dynptr test failures with 64K page size

PATCH Applied Yonghong Song 4 participants 10 messages Jul 25, 2025 – Jul 26, 2025

Subsystems (5)
lore
Share & tools
lore

Yonghong Song

author reviewer
#0 lore raw

cover selftests/bpf: Fix a few dynptr test failures with 64K page size

There are a few dynptr test failures with arm64 64K page size. They are fixed in this patch set and please see individual patches for details.

Yonghong Song (3):
selftests/bpf: Increase xdp data size for arm64 64K page size selftests/bpf: Fix test dynptr/test_dynptr_copy_xdp failure selftests/bpf: Fix test dynptr/test_dynptr_memset_xdp_chunks failure

 .../testing/selftests/bpf/prog_tests/dynptr.c  | 10 ++++++++--
 .../selftests/bpf/progs/dynptr_success.c       | 18 +++++++++++++++---
 2 files changed, 23 insertions(+), 5 deletions(-)
Signature · 1 line
2.47.3
author reviewer
#1 lore raw

PATCH 1/3 selftests/bpf: Increase xdp data size for arm64 64K page size

With arm64 64K page size, the following 4 subtests failed:

  #97/25   dynptr/test_probe_read_user_dynptr:FAIL
  #97/26   dynptr/test_probe_read_kernel_dynptr:FAIL
  #97/27   dynptr/test_probe_read_user_str_dynptr:FAIL
  #97/28   dynptr/test_probe_read_kernel_str_dynptr:FAIL

These failures are due to function bpf_dynptr_check_off_len() in include/linux/bpf.h where there is a test
if (len > size || offset > size - len)

    return -E2BIG;

With 64K page size, the 'offset' is greater than 'size - len', which caused the test failure.

For 64KB page size, this patch increased the xdp buffer size from 5000 to 90000. The above 4 test failures are fixed as 'size' value is increased. But it introduced two new failures:
#97/4 dynptr/test_dynptr_copy_xdp:FAIL
#97/12 dynptr/test_dynptr_memset_xdp_chunks:FAIL

These two failures will be addressed in subsequent patches.

---
 tools/testing/selftests/bpf/prog_tests/dynptr.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/dynptr.c +8 -2
index f2b65398afce..9b2d9ceda210 100644
@@ -51,6 +51,8 @@ static struct {
 	{"test_copy_from_user_task_str_dynptr", SETUP_SYSCALL_SLEEP},
 };
 
+#define PAGE_SIZE_64K 65536
+
 static void verify_success(const char *prog_name, enum test_setup_type setup_type)
 {
 	char user_data[384] = {[0 ... 382] = 'a', '\0'};
@@ -146,14 +148,18 @@ static void verify_success(const char *prog_name, enum test_setup_type setup_typ
 	}
 	case SETUP_XDP_PROG:
 	{
-		char data[5000];
+		char data[90000];
 		int err, prog_fd;
 		LIBBPF_OPTS(bpf_test_run_opts, opts,
 			    .data_in = &data,
-			    .data_size_in = sizeof(data),
 			    .repeat = 1,
 		);
 
+		if (getpagesize() == PAGE_SIZE_64K)
+			opts.data_size_in = sizeof(data);
+		else
+			opts.data_size_in = 5000;
+
 		prog_fd = bpf_program__fd(prog);
 		err = bpf_prog_test_run_opts(prog_fd, &opts);
 
Signature · 1 line
2.47.3
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH bpf-next 1/3] selftests/bpf: Increase xdp data size for arm64 64K page size

Quoted 50 lines · Yonghong Song

With arm64 64K page size, the following 4 subtests failed:

   #97/25   dynptr/test_probe_read_user_dynptr:FAIL
   #97/26   dynptr/test_probe_read_kernel_dynptr:FAIL
   #97/27   dynptr/test_probe_read_user_str_dynptr:FAIL
   #97/28   dynptr/test_probe_read_kernel_str_dynptr:FAIL

These failures are due to function bpf_dynptr_check_off_len() in include/linux/bpf.h where there is a test
if (len > size || offset > size - len)

     return -E2BIG;

With 64K page size, the 'offset' is greater than 'size - len', which caused the test failure.

For 64KB page size, this patch increased the xdp buffer size from 5000 to 90000. The above 4 test failures are fixed as 'size' value is increased. But it introduced two new failures:
#97/4 dynptr/test_dynptr_copy_xdp:FAIL
#97/12 dynptr/test_dynptr_memset_xdp_chunks:FAIL

These two failures will be addressed in subsequent patches.

---
  tools/testing/selftests/bpf/prog_tests/dynptr.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/dynptr.c +3 -2
index f2b65398afce..9b2d9ceda210 100644
@@ -51,6 +51,8 @@ static struct {
  	{"test_copy_from_user_task_str_dynptr", SETUP_SYSCALL_SLEEP},
  };
 
+#define PAGE_SIZE_64K 65536
+
  static void verify_success(const char *prog_name, enum test_setup_type setup_type)
  {
  	char user_data[384] = {[0 ... 382] = 'a', '\0'};
@@ -146,14 +148,18 @@ static void verify_success(const char *prog_name, enum test_setup_type setup_typ
  	}
  	case SETUP_XDP_PROG:
  	{
-		char data[5000];
+		char data[90000];
  		int err, prog_fd;
  		LIBBPF_OPTS(bpf_test_run_opts, opts,
  			    .data_in = &data,
-			    .data_size_in = sizeof(data),
  			    .repeat = 1,

tools/testing/selftests/bpf/prog_tests/dynptr.c static void verify_success(const char *prog_name, enum test_setup_type setup_typ · line 165

Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/dynptr.c +5 -0
  		);
 
+		if (getpagesize() == PAGE_SIZE_64K)
+			opts.data_size_in = sizeof(data);
+		else
+			opts.data_size_in = 5000;
+
  		prog_fd = bpf_program__fd(prog);
  		err = bpf_prog_test_run_opts(prog_fd, &opts);
 

Thanks for fixing these tests for 64K page size.

author reviewer
#3 lore raw

PATCH 2/3 selftests/bpf: Fix test dynptr/test_dynptr_copy_xdp failure

In reply to Yonghong Song

For arm64 64K page size, the bpf_dynptr_copy() in test dynptr/test_dynptr_copy_xdp will succeed, but the test will failure with 4K page size. This patch made a change so the test will fail expectedly for both 4K and 64K page sizes.

---
 tools/testing/selftests/bpf/progs/dynptr_success.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/progs/dynptr_success.c +3 -2
index 7d7081d05d47..3094a1e4ee91 100644
@@ -611,11 +611,12 @@ int test_dynptr_copy_xdp(struct xdp_md *xdp)
 	struct bpf_dynptr ptr_buf, ptr_xdp;
 	char data[] = "qwertyuiopasdfghjkl";
 	char buf[32] = {'\0'};
-	__u32 len = sizeof(data);
+	__u32 len = sizeof(data), xdp_data_size;
 	int i, chunks = 200;
 
 	/* ptr_xdp is backed by non-contiguous memory */
 	bpf_dynptr_from_xdp(xdp, 0, &ptr_xdp);
+	xdp_data_size = bpf_dynptr_size(&ptr_xdp);
 	bpf_ringbuf_reserve_dynptr(&ringbuf, len * chunks, 0, &ptr_buf);
 
 	/* Destination dynptr is backed by non-contiguous memory */
@@ -673,7 +674,7 @@ int test_dynptr_copy_xdp(struct xdp_md *xdp)
 			goto out;
 	}
 
-	if (bpf_dynptr_copy(&ptr_xdp, 2000, &ptr_xdp, 0, len * chunks) != -E2BIG)
+	if (bpf_dynptr_copy(&ptr_xdp, xdp_data_size - 3000, &ptr_xdp, 0, len * chunks) != -E2BIG)
 		err = 1;
 
 out:
Signature · 1 line
2.47.3
Acked-by on v1 2/3
#4 lore raw

Re: [PATCH bpf-next 2/3] selftests/bpf: Fix test dynptr/test_dynptr_copy_xdp failure

Quoted 28 lines · Yonghong Song

For arm64 64K page size, the bpf_dynptr_copy() in test dynptr/test_dynptr_copy_xdp will succeed, but the test will failure with 4K page size. This patch made a change so the test will fail expectedly for both 4K and 64K page sizes.

---
  tools/testing/selftests/bpf/progs/dynptr_success.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/progs/dynptr_success.c +2 -1
index 7d7081d05d47..3094a1e4ee91 100644
@@ -611,11 +611,12 @@ int test_dynptr_copy_xdp(struct xdp_md *xdp)
  	struct bpf_dynptr ptr_buf, ptr_xdp;
  	char data[] = "qwertyuiopasdfghjkl";
  	char buf[32] = {'\0'};
-	__u32 len = sizeof(data);
+	__u32 len = sizeof(data), xdp_data_size;
  	int i, chunks = 200;
 
  	/* ptr_xdp is backed by non-contiguous memory */
  	bpf_dynptr_from_xdp(xdp, 0, &ptr_xdp);
+	xdp_data_size = bpf_dynptr_size(&ptr_xdp);
  	bpf_ringbuf_reserve_dynptr(&ringbuf, len * chunks, 0, &ptr_buf);
 
  	/* Destination dynptr is backed by non-contiguous memory */

tools/testing/selftests/bpf/progs/dynptr_success.c int test_dynptr_copy_xdp(struct xdp_md *xdp) · line 680

Quoted 8 lines
tools/testing/selftests/bpf/progs/dynptr_success.c +1 -1
@@ -673,7 +674,7 @@ int test_dynptr_copy_xdp(struct xdp_md *xdp)
  			goto out;
  	}
 
-	if (bpf_dynptr_copy(&ptr_xdp, 2000, &ptr_xdp, 0, len * chunks) != -E2BIG)
+	if (bpf_dynptr_copy(&ptr_xdp, xdp_data_size - 3000, &ptr_xdp, 0, len * chunks) != -E2BIG)
  		err = 1;
 
  out:
author reviewer
#5 lore raw

PATCH 3/3 selftests/bpf: Fix test dynptr/test_dynptr_memset_xdp_chunks failure

In reply to Yonghong Song

For arm64 64K page size, the xdp data size was set to be more than 64K in one of previous patches. This will cause failure for bpf_dynptr_memset(). Since the failure of bpf_dynptr_memset() is expected with 64K page size, return success.

---
 tools/testing/selftests/bpf/progs/dynptr_success.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/dynptr_success.c +12 -1
index 3094a1e4ee91..8315273cb900 100644
@@ -9,6 +9,8 @@
 #include "bpf_misc.h"
 #include "errno.h"
 
+#define PAGE_SIZE_64K 65536
+
 char _license[] SEC("license") = "GPL";
 
 int pid, err, val;
@@ -821,8 +823,17 @@ int test_dynptr_memset_xdp_chunks(struct xdp_md *xdp)
 	data_sz = bpf_dynptr_size(&ptr_xdp);
 
 	err = bpf_dynptr_memset(&ptr_xdp, 0, data_sz, DYNPTR_MEMSET_VAL);
-	if (err)
+	if (err) {
+		/* bpf_dynptr_memset() eventually called bpf_xdp_pointer()
+		 * where if data_sz is greater than 0xffff, -EFAULT will be
+		 * returned. For 64K page size, data_sz is greater than
+		 * 64K, so error is expected and let us zero out error and
+		 * return success.
+		 */
+		if (data_sz >= PAGE_SIZE_64K)
+			err = 0;
 		goto out;
+	}
 
 	bpf_for(i, 0, max_chunks) {
 		offset = i * sizeof(buf);
Signature · 1 line
2.47.3
#6 lore raw

Re: [PATCH bpf-next 3/3] selftests/bpf: Fix test dynptr/test_dynptr_memset_xdp_chunks failure

Quoted 24 lines · Yonghong Song

For arm64 64K page size, the xdp data size was set to be more than 64K in one of previous patches. This will cause failure for bpf_dynptr_memset(). Since the failure of bpf_dynptr_memset() is expected with 64K page size, return success.

---
  tools/testing/selftests/bpf/progs/dynptr_success.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/dynptr_success.c +2 -0
index 3094a1e4ee91..8315273cb900 100644
@@ -9,6 +9,8 @@
  #include "bpf_misc.h"
  #include "errno.h"
 
+#define PAGE_SIZE_64K 65536
+
  char _license[] SEC("license") = "GPL";
 
  int pid, err, val;

tools/testing/selftests/bpf/progs/dynptr_success.c int test_dynptr_memset_xdp_chunks(struct xdp_md *xdp) · line 827

Quoted 6 lines
tools/testing/selftests/bpf/progs/dynptr_success.c +2 -1
@@ -821,8 +823,17 @@ int test_dynptr_memset_xdp_chunks(struct xdp_md *xdp)
  	data_sz = bpf_dynptr_size(&ptr_xdp);
 
  	err = bpf_dynptr_memset(&ptr_xdp, 0, data_sz, DYNPTR_MEMSET_VAL);
-	if (err)
+	if (err) {
+		/* bpf_dynptr_memset() eventually called bpf_xdp_pointer()

I don't think I understand why the test fixed in patch 1 (e.g. test_probe_read_user_dynptr) can pass the bpf_xdp_pointer test on 0xffff. I thought the bpf_probe_read_user_str_dynptr will eventually call the __bpf_xdp_store_bytes which also does a bpf_xdp_pointer?

Quoted 12 lines
tools/testing/selftests/bpf/progs/dynptr_success.c +8 -0
+		 * where if data_sz is greater than 0xffff, -EFAULT will be
+		 * returned. For 64K page size, data_sz is greater than
+		 * 64K, so error is expected and let us zero out error and
+		 * return success.
+		 */
+		if (data_sz >= PAGE_SIZE_64K)
+			err = 0;
  		goto out;
+	}
 
  	bpf_for(i, 0, max_chunks) {
  		offset = i * sizeof(buf);
author reviewer
#7 lore raw

Re: [PATCH bpf-next 3/3] selftests/bpf: Fix test dynptr/test_dynptr_memset_xdp_chunks failure

Quoted 23 lines · Martin KaFai Lau
Quoted 22 lines · Yonghong Song

For arm64 64K page size, the xdp data size was set to be more than 64K in one of previous patches. This will cause failure for bpf_dynptr_memset(). Since the failure of bpf_dynptr_memset() is expected with 64K page size, return success.

---
  tools/testing/selftests/bpf/progs/dynptr_success.c | 13 ++++++++++++-

  1 file changed, 12 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/dynptr_success.c +0 -0
index 3094a1e4ee91..8315273cb900 100644
@@ -9,6 +9,8 @@
   #include "bpf_misc.h"
   #include "errno.h"

  +#define PAGE_SIZE_64K 65536
+
  char _license[] SEC("license") = "GPL";
    int pid, err, val;

tools/testing/selftests/bpf/progs/dynptr_success.c +0 -0
@@ -821,8 +823,17 @@ int test_dynptr_memset_xdp_chunks(struct xdp_md 
Quoted 8 lines

tools/testing/selftests/bpf/progs/dynptr_success.c int test_dynptr_memset_xdp_chunks(struct xdp_md *xdp) · line 827

Quoted 6 lines
tools/testing/selftests/bpf/progs/dynptr_success.c +2 -1
 *xdp)
       data_sz = bpf_dynptr_size(&ptr_xdp);
         err = bpf_dynptr_memset(&ptr_xdp, 0, data_sz, DYNPTR_MEMSET_VAL);
-    if (err)
+    if (err) {
+        /* bpf_dynptr_memset() eventually called bpf_xdp_pointer()

I don't think I understand why the test fixed in patch 1 (e.g. test_probe_read_user_dynptr) can pass the bpf_xdp_pointer test on 0xffff. I thought the bpf_probe_read_user_str_dynptr will eventually call the __bpf_xdp_store_bytes which also does a bpf_xdp_pointer?

For example, for test_probe_read_user_dynptr, for function test_dynptr_probe_xdp(), for this one:
off = xdp_near_frag_end_offset();

the off = 64928. Note that xdp_near_frag_end_offset() return value depends page size.

__u32 xdp_near_frag_end_offset(void)

{
        const __u32 headroom = 256;
        const __u32 max_frag_size =  __PAGE_SIZE - headroom - sizeof(struct skb_shared_info);
        
        /* 32 bytes before the approximate end of the fragment */
        return max_frag_size - 32;
}

The 'len' depends on 'test_len[i]' and test_len is
__u32 test_len[7] = {0/* placeholder */, 0, 1, 2, 255, 256, 257};

In bpf_xdp_pointer, we have the following test

        if (unlikely(offset > 0xffff || len > 0xffff))
                return ERR_PTR(-EFAULT);

In this particular case, offset = 64928, len = {0, 1, 2, 255, 256, 257}, so it won't return -EFAULT.

For this patch 3, test_dynptr_memset_xdp_chunks, eventually we reached here:

        for (write_off = 0; write_off < size; write_off += chunk_sz) {
                chunk_sz = min_t(u32, sizeof(buf), size - write_off);
                err = __bpf_dynptr_write(ptr, offset + write_off, buf, chunk_sz, 0);
                if (err)
                        return err;
        }

So the 'size' is 90000, chunk_sz is 256.
So 'offset + write_off' will be 0, 256, 512, ..., 65536
Once it reached 65536, 'offset > 0xffff' will become true since 0xffff = 65535. and the -EFAULT will be returned.

Quoted 13 lines
Quoted 12 lines
tools/testing/selftests/bpf/progs/dynptr_success.c +8 -0
+         * where if data_sz is greater than 0xffff, -EFAULT will be
+         * returned. For 64K page size, data_sz is greater than
+         * 64K, so error is expected and let us zero out error and
+         * return success.
+         */
+        if (data_sz >= PAGE_SIZE_64K)
+            err = 0;
           goto out;
+    }
         bpf_for(i, 0, max_chunks) {
           offset = i * sizeof(buf);
#8 lore raw

Re: [PATCH bpf-next 3/3] selftests/bpf: Fix test dynptr/test_dynptr_memset_xdp_chunks failure

Quoted 49 lines · Yonghong Song
Quoted 22 lines · Martin KaFai Lau
Quoted 21 lines · Yonghong Song

For arm64 64K page size, the xdp data size was set to be more than 64K in one of previous patches. This will cause failure for bpf_dynptr_memset(). Since the failure of bpf_dynptr_memset() is expected with 64K page size, return success.

---
  tools/testing/selftests/bpf/progs/dynptr_success.c | 13 ++++++++++++-

  1 file changed, 12 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/dynptr_success.c +0 -0
index 3094a1e4ee91..8315273cb900 100644
@@ -9,6 +9,8 @@
   #include "bpf_misc.h"
   #include "errno.h"

  +#define PAGE_SIZE_64K 65536
+
  char _license[] SEC("license") = "GPL";
    int pid, err, val;

Quoted 8 lines

tools/testing/selftests/bpf/progs/dynptr_success.c int test_dynptr_memset_xdp_chunks(struct xdp_md *xdp) · line 826

Quoted 6 lines
tools/testing/selftests/bpf/progs/dynptr_success.c +2 -1
@@ -821,8 +823,17 @@ int test_dynptr_memset_xdp_chunks(struct xdp_md *xdp)
       data_sz = bpf_dynptr_size(&ptr_xdp);
         err = bpf_dynptr_memset(&ptr_xdp, 0, data_sz, DYNPTR_MEMSET_VAL);
-    if (err)
+    if (err) {
+        /* bpf_dynptr_memset() eventually called bpf_xdp_pointer()

I don't think I understand why the test fixed in patch 1 (e.g. test_probe_read_user_dynptr) can pass the bpf_xdp_pointer test on 0xffff. I thought the bpf_probe_read_user_str_dynptr will eventually call the __bpf_xdp_store_bytes which also does a bpf_xdp_pointer?

For example, for test_probe_read_user_dynptr, for function test_dynptr_probe_xdp(), for this one:
   off = xdp_near_frag_end_offset();

the off = 64928. Note that xdp_near_frag_end_offset() return value depends page size.

__u32 xdp_near_frag_end_offset(void)
{
        const __u32 headroom = 256;
        const __u32 max_frag_size =  __PAGE_SIZE - headroom - sizeof(struct
skb_shared_info);
        /* 32 bytes before the approximate end of the fragment */ return max_frag_size - 32;
}

Quoted 6 lines

The 'len' depends on 'test_len[i]' and test_len is
   __u32 test_len[7] = {0/* placeholder */, 0, 1, 2, 255, 256, 257};

In bpf_xdp_pointer, we have the following test

        if (unlikely(offset > 0xffff || len > 0xffff))

Thanks for the explanation. Applied. Thanks.

I wonder if the 0xffff check can be removed from bpf_xdp_pointer() and depend on checking the xdp_get_buff_len(). The 0xffff check was also removed from the bpf_skb_load_bytes some time ago. [cc: Lorenzo, netdev]

Otherwise, it is not very useful to be able to create such xdp buff from the bpf_prog_test_run_xdp.

#9 lore raw
In reply to Yonghong Song
This series was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:

Hello:

This series was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:

Quoted 10 lines · On Thu, 24 Jul 2025 21:34:25 -0700 you wrote:

There are a few dynptr test failures with arm64 64K page size. They are fixed in this patch set and please see individual patches for details.

Yonghong Song (3):
selftests/bpf: Increase xdp data size for arm64 64K page size selftests/bpf: Fix test dynptr/test_dynptr_copy_xdp failure selftests/bpf: Fix test dynptr/test_dynptr_memset_xdp_chunks failure

[...]

Here is the summary with links:
- [bpf-next,1/3] selftests/bpf: Increase xdp data size for arm64 64K page size

    https://git.kernel.org/bpf/bpf-next/c/4c82768e4134
  - [bpf-next,2/3] selftests/bpf: Fix test dynptr/test_dynptr_copy_xdp failure
    https://git.kernel.org/bpf/bpf-next/c/90f791a975af
  - [bpf-next,3/3] selftests/bpf: Fix test dynptr/test_dynptr_memset_xdp_chunks failure
    https://git.kernel.org/bpf/bpf-next/c/4a5dcb337395

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html