* Re: [PATCH] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
2026-06-03 14:15 [PATCH] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode Amit Machhiwal
@ 2026-06-03 15:11 ` Ritesh Harjani
2026-06-03 17:57 ` Mukesh Kumar Chaurasiya
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Ritesh Harjani @ 2026-06-03 15:11 UTC (permalink / raw)
To: Amit Machhiwal, linuxppc-dev, Madhavan Srinivasan
Cc: Amit Machhiwal, Vaibhav Jain, Harsh Prateek Bora, Anushree Mathur,
Nicholas Piggin, Michael Ellerman, Christophe Leroy (CS GROUP),
kvm, stable, linux-kernel
Amit Machhiwal <amachhiw@linux.ibm.com> writes:
> On IBM POWER systems, newer processor generations can operate in
> compatibility modes corresponding to earlier generations. This becomes
> relevant for nested virtualization, where nested KVM guests may need to
> run with a specific processor compatibility level.
>
> Currently, when running a nested KVM guest (L2) inside a Power11 pSeries
> logical partition (L1) booted in Power10 compatibility mode, the guest
> fails to boot while setting 'arch_compat'. This happens because the CPU
> class is derived from the hardware PVR (via mfspr()), which reflects the
> physical processor generation (Power11), rather than the effective
> compatibility mode (Power10).
>
> As a result, userspace may request a Power11 arch_compat for the L2
> guest. However, the L1 partition, running in Power10 compatibility, has
> only negotiated support up to Power10 with the Power Hypervisor (L0).
> When H_GUEST_SET_STATE is invoked with a Power11 Logical PVR, the
> hypervisor rejects the request, leading to a late guest boot failure:
>
> KVM-NESTEDv2: couldn't set guest wide elements
> [..KVM reg dump..]
>
Thanks! It make sense to return a proper error code to the user (VMM)
while the VM/VCPU are being initialized, rather then the guest failing
to boot with a weird error like this, at the time when kernel makes this
H_GUEST_SET_STATE hcall.
> This situation should be detected earlier. Rejecting unsupported
> 'arch_compat' values in 'kvmppc_set_arch_compat()' avoids issuing an
> invalid H_GUEST_SET_STATE hcall and provides a clearer failure mode.
>
> Add a check to reject Power11 'arch_compat' requests when the host is
> running in Power10 compatibility mode, returning -EINVAL early instead
> of deferring the failure to the hypervisor.
>
> Suggested-by: Vaibhav Jain <vaibhav@linux.ibm.com>
> Tested-by: Anushree Mathur <anushree.mathur@linux.ibm.com>
> Cc: <stable@vger.kernel.org> # v6.13+
Sure, v6.13 sounds fair as you pointed out.
> Signed-off-by: Amit Machhiwal <amachhiw@linux.ibm.com>
> ---
> Changelog:
>
> * Moved this patch out of the v3 series [1] as discussed here [2]
> * Addressed below review comments from Ritesh:
> - Based the PVR validation on cpu features
> - Fixed hcall name typo
> - Stable backport
The changes looks good to me. Please feel free to add:
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
2026-06-03 14:15 [PATCH] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode Amit Machhiwal
2026-06-03 15:11 ` Ritesh Harjani
@ 2026-06-03 17:57 ` Mukesh Kumar Chaurasiya
2026-06-04 14:20 ` Gautam Menghani
2026-06-05 7:30 ` Vaibhav Jain
3 siblings, 0 replies; 6+ messages in thread
From: Mukesh Kumar Chaurasiya @ 2026-06-03 17:57 UTC (permalink / raw)
To: Amit Machhiwal
Cc: linuxppc-dev, Madhavan Srinivasan, Vaibhav Jain,
Harsh Prateek Bora, Ritesh Harjani, Anushree Mathur,
Nicholas Piggin, Michael Ellerman, Christophe Leroy (CS GROUP),
kvm, stable, linux-kernel
On Wed, Jun 03, 2026 at 07:45:39PM +0530, Amit Machhiwal wrote:
> On IBM POWER systems, newer processor generations can operate in
> compatibility modes corresponding to earlier generations. This becomes
> relevant for nested virtualization, where nested KVM guests may need to
> run with a specific processor compatibility level.
>
> Currently, when running a nested KVM guest (L2) inside a Power11 pSeries
> logical partition (L1) booted in Power10 compatibility mode, the guest
> fails to boot while setting 'arch_compat'. This happens because the CPU
> class is derived from the hardware PVR (via mfspr()), which reflects the
> physical processor generation (Power11), rather than the effective
> compatibility mode (Power10).
>
> As a result, userspace may request a Power11 arch_compat for the L2
> guest. However, the L1 partition, running in Power10 compatibility, has
> only negotiated support up to Power10 with the Power Hypervisor (L0).
> When H_GUEST_SET_STATE is invoked with a Power11 Logical PVR, the
> hypervisor rejects the request, leading to a late guest boot failure:
>
> KVM-NESTEDv2: couldn't set guest wide elements
> [..KVM reg dump..]
>
> This situation should be detected earlier. Rejecting unsupported
> 'arch_compat' values in 'kvmppc_set_arch_compat()' avoids issuing an
> invalid H_GUEST_SET_STATE hcall and provides a clearer failure mode.
>
> Add a check to reject Power11 'arch_compat' requests when the host is
> running in Power10 compatibility mode, returning -EINVAL early instead
> of deferring the failure to the hypervisor.
>
> Suggested-by: Vaibhav Jain <vaibhav@linux.ibm.com>
> Tested-by: Anushree Mathur <anushree.mathur@linux.ibm.com>
> Cc: <stable@vger.kernel.org> # v6.13+
> Signed-off-by: Amit Machhiwal <amachhiw@linux.ibm.com>
> ---
> Changelog:
>
> * Moved this patch out of the v3 series [1] as discussed here [2]
> * Addressed below review comments from Ritesh:
> - Based the PVR validation on cpu features
> - Fixed hcall name typo
> - Stable backport
>
> [1] https://lore.kernel.org/all/20260522152744.55251-1-amachhiw@linux.ibm.com/
> [2] https://lore.kernel.org/all/20260522152744.55251-2-amachhiw@linux.ibm.com/
> ---
> arch/powerpc/kvm/book3s_hv.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index 61dbeea317f3..e16dbb199366 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -446,7 +446,17 @@ static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat)
> guest_pcr_bit = PCR_ARCH_300;
> break;
> case PVR_ARCH_31:
> + guest_pcr_bit = PCR_ARCH_31;
> + break;
> case PVR_ARCH_31_P11:
> + /*
> + * Need to check this for ISA 3.1, as Power10 and
> + * Power11 share the same PCR. For any subsequent ISA
> + * versions, this will be taken care of by the guest vs
> + * host PCR comparison below.
> + */
> + if (!cpu_has_feature(CPU_FTR_P11_PVR))
> + return -EINVAL;
> guest_pcr_bit = PCR_ARCH_31;
> break;
> default:
>
> base-commit: ba3e43a9e601636f5edb54e259a74f96ca3b8fd8
> --
> 2.50.1 (Apple Git-155)
>
yeah this makes sense to throw an error early.
LGTM
Reviewed-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
2026-06-03 14:15 [PATCH] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode Amit Machhiwal
2026-06-03 15:11 ` Ritesh Harjani
2026-06-03 17:57 ` Mukesh Kumar Chaurasiya
@ 2026-06-04 14:20 ` Gautam Menghani
2026-06-05 7:25 ` Vaibhav Jain
2026-06-05 7:30 ` Vaibhav Jain
3 siblings, 1 reply; 6+ messages in thread
From: Gautam Menghani @ 2026-06-04 14:20 UTC (permalink / raw)
To: Amit Machhiwal
Cc: linuxppc-dev, Madhavan Srinivasan, Vaibhav Jain,
Harsh Prateek Bora, Ritesh Harjani, Anushree Mathur,
Nicholas Piggin, Michael Ellerman, Christophe Leroy (CS GROUP),
kvm, stable, linux-kernel
On Wed, Jun 03, 2026 at 07:45:39PM +0530, Amit Machhiwal wrote:
> On IBM POWER systems, newer processor generations can operate in
> compatibility modes corresponding to earlier generations. This becomes
> relevant for nested virtualization, where nested KVM guests may need to
> run with a specific processor compatibility level.
>
> Currently, when running a nested KVM guest (L2) inside a Power11 pSeries
> logical partition (L1) booted in Power10 compatibility mode, the guest
> fails to boot while setting 'arch_compat'. This happens because the CPU
> class is derived from the hardware PVR (via mfspr()), which reflects the
> physical processor generation (Power11), rather than the effective
> compatibility mode (Power10).
>
> As a result, userspace may request a Power11 arch_compat for the L2
> guest. However, the L1 partition, running in Power10 compatibility, has
> only negotiated support up to Power10 with the Power Hypervisor (L0).
> When H_GUEST_SET_STATE is invoked with a Power11 Logical PVR, the
> hypervisor rejects the request, leading to a late guest boot failure:
>
> KVM-NESTEDv2: couldn't set guest wide elements
> [..KVM reg dump..]
>
> This situation should be detected earlier. Rejecting unsupported
> 'arch_compat' values in 'kvmppc_set_arch_compat()' avoids issuing an
> invalid H_GUEST_SET_STATE hcall and provides a clearer failure mode.
>
> Add a check to reject Power11 'arch_compat' requests when the host is
> running in Power10 compatibility mode, returning -EINVAL early instead
> of deferring the failure to the hypervisor.
>
> Suggested-by: Vaibhav Jain <vaibhav@linux.ibm.com>
> Tested-by: Anushree Mathur <anushree.mathur@linux.ibm.com>
> Cc: <stable@vger.kernel.org> # v6.13+
> Signed-off-by: Amit Machhiwal <amachhiw@linux.ibm.com>
> ---
> Changelog:
>
> * Moved this patch out of the v3 series [1] as discussed here [2]
> * Addressed below review comments from Ritesh:
> - Based the PVR validation on cpu features
> - Fixed hcall name typo
> - Stable backport
>
> [1] https://lore.kernel.org/all/20260522152744.55251-1-amachhiw@linux.ibm.com/
> [2] https://lore.kernel.org/all/20260522152744.55251-2-amachhiw@linux.ibm.com/
> ---
> arch/powerpc/kvm/book3s_hv.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index 61dbeea317f3..e16dbb199366 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -446,7 +446,17 @@ static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat)
> guest_pcr_bit = PCR_ARCH_300;
> break;
> case PVR_ARCH_31:
> + guest_pcr_bit = PCR_ARCH_31;
> + break;
> case PVR_ARCH_31_P11:
> + /*
> + * Need to check this for ISA 3.1, as Power10 and
> + * Power11 share the same PCR. For any subsequent ISA
> + * versions, this will be taken care of by the guest vs
> + * host PCR comparison below.
> + */
> + if (!cpu_has_feature(CPU_FTR_P11_PVR))
> + return -EINVAL;
> guest_pcr_bit = PCR_ARCH_31;
> break;
> default:
>
> base-commit: ba3e43a9e601636f5edb54e259a74f96ca3b8fd8
> --
> 2.50.1 (Apple Git-155)
>
I booted a KVM guest on LPAR with this patch in the following scenarios:
1. P10 guest on P10 host: No error observed
2. P11 guest on P11 host: No error observed
3. P11 guest on P11 host booted in P10 compat mode: No error observed
Tested-by: Gautam Menghani <gautam@linux.ibm.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
2026-06-04 14:20 ` Gautam Menghani
@ 2026-06-05 7:25 ` Vaibhav Jain
0 siblings, 0 replies; 6+ messages in thread
From: Vaibhav Jain @ 2026-06-05 7:25 UTC (permalink / raw)
To: Gautam Menghani, Amit Machhiwal
Cc: linuxppc-dev, Madhavan Srinivasan, Harsh Prateek Bora,
Ritesh Harjani, Anushree Mathur, Nicholas Piggin,
Michael Ellerman, Christophe Leroy (CS GROUP), kvm, stable,
linux-kernel
Hi Gautam,
Thanks for testing this patch. Few questions:
Gautam Menghani <gautam@linux.ibm.com> writes:
> On Wed, Jun 03, 2026 at 07:45:39PM +0530, Amit Machhiwal wrote:
>> On IBM POWER systems, newer processor generations can operate in
>> compatibility modes corresponding to earlier generations. This becomes
>> relevant for nested virtualization, where nested KVM guests may need to
>> run with a specific processor compatibility level.
>>
<snip>
>
> I booted a KVM guest on LPAR with this patch in the following scenarios:
<snip>
> 3. P11 guest on P11 host booted in P10 compat mode: No error observed
This should have resulted in an error since booting a P11 guest on P10
compat mode host is not allowed with/without this patch. Can you please
check your test env and share the boot results.
>
> Tested-by: Gautam Menghani <gautam@linux.ibm.com>
--
Cheers
~ Vaibhav
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
2026-06-03 14:15 [PATCH] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode Amit Machhiwal
` (2 preceding siblings ...)
2026-06-04 14:20 ` Gautam Menghani
@ 2026-06-05 7:30 ` Vaibhav Jain
3 siblings, 0 replies; 6+ messages in thread
From: Vaibhav Jain @ 2026-06-05 7:30 UTC (permalink / raw)
To: Amit Machhiwal, linuxppc-dev, Madhavan Srinivasan
Cc: Amit Machhiwal, Harsh Prateek Bora, Ritesh Harjani,
Anushree Mathur, Nicholas Piggin, Michael Ellerman,
Christophe Leroy (CS GROUP), kvm, stable, linux-kernel
Amit Machhiwal <amachhiw@linux.ibm.com> writes:
> On IBM POWER systems, newer processor generations can operate in
> compatibility modes corresponding to earlier generations. This becomes
> relevant for nested virtualization, where nested KVM guests may need to
> run with a specific processor compatibility level.
>
> Currently, when running a nested KVM guest (L2) inside a Power11 pSeries
> logical partition (L1) booted in Power10 compatibility mode, the guest
> fails to boot while setting 'arch_compat'. This happens because the CPU
> class is derived from the hardware PVR (via mfspr()), which reflects the
> physical processor generation (Power11), rather than the effective
> compatibility mode (Power10).
>
> As a result, userspace may request a Power11 arch_compat for the L2
> guest. However, the L1 partition, running in Power10 compatibility, has
> only negotiated support up to Power10 with the Power Hypervisor (L0).
> When H_GUEST_SET_STATE is invoked with a Power11 Logical PVR, the
> hypervisor rejects the request, leading to a late guest boot failure:
>
> KVM-NESTEDv2: couldn't set guest wide elements
> [..KVM reg dump..]
>
> This situation should be detected earlier. Rejecting unsupported
> 'arch_compat' values in 'kvmppc_set_arch_compat()' avoids issuing an
> invalid H_GUEST_SET_STATE hcall and provides a clearer failure mode.
>
> Add a check to reject Power11 'arch_compat' requests when the host is
> running in Power10 compatibility mode, returning -EINVAL early instead
> of deferring the failure to the hypervisor.
>
> Suggested-by: Vaibhav Jain <vaibhav@linux.ibm.com>
> Tested-by: Anushree Mathur <anushree.mathur@linux.ibm.com>
> Cc: <stable@vger.kernel.org> # v6.13+
> Signed-off-by: Amit Machhiwal <amachhiw@linux.ibm.com>
Thanks, this LGTM
Reviewed-by: Vaibhav Jain <vaibhav@linux.ibm.com>
--
Cheers
~ Vaibhav
^ permalink raw reply [flat|nested] 6+ messages in thread