From: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
qemu-s390x@nongnu.org,
"Dr. David Alan Gilbert" <dave@treblig.org>,
"Thomas Huth" <thuth@redhat.com>,
qemu-ppc@nongnu.org, "Corey Minyard" <minyard@acm.org>,
"Markus Armbruster" <armbru@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@mailo.com>
Subject: [PATCH v3 4/7] hw/nmi: Remove @cpu_index argument from nmi_trigger()
Date: Tue, 11 Aug 2026 12:54:22 +0200 [thread overview]
Message-ID: <20260811105425.7429-5-philmd@oss.qualcomm.com> (raw)
In-Reply-To: <20260811105425.7429-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_trigger().
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.
Document nmi_trigger() 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>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
include/hw/core/nmi.h | 25 ++++++++++++++++++++++++-
hw/core/nmi.c | 9 ++++-----
hw/ipmi/ipmi.c | 3 +--
hw/watchdog/watchdog.c | 2 +-
system/cpus.c | 2 +-
5 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/include/hw/core/nmi.h b/include/hw/core/nmi.h
index 4c4ce79071d..e77c382452a 100644
--- a/include/hw/core/nmi.h
+++ b/include/hw/core/nmi.h
@@ -46,6 +46,29 @@ struct NMIClass {
void (*nmi_monitor_handler)(NMIState *ns, Error **errp);
};
-void nmi_monitor_handle(int cpu_index, Error **errp);
+/**
+ * nmi_trigger: Trigger an NMI, in a machine-specific way
+ * @errp: pointer to error object
+ *
+ * This function triggers 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 triggered by looking for QOM objects which
+ * implement the TYPE_NMI interface, and calling their nmi_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_trigger(Error **errp);
#endif /* NMI_H */
diff --git a/hw/core/nmi.c b/hw/core/nmi.c
index ff6454437c1..662f2051123 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_trigger(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..444af726d75 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_trigger(NULL);
return 0;
case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP:
diff --git a/hw/watchdog/watchdog.c b/hw/watchdog/watchdog.c
index 0842fe373ae..026768e9fb2 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_trigger(NULL);
break;
default:
diff --git a/system/cpus.c b/system/cpus.c
index 97e5a5edee2..5c0a192c01e 100644
--- a/system/cpus.c
+++ b/system/cpus.c
@@ -926,6 +926,6 @@ exit:
void qmp_inject_nmi(Error **errp)
{
- nmi_monitor_handle(monitor_get_cpu_index(monitor_cur()), errp);
+ nmi_trigger(errp);
}
--
2.53.0
next prev parent reply other threads:[~2026-08-11 10:56 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 10:54 [PATCH v3 0/7] hw/nmi: Disconnect of vCPU and disentangle Monitor code Philippe Mathieu-Daudé
2026-08-11 10:54 ` [PATCH v3 1/7] hw/nmi: Use object_child_foreach_recursive() in nmi_children() Philippe Mathieu-Daudé
2026-08-11 10:54 ` [PATCH v3 2/7] hw/s390x/virtio-ccw: Always deliver NMI to first CPU Philippe Mathieu-Daudé
2026-08-11 10:54 ` [PATCH v3 3/7] hw/nmi: Remove @cpu_index argument from NMIClass::nmi_monitor_handler() Philippe Mathieu-Daudé
2026-08-11 13:21 ` Peter Maydell
2026-08-11 10:54 ` Philippe Mathieu-Daudé [this message]
2026-08-11 11:10 ` [PATCH v3 4/7] hw/nmi: Remove @cpu_index argument from nmi_trigger() Marc-André Lureau
2026-08-11 13:55 ` Philippe Mathieu-Daudé
2026-08-11 10:54 ` [PATCH v3 5/7] hw/nmi: Rename nmi_monitor_handler() -> deliver_nmi() Philippe Mathieu-Daudé
2026-08-11 10:54 ` [PATCH v3 6/7] hw/nmi: Remove unused @errp argument from deliver_nmi() Philippe Mathieu-Daudé
2026-08-11 13:24 ` Peter Maydell
2026-08-11 10:54 ` [PATCH v3 7/7] hw/nmi: Deliver NMI only once Philippe Mathieu-Daudé
2026-08-11 13:34 ` Peter Maydell
2026-08-11 14:09 ` Philippe Mathieu-Daudé
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=20260811105425.7429-5-philmd@oss.qualcomm.com \
--to=philmd@oss.qualcomm.com \
--cc=armbru@redhat.com \
--cc=dave@treblig.org \
--cc=marcandre.lureau@redhat.com \
--cc=minyard@acm.org \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=philmd@mailo.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thuth@redhat.com \
/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.