All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
To: qemu-devel@nongnu.org
Cc: "Corey Minyard" <minyard@acm.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	qemu-s390x@nongnu.org
Subject: [PATCH 1/4] hw/nmi: Allow delivering to first available vCPU (not by index)
Date: Mon, 10 Aug 2026 23:37:19 +0200	[thread overview]
Message-ID: <20260810213723.58467-2-philmd@oss.qualcomm.com> (raw)
In-Reply-To: <20260810213723.58467-1-philmd@oss.qualcomm.com>

Allow callers to deliver on any vCPU (for example when
the vCPU index is not known).

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
 include/hw/core/nmi.h  | 7 +++++++
 hw/core/nmi.c          | 5 +++++
 hw/ipmi/ipmi.c         | 2 +-
 hw/watchdog/watchdog.c | 2 +-
 4 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/include/hw/core/nmi.h b/include/hw/core/nmi.h
index fff41bebc69..6136290f4fe 100644
--- a/include/hw/core/nmi.h
+++ b/include/hw/core/nmi.h
@@ -40,6 +40,13 @@ struct NMIClass {
     void (*nmi_monitor_handler)(NMIState *n, int cpu_index, Error **errp);
 };
 
+/**
+ * nmi_monitor_handle:
+ * @cpu_index: Index of the CPU to deliver the NMI
+ * @errp: pointer to a NULL-initialized error object
+ *
+ * Note: cpu_index = -1 can be used to deliver to the first vCPU available.
+ */
 void nmi_monitor_handle(int cpu_index, Error **errp);
 
 #endif /* NMI_H */
diff --git a/hw/core/nmi.c b/hw/core/nmi.c
index 4b447e126ba..67213631c04 100644
--- a/hw/core/nmi.c
+++ b/hw/core/nmi.c
@@ -20,6 +20,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "hw/core/cpu.h"
 #include "hw/core/nmi.h"
 #include "qapi/error.h"
 #include "qemu/module.h"
@@ -42,6 +43,10 @@ static int do_nmi(Object *o, void *opaque)
         NMIClass *nc = NMI_GET_CLASS(n);
 
         ns->handled = true;
+        if (ns->cpu_index == -1) {
+            /* Any vCPU is OK, take the first one */
+            ns->cpu_index = first_cpu->cpu_index;
+        }
         nc->nmi_monitor_handler(n, ns->cpu_index, &ns->err);
         if (ns->err) {
             return -1;
diff --git a/hw/ipmi/ipmi.c b/hw/ipmi/ipmi.c
index 74818ff3cea..8c492271f90 100644
--- a/hw/ipmi/ipmi.c
+++ b/hw/ipmi/ipmi.c
@@ -60,7 +60,7 @@ static int ipmi_do_hw_op(IPMIInterface *s, enum ipmi_op op, int checkonly)
             return 0;
         }
         /* We don't care what CPU we use. */
-        nmi_monitor_handle(0, NULL);
+        nmi_monitor_handle(-1, NULL);
         return 0;
 
     case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP:
diff --git a/hw/watchdog/watchdog.c b/hw/watchdog/watchdog.c
index 0842fe373ae..0c1b94a62f3 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_monitor_handle(-1, NULL);
         break;
 
     default:
-- 
2.53.0



  reply	other threads:[~2026-08-10 21:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-10 21:37 [PATCH 0/4] hw/nmi: Safer vCPU delivery Philippe Mathieu-Daudé
2026-08-10 21:37 ` Philippe Mathieu-Daudé [this message]
2026-08-10 21:37 ` [PATCH 2/4] hw/nmi: Introduce nmi_cpu_handler() for vcpu-specific delivery Philippe Mathieu-Daudé
2026-08-10 21:37 ` [PATCH 3/4] hw/s390x: Deliver per-vcpu NMI using nmi_cpu_handler Philippe Mathieu-Daudé
2026-08-10 21:37 ` [PATCH 4/4] hw/nmi: Remove unused @cpu_index and @errp arguments Philippe Mathieu-Daudé
2026-08-11  8:44 ` [PATCH 0/4] hw/nmi: Safer vCPU delivery Philippe Mathieu-Daudé
2026-08-11  8:50   ` Philippe Mathieu-Daudé
2026-08-11  9:36     ` Philippe Mathieu-Daudé
2026-08-11  9:49       ` Daniel P. Berrangé
2026-08-11 10:56         ` 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=20260810213723.58467-2-philmd@oss.qualcomm.com \
    --to=philmd@oss.qualcomm.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=minyard@acm.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@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.