Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Fix a selftest compilation error with CONFIG_SMP=n

Kernel test robot reported bpf selftest build failure when CONFIG_SMP
is not set. The error message looks below:

>> progs/rcu_read_lock.c:256:34: error: no member named 'last_wakee' in 'struct task_struct'
last_wakee = task->real_parent->last_wakee;
~~~~~~~~~~~~~~~~~ ^
1 error generated.

When CONFIG_SMP is not set, the field 'last_wakee' is not available in struct
'task_struct'. Hence the above compilation failure. To fix the issue, let us
choose another field 'group_leader' which is available regardless of
CONFIG_SMP set or not.

Fixes: fe147956fca4 ("bpf/selftests: Add selftests for new task kfuncs")
Fixes: 48671232fcb8 ("selftests/bpf: Add tests for bpf_rcu_read_lock()")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: David Vernet <void@manifault.com>
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: David Vernet <void@manifault.com>
Link: https://lore.kernel.org/bpf/20221213012224.379581-1-yhs@fb.com

authored by

Yonghong Song and committed by
Daniel Borkmann
ec9230b1 d2b497a9

+5 -5
+4 -4
tools/testing/selftests/bpf/progs/rcu_read_lock.c
··· 288 288 SEC("?fentry.s/" SYS_PREFIX "sys_getpgid") 289 289 int task_untrusted_non_rcuptr(void *ctx) 290 290 { 291 - struct task_struct *task, *last_wakee; 291 + struct task_struct *task, *group_leader; 292 292 293 293 task = bpf_get_current_task_btf(); 294 294 bpf_rcu_read_lock(); 295 - /* the pointer last_wakee marked as untrusted */ 296 - last_wakee = task->real_parent->last_wakee; 297 - (void)bpf_task_storage_get(&map_a, last_wakee, 0, 0); 295 + /* the pointer group_leader marked as untrusted */ 296 + group_leader = task->real_parent->group_leader; 297 + (void)bpf_task_storage_get(&map_a, group_leader, 0, 0); 298 298 bpf_rcu_read_unlock(); 299 299 return 0; 300 300 }
+1 -1
tools/testing/selftests/bpf/progs/task_kfunc_failure.c
··· 73 73 struct task_struct *acquired; 74 74 75 75 /* Can't invoke bpf_task_acquire() on a trusted pointer obtained from walking a struct. */ 76 - acquired = bpf_task_acquire(task->last_wakee); 76 + acquired = bpf_task_acquire(task->group_leader); 77 77 bpf_task_release(acquired); 78 78 79 79 return 0;