Skip to content

Commit 56bfc42

Browse files
committed
sh: TS_RESTORE_SIGMASK conversion.
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. Based on the x86 and powerpc change. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent b195e46 commit 56bfc42

5 files changed

Lines changed: 44 additions & 23 deletions

File tree

‎arch/sh/include/asm/thread_info.h‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct thread_info {
1919
struct task_struct *task; /* main task structure */
2020
struct exec_domain *exec_domain; /* execution domain */
2121
unsigned long flags; /* low level flags */
22+
__u32 status; /* thread synchronous flags */
2223
__u32 cpu;
2324
int preempt_count; /* 0 => preemptable, <0 => BUG */
2425
mm_segment_t addr_limit; /* thread address space */
@@ -111,7 +112,6 @@ extern void free_thread_info(struct thread_info *ti);
111112
#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
112113
#define TIF_SIGPENDING 1 /* signal pending */
113114
#define TIF_NEED_RESCHED 2 /* rescheduling necessary */
114-
#define TIF_RESTORE_SIGMASK 3 /* restore signal mask in do_signal() */
115115
#define TIF_SINGLESTEP 4 /* singlestepping active */
116116
#define TIF_SYSCALL_AUDIT 5 /* syscall auditing active */
117117
#define TIF_SECCOMP 6 /* secure computing */
@@ -125,7 +125,6 @@ extern void free_thread_info(struct thread_info *ti);
125125
#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
126126
#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
127127
#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
128-
#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
129128
#define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP)
130129
#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
131130
#define _TIF_SECCOMP (1 << TIF_SECCOMP)
@@ -149,13 +148,32 @@ extern void free_thread_info(struct thread_info *ti);
149148
/* work to do on any return to u-space */
150149
#define _TIF_ALLWORK_MASK (_TIF_SYSCALL_TRACE | _TIF_SIGPENDING | \
151150
_TIF_NEED_RESCHED | _TIF_SYSCALL_AUDIT | \
152-
_TIF_SINGLESTEP | _TIF_RESTORE_SIGMASK | \
153-
_TIF_NOTIFY_RESUME | _TIF_SYSCALL_TRACEPOINT)
151+
_TIF_SINGLESTEP | _TIF_NOTIFY_RESUME | \
152+
_TIF_SYSCALL_TRACEPOINT)
154153

155154
/* work to do on interrupt/exception return */
156155
#define _TIF_WORK_MASK (_TIF_ALLWORK_MASK & ~(_TIF_SYSCALL_TRACE | \
157156
_TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP))
158157

158+
/*
159+
* Thread-synchronous status.
160+
*
161+
* This is different from the flags in that nobody else
162+
* ever touches our thread-synchronous status, so we don't
163+
* have to worry about atomic accesses.
164+
*/
165+
#define TS_RESTORE_SIGMASK 0x0001 /* restore signal mask in do_signal() */
166+
167+
#ifndef __ASSEMBLY__
168+
#define HAVE_SET_RESTORE_SIGMASK 1
169+
static inline void set_restore_sigmask(void)
170+
{
171+
struct thread_info *ti = current_thread_info();
172+
ti->status |= TS_RESTORE_SIGMASK;
173+
set_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags);
174+
}
175+
#endif /* !__ASSEMBLY__ */
176+
159177
#endif /* __KERNEL__ */
160178

161179
#endif /* __ASM_SH_THREAD_INFO_H */

‎arch/sh/kernel/cpu/sh5/entry.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ ret_with_reschedule:
933933

934934
pta restore_all, tr1
935935

936-
movi (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), r8
936+
movi _TIF_SIGPENDING, r8
937937
and r8, r7, r8
938938
pta work_notifysig, tr0
939939
bne r8, ZERO, tr0

‎arch/sh/kernel/entry-common.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ work_pending:
133133
! r8: current_thread_info
134134
! t: result of "tst #_TIF_NEED_RESCHED, r0"
135135
bf/s work_resched
136-
tst #(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), r0
136+
tst #_TIF_SIGPENDING, r0
137137
work_notifysig:
138138
bt/s __restore_all
139139
mov r15, r4

