[PATCH v2 0/3] ppc/kvm: Handle CPU compatibility mode correctly for nested guests

Amit Machhiwal posted 3 patches 4 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260502140021.69712-1-amachhiw@linux.ibm.com
Maintainers: Nicholas Piggin <npiggin@gmail.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, "Michael S. Tsirkin" <mst@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Chinmay Rath <rathc@linux.ibm.com>, Glenn Miles <milesg@linux.ibm.com>
hw/ppc/spapr_hcall.c            |  9 ++++++
linux-headers/asm-powerpc/kvm.h |  7 ++++
linux-headers/linux/kvm.h       |  3 ++
target/ppc/kvm.c                | 57 +++++++++++++++++++++++++++++++++
4 files changed, 76 insertions(+)
[PATCH v2 0/3] ppc/kvm: Handle CPU compatibility mode correctly for nested guests
Posted by Amit Machhiwal 4 weeks ago
On POWER systems, newer processor generations can operate in compatibility
modes corresponding to earlier generations (e.g., a Power11 system running
in Power10 compatibility mode). In such cases, the effective CPU level
exposed to guests differs from the physical processor generation.

This creates issues for nested virtualization. When booting a nested KVM
guest, QEMU may derive the CPU model from the raw hardware PVR and attempt
to configure the guest accordingly. However, the host is constrained by the
compatibility level negotiated with the hypervisor, and requests exceeding
that level are rejected by KVM, leading to guest boot failures such as:

  KVM-NESTEDv2: couldn't set guest wide elements

This series addresses the issue in two ways:

1. Do not silently fall back to raw mode when KVM rejects a requested
   compatibility level during CAS. Instead, propagate the error so invalid
   configurations are visible and fail early.

2. Query the effective CPU compatibility modes supported by the host via
   KVM and use this information to select an appropriate CPU model for
   nested guests.

With these changes, QEMU avoids masking KVM errors and ensures that nested
guests are configured with CPU models consistent with the host
compatibility mode, allowing them to boot correctly.

Patch summary:
  [1/3] hw/ppc/spapr: Do not fallback to raw mode when KVM rejects compat
  [2/3] [DO_NOT_MERGE] linux-headers: Add uapi header changes
  [3/3] target/ppc/kvm: Use host compatibility mode for nested guests

Changes in v2:
- Patch 3: Guard compatibility mode code with #if defined(TARGET_PPC64)
  to fix compilation for ppc32 targets. The POWER9/10/11 PVR constants
  are only defined for 64-bit builds, and compatibility modes are only
  relevant for 64-bit systems.

Tested on:
  - Power11 pSeries LPAR in Power10 compatibility mode
  - Power10 PowerNV and QEMU PowerNV 11 TCG L0 host

CI test results: https://gitlab.com/amachhiw/qemu/-/pipelines/2494987253

Note: Patch 2 is marked DO_NOT_MERGE as it contains linux-headers updates
that will be synced separately once the corresponding kernel patches are
merged.

The corresponding Linux patches have been posted [1]

[1] https://lore.kernel.org/all/20260430054906.94431-1-amachhiw@linux.ibm.com/

Amit Machhiwal (3):
  hw/ppc/spapr: Do not fallback to raw mode when KVM rejects compat
  [DO_NOT_MERGE] linux-headers: Add uapi header changes
  target/ppc/kvm: Use host compatibility mode for nested guests

 hw/ppc/spapr_hcall.c            |  9 ++++++
 linux-headers/asm-powerpc/kvm.h |  7 ++++
 linux-headers/linux/kvm.h       |  3 ++
 target/ppc/kvm.c                | 57 +++++++++++++++++++++++++++++++++
 4 files changed, 76 insertions(+)


base-commit: 3d626609ccae61a2e552bccd59c7a0931bab8261
-- 
2.50.1 (Apple Git-155)
Re: [PATCH v2 0/3] ppc/kvm: Handle CPU compatibility mode correctly for nested guests
Posted by Anushree Mathur 2 weeks, 1 day ago

