linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matt Fleming <matt@console-pimps.org>
To: linux-arch@vger.kernel.org
Cc: Oleg Nesterov <oleg@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org,
	Matt Fleming <matt.fleming@intel.com>,
	Mikael Starvik <starvik@axis.com>,
	Jesper Nilsson <jesper.nilsson@axis.com>,
	linux-cris-kernel@axis.com
Subject: [PATCH 08/40] cris: Use set_current_blocked() and block_sigmask()
Date: Tue, 14 Feb 2012 11:40:41 +0000	[thread overview]
Message-ID: <1329219673-28711-9-git-send-email-matt@console-pimps.org> (raw)
In-Reply-To: <1329219673-28711-1-git-send-email-matt@console-pimps.org>

From: Matt Fleming <matt.fleming@intel.com>

As described in e6fa16ab ("signal: sigprocmask() should do
retarget_shared_pending()") the modification of current->blocked is
incorrect as we need to check whether the signal we're about to block
is pending in the shared queue.

Also, use the new helper function introduced in commit 5e6292c0f28f
("signal: add block_sigmask() for adding sigmask to current->blocked")
which centralises the code for updating current->blocked after
successfully delivering a signal and reduces the amount of duplicate
code across architectures. In the past some architectures got this
code wrong, so using this helper function should stop that from
happening again.

Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Mikael Starvik <starvik@axis.com>
Cc: Jesper Nilsson <jesper.nilsson@axis.com>
Cc: linux-cris-kernel@axis.com
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
---
 arch/cris/arch-v10/kernel/signal.c |   34 +++++++++++---------------------
 arch/cris/arch-v32/kernel/signal.c |   37 ++++++++++-------------------------
 2 files changed, 23 insertions(+), 48 deletions(-)

diff --git a/arch/cris/arch-v10/kernel/signal.c b/arch/cris/arch-v10/kernel/signal.c
index e78fe49..a6e1ff0 100644
--- a/arch/cris/arch-v10/kernel/signal.c
+++ b/arch/cris/arch-v10/kernel/signal.c
@@ -50,12 +50,14 @@ void do_signal(int canrestart, struct pt_regs *regs);
 int sys_sigsuspend(old_sigset_t mask, long r11, long r12, long r13, long mof,
 	long srp, struct pt_regs *regs)
 {
-	mask &= _BLOCKABLE;
-	spin_lock_irq(&current->sighand->siglock);
+	sigset_t blocked;
+
 	current->saved_sigmask = current->blocked;
-	siginitset(&current->blocked, mask);
-	recalc_sigpending();
-	spin_unlock_irq(&current->sighand->siglock);
+
+	mask &= _BLOCKABLE;
+	siginitset(&blocked, mask);
+	set_current_blocked(&blocked);
+
 	current->state = TASK_INTERRUPTIBLE;
 	schedule();
 	set_thread_flag(TIF_RESTORE_SIGMASK);
@@ -184,10 +186,7 @@ asmlinkage int sys_sigreturn(long r10, long r11, long r12, long r13, long mof,
 		goto badframe;
 
 	sigdelsetmask(&set, ~_BLOCKABLE);
-	spin_lock_irq(&current->sighand->siglock);
-	current->blocked = set;
-	recalc_sigpending();
-	spin_unlock_irq(&current->sighand->siglock);
+	set_current_blocked(&set);
 
 	if (restore_sigcontext(regs, &frame->sc))
 		goto badframe;
@@ -223,10 +222,7 @@ asmlinkage int sys_rt_sigreturn(long r10, long r11, long r12, long r13,
 		goto badframe;
 
 	sigdelsetmask(&set, ~_BLOCKABLE);
-	spin_lock_irq(&current->sighand->siglock);
-	current->blocked = set;
-	recalc_sigpending();
-	spin_unlock_irq(&current->sighand->siglock);
+	set_current_blocked(&set);
 
 	if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
 		goto badframe;
@@ -468,15 +464,9 @@ static inline int handle_signal(int canrestart, unsigned long sig,
 	else
 		ret = setup_frame(sig, ka, oldset, regs);
 
-	if (ret == 0) {
-		spin_lock_irq(&current->sighand->siglock);
-		sigorsets(&current->blocked, &current->blocked,
-			&ka->sa.sa_mask);
-		if (!(ka->sa.sa_flags & SA_NODEFER))
-			sigaddset(&current->blocked, sig);
-		recalc_sigpending();
-		spin_unlock_irq(&current->sighand->siglock);
-	}
+	if (ret == 0)
+		block_sigmask(ka, sig);
+
 	return ret;
 }
 
diff --git a/arch/cris/arch-v32/kernel/signal.c b/arch/cris/arch-v32/kernel/signal.c
index ce4ab1a..e7ea1ea 100644
--- a/arch/cris/arch-v32/kernel/signal.c
+++ b/arch/cris/arch-v32/kernel/signal.c
@@ -62,12 +62,14 @@ int
 sys_sigsuspend(old_sigset_t mask, long r11, long r12, long r13, long mof,
 	       long srp, struct pt_regs *regs)
 {
-	mask &= _BLOCKABLE;
-	spin_lock_irq(&current->sighand->siglock);
+	sigset_t blocked;
+
 	current->saved_sigmask = current->blocked;
-	siginitset(&current->blocked, mask);
-	recalc_sigpending();
-	spin_unlock_irq(&current->sighand->siglock);
+
+	mask &= _BLOCKABLE;
+	siginitset(&blocked, mask);
+	set_current_blocked(&blocked);
+
 	current->state = TASK_INTERRUPTIBLE;
 	schedule();
 	set_thread_flag(TIF_RESTORE_SIGMASK);
@@ -176,12 +178,7 @@ sys_sigreturn(long r10, long r11, long r12, long r13, long mof, long srp,
 		goto badframe;
 
 	sigdelsetmask(&set, ~_BLOCKABLE);
-	spin_lock_irq(&current->sighand->siglock);
-
-	current->blocked = set;
-
-	recalc_sigpending();
-	spin_unlock_irq(&current->sighand->siglock);
+	set_current_blocked(&set);
 
 	if (restore_sigcontext(regs, &frame->sc))
 		goto badframe;
@@ -222,12 +219,7 @@ sys_rt_sigreturn(long r10, long r11, long r12, long r13, long mof, long srp,
 		goto badframe;
 
 	sigdelsetmask(&set, ~_BLOCKABLE);
-	spin_lock_irq(&current->sighand->siglock);
-
-	current->blocked = set;
-
-	recalc_sigpending();
-	spin_unlock_irq(&current->sighand->siglock);
+	set_current_blocked(&set);
 
 	if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
 		goto badframe;
@@ -515,15 +507,8 @@ handle_signal(int canrestart, unsigned long sig,
 	if (ka->sa.sa_flags & SA_ONESHOT)
 		ka->sa.sa_handler = SIG_DFL;
 
-	if (ret == 0) {
-		spin_lock_irq(&current->sighand->siglock);
-		sigorsets(&current->blocked, &current->blocked,
-			&ka->sa.sa_mask);
-		if (!(ka->sa.sa_flags & SA_NODEFER))
-			sigaddset(&current->blocked, sig);
-		recalc_sigpending();
-		spin_unlock_irq(&current->sighand->siglock);
-	}
+	if (ret == 0)
+		block_sigmask(ka, sig);
 
 	return ret;
 }
-- 
1.7.4.4

  parent reply	other threads:[~2012-02-14 11:40 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-14 11:40 [PATCH 00/40] arch: set_current_blocked() and block_sigmask() Matt Fleming
2012-02-14 11:40 ` [PATCH 01/40] alpha: Use " Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 02/40] arm: " Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 03/40] avr32: Don't mask signals in the error path Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 04/40] avr32: use set_current_blocked() in handle_signal/sys_rt_sigreturn Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 05/40] avr32: Use block_sigmask() Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 06/40] blackfin: Use set_current_blocked() and block_sigmask() Matt Fleming
2012-02-16  9:28   ` Bob Liu
2012-02-14 11:40 ` [PATCH 07/40] C6X: " Matt Fleming
2012-02-14 11:40 ` Matt Fleming [this message]
2012-02-14 11:40   ` [PATCH 08/40] cris: " Matt Fleming
2012-02-15  8:43   ` Jesper Nilsson
2012-02-14 11:40 ` [PATCH 09/40] frv: " Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 10/40] h8300: " Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 11/40] Hexagon: " Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 12/40] ia64: " Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 13/40] m32r: " Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 14/40] m68k: " Matt Fleming
2012-02-14 11:40 ` [PATCH 15/40] microblaze: Don't reimplement force_sigsegv() Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 16/40] microblaze: No need to reset handler if SA_ONESHOT Matt Fleming
2012-02-14 11:40 ` [PATCH 17/40] microblaze: Fix signal masking Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 18/40] microblaze: Use set_current_blocked() and block_sigmask() Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 19/40] MIPS: " Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 20/40] mn10300: " Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 21/40] OpenRISC: Don't reimplement force_sigsegv() Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-15 15:40   ` Jonas Bonn
2012-02-15 15:40     ` Jonas Bonn
2012-02-15 15:49     ` Matt Fleming
2012-02-15 15:57       ` Jonas Bonn
2012-02-15 15:57         ` Jonas Bonn
2012-02-14 11:40 ` [PATCH 22/40] OpenRISC: No need to reset handler if SA_ONESHOT Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 23/40] OpenRISC: Don't mask signals if we fail to setup signal stack Matt Fleming
2012-02-14 11:40 ` [PATCH 24/40] OpenRISC: Use set_current_blocked() and block_sigmask() Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:40 ` [PATCH 25/40] parisc: " Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-04-06 14:59   ` Kyle McMartin
2012-02-14 11:40 ` [PATCH 26/40] powerpc: " Matt Fleming
2012-02-14 11:40   ` Matt Fleming
2012-02-14 11:41 ` [PATCH 27/40] [S390] Use block_sigmask() Matt Fleming
2012-02-14 11:41   ` Matt Fleming
2012-02-14 11:41 ` [PATCH 28/40] score: Don't mask signals if we fail to setup signal stack Matt Fleming
2012-02-14 11:41   ` Matt Fleming
2012-02-14 11:41 ` [PATCH 29/40] score: Use set_current_blocked() and block_sigmask() Matt Fleming
2012-02-14 11:41   ` Matt Fleming
2012-02-14 11:41 ` [PATCH 30/40] sh: No need to reset handler if SA_ONESHOT Matt Fleming
2012-02-14 11:41   ` Matt Fleming
2012-02-14 11:41 ` [PATCH 31/40] sh: Use set_current_blocked() and block_sigmask() Matt Fleming
2012-02-14 11:41   ` Matt Fleming
2012-02-14 11:41 ` [PATCH 32/40] sparc: Use block_sigmask() Matt Fleming
2012-02-14 11:41   ` Matt Fleming
2012-02-15  3:57   ` David Miller
2012-02-15  3:57     ` David Miller
2012-02-14 11:41 ` [PATCH 33/40] tile: Use set_current_blocked() and block_sigmask() Matt Fleming
2012-02-14 11:41   ` Matt Fleming
2012-02-14 11:41 ` [PATCH 34/40] um: Don't restore current->blocked on error Matt Fleming
2012-02-14 11:41   ` Matt Fleming
2012-02-14 11:41 ` [PATCH 35/40] um: Use set_current_blocked() and block_sigmask() Matt Fleming
2012-02-14 11:41   ` Matt Fleming
2012-02-14 11:41 ` [PATCH 36/40] unicore32: Use block_sigmask() Matt Fleming
2012-02-14 11:41   ` Matt Fleming
2012-02-14 11:41 ` [PATCH 37/40] xtensa: Don't reimplement force_sigsegv() Matt Fleming
2012-02-14 11:41   ` Matt Fleming
2012-02-14 11:41 ` [PATCH 38/40] xtensa: No need to reset handler if SA_ONESHOT Matt Fleming
2012-02-14 11:41   ` Matt Fleming
2012-02-14 11:41 ` [PATCH 39/40] xtensa: Don't mask signals if we fail to setup signal stack Matt Fleming
2012-02-14 11:41   ` Matt Fleming
2012-02-14 11:41 ` [PATCH 40/40] xtensa: Use set_current_blocked() and block_sigmask() Matt Fleming
2012-02-14 11:41   ` Matt Fleming
2012-02-14 13:45 ` [PATCH 00/40] arch: " Mark Salter
2012-02-14 13:52   ` Matt Fleming
2012-02-14 13:58     ` Mark Salter
2012-02-14 14:08       ` Matt Fleming
2012-02-14 15:56 ` [PATCH 20/40] mn10300: Use " David Howells
2012-02-14 17:23   ` Oleg Nesterov
2012-02-14 17:59   ` Matt Fleming
2012-02-14 18:12   ` David Howells
2012-02-14 18:24     ` Oleg Nesterov
2012-02-14 18:30   ` David Howells
2012-02-14 18:30     ` David Howells
2012-02-15 11:49     ` Matt Fleming
2012-02-14 17:32 ` [PATCH 00/40] arch: " Oleg Nesterov
2012-02-15 11:47   ` Matt Fleming
2012-02-15 11:47     ` Matt Fleming

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=1329219673-28711-9-git-send-email-matt@console-pimps.org \
    --to=matt@console-pimps.org \
    --cc=akpm@linux-foundation.org \
    --cc=jesper.nilsson@axis.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-cris-kernel@axis.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt.fleming@intel.com \
    --cc=oleg@redhat.com \
    --cc=starvik@axis.com \
    /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 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).