Skip to contentSkip to conversation

s390x/cpu: expose the guest crash information

PATCH Superseded Christian Borntraeger 4 participants 6 messages Sep 18, 2017 – Sep 19, 2017

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390x/cpu: expose the guest crash information

From: Jing Liu <[email protected]>

This patch is the s390 implementation of guest crash information, similar to commit d187e08dc4 ("i386/cpu: add crash-information QOM property") and the related commits. We will detect several crash reasons, with the "disabled wait" being the most important one, since this is used by all s390 guests as a "panic like" notification.

Demonstrate the these ways with examples as follows.

1. crash-information QOM property;

Run qemu with -qmp unix:qmp-sock,server, then use utility "qmp-shell" to execute "qom-get" command, and might get the result like,

(QEMU) qom-get path=/machine/cpu[0]/ property=crash-information {"return": {"psw_addr": 1105350, "psw_mask": 562956395872256, "reason":
"disabled wait", "type": "kvm-s390"}}

2. GUEST_PANICKED event reporting;

Run qemu with a socket option, and telnet or nc to that, -chardev socket,id=qmp,port=4444,host=localhost,server \
-mon chardev=qmp,mode=control,pretty=on \
Negotiating the mode by { "execute": "qmp_capabilities" }, and the crash information will be reported on a guest crash event like,

  {
      "timestamp": {
          "seconds": 1499931739,
          "microseconds": 961296
      },
      "event": "GUEST_PANICKED",
      "data": {
          "action": "pause",
          "info": {
              "psw_addr": 1105350,
              "reason": "disabled wait",
              "psw_mask": 562956395872256,
              "type": "kvm-s390"
          }
      }
  }

3. log;

Run qemu with the parameters: -D <logfile> -d guest_errors, to specify the logfile and log item. The results might be,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Guest crashed
KVM-S390 crash parameters: (0x2000180000000 0x10ddc6) KVM-S390 crash reason: disabled wait

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
---
 qapi/run-state.json | 19 ++++++++++++++++--
 target/s390x/cpu.c  | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 target/s390x/cpu.h  |  6 ++++++
 target/s390x/kvm.c  | 29 +++++++++++++++++++++------
 vl.c                |  6 ++++++
 5 files changed, 109 insertions(+), 8 deletions(-)
qapi/run-state.json +17 -2
index d36ff49..3bf65ea 100644
@@ -320,10 +320,12 @@
 #
 # An enumeration of the guest panic information types
 #
+# @kvm-s390: s390 guest panic information type (Since: 2.11)
+#
 # Since: 2.9
 ##
 { 'enum': 'GuestPanicInformationType',
-  'data': [ 'hyper-v'] }
+  'data': [ 'hyper-v', 'kvm-s390' ] }
 
 ##
 # @GuestPanicInformation:
@@ -335,7 +337,8 @@
 {'union': 'GuestPanicInformation',
  'base': {'type': 'GuestPanicInformationType'},
  'discriminator': 'type',
- 'data': { 'hyper-v': 'GuestPanicInformationHyperV' } }
+ 'data': { 'hyper-v': 'GuestPanicInformationHyperV',
+           'kvm-s390': 'GuestPanicInformationKVMS390' } }
 
 ##
 # @GuestPanicInformationHyperV:
@@ -350,3 +353,15 @@
            'arg3': 'uint64',
            'arg4': 'uint64',
            'arg5': 'uint64' } }
+
+##
+# @GuestPanicInformationKVMS390:
+#
+# KVM-S390 specific guest panic information (PSW)
+#
+# Since: 2.11
+##
+{'struct': 'GuestPanicInformationKVMS390',
+ 'data': { 'psw_mask': 'uint64',
+           'psw_addr': 'uint64',
+           'reason': 'str' } }
target/s390x/cpu.c +57 -0

81 lines not on this page · raw message

