mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Walt Drummond <walt@drummond.us>
To: unlisted-recipients:; (no To-header on input)
Cc: linux-kernel@vger.kernel.org, Walt Drummond <walt@drummond.us>,
	linux-fsdevel@vger.kernel.org
Subject: [RFC PATCH 5/8] signals: Better support cases where _NSIG_WORDS is greater than 2
Date: Mon,  3 Jan 2022 10:19:53 -0800	[thread overview]
Message-ID: <20220103181956.983342-6-walt@drummond.us> (raw)
In-Reply-To: <20220103181956.983342-1-walt@drummond.us>

Directly handle the now more common cases where _NSIG_WORDS could be 3
or 4.

Signed-off-by: Walt Drummond <walt@drummond.us>
---
 fs/proc/array.c        |  3 +-
 include/linux/signal.h | 74 +++++++++++++++++++++++++++---------------
 kernel/signal.c        |  5 +++
 3 files changed, 55 insertions(+), 27 deletions(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 49be8c8ef555..f37c03077b58 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -223,7 +223,8 @@ void render_sigset_t(struct seq_file *m, const char *header,
 
 	seq_puts(m, header);
 
-	i = _NSIG;
+	/* Round up when _NSIG isn't a multiple of 4 */
+	i = (_NSIG + 3) & ~0x03;
 	do {
 		int x = 0;
 
diff --git a/include/linux/signal.h b/include/linux/signal.h
index eaf7991fffee..4084b765a6cc 100644
--- a/include/linux/signal.h
+++ b/include/linux/signal.h
@@ -168,18 +168,22 @@ do {					        \
 static inline int sigequalsets(const sigset_t *set1, const sigset_t *set2)
 {
 	switch (_NSIG_WORDS) {
+	default:
+		return memcmp(set1, set2, sizeof(sigset_t)) == 0;
 	case 4:
 		return	(set1->sig[3] == set2->sig[3]) &&
 			(set1->sig[2] == set2->sig[2]) &&
 			(set1->sig[1] == set2->sig[1]) &&
 			(set1->sig[0] == set2->sig[0]);
+	case 3:
+		return  (set1->sig[2] == set2->sig[2]) &&
+			(set1->sig[1] == set2->sig[1]) &&
+			(set1->sig[0] == set2->sig[0]);
 	case 2:
 		return	(set1->sig[1] == set2->sig[1]) &&
 			(set1->sig[0] == set2->sig[0]);
 	case 1:
 		return	set1->sig[0] == set2->sig[0];
-	default:
-		return memcmp(set1, set2, sizeof(sigset_t)) == 0;
 	}
 	return 0;
 }
@@ -197,27 +201,24 @@ static inline int sigisemptyset(sigset_t *set)
 #define _SIG_SET_BINOP(name, op)					\
 static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
 {									\
-	unsigned long a0, a1, a2, a3, b0, b1, b2, b3;			\
 	int i;								\
 									\
 	switch (_NSIG_WORDS) {						\
+	default:							\
+		for (i = 0; i < _NSIG_WORDS; i++)			\
+			r->sig[i] = op(a->sig[i], b->sig[i]);		\
+		break;							\
 	case 4:								\
-		a3 = a->sig[3]; a2 = a->sig[2];				\
-		b3 = b->sig[3]; b2 = b->sig[2];				\
-		r->sig[3] = op(a3, b3);					\
-		r->sig[2] = op(a2, b2);					\
+		r->sig[3] = op(a->sig[3], b->sig[3]);			\
+		fallthrough;						\
+	case 3:								\
+		r->sig[2] = op(a->sig[2], b->sig[2]);			\
 		fallthrough;						\
 	case 2:								\
-		a1 = a->sig[1]; b1 = b->sig[1];				\
-		r->sig[1] = op(a1, b1);					\
+		r->sig[1] = op(a->sig[1], b->sig[1]);			\
 		fallthrough;						\
 	case 1:								\
-		a0 = a->sig[0]; b0 = b->sig[0];				\
-		r->sig[0] = op(a0, b0);					\
-		break;							\
-	default:							\
-		for (i = 0; i < _NSIG_WORDS; i++)			\
-			r->sig[i] = op(a->sig[i], b->sig[i]);		\
+		r->sig[0] = op(a->sig[0], b->sig[0]);			\
 		break;							\
 	}								\
 }
@@ -242,17 +243,22 @@ static inline void name(sigset_t *set)					\
 	int i;								\
 									\
 	switch (_NSIG_WORDS) {						\
-	case 4:	set->sig[3] = op(set->sig[3]);				\
-		set->sig[2] = op(set->sig[2]);				\
-		fallthrough;						\
-	case 2:	set->sig[1] = op(set->sig[1]);				\
-		fallthrough;						\
-	case 1:	set->sig[0] = op(set->sig[0]);				\
-		    break;						\
 	default:							\
 		for (i = 0; i < _NSIG_WORDS; i++)			\
 			set->sig[i] = op(set->sig[i]);			\
 		break;							\
+	case 4:								\
+		set->sig[3] = op(set->sig[3]);				\
+		fallthrough;						\
+	case 3:								\
+		set->sig[2] = op(set->sig[2]);				\
+		fallthrough;						\
+	case 2:								\
+		set->sig[1] = op(set->sig[1]);				\
+		fallthrough;						\
+	case 1:								\
+		set->sig[0] = op(set->sig[0]);				\
+		break;							\
 	}								\
 }
 
@@ -268,9 +274,17 @@ static inline void sigemptyset(sigset_t *set)
 	default:
 		memset(set, 0, sizeof(sigset_t));
 		break;
-	case 2: set->sig[1] = 0;
+	case 4:
+		set->sig[3] = 0;
+		fallthrough;
+	case 3:
+		set->sig[2] = 0;
 		fallthrough;
-	case 1:	set->sig[0] = 0;
+	case 2:
+		set->sig[1] = 0;
+		fallthrough;
+	case 1:
+		set->sig[0] = 0;
 		break;
 	}
 }
@@ -281,9 +295,17 @@ static inline void sigfillset(sigset_t *set)
 	default:
 		memset(set, -1, sizeof(sigset_t));
 		break;
-	case 2: set->sig[1] = -1;
+	case 4:
+		set->sig[3] = -1;
 		fallthrough;
-	case 1:	set->sig[0] = -1;
+	case 3:
+		set->sig[2] = -1;
+		fallthrough;
+	case 2:
+		set->sig[1] = -1;
+		fallthrough;
+	case 1:
+		set->sig[0] = -1;
 		break;
 	}
 }
