From: Madhuparna Bhowmik <[email protected]>
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 <[email protected]>
---
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
On January 24, 2020 5:59:08 AM GMT+01:00, [email protected] wrote:
>From: Madhuparna Bhowmik <[email protected]>
>
>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 <[email protected]>
>---
> 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
On Sat, Jan 25, 2020 at 10:41:06PM +0100, Christian Brauner wrote:
> On January 24, 2020 5:59:08 AM GMT+01:00, [email protected] wrote:
> >From: Madhuparna Bhowmik <[email protected]>
> >
> >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 <[email protected]>
Acked-by: Paul E. McKenney <[email protected]>
> >---
> > 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
On 01/24, [email protected] 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.
On Mon, Jan 27, 2020 at 10:29:52AM +0100, Oleg Nesterov wrote:
> On 01/24, [email protected] 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
On Mon, Jan 27, 2020 at 10:29:52AM +0100, Oleg Nesterov wrote:
> On 01/24, [email protected] 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.
>