target/s390x/cpu.h +6 -0
index 0bd97a5..dba32db 100644
@@ -396,6 +396,12 @@ static inline void cpu_get_tb_cpu_state(CPUS390XState* env, target_ulong *pc,
 #define EXCP_IO  7 /* I/O interrupt */
 #define EXCP_MCHK 8 /* machine check */
 
+/* Crash cases. */
+#define EXCP_CRASH_PGM 9
+#define EXCP_CRASH_EXT 10
+#define EXCP_CRASH_WAITPSW 11
+#define EXCP_CRASH_OPEREXC 12
+
 #define INTERRUPT_EXT        (1 << 0)
 #define INTERRUPT_TOD        (1 << 1)
 #define INTERRUPT_CPUTIMER   (1 << 2)
target/s390x/kvm.c +23 -6
index d07763f..950ea42 100644
@@ -1941,15 +1941,31 @@ static bool is_special_wait_psw(CPUState *cs)
     return cs->kvm_run->psw_addr == 0xfffUL;
 }
 
-static void unmanageable_intercept(S390CPU *cpu, const char *str, int pswoffset)
+static void unmanageable_intercept(S390CPU *cpu, int32_t reason, int pswoffset)
 {
     CPUState *cs = CPU(cpu);
+    const char *str;
 
+    switch (reason) {
+    case EXCP_CRASH_PGM:
+        str = "program interrupt";
+        break;
+    case EXCP_CRASH_EXT:
+        str = "external interrupt";
+        break;
+    case EXCP_CRASH_OPEREXC:
+        str = "operation exception loop";
+        break;
+    default:
+        str = "unknown crash reason";
+        break;
+    }
     error_report("Unmanageable %s! CPU%i new PSW: 0x%016lx:%016lx",
                  str, cs->cpu_index, ldq_phys(cs->as, cpu->env.psa + pswoffset),
                  ldq_phys(cs->as, cpu->env.psa + pswoffset + 8));
     s390_cpu_halt(cpu);
-    qemu_system_guest_panicked(NULL);
+    cs->exception_index = reason;
+    qemu_system_guest_panicked(cpu_get_crash_info(cs));
 }
 
 /* try to detect pgm check loops */
@@ -1979,7 +1995,7 @@ static int handle_oper_loop(S390CPU *cpu, struct kvm_run *run)
         !(oldpsw.mask & PSW_MASK_PSTATE) &&
         (newpsw.mask & PSW_MASK_ASC) == (oldpsw.mask & PSW_MASK_ASC) &&
         (newpsw.mask & PSW_MASK_DAT) == (oldpsw.mask & PSW_MASK_DAT)) {
-        unmanageable_intercept(cpu, "operation exception loop",
+        unmanageable_intercept(cpu, EXCP_CRASH_OPEREXC,
                                offsetof(LowCore, program_new_psw));
         return EXCP_HALTED;
     }
@@ -2000,12 +2016,12 @@ static int handle_intercept(S390CPU *cpu)
             r = handle_instruction(cpu, run);
             break;
         case ICPT_PROGRAM:
-            unmanageable_intercept(cpu, "program interrupt",
+            unmanageable_intercept(cpu, EXCP_CRASH_PGM,
                                    offsetof(LowCore, program_new_psw));
             r = EXCP_HALTED;
             break;
         case ICPT_EXT_INT:
-            unmanageable_intercept(cpu, "external interrupt",
+            unmanageable_intercept(cpu, EXCP_CRASH_EXT,
                                    offsetof(LowCore, external_new_psw));
             r = EXCP_HALTED;
             break;
@@ -2016,7 +2032,8 @@ static int handle_intercept(S390CPU *cpu)
                 if (is_special_wait_psw(cs)) {
                     qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
                 } else {
-                    qemu_system_guest_panicked(NULL);
+                    cs->exception_index = EXCP_CRASH_WAITPSW;
+                    qemu_system_guest_panicked(cpu_get_crash_info(cs));
                 }
             }
             r = EXCP_HALTED;
vl.c +6 -0
index 9e62e92..354513a 100644
@@ -1825,6 +1825,12 @@ void qemu_system_guest_panicked(GuestPanicInformation *info)
                           info->u.hyper_v.arg3,
                           info->u.hyper_v.arg4,
                           info->u.hyper_v.arg5);
+        } else if (info->type == GUEST_PANIC_INFORMATION_TYPE_KVM_S390) {
+            qemu_log_mask(LOG_GUEST_ERROR, "KVM-S390 crash parameters: (%#"
+                          PRIx64" %#"PRIx64")\nKVM-S390 crash reason: %s\n",
+                          info->u.kvm_s390.psw_mask,
+                          info->u.kvm_s390.psw_addr,
+                          info->u.kvm_s390.reason);
         }
         qapi_free_GuestPanicInformation(info);
     }
