login
Header Space

 
 

Re: [PATCH 2/4] set_restore_sigmask TIF_SIGPENDING

Previous thread: unexpected rename() behaviour by Ketil Froyn on Friday, March 28, 2008 - 8:07 pm. (5 messages)

Next thread: Re: sata io freeze, 2.6.18 and also 2.6.24 by Luis Sousa on Friday, March 28, 2008 - 8:22 pm. (1 message)
To: Andrew Morton <akpm@...>, Linus Torvalds <torvalds@...>
Cc: Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Friday, March 28, 2008 - 8:12 pm

This adds the set_restore_sigmask() inline in &lt;linux/thread_info.h&gt; and
replaces every set_thread_flag(TIF_RESTORE_SIGMASK) with a call to it.
No change, but abstracts the flag protocol details from all the calls.

Signed-off-by: Roland McGrath &lt;roland@redhat.com&gt;
---
 fs/compat.c                 |    6 +++---
 fs/eventpoll.c              |    3 +--
 fs/select.c                 |    4 ++--
 include/linux/thread_info.h |   15 ++++++++++++++-
 kernel/compat.c             |    3 +--
 kernel/signal.c             |    2 +-
 6 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/fs/compat.c b/fs/compat.c
index 2ce4456..9964d54 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -1720,7 +1720,7 @@ sticky:
 		if (sigmask) {
 			memcpy(&amp;current-&gt;saved_sigmask, &amp;sigsaved,
 					sizeof(sigsaved));
-			set_thread_flag(TIF_RESTORE_SIGMASK);
+			set_restore_sigmask();
 		}
 	} else if (sigmask)
 		sigprocmask(SIG_SETMASK, &amp;sigsaved, NULL);
@@ -1791,7 +1791,7 @@ asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds,
 		if (sigmask) {
 			memcpy(&amp;current-&gt;saved_sigmask, &amp;sigsaved,
 				sizeof(sigsaved));
-			set_thread_flag(TIF_RESTORE_SIGMASK);
+			set_restore_sigmask();
 		}
 		ret = -ERESTARTNOHAND;
 	} else if (sigmask)
@@ -2117,7 +2117,7 @@ asmlinkage long compat_sys_epoll_pwait(int epfd,
 		if (err == -EINTR) {
 			memcpy(&amp;current-&gt;saved_sigmask, &amp;sigsaved,
 			       sizeof(sigsaved));
-			set_thread_flag(TIF_RESTORE_SIGMASK);
+			set_restore_sigmask();
 		} else
 			sigprocmask(SIG_SETMASK, &amp;sigsaved, NULL);
 	}
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index a415f42..503ffa4 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1300,7 +1300,7 @@ asmlinkage long sys_epoll_pwait(int epfd, struct epoll_event __user *events,
 		if (error == -EINTR) {
 			memcpy(&amp;current-&gt;saved_sigmask, &amp;sigsaved,
 			       sizeof(sigsaved));
-			set_thread_flag(TIF_RESTORE_SIGMASK);
+			set_restore_sigmask();
 ...
To: Andrew Morton <akpm@...>, Linus Torvalds <torvalds@...>
Cc: Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Friday, March 28, 2008 - 8:14 pm

TIF_RESTORE_SIGMASK no longer needs to be in the _TIF_WORK_* masks.
Those low bits are scarce.  Renumber TIF_RESTORE_SIGMASK to free one up.

Signed-off-by: Roland McGrath &lt;roland@redhat.com&gt;
---
 arch/ia64/kernel/process.c     |    2 +-
 include/asm-ia64/thread_info.h |    5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index 49937a3..2ef2794 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -183,7 +183,7 @@ do_notify_resume_user (sigset_t *unused, struct sigscratch *scr, long in_syscall
 #endif
 
 	/* deal with pending signal delivery */
-	if (test_thread_flag(TIF_SIGPENDING)||test_thread_flag(TIF_RESTORE_SIGMASK))
+	if (test_thread_flag(TIF_SIGPENDING))
 		ia64_do_signal(scr, in_syscall);
 
 	/* copy user rbs to kernel rbs */
diff --git a/include/asm-ia64/thread_info.h b/include/asm-ia64/thread_info.h
index 93d83cb..366e517 100644
--- a/include/asm-ia64/thread_info.h
+++ b/include/asm-ia64/thread_info.h
@@ -87,7 +87,6 @@ extern void tsk_clear_notify_resume(struct task_struct *tsk);
 #define TIF_SYSCALL_TRACE	2	/* syscall trace active */
 #define TIF_SYSCALL_AUDIT	3	/* syscall auditing active */
 #define TIF_SINGLESTEP		4	/* restore singlestep on return to user mode */
-#define TIF_RESTORE_SIGMASK	5	/* restore signal mask in do_signal() */
 #define TIF_NOTIFY_RESUME	6	/* resumption notification requested */
 #define TIF_POLLING_NRFLAG	16	/* true if poll_idle() is polling TIF_NEED_RESCHED */
 #define TIF_MEMDIE		17
@@ -95,6 +94,7 @@ extern void tsk_clear_notify_resume(struct task_struct *tsk);
 #define TIF_DB_DISABLED		19	/* debug trap disabled for fsyscall */
 #define TIF_FREEZE		20	/* is freezing for suspend */
 #define TIF_RESTORE_RSE		21	/* user RBS is newer than kernel RBS */
+#define TIF_RESTORE_SIGMASK	22	/* restore signal mask in do_signal() */
 
 #define _TIF_SYSCALL_TRACE	(1 &lt;&lt; TIF_SYSCALL_TRACE)
 #define _TIF_SYSCALL_AUDIT	(1 &lt;&lt; TIF_SYSCAL...
To: Andrew Morton <akpm@...>, Linus Torvalds <torvalds@...>
Cc: Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Friday, March 28, 2008 - 8:14 pm

TIF_RESTORE_SIGMASK no longer needs to be in the _TIF_WORK_* masks.
Those low bits are scarce, and are all used up now.
Renumber TIF_RESTORE_SIGMASK to free one up.

Signed-off-by: Roland McGrath &lt;roland@redhat.com&gt;
---
 arch/s390/kernel/entry.S       |   14 +++++++-------
 arch/s390/kernel/entry64.S     |   12 ++++++------
 include/asm-s390/thread_info.h |    2 +-
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index 6766e37..bdbb3bc 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -49,9 +49,9 @@ SP_ILC	     =	STACK_FRAME_OVERHEAD + __PT_ILC
 SP_TRAP      =	STACK_FRAME_OVERHEAD + __PT_TRAP
 SP_SIZE      =	STACK_FRAME_OVERHEAD + __PT_SIZE
 
-_TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | _TIF_NEED_RESCHED | \
+_TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
 		 _TIF_MCCK_PENDING | _TIF_RESTART_SVC | _TIF_SINGLE_STEP )
-_TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | _TIF_NEED_RESCHED | \
+_TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
 		 _TIF_MCCK_PENDING)
 
 STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
@@ -316,7 +316,7 @@ sysc_work:
 	bo	BASED(sysc_mcck_pending)
 	tm	__TI_flags+3(%r9),_TIF_NEED_RESCHED
 	bo	BASED(sysc_reschedule)
-	tm	__TI_flags+3(%r9),(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)
+	tm	__TI_flags+3(%r9),_TIF_SIGPENDING
 	bnz	BASED(sysc_sigpending)
 	tm	__TI_flags+3(%r9),_TIF_RESTART_SVC
 	bo	BASED(sysc_restart)
@@ -342,7 +342,7 @@ sysc_mcck_pending:
 	br	%r1			# TIF bit will be cleared by handler
 
 #
-# _TIF_SIGPENDING or _TIF_RESTORE_SIGMASK is set, call do_signal
+# _TIF_SIGPENDING is set, call do_signal
 #
 sysc_sigpending:
 	ni	__TI_flags+3(%r9),255-_TIF_SINGLE_STEP # clear TIF_SINGLE_STEP
@@ -657,7 +657,7 @@ io_work:
 	lr	%r15,%r1
 #
 # One of the work bits is on. Find out which one.
-# Checked are: _TIF_SIGPENDING, _TIF_RESTORE_SIGMASK, _TIF_NEED_RESCHED
+# Checked are: _TIF_SIGPENDING, _TIF_NEED_RESCHED
 #		an...
To: Roland McGrath <roland@...>
Cc: Andrew Morton <akpm@...>, Linus Torvalds <torvalds@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Monday, March 31, 2008 - 3:53 am

Acked-by: Martin Schwidefsky &lt;schwidefsky@de.ibm.com&gt;

-- 
blue skies,
  Martin.

"Reality continues to ruin my life." - Calvin.


--
To: Andrew Morton <akpm@...>, Linus Torvalds <torvalds@...>
Cc: Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Friday, March 28, 2008 - 8:13 pm

Set TIF_SIGPENDING in set_restore_sigmask.  This lets arch code take
TIF_RESTORE_SIGMASK out of the set of bits that will be noticed on
return to user mode.  On some machines those bits are scarce, and we
can free this unneeded one up for other uses.

It is probably the case that TIF_SIGPENDING is always set anyway
everywhere set_restore_sigmask() is used.  But this is some cheap
paranoia in case there is an arcane case where it might not be.

Signed-off-by: Roland McGrath &lt;roland@redhat.com&gt;
---
 include/linux/thread_info.h |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index d82c073..4a89477 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -85,11 +85,17 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
  * set_restore_sigmask() - make sure saved_sigmask processing gets done
  *
  * This sets TIF_RESTORE_SIGMASK and ensures that the arch signal code
- * will run before returning to user mode, to process the flag.
+ * will run before returning to user mode, to process the flag.  For
+ * all callers, TIF_SIGPENDING is already set or it's no harm to set
+ * it.  TIF_RESTORE_SIGMASK need not be in the set of bits that the
+ * arch code will notice on return to user mode, in case those bits
+ * are scarce.  We set TIF_SIGPENDING here to ensure that the arch
+ * signal code always gets run when TIF_RESTORE_SIGMASK is set.
  */
 static inline void set_restore_sigmask(void)
 {
 	set_thread_flag(TIF_RESTORE_SIGMASK);
+	set_thread_flag(TIF_SIGPENDING);
 }
 #endif	/* TIF_RESTORE_SIGMASK */
 
--
To: Roland McGrath <roland@...>
Cc: Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Friday, March 28, 2008 - 8:53 pm

Hmm. That probably means that TIF_RESTORE_SIGMASK shouldn't be a "TIF" 
flag at all, but a "TS" ("thread status") flag.

The TS flags are faster, because they are thread-synchronous and do not 
need atomic accesses (ie they are purely thread-local in setting, testing 
and clearing).

Of course, it may well not be worth it. Unlike the TIF flags, the TS flags 
have been architecture-specific and I don't think all architectures even 
do them (x86 uses them for FP state bits and stuff like that).

I guess TIF_RESTORE_SIGMASK is never *so* performance-critical that we'd 
care about the difference between a single cycle (approx) for a non-atomic 
"or" into memory and an atomic bitop (~50 cycles or so). 

			Linus
--
To: Linus Torvalds <torvalds@...>
Cc: Roland McGrath <roland@...>, Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Tuesday, April 8, 2008 - 7:35 am

Roland, Linus, I'm sorry for being offtopic, but there is something
I can't understand from the very beginning, when TIF_RESTORE_SIGMASK
was introduced.



Why do we need any flag? It looks a bit ugly. Isn't it better to introduce
the new magic ERESTART_XXX which means ERESTARTNOHAND + restore-sigmask ?

We only need this flag as an implicit parameter to the arch dependent do_signal()
which we can't call directly, and thus it must imply TIF_SIGPENDING, and it
is not valid after do_signal() (should be cleared). This all looks like
ERESTART_ magic, why should we add something else ?

See also http://marc.info/?l=linux-kernel&amp;m=113734458516136

Of course, probably it is too late to change the implementation even if
I am right, the question is: what I am missed?

Oleg.

--
To: Oleg Nesterov <oleg@...>
Cc: Linus Torvalds <torvalds@...>, Roland McGrath <roland@...>, Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Wednesday, April 9, 2008 - 7:16 am

Q: When ppoll() is interrupted by a signal, what signal mask should be
active when the signal handler is active?

I believe that the signal handler should run with the temporary sigmask
which was set by ppoll(), and the original sigmask should be restored
only when the handler completes -- and that's what we achieve with
TIF_RESTORE_SIGMASK.

So a signal which was originally enabled but is temporarily disabled by
the mask passed to ppoll() will not be able to interrupt the handler for
the signal which interrupted ppoll().

Your version will restore the original signal mask _before_ invoking the
signal handler which interrupted ppoll() -- which I believe is not the
intended semantics. And IIRC that was the whole point in implementing
ppoll() in kernel rather than trying to emulate it in userspace in the
first place.

-- 
dwmw2

--
To: David Woodhouse <dwmw2@...>
Cc: Linus Torvalds <torvalds@...>, Roland McGrath <roland@...>, Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Wednesday, April 9, 2008 - 7:39 am

Why do you think so?

Please look at the "patch" below,

	--- arch/x86/kernel/signal_32.c	2008-02-15 16:58:38.000000000 +0300
	+++ -	2008-04-09 15:16:05.393510662 +0400
	@@ -526,10 +526,14 @@ handle_signal(unsigned long sig, siginfo
	 {
		int ret;
	 
	+	oldset = &amp;current-&gt;blocked;
	+
		/* Are we from a system call? */
		if (regs-&gt;orig_ax &gt;= 0) {
			/* If so, check system call restarting.. */
			switch (regs-&gt;ax) {
	+			case -ERESTART_XXX:
	+				oldset = &amp;current-&gt;saved_sigmask;
				case -ERESTART_RESTARTBLOCK:
				case -ERESTARTNOHAND:
					regs-&gt;ax = -EINTR;

We also need a similar change in do_signal(). Now,

	--- fs/select.c	2008-02-15 16:59:15.000000000 +0300
	+++ -	2008-04-09 15:19:29.015991911 +0400
	@@ -805,9 +805,8 @@ asmlinkage long sys_ppoll(struct pollfd 
			if (sigmask) {
				memcpy(&amp;current-&gt;saved_sigmask, &amp;sigsaved,
						sizeof(sigsaved));
	-			set_thread_flag(TIF_RESTORE_SIGMASK);
			}
	-		ret = -ERESTARTNOHAND;
	+		ret = -ERESTART_XXX;
		} else if (sigmask)
			sigprocmask(SIG_SETMASK, &amp;sigsaved, NULL);

Perhaps I missed something else, though. Not that I really think it worth
changing, but I'll try to make a proof of concept patch on Weekend, on top
of Roland's cleanups.

As I see it, the main disadvantage of ERESTART_ approach is that we need 2
new ERESTART_ codes, one for ERESTARTNOHAND, another for ERESTART_RESTARTBLOCK.
And yes, while I personally think this is "more clean", it is very subjective.

Oleg.

--
To: Oleg Nesterov <oleg@...>
Cc: Linus Torvalds <torvalds@...>, Roland McGrath <roland@...>, Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Wednesday, April 9, 2008 - 12:14 pm

Subjective, yeah.... personally, I don't like using ERESTART_xxx much,
because you're _not_ necessarily restarting the system call. The
separate flag for TIF_RESTORE_SIGMASK (or TLF_RESTORE_SIGMASK) seems
cleaner to me -- especially once you observe that you need new codes for
ERESTART_xxx_AND_RESTORE_SIGMASK for each ERESTART_xxx that you might
want to use in conjunction with the flags.

But I don't really care much either, if you want to change it and get
the details right.

One of the supposed advantages of TIF_RESTORE_SIGMASK in the first
place, iirc, was that it allowed us to return a result code other than
-EINTR as _well_ as restoring the signal mask. But we don't actually
make use of that possibility now anyway.

-- 
dwmw2

--
To: David Woodhouse <dwmw2@...>
Cc: Linus Torvalds <torvalds@...>, Roland McGrath <roland@...>, Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Wednesday, April 9, 2008 - 12:22 pm

Agreed, good point. ERESTART_ is not that flexible.

Somehow I assumed we will never need something "special" here, this is
not very clever.

Thanks to all!

Oleg.

--
To: Oleg Nesterov <oleg@...>
Cc: Linus Torvalds <torvalds@...>, Roland McGrath <roland@...>, Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Wednesday, April 9, 2008 - 2:40 pm

Well, it's not clear that we _will_ need it to be so special. You could
perhaps argue that it's overengineering. It's just that at the time I
did it, I _thought_ I'd need it for ppoll().

It's only in later optimisations that I realised we only ever really
needed to use TIF_RESTORE_SIGMASK in the case where ppoll() or pselect()
was interrupted.

-- 
dwmw2

--
To: Oleg Nesterov <oleg@...>
Cc: David Woodhouse <dwmw2@...>, Linus Torvalds <torvalds@...>, Roland McGrath <roland@...>, Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Wednesday, April 9, 2008 - 8:57 am

One error code more or less, that's cheap. Thread flags are a much more
limited resource.

Just my two cents,
Petr Tesarik

--
To: Oleg Nesterov <oleg@...>
Cc: Linus Torvalds <torvalds@...>, Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Tuesday, April 8, 2008 - 3:51 pm

Off hand, I concur with you and Linus.  I wasn't involved in the
introduction of TIF_RESTORE_SIGMASK and never thought too much about
it before.  In my recent changes I only considered the issue of
getting it out of _TIF_WORK_MASK et al to free up the low bit, and
didn't contemplate the structure of the implementation beyond that.

I don't think it's "too late" to change anything.  (It's never too
late!  It just might take a while to make a change in a safe and
orderly fashion for all the arch's.)  After my patch series, the
details are fully in the arch's corner.  It should be straightforward
to convert one at a time to use regs-&gt;return_register = -ERESTARTRESTOREMASK
to implement set_restore_sigmask() if you want to tackle it.


Thanks,
Roland
--
To: Oleg Nesterov <oleg@...>
Cc: Roland McGrath <roland@...>, Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Tuesday, April 8, 2008 - 10:53 am

I think you're right. I didn't look at the actual code-paths, but my gut 
feel says "yes, TIF_RESTORE_SIGMASK should actually have been 
-ERESTARTSIGRESTORE". That sounds like the right thing to do.

		Linus
--
To: Linus Torvalds <torvalds@...>
Cc: Roland McGrath <roland@...>, Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Sunday, March 30, 2008 - 6:53 am

Powerpc has a "local_flags" field.  I don't mind changing it if we are
going to have a consistent name across architectures, but "status" (as
x86 uses) seems a bit nondescript to me.

Paul.
--
To: Linus Torvalds <torvalds@...>
Cc: Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Friday, March 28, 2008 - 10:24 pm

Yes.  It only ever needs to be set or tested by the thread itself.
It's used in an entirely synchronous fashion and never from
interrupts or anything like that.  

I didn't tackle changing this at the same time because of the can of
worms you cited (and because of doing one thing at a time).

It could be a PF_* too, I suppose.  There aren't too many of those
bits free, but it would have the advantage of being a place for an
arch that doesn't store any TS_* bits anywhere.

Since acting on the flag is in arch signal code anyway, it makes some
sense to let the arch define how it gets that to happen.  I'll send
some follow-on patches that change the conditionals to use #ifdef
HAVE_SET_RESTORE_SIGMASK.  Then an arch can define that to provide
its own set_restore_sigmask() instead of TIF_RESTORE_SIGMASK, using a
TS_* flag or whatever it likes.  It will make for an easy slow

I doubt it is.  There is always about to be a whole lot more overhead
for taking siglock and all manner of synchronizing hooey, anyway.

OTOH, my patch here just added a second set_thread_flag there purely
for paranoia (it's probably never needed, but I'd have to be Oleg to
be sure ;-).  So even if 50 doesn't much matter, 51 sounds better
than 100.


Thanks,
Roland
--
To: Linus Torvalds <torvalds@...>
Cc: Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Friday, March 28, 2008 - 11:14 pm

Change all the #ifdef TIF_RESTORE_SIGMASK conditionals in non-arch
code to #ifdef HAVE_SET_RESTORE_SIGMASK.  If arch code defines it
first, the generic set_restore_sigmask() using TIF_RESTORE_SIGMASK
is not defined.

Signed-off-by: Roland McGrath &lt;roland@redhat.com&gt;
---
 fs/compat.c                 |    8 ++++----
 fs/eventpoll.c              |    4 ++--
 fs/select.c                 |    8 ++++----
 include/linux/sched.h       |    2 +-
 include/linux/thread_info.h |   10 ++++++++--
 5 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/fs/compat.c b/fs/compat.c
index 9964d54..139dc93 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -1634,7 +1634,7 @@ sticky:
 	return ret;
 }
 
-#ifdef TIF_RESTORE_SIGMASK
+#ifdef HAVE_SET_RESTORE_SIGMASK
 asmlinkage long compat_sys_pselect7(int n, compat_ulong_t __user *inp,
 	compat_ulong_t __user *outp, compat_ulong_t __user *exp,
 	struct compat_timespec __user *tsp, compat_sigset_t __user *sigmask,
@@ -1825,7 +1825,7 @@ sticky:
 
 	return ret;
 }
-#endif /* TIF_RESTORE_SIGMASK */
+#endif /* HAVE_SET_RESTORE_SIGMASK */
 
 #if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
 /* Stuff for NFS server syscalls... */
@@ -2080,7 +2080,7 @@ long asmlinkage compat_sys_nfsservctl(int cmd, void *notused, void *notused2)
 
 #ifdef CONFIG_EPOLL
 
-#ifdef TIF_RESTORE_SIGMASK
+#ifdef HAVE_SET_RESTORE_SIGMASK
 asmlinkage long compat_sys_epoll_pwait(int epfd,
 			struct compat_epoll_event __user *events,
 			int maxevents, int timeout,
@@ -2124,7 +2124,7 @@ asmlinkage long compat_sys_epoll_pwait(int epfd,
 
 	return err;
 }
-#endif /* TIF_RESTORE_SIGMASK */
+#endif /* HAVE_SET_RESTORE_SIGMASK */
 
 #endif /* CONFIG_EPOLL */
 
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 503ffa4..e55451e 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1262,7 +1262,7 @@ error_return:
 	return error;
 }
 
-#ifdef TIF_RESTORE_SIGMASK
+#ifdef HAVE_SET_RESTORE_SIGMASK
 
 /*
  * Implement the event wait interface for the e...
To: Linus Torvalds <torvalds@...>
Cc: Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Friday, March 28, 2008 - 11:14 pm

Replace TIF_RESTORE_SIGMASK with TS_RESTORE_SIGMASK and define
our own set_restore_sigmask() function.  This saves the costly
SMP-safe set_bit operation, which we do not need for the sigmask
flag since TIF_SIGPENDING always has to be set too.

Signed-off-by: Roland McGrath &lt;roland@redhat.com&gt;
---
 arch/x86/ia32/ia32_signal.c      |    2 +-
 arch/x86/kernel/signal_32.c      |   19 ++++++++++---------
 arch/x86/kernel/signal_64.c      |   16 +++++++++-------
 include/asm-x86/thread_info_32.h |   13 +++++++++++--
 include/asm-x86/thread_info_64.h |   13 +++++++++++--
 5 files changed, 42 insertions(+), 21 deletions(-)

diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
index 101b4b8..b7a531f 100644
--- a/arch/x86/ia32/ia32_signal.c
+++ b/arch/x86/ia32/ia32_signal.c
@@ -128,7 +128,7 @@ asmlinkage long sys32_sigsuspend(int history0, int history1, old_sigset_t mask)
 
 	current-&gt;state = TASK_INTERRUPTIBLE;
 	schedule();
-	set_thread_flag(TIF_RESTORE_SIGMASK);
+	set_restore_sigmask();
 	return -ERESTARTNOHAND;
 }
 
diff --git a/arch/x86/kernel/signal_32.c b/arch/x86/kernel/signal_32.c
index a06fa55..f8fbc20 100644
--- a/arch/x86/kernel/signal_32.c
+++ b/arch/x86/kernel/signal_32.c
@@ -45,7 +45,7 @@ sys_sigsuspend(int history0, int history1, old_sigset_t mask)
 
 	current-&gt;state = TASK_INTERRUPTIBLE;
 	schedule();
-	set_thread_flag(TIF_RESTORE_SIGMASK);
+	set_restore_sigmask();
 	return -ERESTARTNOHAND;
 }
 
@@ -591,7 +591,7 @@ static void do_signal(struct pt_regs *regs)
 	if (!user_mode(regs))
 		return;
 
-	if (test_thread_flag(TIF_RESTORE_SIGMASK))
+	if (current_thread_info()-&gt;status &amp; TS_RESTORE_SIGMASK)
 		oldset = &amp;current-&gt;saved_sigmask;
 	else
 		oldset = &amp;current-&gt;blocked;
@@ -608,12 +608,13 @@ static void do_signal(struct pt_regs *regs)
 
 		/* Whee!  Actually deliver the signal.  */
 		if (handle_signal(signr, &amp;info, &amp;ka, oldset, regs) == 0) {
-			/* a signal was successfully delivered; the saved
...
To: Roland McGrath <roland@...>
Cc: Linus Torvalds <torvalds@...>, Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Monday, March 31, 2008 - 9:01 am

the x86 bits look nice - but i guess this all wants to go into 2.6.26 
via -mm (or linux-next), due to its cross-arch nature?

	Ingo
--
To: Ingo Molnar <mingo@...>
Cc: Linus Torvalds <torvalds@...>, Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Monday, March 31, 2008 - 3:30 pm

Yes, I would not suggest this change for 2.6.25 at this late date.


Thanks,
Roland
--
To: Linus Torvalds Andrew Morton <akpm@...>
Cc: Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Friday, March 28, 2008 - 11:11 pm

Change all the #ifdef TIF_RESTORE_SIGMASK conditionals in non-arch
code to #ifdef HAVE_SET_RESTORE_SIGMASK.  If arch code defines it
first, the generic set_restore_sigmask() using TIF_RESTORE_SIGMASK
is not defined.

Signed-off-by: Roland McGrath &lt;roland@redhat.com&gt;
---
 fs/compat.c                 |    8 ++++----
 fs/eventpoll.c              |    4 ++--
 fs/select.c                 |    8 ++++----
 include/linux/sched.h       |    2 +-
 include/linux/thread_info.h |   10 ++++++++--
 5 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/fs/compat.c b/fs/compat.c
index 9964d54..139dc93 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -1634,7 +1634,7 @@ sticky:
 	return ret;
 }
 
-#ifdef TIF_RESTORE_SIGMASK
+#ifdef HAVE_SET_RESTORE_SIGMASK
 asmlinkage long compat_sys_pselect7(int n, compat_ulong_t __user *inp,
 	compat_ulong_t __user *outp, compat_ulong_t __user *exp,
 	struct compat_timespec __user *tsp, compat_sigset_t __user *sigmask,
@@ -1825,7 +1825,7 @@ sticky:
 
 	return ret;
 }
-#endif /* TIF_RESTORE_SIGMASK */
+#endif /* HAVE_SET_RESTORE_SIGMASK */
 
 #if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
 /* Stuff for NFS server syscalls... */
@@ -2080,7 +2080,7 @@ long asmlinkage compat_sys_nfsservctl(int cmd, void *notused, void *notused2)
 
 #ifdef CONFIG_EPOLL
 
-#ifdef TIF_RESTORE_SIGMASK
+#ifdef HAVE_SET_RESTORE_SIGMASK
 asmlinkage long compat_sys_epoll_pwait(int epfd,
 			struct compat_epoll_event __user *events,
 			int maxevents, int timeout,
@@ -2124,7 +2124,7 @@ asmlinkage long compat_sys_epoll_pwait(int epfd,
 
 	return err;
 }
-#endif /* TIF_RESTORE_SIGMASK */
+#endif /* HAVE_SET_RESTORE_SIGMASK */
 
 #endif /* CONFIG_EPOLL */
 
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 503ffa4..e55451e 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1262,7 +1262,7 @@ error_return:
 	return error;
 }
 
-#ifdef TIF_RESTORE_SIGMASK
+#ifdef HAVE_SET_RESTORE_SIGMASK
 
 /*
  * Implement the event wait interface for the e...
To: Roland McGrath <roland@...>
Cc: Linus Torvalds Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>, <miles@...>, <rmk+linux@...>, <geert@...>, <zippel@...>
Date: Wednesday, April 9, 2008 - 7:45 am

That ifdef was only supposed to be a temporary thing until all
architectures had implemented TIF_RESTORE_SIGMASK anyway.

It looks like only ARM, v850 and m68k which are still missing it; if
those three architectures can catch up, then hopefully it can die off
completely quite soon.

-- 
dwmw2

--
To: David Woodhouse <dwmw2@...>
Cc: Roland McGrath <roland@...>, Linus Torvalds Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>, <miles@...>, <geert@...>, <zippel@...>
Date: Thursday, April 10, 2008 - 4:32 pm

Well, we don't have the pselect/ppoll/epoll_wait syscalls and there's
been no demand for them, so I don't particularly see the point of
going to the trouble of adding support for something no one's
interested in using.

I was going to suggest defining TIF_RESTORE_SIGMASK to zero to eliminate
some of the code (and the ifdefs), but unfortunately its a bit position
not a bitmask so that won't work.

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:
--
To: Russell King <rmk+lkml@...>
Cc: Roland McGrath <roland@...>, Linus Torvalds Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>, <miles@...>, <geert@...>, <zippel@...>
Date: Friday, April 11, 2008 - 9:40 am

You're not likely to see demand for it from users. I believe glibc will
emulate it as best it can (which is not very well), and things will
appear to work.... most of the time.

-- 
dwmw2

--
To: Roland McGrath <roland@...>
Cc: Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Friday, March 28, 2008 - 10:52 pm

Yeah, I guess PF_ would be a bit more regular. Maybe we should even try to 
avoid the use of TS_ in x86, and turn it into PF_. There are probably bad 

Let's see if it matters first. No reason to add another arch-specific 
thing if nobody can even measure this thing, and from a quick look it 
seems like every RESTORE_SIGMASK user is basically an error path for a 
system call. Those few extra cycles really won't be noticeable, we almost 
certainly have better things we could use our energy on.

So never mind. I think your series is fine, and my TS_ idea doesn't really 
look like it's worth it (and using PF_ sounds a bit more palatable since 
we could do it with existing infrastructure, but a quick grep shows that 
there's more users of test_thread_flag(TIF_RESTORE_SIGMASK) than I would 
have expected (and the *testing* is equally cheap for atomic and thread- 
synchronous fields, so that's not a performance issue).

			Linus
--
To: Linus Torvalds <torvalds@...>
Cc: Andrew Morton <akpm@...>, Martin Schwidefsky <schwidefsky@...>, <linux-s390@...>, <tony.luck@...>, <linux-ia64@...>, <linux-arch@...>, <linux-kernel@...>
Date: Friday, March 28, 2008 - 11:12 pm

&gt; So never mind. [...]

Well fooey on you, 'cause I wrote it already.  So I'm a'postin'!
--
Previous thread: unexpected rename() behaviour by Ketil Froyn on Friday, March 28, 2008 - 8:07 pm. (5 messages)

Next thread: Re: sata io freeze, 2.6.18 and also 2.6.24 by Luis Sousa on Friday, March 28, 2008 - 8:22 pm. (1 message)
speck-geostationary