powerpc: Refactor verification of MSR_RI
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Mon, 23 Aug 2021 08:24:21 +0000 (08:24 +0000)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 26 Aug 2021 11:21:07 +0000 (21:21 +1000)
40x and BOOKE don't have MSR_RI therefore all tests involving
MSR_RI may be problematic on those plateforms.

Create helpers to check or set MSR_RI in regs, and use them
in common code.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/c2fb93708196734f4176dda334aaa3055f213b89.1629707037.git.christophe.leroy@csgroup.eu
arch/powerpc/include/asm/ptrace.h
arch/powerpc/kernel/interrupt.c
arch/powerpc/kernel/traps.c
arch/powerpc/mm/book3s64/slb.c
arch/powerpc/platforms/embedded6xx/holly.c
arch/powerpc/platforms/embedded6xx/mpc7448_hpc2.c
arch/powerpc/platforms/pasemi/idle.c
arch/powerpc/platforms/powernv/opal.c
arch/powerpc/platforms/pseries/ras.c
arch/powerpc/sysdev/fsl_rio.c
arch/powerpc/xmon/xmon.c

index 5114ddba6f164ca426d7ca457309bbce796afe08..f9c235c1d6ce258a96d04b59696dff30c2bbc977 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/err.h>
 #include <uapi/asm/ptrace.h>
 #include <asm/asm-const.h>
+#include <asm/reg.h>
 
 #ifndef __ASSEMBLY__
 struct pt_regs
@@ -272,6 +273,28 @@ static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc)
        regs->gpr[3] = rc;
 }
 
+static inline bool cpu_has_msr_ri(void)
+{
+       return !IS_ENABLED(CONFIG_BOOKE) && !IS_ENABLED(CONFIG_40x);
+}
+
+static inline bool regs_is_unrecoverable(struct pt_regs *regs)
+{
+       return unlikely(cpu_has_msr_ri() && !(regs->msr & MSR_RI));
+}
+
+static inline void regs_set_recoverable(struct pt_regs *regs)
+{
+       if (cpu_has_msr_ri())
+               regs_set_return_msr(regs, regs->msr | MSR_RI);
+}
+
+static inline void regs_set_unrecoverable(struct pt_regs *regs)
+{
+       if (cpu_has_msr_ri())
+               regs_set_return_msr(regs, regs->msr & ~MSR_RI);
+}
+
 #define arch_has_single_step() (1)
 #define arch_has_block_step()  (true)
 #define ARCH_HAS_USER_SINGLE_STEP_REPORT
index 531f0a1dbabc724733274e0bbd60213e28ffebfa..a73f3f70a6576ff9ab4a1450a123e8d011837a93 100644 (file)
@@ -92,8 +92,7 @@ notrace long system_call_exception(long r3, long r4, long r5,
        CT_WARN_ON(ct_state() == CONTEXT_KERNEL);
        user_exit_irqoff();
 
-       if (!IS_ENABLED(CONFIG_BOOKE) && !IS_ENABLED(CONFIG_40x))
-               BUG_ON(!(regs->msr & MSR_RI));
+       BUG_ON(regs_is_unrecoverable(regs));
        BUG_ON(!(regs->msr & MSR_PR));
        BUG_ON(arch_irq_disabled_regs(regs));
 
@@ -462,8 +461,7 @@ notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs)
 {
        unsigned long ret;
 
-       if (!IS_ENABLED(CONFIG_BOOKE) && !IS_ENABLED(CONFIG_40x))
-               BUG_ON(!(regs->msr & MSR_RI));
+       BUG_ON(regs_is_unrecoverable(regs));
        BUG_ON(arch_irq_disabled_regs(regs));
        CT_WARN_ON(ct_state() == CONTEXT_USER);
 
@@ -494,8 +492,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs)
        bool stack_store = current_thread_info()->flags &
                                                _TIF_EMULATE_STACK_STORE;
 
