Skip to content

Commit 5a8da0e

Browse files
Roland McGrathtorvalds
authored andcommitted
signals: x86 TS_RESTORE_SIGMASK
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 <roland@redhat.com> Cc: Oleg Nesterov <oleg@tv-sign.ru> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: "Luck, Tony" <tony.luck@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f3de272 commit 5a8da0e

File tree

5 files changed

+40
-21
lines changed

5 files changed

+40
-21
lines changed

arch/x86/ia32/ia32_signal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ asmlinkage long sys32_sigsuspend(int history0, int history1, old_sigset_t mask)
128128

129129
current->state = TASK_INTERRUPTIBLE;
130130
schedule();
131-
set_thread_flag(TIF_RESTORE_SIGMASK);
131+
set_restore_sigmask();
132132
return -ERESTARTNOHAND;
133133
}
134134

arch/x86/kernel/signal_32.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ sys_sigsuspend(int history0, int history1, old_sigset_t mask)
5757

5858
current->state = TASK_INTERRUPTIBLE;
5959
schedule();
60-
set_thread_flag(TIF_RESTORE_SIGMASK);
60+
set_restore_sigmask();
6161

6262
return -ERESTARTNOHAND;
6363
}
@@ -593,7 +593,7 @@ static void do_signal(struct pt_regs *regs)
593593
if (!user_mode(regs))
594594
return;
595595

596-
if (test_thread_flag(TIF_RESTORE_SIGMASK))
596+
if (current_thread_info()->status & TS_RESTORE_SIGMASK)
597597
oldset = &current->saved_sigmask;
598598
else
599599
oldset = &current->blocked;
@@ -612,13 +612,12 @@ static void do_signal(struct pt_regs *regs)
612612
/* Whee! Actually deliver the signal. */
613613
if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
614614
/*
615-
* a signal was successfully delivered; the saved
615+
* A signal was successfully delivered; the saved
616616
* sigmask will have been stored in the signal frame,
617617
* and will be restored by sigreturn, so we can simply
618-
* clear the TIF_RESTORE_SIGMASK flag
618+
* clear the TS_RESTORE_SIGMASK flag.
619619
*/
620-
if (test_thread_flag(TIF_RESTORE_SIGMASK))
621-
clear_thread_flag(TIF_RESTORE_SIGMASK);
620+
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
622621
}
623622
return;
624623
}
@@ -645,8 +644,8 @@ static void do_signal(struct pt_regs *regs)
645644
* If there's no signal to deliver, we just put the saved sigmask
646645
* back.
647646
*/
648-
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
649-
clear_thread_flag(TIF_RESTORE_SIGMASK);
647+
if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
648+
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
650649
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
651650
}
652651
}
@@ -665,7 +664,7 @@ do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
665664
}
666665

667666
/* deal with pending signal delivery */
668-
if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
667+
if (thread_info_flags & _TIF_SIGPENDING)
669668
do_signal(regs);
670669

671670
if (thread_info_flags & _TIF_HRTICK_RESCHED)

arch/x86/kernel/signal_64.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ static void do_signal(struct pt_regs *regs)
427427
if (!user_mode(regs))
428428
return;
429429

430-
if (test_thread_flag(TIF_RESTORE_SIGMASK))
430+
if (current_thread_info()->status & TS_RESTORE_SIGMASK)
431431
oldset = &current->saved_sigmask;
432432
else
433433
oldset = &current->blocked;
@@ -444,11 +444,13 @@ static void do_signal(struct pt_regs *regs)
444444

