Commit 64011ef0d9 for qemu.org
commit 64011ef0d93fa892333782643ec544cc10504651
Author: Philippe Mathieu-Daudé <philmd@mailo.com>
Date: Tue Feb 20 14:31:25 2024 +0100
hw/nmi: Remove @cpu_index argument from nmi_inject()
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>
diff --git a/hmp-commands.hx b/hmp-commands.hx
index a29f02b623..43ff220b5f 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
diff --git a/hw/core/nmi.c b/hw/core/nmi.c
index ff6454437c..2d890f2995 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 74818ff3ce..dedf23cb99 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 0842fe373a..5f764a0c1b 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/include/hw/core/nmi.h b/include/hw/core/nmi.h
index 4c4ce79071..851be28257 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/system/cpus.c b/system/cpus.c
index 97e5a5edee..9758cda463 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);
}