All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf] selftests/bpf: Fix a selftest compilation error with CONFIG_SMP=n
@ 2022-12-12 23:46 Yonghong Song
  2022-12-12 23:58 ` David Vernet
  0 siblings, 1 reply; 4+ messages in thread
From: Yonghong Song @ 2022-12-12 23:46 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann, kernel-team,
	Martin KaFai Lau, kernel test robot

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

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Yonghong Song <yhs@fb.com>
---
 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(-)

diff --git a/tools/testing/selftests/bpf/progs/rcu_read_lock.c b/tools/testing/selftests/bpf/progs/rcu_read_lock.c
index 125f908024d3..5cecbdbbb16e 100644
--- a/tools/testing/selftests/bpf/progs/rcu_read_lock.c
+++ b/tools/testing/selftests/bpf/progs/rcu_read_lock.c
@@ -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;
 }
diff --git a/tools/testing/selftests/bpf/progs/task_kfunc_failure.c b/tools/testing/selftests/bpf/progs/task_kfunc_failure.c
index 87fa1db9d9b5..1b47b94dbca0 100644
--- a/tools/testing/selftests/bpf/progs/task_kfunc_failure.c
+++ b/tools/testing/selftests/bpf/progs/task_kfunc_failure.c
@@ -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;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf] selftests/bpf: Fix a selftest compilation error with CONFIG_SMP=n
  2022-12-12 23:46 [PATCH bpf] selftests/bpf: Fix a selftest compilation error with CONFIG_SMP=n Yonghong Song
@ 2022-12-12 23:58 ` David Vernet
  2022-12-12 23:58   ` David Vernet
  2022-12-13  0:41   ` Yonghong Song
  0 siblings, 2 replies; 4+ messages in thread
From: David Vernet @ 2022-12-12 23:58 UTC (permalink / raw)
  To: Yonghong Song
  Cc: bpf, Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	kernel-team, Martin KaFai Lau, kernel test robot

On Mon, Dec 12, 2022 at 03:46:17PM -0800, Yonghong Song wrote:
> 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
> CONDFIG_SMP set or not.

s/CONDFIG_SMP/CONFIG_SMP

> 
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Yonghong Song <yhs@fb.com>
> ---
>  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(-)
> 
> diff --git a/tools/testing/selftests/bpf/progs/rcu_read_lock.c b/tools/testing/selftests/bpf/progs/rcu_read_lock.c
> index 125f908024d3..5cecbdbbb16e 100644
> --- a/tools/testing/selftests/bpf/progs/rcu_read_lock.c
> +++ b/tools/testing/selftests/bpf/progs/rcu_read_lock.c
> @@ -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;
>  }
> diff --git a/tools/testing/selftests/bpf/progs/task_kfunc_failure.c b/tools/testing/selftests/bpf/progs/task_kfunc_failure.c
> index 87fa1db9d9b5..1b47b94dbca0 100644
> --- a/tools/testing/selftests/bpf/progs/task_kfunc_failure.c
> +++ b/tools/testing/selftests/bpf/progs/task_kfunc_failure.c
> @@ -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/20221212235344.1563280-1-void@manifault.com/

>  	bpf_task_release(acquired);
>  
>  	return 0;
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf] selftests/bpf: Fix a selftest compilation error with CONFIG_SMP=n
  2022-12-12 23:58 ` David Vernet
@ 2022-12-12 23:58   ` David Vernet
  2022-12-13  0:41   ` Yonghong Song
  1 sibling, 0 replies; 4+ messages in thread
From: David Vernet @ 2022-12-12 23:58 UTC (permalink / raw)
  To: Yonghong Song
  Cc: bpf, Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	kernel-team, Martin KaFai Lau, kernel test robot

On Mon, Dec 12, 2022 at 05:58:20PM -0600, David Vernet wrote:
> On Mon, Dec 12, 2022 at 03:46:17PM -0800, Yonghong Song wrote:
> > 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
> > CONDFIG_SMP set or not.
> 
> s/CONDFIG_SMP/CONFIG_SMP
> 
> > 
> > Reported-by: kernel test robot <lkp@intel.com>
> > Signed-off-by: Yonghong Song <yhs@fb.com>

Also:

Acked-by: David Vernet <void@manifault.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf] selftests/bpf: Fix a selftest compilation error with CONFIG_SMP=n
  2022-12-12 23:58 ` David Vernet
  2022-12-12 23:58   ` David Vernet
@ 2022-12-13  0:41   ` Yonghong Song
  1 sibling, 0 replies; 4+ messages in thread
From: Yonghong Song @ 2022-12-13  0:41 UTC (permalink / raw)
  To: David Vernet, Yonghong Song
  Cc: bpf, Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	kernel-team, Martin KaFai Lau, kernel test robot



On 12/12/22 3:58 PM, David Vernet wrote:
> On Mon, Dec 12, 2022 at 03:46:17PM -0800, Yonghong Song wrote:
>> 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
>> CONDFIG_SMP set or not.
> 
> s/CONDFIG_SMP/CONFIG_SMP
> 
>>
>> Reported-by: kernel test robot <lkp@intel.com>
>> Signed-off-by: Yonghong Song <yhs@fb.com>
>> ---
>>   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(-)
>>
>> diff --git a/tools/testing/selftests/bpf/progs/rcu_read_lock.c b/tools/testing/selftests/bpf/progs/rcu_read_lock.c
>> index 125f908024d3..5cecbdbbb16e 100644
>> --- a/tools/testing/selftests/bpf/progs/rcu_read_lock.c
>> +++ b/tools/testing/selftests/bpf/progs/rcu_read_lock.c
>> @@ -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;
>>   }
>> diff --git a/tools/testing/selftests/bpf/progs/task_kfunc_failure.c b/tools/testing/selftests/bpf/progs/task_kfunc_failure.c
>> index 87fa1db9d9b5..1b47b94dbca0 100644
>> --- a/tools/testing/selftests/bpf/progs/task_kfunc_failure.c
>> +++ b/tools/testing/selftests/bpf/progs/task_kfunc_failure.c
>> @@ -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/20221212235344.1563280-1-void@manifault.com/

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!

> 
>>   	bpf_task_release(acquired);
>>   
>>   	return 0;
>> -- 
>> 2.30.2
>>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-13  0:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-12 23:46 [PATCH bpf] selftests/bpf: Fix a selftest compilation error with CONFIG_SMP=n Yonghong Song
2022-12-12 23:58 ` David Vernet
2022-12-12 23:58   ` David Vernet
2022-12-13  0:41   ` Yonghong Song

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.