Skip to contentSkip to conversation

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

PATCH Superseded Yonghong Song 3 participants 4 messages Dec 12, 2022 – Dec 13, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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:

Quoted 1 line
Quoted 1 line

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 CONDFIG_SMP set or not.

---
 tools/testing/selftests/bpf/progs/rcu_read_lock.c      | 8 ++++----
 tools/testing/selftests/bpf/progs/task_kfunc_failure.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
tools/testing/selftests/bpf/progs/rcu_read_lock.c +4 -4
index 125f908024d3..5cecbdbbb16e 100644
@@ -288,13 +288,13 @@ int nested_rcu_region(void *ctx)
 SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
 int task_untrusted_non_rcuptr(void *ctx)
 {
-	struct task_struct *task, *last_wakee;
+	struct task_struct *task, *group_leader;
 
 	task = bpf_get_current_task_btf();
 	bpf_rcu_read_lock();
-	/* the pointer last_wakee marked as untrusted */
-	last_wakee = task->real_parent->last_wakee;
-	(void)bpf_task_storage_get(&map_a, last_wakee, 0, 0);
+	/* the pointer group_leader marked as untrusted */
+	group_leader = task->real_parent->group_leader;
+	(void)bpf_task_storage_get(&map_a, group_leader, 0, 0);
 	bpf_rcu_read_unlock();
 	return 0;
 }
