From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Peter Zijlstra <peterz@infradead.org>,
Rik van Riel <riel@redhat.com>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] signal: simplify deadlock-avoidance in lock_task_sighand()
Date: Mon, 22 Sep 2014 18:44:37 +0200 [thread overview]
Message-ID: <20140922164437.GA28939@redhat.com> (raw)
In-Reply-To: <20140922164404.GA28910@redhat.com>
__lock_task_sighand() does local_irq_save() to prevent the potential
deadlock, we can use preempt_disable() with the same effect. And in
this case we can do preempt_disable/enable + rcu_read_lock/unlock only
once outside of the main loop and simplify the code. This also shaves
112 bytes from signal.o.
With this patch the main loop runs with preemption disabled, but this
should be fine because restart is very unlikely: it can only happen if
we race with de_thread() and ->sighand is shared. And the latter is only
possible if CLONE_SIGHAND was used without CLONE_THREAD, most probably
nobody does this nowadays.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/signal.c | 31 +++++++++++++------------------
1 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/kernel/signal.c b/kernel/signal.c
index 8f0876f..61a1f55 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1261,30 +1261,25 @@ struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
unsigned long *flags)
{
struct sighand_struct *sighand;
-
+ /*
+ * We are going to do rcu_read_unlock() under spin_lock_irqsave().
+ * Make sure we can not be preempted after rcu_read_lock(), see
+ * rcu_read_unlock() comment header for details.
+ */
+ preempt_disable();
+ rcu_read_lock();
for (;;) {
- /*
- * Disable interrupts early to avoid deadlocks.
- * See rcu_read_unlock() comment header for details.
- */
- local_irq_save(*flags);
- rcu_read_lock();
sighand = rcu_dereference(tsk->sighand);
- if (unlikely(sighand == NULL)) {
- rcu_read_unlock();
- local_irq_restore(*flags);
+ if (unlikely(sighand == NULL))
break;
- }
- spin_lock(&sighand->siglock);
- if (likely(sighand == tsk->sighand)) {
- rcu_read_unlock();
+ spin_lock_irqsave(&sighand->siglock, *flags);
+ if (likely(sighand == tsk->sighand))
break;
- }
- spin_unlock(&sighand->siglock);
- rcu_read_unlock();
- local_irq_restore(*flags);
+ spin_unlock_irqrestore(&sighand->siglock, *flags);
}
+ rcu_read_unlock();
+ preempt_enable();
return sighand;
}
--
1.5.5.1
next prev parent reply other threads:[~2014-09-22 16:47 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-22 16:44 [PATCH 0/2] signal: simplify/document lock_task_sighand() logic Oleg Nesterov
2014-09-22 16:44 ` Oleg Nesterov [this message]
2014-09-22 18:58 ` [PATCH 1/2] signal: simplify deadlock-avoidance in lock_task_sighand() Steven Rostedt
2014-09-22 19:11 ` Oleg Nesterov
2014-09-22 21:24 ` Steven Rostedt
2014-09-23 11:45 ` Rik van Riel
2014-09-23 14:20 ` Peter Zijlstra
2014-09-23 14:30 ` Steven Rostedt
2014-09-23 19:03 ` Oleg Nesterov
2014-09-24 8:36 ` Paul E. McKenney
2014-09-23 15:55 ` Peter Zijlstra
2014-09-22 16:44 ` [PATCH 2/2] signal: document the RCU protection of ->sighand Oleg Nesterov
2014-09-22 19:00 ` Steven Rostedt
2014-09-23 11:50 ` Rik van Riel
2014-09-28 21:43 ` [PATCH v2 0/2] document ->sighand protection, rcu_read_unlock() deadlocks Oleg Nesterov
2014-09-28 21:44 ` [PATCH v2 1/2] signal: document the RCU protection of ->sighand Oleg Nesterov
2014-09-28 21:44 ` [PATCH v2 2/2] rcu: more info about potential deadlocks with rcu_read_unlock() Oleg Nesterov
2014-10-23 19:56 ` [PATCH v2 0/2] document ->sighand protection, rcu_read_unlock() deadlocks Oleg Nesterov
2014-10-23 20:29 ` Paul E. McKenney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140922164437.GA28939@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=riel@redhat.com \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.