From: "Jörg Rödel" <joro@8bytes.org>
To: Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <richard.henderson@linaro.org>
Cc: philmd@linaro.org, marcel.apfelbaum@gmail.com,
zhao1.liu@intel.com, berrange@redhat.com, mst@redhat.com,
cohuck@redhat.com, mtosatti@redhat.com,
Tom Lendacky <thomas.lendacky@amd.com>,
qemu-devel@nongnu.org, kvm@vger.kernel.org,
coconut-svsm@lists.linux.dev, joerg.roedel@amd.com
Subject: [RFC PATCH 06/10] accel/kvm: Handle KVM_PLANE_EVENT_CREATE_CPU event
Date: Mon, 8 Jun 2026 17:21:05 +0200 [thread overview]
Message-ID: <20260608152109.356783-7-joro@8bytes.org> (raw)
In-Reply-To: <20260608152109.356783-1-joro@8bytes.org>
From: Joerg Roedel <joerg.roedel@amd.com>
Implement the plane event handling infrastructure and handle the
KVM_PLANE_EVENT_CREATE_CPU event.
Co-developed-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
accel/kvm/kvm-all.c | 13 +++++++---
include/system/kvm.h | 2 +-
target/i386/kvm/kvm.c | 57 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 67 insertions(+), 5 deletions(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index dbfef63a84b0..c5fe6d189e62 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -573,11 +573,17 @@ static void kvm_alloc_vcpu_plane(CPUState *cpu, unsigned plane_id, int kvm_fd)
cpu->kvm_plane_state[plane_id] = p;
}
-void kvm_create_vcpu_plane(CPUState *cpu, unsigned plane_id, int kvm_fd)
+void kvm_create_vcpu_plane(CPUState *cpu, unsigned plane_id)
{
- int vcpu_fd = cpu_kvm_plane(cpu, 0)->kvm_fd;
- int plane_fd = kvm_vm_plane_ioctl(cpu->kvm_state, plane_id, KVM_CREATE_VCPU, vcpu_fd);
+ X86CPU *x86_cpu = X86_CPU(cpu);
+ int plane_fd;
+ if (kvm_get_or_create_plane_fd(cpu->kvm_state, plane_id) < 0) {
+ fprintf(stderr, "Failed to create plane %d\n", plane_id);
+ abort();
+ }
+
+ plane_fd = kvm_vm_plane_ioctl(cpu->kvm_state, plane_id, KVM_CREATE_VCPU, x86_cpu->apic_id);
if (plane_fd < 0) {
fprintf(stderr, "Failed to create plane vcpu\n");
abort();
@@ -586,7 +592,6 @@ void kvm_create_vcpu_plane(CPUState *cpu, unsigned plane_id, int kvm_fd)
kvm_alloc_vcpu_plane(cpu, plane_id, plane_fd);
}
-
/**
* kvm_create_vcpu - Gets a parked KVM vCPU or creates a KVM vCPU
* @cpu: QOM CPUState object for which KVM vCPU has to be fetched/created.
diff --git a/include/system/kvm.h b/include/system/kvm.h
index 16597333cfa5..24a21915366f 100644
--- a/include/system/kvm.h
+++ b/include/system/kvm.h
@@ -221,7 +221,7 @@ int kvm_vm_ioctl(KVMState *s, unsigned long type, ...);
int kvm_vm_plane_ioctl(KVMState *s, unsigned plane_id, unsigned long type, ...);
int kvm_get_or_create_plane_fd(KVMState *s, unsigned id);
-void kvm_create_vcpu_plane(CPUState *cpu, unsigned plane, int kvm_fd);
+void kvm_create_vcpu_plane(CPUState *cpu, unsigned plane);
void kvm_flush_coalesced_mmio_buffer(void);
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 9e352882c8c3..30fba9e75016 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -6524,6 +6524,60 @@ static int kvm_handle_hypercall(X86CPU *cpu, struct kvm_run *run)
return -EINVAL;
}
+static CPUState *kvm_get_cpu_by_apicid(CPUState *cpu, unsigned apic_id)
+{
+ CPU_FOREACH(cpu) {
+ X86CPU *x86_cpu = X86_CPU(cpu);
+ if (x86_cpu->apic_id == apic_id) {
+ return cpu;
+ }
+ }
+
+ return NULL;
+}
+
+static void create_plane_vcpu_cb(CPUState *cs, run_on_cpu_data data)
+{
+ int plane = data.host_int;
+
+ kvm_create_vcpu_plane(cs, plane);
+}
+
+static int kvm_handle_plane_create_vcpu(CPUState *cpu, struct kvm_run *run)
+{
+ CPUState *target_cpu = NULL;
+ int plane = -EINVAL;
+
+ plane = run->plane_event.plane;
+ if (plane < 0) {
+ return plane;
+ }
+
+ target_cpu = kvm_get_cpu_by_apicid(cpu, run->plane_event.extra[0]);
+ if (target_cpu == NULL) {
+ return -EINVAL;
+ }
+
+ bql_lock();
+ run_on_cpu(target_cpu, create_plane_vcpu_cb, RUN_ON_CPU_HOST_INT(plane));
+ bql_unlock();
+
+ return 0;
+}
+
+static int kvm_handle_plane_event(CPUState *cpu, struct kvm_run *run)
+{
+ switch (run->plane_event.cause) {
+ case KVM_PLANE_EVENT_CREATE_VCPU:
+ return kvm_handle_plane_create_vcpu(cpu, run);
+ default:
+ fprintf(stderr, "KVM: unknown plane event %d\n", run->plane_event.cause);
+ break;
+ }
+
+ return -EINVAL;
+}
+
#define VMX_INVALID_GUEST_STATE 0x80000021
int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
@@ -6648,6 +6702,9 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
break;
}
ret = 0;
+ break;
+ case KVM_EXIT_PLANE_EVENT:
+ ret = kvm_handle_plane_event(cs, run);
break;
default:
fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason);
--
2.53.0
next prev parent reply other threads:[~2026-06-08 15:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-08 15:20 [RFC PATCH 00/10] QEMU Support for KVM Planes Jörg Rödel
2026-06-08 15:21 ` [RFC PATCH 01/10] Update Linux Header for KVM Planes Support Jörg Rödel
2026-06-08 15:21 ` [RFC PATCH 02/10] accel/kvm: Extend KVMState to carry fds for planes Jörg Rödel
2026-06-08 15:21 ` [RFC PATCH 03/10] accel/kvm: Extend CPUState to handle Planes Jörg Rödel
2026-06-08 15:21 ` [RFC PATCH 04/10] accel: Add nr_planes() op Jörg Rödel
2026-06-08 15:21 ` [RFC PATCH 05/10] accel/kvm: Support nr_planes call-back Jörg Rödel
2026-06-08 15:21 ` Jörg Rödel [this message]
2026-06-08 15:21 ` [RFC PATCH 07/10] hw/core/machine: Add device-plane property Jörg Rödel
2026-06-08 15:21 ` [RFC PATCH 08/10] qdev: Add plane property Jörg Rödel
2026-06-08 15:21 ` [RFC PATCH 09/10] MSI: Inject into correct plane Jörg Rödel
2026-06-08 15:21 ` [RFC PATCH 10/10] KVM: Set GSI routes for default plane Jörg Rödel
2026-06-08 15:40 ` [RFC PATCH 00/10] QEMU Support for KVM Planes Daniel P. Berrangé
2026-06-08 15:45 ` Jörg Rödel
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=20260608152109.356783-7-joro@8bytes.org \
--to=joro@8bytes.org \
--cc=berrange@redhat.com \
--cc=coconut-svsm@lists.linux.dev \
--cc=cohuck@redhat.com \
--cc=joerg.roedel@amd.com \
--cc=kvm@vger.kernel.org \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thomas.lendacky@amd.com \
--cc=zhao1.liu@intel.com \
/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.