Skip to contentSkip to conversation

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

PATCH Applied Yonghong Song 2 participants 6 messages Jun 12, 2025 – Jun 13, 2025

Subsystems (5)
lore
Share & tools
lore

Yonghong Song

author reviewer
#0 lore raw

v3 cover bpf: Fix a few test failures with 64K page size

Changelog:
v2 -> v3:
- v2: https://lore.kernel.org/bpf/[email protected]/
- Add additional comments for xdp_adjust_tail test.
- Use actual kernel page size to set new_len for Patch 2 tests.
v1 -> v2:
- v1: https://lore.kernel.org/bpf/[email protected]/
- For xdp_adjust_tail, let kernel test_run can handle various page sizes for xdp progs.
- For two change_tail tests, make code easier to understand.
- Resolved a new test failure (xdp_do_redirect).

Yonghong Song (3):
bpf: Fix an issue in bpf_prog_test_run_xdp when page size greater than

    4K

selftests/bpf: Fix two net related test failures with 64K page size selftests/bpf: Fix xdp_do_redirect failure with 64KB page size

 net/bpf/test_run.c                            |  2 +-
 .../bpf/prog_tests/xdp_adjust_tail.c          | 96 +++++++++++++++++--
 .../bpf/prog_tests/xdp_do_redirect.c          | 13 ++-
 .../bpf/progs/test_sockmap_change_tail.c      |  9 +-
 .../selftests/bpf/progs/test_tc_change_tail.c | 14 +--
 .../bpf/progs/test_xdp_adjust_tail_grow.c     |  8 +-
 6 files changed, 122 insertions(+), 20 deletions(-)
Signature · 1 line
2.47.1
author reviewer
#1 lore raw

PATCH v3 1/3 bpf: Fix an issue in bpf_prog_test_run_xdp when page size greater than 4K

The bpf selftest xdp_adjust_tail/xdp_adjust_frags_tail_grow failed on arm64 with 64KB page:
xdp_adjust_tail/xdp_adjust_frags_tail_grow:FAIL

In bpf_prog_test_run_xdp(), the xdp->frame_sz is set to 4K, but later on when constructing frags, with 64K page size, the frag data_len could be more than 4K. This will cause problems in bpf_xdp_frags_increase_tail().

To fix the failure, the xdp->frame_sz is set to be PAGE_SIZE so kernel can test different page size properly. With the kernel change, the user space and bpf prog needs adjustment. Currently, the MAX_SKB_FRAGS default value is 17, so for 4K page, the maximum packet size will be less than 68K. To test 64K page, a bigger maximum packet size than 68K is desired. So two different functions are implemented for subtest xdp_adjust_frags_tail_grow. Depending on different page size, different data input/output sizes are used to adapt with different page size.

---
 net/bpf/test_run.c                            |  2 +-
 .../bpf/prog_tests/xdp_adjust_tail.c          | 96 +++++++++++++++++--
 .../bpf/progs/test_xdp_adjust_tail_grow.c     |  8 +-
 3 files changed, 97 insertions(+), 9 deletions(-)
net/bpf/test_run.c +1 -1
index aaf13a7d58ed..9728dbd4c66c 100644
@@ -1255,7 +1255,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
 		headroom -= ctx->data;
 	}
 
