Commit c489b04fbc for qemu.org

commit c489b04fbc94e7f738704b2b85e88d92ecf5cc6f
Author: Philippe Mathieu-Daudé <philmd@mailo.com>
Date:   Tue Feb 20 14:28:25 2024 +0100

    hw/s390x/virtio-ccw: Always inject NMI to first CPU

    We can trigger NMI from HMP or QMP.

    QEMU maps the NMI to the s390x per-CPU 'RESTART' interrupt.
    Linux guests usually setup this interrupt to trigger kdump
    or crash. Such crashdump can be triggered in QEMU by HMP
    "nmi" or QMP "inject-nmi" commands.

    Using QMP, since we can not select a particular CPU, the first
    CPU is used (CPU#0). See the documentation from commit 795dc6e4
    ("watchdog: Add new Virtual Watchdog action INJECT-NMI"):

      @inject-nmi: a non-maskable interrupt is injected into the
                   first VCPU (all VCPUS on x86) (since 2.4)

    While we can select a particular CPU on HMP, the guest behavior
    is expected to be the same if using CPU #N or CPU #0. Since
    always using CPU#0 simplifies API maintenance , update s390_nmi()
    to inject NMI to the first CPU.

    Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
    Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
    Reviewed-by: David Hildenbrand <david@redhat.com>
    Reviewed-by: Eric Farman <farman@linux.ibm.com>
    Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
    Message-Id: <20260812121232.71958-3-philmd@oss.qualcomm.com>
    Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 7f43cf537f..a29f02b623 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -865,12 +865,13 @@ ERST
         .name       = "nmi",
         .args_type  = "",
         .params     = "",
-        .help       = "inject an NMI",
+        .help       = "Inject an NMI, in a machine-specific way",
         .cmd        = hmp_nmi,
     },
 SRST
 ``nmi`` *cpu*
-  Inject an NMI on the default CPU (x86/s390) or all CPUs (ppc64).
+  Inject an NMI, in a machine-specific way.
+  Not all machines implement NMI handling.
 ERST

     {
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 55131c1a44..a2f373b119 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -727,9 +727,7 @@ static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,

 static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
 {
-    CPUState *cs = qemu_get_cpu(cpu_index);
-
-    s390_cpu_restart(S390_CPU(cs));
+    s390_cpu_restart(S390_CPU(first_cpu));
 }

 static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
diff --git a/qapi/machine.json b/qapi/machine.json
index 9b2248038f..2d63c1bac3 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -432,9 +432,10 @@
 ##
 # @inject-nmi:
 #
-# Injects a Non-Maskable Interrupt into the default CPU (x86/s390) or
-# all CPUs (ppc64).  The command fails when the guest doesn't support
-# injecting.
+# Injects a Non-Maskable Interrupt (machine specific: for example on
+# s390x CCW only the first vCPU receives the NMI, but on x86 machines
+# all vCPUs receive it).  The command fails when the guest doesn't
+# support injecting.
 #
 # Since: 0.14
 #
diff --git a/qapi/run-state.json b/qapi/run-state.json
index a5771ad468..e4fdead1e0 100644
--- a/qapi/run-state.json
+++ b/qapi/run-state.json
@@ -317,8 +317,10 @@
 #
 # @none: nothing is done
 #
-# @inject-nmi: a non-maskable interrupt is injected into the first
-#     VCPU (all VCPUS on x86) (since 2.4)
+# @inject-nmi: a non-maskable interrupt is injected (machine
+#     specific: for example on s390x CCW only the first vCPU
+#     receives the NMI, but on x86 machines all vCPUs receive
+#     it).  (since 2.4)
 #
 # Since: 2.1
 ##