linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
* [Linux-kernel-mentees] [PATCH] sched.h: Annotate sighand_struct with __rcu
@ 2020-01-24  4:59 madhuparnabhowmik10
  2020-01-25 21:41 ` Christian Brauner
  2020-01-27  9:29 ` Oleg Nesterov
  0 siblings, 2 replies; 10+ messages in thread
From: madhuparnabhowmik10 @ 2020-01-24  4:59 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, ebiederm,
	christian.brauner, oleg, paulmck
  Cc: linux-kernel, rcu, Madhuparna Bhowmik, joel, linux-kernel-mentees

From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>

This patch fixes the following sparse errors by annotating the
sighand_struct with __rcu

kernel/fork.c:1511:9: error: incompatible types in comparison expression
kernel/exit.c:100:19: error: incompatible types in comparison expression
kernel/signal.c:1370:27: error: incompatible types in comparison expression

This fix introduces the following sparse error in signal.c due to
checking the sighand pointer without rcu primitives:

kernel/signal.c:1386:21: error: incompatible types in comparison expression

This new sparse error is also fixed in this patch.

Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
---
 include/linux/sched.h | 2 +-
 kernel/signal.c       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index b511e178a89f..7a351360ad54 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -918,7 +918,7 @@ struct task_struct {
 
 	/* Signal handlers: */
 	struct signal_struct		*signal;
-	struct sighand_struct		*sighand;
+	struct sighand_struct __rcu		*sighand;
 	sigset_t			blocked;
 	sigset_t			real_blocked;
 	/* Restored if set_restore_sigmask() was used: */
diff --git a/kernel/signal.c b/kernel/signal.c
index bcd46f547db3..9ad8dea93dbb 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1383,7 +1383,7 @@ struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
 		 * must see ->sighand == NULL.
 		 */
 		spin_lock_irqsave(&sighand->siglock, *flags);
-		if (likely(sighand == tsk->sighand))
+		if (likely(sighand == rcu_access_pointer(tsk->sighand)))
 			break;
 		spin_unlock_irqrestore(&sighand->siglock, *flags);
 	}
-- 
2.17.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH] sched.h: Annotate sighand_struct with __rcu
  2020-01-24  4:59 [Linux-kernel-mentees] [PATCH] sched.h: Annotate sighand_struct with __rcu madhuparnabhowmik10
@ 2020-01-25 21:41 ` Christian Brauner
  2020-01-26  1:23   ` Paul E. McKenney
  2020-01-27  9:29 ` Oleg Nesterov
  1 sibling, 1 reply; 10+ messages in thread
From: Christian Brauner @ 2020-01-25 21:41 UTC (permalink / raw)
  To: madhuparnabhowmik10, mingo, peterz, juri.lelli, vincent.guittot,
	ebiederm, oleg, paulmck
  Cc: linux-kernel, rcu, Madhuparna Bhowmik, joel, linux-kernel-mentees

On January 24, 2020 5:59:08 AM GMT+01:00, madhuparnabhowmik10@gmail.com wrote:
>From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
>
>This patch fixes the following sparse errors by annotating the
>sighand_struct with __rcu
>
>kernel/fork.c:1511:9: error: incompatible types in comparison
>expression
>kernel/exit.c:100:19: error: incompatible types in comparison
>expression
>kernel/signal.c:1370:27: error: incompatible types in comparison
>expression
>
>This fix introduces the following sparse error in signal.c due to
>checking the sighand pointer without rcu primitives:
>
>kernel/signal.c:1386:21: error: incompatible types in comparison
>expression
>
>This new sparse error is also fixed in this patch.
>
>Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
>---
> include/linux/sched.h | 2 +-
> kernel/signal.c       | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/include/linux/sched.h b/include/linux/sched.h
>index b511e178a89f..7a351360ad54 100644
>--- a/include/linux/sched.h
>+++ b/include/linux/sched.h
>@@ -918,7 +918,7 @@ struct task_struct {
> 
> 	/* Signal handlers: */
> 	struct signal_struct		*signal;
>-	struct sighand_struct		*sighand;
>+	struct sighand_struct __rcu		*sighand;
> 	sigset_t			blocked;
> 	sigset_t			real_blocked;
> 	/* Restored if set_restore_sigmask() was used: */
>diff --git a/kernel/signal.c b/kernel/signal.c
>index bcd46f547db3..9ad8dea93dbb 100644
>--- a/kernel/signal.c
>+++ b/kernel/signal.c
>@@ -1383,7 +1383,7 @@ struct sighand_struct *__lock_task_sighand(struct
>task_struct *tsk,
> 		 * must see ->sighand == NULL.
> 		 */
> 		spin_lock_irqsave(&sighand->siglock, *flags);
>-		if (likely(sighand == tsk->sighand))
>+		if (likely(sighand == rcu_access_pointer(tsk->sighand)))
> 			break;
> 		spin_unlock_irqrestore(&sighand->siglock, *flags);
> 	}

If Paul is happy with this and nobody wants to take it I'll pick this up.

Thanks!
Christian
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH] sched.h: Annotate sighand_struct with __rcu
  2020-01-25 21:41 ` Christian Brauner
