Skip to contentSkip to conversation

target/ppc: Fix checkstop and add attn instruction

PATCH In review Nicholas Piggin 2 participants 5 messages Jan 18, 2024 – Jan 23, 2024

lore
Share & tools
lore
#0 lore raw

v3 cover target/ppc: Fix checkstop and add attn instruction

Try these again. checkstop fix is mostly unchanged since last posted, but several fixes to attn. Seems to work well enough.

Thanks,
Nick

Nicholas Piggin (2):
target/ppc: Make checkstop actually stop the system target/ppc: Implement attn instruction on BookS 64-bit processors

 target/ppc/cpu.h         | 16 +++++++-
 target/ppc/helper.h      |  1 +
 target/ppc/cpu_init.c    | 82 +++++++++++++++++++++++++++++++++++++---
 target/ppc/excp_helper.c | 52 +++++++++++++++++++------
 target/ppc/translate.c   | 11 ++++++
 roms/skiboot             |  2 +-
 6 files changed, 145 insertions(+), 19 deletions(-)
Signature · 1 line
2.42.0
#1 lore raw

PATCH v3 1/2 target/ppc: Make checkstop actually stop the system

checkstop state does not halt the system, interrupts continue to be serviced, and other CPUs run. Stop the machine with qemu_system_guest_panicked.

Change the logging not to print separately to stderr because a checkstop is a guest error (or perhaps a simulated machine error) rather than a QEMU error. CPU registers are dumped.

---
Since v1:
- Fix loop exit so it stops on the checkstop-causing instruction, rather than after it.

Since v2:
- Use qemu_system_guest_panicked rather than vm_stop (Richard)
- Move away from printing to stderr (Zoltan)
- Reduce changes to log messages.

---
 target/ppc/excp_helper.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
target/ppc/excp_helper.c +19 -8
index 1db6aaf7ee..022adc36c5 100644
@@ -19,6 +19,8 @@
 #include "qemu/osdep.h"
 #include "qemu/main-loop.h"
 #include "qemu/log.h"
+#include "sysemu/sysemu.h"
+#include "sysemu/runstate.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
 #include "internal.h"
