Skip to content

Commit 0925e82

Browse files
committed

File tree

3 files changed

+211
-0
lines changed

3 files changed

+211
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
From bd06a13f44e15e2e83561ea165061c445a15bd9e Mon Sep 17 00:00:00 2001
2+
From: Song Liu <song@kernel.org>
3+
Date: Thu, 27 Mar 2025 11:55:28 -0700
4+
Subject: [PATCH 4000/4002] selftests/bpf: Fix tests after fields reorder in
5+
struct file
6+
7+
The change in struct file [1] moved f_ref to the 3rd cache line.
8+
It made *(u64 *)file dereference invalid from the verifier point of view,
9+
because btf_struct_walk() walks into f_lock field, which is 4-byte long.
10+
11+
Fix the selftests to deference the file pointer as a 4-byte access.
12+
13+
[1] commit e249056c91a2 ("fs: place f_ref to 3rd cache line in struct file to resolve false sharing")
14+
Reported-by: Jakub Kicinski <kuba@kernel.org>
15+
Signed-off-by: Song Liu <song@kernel.org>
16+
Link: https://lore.kernel.org/r/20250327185528.1740787-1-song@kernel.org
17+
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
18+
---
19+
tools/testing/selftests/bpf/progs/test_module_attach.c | 2 +-
20+
tools/testing/selftests/bpf/progs/test_subprogs_extable.c | 6 +++---
21+
2 files changed, 4 insertions(+), 4 deletions(-)
22+
23+
diff --git a/tools/testing/selftests/bpf/progs/test_module_attach.c b/tools/testing/selftests/bpf/progs/test_module_attach.c
24+
index fb07f5773888..7f3c233943b3 100644
25+
--- a/tools/testing/selftests/bpf/progs/test_module_attach.c
26+
+++ b/tools/testing/selftests/bpf/progs/test_module_attach.c
27+
@@ -117,7 +117,7 @@ int BPF_PROG(handle_fexit_ret, int arg, struct file *ret)
28+
29+
bpf_probe_read_kernel(&buf, 8, ret);
30+
bpf_probe_read_kernel(&buf, 8, (char *)ret + 256);
31+
- *(volatile long long *)ret;
32+
+ *(volatile int *)ret;
33+
*(volatile int *)&ret->f_mode;
34+
return 0;
35+
}
36+
diff --git a/tools/testing/selftests/bpf/progs/test_subprogs_extable.c b/tools/testing/selftests/bpf/progs/test_subprogs_extable.c
37+
index e2a21fbd4e44..dcac69f5928a 100644
38+
--- a/tools/testing/selftests/bpf/progs/test_subprogs_extable.c
39+
+++ b/tools/testing/selftests/bpf/progs/test_subprogs_extable.c
40+
@@ -21,7 +21,7 @@ static __u64 test_cb(struct bpf_map *map, __u32 *key, __u64 *val, void *data)
41+
SEC("fexit/bpf_testmod_return_ptr")
42+
int BPF_PROG(handle_fexit_ret_subprogs, int arg, struct file *ret)
43+
{
44+
- *(volatile long *)ret;
45+
+ *(volatile int *)ret;
46+
*(volatile int *)&ret->f_mode;
47+
bpf_for_each_map_elem(&test_array, test_cb, NULL, 0);
48+
triggered++;
49+
@@ -31,7 +31,7 @@ int BPF_PROG(handle_fexit_ret_subprogs, int arg, struct file *ret)
50+
SEC("fexit/bpf_testmod_return_ptr")
51+
int BPF_PROG(handle_fexit_ret_subprogs2, int arg, struct file *ret)
52+
{
53+
- *(volatile long *)ret;
54+
+ *(volatile int *)ret;
55+
*(volatile int *)&ret->f_mode;
56+
bpf_for_each_map_elem(&test_array, test_cb, NULL, 0);
57+
triggered++;
58+
@@ -41,7 +41,7 @@ int BPF_PROG(handle_fexit_ret_subprogs2, int arg, struct file *ret)
59+
SEC("fexit/bpf_testmod_return_ptr")
60+
int BPF_PROG(handle_fexit_ret_subprogs3, int arg, struct file *ret)
61+
{
62+
- *(volatile long *)ret;
63+
+ *(volatile int *)ret;
64+
*(volatile int *)&ret->f_mode;
65+
bpf_for_each_map_elem(&test_array, test_cb, NULL, 0);
66+
triggered++;
67+
--
68+
2.49.0
69+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
From 8be3a12f9f266aaf3f06f0cfe0e90cfe4d956f3d Mon Sep 17 00:00:00 2001
2+
From: Song Liu <song@kernel.org>
3+
Date: Fri, 28 Mar 2025 12:31:24 -0700
4+
Subject: [PATCH 4001/4002] selftests/bpf: Fix verifier_bpf_fastcall test
5+
6+
Commit [1] moves percpu data on x86 from address 0x000... to address
7+
0xfff...
8+
9+
Before [1]:
10+
11+
159020: 0000000000030700 0 OBJECT GLOBAL DEFAULT 23 pcpu_hot
12+
13+
After [1]:
14+
15+
152602: ffffffff83a3e034 4 OBJECT GLOBAL DEFAULT 35 pcpu_hot
16+
17+
As a result, verifier_bpf_fastcall tests should now expect a negative
18+
value for pcpu_hot, IOW, the disassemble should show "r=" instead of
19+
"w=".
20+
21+
Fix this in the test.
22+
23+
Note that, a later change created a new variable "cpu_number" for
24+
bpf_get_smp_processor_id() [2]. The inlining logic is updated properly
25+
as part of this change, so there is no need to fix anything on the
26+
kernel side.
27+
28+
[1] commit 9d7de2aa8b41 ("x86/percpu/64: Use relative percpu offsets")
29+
[2] commit 01c7bc5198e9 ("x86/smp: Move cpu number to percpu hot section")
30+
Reported-by: Jakub Kicinski <kuba@kernel.org>
31+
Signed-off-by: Song Liu <song@kernel.org>
32+
Link: https://lore.kernel.org/r/20250328193124.808784-1-song@kernel.org
33+
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
34+
---
35+
tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c | 6 +++---
36+
1 file changed, 3 insertions(+), 3 deletions(-)
37+
38+
diff --git a/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c b/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c
39+
index a9be6ae49454..c258b0722e04 100644
40+
--- a/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c
41+
+++ b/tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c
42+
@@ -12,7 +12,7 @@ SEC("raw_tp")
43+
__arch_x86_64
44+
__log_level(4) __msg("stack depth 8")
45+
__xlated("4: r5 = 5")
46+
-__xlated("5: w0 = ")
47+
+__xlated("5: r0 = ")
48+
__xlated("6: r0 = &(void __percpu *)(r0)")
49+
__xlated("7: r0 = *(u32 *)(r0 +0)")
50+
__xlated("8: exit")
51+
@@ -704,7 +704,7 @@ SEC("raw_tp")
52+
__arch_x86_64
53+
__log_level(4) __msg("stack depth 32+0")
54+
__xlated("2: r1 = 1")
55+
-__xlated("3: w0 =")
56+
+__xlated("3: r0 =")
57+
__xlated("4: r0 = &(void __percpu *)(r0)")
58+
__xlated("5: r0 = *(u32 *)(r0 +0)")
59+
/* bpf_loop params setup */
60+
@@ -753,7 +753,7 @@ __arch_x86_64
61+
__log_level(4) __msg("stack depth 40+0")
62+
/* call bpf_get_smp_processor_id */
63+
__xlated("2: r1 = 42")
64+
-__xlated("3: w0 =")
65+
+__xlated("3: r0 =")
66+
__xlated("4: r0 = &(void __percpu *)(r0)")
67+
__xlated("5: r0 = *(u32 *)(r0 +0)")
68+
/* call bpf_get_prandom_u32 */
69+
--
70+
2.49.0
71+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
From 07be1f644ff9eeb842fd0490ddd824df0828cb0e Mon Sep 17 00:00:00 2001
2+
From: Yonghong Song <yonghong.song@linux.dev>
3+
Date: Sun, 30 Mar 2025 20:38:28 -0700
4+
Subject: [PATCH 4002/4002] selftests/bpf: Fix verifier_private_stack test
5+
failure
6+
7+
Several verifier_private_stack tests failed with latest bpf-next.
8+
For example, for 'Private stack, single prog' subtest, the
9+
jitted code:
10+
func #0:
11+
0: f3 0f 1e fa endbr64
12+
4: 0f 1f 44 00 00 nopl (%rax,%rax)
13+
9: 0f 1f 00 nopl (%rax)
14+
c: 55 pushq %rbp
15+
d: 48 89 e5 movq %rsp, %rbp
16+
10: f3 0f 1e fa endbr64
17+
14: 49 b9 58 74 8a 8f 7d 60 00 00 movabsq $0x607d8f8a7458, %r9
18+
1e: 65 4c 03 0c 25 28 c0 48 87 addq %gs:-0x78b73fd8, %r9
19+
27: bf 2a 00 00 00 movl $0x2a, %edi
20+
2c: 49 89 b9 00 ff ff ff movq %rdi, -0x100(%r9)
21+
33: 31 c0 xorl %eax, %eax
22+
35: c9 leave
23+
36: e9 20 5d 0f e1 jmp 0xffffffffe10f5d5b
24+
25+
The insn 'addq %gs:-0x78b73fd8, %r9' does not match the expected
26+
regex 'addq %gs:0x{{.*}}, %r9' and this caused test failure.
27+
28+
Fix it by changing '%gs:0x{{.*}}' to '%gs:{{.*}}' to accommodate the
29+
possible negative offset. A few other subtests are fixed in a similar way.
30+
31+
Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
32+
Link: https://lore.kernel.org/r/20250331033828.365077-1-yonghong.song@linux.dev
33+
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
34+
---
35+
tools/testing/selftests/bpf/progs/verifier_private_stack.c | 6 +++---
36+
1 file changed, 3 insertions(+), 3 deletions(-)
37+
38+
diff --git a/tools/testing/selftests/bpf/progs/verifier_private_stack.c b/tools/testing/selftests/bpf/progs/verifier_private_stack.c
39+
index b1fbdf119553..fc91b414364e 100644
40+
--- a/tools/testing/selftests/bpf/progs/verifier_private_stack.c
41+
+++ b/tools/testing/selftests/bpf/progs/verifier_private_stack.c
42+
@@ -27,7 +27,7 @@ __description("Private stack, single prog")
43+
__success
44+
__arch_x86_64
45+
__jited(" movabsq $0x{{.*}}, %r9")
46+
-__jited(" addq %gs:0x{{.*}}, %r9")
47+
+__jited(" addq %gs:{{.*}}, %r9")
48+
__jited(" movl $0x2a, %edi")
49+
__jited(" movq %rdi, -0x100(%r9)")
50+
__naked void private_stack_single_prog(void)
51+
@@ -74,7 +74,7 @@ __success
52+
__arch_x86_64
53+
/* private stack fp for the main prog */
54+
__jited(" movabsq $0x{{.*}}, %r9")
55+
-__jited(" addq %gs:0x{{.*}}, %r9")
56+
+__jited(" addq %gs:{{.*}}, %r9")
57+
__jited(" movl $0x2a, %edi")
58+
__jited(" movq %rdi, -0x200(%r9)")
59+
__jited(" pushq %r9")
60+
@@ -122,7 +122,7 @@ __jited(" pushq %rbp")
61+
__jited(" movq %rsp, %rbp")
62+
__jited(" endbr64")
63+
__jited(" movabsq $0x{{.*}}, %r9")
64+
-__jited(" addq %gs:0x{{.*}}, %r9")
65+
+__jited(" addq %gs:{{.*}}, %r9")
66+
__jited(" pushq %r9")
67+
__jited(" callq")
68+
__jited(" popq %r9")
69+
--
70+
2.49.0
71+

0 commit comments

Comments
 (0)