Skip to content

Commit db7d9a4

Browse files
committed
[SPARC64]: Move syscall success and newchild state out of thread flags.
These two bits were accesses non-atomically from assembler code. So, in order to eliminate any potential races resulting from that, move these pieces of state into two bytes elsewhere in struct thread_info. Signed-off-by: David S. Miller <[email protected]>
1 parent cdd5186 commit db7d9a4

File tree

7 files changed

+27
-24
lines changed

7 files changed

+27
-24
lines changed

arch/sparc64/kernel/entry.S

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,11 +1600,11 @@ sys_clone: flushw
16001600
ba,pt %xcc, sparc_do_fork
16011601
add %sp, PTREGS_OFF, %o2
16021602
ret_from_syscall:
1603-
/* Clear SPARC_FLAG_NEWCHILD, switch_to leaves thread.flags in
1604-
* %o7 for us. Check performance counter stuff too.
1603+
/* Clear current_thread_info()->new_child, and
1604+
* check performance counter stuff too.
16051605
*/
1606-
andn %o7, _TIF_NEWCHILD, %l0
1607-
stx %l0, [%g6 + TI_FLAGS]
1606+
stb %g0, [%g6 + TI_NEW_CHILD]
1607+
ldx [%g6 + TI_FLAGS], %l0
16081608
call schedule_tail
16091609
mov %g7, %o0
16101610
andcc %l0, _TIF_PERFCTR, %g0
@@ -1720,12 +1720,11 @@ ret_sys_call:
17201720
/* Check if force_successful_syscall_return()
17211721
* was invoked.
17221722
*/
1723-
ldx [%curptr + TI_FLAGS], %l0
1724-
andcc %l0, _TIF_SYSCALL_SUCCESS, %g0
1725-
be,pt %icc, 1f
1726-
andn %l0, _TIF_SYSCALL_SUCCESS, %l0
1723+
ldub [%curptr + TI_SYS_NOERROR], %l0
1724+
brz,pt %l0, 1f
1725+
nop
17271726
ba,pt %xcc, 80f
1728-
stx %l0, [%curptr + TI_FLAGS]
1727+
stb %g0, [%curptr + TI_SYS_NOERROR]
17291728

17301729
1:
17311730
cmp %o0, -ERESTART_RESTARTBLOCK

arch/sparc64/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,8 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
621621
memcpy(child_trap_frame, (((struct sparc_stackf *)regs)-1), (TRACEREG_SZ+STACKFRAME_SZ));
622622

623623
t->flags = (t->flags & ~((0xffUL << TI_FLAG_CWP_SHIFT) | (0xffUL << TI_FLAG_CURRENT_DS_SHIFT))) |
624-
_TIF_NEWCHILD |
625624
(((regs->tstate + 1) & TSTATE_CWP) << TI_FLAG_CWP_SHIFT);
625+
t->new_child = 1;
626626
t->ksp = ((unsigned long) child_trap_frame) - STACK_BIAS;
627627
t->kregs = (struct pt_regs *)(child_trap_frame+sizeof(struct sparc_stackf));
628628
t->fpsaved[0] = 0;

arch/sparc64/kernel/smp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void __init smp_callin(void)
137137
/* Clear this or we will die instantly when we
138138
* schedule back to this idler...
139139
*/
140-
clear_thread_flag(TIF_NEWCHILD);
140+
current_thread_info()->new_child = 0;
141141

142142
/* Attach to the address space of init_task. */
143143
atomic_inc(&init_mm.mm_count);

arch/sparc64/kernel/traps.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,8 @@ void __init trap_init(void)
21252125
TI_PCR != offsetof(struct thread_info, pcr_reg) ||
21262126
TI_CEE_STUFF != offsetof(struct thread_info, cee_stuff) ||
21272127
TI_PRE_COUNT != offsetof(struct thread_info, preempt_count) ||
2128+
TI_NEW_CHILD != offsetof(struct thread_info, new_child) ||
2129+
TI_SYS_NOERROR != offsetof(struct thread_info, syscall_noerror) ||
21282130
TI_FPREGS != offsetof(struct thread_info, fpregs) ||
21292131
(TI_FPREGS & (64 - 1)))
21302132
thread_info_offsets_are_bolixed_dave();