On 02/05/26 7:30 PM, Amit Machhiwal wrote:
> On POWER systems, newer processor generations can operate in compatibility
> modes corresponding to earlier generations (e.g., a Power11 system running
> in Power10 compatibility mode). In such cases, the effective CPU level
> exposed to guests differs from the physical processor generation.
>
> This creates issues for nested virtualization. When booting a nested KVM
> guest, QEMU may derive the CPU model from the raw hardware PVR and attempt
> to configure the guest accordingly. However, the host is constrained by the
> compatibility level negotiated with the hypervisor, and requests exceeding
> that level are rejected by KVM, leading to guest boot failures such as:
>
>    KVM-NESTEDv2: couldn't set guest wide elements
>
> This series addresses the issue in two ways:
>
> 1. Do not silently fall back to raw mode when KVM rejects a requested
>     compatibility level during CAS. Instead, propagate the error so invalid
>     configurations are visible and fail early.
>
> 2. Query the effective CPU compatibility modes supported by the host via
>     KVM and use this information to select an appropriate CPU model for
>     nested guests.
>
> With these changes, QEMU avoids masking KVM errors and ensures that nested
> guests are configured with CPU models consistent with the host
> compatibility mode, allowing them to boot correctly.
>
> Patch summary:
>    [1/3] hw/ppc/spapr: Do not fallback to raw mode when KVM rejects compat
>    [2/3] [DO_NOT_MERGE] linux-headers: Add uapi header changes
>    [3/3] target/ppc/kvm: Use host compatibility mode for nested guests
>
> Changes in v2:
> - Patch 3: Guard compatibility mode code with #if defined(TARGET_PPC64)
>    to fix compilation for ppc32 targets. The POWER9/10/11 PVR constants
>    are only defined for 64-bit builds, and compatibility modes are only
>    relevant for 64-bit systems.
>
> Tested on:
>    - Power11 pSeries LPAR in Power10 compatibility mode
>    - Power10 PowerNV and QEMU PowerNV 11 TCG L0 host
>
> CI test results: https://gitlab.com/amachhiw/qemu/-/pipelines/2494987253
>
> Note: Patch 2 is marked DO_NOT_MERGE as it contains linux-headers updates
> that will be synced separately once the corresponding kernel patches are
> merged.
>
> The corresponding Linux patches have been posted [1]
>
> [1] https://lore.kernel.org/all/20260430054906.94431-1-amachhiw@linux.ibm.com/
>
> Amit Machhiwal (3):
>    hw/ppc/spapr: Do not fallback to raw mode when KVM rejects compat
>    [DO_NOT_MERGE] linux-headers: Add uapi header changes
>    target/ppc/kvm: Use host compatibility mode for nested guests
>
>   hw/ppc/spapr_hcall.c            |  9 ++++++
>   linux-headers/asm-powerpc/kvm.h |  7 ++++
>   linux-headers/linux/kvm.h       |  3 ++
>   target/ppc/kvm.c                | 57 +++++++++++++++++++++++++++++++++
>   4 files changed, 76 insertions(+)
>
>
> base-commit: 3d626609ccae61a2e552bccd59c7a0931bab8261



Hi Amit,
I tried booting up a guest on P11 lpar booted with P10 compat mode 
applying your patch along with the linux patch series and it has been 
working perfectly fine.

Host lscpu:

lscpu
Architecture:                ppc64le
   Byte Order:                Little Endian
CPU(s):                      80
   On-line CPU(s) list:       0-79
Model name:                  POWER10 (architected), altivec supported


Guest lscpu:

lscpu
Architecture:                ppc64le
   Byte Order:                Little Endian
CPU(s):                      10
   On-line CPU(s) list:       0-9
Model name:                  POWER10 (architected), altivec supported

Feel free to add :

Tested-by: Anushree Mathur <anushree.mathur@linux.ibm.com>

Thank you!
Anushree Mathur