powerpc/64: Sanitise common exit code for interrupts
authorRohan McLure <rmclure@linux.ibm.com>
Thu, 1 Dec 2022 07:10:15 +0000 (18:10 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 2 Dec 2022 09:46:01 +0000 (20:46 +1100)
Interrupt code is shared between Book3E/S 64-bit systems for interrupt
handlers. Ensure that exit code correctly restores non-volatile gprs on
each system when CONFIG_INTERRUPT_SANITIZE_REGISTERS is enabled.

Also introduce macros for clearing/restoring registers on interrupt
entry for when this configuration option is either disabled or enabled.

Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Rohan McLure <rmclure@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20221201071019.1953023-3-rmclure@linux.ibm.com
arch/powerpc/kernel/interrupt_64.S

index 321992c1c9f900881250b2728e3668557e75dd17..dd04b0ba3959ac41927743f2e3b000f30b30a4b1 100644 (file)
@@ -408,9 +408,11 @@ interrupt_return_\srr\()_user: /* make backtraces match the _kernel variant */
 _ASM_NOKPROBE_SYMBOL(interrupt_return_\srr\()_user)
        addi    r3,r1,STACK_INT_FRAME_REGS
        bl      interrupt_exit_user_prepare
+#ifndef CONFIG_INTERRUPT_SANITIZE_REGISTERS
        cmpdi   r3,0
        bne-    .Lrestore_nvgprs_\srr
 .Lrestore_nvgprs_\srr\()_cont:
+#endif
        std     r1,PACA_EXIT_SAVE_R1(r13) /* save r1 for restart */
 #ifdef CONFIG_PPC_BOOK3S
 .Linterrupt_return_\srr\()_user_rst_start:
@@ -424,6 +426,7 @@ _ASM_NOKPROBE_SYMBOL(interrupt_return_\srr\()_user)
        stb     r11,PACAIRQHAPPENED(r13) # clear out possible HARD_DIS
 
 .Lfast_user_interrupt_return_\srr\():
+       SANITIZE_RESTORE_NVGPRS()
 #ifdef CONFIG_PPC_BOOK3S
        .ifc \srr,srr
        lbz     r4,PACASRR_VALID(r13)
@@ -493,9 +496,11 @@ ALT_FTR_SECTION_END_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS)
        b       .       /* prevent speculative execution */
 .Linterrupt_return_\srr\()_user_rst_end:
 
+#ifndef CONFIG_INTERRUPT_SANITIZE_REGISTERS
 .Lrestore_nvgprs_\srr\():
        REST_NVGPRS(r1)
        b       .Lrestore_nvgprs_\srr\()_cont
+#endif
 
 #ifdef CONFIG_PPC_BOOK3S
 interrupt_return_\srr\()_user_restart:
@@ -585,6 +590,7 @@ _ASM_NOKPROBE_SYMBOL(interrupt_return_\srr\()_kernel)
        stb     r11,PACAIRQHAPPENED(r13) // clear the possible HARD_DIS
 
 .Lfast_kernel_interrupt_return_\srr\():
+       SANITIZE_RESTORE_NVGPRS()
        cmpdi   cr1,r3,0
 #ifdef CONFIG_PPC_BOOK3S
        .ifc \srr,srr