include/asm-sparc64/ptrace.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ struct sparc_trapf {
9494
#define STACKFRAME32_SZ sizeof(struct sparc_stackf32)
9595

9696
#ifdef __KERNEL__
97-
#define force_successful_syscall_return() \
98-
set_thread_flag(TIF_SYSCALL_SUCCESS)
97+
#define force_successful_syscall_return() \
98+
do { current_thread_info()->syscall_noerror = 1; \
99+
} while (0)
99100
#define user_mode(regs) (!((regs)->tstate & TSTATE_PRIV))
100101
#define instruction_pointer(regs) ((regs)->tpc)
101102
#ifdef CONFIG_SMP

include/asm-sparc64/system.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,24 +190,23 @@ do { if (test_thread_flag(TIF_PERFCTR)) { \
190190
"wrpr %%g1, %%cwp\n\t" \
191191
"ldx [%%g6 + %3], %%o6\n\t" \
192192
"ldub [%%g6 + %2], %%o5\n\t" \
193-
"ldx [%%g6 + %4], %%o7\n\t" \
193+
"ldub [%%g6 + %4], %%o7\n\t" \
194194
"mov %%g6, %%l2\n\t" \
195195
"wrpr %%o5, 0x0, %%wstate\n\t" \
196196
"ldx [%%sp + 2047 + 0x70], %%i6\n\t" \
197197
"ldx [%%sp + 2047 + 0x78], %%i7\n\t" \
198198
"wrpr %%g0, 0x94, %%pstate\n\t" \
199199
"mov %%l2, %%g6\n\t" \
200-
"ldx [%%g6 + %7], %%g4\n\t" \
200+
"ldx [%%g6 + %6], %%g4\n\t" \
201201
"wrpr %%g0, 0x96, %%pstate\n\t" \
202-
"andcc %%o7, %6, %%g0\n\t" \
203-
"beq,pt %%icc, 1f\n\t" \
202+
"brz,pt %%o7, 1f\n\t" \
204203
" mov %%g7, %0\n\t" \
205204
"b,a ret_from_syscall\n\t" \
206205
"1:\n\t" \
207206
: "=&r" (last) \
208207
: "0" (next->thread_info), \
209-
"i" (TI_WSTATE), "i" (TI_KSP), "i" (TI_FLAGS), "i" (TI_CWP), \
210-
"i" (_TIF_NEWCHILD), "i" (TI_TASK) \
208+
"i" (TI_WSTATE), "i" (TI_KSP), "i" (TI_NEW_CHILD), \
209+
"i" (TI_CWP), "i" (TI_TASK) \
211210
: "cc", \
212211
"g1", "g2", "g3", "g7", \
213212
"l2", "l3", "l4", "l5", "l6", "l7", \

include/asm-sparc64/thread_info.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ struct thread_info {
4747
struct pt_regs *kregs;
4848
struct exec_domain *exec_domain;
4949
int preempt_count; /* 0 => preemptable, <0 => BUG */
50-
int __pad;
50+
__u8 new_child;
51+
__u8 syscall_noerror;
52+
__u16 __pad;
5153

5254
unsigned long *utraps;
5355

@@ -87,6 +89,8 @@ struct thread_info {
8789
#define TI_KREGS 0x00000028
8890
#define TI_EXEC_DOMAIN 0x00000030
8991
#define TI_PRE_COUNT 0x00000038
92+
#define TI_NEW_CHILD 0x0000003c
93+
#define TI_SYS_NOERROR 0x0000003d
9094
#define TI_UTRAPS 0x00000040
9195
#define TI_REG_WINDOW 0x00000048
9296
#define TI_RWIN_SPTRS 0x000003c8
@@ -219,10 +223,10 @@ register struct thread_info *current_thread_info_reg asm("g6");
219223
#define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
220224
#define TIF_NEWSIGNALS 6 /* wants new-style signals */
221225
#define TIF_32BIT 7 /* 32-bit binary */
222-
#define TIF_NEWCHILD 8 /* just-spawned child process */
226+
/* flag bit 8 is available */
223227
#define TIF_SECCOMP 9 /* secure computing */
224228
#define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
225-
#define TIF_SYSCALL_SUCCESS 11
229+
/* flag bit 11 is available */
226230
/* NOTE: Thread flags >= 12 should be ones we have no interest
227231
* in using in assembly, else we can't use the mask as
228232
* an immediate value in instructions such as andcc.
@@ -239,10 +243,8 @@ register struct thread_info *current_thread_info_reg asm("g6");
239243
#define _TIF_UNALIGNED (1<<TIF_UNALIGNED)
240244
#define _TIF_NEWSIGNALS (1<<TIF_NEWSIGNALS)
241245
#define _TIF_32BIT (1<<TIF_32BIT)
242-
#define _TIF_NEWCHILD (1<<TIF_NEWCHILD)
243246
#define _TIF_SECCOMP (1<<TIF_SECCOMP)
244247
#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
245-
#define _TIF_SYSCALL_SUCCESS (1<<TIF_SYSCALL_SUCCESS)
246248
#define _TIF_ABI_PENDING (1<<TIF_ABI_PENDING)
247249
#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
248250

0 commit comments

Comments
 (0)