Commit db7d9a4e authored by David S. Miller's avatar David S. Miller

[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: default avatarDavid S. Miller <davem@davemloft.net>
parent cdd5186f
...@@ -1600,11 +1600,11 @@ sys_clone: flushw ...@@ -1600,11 +1600,11 @@ sys_clone: flushw
ba,pt %xcc, sparc_do_fork ba,pt %xcc, sparc_do_fork
add %sp, PTREGS_OFF, %o2 add %sp, PTREGS_OFF, %o2
ret_from_syscall: ret_from_syscall:
/* Clear SPARC_FLAG_NEWCHILD, switch_to leaves thread.flags in /* Clear current_thread_info()->new_child, and
* %o7 for us. Check performance counter stuff too. * check performance counter stuff too.
*/ */
andn %o7, _TIF_NEWCHILD, %l0 stb %g0, [%g6 + TI_NEW_CHILD]
stx %l0, [%g6 + TI_FLAGS] ldx [%g6 + TI_FLAGS], %l0
call schedule_tail call schedule_tail
mov %g7, %o0 mov %g7, %o0
andcc %l0, _TIF_PERFCTR, %g0 andcc %l0, _TIF_PERFCTR, %g0
...@@ -1720,12 +1720,11 @@ ret_sys_call: ...@@ -1720,12 +1720,11 @@ ret_sys_call:
/* Check if force_successful_syscall_return() /* Check if force_successful_syscall_return()
* was invoked. * was invoked.
*/ */
ldx [%curptr + TI_FLAGS], %l0 ldub [%curptr + TI_SYS_NOERROR], %l0
andcc %l0, _TIF_SYSCALL_SUCCESS, %g0 brz,pt %l0, 1f
be,pt %icc, 1f nop
andn %l0, _TIF_SYSCALL_SUCCESS, %l0
ba,pt %xcc, 80f ba,pt %xcc, 80f
stx %l0, [%curptr + TI_FLAGS] stb %g0, [%curptr + TI_SYS_NOERROR]
1: 1:
cmp %o0, -ERESTART_RESTARTBLOCK cmp %o0, -ERESTART_RESTARTBLOCK
......
...@@ -621,8 +621,8 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long sp, ...@@ -621,8 +621,8 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
memcpy(child_trap_frame, (((struct sparc_stackf *)regs)-1), (TRACEREG_SZ+STACKFRAME_SZ)); memcpy(child_trap_frame, (((struct sparc_stackf *)regs)-1), (TRACEREG_SZ+STACKFRAME_SZ));
t->flags = (t->flags & ~((0xffUL << TI_FLAG_CWP_SHIFT) | (0xffUL << TI_FLAG_CURRENT_DS_SHIFT))) | t->flags = (t->flags & ~((0xffUL << TI_FLAG_CWP_SHIFT) | (0xffUL << TI_FLAG_CURRENT_DS_SHIFT))) |
_TIF_NEWCHILD |
(((regs->tstate + 1) & TSTATE_CWP) << TI_FLAG_CWP_SHIFT); (((regs->tstate + 1) & TSTATE_CWP) << TI_FLAG_CWP_SHIFT);
t->new_child = 1;
t->ksp = ((unsigned long) child_trap_frame) - STACK_BIAS; t->ksp = ((unsigned long) child_trap_frame) - STACK_BIAS;
t->kregs = (struct pt_regs *)(child_trap_frame+sizeof(struct sparc_stackf)); t->kregs = (struct pt_regs *)(child_trap_frame+sizeof(struct sparc_stackf));
t->fpsaved[0] = 0; t->fpsaved[0] = 0;
......
...@@ -137,7 +137,7 @@ void __init smp_callin(void) ...@@ -137,7 +137,7 @@ void __init smp_callin(void)
/* Clear this or we will die instantly when we /* Clear this or we will die instantly when we
* schedule back to this idler... * schedule back to this idler...
*/ */
clear_thread_flag(TIF_NEWCHILD); current_thread_info()->new_child = 0;
/* Attach to the address space of init_task. */ /* Attach to the address space of init_task. */
atomic_inc(&init_mm.mm_count); atomic_inc(&init_mm.mm_count);
......
...@@ -2125,6 +2125,8 @@ void __init trap_init(void) ...@@ -2125,6 +2125,8 @@ void __init trap_init(void)
TI_PCR != offsetof(struct thread_info, pcr_reg) || TI_PCR != offsetof(struct thread_info, pcr_reg) ||
TI_CEE_STUFF != offsetof(struct thread_info, cee_stuff) || TI_CEE_STUFF != offsetof(struct thread_info, cee_stuff) ||
TI_PRE_COUNT != offsetof(struct thread_info, preempt_count) || TI_PRE_COUNT != offsetof(struct thread_info, preempt_count) ||
TI_NEW_CHILD != offsetof(struct thread_info, new_child) ||
TI_SYS_NOERROR != offsetof(struct thread_info, syscall_noerror) ||
TI_FPREGS != offsetof(struct thread_info, fpregs) || TI_FPREGS != offsetof(struct thread_info, fpregs) ||
(TI_FPREGS & (64 - 1))) (TI_FPREGS & (64 - 1)))
thread_info_offsets_are_bolixed_dave(); thread_info_offsets_are_bolixed_dave();
......
...@@ -94,8 +94,9 @@ struct sparc_trapf { ...@@ -94,8 +94,9 @@ struct sparc_trapf {
#define STACKFRAME32_SZ sizeof(struct sparc_stackf32) #define STACKFRAME32_SZ sizeof(struct sparc_stackf32)
#ifdef __KERNEL__ #ifdef __KERNEL__
#define force_successful_syscall_return() \ #define force_successful_syscall_return() \
set_thread_flag(TIF_SYSCALL_SUCCESS) do { current_thread_info()->syscall_noerror = 1; \
} while (0)
#define user_mode(regs) (!((regs)->tstate & TSTATE_PRIV)) #define user_mode(regs) (!((regs)->tstate & TSTATE_PRIV))
#define instruction_pointer(regs) ((regs)->tpc) #define instruction_pointer(regs) ((regs)->tpc)
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
......
...@@ -190,24 +190,23 @@ do { if (test_thread_flag(TIF_PERFCTR)) { \ ...@@ -190,24 +190,23 @@ do { if (test_thread_flag(TIF_PERFCTR)) { \
"wrpr %%g1, %%cwp\n\t" \ "wrpr %%g1, %%cwp\n\t" \
"ldx [%%g6 + %3], %%o6\n\t" \ "ldx [%%g6 + %3], %%o6\n\t" \
"ldub [%%g6 + %2], %%o5\n\t" \ "ldub [%%g6 + %2], %%o5\n\t" \
"ldx [%%g6 + %4], %%o7\n\t" \ "ldub [%%g6 + %4], %%o7\n\t" \
"mov %%g6, %%l2\n\t" \ "mov %%g6, %%l2\n\t" \
"wrpr %%o5, 0x0, %%wstate\n\t" \ "wrpr %%o5, 0x0, %%wstate\n\t" \
"ldx [%%sp + 2047 + 0x70], %%i6\n\t" \ "ldx [%%sp + 2047 + 0x70], %%i6\n\t" \
"ldx [%%sp + 2047 + 0x78], %%i7\n\t" \ "ldx [%%sp + 2047 + 0x78], %%i7\n\t" \
"wrpr %%g0, 0x94, %%pstate\n\t" \ "wrpr %%g0, 0x94, %%pstate\n\t" \
"mov %%l2, %%g6\n\t" \ "mov %%l2, %%g6\n\t" \
"ldx [%%g6 + %7], %%g4\n\t" \ "ldx [%%g6 + %6], %%g4\n\t" \
"wrpr %%g0, 0x96, %%pstate\n\t" \ "wrpr %%g0, 0x96, %%pstate\n\t" \
"andcc %%o7, %6, %%g0\n\t" \ "brz,pt %%o7, 1f\n\t" \
"beq,pt %%icc, 1f\n\t" \
" mov %%g7, %0\n\t" \ " mov %%g7, %0\n\t" \
"b,a ret_from_syscall\n\t" \ "b,a ret_from_syscall\n\t" \
"1:\n\t" \ "1:\n\t" \
: "=&r" (last) \ : "=&r" (last) \
: "0" (next->thread_info), \ : "0" (next->thread_info), \
"i" (TI_WSTATE), "i" (TI_KSP), "i" (TI_FLAGS), "i" (TI_CWP), \ "i" (TI_WSTATE), "i" (TI_KSP), "i" (TI_NEW_CHILD), \
"i" (_TIF_NEWCHILD), "i" (TI_TASK) \ "i" (TI_CWP), "i" (TI_TASK) \
: "cc", \ : "cc", \
"g1", "g2", "g3", "g7", \ "g1", "g2", "g3", "g7", \
"l2", "l3", "l4", "l5", "l6", "l7", \ "l2", "l3", "l4", "l5", "l6", "l7", \
......
...@@ -47,7 +47,9 @@ struct thread_info { ...@@ -47,7 +47,9 @@ struct thread_info {
struct pt_regs *kregs; struct pt_regs *kregs;
struct exec_domain *exec_domain; struct exec_domain *exec_domain;
int preempt_count; /* 0 => preemptable, <0 => BUG */ int preempt_count; /* 0 => preemptable, <0 => BUG */
int __pad; __u8 new_child;
__u8 syscall_noerror;
__u16 __pad;
unsigned long *utraps; unsigned long *utraps;
...@@ -87,6 +89,8 @@ struct thread_info { ...@@ -87,6 +89,8 @@ struct thread_info {
#define TI_KREGS 0x00000028 #define TI_KREGS 0x00000028
#define TI_EXEC_DOMAIN 0x00000030 #define TI_EXEC_DOMAIN 0x00000030
#define TI_PRE_COUNT 0x00000038 #define TI_PRE_COUNT 0x00000038
#define TI_NEW_CHILD 0x0000003c
#define TI_SYS_NOERROR 0x0000003d
#define TI_UTRAPS 0x00000040 #define TI_UTRAPS 0x00000040
#define TI_REG_WINDOW 0x00000048 #define TI_REG_WINDOW 0x00000048
#define TI_RWIN_SPTRS 0x000003c8 #define TI_RWIN_SPTRS 0x000003c8
...@@ -219,10 +223,10 @@ register struct thread_info *current_thread_info_reg asm("g6"); ...@@ -219,10 +223,10 @@ register struct thread_info *current_thread_info_reg asm("g6");
#define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */ #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
#define TIF_NEWSIGNALS 6 /* wants new-style signals */ #define TIF_NEWSIGNALS 6 /* wants new-style signals */
#define TIF_32BIT 7 /* 32-bit binary */ #define TIF_32BIT 7 /* 32-bit binary */
#define TIF_NEWCHILD 8 /* just-spawned child process */ /* flag bit 8 is available */
#define TIF_SECCOMP 9 /* secure computing */ #define TIF_SECCOMP 9 /* secure computing */
#define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */ #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
#define TIF_SYSCALL_SUCCESS 11 /* flag bit 11 is available */
/* NOTE: Thread flags >= 12 should be ones we have no interest /* NOTE: Thread flags >= 12 should be ones we have no interest
* in using in assembly, else we can't use the mask as * in using in assembly, else we can't use the mask as
* an immediate value in instructions such as andcc. * an immediate value in instructions such as andcc.
...@@ -239,10 +243,8 @@ register struct thread_info *current_thread_info_reg asm("g6"); ...@@ -239,10 +243,8 @@ register struct thread_info *current_thread_info_reg asm("g6");
#define _TIF_UNALIGNED (1<<TIF_UNALIGNED) #define _TIF_UNALIGNED (1<<TIF_UNALIGNED)
#define _TIF_NEWSIGNALS (1<<TIF_NEWSIGNALS) #define _TIF_NEWSIGNALS (1<<TIF_NEWSIGNALS)
#define _TIF_32BIT (1<<TIF_32BIT) #define _TIF_32BIT (1<<TIF_32BIT)
#define _TIF_NEWCHILD (1<<TIF_NEWCHILD)
#define _TIF_SECCOMP (1<<TIF_SECCOMP) #define _TIF_SECCOMP (1<<TIF_SECCOMP)
#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT) #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
#define _TIF_SYSCALL_SUCCESS (1<<TIF_SYSCALL_SUCCESS)
#define _TIF_ABI_PENDING (1<<TIF_ABI_PENDING) #define _TIF_ABI_PENDING (1<<TIF_ABI_PENDING)
#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG) #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment