2020-01-28 17:22:30

by Madhuparna Bhowmik

[permalink] [raw]
Subject: [PATCH] exit.c: Fix Sparse errors and warnings

From: Madhuparna Bhowmik <[email protected]>

This patch fixes the following sparse error:
kernel/exit.c:627:25: error: incompatible types in comparison expression
caused due to accessing rcu protected pointer without using rcu primitives.

And the following warning:

kernel/exit.c:626:40: warning: incorrect type in assignment

Signed-off-by: Madhuparna Bhowmik <[email protected]>
---
kernel/exit.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/exit.c b/kernel/exit.c
index bcbd59888e67..c5a9d6360440 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -623,8 +623,8 @@ static void forget_original_parent(struct task_struct *father,
reaper = find_new_reaper(father, reaper);
list_for_each_entry(p, &father->children, sibling) {
for_each_thread(p, t) {
- t->real_parent = reaper;
- BUG_ON((!t->ptrace) != (t->parent == father));
+ rcu_assign_pointer(t->real_parent, reaper);
+ BUG_ON((!t->ptrace) != (rcu_access_pointer(t->parent) == father));
if (likely(!t->ptrace))
t->parent = t->real_parent;
if (t->pdeath_signal)
--
2.17.1


2020-01-28 18:03:52

by Christian Brauner

[permalink] [raw]
Subject: Re: [PATCH] exit.c: Fix Sparse errors and warnings

On Tue, Jan 28, 2020 at 10:50:08PM +0530, [email protected] wrote:
> From: Madhuparna Bhowmik <[email protected]>
>
> This patch fixes the following sparse error:
> kernel/exit.c:627:25: error: incompatible types in comparison expression
> caused due to accessing rcu protected pointer without using rcu primitives.
>
> And the following warning:
>
> kernel/exit.c:626:40: warning: incorrect type in assignment
>
> Signed-off-by: Madhuparna Bhowmik <[email protected]>

Thanks, looks good to me!
Acked-by: Christian Brauner <[email protected]>

2020-01-29 12:33:12

by Oleg Nesterov

[permalink] [raw]
Subject: Re: [PATCH] exit.c: Fix Sparse errors and warnings

On 01/28, [email protected] wrote:
>
> kernel/exit.c:626:40: warning: incorrect type in assignment
>
> Signed-off-by: Madhuparna Bhowmik <[email protected]>
> ---
> kernel/exit.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/exit.c b/kernel/exit.c
> index bcbd59888e67..c5a9d6360440 100644
> --- a/kernel/exit.c
> +++ b/kernel/exit.c
> @@ -623,8 +623,8 @@ static void forget_original_parent(struct task_struct *father,
> reaper = find_new_reaper(father, reaper);
> list_for_each_entry(p, &father->children, sibling) {
> for_each_thread(p, t) {
> - t->real_parent = reaper;
> - BUG_ON((!t->ptrace) != (t->parent == father));
> + rcu_assign_pointer(t->real_parent, reaper);

Another case when RCU_INIT_POINTER() makes more sense (although to me it
too looks confusing). We didn't modify the new parent.

Oleg.

2020-01-29 16:03:52

by Madhuparna Bhowmik

[permalink] [raw]
Subject: Re: [PATCH] exit.c: Fix Sparse errors and warnings

On Wed, Jan 29, 2020 at 01:30:47PM +0100, Oleg Nesterov wrote:
> On 01/28, [email protected] wrote:
> >
> > kernel/exit.c:626:40: warning: incorrect type in assignment
> >
> > Signed-off-by: Madhuparna Bhowmik <[email protected]>
> > ---
> > kernel/exit.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/exit.c b/kernel/exit.c
> > index bcbd59888e67..c5a9d6360440 100644
> > --- a/kernel/exit.c
> > +++ b/kernel/exit.c
> > @@ -623,8 +623,8 @@ static void forget_original_parent(struct task_struct *father,
> > reaper = find_new_reaper(father, reaper);
> > list_for_each_entry(p, &father->children, sibling) {
> > for_each_thread(p, t) {
> > - t->real_parent = reaper;
> > - BUG_ON((!t->ptrace) != (t->parent == father));
> > + rcu_assign_pointer(t->real_parent, reaper);
>
> Another case when RCU_INIT_POINTER() makes more sense (although to me it
> too looks confusing). We didn't modify the new parent.
>
Alright, I will resend this patch with RCU_INIT_POINTER().

Thank you,
Madhuparna

> Oleg.
>