From: Amit Machhiwal <amachhiw@linux.ibm.com>
To: qemu-ppc@nongnu.org, Harsh Prateek Bora <harshpb@linux.ibm.com>
Cc: Amit Machhiwal <amachhiw@linux.ibm.com>,
Vaibhav Jain <vaibhav@linux.ibm.com>,
Nicholas Piggin <npiggin@gmail.com>,
Chinmay Rath <rathc@linux.ibm.com>,
Glenn Miles <milesg@linux.ibm.com>,
Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, qemu-devel@nongnu.org
Subject: [PATCH 2/2] target/ppc/kvm: Use host compatibility mode for nested guests
Date: Thu, 30 Apr 2026 11:43:33 +0530 [thread overview]
Message-ID: <20260430061333.37905-3-amachhiw@linux.ibm.com> (raw)
In-Reply-To: <20260430061333.37905-1-amachhiw@linux.ibm.com>
On POWER systems, the host CPU may run in a compatibility mode (e.g.,
a Power11 processor operating in Power10 compatibility mode). In such
cases, the effective CPU level exposed to guests differs from the
physical processor generation.
When running nested KVM guests, QEMU currently derives the host CPU type
using mfpvr(), which reflects the physical processor version. This can
result in a mismatch between the CPU model used by QEMU and the
compatibility mode enforced by the host, leading to guest boot failures.
In particular, booting a nested guest on a Power11 LPAR configured in
Power10 compatibility mode fails with errors such as:
KVM-NESTEDv2: couldn't set guest wide elements
This occurs because QEMU selects a CPU model based on the physical
processor version, while the host operates in a lower compatibility
mode. As a result, KVM rejects the requested compatibility level during
guest initialization.
Add support for querying host compatibility capabilities via the
KVM_PPC_GET_COMPAT_CAPS ioctl and derive the effective PVR based on the
compatibility mode reported by KVM. When available, use this
compatibility PVR instead of the raw hardware PVR when selecting
the CPU model.
If the capability is not supported or the query fails, fall back to the
existing behavior.
This ensures that QEMU selects a CPU model consistent with the host
compatibility mode, allowing nested guests to boot correctly.
Signed-off-by: Amit Machhiwal <amachhiw@linux.ibm.com>
---
target/ppc/kvm.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 25c28ad089c6..d384161f780b 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -2602,11 +2602,63 @@ bool kvmppc_supports_ail_3(void)
return cap_ail_mode_3;
}
+static target_ulong kvmppc_get_compat_caps(void)
+{
+ struct kvm_ppc_compat_caps host_compat;
+ target_ulong host_caps;
+ int ret;
+
+ if (!kvm_check_extension(kvm_state, KVM_CAP_PPC_COMPAT_CAPS)) {
+ return 0;
+ }
+
+ ret = kvm_vm_ioctl(kvm_state, KVM_PPC_GET_COMPAT_CAPS, &host_compat);
+ if (ret < 0) {
+ fprintf(stderr, "KVM: failed to get host capabilities\n");
+ return 0;
+ }
+
+ host_caps = host_compat.compat_capabilities;
+ return host_caps;
+}
+
+static uint32_t kvm_ppc_host_compat_pvr(void)
+{
+ uint32_t compat_host_pvr = 0;
+ int cap_idx = 0;
+ target_ulong host_caps = kvmppc_get_compat_caps();
+
+ if (host_caps) {
+ cap_idx = 63 - __builtin_ctzll(host_caps);
+ switch (cap_idx) {
+ case H_GUEST_CAP_P9_MODE_BMAP:
+ compat_host_pvr = CPU_POWERPC_POWER9_DD22;
+ break;
+ case H_GUEST_CAP_P10_MODE_BMAP:
+ compat_host_pvr = CPU_POWERPC_POWER10_DD20;
+ break;
+ case H_GUEST_CAP_P11_MODE_BMAP:
+ compat_host_pvr = CPU_POWERPC_POWER11_DD20;
+ break;
+ default:
+ break;
+ }
+ }
+
+ return compat_host_pvr;
+}
+
PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void)
{
uint32_t host_pvr = mfpvr();
+ uint32_t compat_host_pvr;
PowerPCCPUClass *pvr_pcc;
+ compat_host_pvr = kvm_ppc_host_compat_pvr();
+ if (compat_host_pvr) {
+ host_pvr = compat_host_pvr;
+ }
+
pvr_pcc = ppc_cpu_class_by_pvr(host_pvr);
if (pvr_pcc == NULL) {
pvr_pcc = ppc_cpu_class_by_pvr_mask(host_pvr);
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-04-30 6:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 6:13 [PATCH 0/2] ppc/kvm: Handle CPU compatibility mode correctly for nested guests Amit Machhiwal
2026-04-30 6:13 ` Amit Machhiwal [this message]
2026-05-02 20:14 ` [PATCH 2/2] target/ppc/kvm: Use host compatibility mode " Amit Machhiwal
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=20260430061333.37905-3-amachhiw@linux.ibm.com \
--to=amachhiw@linux.ibm.com \
--cc=harshpb@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=milesg@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=rathc@linux.ibm.com \
--cc=vaibhav@linux.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox