powerpc/64s/interrupt: halt early boot interrupts if paca is not set up
authorNicholas Piggin <npiggin@gmail.com>
Mon, 26 Sep 2022 05:56:20 +0000 (15:56 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 28 Sep 2022 09:22:13 +0000 (19:22 +1000)
Ensure r13 is zero from very early in boot until it gets set to the
boot paca pointer. This allows early program and mce handlers to halt
if there is no valid paca, rather than potentially run off into the
weeds. This preserves register and memory contents for low level
debugging tools.

Nothing could be printed to console at this point in any case because
even udbg is only set up after the boot paca is set, so this shouldn't
be missed.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220926055620.2676869-6-npiggin@gmail.com
arch/powerpc/kernel/exceptions-64s.S
arch/powerpc/kernel/head_64.S
arch/powerpc/kernel/setup_64.c

index 8d658c7..c3b803d 100644 (file)
@@ -725,8 +725,8 @@ END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  * userspace starts.
  */
 .macro EARLY_BOOT_FIXUP
-#ifdef CONFIG_CPU_LITTLE_ENDIAN
 BEGIN_FTR_SECTION
+#ifdef CONFIG_CPU_LITTLE_ENDIAN
        tdi   0,0,0x48    // Trap never, or in reverse endian: b . + 8
        b     2f          // Skip trampoline if endian is correct
        .long 0xa643707d  // mtsprg  0, r11      Backup r11
@@ -753,8 +753,19 @@ BEGIN_FTR_SECTION
        mtsrr0 r11        // Restore SRR0
        mfsprg r11, 0     // Restore r11
 2:
-END_FTR_SECTION(0, 1)     // nop out after boot
 #endif
+       /*
+        * program check could hit at any time, and pseries can not block
+        * MSR[ME] in early boot. So check if there is anything useful in r13
+        * yet, and spin forever if not.
+        */
+       mtsprg  0, r11
+       mfcr    r11
+       cmpdi   r13, 0
+       beq     .
+       mtcr    r11
+       mfsprg  r11, 0
+END_FTR_SECTION(0, 1)     // nop out after boot
 .endm
 
 /*
index c63e0c0..cfc09a9 100644 (file)
@@ -487,6 +487,9 @@ __start_initialization_multiplatform:
        /* Make sure we are running in 64 bits mode */
        bl      enable_64b_mode
 
+       /* Zero r13 (paca) so early program check / mce don't use it */
+       li      r13,0
+
        /* Get TOC pointer (current runtime address) */
        bl      relative_toc
 
index 6312a3f..a0dee73 100644 (file)
@@ -364,6 +364,7 @@ void __init early_setup(unsigned long dt_ptr)
         */
        initialise_paca(&boot_paca, 0);
        fixup_boot_paca(&boot_paca);
+       WARN_ON(local_paca != 0);
        setup_paca(&boot_paca); /* install the paca into registers */
 
        /* -------- printk is now safe to use ------- */