tools/testing/selftests/bpf/progs/task_kfunc_failure.c +1 -1
index 87fa1db9d9b5..1b47b94dbca0 100644
@@ -73,7 +73,7 @@ int BPF_PROG(task_kfunc_acquire_trusted_walked, struct task_struct *task, u64 cl
 	struct task_struct *acquired;
 
 	/* Can't invoke bpf_task_acquire() on a trusted pointer obtained from walking a struct. */
-	acquired = bpf_task_acquire(task->last_wakee);
+	acquired = bpf_task_acquire(task->group_leader);
 	bpf_task_release(acquired);
 
 	return 0;
Signature · 1 line
2.30.2
#1 lore raw
Quoted 4 lines · Yonghong Song

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

Quoted 1 line
Quoted 1 line

progs/rcu_read_lock.c:256:34: error: no member named 'last_wakee' in 'struct task_struct'

Quoted 8 lines
             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 CONDFIG_SMP set or not.

s/CONDFIG_SMP/CONFIG_SMP

Quoted 35 lines
---
 tools/testing/selftests/bpf/progs/rcu_read_lock.c      | 8 ++++----
 tools/testing/selftests/bpf/progs/task_kfunc_failure.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
tools/testing/selftests/bpf/progs/rcu_read_lock.c +4 -4
index 125f908024d3..5cecbdbbb16e 100644
@@ -288,13 +288,13 @@ int nested_rcu_region(void *ctx)
 SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
 int task_untrusted_non_rcuptr(void *ctx)
 {
-	struct task_struct *task, *last_wakee;
+	struct task_struct *task, *group_leader;
 
 	task = bpf_get_current_task_btf();
 	bpf_rcu_read_lock();
-	/* the pointer last_wakee marked as untrusted */
-	last_wakee = task->real_parent->last_wakee;
-	(void)bpf_task_storage_get(&map_a, last_wakee, 0, 0);
+	/* the pointer group_leader marked as untrusted */
+	group_leader = task->real_parent->group_leader;
+	(void)bpf_task_storage_get(&map_a, group_leader, 0, 0);
 	bpf_rcu_read_unlock();
 	return 0;
 }
tools/testing/selftests/bpf/progs/task_kfunc_failure.c +0 -0
index 87fa1db9d9b5..1b47b94dbca0 100644

tools/testing/selftests/bpf/progs/task_kfunc_failure.c int BPF_PROG(task_kfunc_acquire_trusted_walked, struct task_struct *task, u64 cl · line 76

Quoted 5 lines
tools/testing/selftests/bpf/progs/task_kfunc_failure.c +1 -1
@@ -73,7 +73,7 @@ int BPF_PROG(task_kfunc_acquire_trusted_walked, struct task_struct *task, u64 cl
 	struct task_struct *acquired;
 
 	/* Can't invoke bpf_task_acquire() on a trusted pointer obtained from walking a struct. */
-	acquired = bpf_task_acquire(task->last_wakee);
+	acquired = bpf_task_acquire(task->group_leader);

Ah, I missed that you'd sent this out before I sent out [0]. Thanks for fixing this for me. I'm fine with just merging this patch and dropping
[0] if it's easier for the maintainers.

[0]: https://lore.kernel.org/all/[email protected]/

Quoted 6 lines
tools/testing/selftests/bpf/progs/task_kfunc_failure.c +0 -0
 	bpf_task_release(acquired);
 
 	return 0;
Signature · 1 line
2.30.2
Acked-by
#2 lore raw
Quoted 9 lines · David Vernet
Quoted 8 lines · Yonghong Song

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

Quoted 1 line
Quoted 1 line

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.
Quoted 10 lines
Quoted 4 lines

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 CONDFIG_SMP set or not.

s/CONDFIG_SMP/CONFIG_SMP

Quoted 3 lines

Also:

#3 lore raw
In reply to David Vernet
Quoted 61 lines · David Vernet
Quoted 4 lines · Yonghong Song

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

Quoted 1 line
Quoted 1 line

progs/rcu_read_lock.c:256:34: error: no member named 'last_wakee' in 'struct task_struct'

Quoted 8 lines
              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 CONDFIG_SMP set or not.

s/CONDFIG_SMP/CONFIG_SMP

Quoted 35 lines
---
  tools/testing/selftests/bpf/progs/rcu_read_lock.c      | 8 ++++----
  tools/testing/selftests/bpf/progs/task_kfunc_failure.c | 2 +-
  2 files changed, 5 insertions(+), 5 deletions(-)
tools/testing/selftests/bpf/progs/rcu_read_lock.c +4 -4
index 125f908024d3..5cecbdbbb16e 100644
@@ -288,13 +288,13 @@ int nested_rcu_region(void *ctx)
  SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
  int task_untrusted_non_rcuptr(void *ctx)
  {
-	struct task_struct *task, *last_wakee;
+	struct task_struct *task, *group_leader;
 
  	task = bpf_get_current_task_btf();
  	bpf_rcu_read_lock();
-	/* the pointer last_wakee marked as untrusted */
-	last_wakee = task->real_parent->last_wakee;
-	(void)bpf_task_storage_get(&map_a, last_wakee, 0, 0);
+	/* the pointer group_leader marked as untrusted */
+	group_leader = task->real_parent->group_leader;
+	(void)bpf_task_storage_get(&map_a, group_leader, 0, 0);
  	bpf_rcu_read_unlock();
  	return 0;
  }
tools/testing/selftests/bpf/progs/task_kfunc_failure.c +0 -0
index 87fa1db9d9b5..1b47b94dbca0 100644

tools/testing/selftests/bpf/progs/task_kfunc_failure.c int BPF_PROG(task_kfunc_acquire_trusted_walked, struct task_struct *task, u64 cl · line 76

Quoted 5 lines
tools/testing/selftests/bpf/progs/task_kfunc_failure.c +1 -1
@@ -73,7 +73,7 @@ int BPF_PROG(task_kfunc_acquire_trusted_walked, struct task_struct *task, u64 cl
  	struct task_struct *acquired;
 
  	/* Can't invoke bpf_task_acquire() on a trusted pointer obtained from walking a struct. */
-	acquired = bpf_task_acquire(task->last_wakee);
+	acquired = bpf_task_acquire(task->group_leader);

Ah, I missed that you'd sent this out before I sent out [0]. Thanks for fixing this for me. I'm fine with just merging this patch and dropping
[0] if it's easier for the maintainers.

Quoted 1 line

[0]: https://lore.kernel.org/all/[email protected]/

I found the above as well since with the kernel-test-bot config, both rcu_read_lock.c and task_kfunc_failure.c caused compilation errors.

Let me send another version by fixing the above CONFIG_SMP typo, adding proper fix tags and adding your sign-off and ack.

Thanks!

Quoted 7 lines
Quoted 7 lines
tools/testing/selftests/bpf/progs/task_kfunc_failure.c +0 -0
  	bpf_task_release(acquired);
 
  	return 0;
Signature · 1 line
2.30.2