@@ -427,20 +429,29 @@ static void powerpc_set_excp_state(PowerPCCPU *cpu, target_ulong vector,
 static void powerpc_mcheck_checkstop(CPUPPCState *env)
 {
     CPUState *cs = env_cpu(env);
+    FILE *f;
 
     if (FIELD_EX64(env->msr, MSR, ME)) {
         return;
     }
 
-    /* Machine check exception is not enabled. Enter checkstop state. */
-    fprintf(stderr, "Machine check while not allowed. "
-            "Entering checkstop state\n");
-    if (qemu_log_separate()) {
-        qemu_log("Machine check while not allowed. "
-                 "Entering checkstop state\n");
+    /*
+     * This stops the machine and logs CPU state without killing QEMU
+     * (like cpu_abort()) so the machine can still be debugged (because
+     * it is often a guest error).
+     */
+
+    f = qemu_log_trylock();
+    if (f) {
+        fprintf(f, "Entering checkstop state: "
+                   "machine check with MSR[ME]=0\n");
+        cpu_dump_state(cs, f, CPU_DUMP_FPU | CPU_DUMP_CCOP);
+        qemu_log_unlock(f);
     }
-    cs->halted = 1;
-    cpu_interrupt_exittb(cs);
+
+    qemu_system_guest_panicked(NULL);
+
+    cpu_loop_exit_noexc(cs);
 }
 
 static void powerpc_excp_40x(PowerPCCPU *cpu, int excp)
Signature · 1 line
2.42.0
#2 lore raw

PATCH v3 2/2 target/ppc: Implement attn instruction on BookS 64-bit processors

In reply to Nicholas Piggin

attn is an implementation-specific instruction that on POWER (and G5/
970) can be enabled with a HID bit (disabled = illegal), and executing it causes the host processor to stop and the service processor to be notified. Generally used for debugging.

Implement attn and make it checkstop the system, which should be good enough for QEMU debugging.

---
Since v1:
- New patch that also uses checkstop function

Since v2:
- Include support for 970.
- Add class attn enable check, similar to check_pow.

---
 target/ppc/cpu.h         | 16 +++++++-
 target/ppc/helper.h      |  1 +
 target/ppc/cpu_init.c    | 82 +++++++++++++++++++++++++++++++++++++---
 target/ppc/excp_helper.c | 59 +++++++++++++++++++----------
 target/ppc/translate.c   | 11 ++++++
 roms/skiboot             |  2 +-
 6 files changed, 143 insertions(+), 28 deletions(-)
target/ppc/cpu.h +15 -1
index 376aee652f..0c6d3e7722 100644
@@ -1384,6 +1384,9 @@ struct CPUArchState {
     /* Power management */
     int (*check_pow)(CPUPPCState *env);
 
+    /* attn instruction enable */
+    int (*check_attn)(CPUPPCState *env);
+
 #if !defined(CONFIG_USER_ONLY)
     void *load_info;  /* holds boot loading state */
 #endif
@@ -1532,6 +1535,7 @@ struct PowerPCCPUClass {
     int n_host_threads;
     void (*init_proc)(CPUPPCState *env);
     int  (*check_pow)(CPUPPCState *env);
+    int  (*check_attn)(CPUPPCState *env);
 };
 
 ObjectClass *ppc_cpu_class_by_name(const char *name);
@@ -2324,6 +2328,8 @@ void ppc_compat_add_property(Object *obj, const char *name,
 #define HID0_NAP            (1 << 22)           /* pre-2.06 */
 #define HID0_HILE           PPC_BIT(19) /* POWER8 */
 #define HID0_POWER9_HILE    PPC_BIT(4)
+#define HID0_ENABLE_ATTN    PPC_BIT(31) /* POWER8 */
+#define HID0_POWER9_ENABLE_ATTN PPC_BIT(3)
 
 /*****************************************************************************/
 /* PowerPC Instructions types definitions                                    */
@@ -2520,6 +2526,8 @@ enum {
     PPC2_MEM_LWSYNC    = 0x0000000000200000ULL,
     /* ISA 2.06 BCD assist instructions                                      */
     PPC2_BCDA_ISA206   = 0x0000000000400000ULL,
+    /* attn instruction found in IBM POWER (including 970)                   */
+    PPC2_ATTN          = 0x0000000000800000ULL,
 
 #define PPC_TCG_INSNS2 (PPC2_BOOKE206 | PPC2_VSX | PPC2_PRCNTL | PPC2_DBRX | \
                         PPC2_ISA205 | PPC2_VSX207 | PPC2_PERM_ISA206 | \
@@ -2529,7 +2537,7 @@ enum {
                         PPC2_ALTIVEC_207 | PPC2_ISA207S | PPC2_DFP | \
                         PPC2_FP_CVT_S64 | PPC2_TM | PPC2_PM_ISA206 | \
                         PPC2_ISA300 | PPC2_ISA310 | PPC2_MEM_LWSYNC | \
-                        PPC2_BCDA_ISA206)
+                        PPC2_BCDA_ISA206 | PPC2_ATTN)
 };
 
 /*****************************************************************************/
@@ -3028,6 +3036,12 @@ static inline int check_pow_nocheck(CPUPPCState *env)
     return 1;
 }
 
+/* attn enable check                                                         */
+static inline int check_attn_none(CPUPPCState *env)
+{
+    return 0;
+}
+
 /*****************************************************************************/
 /* PowerPC implementations definitions                                       */
 
target/ppc/helper.h +1 -0
index cb1b5345fb..cbd94ea51f 100644
@@ -828,5 +828,6 @@ DEF_HELPER_FLAGS_1(fixup_thrm, TCG_CALL_NO_RWG, void, env)
 #if defined(TARGET_PPC64)
 DEF_HELPER_1(clrbhrb, void, env)
 DEF_HELPER_FLAGS_2(mfbhrbe, TCG_CALL_NO_WG, i64, env, i32)
+DEF_HELPER_1(attn, noreturn, env)
 #endif
 #endif
target/ppc/cpu_init.c +76 -6

394 lines not on this page · raw message

target/ppc/excp_helper.c +39 -20

76 lines not on this page · raw message

target/ppc/translate.c +11 -0
index bdd39c89e0..80c10b9bae 100644
@@ -6633,6 +6633,16 @@ static void gen_dform3D(DisasContext *ctx)
 }
 
 #if defined(TARGET_PPC64)
+/* attn */
+static void gen_attn(DisasContext *ctx)
+{
+#if defined(CONFIG_USER_ONLY)
+    GEN_PRIV(ctx);
+#else
+    gen_helper_attn(tcg_env);
+#endif
+}
+
 /* brd */
 static void gen_brd(DisasContext *ctx)
 {
@@ -6664,6 +6674,7 @@ static void gen_brh(DisasContext *ctx)
 
 static opcode_t opcodes[] = {
 #if defined(TARGET_PPC64)
+GEN_HANDLER_E(attn, 0x00, 0x00, 0x08, 0xFFFFFDFF, PPC_NONE, PPC2_ATTN),
 GEN_HANDLER_E(brd, 0x1F, 0x1B, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA310),
 GEN_HANDLER_E(brw, 0x1F, 0x1B, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA310),
 GEN_HANDLER_E(brh, 0x1F, 0x1B, 0x06, 0x0000F801, PPC_NONE, PPC2_ISA310),
roms/skiboot +1 -1
index dbd5de6624..24a7eb3596 160000
@@ -1 +1 @@
-Subproject commit dbd5de6624d7466bb67d1eb4e57bc3a8e2ad9e87
+Subproject commit 24a7eb35966d93455520bc2debdd7954314b638b
Signature · 1 line
2.42.0
#3 lore raw

Re: [PATCH v3 2/2] target/ppc: Implement attn instruction on BookS 64-bit processors

target/ppc/cpu.h static inline int check_pow_nocheck(CPUPPCState *env) · line 3040

Quoted 2 lines · Nicholas Piggin
target/ppc/cpu.h +2 -0
+/* attn enable check                                                         */
+static inline int check_attn_none(CPUPPCState *env)

Don't mark inline ...

target/ppc/cpu_init.c POWERPC_FAMILY(405)(ObjectClass *oc, void *data) · line 2173

Quoted 5 lines
target/ppc/cpu_init.c +1 -0
@@ -2150,6 +2170,7 @@ POWERPC_FAMILY(405)(ObjectClass *oc, void *data)
      dc->desc = "PowerPC 405";
      pcc->init_proc = init_proc_405;
      pcc->check_pow = check_pow_nocheck;
+    pcc->check_attn = check_attn_none;

... since it is never called directly.

r~

#4 lore raw

Re: [PATCH v3 2/2] target/ppc: Implement attn instruction on BookS 64-bit processors

Quoted 6 lines · Richard Henderson

target/ppc/cpu.h static inline int check_pow_nocheck(CPUPPCState *env) · line 3040

Quoted 2 lines · Nicholas Piggin
target/ppc/cpu.h +2 -0
+/* attn enable check                                                         */
+static inline int check_attn_none(CPUPPCState *env)

Don't mark inline ...

Quoted 7 lines

target/ppc/cpu_init.c POWERPC_FAMILY(405)(ObjectClass *oc, void *data) · line 2173

Quoted 5 lines
target/ppc/cpu_init.c +1 -0
@@ -2150,6 +2170,7 @@ POWERPC_FAMILY(405)(ObjectClass *oc, void *data)
      dc->desc = "PowerPC 405";
      pcc->init_proc = init_proc_405;
      pcc->check_pow = check_pow_nocheck;
+    pcc->check_attn = check_attn_none;

... since it is never called directly.

True, I mindlessly followed check_pow_none(). Maybe all those helpers could be uninlined and moved into cpu_init.c.

Thanks,
Nick