Signature · 1 line
2.9.4
#1 lore raw
Quoted 13 lines

# An enumeration of the guest panic information types #

qapi/run-state.json +3 -1
+# @kvm-s390: s390 guest panic information type (Since: 2.11)
+#
 # Since: 2.9
 ##
 { 'enum': 'GuestPanicInformationType',
-  'data': [ 'hyper-v'] }
+  'data': [ 'hyper-v', 'kvm-s390' ] }
 
 ##
 # @GuestPanicInformation:

qapi/run-state.json line 341

Quoted 6 lines
qapi/run-state.json +2 -1
@@ -335,7 +337,8 @@
 {'union': 'GuestPanicInformation',
  'base': {'type': 'GuestPanicInformationType'},
  'discriminator': 'type',
- 'data': { 'hyper-v': 'GuestPanicInformationHyperV' } }
+ 'data': { 'hyper-v': 'GuestPanicInformationHyperV',
+           'kvm-s390': 'GuestPanicInformationKVMS390' } }

kvm-s390 is wrong. This is general s390x and should be named s390/s390x and GuestPanicInformationS390(x). One can argue about s390 v s390x. See last comment in this mail.

Quoted 33 lines
qapi/run-state.json +12 -0
 ##
 # @GuestPanicInformationHyperV:
@@ -350,3 +353,15 @@
            'arg3': 'uint64',
            'arg4': 'uint64',
            'arg5': 'uint64' } }
+
+##
+# @GuestPanicInformationKVMS390:
+#
+# KVM-S390 specific guest panic information (PSW)
+#
+# Since: 2.11
+##
+{'struct': 'GuestPanicInformationKVMS390',
+ 'data': { 'psw_mask': 'uint64',
+           'psw_addr': 'uint64',
+           'reason': 'str' } }
target/s390x/cpu.c +2 -0
index 74b3e4f..bfaee04 100644
@@ -35,6 +35,8 @@
 #include "qemu/error-report.h"
 #include "trace.h"
 #include "qapi/visitor.h"
+#include "qapi-visit.h"
+#include "sysemu/hw_accel.h"
 #include "exec/exec-all.h"
 #ifndef CONFIG_USER_ONLY
 #include "hw/hw.h"

