@samitouri / QOSamiQemu / commits / 64011ef0d9

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>

Philippe Mathieu-Daudé committed Feb 20, 2024 at 14:31 UTC 64011ef0d93fa892333782643ec544cc10504651
6 files changed +31 -12
hmp-commands.hx
+1 -1
@@ -869,7 +869,7 @@ ERST
869 .cmd = hmp_nmi,
870 },
871 SRST
872 -``nmi`` *cpu*
872 +``nmi``
873 Inject an NMI, in a machine-specific way.
874 Not all machines implement NMI handling.
875 ERST
hw/core/nmi.c
+4 -5
@@ -22,11 +22,8 @@
22 #include "qemu/osdep.h"
23 #include "hw/core/nmi.h"
24 #include "qapi/error.h"
25 -#include "qemu/module.h"
26 -#include "monitor/monitor.h"
25
26 struct do_nmi_s {
29 - int cpu_index;
27 Error *err;
28 bool handled;
29 };
@@ -54,19 +51,21 @@ static int nmi_children(Object *o, struct do_nmi_s *ns)
51 return object_child_foreach_recursive(o, do_nmi, ns);
52 }
53
57 -void nmi_monitor_handle(int cpu_index, Error **errp)
54 +bool nmi_inject(Error **errp)
55 {
56 struct do_nmi_s ns = {
60 - .cpu_index = cpu_index,
57 .err = NULL,
58 .handled = false
59 };
60
61 if (nmi_children(object_get_root(), &ns)) {
62 error_propagate(errp, ns.err);
63 + return false;
64 } else if (!ns.handled) {
65 error_setg(errp, "machine does not provide NMIs");
66 + return false;
67 }
68 + return true;
69 }
70
71 static const TypeInfo nmi_info = {
hw/ipmi/ipmi.c
+1 -2
@@ -59,8 +59,7 @@ static int ipmi_do_hw_op(IPMIInterface *s, enum ipmi_op op, int checkonly)
59 if (checkonly) {
60 return 0;
61 }
62 - /* We don't care what CPU we use. */
63 - nmi_monitor_handle(0, NULL);
62 + nmi_inject(NULL);
63 return 0;
64
65 case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP:
hw/watchdog/watchdog.c
+1 -1
@@ -81,7 +81,7 @@ void watchdog_perform_action(void)
81
82 case WATCHDOG_ACTION_INJECT_NMI:
83 qapi_event_send_watchdog(WATCHDOG_ACTION_INJECT_NMI);
84 - nmi_monitor_handle(0, NULL);
84 + nmi_inject(NULL);
85 break;
86
87 default:
include/hw/core/nmi.h
+23 -1
@@ -46,6 +46,28 @@ struct NMIClass {
46 void (*nmi_monitor_handler)(NMIState *ns, Error **errp);
47 };
48
49 -void nmi_monitor_handle(int cpu_index, Error **errp);
49 +/**
50 + * nmi_inject: Inject an NMI, in a machine-specific way
51 + * @errp: pointer to error object
52 + *
53 + * This function injects an NMI, in a machine-specific way. The
54 + * intention is that this should typically trigger a guest kernel
55 + * dump or reboot, and might happen as a result of user request
56 + * from the monitor, watchdog timeouts, and similar events.
57 + * (For example on the x86 PC it triggers an NMI on all CPUs,
58 + * and on s390 it triggers the RESTART interrupt on the first CPU.)
59 + *
60 + * The NMI is injected by looking for a QOM object which implements
61 + * the TYPE_NMI interface, and calling its nmi_monitor_handler method. Usually
62 + * it is the machine model class that implements this interface.
63 + *
64 + * Not all machines implement NMI handling; this function
65 + * will return an error if used on a machine which does not
66 + * implement NMIs.
67 + *
68 + * On success, return %true.
69 + * On failure, store an error through @errp and return %false.
70 + */
71 +bool nmi_inject(Error **errp);
72
73 #endif /* NMI_H */
system/cpus.c
+1 -2
@@ -23,7 +23,6 @@
23 */
24
25 #include "qemu/osdep.h"
26 -#include "monitor/monitor.h"
26 #include "qemu/coroutine-tls.h"
27 #include "qapi/error.h"
28 #include "qapi/qapi-commands-machine.h"
@@ -926,6 +925,6 @@ exit:
925
926 void qmp_inject_nmi(Error **errp)
927 {
929 - nmi_monitor_handle(monitor_get_cpu_index(monitor_cur()), errp);
928 + nmi_inject(errp);
929 }
930