@ 2020-01-26  1:23   ` Paul E. McKenney
  0 siblings, 0 replies; 10+ messages in thread
From: Paul E. McKenney @ 2020-01-26  1:23 UTC (permalink / raw)
  To: Christian Brauner
  Cc: juri.lelli, vincent.guittot, peterz, oleg, linux-kernel, rcu,
	madhuparnabhowmik10, mingo, ebiederm, joel, linux-kernel-mentees

On Sat, Jan 25, 2020 at 10:41:06PM +0100, Christian Brauner wrote:
> On January 24, 2020 5:59:08 AM GMT+01:00, madhuparnabhowmik10@gmail.com wrote:
> >From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
> >
> >This patch fixes the following sparse errors by annotating the
> >sighand_struct with __rcu
> >
> >kernel/fork.c:1511:9: error: incompatible types in comparison
> >expression
> >kernel/exit.c:100:19: error: incompatible types in comparison
> >expression
> >kernel/signal.c:1370:27: error: incompatible types in comparison
> >expression
> >
> >This fix introduces the following sparse error in signal.c due to
> >checking the sighand pointer without rcu primitives:
> >
> >kernel/signal.c:1386:21: error: incompatible types in comparison
> >expression
> >
> >This new sparse error is also fixed in this patch.
> >
> >Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>

Acked-by: Paul E. McKenney <paulmck@kernel.org>

> >---
> > include/linux/sched.h | 2 +-
> > kernel/signal.c       | 2 +-
> > 2 files changed, 2 insertions(+), 2 deletions(-)
> >
> >diff --git a/include/linux/sched.h b/include/linux/sched.h
> >index b511e178a89f..7a351360ad54 100644
> >--- a/include/linux/sched.h
> >+++ b/include/linux/sched.h
> >@@ -918,7 +918,7 @@ struct task_struct {
> > 
> > 	/* Signal handlers: */
> > 	struct signal_struct		*signal;
> >-	struct sighand_struct		*sighand;
> >+	struct sighand_struct __rcu		*sighand;
> > 	sigset_t			blocked;
> > 	sigset_t			real_blocked;
> > 	/* Restored if set_restore_sigmask() was used: */
> >diff --git a/kernel/signal.c b/kernel/signal.c
> >index bcd46f547db3..9ad8dea93dbb 100644
> >--- a/kernel/signal.c
> >+++ b/kernel/signal.c
> >@@ -1383,7 +1383,7 @@ struct sighand_struct *__lock_task_sighand(struct
> >task_struct *tsk,
> > 		 * must see ->sighand == NULL.
> > 		 */
> > 		spin_lock_irqsave(&sighand->siglock, *flags);
> >-		if (likely(sighand == tsk->sighand))
> >+		if (likely(sighand == rcu_access_pointer(tsk->sighand)))
> > 			break;
> > 		spin_unlock_irqrestore(&sighand->siglock, *flags);
> > 	}
> 
> If Paul is happy with this and nobody wants to take it I'll pick this up.

Works for me!

							Thanx, Paul
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH] sched.h: Annotate sighand_struct with __rcu
  2020-01-24  4:59 [Linux-kernel-mentees] [PATCH] sched.h: Annotate sighand_struct with __rcu madhuparnabhowmik10
  2020-01-25 21:41 ` Christian Brauner