target/s390x/cpu.c static void s390x_cpu_set_id(Object *obj, Visitor *v, const char *name, · line 286

Quoted 9 lines
target/s390x/cpu.c +6 -0
@@ -276,6 +278,58 @@ static void s390x_cpu_set_id(Object *obj, Visitor *v, const char *name,
     cpu->id = value;
 }
 
+static GuestPanicInformation *s390x_cpu_get_crash_info(CPUState *cs)
+{
+    GuestPanicInformation *panic_info;
+    S390CPU *cpu = S390_CPU(cs);
+
+    cpu_synchronize_state(cs);

Is this the correct place here? Or rephrasing it: in order to detect an crash this should already have been done. E.g. unmanageable_intercept() uses cpu->env.psa, which has to be synchronized (especially for older kernels).

So we should rather make sure that all crash paths have synchronized the state (e.g. in unmanageable_intercept()).
[...]

Quoted 6 lines

index d07763f..950ea42 100644

target/s390x/kvm.c +0 -0
@@ -1941,15 +1941,31 @@ static bool is_special_wait_psw(CPUState *cs)
     return cs->kvm_run->psw_addr == 0xfffUL;
 }

target/s390x/kvm.c static bool is_special_wait_psw(CPUState *cs) · line 1951

Quoted 10 lines
target/s390x/kvm.c +5 -1
 
-static void unmanageable_intercept(S390CPU *cpu, const char *str, int pswoffset)
+static void unmanageable_intercept(S390CPU *cpu, int32_t reason, int pswoffset)
 {
     CPUState *cs = CPU(cpu);
+    const char *str;
 
+    switch (reason) {
+    case EXCP_CRASH_PGM:
+        str = "program interrupt";

program interrupt loop

target/s390x/kvm.c static bool is_special_wait_psw(CPUState *cs) · line 1954

Quoted 3 lines
target/s390x/kvm.c +3 -0
+        break;
+    case EXCP_CRASH_EXT:
+        str = "external interrupt";

... loop

[...]

target/s390x/kvm.c static int handle_intercept(S390CPU *cpu) · line 2036

Quoted 8 lines
target/s390x/kvm.c +2 -1
             break;
@@ -2016,7 +2032,8 @@ static int handle_intercept(S390CPU *cpu)
                 if (is_special_wait_psw(cs)) {
                     qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
                 } else {
-                    qemu_system_guest_panicked(NULL);
+                    cs->exception_index = EXCP_CRASH_WAITPSW;
+                    qemu_system_guest_panicked(cpu_get_crash_info(cs));

Especially because in my latest series ([PATCH v1 00/27] s390x: SMP for TCG (+ cleanups)) this code is also used for TCG.

Signature · 3 lines
Thanks,

David
#2 lore raw
Quoted 10 lines · David Hildenbrand
Quoted 10 lines

# An enumeration of the guest panic information types #

qapi/run-state.json +3 -1
+# @kvm-s390: s390 guest panic information type (Since: 2.11)
+#
 # Since: 2.9
 ##
 { 'enum': 'GuestPanicInformationType',
-  'data': [ 'hyper-v'] }
+  'data': [ 'hyper-v', 'kvm-s390' ] }
Quoted 13 lines

qapi/run-state.json line 341

Quoted 9 lines

##
# @GuestPanicInformation:

qapi/run-state.json +2 -1
@@ -335,7 +337,8 @@
 {'union': 'GuestPanicInformation',
  'base': {'type': 'GuestPanicInformationType'},
  'discriminator': 'type',
- 'data': { 'hyper-v': 'GuestPanicInformationHyperV' } }
+ 'data': { 'hyper-v': 'GuestPanicInformationHyperV',
+           'kvm-s390': 'GuestPanicInformationKVMS390' } }

kvm-s390 is wrong. This is general s390x and should be named s390/s390x and GuestPanicInformationS390(x). One can argue about s390 v s390x. See last comment in this mail.

Yes, will remove the kvm part and only use s390. Not sure about s390 vs. s390x. I slightly prefer the s390 name as in the kernel but I really do not care if we follow the s390x as in QEMU. Conny, any opinion?

[..]

Quoted 13 lines

target/s390x/cpu.c static void s390x_cpu_set_id(Object *obj, Visitor *v, const char *name, · line 286

Quoted 7 lines
target/s390x/cpu.c +6 -0
+static GuestPanicInformation *s390x_cpu_get_crash_info(CPUState *cs)
+{
+    GuestPanicInformation *panic_info;
+    S390CPU *cpu = S390_CPU(cs);
+
+    cpu_synchronize_state(cs);

Is this the correct place here? Or rephrasing it: in order to detect an crash this should already have been done. E.g. unmanageable_intercept() uses cpu->env.psa, which has to be synchronized (especially for older kernels).

Quoted 3 lines

So we should rather make sure that all crash paths have synchronized the state (e.g. in unmanageable_intercept()).
[...]

This code will also be called from common code (e.g. if KVM_RUN returns with EFAULT) so I would like to keep it here. After all cpu_synchronize_state called be called multiple times without any problems.

Quoted 14 lines
Quoted 14 lines

index d07763f..950ea42 100644

target/s390x/kvm.c +2 -1
@@ -1941,15 +1941,31 @@ static bool is_special_wait_psw(CPUState *cs)
     return cs->kvm_run->psw_addr == 0xfffUL;
 }
 
-static void unmanageable_intercept(S390CPU *cpu, const char *str, int pswoffset)
+static void unmanageable_intercept(S390CPU *cpu, int32_t reason, int pswoffset)
 {
     CPUState *cs = CPU(cpu);
+    const char *str;
 
Quoted 5 lines

target/s390x/kvm.c static bool is_special_wait_psw(CPUState *cs) · line 1951

Quoted 3 lines
target/s390x/kvm.c +3 -0
+    switch (reason) {
+    case EXCP_CRASH_PGM:
+        str = "program interrupt";

program interrupt loop

Yes.

Quoted 7 lines

target/s390x/kvm.c static bool is_special_wait_psw(CPUState *cs) · line 1954

Quoted 4 lines
target/s390x/kvm.c +3 -0
+        break;
+    case EXCP_CRASH_EXT:
+        str = "external interrupt";

... loop

yes

Quoted 1 line

[...]

#3 lore raw
Quoted 9 lines · Christian Borntraeger
Quoted 3 lines · David Hildenbrand

kvm-s390 is wrong. This is general s390x and should be named s390/s390x and GuestPanicInformationS390(x). One can argue about s390 v s390x. See last comment in this mail.

Yes, will remove the kvm part and only use s390. Not sure about s390 vs. s390x. I slightly prefer the s390 name as in the kernel but I really do not care if we follow the s390x as in QEMU. Conny, any opinion?

Note that qemu is inconsistent here:

target/s390x
tcg/s390

which is arguably exactly wrong because target/s390x handles 32-bit mode, whereas tcg/s390 requires 64-bit mode. ;-)

r~

#4 lore raw
In reply to Christian Borntraeger
Quoted 10 lines · Christian Borntraeger

From: Jing Liu <[email protected]>

This patch is the s390 implementation of guest crash information, similar to commit d187e08dc4 ("i386/cpu: add crash-information QOM property") and the related commits. We will detect several crash reasons, with the "disabled wait" being the most important one, since this is used by all s390 guests as a "panic like" notification.

qapi/run-state.json +1 -0
+

qapi/run-state.json line 366

Quoted 10 lines
qapi/run-state.json +10 -0
+##
+# @GuestPanicInformationKVMS390:
+#
+# KVM-S390 specific guest panic information (PSW)
+#
+# Since: 2.11
+##
+{'struct': 'GuestPanicInformationKVMS390',
+ 'data': { 'psw_mask': 'uint64',
+           'psw_addr': 'uint64',

New interfaces should favor '-' over '_'; is there any reason we can't name these 'psw-mask' and 'pws-addr'?

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#5 lore raw
Quoted 10 lines · Eric Blake
Quoted 8 lines · Christian Borntraeger

From: Jing Liu <[email protected]>

This patch is the s390 implementation of guest crash information, similar to commit d187e08dc4 ("i386/cpu: add crash-information QOM property") and the related commits. We will detect several crash reasons, with the "disabled wait" being the most important one, since this is used by all s390 guests as a "panic like" notification.

Quoted 14 lines

qapi/run-state.json line 366

Quoted 11 lines
qapi/run-state.json +11 -0
+
+##
+# @GuestPanicInformationKVMS390:
+#
+# KVM-S390 specific guest panic information (PSW)
+#
+# Since: 2.11
+##
+{'struct': 'GuestPanicInformationKVMS390',
+ 'data': { 'psw_mask': 'uint64',
+           'psw_addr': 'uint64',

New interfaces should favor '-' over '_'; is there any reason we can't name these 'psw-mask' and 'pws-addr'?

Can change.