[PATCH 2/4] hw/s390x/virtio-ccw: Always deliver NMI to first CPU

Philippe Mathieu-Daudé posted 4 patches 8 months, 3 weeks ago
Maintainers: "Dr. David Alan Gilbert" <dave@treblig.org>, Richard Henderson <richard.henderson@linaro.org>, Helge Deller <deller@gmx.de>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Paolo Bonzini <pbonzini@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Laurent Vivier <laurent@vivier.eu>, Corey Minyard <minyard@acm.org>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, "Cédric Le Goater" <clg@kaod.org>, Nicholas Piggin <npiggin@gmail.com>, "Frédéric Barrat" <fbarrat@linux.ibm.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, David Gibson <david@gibson.dropbear.id.au>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>
[PATCH 2/4] hw/s390x/virtio-ccw: Always deliver NMI to first CPU
Posted by Philippe Mathieu-Daudé 8 months, 3 weeks ago
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 maintainance, update s390_nmi()
to deliver NMI to the first CPU.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 qapi/run-state.json        | 5 +++--
 hw/s390x/s390-virtio-ccw.c | 4 +---
 hmp-commands.hx            | 2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/qapi/run-state.json b/qapi/run-state.json
index 08bc99cb85..a2542f1a50 100644
--- a/qapi/run-state.json
+++ b/qapi/run-state.json
@@ -320,8 +320,9 @@
 #
 # @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 (architecture
+#     specific: on s390x only the first vCPU receive the NMI, on
+#     other architectures all vCPUs receive it). (since 2.4)
 #
 # Since: 2.1
 ##
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 62804cc228..ba1fa6472f 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -605,9 +605,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 ram_addr_t s390_fixup_ram_size(ram_addr_t sz)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 17b5ea839d..2b01bb5926 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -851,7 +851,7 @@ ERST
     },
 SRST
 ``nmi`` *cpu*
-  Inject an NMI on the default CPU (x86/s390) or all CPUs (ppc64).
+  Inject an NMI.
 ERST
 
     {
-- 
2.41.0


Re: [PATCH 2/4] hw/s390x/virtio-ccw: Always deliver NMI to first CPU
Posted by David Hildenbrand 7 months, 4 weeks ago
On 20.02.24 16:08, Philippe Mathieu-Daudé wrote:
> 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 maintainance, update s390_nmi()
> to deliver NMI to the first CPU.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb


Re: [PATCH 2/4] hw/s390x/virtio-ccw: Always deliver NMI to first CPU
Posted by Peter Maydell 7 months, 4 weeks ago
On Tue, 20 Feb 2024 at 15:09, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> 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 maintainance, update s390_nmi()
> to deliver NMI to the first CPU.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  qapi/run-state.json        | 5 +++--
>  hw/s390x/s390-virtio-ccw.c | 4 +---
>  hmp-commands.hx            | 2 +-
>  3 files changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/qapi/run-state.json b/qapi/run-state.json
> index 08bc99cb85..a2542f1a50 100644
> --- a/qapi/run-state.json
> +++ b/qapi/run-state.json
> @@ -320,8 +320,9 @@
>  #
>  # @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 (architecture
> +#     specific: on s390x only the first vCPU receive the NMI, on

"receives"


> +#     other architectures all vCPUs receive it). (since 2.4)

This part isn't really true, because it's machine-specific rather
than architecture-specific (and many architectures don't implement
it at all). But I don't think we want to introduce that doc cleanup into
this patch. Maybe we should leave it as only saying "all vCPUs on x86",
though.

>  #
>  # Since: 2.1
>  ##
> diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
> index 62804cc228..ba1fa6472f 100644
> --- a/hw/s390x/s390-virtio-ccw.c
> +++ b/hw/s390x/s390-virtio-ccw.c
> @@ -605,9 +605,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 ram_addr_t s390_fixup_ram_size(ram_addr_t sz)
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index 17b5ea839d..2b01bb5926 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -851,7 +851,7 @@ ERST
>      },
>  SRST
>  ``nmi`` *cpu*
> -  Inject an NMI on the default CPU (x86/s390) or all CPUs (ppc64).
> +  Inject an NMI.
>  ERST
>
>      {

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM