Skip to content

Commit 96fcf7e

Browse files
Yonghong SongAlexei Starovoitov
authored andcommitted
selftests/bpf: Fix two net related test failures with 64K page size
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. Signed-off-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 4fc012d commit 96fcf7e

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

tools/testing/selftests/bpf/progs/test_sockmap_change_tail.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/* Copyright (c) 2024 ByteDance */
3-
#include <linux/bpf.h>
3+
#include "vmlinux.h"
44
#include <bpf/bpf_helpers.h>
55

6+
#ifndef PAGE_SIZE
7+
#define PAGE_SIZE __PAGE_SIZE
8+
#endif
9+
#define BPF_SKB_MAX_LEN (PAGE_SIZE << 2)
10+
611
struct {
712
__uint(type, BPF_MAP_TYPE_SOCKMAP);
813
__uint(max_entries, 1);
@@ -31,7 +36,7 @@ int prog_skb_verdict(struct __sk_buff *skb)
3136
change_tail_ret = bpf_skb_change_tail(skb, skb->len + 1, 0);
3237
return SK_PASS;
3338
} else if (data[0] == 'E') { /* Error */
34-
change_tail_ret = bpf_skb_change_tail(skb, 65535, 0);
39+
change_tail_ret = bpf_skb_change_tail(skb, BPF_SKB_MAX_LEN, 0);
3540
return SK_PASS;
3641
}
3742
return SK_PASS;

tools/testing/selftests/bpf/progs/test_tc_change_tail.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SPDX-License-Identifier: GPL-2.0
2-
#include <linux/bpf.h>
2+
#include "vmlinux.h"
33
#include <bpf/bpf_helpers.h>
4-
#include <linux/if_ether.h>
5-
#include <linux/in.h>
6-
#include <linux/ip.h>
7-
#include <linux/udp.h>
8-
#include <linux/pkt_cls.h>
4+
5+
#ifndef PAGE_SIZE
6+
#define PAGE_SIZE __PAGE_SIZE
7+
#endif
8+
#define BPF_SKB_MAX_LEN (PAGE_SIZE << 2)
99

1010
long change_tail_ret = 1;
1111

@@ -94,7 +94,7 @@ int change_tail(struct __sk_buff *skb)
9494
bpf_skb_change_tail(skb, len, 0);
9595
return TCX_PASS;
9696
} else if (payload[0] == 'E') { /* Error */
97-
change_tail_ret = bpf_skb_change_tail(skb, 65535, 0);
97+
change_tail_ret = bpf_skb_change_tail(skb, BPF_SKB_MAX_LEN, 0);
9898
return TCX_PASS;
9999
} else if (payload[0] == 'Z') { /* Zero */
100100
change_tail_ret = bpf_skb_change_tail(skb, 0, 0);

0 commit comments

Comments
 (0)