-       if (!IS_ENABLED(CONFIG_BOOKE) && !IS_ENABLED(CONFIG_40x) &&
-           unlikely(!(regs->msr & MSR_RI)))
+       if (regs_is_unrecoverable(regs))
                unrecoverable_exception(regs);
        /*
         * CT_WARN_ON comes here via program_check_exception,
index 5463d201d46576a70ecae141f442c90bff5b6cd8..3a344f5265c220c0317ebf671a85ddfebb502785 100644 (file)
@@ -428,7 +428,7 @@ void hv_nmi_check_nonrecoverable(struct pt_regs *regs)
        return;
 
 nonrecoverable:
-       regs_set_return_msr(regs, regs->msr & ~MSR_RI);
+       regs_set_unrecoverable(regs);
 #endif
 }
 DEFINE_INTERRUPT_HANDLER_NMI(system_reset_exception)
@@ -498,7 +498,7 @@ out:
                die("Unrecoverable nested System Reset", regs, SIGABRT);
 #endif
        /* Must die if the interrupt is not recoverable */
-       if (!(regs->msr & MSR_RI)) {
+       if (regs_is_unrecoverable(regs)) {
                /* For the reason explained in die_mce, nmi_exit before die */
                nmi_exit();
                die("Unrecoverable System Reset", regs, SIGABRT);
@@ -550,7 +550,7 @@ static inline int check_io_access(struct pt_regs *regs)
                        printk(KERN_DEBUG "%s bad port %lx at %p\n",
                               (*nip & 0x100)? "OUT to": "IN from",
                               regs->gpr[rb] - _IO_BASE, nip);
-                       regs_set_return_msr(regs, regs->msr | MSR_RI);
+                       regs_set_recoverable(regs);
                        regs_set_return_ip(regs, extable_fixup(entry));
                        return 1;
                }
@@ -840,7 +840,7 @@ DEFINE_INTERRUPT_HANDLER_NMI(machine_check_exception)
 
 bail:
        /* Must die if the interrupt is not recoverable */
-       if (!(regs->msr & MSR_RI))
+       if (regs_is_unrecoverable(regs))
                die_mce("Unrecoverable Machine check", regs, SIGBUS);
 
 #ifdef CONFIG_PPC_BOOK3S_64
index c91bd85eb90e3b3a2f876c5528c3241dde4241e4..f0037bcc47a0eb57a6f3aaf9062fa0bb43843705 100644 (file)
@@ -822,7 +822,7 @@ DEFINE_INTERRUPT_HANDLER_RAW(do_slb_fault)
        /* IRQs are not reconciled here, so can't check irqs_disabled */
        VM_WARN_ON(mfmsr() & MSR_EE);
 
-       if (unlikely(!(regs->msr & MSR_RI)))
+       if (regs_is_unrecoverable(regs))
                return -EINVAL;
 
        /*
index 85521b3e7098406b501191472560d5517b367f1a..7a85b117f7a49e87f80c449bc3583dd970e3df58 100644 (file)
@@ -251,7 +251,7 @@ static int ppc750_machine_check_exception(struct pt_regs *regs)
        /* Are we prepared to handle this fault */
        if ((entry = search_exception_tables(regs->nip)) != NULL) {
                tsi108_clear_pci_cfg_error();
-               regs_set_return_msr(regs, regs->msr | MSR_RI);
+               regs_set_recoverable(regs);
                regs_set_return_ip(regs, extable_fixup(entry));
                return 1;
        }
index d8da6a483e59101eb92eb006c2da15215c4490eb..9eb9abb5bce2574bc3acc9b614a52e08e1d6ca57 100644 (file)
@@ -173,7 +173,7 @@ static int mpc7448_machine_check_exception(struct pt_regs *regs)
        /* Are we prepared to handle this fault */
        if ((entry = search_exception_tables(regs->nip)) != NULL) {
                tsi108_clear_pci_cfg_error();
-               regs_set_return_msr(regs, regs->msr | MSR_RI);
+               regs_set_recoverable(regs);
                regs_set_return_ip(regs, extable_fixup(entry));
                return 1;
        }
index 9b88e3cded7d2dc07d165444688071d9c51a3b95..2a5b84268b773e7c3d62843f2feeb285fa0254d5 100644 (file)
@@ -58,7 +58,7 @@ static int pasemi_system_reset_exception(struct pt_regs *regs)
        restore_astate(hard_smp_processor_id());
 
        /* everything handled */
-       regs_set_return_msr(regs, regs->msr | MSR_RI);
+       regs_set_recoverable(regs);
        return 1;
 }
 
