On 11/8/26 13:10, Marc-André Lureau wrote:
Hi

On Tue, Aug 11, 2026 at 2:55 PM Philippe Mathieu-Daudé
<[email protected]> wrote:

From: Philippe Mathieu-Daudé <[email protected]>

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-yalysmcjlbitcmypizkuxjnoavgjg9ryeo8fkqz7...@mail.gmail.com/.

Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
  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(-)


-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);


-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);
  }

This officially drops the current CPU for HMP command too. Just
acknowledge it in the commit message, and remove the "*cpu*"
documentation in hmp-commands.hx?

Ack.


Also, can we use one word for "deliver", "trigger", "inject"? or is
there any distinction I am missing?

Hmm indeed from the monitor perspective we "inject" a NMI.

Watchdog seems to also "inject" with WATCHDOG_ACTION_INJECT_NMI
(here my understanding is "raise", but whatever).

I suppose IPMI devices also "raise", but "inject" is acceptable.

$ git grep deliver_nmi
hw/i386/x86.c:159:            apic_deliver_nmi(cpu->apic_state);
hw/intc/apic_common.c:122:void apic_deliver_nmi(APICCommonState *s)
include/hw/i386/apic.h:10:void apic_deliver_nmi(APICCommonState *s);

The NMIClass handler then "route" or "deliver" it.


I'll rename as 'nmi_inject' I suppose, better to keep in pair with
the QMP command name.

Reply via email to