From: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
To: qemu-devel@nongnu.org
Subject: [PULL 32/56] hw/nmi: Remove @cpu_index argument from nmi_inject()
Date: Sun, 16 Aug 2026 16:45:31 +0200 [thread overview]
Message-ID: <20260816144556.69009-33-philmd@oss.qualcomm.com> (raw)
In-Reply-To: <20260816144556.69009-1-philmd@oss.qualcomm.com>
From: Philippe Mathieu-Daudé <philmd@linaro.org>
nmi_monitor_handle() is not related to the monitor, rename
it as nmi_inject().
Return a boolean value indicating success / failure as
recommended by the Error API since commit e3fe3988d7
("error: Document Error API usage rules").
The 'cpu_index' argument is not used, remove it.
This officially drops the current CPU for HMP command.
Document nmi_inject() as suggested by Peter Maydell in
https://lore.kernel.org/qemu-devel/CAFEAcA-yALySmCJLbitCmYpiZKUXJNOavGJG9RYeo8fKqz7gcw@mail.gmail.com/.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Message-Id: <20260812121232.71958-5-philmd@oss.qualcomm.com>
---
include/hw/core/nmi.h | 24 +++++++++++++++++++++++-
hw/core/nmi.c | 9 ++++-----
hw/ipmi/ipmi.c | 3 +--
hw/watchdog/watchdog.c | 2 +-
system/cpus.c | 3 +--
hmp-commands.hx | 2 +-
6 files changed, 31 insertions(+), 12 deletions(-)
diff --git a/include/hw/core/nmi.h b/include/hw/core/nmi.h
index 4c4ce79071d..851be28257e 100644
--- a/include/hw/core/nmi.h
+++ b/include/hw/core/nmi.h
@@ -46,6 +46,28 @@ struct NMIClass {
void (*nmi_monitor_handler)(NMIState *ns, Error **errp);
};
-void nmi_monitor_handle(int cpu_index, Error **errp);
+/**
+ * nmi_inject: Inject an NMI, in a machine-specific way
+ * @errp: pointer to error object
+ *
+ * This function injects an NMI, in a machine-specific way. The
+ * intention is that this should typically trigger a guest kernel
+ * dump or reboot, and might happen as a result of user request
+ * from the monitor, watchdog timeouts, and similar events.
+ * (For example on the x86 PC it triggers an NMI on all CPUs,
+ * and on s390 it triggers the RESTART interrupt on the first CPU.)
+ *
+ * The NMI is injected by looking for a QOM object which implements
+ * the TYPE_NMI interface, and calling its nmi_monitor_handler method. Usually
+ * it is the machine model class that implements this interface.
+ *
+ * Not all machines implement NMI handling; this function
+ * will return an error if used on a machine which does not
+ * implement NMIs.
+ *
+ * On success, return %true.
+ * On failure, store an error through @errp and return %false.
+ */
+bool nmi_inject(Error **errp);
#endif /* NMI_H */
diff --git a/hw/core/nmi.c b/hw/core/nmi.c
index ff6454437c1..2d890f2995d 100644
--- a/hw/core/nmi.c
+++ b/hw/core/nmi.c
@@ -22,11 +22,8 @@
#include "qemu/osdep.h"
#include "hw/core/nmi.h"
#include "qapi/error.h"
-#include "qemu/module.h"
-#include "monitor/monitor.h"
struct do_nmi_s {
- int cpu_index;
Error *err;
bool handled;
};
@@ -54,19 +51,21 @@ static int nmi_children(Object *o, struct do_nmi_s *ns)
return object_child_foreach_recursive(o, do_nmi, ns);
}
-void nmi_monitor_handle(int cpu_index, Error **errp)
+bool nmi_inject(Error **errp)
{
struct do_nmi_s ns = {
- .cpu_index = cpu_index,
.err = NULL,
.handled = false
};
if (nmi_children(object_get_root(), &ns)) {
error_propagate(errp, ns.err);
+ return false;
} else if (!ns.handled) {
error_setg(errp, "machine does not provide NMIs");
+ return false;
}
+ return true;
}
static const TypeInfo nmi_info = {
diff --git a/hw/ipmi/ipmi.c b/hw/ipmi/ipmi.c
index 74818ff3cea..dedf23cb997 100644
--- a/hw/ipmi/ipmi.c
+++ b/hw/ipmi/ipmi.c
@@ -59,8 +59,7 @@ static int ipmi_do_hw_op(IPMIInterface *s, enum ipmi_op op, int checkonly)
if (checkonly) {
return 0;
}
- /* We don't care what CPU we use. */
- nmi_monitor_handle(0, NULL);
+ nmi_inject(NULL);
return 0;
case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP:
diff --git a/hw/watchdog/watchdog.c b/hw/watchdog/watchdog.c
index 0842fe373ae..5f764a0c1b8 100644
--- a/hw/watchdog/watchdog.c
+++ b/hw/watchdog/watchdog.c
@@ -81,7 +81,7 @@ void watchdog_perform_action(void)
case WATCHDOG_ACTION_INJECT_NMI:
qapi_event_send_watchdog(WATCHDOG_ACTION_INJECT_NMI);
- nmi_monitor_handle(0, NULL);
+ nmi_inject(NULL);
break;
default:
diff --git a/system/cpus.c b/system/cpus.c
index 97e5a5edee2..9758cda4636 100644
--- a/system/cpus.c
+++ b/system/cpus.c
@@ -23,7 +23,6 @@
*/
#include "qemu/osdep.h"
-#include "monitor/monitor.h"
#include "qemu/coroutine-tls.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-machine.h"
@@ -926,6 +925,6 @@ exit:
void qmp_inject_nmi(Error **errp)
{
- nmi_monitor_handle(monitor_get_cpu_index(monitor_cur()), errp);
+ nmi_inject(errp);
}
diff --git a/hmp-commands.hx b/hmp-commands.hx
index a29f02b623e..43ff220b5fe 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -869,7 +869,7 @@ ERST
.cmd = hmp_nmi,
},
SRST
-``nmi`` *cpu*
+``nmi``
Inject an NMI, in a machine-specific way.
Not all machines implement NMI handling.
ERST
--
2.53.0
next prev parent reply other threads:[~2026-08-16 14:50 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-16 14:44 [PULL 00/56] Misc HW patches for 2026-08-16 Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 01/56] hw/qdev: Remove DEFINE_PROP_DMAADDR() and 'hw/qdev-dma.h' Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 02/56] hw/mem/nvdimm: fix "size" property typename Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 03/56] qdev: Make qdev_is_realized() take a const DeviceState * Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 04/56] hw/hyperv/balloon: Use qdev_is_realized() Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 05/56] hw/intc/apic: " Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 06/56] hw/mem/memory-device: " Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 07/56] hw/mem/pc-dimm: " Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 08/56] hw/nvram: " Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 09/56] hw/ppc/pnv_xscom: " Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 10/56] hw/vfio: " Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 11/56] hw/virtio/virtio-mem: " Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 12/56] hw/virtio/virtio-qmp: " Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 13/56] target/i386/cpu: " Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 14/56] target/s390x: " Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 15/56] hw/qdev: Parent device before setting parent bus Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 16/56] hw/i386/pc: xen: reinstate the "xenfv" machine alias Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 17/56] hw/net/rtl8139: Fix handling of VLAN tags on incoming short packets Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 18/56] hw/net/rtl8139: Send whole of vlan-tagged packet when doing loopback Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 19/56] hw/block/pflash_cfi01: Restore ROMD mode after migration Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 20/56] hw/nvme: add SPDM_SOCKET Kconfig dependency Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 21/56] hw/cpu: Correct CPU_GET_CLASS() comment Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 22/56] hw/cpu: Include missing 'qemu/accel.h' header Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 23/56] hw/cpu: Move internal declarations to new 'cpu-internal.h' header Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 24/56] hw/cpu: Rename cpu_common_realizefn() -> cpu_exec_realize() Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 25/56] hw/cpu: Rename cpu_exec_realizefn() -> cpu_common_realize() Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 26/56] hw/cpu: Rename cpu_exec_unrealizefn() -> cpu_common_unrealize() Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 27/56] hw/cpu: Extract cpu_exec_realize() out of cpu_common_realizefn() Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 28/56] hw/cpu: Move system-specific cpu_exec_realize() to cpu-system.c Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 29/56] hw/nmi: Use object_child_foreach_recursive() in nmi_children() Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 30/56] hw/s390x/virtio-ccw: Always inject NMI to first CPU Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 31/56] hw/nmi: Remove @cpu_index argument from NMIClass::nmi_monitor_handler() Philippe Mathieu-Daudé
2026-08-16 14:45 ` Philippe Mathieu-Daudé [this message]
2026-08-16 14:45 ` [PULL 33/56] hw/nmi: Rename nmi_monitor_handler() -> raise_nmi() Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 34/56] hw/nmi: Remove unused @errp argument from raise_nmi() Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 35/56] hw/nmi: Raise NMI line only once Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 36/56] hexagon: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 37/56] net/vhost-vdpa: Include missing 'qemu/iov.h' header Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 38/56] tests/unit: Include 'qemu/main-loop.h' header in test-util-sockets.c Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 39/56] qapi/qmp-dispatch: Include 'qemu/aio-wait.h' and 'monitor/monitor.h' Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 40/56] qapi/qmp-registry: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 41/56] migration/hmp-cmds: Include 'block/block-global-state.h' header Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 42/56] monitor: Include missing 'qemu/aio-wait.h' header Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 43/56] monitor: Include missing 'qemu/lockable.h' header Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 44/56] monitor: Include missing 'qemu/coroutine-core.h' header Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 45/56] monitor: Reduce inclusion of 'qapi/qapi-emit-events.h' header Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 46/56] monitor: Remove unnecessary 'block/block.h' header Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 47/56] system: Remove unnecessary 'monitor/monitor.h' header Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 48/56] system/dirtylimit: Extract HMP code to dirtylimit-hmp-cmds.c Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 49/56] system: Move qmp_inject_nmi() to hw/core/machine-qmp-cmds.c Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 50/56] system: Extract QMP memsave/pmemsave commands to physmem-qmp-cmds.c Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 51/56] system: Move runstate-related code from cpus.c to runstate.c Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 52/56] monitor: Rename MonitorHMP @mon -> @hmp Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 53/56] monitor: Better express monitor_read()'s opaque arg is of Monitor type Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 54/56] monitor: Replace container_of(MonitorHMP, parent_obj) -> MONITOR_HMP() Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 55/56] hw/elf_ops: defend against weird elf headers Philippe Mathieu-Daudé
2026-08-16 14:45 ` [PULL 56/56] hw/core/machine: Move EHCI migration compat properties to 11.1 Philippe Mathieu-Daudé
2026-08-16 17:26 ` [PULL 00/56] Misc HW patches for 2026-08-16 Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260816144556.69009-33-philmd@oss.qualcomm.com \
--to=philmd@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.