index 2835376e61a495c1f8c22b160fadfb232bc0055b..e9d18519e650bb1a13dad68e9fefecea0f440fb6 100644 (file)
@@ -588,7 +588,7 @@ static int opal_recover_mce(struct pt_regs *regs,
 {
        int recovered = 0;
 
-       if (!(regs->msr & MSR_RI)) {
+       if (regs_is_unrecoverable(regs)) {
                /* If MSR_RI isn't set, we cannot recover */
                pr_err("Machine check interrupt unrecoverable: MSR(RI=0)\n");
                recovered = 0;
index 167f2e1b8d39cd0d94d89c09ba247f1b7280d342..56092dccfdb8050babf2fada0ac3e38d485d601b 100644 (file)
@@ -783,7 +783,7 @@ static int recover_mce(struct pt_regs *regs, struct machine_check_event *evt)
 {
        int recovered = 0;
 
-       if (!(regs->msr & MSR_RI)) {
+       if (regs_is_unrecoverable(regs)) {
                /* If MSR_RI isn't set, we cannot recover */
                pr_err("Machine check interrupt unrecoverable: MSR(RI=0)\n");
                recovered = 0;
index 5a95b8ea23d8c3c130704d15daa161a87ad20abf..ff7906b48ca1e99c8d619daa89ab4c7d2c94927b 100644 (file)
@@ -108,7 +108,7 @@ int fsl_rio_mcheck_exception(struct pt_regs *regs)
                                 __func__);
                        out_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR),
                                 0);
-                       regs_set_return_msr(regs, regs->msr | MSR_RI);
+                       regs_set_recoverable(regs);
                        regs_set_return_ip(regs, extable_fixup(entry));
                        return 1;
                }
index ead460b809053455e6c295241e2afe341e9f7e5c..dd8241c009e533dc478f6227bb41dc8464996970 100644 (file)
@@ -482,16 +482,6 @@ static inline void get_output_lock(void) {}
 static inline void release_output_lock(void) {}
 #endif
 
-static inline int unrecoverable_excp(struct pt_regs *regs)
-{
-#if defined(CONFIG_4xx) || defined(CONFIG_PPC_BOOK3E)
-       /* We have no MSR_RI bit on 4xx or Book3e, so we simply return false */
-       return 0;
-#else
-       return ((regs->msr & MSR_RI) == 0);
-#endif
-}
-
 static void xmon_touch_watchdogs(void)
 {
        touch_softlockup_watchdog_sync();
@@ -565,7 +555,7 @@ static int xmon_core(struct pt_regs *regs, volatile int fromipi)
        bp = NULL;
        if ((regs->msr & (MSR_IR|MSR_PR|MSR_64BIT)) == (MSR_IR|MSR_64BIT))
                bp = at_breakpoint(regs->nip);
-       if (bp || unrecoverable_excp(regs))
+       if (bp || regs_is_unrecoverable(regs))
                fromipi = 0;
 
        if (!fromipi) {
@@ -577,7 +567,7 @@ static int xmon_core(struct pt_regs *regs, volatile int fromipi)
                               cpu, BP_NUM(bp));
                        xmon_print_symbol(regs->nip, " ", ")\n");
                }
-               if (unrecoverable_excp(regs))
+               if (regs_is_unrecoverable(regs))
                        printf("WARNING: exception is not recoverable, "
                               "can't continue\n");
                release_output_lock();
@@ -693,7 +683,7 @@ static int xmon_core(struct pt_regs *regs, volatile int fromipi)
                        printf("Stopped at breakpoint %tx (", BP_NUM(bp));
                        xmon_print_symbol(regs->nip, " ", ")\n");
                }
-               if (unrecoverable_excp(regs))
+               if (regs_is_unrecoverable(regs))
                        printf("WARNING: exception is not recoverable, "
                               "can't continue\n");
                remove_bpts();