@ 2020-01-27  9:29 ` Oleg Nesterov
  2020-01-27 12:23   ` Christian Brauner
  2020-01-27 17:14   ` Madhuparna Bhowmik
  1 sibling, 2 replies; 10+ messages in thread
From: Oleg Nesterov @ 2020-01-27  9:29 UTC (permalink / raw)
  To: madhuparnabhowmik10
  Cc: juri.lelli, vincent.guittot, paulmck, peterz, linux-kernel, rcu,
	mingo, ebiederm, joel, christian.brauner, linux-kernel-mentees

On 01/24, madhuparnabhowmik10@gmail.com wrote:
>
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -918,7 +918,7 @@ struct task_struct {
>  
>  	/* Signal handlers: */
>  	struct signal_struct		*signal;
> -	struct sighand_struct		*sighand;
> +	struct sighand_struct __rcu		*sighand;
>  	sigset_t			blocked;
>  	sigset_t			real_blocked;
>  	/* Restored if set_restore_sigmask() was used: */
> diff --git a/kernel/signal.c b/kernel/signal.c
> index bcd46f547db3..9ad8dea93dbb 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -1383,7 +1383,7 @@ struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
>  		 * must see ->sighand == NULL.
>  		 */
>  		spin_lock_irqsave(&sighand->siglock, *flags);
> -		if (likely(sighand == tsk->sighand))
> +		if (likely(sighand == rcu_access_pointer(tsk->sighand)))
>  			break;
>  		spin_unlock_irqrestore(&sighand->siglock, *flags);
>  	}

ACK,

perhaps you can also cleanup copy_sighand(). rcu_assign_pointer() makes no
sense, we should either move it down or simply use RCU_INIT_POINTER().

Oleg.

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH] sched.h: Annotate sighand_struct with __rcu
  2020-01-27  9:29 ` Oleg Nesterov
@ 2020-01-27 12:23   ` Christian Brauner
  2020-01-27 17:14   ` Madhuparna Bhowmik
  1 sibling, 0 replies; 10+ messages in thread
From: Christian Brauner @ 2020-01-27 12:23 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: juri.lelli, vincent.guittot, paulmck, peterz, linux-kernel, rcu,
	madhuparnabhowmik10, mingo, ebiederm, joel, linux-kernel-mentees

On Mon, Jan 27, 2020 at 10:29:52AM +0100, Oleg Nesterov wrote:
> On 01/24, madhuparnabhowmik10@gmail.com wrote:
> >
> > --- a/include/linux/sched.h
> > +++ b/include/linux/sched.h
> > @@ -918,7 +918,7 @@ struct task_struct {
> >  
> >  	/* Signal handlers: */
> >  	struct signal_struct		*signal;
> > -	struct sighand_struct		*sighand;
> > +	struct sighand_struct __rcu		*sighand;
> >  	sigset_t			blocked;
> >  	sigset_t			real_blocked;
> >  	/* Restored if set_restore_sigmask() was used: */
> > diff --git a/kernel/signal.c b/kernel/signal.c
> > index bcd46f547db3..9ad8dea93dbb 100644
> > --- a/kernel/signal.c
> > +++ b/kernel/signal.c
> > @@ -1383,7 +1383,7 @@ struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
> >  		 * must see ->sighand == NULL.
> >  		 */
> >  		spin_lock_irqsave(&sighand->siglock, *flags);
> > -		if (likely(sighand == tsk->sighand))
> > +		if (likely(sighand == rcu_access_pointer(tsk->sighand)))
> >  			break;
> >  		spin_unlock_irqrestore(&sighand->siglock, *flags);
> >  	}
> 
> ACK,

Applied.