diff --git a/kernel/signal.c b/kernel/signal.c
index 9421f1112b20..9c846a017201 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -143,6 +143,11 @@ static inline bool has_pending_signals(sigset_t *signal, sigset_t *blocked)
 		ready |= signal->sig[0] &~ blocked->sig[0];
 		break;
 
+	case 3: ready  = signal->sig[2] &~ blocked->sig[2];
+		ready |= signal->sig[1] &~ blocked->sig[1];
+		ready |= signal->sig[0] &~ blocked->sig[0];
+		break;
+
 	case 2: ready  = signal->sig[1] &~ blocked->sig[1];
 		ready |= signal->sig[0] &~ blocked->sig[0];
 		break;
-- 
2.30.2


  parent reply	other threads:[~2022-01-03 18:34 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-03 18:19 [RFC PATCH 0/8] signals: Support more than 64 signals Walt Drummond
2022-01-03 18:19 ` [RFC PATCH 1/8] signals: Make the real-time signal system calls accept different sized sigset_t from user space Walt Drummond
2022-01-03 18:19 ` [RFC PATCH 2/8] signals: Put the full signal mask on the signal stack for x86_64, X32 and ia32 compatibility mode Walt Drummond
2022-01-03 18:19 ` [RFC PATCH 3/8] signals: Use a helper function to test if a signal is a real-time signal Walt Drummond
2022-01-03 18:19 ` [RFC PATCH 4/8] signals: Remove sigmask() macro Walt Drummond
2022-01-03 18:19 ` Walt Drummond [this message]
2022-01-03 18:19 ` [RFC PATCH 6/8] signals: Round up _NSIG_WORDS Walt Drummond
2022-01-03 18:19 ` [RFC PATCH 7/8] signals: Add signal debugging Walt Drummond
2022-01-03 18:19 ` [RFC PATCH 8/8] signals: Support BSD VSTATUS, KERNINFO and SIGINFO Walt Drummond
2022-01-04  7:27   ` Greg Kroah-Hartman
2022-01-07 21:48   ` Arseny Maslennikov
2022-01-07 21:52     ` Walt Drummond
2022-01-07 22:39       ` Arseny Maslennikov
2022-01-08 14:38   ` Arseny Maslennikov
2022-01-03 18:48 ` [RFC PATCH 0/8] signals: Support more than 64 signals Al Viro
2022-01-04  1:00   ` Walt Drummond
2022-01-04  1:16     ` Al Viro
2022-01-04  1:49       ` Al Viro
2022-01-04 18:00 ` Eric W. Biederman
2022-01-04 20:52   ` Theodore Ts'o
2022-01-04 21:33     ` Walt Drummond
2022-01-04 22:05     ` Eric W. Biederman
2022-01-04 22:23       ` Theodore Ts'o
2022-01-04 22:31         ` Walt Drummond
2022-01-07 19:29           ` Arseny Maslennikov
2022-05-19 12:27             ` Pavel Machek
2022-01-07 19:19     ` Arseny Maslennikov

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=20220103181956.983342-6-walt@drummond.us \
    --to=walt@drummond.us \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®