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 2/4] hw/nmi: Introduce nmi_cpu_handler() for vcpu-specific delivery
Date: Mon, 10 Aug 2026 23:37:20 +0200 [thread overview]
Message-ID: <20260810213723.58467-3-philmd@oss.qualcomm.com> (raw)
In-Reply-To: <20260810213723.58467-1-philmd@oss.qualcomm.com>
No need to have handlers check for existing CPU index,
lookup the CPUState once in the core do_nmi() code and
pass along.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
include/hw/core/nmi.h | 1 +
hw/core/nmi.c | 29 +++++++++++++++++++++++------
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/include/hw/core/nmi.h b/include/hw/core/nmi.h
index 6136290f4fe..2f554d58b7f 100644
--- a/include/hw/core/nmi.h
+++ b/include/hw/core/nmi.h
@@ -38,6 +38,7 @@ struct NMIClass {
InterfaceClass parent_class;
void (*nmi_monitor_handler)(NMIState *n, int cpu_index, Error **errp);
+ void (*nmi_cpu_handler)(NMIState *ns, CPUState *cs);
};
/**
diff --git a/hw/core/nmi.c b/hw/core/nmi.c
index 67213631c04..fb623fd00be 100644
--- a/hw/core/nmi.c
+++ b/hw/core/nmi.c
@@ -43,13 +43,30 @@ 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;
+
+ /* Generic handler */
+ if (nc->nmi_monitor_handler) {
+ nc->nmi_monitor_handler(n, ns->cpu_index, &ns->err);
+ if (ns->err) {
+ return -1;
+ }
}
- nc->nmi_monitor_handler(n, ns->cpu_index, &ns->err);
- if (ns->err) {
- return -1;
+ /* Per vCPU handler */
+ if (nc->nmi_cpu_handler) {
+ CPUState *cs;
+
+ if (ns->cpu_index >= 0) {
+ /* Specific vCPU requested */
+ cs = qemu_get_cpu(ns->cpu_index);
+ } else {
+ /* Any vCPU is OK, take the first one */
+ cs = first_cpu;
+ }
+ if (!cs) {
+ error_setg(&ns->err, "CPU %d does not exist", ns->cpu_index);
+ return -1;
+ }
+ nc->nmi_cpu_handler(n, cs);
}
}
nmi_children(o, ns);
--
2.53.0
next prev parent 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 ` [PATCH 1/4] hw/nmi: Allow delivering to first available vCPU (not by index) Philippe Mathieu-Daudé
2026-08-10 21:37 ` Philippe Mathieu-Daudé [this message]
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-3-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.