Thanks Paul and Oleg!
Christian
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH] sched.h: Annotate sighand_struct with __rcu
  2020-01-27  9:29 ` Oleg Nesterov
  2020-01-27 12:23   ` Christian Brauner
@ 2020-01-27 17:14   ` Madhuparna Bhowmik
  1 sibling, 0 replies; 10+ messages in thread
From: Madhuparna Bhowmik @ 2020-01-27 17:14 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: juri.lelli, vincent.guittot, paulmck, peterz, linux-kernel, rcu,
	madhuparnabhowmik10, mingo, ebiederm, joel, christian.brauner,
	linux-kernel-mentees

On Mon, Jan 27, 2020 at 10:29:52AM +0100, Oleg Nesterov wrote:
> On 01/24, madhuparnabhowmik10@gmail.com wrote:
> >
> > --- a/include/linux/sched.h
> > +++ b/include/linux/sched.h
> > @@ -918,7 +918,7 @@ struct task_struct {
> >  
> >  	/* Signal handlers: */
> >  	struct signal_struct		*signal;
> > -	struct sighand_struct		*sighand;
> > +	struct sighand_struct __rcu		*sighand;
> >  	sigset_t			blocked;
> >  	sigset_t			real_blocked;
> >  	/* Restored if set_restore_sigmask() was used: */
> > diff --git a/kernel/signal.c b/kernel/signal.c
> > index bcd46f547db3..9ad8dea93dbb 100644
> > --- a/kernel/signal.c
> > +++ b/kernel/signal.c
> > @@ -1383,7 +1383,7 @@ struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
> >  		 * must see ->sighand == NULL.
> >  		 */
> >  		spin_lock_irqsave(&sighand->siglock, *flags);
> > -		if (likely(sighand == tsk->sighand))
> > +		if (likely(sighand == rcu_access_pointer(tsk->sighand)))
> >  			break;
> >  		spin_unlock_irqrestore(&sighand->siglock, *flags);
> >  	}
> 
> ACK,
> 
> perhaps you can also cleanup copy_sighand(). rcu_assign_pointer() makes no
> sense, we should either move it down or simply use RCU_INIT_POINTER().
> 
Sure, I will do it and send a patch soon.

Thank you,
Madhuparna

> Oleg.
> 
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH] sched.h: Annotate sighand_struct with __rcu
  2020-01-23 16:41 ` Paul E. McKenney
