Skip to content

Commit e108843

Browse files
committed
[XTENSA] Fix register corruption for certain processor configurations
For processor configurations that have optional registers (compiler-used but non-coprocessor), user space registers might get corrupted when there are only 4 registers in the current window-frame, ie. register a4 belongs to the oldest frame in the register file. Signed-off-by: Chris Zankel <chris@zankel.net>
1 parent 9f8fcf3 commit e108843

1 file changed

Lines changed: 15 additions & 29 deletions

File tree

‎arch/xtensa/kernel/entry.S‎

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -395,55 +395,49 @@ common_exception_return:
395395
/* Jump if we are returning from kernel exceptions. */
396396

397397
1: l32i a3, a1, PT_PS
398-
_bbsi.l a3, PS_UM_BIT, 2f
399-
j kernel_exception_exit
398+
_bbci.l a3, PS_UM_BIT, 4f
400399

401400
/* Specific to a user exception exit:
402401
* We need to check some flags for signal handling and rescheduling,
403402
* and have to restore WB and WS, extra states, and all registers
404403
* in the register file that were in use in the user task.
405-
*/
406-
407-
2: wsr a3, PS /* disable interrupts */
408-
409-
/* Check for signals (keep interrupts disabled while we read TI_FLAGS)
410-
* Note: PS.INTLEVEL = 0, PS.EXCM = 1
404+
* Note that we don't disable interrupts here.
411405
*/
412406

413407
GET_THREAD_INFO(a2,a1)
414408
l32i a4, a2, TI_FLAGS
415409

416-
/* Enable interrupts again.
417-
* Note: When we get here, we certainly have handled any interrupts.
418-
* (Hint: There is only one user exception frame on stack)
419-
*/
420-
421-
movi a3, 1 << PS_WOE_BIT
422-
423410
_bbsi.l a4, TIF_NEED_RESCHED, 3f
424411
_bbci.l a4, TIF_SIGPENDING, 4f
425412

426413
l32i a4, a1, PT_DEPC
427414
bgeui a4, VALID_DOUBLE_EXCEPTION_ADDRESS, 4f
428-
/* Reenable interrupts and call do_signal() */
429415

430-
wsr a3, PS
416+
/* Call do_signal() */
417+
431418
movi a4, do_signal # int do_signal(struct pt_regs*, sigset_t*)
432419
mov a6, a1
433420
movi a7, 0
434421
callx4 a4
435422
j 1b
436423

437-
3: /* Reenable interrupts and reschedule */
424+
3: /* Reschedule */
438425

439-
wsr a3, PS
440426
movi a4, schedule # void schedule (void)
441427
callx4 a4
442428
j 1b
443429

444-
/* Restore the state of the task and return from the exception. */
430+
4: /* Restore optional registers. */
431+
432+
load_xtregs_opt a1 a2 a4 a5 a6 a7 PT_XTREGS_OPT
445433

446-
4: /* a2 holds GET_CURRENT(a2,a1) */
434+
wsr a3, PS /* disable interrupts */
435+
436+
_bbci.l a3, PS_UM_BIT, kernel_exception_exit
437+
438+
user_exception_exit:
439+
440+
/* Restore the state of the task and return from the exception. */
447441

448442
/* Switch to the user thread WINDOWBASE. Save SP temporarily in DEPC */
449443

@@ -509,10 +503,6 @@ common_exception_return:
509503

510504
kernel_exception_exit:
511505

512-
/* Disable interrupts (a3 holds PT_PS) */
513-
514-
wsr a3, PS
515-
516506
#ifdef PREEMPTIBLE_KERNEL
517507

518508
#ifdef CONFIG_PREEMPT
@@ -591,10 +581,6 @@ kernel_exception_exit:
591581

592582
common_exception_exit:
593583

594-
/* Restore optional registers. */
595-
596-
load_xtregs_opt a1 a3 a4 a5 a6 a7 PT_XTREGS_OPT
597-
598584
/* Restore address registers. */
599585

600586
_bbsi.l a2, 1, 1f

0 commit comments

Comments
 (0)