xtensa fixes for 3.12
Max Filippov
maintainerv2 cover xtensa fixes for 3.12
Hi Chris,
This is the second version of late 3.12 fixes, changes v1->v2:
xtensa: fix fast_syscall_spill_registers_fixup: set windowstart bit for
the current register frame in the fast_syscall_spill_registers_fixup; expand comments, add FIXME mark.
xtensa: don't use alternate signal stack on threads: no changes.
I can post the third version if using a1 instead of a2 in the _spill_registers .Lc12 is fine.
You can pull these changes from my git tree,
the following changes since commit 61e6cfa80de5760bbe406f4e815b7739205754d2:
Linux 3.12-rc5 (2013-10-13 15:41:28 -0700)
are available in the git repository at:
git://github.com/jcmvbkbc/linux-xtensa.git xtensa-fixes-for-upstream
for you to fetch changes up to cbcc64e11437f701121e71ca55ff0eb9815af530:
xtensa: don't use alternate signal stack on threads (2013-10-26 04:39:13 +0400)
----------------------------------------------------------------
Baruch Siach (1):
xtensa: don't use alternate signal stack on threads
Max Filippov (1):
xtensa: fix fast_syscall_spill_registers_fixup
arch/xtensa/kernel/entry.S | 64 +++++++++++++++++++++++++++++++-------------- arch/xtensa/kernel/signal.c | 2 +- 2 files changed, 46 insertions(+), 20 deletions(-)
Signature · 1 line
1.8.1.4
Max Filippov
maintainerPATCH v2 1/2 xtensa: fix fast_syscall_spill_registers_fixup
fast_syscall_spill_registers_fixup was not correctly updated by the 'keep a3 and excsave1 on entry to exception handlers' patch: it doesn't preserve a3 that it gets on entry, breaking _spill_registers in case of page fault on stack during register spilling, leading to unhandled exception in kernel mode.
Preserve a3 by saving it in the original _spill_registers stack frame's a3 during exception handling and restoring it afterwards.
Also fix comments and function bounds annotations.
--- arch/xtensa/kernel/entry.S | 64 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 19 deletions(-)
arch/xtensa/kernel/entry.S +45 -19
@@ -1064,6 +1064,9 @@ ENDPROC(fast_syscall_xtensa) * excsave_1: dispatch table * * Note: We assume the stack pointer is EXC_TABLE_KSTK in the fixup handler. + * FIXME: this may be wrong in case we enter _spill_registers with 4 live + * registers, followed by a 12-register live window: .Lc12 in the + * _spill_registers would use a2 then. */ ENTRY(fast_syscall_spill_registers)
@@ -1117,12 +1120,19 @@ ENDPROC(fast_syscall_spill_registers) * We basically restore WINDOWBASE and WINDOWSTART to the condition when * we entered the spill routine and jump to the user exception handler. * + * Note that we only need to restore the bits in windowstart that have not + * been spilled yet by the _spill_register routine. Luckily, a3 contains a + * rotated windowstart with only those bits set for frames that haven't been + * spilled yet. Because a3 is rotated such that bit 0 represents the register + * frame for the current windowbase - 1, we need to rotate a3 left by the + * value of the current windowbase + 1 and move it to windowstart. + * * a0: value of depc, original value in depc * a2: trashed, original value in EXC_TABLE_DOUBLE_SAVE * a3: exctable, original value in excsave1 */ -fast_syscall_spill_registers_fixup: +ENTRY(fast_syscall_spill_registers_fixup) rsr a2, windowbase # get current windowbase (a2 is saved) xsr a0, depc # restore depc and a0
@@ -1131,25 +1141,34 @@ fast_syscall_spill_registers_fixup: /* We need to make sure the current registers (a0-a3) are preserved. * To do this, we simply set the bit for the current window frame * in WS, so that the exception handlers save them to the task stack. + * + * Note: we use a3 to set the windowbase, so we take a special care + * of it, saving it in the original _spill_registers frame across + * the exception handler call. */ xsr a3, excsave1 # get spill-mask - slli a2, a3, 1 # shift left by one + slli a3, a3, 1 # shift left by one + addi a3, a3, 1 # set the bit for the current window frame - slli a3, a2, 32-WSBITS - src a2, a2, a3 # a1 = xxwww1yyxxxwww1yy...... + slli a2, a3, 32-WSBITS + src a2, a3, a2 # a2 = xxwww1yyxxxwww1yy...... wsr a2, windowstart # set corrected windowstart - rsr a3, excsave1 - l32i a2, a3, EXC_TABLE_DOUBLE_SAVE # restore a2 - l32i a3, a3, EXC_TABLE_PARAM # original WB (in user task) + srli a3, a3, 1 + rsr a2, excsave1 + l32i a2, a2, EXC_TABLE_DOUBLE_SAVE # restore a2 + xsr a2, excsave1 + s32i a3, a2, EXC_TABLE_DOUBLE_SAVE # save a3 + l32i a3, a2, EXC_TABLE_PARAM # original WB (in user task) + xsr a2, excsave1 /* Return to the original (user task) WINDOWBASE. * We leave the following frame behind: * a0, a1, a2 same - * a3: trashed (saved in excsave_1) + * a3: trashed (saved in EXC_TABLE_DOUBLE_SAVE) * depc: depc (we have to return to that address) - * excsave_1: a3 + * excsave_1: exctable */ wsr a3, windowbase
@@ -1159,9 +1178,9 @@ fast_syscall_spill_registers_fixup: * a0: return address * a1: used, stack pointer * a2: kernel stack pointer - * a3: available, saved in EXCSAVE_1 + * a3: available * depc: exception address - * excsave: a3 + * excsave: exctable * Note: This frame might be the same as above. */
@@ -1181,9 +1200,12 @@ fast_syscall_spill_registers_fixup: rsr a0, exccause addx4 a0, a0, a3 # find entry in table l32i a0, a0, EXC_TABLE_FAST_USER # load handler + l32i a3, a3, EXC_TABLE_DOUBLE_SAVE jx a0 -fast_syscall_spill_registers_fixup_return: +ENDPROC(fast_syscall_spill_registers_fixup) + +ENTRY(fast_syscall_spill_registers_fixup_return) /* When we return here, all registers have been restored (a2: DEPC) */
@@ -1191,13 +1213,13 @@ fast_syscall_spill_registers_fixup_return: /* Restore fixup handler. */ - xsr a3, excsave1 - movi a2, fast_syscall_spill_registers_fixup - s32i a2, a3, EXC_TABLE_FIXUP - s32i a0, a3, EXC_TABLE_DOUBLE_SAVE - rsr a2, windowbase - s32i a2, a3, EXC_TABLE_PARAM - l32i a2, a3, EXC_TABLE_KSTK + rsr a2, excsave1 + s32i a3, a2, EXC_TABLE_DOUBLE_SAVE + movi a3, fast_syscall_spill_registers_fixup + s32i a3, a2, EXC_TABLE_FIXUP + rsr a3, windowbase + s32i a3, a2, EXC_TABLE_PARAM + l32i a2, a2, EXC_TABLE_KSTK /* Load WB at the time the exception occurred. */
@@ -1206,8 +1228,12 @@ fast_syscall_spill_registers_fixup_return: wsr a3, windowbase rsync + rsr a3, excsave1 + l32i a3, a3, EXC_TABLE_DOUBLE_SAVE + rfde +ENDPROC(fast_syscall_spill_registers_fixup_return) /* * spill all registers.
Signature · 1 line
1.8.1.4
Max Filippov
maintainerPATCH v2 2/2 xtensa: don't use alternate signal stack on threads
In reply to Max FilippovFrom: Baruch Siach <[email protected]>
According to create_thread(3): "The new thread does not inherit the creating thread's alternate signal stack". Since commit f9a3879a (Fix sigaltstack corruption among cloned threads), current->sas_ss_size is set to 0 for cloned processes sharing VM with their parent. Don't use the (nonexistent) alternate signal stack in this case. This has been broken since commit 29c4dfd9 ([XTENSA] Remove non-rt signal handling).
Fixes the SA_ONSTACK part of the nptl/tst-cancel20 test from uClibc.
--- arch/xtensa/kernel/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/xtensa/kernel/signal.c +1 -1
@@ -341,7 +341,7 @@ static int setup_frame(int sig, struct k_sigaction *ka, siginfo_t *info, sp = regs->areg[1 ]; -if ((ka->sa.sa_flags &SA_ONSTACK ) !=0 && !on_sig_stack (sp)) { +if ((ka->sa.sa_flags &SA_ONSTACK ) !=0 &&sas_ss_flags (sp) ==0 ) { sp = current->sas_ss_sp + current->sas_ss_size; }
Signature · 1 line
1.8.1.4