445445
/* Whee! Actually deliver the signal. */
446446
if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
447-
/* a signal was successfully delivered; the saved
447+
/*
448+
* A signal was successfully delivered; the saved
448449
* sigmask will have been stored in the signal frame,
449450
* and will be restored by sigreturn, so we can simply
450-
* clear the TIF_RESTORE_SIGMASK flag */
451-
clear_thread_flag(TIF_RESTORE_SIGMASK);
451+
* clear the TS_RESTORE_SIGMASK flag.
452+
*/
453+
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
452454
}
453455
return;
454456
}
@@ -476,8 +478,8 @@ static void do_signal(struct pt_regs *regs)
476478
* If there's no signal to deliver, we just put the saved sigmask
477479
* back.
478480
*/
479-
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
480-
clear_thread_flag(TIF_RESTORE_SIGMASK);
481+
if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
482+
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
481483
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
482484
}
483485
}
@@ -498,7 +500,7 @@ void do_notify_resume(struct pt_regs *regs, void *unused,
498500
#endif /* CONFIG_X86_MCE */
499501

500502
/* deal with pending signal delivery */
501-
if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
503+
if (thread_info_flags & _TIF_SIGPENDING)
502504
do_signal(regs);
503505

504506
if (thread_info_flags & _TIF_HRTICK_RESCHED)

include/asm-x86/thread_info_32.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ static inline struct thread_info *current_thread_info(void)
131131
#define TIF_SYSCALL_EMU 5 /* syscall emulation active */
132132
#define TIF_SYSCALL_AUDIT 6 /* syscall auditing active */
133133
#define TIF_SECCOMP 7 /* secure computing */
134-
#define TIF_RESTORE_SIGMASK 8 /* restore signal mask in do_signal() */
135134
#define TIF_HRTICK_RESCHED 9 /* reprogram hrtick timer */
136135
#define TIF_MEMDIE 16
137136
#define TIF_DEBUG 17 /* uses debug registers */
@@ -151,7 +150,6 @@ static inline struct thread_info *current_thread_info(void)
151150
#define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU)
152151
#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
153152
#define _TIF_SECCOMP (1 << TIF_SECCOMP)
154-
#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
155153
#define _TIF_HRTICK_RESCHED (1 << TIF_HRTICK_RESCHED)
156154
#define _TIF_DEBUG (1 << TIF_DEBUG)
157155
#define _TIF_IO_BITMAP (1 << TIF_IO_BITMAP)
@@ -188,9 +186,20 @@ static inline struct thread_info *current_thread_info(void)
188186
this quantum (SMP) */
189187
#define TS_POLLING 0x0002 /* True if in idle loop
190188
and not sleeping */
189+
#define TS_RESTORE_SIGMASK 0x0004 /* restore signal mask in do_signal() */
191190

192191
#define tsk_is_polling(t) (task_thread_info(t)->status & TS_POLLING)
193192

193+
#ifndef __ASSEMBLY__
194+
#define HAVE_SET_RESTORE_SIGMASK 1
195+
static inline void set_restore_sigmask(void)
196+
{
197+
struct thread_info *ti = current_thread_info();
198+
ti->status |= TS_RESTORE_SIGMASK;
199+
set_bit(TIF_SIGPENDING, &ti->flags);
200+
}
201+
#endif /* !__ASSEMBLY__ */
202+
194203
#endif /* __KERNEL__ */
195204

196205
#endif /* _ASM_THREAD_INFO_H */

include/asm-x86/thread_info_64.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ static inline struct thread_info *stack_thread_info(void)
109109
#define TIF_IRET 5 /* force IRET */
110110
#define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
111111
#define TIF_SECCOMP 8 /* secure computing */
112-
#define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal */
113112
#define TIF_MCE_NOTIFY 10 /* notify userspace of an MCE */
114113
#define TIF_HRTICK_RESCHED 11 /* reprogram hrtick timer */
115114
/* 16 free */
@@ -133,7 +132,6 @@ static inline struct thread_info *stack_thread_info(void)
133132
#define _TIF_IRET (1 << TIF_IRET)
134133
#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
135134
#define _TIF_SECCOMP (1 << TIF_SECCOMP)
136-
#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
137135
#define _TIF_MCE_NOTIFY (1 << TIF_MCE_NOTIFY)
138136
#define _TIF_HRTICK_RESCHED (1 << TIF_HRTICK_RESCHED)
139137
#define _TIF_IA32 (1 << TIF_IA32)
@@ -178,9 +176,20 @@ static inline struct thread_info *stack_thread_info(void)
178176
#define TS_COMPAT 0x0002 /* 32bit syscall active */
179177
#define TS_POLLING 0x0004 /* true if in idle loop
180178
and not sleeping */
179+
#define TS_RESTORE_SIGMASK 0x0008 /* restore signal mask in do_signal() */
181180

182181
#define tsk_is_polling(t) (task_thread_info(t)->status & TS_POLLING)
183182

183+
#ifndef __ASSEMBLY__
184+
#define HAVE_SET_RESTORE_SIGMASK 1
185+
static inline void set_restore_sigmask(void)
186+
{
187+
struct thread_info *ti = current_thread_info();
188+
ti->status |= TS_RESTORE_SIGMASK;
189+
set_bit(TIF_SIGPENDING, &ti->flags);
190+
}
191+
#endif /* !__ASSEMBLY__ */
192+
184193
#endif /* __KERNEL__ */
185194

186195
#endif /* _ASM_THREAD_INFO_H */

0 commit comments

Comments
 (0)