Skip to content

Commit da59f1d

Browse files
mrutland-armwilldeacon
authored andcommitted
arm64: entry: simplify kernel_exit logic
For historical reasons, the non-KPTI exception return path is duplicated for EL1 and EL0, with the structure: .if \el == 0 [ KPTI handling ] ldr lr, [sp, #S_LR] add sp, sp, #PT_REGS_SIZE // restore sp [ EL0 exception return workaround ] eret .else ldr lr, [sp, #S_LR] add sp, sp, #PT_REGS_SIZE // restore sp [ EL1 exception return workaround ] eret .endif sb This would be simpler and clearer with the common portions factored out, e.g. .if \el == 0 [ KPTI handling ] .endif ldr lr, [sp, #S_LR] add sp, sp, #PT_REGS_SIZE // restore sp .if \el == 0 [ EL0 exception return workaround ] .else [ EL1 exception return workaround ] .endif eret sb This expands to the same code, but is simpler for a human to follow as it avoids duplicates the restore of LR+SP, and makes it clear that the ERET is associated with the SB. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: James Morse <[email protected]> Cc: Rob Herring <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 832dd63 commit da59f1d

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

arch/arm64/kernel/entry.S

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,24 +442,23 @@ alternative_else_nop_endif
442442

443443
.L_skip_tramp_exit_\@:
444444
#endif
445+
.endif
446+
445447
ldr lr, [sp, #S_LR]
446448
add sp, sp, #PT_REGS_SIZE // restore sp
447449

450+
.if \el == 0
448451
/* This must be after the last explicit memory access */
449452
alternative_if ARM64_WORKAROUND_SPECULATIVE_UNPRIV_LOAD
450453
tlbi vale1, xzr
451454
dsb nsh
452455
alternative_else_nop_endif
453-
eret
454456
.else
455-
ldr lr, [sp, #S_LR]
456-
add sp, sp, #PT_REGS_SIZE // restore sp
457-
458457
/* Ensure any device/NC reads complete */
459458
alternative_insn nop, "dmb sy", ARM64_WORKAROUND_1508412
459+
.endif
460460

461461
eret
462-
.endif
463462
sb
464463
.endm
465464

0 commit comments

Comments
 (0)