‎arch/sh/kernel/signal_32.c‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ sys_sigsuspend(old_sigset_t mask,
6767

6868
current->state = TASK_INTERRUPTIBLE;
6969
schedule();
70-
set_thread_flag(TIF_RESTORE_SIGMASK);
70+
set_restore_sigmask();
71+
7172
return -ERESTARTNOHAND;
7273
}
7374

@@ -590,7 +591,7 @@ static void do_signal(struct pt_regs *regs, unsigned int save_r0)
590591
if (try_to_freeze())
591592
goto no_signal;
592593

593-
if (test_thread_flag(TIF_RESTORE_SIGMASK))
594+
if (current_thread_info()->status & TS_RESTORE_SIGMASK)
594595
oldset = &current->saved_sigmask;
595596
else
596597
oldset = &current->blocked;
@@ -602,12 +603,13 @@ static void do_signal(struct pt_regs *regs, unsigned int save_r0)
602603
/* Whee! Actually deliver the signal. */
603604
if (handle_signal(signr, &ka, &info, oldset,
604605
regs, save_r0) == 0) {
605-
/* a signal was successfully delivered; the saved
606+
/*
607+
* A signal was successfully delivered; the saved
606608
* sigmask will have been stored in the signal frame,
607609
* and will be restored by sigreturn, so we can simply
608-
* clear the TIF_RESTORE_SIGMASK flag */
609-
if (test_thread_flag(TIF_RESTORE_SIGMASK))
610-
clear_thread_flag(TIF_RESTORE_SIGMASK);
610+
* clear the TS_RESTORE_SIGMASK flag
611+
*/
612+
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
611613

612614
tracehook_signal_handler(signr, &info, &ka, regs,
613615
test_thread_flag(TIF_SINGLESTEP));
@@ -631,10 +633,12 @@ static void do_signal(struct pt_regs *regs, unsigned int save_r0)
631633
}
632634
}
633635

634-
/* if there's no signal to deliver, we just put the saved sigmask
635-
* back */
636-
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
637-
clear_thread_flag(TIF_RESTORE_SIGMASK);
636+
/*
637+
* If there's no signal to deliver, we just put the saved sigmask
638+
* back.
639+
*/
640+
if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
641+
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
638642
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
639643
}
640644
}

‎arch/sh/kernel/signal_64.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static int do_signal(struct pt_regs *regs, sigset_t *oldset)
101101
if (try_to_freeze())
102102
goto no_signal;
103103

104-
if (test_thread_flag(TIF_RESTORE_SIGMASK))
104+
if (current_thread_info()->status & TS_RESTORE_SIGMASK)
105105
oldset = &current->saved_sigmask;
106106
else if (!oldset)
107107
oldset = &current->blocked;
@@ -115,11 +115,9 @@ static int do_signal(struct pt_regs *regs, sigset_t *oldset)
115115
/*
116116
* If a signal was successfully delivered, the
117117
* saved sigmask is in its frame, and we can
118-
* clear the TIF_RESTORE_SIGMASK flag.
118+
* clear the TS_RESTORE_SIGMASK flag.
119119
*/
120-
if (test_thread_flag(TIF_RESTORE_SIGMASK))
121-
clear_thread_flag(TIF_RESTORE_SIGMASK);
122-
120+
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
123121
tracehook_signal_handler(signr, &info, &ka, regs, 0);
124122
return 1;
125123
}
@@ -146,8 +144,8 @@ static int do_signal(struct pt_regs *regs, sigset_t *oldset)
146144
}
147145

148146
/* No signal to deliver -- put the saved sigmask back */
149-
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
150-
clear_thread_flag(TIF_RESTORE_SIGMASK);
147+
if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
148+
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
151149
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
152150
}
153151

@@ -176,6 +174,7 @@ sys_sigsuspend(old_sigset_t mask,
176174
while (1) {
177175
current->state = TASK_INTERRUPTIBLE;
178176
schedule();
177+
set_restore_sigmask();
179178
regs->pc += 4; /* because sys_sigreturn decrements the pc */
180179
if (do_signal(regs, &saveset)) {
181180
/* pc now points at signal handler. Need to decrement

0 commit comments

Comments
 (0)