@ 2020-01-24  4:28   ` Madhuparna Bhowmik
  0 siblings, 0 replies; 10+ messages in thread
From: Madhuparna Bhowmik @ 2020-01-24  4:28 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: juri.lelli, vincent.guittot, peterz, oleg, linux-kernel, rcu,
	madhuparnabhowmik10, mingo, ebiederm, joel, christian.brauner,
	linux-kernel-mentees

On Thu, Jan 23, 2020 at 08:41:08AM -0800, Paul E. McKenney wrote:
> On Thu, Jan 23, 2020 at 08:23:05PM +0530, madhuparnabhowmik10@gmail.com wrote:
> > From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
> > 
> > This patch fixes the following sparse errors by annotating the
> > sighand_struct with __rcu
> > 
> > kernel/fork.c:1511:9: error: incompatible types in comparison expression
> > kernel/exit.c:100:19: error: incompatible types in comparison expression
> > kernel/signal.c:1370:27: error: incompatible types in comparison expression
> > 
> > This fix introduces the following sparse error in signal.c due to
> > checking the sighand pointer without rcu primitives:
> > 
> > kernel/signal.c:1386:21: error: incompatible types in comparison expression
> > 
> > This new sparse error is also addressed in this patch.
> > 
> > Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
> > ---
> >  include/linux/sched.h | 2 +-
> >  kernel/signal.c       | 3 ++-
> >  2 files changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/include/linux/sched.h b/include/linux/sched.h
> > index b511e178a89f..7a351360ad54 100644
> > --- a/include/linux/sched.h
> > +++ b/include/linux/sched.h
> > @@ -918,7 +918,7 @@ struct task_struct {
> >  
> >  	/* Signal handlers: */
> >  	struct signal_struct		*signal;
> > -	struct sighand_struct		*sighand;
> > +	struct sighand_struct __rcu		*sighand;
> >  	sigset_t			blocked;
> >  	sigset_t			real_blocked;
> >  	/* Restored if set_restore_sigmask() was used: */
> > diff --git a/kernel/signal.c b/kernel/signal.c
> > index bcd46f547db3..1272def37462 100644
> > --- a/kernel/signal.c
> > +++ b/kernel/signal.c
> > @@ -1383,7 +1383,8 @@ struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
> >  		 * must see ->sighand == NULL.
> >  		 */
> >  		spin_lock_irqsave(&sighand->siglock, *flags);
> > -		if (likely(sighand == tsk->sighand))
> > +		if (likely(sighand == rcu_dereference_protected(tsk->sighand,
> > +						lockdep_is_held(&sighand->siglock))))
> 
> Given that the return value is never dereferenced, you can use
> rcu_access_pointer(), which may be used outside of an RCU read-side
> critical section, and thus does not need the lockdep_is_held().  So this
> change would save a line of code and would be a bit easier on the eyes.
>
Okay got it! I will send the updated patch soon.

Thank you,
Madhuparna
> 							Thanx, Paul
> 
> >  			break;
> >  		spin_unlock_irqrestore(&sighand->siglock, *flags);
> >  	}
> > -- 
> > 2.17.1
> > 
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH] sched.h: Annotate sighand_struct with __rcu
  2020-01-23 14:53 madhuparnabhowmik10
@ 2020-01-23 16:41 ` Paul E. McKenney
  2020-01-24  4:28   ` Madhuparna Bhowmik
  0 siblings, 1 reply; 10+ messages in thread
From: Paul E. McKenney @ 2020-01-23 16:41 UTC (permalink / raw)
  To: madhuparnabhowmik10
  Cc: juri.lelli, vincent.guittot, peterz, oleg, linux-kernel, rcu,
	mingo, ebiederm, joel, christian.brauner, linux-kernel-mentees

On Thu, Jan 23, 2020 at 08:23:05PM +0530, madhuparnabhowmik10@gmail.com wrote:
> From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
> 
> This patch fixes the following sparse errors by annotating the
> sighand_struct with __rcu
> 
> kernel/fork.c:1511:9: error: incompatible types in comparison expression
> kernel/exit.c:100:19: error: incompatible types in comparison expression
> kernel/signal.c:1370:27: error: incompatible types in comparison expression
> 
> This fix introduces the following sparse error in signal.c due to
> checking the sighand pointer without rcu primitives:
> 
> kernel/signal.c:1386:21: error: incompatible types in comparison expression
> 
> This new sparse error is also addressed in this patch.
> 
> Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
> ---
>  include/linux/sched.h | 2 +-
>  kernel/signal.c       | 3 ++-
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index b511e178a89f..7a351360ad54 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -918,7 +918,7 @@ struct task_struct {
>  
>  	/* Signal handlers: */
>  	struct signal_struct		*signal;
> -	struct sighand_struct		*sighand;
> +	struct sighand_struct __rcu		*sighand;
>  	sigset_t			blocked;
>  	sigset_t			real_blocked;
>  	/* Restored if set_restore_sigmask() was used: */
> diff --git a/kernel/signal.c b/kernel/signal.c
> index bcd46f547db3..1272def37462 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -1383,7 +1383,8 @@ struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
>  		 * must see ->sighand == NULL.
>  		 */
>  		spin_lock_irqsave(&sighand->siglock, *flags);
> -		if (likely(sighand == tsk->sighand))
> +		if (likely(sighand == rcu_dereference_protected(tsk->sighand,
> +						lockdep_is_held(&sighand->siglock))))

Given that the return value is never dereferenced, you can use
rcu_access_pointer(), which may be used outside of an RCU read-side
critical section, and thus does not need the lockdep_is_held().  So this
change would save a line of code and would be a bit easier on the eyes.

							Thanx, Paul

>  			break;
>  		spin_unlock_irqrestore(&sighand->siglock, *flags);
>  	}
> -- 
> 2.17.1
> 
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH] sched.h: Annotate sighand_struct with __rcu
@ 2020-01-23 14:53 madhuparnabhowmik10
  2020-01-23 16:41 ` Paul E. McKenney
  0 siblings, 1 reply; 10+ messages in thread
