Skip to content

Commit 7a5d2a2

Browse files
dcpleungcarlescufi
authored andcommitted
xtensa: userspace: swap page tables at context restore
Swap page tables at exit of exception handler if we are going to be restored to another thread context. Or else we would be using the outgoing thread's page tables which is not going to work correctly due to mapping and permissions. Signed-off-by: Daniel Leung <[email protected]>
1 parent c9c88a4 commit 7a5d2a2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

arch/xtensa/include/xtensa-asm2-s.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ _do_call_\@:
507507
* spills to the right place.
508508
*/
509509
beq a6, a1, _restore_\@
510+
511+
#ifndef CONFIG_USERSPACE
510512
l32i a1, a1, 0
511513
l32i a0, a1, ___xtensa_irq_bsa_t_a0_OFFSET
512514
addi a1, a1, ___xtensa_irq_bsa_t_SIZEOF
@@ -516,7 +518,37 @@ _do_call_\@:
516518
*/
517519
SPILL_ALL_WINDOWS
518520
#endif
521+
522+
/* Restore A1 stack pointer from "next" handle. */
519523
mov a1, a6
524+
#else
525+
/* With userspace, we cannot simply restore A1 stack pointer
526+
* at this pointer because we need to swap page tables to
527+
* the incoming thread, and we do not want to call that
528+
* function with thread's stack. So we stash the new stack
529+
* pointer into A2 first, then move it to A1 after we have
530+
* swapped the page table.
531+
*/
532+
mov a2, a6
533+
534+
/* Need to switch page tables because the "next" handle
535+
* returned above is not the same handle as we started
536+
* with. This means we are being restored to another
537+
* thread.
538+
*/
539+
rsr a6, ZSR_CPU
540+
l32i a6, a6, ___cpu_t_current_OFFSET
541+
542+
call4 z_xtensa_swap_update_page_tables
543+
l32i a1, a1, 0
544+
l32i a0, a1, ___xtensa_irq_bsa_t_a0_OFFSET
545+
addi a1, a1, ___xtensa_irq_bsa_t_SIZEOF
546+
547+
SPILL_ALL_WINDOWS
548+
549+
/* Moved stashed stack pointer to A1 to restore stack. */
550+
mov a1, a2
551+
#endif
520552

521553
_restore_\@:
522554
j _restore_context

0 commit comments

Comments
 (0)