-	max_data_sz = 4096 - headroom - tailroom;
+	max_data_sz = PAGE_SIZE - headroom - tailroom;
 	if (size > max_data_sz) {
 		/* disallow live data mode for jumbo frames */
 		if (do_live)
tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c +89 -7

133 lines not on this page · raw message

tools/testing/selftests/bpf/progs/test_xdp_adjust_tail_grow.c +7 -1
index dc74d8cf9e3f..5904f45cfbc4 100644
@@ -19,7 +19,9 @@ int _xdp_adjust_tail_grow(struct xdp_md *xdp)
 	/* Data length determine test case */
 
 	if (data_len == 54) { /* sizeof(pkt_v4) */
-		offset = 4096; /* test too large offset */
+		offset = 4096; /* test too large offset, 4k page size */
+	} else if (data_len == 53) { /* sizeof(pkt_v4) - 1 */
+		offset = 65536; /* test too large offset, 64k page size */
 	} else if (data_len == 74) { /* sizeof(pkt_v6) */
 		offset = 40;
 	} else if (data_len == 64) {
@@ -31,6 +33,10 @@ int _xdp_adjust_tail_grow(struct xdp_md *xdp)
 		offset = 10;
 	} else if (data_len == 9001) {
 		offset = 4096;
+	} else if (data_len == 90000) {
+		offset = 10; /* test a small offset, 64k page size */
+	} else if (data_len == 90001) {
+		offset = 65536; /* test too large offset, 64k page size */
 	} else {
 		return XDP_ABORTED; /* No matching test */
 	}
Signature · 1 line
2.47.1
author reviewer
#2 lore raw

PATCH v3 2/3 selftests/bpf: Fix two net related test failures with 64K page size

In reply to Yonghong Song

When running BPF selftests on arm64 with a 64K page size, I encountered the following two test failures:
sockmap_basic/sockmap skb_verdict change tail:FAIL tc_change_tail:FAIL

With further debugging, I identified the root cause in the following kernel code within __bpf_skb_change_tail():

    u32 max_len = BPF_SKB_MAX_LEN;
    u32 min_len = __bpf_skb_min_len(skb);
    int ret;

    if (unlikely(flags || new_len > max_len || new_len < min_len))
        return -EINVAL;

With a 4K page size, new_len = 65535 and max_len = 16064, the function returns -EINVAL. However, With a 64K page size, max_len increases to 261824, allowing execution to proceed further in the function. This is because BPF_SKB_MAX_LEN scales with the page size and larger page sizes result in higher max_len values.

Updating the new_len parameter in both tests based on actual kernel page size resolved both failures.

---
 .../selftests/bpf/progs/test_sockmap_change_tail.c |  9 +++++++--
 .../selftests/bpf/progs/test_tc_change_tail.c      | 14 +++++++-------
 2 files changed, 14 insertions(+), 9 deletions(-)
tools/testing/selftests/bpf/progs/test_sockmap_change_tail.c +7 -2
index 2796dd8545eb..1c7941a4ad00 100644
@@ -1,8 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2024 ByteDance */
-#include <linux/bpf.h>
+#include "vmlinux.h"
 #include <bpf/bpf_helpers.h>
 
+#ifndef PAGE_SIZE
+#define PAGE_SIZE __PAGE_SIZE
+#endif
+#define BPF_SKB_MAX_LEN (PAGE_SIZE << 2)
+
 struct {
 	__uint(type, BPF_MAP_TYPE_SOCKMAP);
 	__uint(max_entries, 1);
@@ -31,7 +36,7 @@ int prog_skb_verdict(struct __sk_buff *skb)
 		change_tail_ret = bpf_skb_change_tail(skb, skb->len + 1, 0);
 		return SK_PASS;
 	} else if (data[0] == 'E') { /* Error */
-		change_tail_ret = bpf_skb_change_tail(skb, 65535, 0);
+		change_tail_ret = bpf_skb_change_tail(skb, BPF_SKB_MAX_LEN, 0);
 		return SK_PASS;
 	}
 	return SK_PASS;
tools/testing/selftests/bpf/progs/test_tc_change_tail.c +7 -7
index 28edafe803f0..fcba8299f0bc 100644
@@ -1,11 +1,11 @@
 // SPDX-License-Identifier: GPL-2.0
-#include <linux/bpf.h>
+#include "vmlinux.h"
 #include <bpf/bpf_helpers.h>
-#include <linux/if_ether.h>
-#include <linux/in.h>
-#include <linux/ip.h>
-#include <linux/udp.h>
-#include <linux/pkt_cls.h>
+
+#ifndef PAGE_SIZE
+#define PAGE_SIZE __PAGE_SIZE
+#endif
+#define BPF_SKB_MAX_LEN (PAGE_SIZE << 2)
 
 long change_tail_ret = 1;
 
@@ -94,7 +94,7 @@ int change_tail(struct __sk_buff *skb)
 			bpf_skb_change_tail(skb, len, 0);
 		return TCX_PASS;
 	} else if (payload[0] == 'E') { /* Error */
-		change_tail_ret = bpf_skb_change_tail(skb, 65535, 0);
+		change_tail_ret = bpf_skb_change_tail(skb, BPF_SKB_MAX_LEN, 0);
 		return TCX_PASS;
 	} else if (payload[0] == 'Z') { /* Zero */
 		change_tail_ret = bpf_skb_change_tail(skb, 0, 0);
Signature · 1 line
2.47.1
author reviewer
#3 lore raw

PATCH v3 3/3 selftests/bpf: Fix xdp_do_redirect failure with 64KB page size

In reply to Yonghong Song

On arm64 with 64KB page size, the selftest xdp_do_redirect failed like
below:
...
test_xdp_do_redirect:PASS:pkt_count_tc 0 nsec test_max_pkt_size:PASS:prog_run_max_size 0 nsec test_max_pkt_size:FAIL:prog_run_too_big unexpected prog_run_too_big: actual -28 != expected -22

With 64KB page size, the xdp frame size will be much bigger so the existing test will fail.

Adjust various parameters so the test can also work on 64K page size.

---
 .../selftests/bpf/prog_tests/xdp_do_redirect.c      | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c +11 -2
index 7dac044664ac..dd34b0cc4b4e 100644
@@ -66,16 +66,25 @@ static int attach_tc_prog(struct bpf_tc_hook *hook, int fd)
 #else
 #define MAX_PKT_SIZE 3408
 #endif
+
+#define PAGE_SIZE_4K  4096
+#define PAGE_SIZE_64K 65536
+
 static void test_max_pkt_size(int fd)
 {
-	char data[MAX_PKT_SIZE + 1] = {};
+	char data[PAGE_SIZE_64K + 1] = {};
 	int err;
 	DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts,
 			    .data_in = &data,
-			    .data_size_in = MAX_PKT_SIZE,
 			    .flags = BPF_F_TEST_XDP_LIVE_FRAMES,
 			    .repeat = 1,
 		);
+
+	if (getpagesize() == PAGE_SIZE_64K)
+		opts.data_size_in = MAX_PKT_SIZE + PAGE_SIZE_64K - PAGE_SIZE_4K;
+	else
+		opts.data_size_in = MAX_PKT_SIZE;
+
 	err = bpf_prog_test_run_opts(fd, &opts);
 	ASSERT_OK(err, "prog_run_max_size");
 
Signature · 1 line
2.47.1
author reviewer
#4 lore raw
In reply to Yonghong Song

Sorry, missed the below small description:

This small patch set tried to fix a few networking related test failures due to 64K page size. Please see each individual patch for details.

Quoted 25 lines

Changelog:
v2 -> v3:
- v2: https://lore.kernel.org/bpf/[email protected]/
- Add additional comments for xdp_adjust_tail test.
- Use actual kernel page size to set new_len for Patch 2 tests.
v1 -> v2:
- v1: https://lore.kernel.org/bpf/[email protected]/
- For xdp_adjust_tail, let kernel test_run can handle various page sizes for xdp progs.
- For two change_tail tests, make code easier to understand.
- Resolved a new test failure (xdp_do_redirect).

Yonghong Song (3):
bpf: Fix an issue in bpf_prog_test_run_xdp when page size greater than

     4K

selftests/bpf: Fix two net related test failures with 64K page size selftests/bpf: Fix xdp_do_redirect failure with 64KB page size

  net/bpf/test_run.c                            |  2 +-
  .../bpf/prog_tests/xdp_adjust_tail.c          | 96 +++++++++++++++++--
  .../bpf/prog_tests/xdp_do_redirect.c          | 13 ++-
  .../bpf/progs/test_sockmap_change_tail.c      |  9 +-
  .../selftests/bpf/progs/test_tc_change_tail.c | 14 +--
  .../bpf/progs/test_xdp_adjust_tail_grow.c     |  8 +-
  6 files changed, 122 insertions(+), 20 deletions(-)
#5 lore raw
In reply to Yonghong Song
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 11 lines · On Wed, 11 Jun 2025 20:50:27 -0700 you wrote:

Changelog:
v2 -> v3:
- v2: https://lore.kernel.org/bpf/[email protected]/
- Add additional comments for xdp_adjust_tail test.
- Use actual kernel page size to set new_len for Patch 2 tests.
v1 -> v2:
- v1: https://lore.kernel.org/bpf/[email protected]/
- For xdp_adjust_tail, let kernel test_run can handle various page sizes for xdp progs.
- For two change_tail tests, make code easier to understand.
- Resolved a new test failure (xdp_do_redirect).

Quoted 1 line

[...]

Here is the summary with links:
- [bpf-next,v3,1/3] bpf: Fix an issue in bpf_prog_test_run_xdp when page size greater than 4K

    https://git.kernel.org/bpf/bpf-next/c/4fc012daf9c0
  - [bpf-next,v3,2/3] selftests/bpf: Fix two net related test failures with 64K page size
    https://git.kernel.org/bpf/bpf-next/c/96fcf7e7a71c
  - [bpf-next,v3,3/3] selftests/bpf: Fix xdp_do_redirect failure with 64KB page size
    https://git.kernel.org/bpf/bpf-next/c/44df9e0d4eec

You are awesome, thank you!

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