From: madhuparnabhowmik10 @ 2020-01-23 14:53 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, ebiederm,
	christian.brauner, oleg, paulmck
  Cc: linux-kernel, rcu, Madhuparna Bhowmik, joel, linux-kernel-mentees

From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>

This patch fixes the following sparse errors by annotating the
sighand_struct with __rcu

kernel/fork.c:1511:9: error: incompatible types in comparison expression
kernel/exit.c:100:19: error: incompatible types in comparison expression
kernel/signal.c:1370:27: error: incompatible types in comparison expression

This fix introduces the following sparse error in signal.c due to
checking the sighand pointer without rcu primitives:

kernel/signal.c:1386:21: error: incompatible types in comparison expression

This new sparse error is also addressed in this patch.

Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
---
 include/linux/sched.h | 2 +-
 kernel/signal.c       | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index b511e178a89f..7a351360ad54 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -918,7 +918,7 @@ struct task_struct {
 
 	/* Signal handlers: */
 	struct signal_struct		*signal;
-	struct sighand_struct		*sighand;
+	struct sighand_struct __rcu		*sighand;
 	sigset_t			blocked;
 	sigset_t			real_blocked;
 	/* Restored if set_restore_sigmask() was used: */
diff --git a/kernel/signal.c b/kernel/signal.c
index bcd46f547db3..1272def37462 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1383,7 +1383,8 @@ struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
 		 * must see ->sighand == NULL.
 		 */
 		spin_lock_irqsave(&sighand->siglock, *flags);
-		if (likely(sighand == tsk->sighand))
+		if (likely(sighand == rcu_dereference_protected(tsk->sighand,
+						lockdep_is_held(&sighand->siglock))))
 			break;
 		spin_unlock_irqrestore(&sighand->siglock, *flags);
 	}
-- 
2.17.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH] sched.h: Annotate sighand_struct with __rcu
@ 2020-01-22 18:11 madhuparnabhowmik10
  0 siblings, 0 replies; 10+ messages in thread
From: madhuparnabhowmik10 @ 2020-01-22 18:11 UTC (permalink / raw)
  To: mingo, peterz
  Cc: paulmck, linux-kernel, rcu, Madhuparna Bhowmik, joel,
	linux-kernel-mentees

From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>

This patch fixes the following sparse errors:

kernel/fork.c:1511:9: error: incompatible types in comparison expression
kernel/exit.c:100:19: error: incompatible types in comparison expression
kernel/signal.c:1370:27: error: incompatible types in comparison expression

Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
---
 include/linux/sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index b511e178a89f..7a351360ad54 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -918,7 +918,7 @@ struct task_struct {
 
 	/* Signal handlers: */
 	struct signal_struct		*signal;
-	struct sighand_struct		*sighand;
+	struct sighand_struct __rcu		*sighand;
 	sigset_t			blocked;
 	sigset_t			real_blocked;
 	/* Restored if set_restore_sigmask() was used: */
-- 
2.17.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

end of thread, other threads:[~2020-01-27 17:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-24  4:59 [Linux-kernel-mentees] [PATCH] sched.h: Annotate sighand_struct with __rcu madhuparnabhowmik10
2020-01-25 21:41 ` Christian Brauner
2020-01-26  1:23   ` Paul E. McKenney
2020-01-27  9:29 ` Oleg Nesterov
2020-01-27 12:23   ` Christian Brauner
2020-01-27 17:14   ` Madhuparna Bhowmik
  -- strict thread matches above, loose matches on Subject: below --
2020-01-23 14:53 madhuparnabhowmik10
2020-01-23 16:41 ` Paul E. McKenney
2020-01-24  4:28   ` Madhuparna Bhowmik
2020-01-22 18:11 madhuparnabhowmik10

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).