Skip to content

Commit 0038780

Browse files
liu-song-6Alexei Starovoitov
authored andcommitted
selftests/bpf: Fix tests after fields reorder in struct file
The change in struct file [1] moved f_ref to the 3rd cache line. It made *(u64 *)file dereference invalid from the verifier point of view, because btf_struct_walk() walks into f_lock field, which is 4-byte long. Fix the selftests to deference the file pointer as a 4-byte access. [1] commit e249056 ("fs: place f_ref to 3rd cache line in struct file to resolve false sharing") Reported-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Song Liu <song@kernel.org> Link: https://lore.kernel.org/r/20250327185528.1740787-1-song@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 5d0b204 commit 0038780

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ int BPF_PROG(handle_fexit_ret, int arg, struct file *ret)
117117

118118
bpf_probe_read_kernel(&buf, 8, ret);
119119
bpf_probe_read_kernel(&buf, 8, (char *)ret + 256);
120-
*(volatile long long *)ret;
120+
*(volatile int *)ret;
121121
*(volatile int *)&ret->f_mode;
122122
return 0;
123123
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static __u64 test_cb(struct bpf_map *map, __u32 *key, __u64 *val, void *data)
2121
SEC("fexit/bpf_testmod_return_ptr")
2222
int BPF_PROG(handle_fexit_ret_subprogs, int arg, struct file *ret)
2323
{
24-
*(volatile long *)ret;
24+
*(volatile int *)ret;
2525
*(volatile int *)&ret->f_mode;
2626
bpf_for_each_map_elem(&test_array, test_cb, NULL, 0);
2727
triggered++;
@@ -31,7 +31,7 @@ int BPF_PROG(handle_fexit_ret_subprogs, int arg, struct file *ret)
3131
SEC("fexit/bpf_testmod_return_ptr")
3232
int BPF_PROG(handle_fexit_ret_subprogs2, int arg, struct file *ret)
3333
{
34-
*(volatile long *)ret;
34+
*(volatile int *)ret;
3535
*(volatile int *)&ret->f_mode;
3636
bpf_for_each_map_elem(&test_array, test_cb, NULL, 0);
3737
triggered++;
@@ -41,7 +41,7 @@ int BPF_PROG(handle_fexit_ret_subprogs2, int arg, struct file *ret)
4141
SEC("fexit/bpf_testmod_return_ptr")
4242
int BPF_PROG(handle_fexit_ret_subprogs3, int arg, struct file *ret)
4343
{
44-
*(volatile long *)ret;
44+
*(volatile int *)ret;
4545
*(volatile int *)&ret->f_mode;
4646
bpf_for_each_map_elem(&test_array, test_cb, NULL, 0);
4747
triggered++;

0 commit comments

Comments
 (0)