* [PATCH v3] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
@ 2026-06-09 5:33 Amit Machhiwal
2026-06-16 9:47 ` Ritesh Harjani
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Amit Machhiwal @ 2026-06-09 5:33 UTC (permalink / raw)
To: linuxppc-dev, Madhavan Srinivasan
Cc: Amit Machhiwal, Vaibhav Jain, Harsh Prateek Bora, Ritesh Harjani,
Anushree Mathur, Gautam Menghani, Mukesh Kumar Chaurasiya,
Nicholas Piggin, Michael Ellerman, Christophe Leroy (CS GROUP),
Thomas Huth, kvm, stable, linux-kernel
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 and rejected by KVM. Without
proper validation, if userspace ignores the error, the guest may continue
to boot in Power11 raw mode on a Power10 compatibility host, which should
not be allowed.
Introduce a validation mechanism that detects unsupported arch_compat
values early in the guest initialization path. When an unsupported
arch_compat is requested (e.g., Power11 on a Power10 compatibility mode
host), kvmppc_set_arch_compat() uses cpu_has_feature(CPU_FTR_P11_PVR) to
detect the mismatch and sets arch_compat to PVR_ARCH_INVALID. This
triggers kvmppc_sanity_check() to mark the vCPU as invalid by setting
vcpu->arch.sane to false. On the next vCPU run, kvmppc_vcpu_run_hv()
checks this flag and returns -EINVAL, preventing the guest from running
with an invalid processor compatibility configuration.
With this, when a Power11 arch_compat is requested on a Power10
compatibility mode host, the guest fails early during boot with:
error: kvm run failed Invalid argument
This provides a much clearer failure mode compared to the previous
behavior where the guest could boot in Power11 raw mode (if userspace
ignored the error) or fail late during H_GUEST_SET_STATE.
Suggested-by: Vaibhav Jain <vaibhav@linux.ibm.com>
Reviewed-by: Vaibhav Jain <vaibhav@linux.ibm.com>
Cc: stable@vger.kernel.org # v6.13+
Signed-off-by: Amit Machhiwal <amachhiw@linux.ibm.com>
---
Changes in v3:
* Fixed null pointer dereference in kvmppc_sanity_check(): added check for
vcpu->arch.vcore before accessing arch_compat, as vcore is NULL for Book3S
PR and BookE guests (only Book3S HV uses vcore) [Reported by Sashiko AI]
* Added Reviewed-by tag from Vaibhav
Changes in v2:
* Fixed issue where v1 allowed guest to boot in Power11 raw mode when
userspace ignored the error, by adding validation in kvmppc_sanity_check()
to ensure early failure during vCPU run [Found the issue after posting v1,
also reported by Gautam.]
* Introduced PVR_ARCH_INVALID constant for marking invalid arch_compat
* Dropped all Reviewed-by and Tested-by tags due to code changes; requesting
fresh reviews
* v1: https://lore.kernel.org/all/20260603141539.47620-1-amachhiw@linux.ibm.com/
Changes in v1:
* 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/include/asm/reg.h | 1 +
arch/powerpc/kvm/book3s_hv.c | 15 ++++++++++++++-
arch/powerpc/kvm/powerpc.c | 4 ++++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
index 3449dd2b577d..7472b9522f71 100644
--- a/arch/powerpc/include/asm/reg.h
+++ b/arch/powerpc/include/asm/reg.h
@@ -1356,6 +1356,7 @@
#define PVR_ARCH_300 0x0f000005
#define PVR_ARCH_31 0x0f000006
#define PVR_ARCH_31_P11 0x0f000007
+#define PVR_ARCH_INVALID 0xffffffff
/* Macros for setting and retrieving special purpose registers */
#ifndef __ASSEMBLER__
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 61dbeea317f3..f9380ef65750 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -446,7 +446,19 @@ 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)) {
+ arch_compat = PVR_ARCH_INVALID;
+ goto out;
+ }
guest_pcr_bit = PCR_ARCH_31;
break;
default:
@@ -469,6 +481,7 @@ static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat)
return -EINVAL;
}
+out:
spin_lock(&vc->lock);
vc->arch_compat = arch_compat;
kvmhv_nestedv2_mark_dirty(vcpu, KVMPPC_GSID_LOGICAL_PVR);
@@ -479,7 +492,7 @@ static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat)
vc->pcr = (host_pcr_bit - guest_pcr_bit) | PCR_MASK;
spin_unlock(&vc->lock);
- return 0;
+ return kvmppc_sanity_check(vcpu);
}
static void kvmppc_dump_regs(struct kvm_vcpu *vcpu)
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 00302399fc37..98de68379b18 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -258,6 +258,10 @@ int kvmppc_sanity_check(struct kvm_vcpu *vcpu)
if (!vcpu->arch.pvr)
goto out;
+ if (vcpu->arch.vcore &&
+ vcpu->arch.vcore->arch_compat == PVR_ARCH_INVALID)
+ goto out;
+
/* PAPR only works with book3s_64 */
if ((vcpu->arch.cpu_type != KVM_CPU_3S_64) && vcpu->arch.papr_enabled)
goto out;
base-commit: 2d3090a8aeb596a26935db0955d46c9a5db5c6ce
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v3] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
2026-06-09 5:33 [PATCH v3] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode Amit Machhiwal
@ 2026-06-16 9:47 ` Ritesh Harjani
2026-06-16 10:54 ` Amit Machhiwal
2026-06-16 10:19 ` Anushree Mathur
2026-06-16 12:22 ` Gautam Menghani
2 siblings, 1 reply; 9+ messages in thread
From: Ritesh Harjani @ 2026-06-16 9:47 UTC (permalink / raw)
To: Amit Machhiwal, linuxppc-dev, Madhavan Srinivasan
Cc: Amit Machhiwal, Vaibhav Jain, Harsh Prateek Bora, Anushree Mathur,
Gautam Menghani, Mukesh Kumar Chaurasiya, Nicholas Piggin,
Michael Ellerman, Christophe Leroy (CS GROUP), Thomas Huth, 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 and rejected by KVM. Without
> proper validation, if userspace ignores the error, the guest may continue
> to boot in Power11 raw mode on a Power10 compatibility host, which should
> not be allowed.
>
> Introduce a validation mechanism that detects unsupported arch_compat
> values early in the guest initialization path. When an unsupported
> arch_compat is requested (e.g., Power11 on a Power10 compatibility mode
> host), kvmppc_set_arch_compat() uses cpu_has_feature(CPU_FTR_P11_PVR) to
> detect the mismatch and sets arch_compat to PVR_ARCH_INVALID. This
> triggers kvmppc_sanity_check() to mark the vCPU as invalid by setting
> vcpu->arch.sane to false. On the next vCPU run, kvmppc_vcpu_run_hv()
> checks this flag and returns -EINVAL, preventing the guest from running
> with an invalid processor compatibility configuration.
>
> With this, when a Power11 arch_compat is requested on a Power10
> compatibility mode host, the guest fails early during boot with:
>
> error: kvm run failed Invalid argument
>
> This provides a much clearer failure mode compared to the previous
> behavior where the guest could boot in Power11 raw mode (if userspace
> ignored the error) or fail late during H_GUEST_SET_STATE.
>
> Suggested-by: Vaibhav Jain <vaibhav@linux.ibm.com>
> Reviewed-by: Vaibhav Jain <vaibhav@linux.ibm.com>
> Cc: stable@vger.kernel.org # v6.13+
> Signed-off-by: Amit Machhiwal <amachhiw@linux.ibm.com>
> ---
> Changes in v3:
> * Fixed null pointer dereference in kvmppc_sanity_check(): added check for
> vcpu->arch.vcore before accessing arch_compat, as vcore is NULL for Book3S
> PR and BookE guests (only Book3S HV uses vcore) [Reported by Sashiko AI]
> * Added Reviewed-by tag from Vaibhav
>
> Changes in v2:
> * Fixed issue where v1 allowed guest to boot in Power11 raw mode when
> userspace ignored the error, by adding validation in kvmppc_sanity_check()
> to ensure early failure during vCPU run [Found the issue after posting v1,
> also reported by Gautam.]
Would be nice if we could post the matrix test results which Gautam
posted earlier with this v3. I guess you meant you already tested all of
those - it would be nice if we could explicitely put that info in the changelog.
> * Introduced PVR_ARCH_INVALID constant for marking invalid arch_compat
> * Dropped all Reviewed-by and Tested-by tags due to code changes; requesting
> fresh reviews
> * v1: https://lore.kernel.org/all/20260603141539.47620-1-amachhiw@linux.ibm.com/
>
> Changes in v1:
> * 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/include/asm/reg.h | 1 +
> arch/powerpc/kvm/book3s_hv.c | 15 ++++++++++++++-
> arch/powerpc/kvm/powerpc.c | 4 ++++
> 3 files changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
> index 3449dd2b577d..7472b9522f71 100644
> --- a/arch/powerpc/include/asm/reg.h
> +++ b/arch/powerpc/include/asm/reg.h
> @@ -1356,6 +1356,7 @@
> #define PVR_ARCH_300 0x0f000005
> #define PVR_ARCH_31 0x0f000006
> #define PVR_ARCH_31_P11 0x0f000007
> +#define PVR_ARCH_INVALID 0xffffffff
Logical processor version is defined as part of the PAPR spec. We should
ensure that this invalid PVR is also documented in the PAPR spec.
If you have already taken care of that, then please confirm and feel free to add:
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
2026-06-09 5:33 [PATCH v3] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode Amit Machhiwal
2026-06-16 9:47 ` Ritesh Harjani
@ 2026-06-16 10:19 ` Anushree Mathur
2026-06-16 12:22 ` Gautam Menghani
2 siblings, 0 replies; 9+ messages in thread
From: Anushree Mathur @ 2026-06-16 10:19 UTC (permalink / raw)
To: Amit Machhiwal, linuxppc-dev, Madhavan Srinivasan
Cc: Vaibhav Jain, Harsh Prateek Bora, Ritesh Harjani, Gautam Menghani,
Mukesh Kumar Chaurasiya, Nicholas Piggin, Michael Ellerman,
Christophe Leroy (CS GROUP), Thomas Huth, kvm, stable,
linux-kernel
Hi Amit,
I have tested this patch and it is working as expected. Here is my
analysis :
After applying the patch all the scenarios works perfectly fine and as
expected.
i) Bringing up P11(Power11) guest on P11 host :
Guest lscpu output after bringing up the guest
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 10
On-line CPU(s) list: 0-9
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
ii) Bringing up P10(Power10) guest on P11 host:
Guest lscpu output -
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 10
On-line CPU(s) list: 0-9
Model name: POWER10 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
iii) Bringing up P11 guest on compat P10 host:
KVM guest fails to boots with P11 PVR when Host is in P10 compat mode as
expected -
Calling ibm,client-architecture-support...qemu-system-ppc64: warning:
kernel_irqchip allowed but unavailable: IRQ_XIVE capability must be
present for KVM
Falling back to kernel-irqchip=off
error: kvm run failed Invalid argument
NIP 000000007daf9790 LR 000000007daf1b7c CTR 000000007daf1b44 XER
0000000020040000 CPU#0
MSR 8000000000103000 HID0 0000000000000000 HF 6c002000 iidx 3 didx 3
TB 00000000 00000000 DECR 0
GPR00 8000000000003000 000000007e581e20 000000007db26c00 0000000000000000
GPR04 0000000002e10c80 000000007df80000 0000000000200000 000000007df80000
GPR08 000000007db6e5d8 000000007e66b5d8 000000007db6e5d0 0000000000003000
GPR12 8000000000000001 0000000000000000 0000000000000000 0000000000000000
GPR16 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20 0000000000000000 0000000000000000 0000000001883676 000000007db21cc0
GPR24 000000007db66000 000000007e66b508 0000000001883676 0000000000000003
GPR28 000000007db6e5e0 000000007db224b0 000000007daf274c 000000007db76000
CR 20000402 [ E - - - - G - E ] RES 000@ffffffffffffffff
SRR0 000000007daf9790 SRR1 8000000000102000 PVR 0000000000820200
VRSAVE 0000000000000000
SPRG0 0000000000000000 SPRG1 000000000000ff10 SPRG2 0000000000000000
SPRG3 0000000000000000
SPRG4 0000000000000000 SPRG5 0000000000000000 SPRG6 0000000000000000
SPRG7 0000000000000000
CFAR 0000000000000000
LPCR 0000000000020400
PTCR 0000000000000000 DAR 0000000000000000 DSISR 0000000000000000
iv) Bringing up P10 guest on compat P10 host:
Guest lscpu output -
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 10
On-line CPU(s) list: 0-9
Model name: POWER10 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 1
Core(s) per socket: 10
Socket(s): 1
Virtualization features:
Please feel free to add:
Tested-by: Anushree Mathur <anushree.mathur@linux.ibm.com>
Thank you,
Anushree Mathur
On 09/06/26 11:03 AM, 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 and rejected by KVM. Without
> proper validation, if userspace ignores the error, the guest may continue
> to boot in Power11 raw mode on a Power10 compatibility host, which should
> not be allowed.
>
> Introduce a validation mechanism that detects unsupported arch_compat
> values early in the guest initialization path. When an unsupported
> arch_compat is requested (e.g., Power11 on a Power10 compatibility mode
> host), kvmppc_set_arch_compat() uses cpu_has_feature(CPU_FTR_P11_PVR) to
> detect the mismatch and sets arch_compat to PVR_ARCH_INVALID. This
> triggers kvmppc_sanity_check() to mark the vCPU as invalid by setting
> vcpu->arch.sane to false. On the next vCPU run, kvmppc_vcpu_run_hv()
> checks this flag and returns -EINVAL, preventing the guest from running
> with an invalid processor compatibility configuration.
>
> With this, when a Power11 arch_compat is requested on a Power10
> compatibility mode host, the guest fails early during boot with:
>
> error: kvm run failed Invalid argument
>
> This provides a much clearer failure mode compared to the previous
> behavior where the guest could boot in Power11 raw mode (if userspace
> ignored the error) or fail late during H_GUEST_SET_STATE.
>
> Suggested-by: Vaibhav Jain <vaibhav@linux.ibm.com>
> Reviewed-by: Vaibhav Jain <vaibhav@linux.ibm.com>
> Cc: stable@vger.kernel.org # v6.13+
> Signed-off-by: Amit Machhiwal <amachhiw@linux.ibm.com>
> ---
> Changes in v3:
> * Fixed null pointer dereference in kvmppc_sanity_check(): added check for
> vcpu->arch.vcore before accessing arch_compat, as vcore is NULL for Book3S
> PR and BookE guests (only Book3S HV uses vcore) [Reported by Sashiko AI]
> * Added Reviewed-by tag from Vaibhav
>
> Changes in v2:
> * Fixed issue where v1 allowed guest to boot in Power11 raw mode when
> userspace ignored the error, by adding validation in kvmppc_sanity_check()
> to ensure early failure during vCPU run [Found the issue after posting v1,
> also reported by Gautam.]
> * Introduced PVR_ARCH_INVALID constant for marking invalid arch_compat
> * Dropped all Reviewed-by and Tested-by tags due to code changes; requesting
> fresh reviews
> * v1: https://lore.kernel.org/all/20260603141539.47620-1-amachhiw@linux.ibm.com/
>
> Changes in v1:
> * 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/include/asm/reg.h | 1 +
> arch/powerpc/kvm/book3s_hv.c | 15 ++++++++++++++-
> arch/powerpc/kvm/powerpc.c | 4 ++++
> 3 files changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
> index 3449dd2b577d..7472b9522f71 100644
> --- a/arch/powerpc/include/asm/reg.h
> +++ b/arch/powerpc/include/asm/reg.h
> @@ -1356,6 +1356,7 @@
> #define PVR_ARCH_300 0x0f000005
> #define PVR_ARCH_31 0x0f000006
> #define PVR_ARCH_31_P11 0x0f000007
> +#define PVR_ARCH_INVALID 0xffffffff
>
> /* Macros for setting and retrieving special purpose registers */
> #ifndef __ASSEMBLER__
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index 61dbeea317f3..f9380ef65750 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -446,7 +446,19 @@ 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)) {
> + arch_compat = PVR_ARCH_INVALID;
> + goto out;
> + }
> guest_pcr_bit = PCR_ARCH_31;
> break;
> default:
> @@ -469,6 +481,7 @@ static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat)
> return -EINVAL;
> }
>
> +out:
> spin_lock(&vc->lock);
> vc->arch_compat = arch_compat;
> kvmhv_nestedv2_mark_dirty(vcpu, KVMPPC_GSID_LOGICAL_PVR);
> @@ -479,7 +492,7 @@ static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat)
> vc->pcr = (host_pcr_bit - guest_pcr_bit) | PCR_MASK;
> spin_unlock(&vc->lock);
>
> - return 0;
> + return kvmppc_sanity_check(vcpu);
> }
>
> static void kvmppc_dump_regs(struct kvm_vcpu *vcpu)
> diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
> index 00302399fc37..98de68379b18 100644
> --- a/arch/powerpc/kvm/powerpc.c
> +++ b/arch/powerpc/kvm/powerpc.c
> @@ -258,6 +258,10 @@ int kvmppc_sanity_check(struct kvm_vcpu *vcpu)
> if (!vcpu->arch.pvr)
> goto out;
>
> + if (vcpu->arch.vcore &&
> + vcpu->arch.vcore->arch_compat == PVR_ARCH_INVALID)
> + goto out;
> +
> /* PAPR only works with book3s_64 */
> if ((vcpu->arch.cpu_type != KVM_CPU_3S_64) && vcpu->arch.papr_enabled)
> goto out;
>
> base-commit: 2d3090a8aeb596a26935db0955d46c9a5db5c6ce
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
2026-06-16 9:47 ` Ritesh Harjani
@ 2026-06-16 10:54 ` Amit Machhiwal
2026-06-16 12:08 ` Ritesh Harjani
0 siblings, 1 reply; 9+ messages in thread
From: Amit Machhiwal @ 2026-06-16 10:54 UTC (permalink / raw)
To: Ritesh Harjani
Cc: Amit Machhiwal, linuxppc-dev, Madhavan Srinivasan, Vaibhav Jain,
Harsh Prateek Bora, Anushree Mathur, Gautam Menghani,
Mukesh Kumar Chaurasiya, Nicholas Piggin, Michael Ellerman,
Christophe Leroy (CS GROUP), Thomas Huth, kvm, stable,
linux-kernel
Hi Ritesh,
Thank you for the review and feedback. Please find my response below.
On 2026/06/16 03:17 PM, Ritesh Harjani wrote:
> 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 and rejected by KVM. Without
> > proper validation, if userspace ignores the error, the guest may continue
> > to boot in Power11 raw mode on a Power10 compatibility host, which should
> > not be allowed.
> >
> > Introduce a validation mechanism that detects unsupported arch_compat
> > values early in the guest initialization path. When an unsupported
> > arch_compat is requested (e.g., Power11 on a Power10 compatibility mode
> > host), kvmppc_set_arch_compat() uses cpu_has_feature(CPU_FTR_P11_PVR) to
> > detect the mismatch and sets arch_compat to PVR_ARCH_INVALID. This
> > triggers kvmppc_sanity_check() to mark the vCPU as invalid by setting
> > vcpu->arch.sane to false. On the next vCPU run, kvmppc_vcpu_run_hv()
> > checks this flag and returns -EINVAL, preventing the guest from running
> > with an invalid processor compatibility configuration.
> >
> > With this, when a Power11 arch_compat is requested on a Power10
> > compatibility mode host, the guest fails early during boot with:
> >
> > error: kvm run failed Invalid argument
> >
> > This provides a much clearer failure mode compared to the previous
> > behavior where the guest could boot in Power11 raw mode (if userspace
> > ignored the error) or fail late during H_GUEST_SET_STATE.
> >
> > Suggested-by: Vaibhav Jain <vaibhav@linux.ibm.com>
> > Reviewed-by: Vaibhav Jain <vaibhav@linux.ibm.com>
> > Cc: stable@vger.kernel.org # v6.13+
> > Signed-off-by: Amit Machhiwal <amachhiw@linux.ibm.com>
> > ---
> > Changes in v3:
> > * Fixed null pointer dereference in kvmppc_sanity_check(): added check for
> > vcpu->arch.vcore before accessing arch_compat, as vcore is NULL for Book3S
> > PR and BookE guests (only Book3S HV uses vcore) [Reported by Sashiko AI]
> > * Added Reviewed-by tag from Vaibhav
> >
> > Changes in v2:
> > * Fixed issue where v1 allowed guest to boot in Power11 raw mode when
> > userspace ignored the error, by adding validation in kvmppc_sanity_check()
> > to ensure early failure during vCPU run [Found the issue after posting v1,
> > also reported by Gautam.]
>
> Would be nice if we could post the matrix test results which Gautam
> posted earlier with this v3. I guess you meant you already tested all of
> those - it would be nice if we could explicitely put that info in the changelog.
Regarding the test matrix: Both Anushree and I have tested all the
scenarios comprehensively. Anushree has shared her detailed test results
in her reply to the patch [1], covering:
- P11 guest on P11 host -> Works
- P10 guest on P11 host -> Works
- P11 guest on compat-P10 host -> Correctly fails with "Invalid argument"
- P10 guest on compat-P10 host -> Works
I have also verified all these scenarios with the same results.
If you'd prefer that I add the test matrix explicitly to the changelog
and send a new version, please let me know and I'll be happy to do so.
[1] https://lore.kernel.org/all/4e833bec-67ae-4b78-9a50-e1b9dec4029a@linux.ibm.com/
>
> > * Introduced PVR_ARCH_INVALID constant for marking invalid arch_compat
> > * Dropped all Reviewed-by and Tested-by tags due to code changes; requesting
> > fresh reviews
> > * v1: https://lore.kernel.org/all/20260603141539.47620-1-amachhiw@linux.ibm.com/
> >
> > Changes in v1:
> > * 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/include/asm/reg.h | 1 +
> > arch/powerpc/kvm/book3s_hv.c | 15 ++++++++++++++-
> > arch/powerpc/kvm/powerpc.c | 4 ++++
> > 3 files changed, 19 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
> > index 3449dd2b577d..7472b9522f71 100644
> > --- a/arch/powerpc/include/asm/reg.h
> > +++ b/arch/powerpc/include/asm/reg.h
> > @@ -1356,6 +1356,7 @@
> > #define PVR_ARCH_300 0x0f000005
> > #define PVR_ARCH_31 0x0f000006
> > #define PVR_ARCH_31_P11 0x0f000007
> > +#define PVR_ARCH_INVALID 0xffffffff
>
> Logical processor version is defined as part of the PAPR spec. We should
> ensure that this invalid PVR is also documented in the PAPR spec.
>
> If you have already taken care of that, then please confirm and feel free to add:
Regarding the PAPR specification documentation: The PAPR spec documents
the valid Processor Version Register (PVR) values for each processor
generation (POWER8, POWER9, POWER10, POWER11, etc.). However, the
PVR_ARCH_INVALID value (0xffffffff) introduced in this patch series is a
KVM implementation detail used internally to mark invalid compatibility
mode requests - it's not an architectural value that would be defined in
PAPR itself.
The validation logic and the use of PVR_ARCH_INVALID as a sentinel value
are documented in the kernel code and commit message.
Please let me know if this addresses your concern, or if you'd like me
to add specific documentation.
>
> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Thanks you again for taking the time out of the review.
~Amit
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
2026-06-16 10:54 ` Amit Machhiwal
@ 2026-06-16 12:08 ` Ritesh Harjani
2026-06-16 12:59 ` Amit Machhiwal
0 siblings, 1 reply; 9+ messages in thread
From: Ritesh Harjani @ 2026-06-16 12:08 UTC (permalink / raw)
To: Amit Machhiwal
Cc: Amit Machhiwal, linuxppc-dev, Madhavan Srinivasan, Vaibhav Jain,
Harsh Prateek Bora, Anushree Mathur, Gautam Menghani,
Mukesh Kumar Chaurasiya, Nicholas Piggin, Michael Ellerman,
Christophe Leroy (CS GROUP), Thomas Huth, kvm, stable,
linux-kernel
Amit Machhiwal <amachhiw@linux.ibm.com> writes:
>> > diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
>> > index 3449dd2b577d..7472b9522f71 100644
>> > --- a/arch/powerpc/include/asm/reg.h
>> > +++ b/arch/powerpc/include/asm/reg.h
>> > @@ -1356,6 +1356,7 @@
>> > #define PVR_ARCH_300 0x0f000005
>> > #define PVR_ARCH_31 0x0f000006
>> > #define PVR_ARCH_31_P11 0x0f000007
>> > +#define PVR_ARCH_INVALID 0xffffffff
>>
>> Logical processor version is defined as part of the PAPR spec. We should
>> ensure that this invalid PVR is also documented in the PAPR spec.
>>
>> If you have already taken care of that, then please confirm and feel free to add:
>
> Regarding the PAPR specification documentation: The PAPR spec documents
> the valid Processor Version Register (PVR) values for each processor
> generation (POWER8, POWER9, POWER10, POWER11, etc.). However, the
> PVR_ARCH_INVALID value (0xffffffff) introduced in this patch series is a
> KVM implementation detail used internally to mark invalid compatibility
> mode requests - it's not an architectural value that would be defined in
> PAPR itself.
>
> The validation logic and the use of PVR_ARCH_INVALID as a sentinel value
> are documented in the kernel code and commit message.
>
But that still worries me on what if PAPR wants to re-use this value for
some other purpose in future.
BTW, thinking more about it, if we purely want this to be in kernel only,
can we instead add, something like:
bool kpvr_compat; /* Does kernel supports this PVR */
rather than re-using & overloading arch_compat which has values that
comes from PAPR spec?
Thoughts?
-ritesh
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
2026-06-09 5:33 [PATCH v3] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode Amit Machhiwal
2026-06-16 9:47 ` Ritesh Harjani
2026-06-16 10:19 ` Anushree Mathur
@ 2026-06-16 12:22 ` Gautam Menghani
2 siblings, 0 replies; 9+ messages in thread
From: Gautam Menghani @ 2026-06-16 12:22 UTC (permalink / raw)
To: Amit Machhiwal
Cc: linuxppc-dev, Madhavan Srinivasan, Vaibhav Jain,
Harsh Prateek Bora, Ritesh Harjani, Anushree Mathur,
Mukesh Kumar Chaurasiya, Nicholas Piggin, Michael Ellerman,
Christophe Leroy (CS GROUP), Thomas Huth, kvm, stable,
linux-kernel
On Tue, Jun 09, 2026 at 11:03:27AM +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 and rejected by KVM. Without
> proper validation, if userspace ignores the error, the guest may continue
> to boot in Power11 raw mode on a Power10 compatibility host, which should
> not be allowed.
>
> Introduce a validation mechanism that detects unsupported arch_compat
> values early in the guest initialization path. When an unsupported
> arch_compat is requested (e.g., Power11 on a Power10 compatibility mode
> host), kvmppc_set_arch_compat() uses cpu_has_feature(CPU_FTR_P11_PVR) to
> detect the mismatch and sets arch_compat to PVR_ARCH_INVALID. This
> triggers kvmppc_sanity_check() to mark the vCPU as invalid by setting
> vcpu->arch.sane to false. On the next vCPU run, kvmppc_vcpu_run_hv()
> checks this flag and returns -EINVAL, preventing the guest from running
> with an invalid processor compatibility configuration.
>
> With this, when a Power11 arch_compat is requested on a Power10
> compatibility mode host, the guest fails early during boot with:
>
> error: kvm run failed Invalid argument
>
> This provides a much clearer failure mode compared to the previous
> behavior where the guest could boot in Power11 raw mode (if userspace
> ignored the error) or fail late during H_GUEST_SET_STATE.
>
> Suggested-by: Vaibhav Jain <vaibhav@linux.ibm.com>
> Reviewed-by: Vaibhav Jain <vaibhav@linux.ibm.com>
> Cc: stable@vger.kernel.org # v6.13+
> Signed-off-by: Amit Machhiwal <amachhiw@linux.ibm.com>
> ---
> Changes in v3:
> * Fixed null pointer dereference in kvmppc_sanity_check(): added check for
> vcpu->arch.vcore before accessing arch_compat, as vcore is NULL for Book3S
> PR and BookE guests (only Book3S HV uses vcore) [Reported by Sashiko AI]
> * Added Reviewed-by tag from Vaibhav
>
> Changes in v2:
> * Fixed issue where v1 allowed guest to boot in Power11 raw mode when
> userspace ignored the error, by adding validation in kvmppc_sanity_check()
> to ensure early failure during vCPU run [Found the issue after posting v1,
> also reported by Gautam.]
> * Introduced PVR_ARCH_INVALID constant for marking invalid arch_compat
> * Dropped all Reviewed-by and Tested-by tags due to code changes; requesting
> fresh reviews
> * v1: https://lore.kernel.org/all/20260603141539.47620-1-amachhiw@linux.ibm.com/
>
> Changes in v1:
> * 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/include/asm/reg.h | 1 +
> arch/powerpc/kvm/book3s_hv.c | 15 ++++++++++++++-
> arch/powerpc/kvm/powerpc.c | 4 ++++
> 3 files changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
> index 3449dd2b577d..7472b9522f71 100644
> --- a/arch/powerpc/include/asm/reg.h
> +++ b/arch/powerpc/include/asm/reg.h
> @@ -1356,6 +1356,7 @@
> #define PVR_ARCH_300 0x0f000005
> #define PVR_ARCH_31 0x0f000006
> #define PVR_ARCH_31_P11 0x0f000007
> +#define PVR_ARCH_INVALID 0xffffffff
>
> /* Macros for setting and retrieving special purpose registers */
> #ifndef __ASSEMBLER__
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index 61dbeea317f3..f9380ef65750 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -446,7 +446,19 @@ 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)) {
> + arch_compat = PVR_ARCH_INVALID;
> + goto out;
> + }
> guest_pcr_bit = PCR_ARCH_31;
> break;
> default:
> @@ -469,6 +481,7 @@ static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat)
> return -EINVAL;
> }
>
> +out:
> spin_lock(&vc->lock);
> vc->arch_compat = arch_compat;
> kvmhv_nestedv2_mark_dirty(vcpu, KVMPPC_GSID_LOGICAL_PVR);
> @@ -479,7 +492,7 @@ static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat)
> vc->pcr = (host_pcr_bit - guest_pcr_bit) | PCR_MASK;
> spin_unlock(&vc->lock);
>
> - return 0;
> + return kvmppc_sanity_check(vcpu);
> }
>
> static void kvmppc_dump_regs(struct kvm_vcpu *vcpu)
> diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
> index 00302399fc37..98de68379b18 100644
> --- a/arch/powerpc/kvm/powerpc.c
> +++ b/arch/powerpc/kvm/powerpc.c
> @@ -258,6 +258,10 @@ int kvmppc_sanity_check(struct kvm_vcpu *vcpu)
> if (!vcpu->arch.pvr)
> goto out;
>
> + if (vcpu->arch.vcore &&
> + vcpu->arch.vcore->arch_compat == PVR_ARCH_INVALID)
> + goto out;
> +
> /* PAPR only works with book3s_64 */
> if ((vcpu->arch.cpu_type != KVM_CPU_3S_64) && vcpu->arch.papr_enabled)
> goto out;
>
> base-commit: 2d3090a8aeb596a26935db0955d46c9a5db5c6ce
> --
> 2.50.1 (Apple Git-155)
LGTM
Acked-by: Gautam Menghani <gautam@linux.ibm.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
2026-06-16 12:08 ` Ritesh Harjani
@ 2026-06-16 12:59 ` Amit Machhiwal
2026-06-16 13:09 ` Ritesh Harjani
0 siblings, 1 reply; 9+ messages in thread
From: Amit Machhiwal @ 2026-06-16 12:59 UTC (permalink / raw)
To: Ritesh Harjani
Cc: Amit Machhiwal, linuxppc-dev, Madhavan Srinivasan, Vaibhav Jain,
Harsh Prateek Bora, Anushree Mathur, Gautam Menghani,
Mukesh Kumar Chaurasiya, Nicholas Piggin, Michael Ellerman,
Christophe Leroy (CS GROUP), Thomas Huth, kvm, stable,
linux-kernel
On 2026/06/16 05:38 PM, Ritesh Harjani wrote:
> Amit Machhiwal <amachhiw@linux.ibm.com> writes:
>
> >> > diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
> >> > index 3449dd2b577d..7472b9522f71 100644
> >> > --- a/arch/powerpc/include/asm/reg.h
> >> > +++ b/arch/powerpc/include/asm/reg.h
> >> > @@ -1356,6 +1356,7 @@
> >> > #define PVR_ARCH_300 0x0f000005
> >> > #define PVR_ARCH_31 0x0f000006
> >> > #define PVR_ARCH_31_P11 0x0f000007
> >> > +#define PVR_ARCH_INVALID 0xffffffff
> >>
> >> Logical processor version is defined as part of the PAPR spec. We should
> >> ensure that this invalid PVR is also documented in the PAPR spec.
> >>
> >> If you have already taken care of that, then please confirm and feel free to add:
> >
> > Regarding the PAPR specification documentation: The PAPR spec documents
> > the valid Processor Version Register (PVR) values for each processor
> > generation (POWER8, POWER9, POWER10, POWER11, etc.). However, the
> > PVR_ARCH_INVALID value (0xffffffff) introduced in this patch series is a
> > KVM implementation detail used internally to mark invalid compatibility
> > mode requests - it's not an architectural value that would be defined in
> > PAPR itself.
> >
> > The validation logic and the use of PVR_ARCH_INVALID as a sentinel value
> > are documented in the kernel code and commit message.
> >
>
> But that still worries me on what if PAPR wants to re-use this value for
> some other purpose in future.
This is a valid concern about potential future conflicts with PAPR.
However, I'd like to point out that PAPR explicitly specifies:
"The first byte of the logical processor version value shall be 0x0F."
Since PVR_ARCH_INVALID (0xffffffff) has a first byte of 0xFF, it's
explicitly outside the valid PAPR-defined range for logical PVR values.
This means there shouldn't be any risk of future conflict with PAPR
specifications.
Please let me know what you think about this?
Thanks,
Amit
>
> BTW, thinking more about it, if we purely want this to be in kernel only,
> can we instead add, something like:
>
> bool kpvr_compat; /* Does kernel supports this PVR */
>
> rather than re-using & overloading arch_compat which has values that
> comes from PAPR spec?
>
> Thoughts?
>
> -ritesh
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
2026-06-16 12:59 ` Amit Machhiwal
@ 2026-06-16 13:09 ` Ritesh Harjani
2026-06-16 13:37 ` Amit Machhiwal
0 siblings, 1 reply; 9+ messages in thread
From: Ritesh Harjani @ 2026-06-16 13:09 UTC (permalink / raw)
To: Amit Machhiwal
Cc: Amit Machhiwal, linuxppc-dev, Madhavan Srinivasan, Vaibhav Jain,
Harsh Prateek Bora, Anushree Mathur, Gautam Menghani,
Mukesh Kumar Chaurasiya, Nicholas Piggin, Michael Ellerman,
Christophe Leroy (CS GROUP), Thomas Huth, kvm, stable,
linux-kernel
Amit Machhiwal <amachhiw@linux.ibm.com> writes:
> On 2026/06/16 05:38 PM, Ritesh Harjani wrote:
>> Amit Machhiwal <amachhiw@linux.ibm.com> writes:
>>
>> >> > diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
>> >> > index 3449dd2b577d..7472b9522f71 100644
>> >> > --- a/arch/powerpc/include/asm/reg.h
>> >> > +++ b/arch/powerpc/include/asm/reg.h
>> >> > @@ -1356,6 +1356,7 @@
>> >> > #define PVR_ARCH_300 0x0f000005
>> >> > #define PVR_ARCH_31 0x0f000006
>> >> > #define PVR_ARCH_31_P11 0x0f000007
>> >> > +#define PVR_ARCH_INVALID 0xffffffff
>> >>
>> >> Logical processor version is defined as part of the PAPR spec. We should
>> >> ensure that this invalid PVR is also documented in the PAPR spec.
>> >>
>> >> If you have already taken care of that, then please confirm and feel free to add:
>> >
>> > Regarding the PAPR specification documentation: The PAPR spec documents
>> > the valid Processor Version Register (PVR) values for each processor
>> > generation (POWER8, POWER9, POWER10, POWER11, etc.). However, the
>> > PVR_ARCH_INVALID value (0xffffffff) introduced in this patch series is a
>> > KVM implementation detail used internally to mark invalid compatibility
>> > mode requests - it's not an architectural value that would be defined in
>> > PAPR itself.
>> >
>> > The validation logic and the use of PVR_ARCH_INVALID as a sentinel value
>> > are documented in the kernel code and commit message.
>> >
>>
>> But that still worries me on what if PAPR wants to re-use this value for
>> some other purpose in future.
>
> This is a valid concern about potential future conflicts with PAPR.
> However, I'd like to point out that PAPR explicitly specifies:
>
> "The first byte of the logical processor version value shall be 0x0F."
>
> Since PVR_ARCH_INVALID (0xffffffff) has a first byte of 0xFF, it's
> explicitly outside the valid PAPR-defined range for logical PVR values.
> This means there shouldn't be any risk of future conflict with PAPR
> specifications.
>
aah ok.. That make sense. Thanks for confirming that.
Can we please update a small comment in the code and log this info,
maybe something like:
/*
* PAPR specifies that the first byte of a valid logical PVR value is
* 0x0f. 0xffffffff therefore lies permanently outside the PAPR-defined
* range and is safe to repurpose as a kernel-internal sentinel. KVM
* stores it in vc->arch_compat when userspace requests an unsupported
* compatibility mode (e.g. Power11 on a Power10 compat host);
* kvmppc_sanity_check() detects this and prevents the vCPU from running
* until a valid arch_compat is set.
*/
#define PVR_ARCH_INVALID 0xffffffff
-ritesh
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
2026-06-16 13:09 ` Ritesh Harjani
@ 2026-06-16 13:37 ` Amit Machhiwal
0 siblings, 0 replies; 9+ messages in thread
From: Amit Machhiwal @ 2026-06-16 13:37 UTC (permalink / raw)
To: Ritesh Harjani
Cc: Amit Machhiwal, linuxppc-dev, Madhavan Srinivasan, Vaibhav Jain,
Harsh Prateek Bora, Anushree Mathur, Gautam Menghani,
Mukesh Kumar Chaurasiya, Nicholas Piggin, Michael Ellerman,
Christophe Leroy (CS GROUP), Thomas Huth, kvm, stable,
linux-kernel
On 2026/06/16 06:39 PM, Ritesh Harjani wrote:
> Amit Machhiwal <amachhiw@linux.ibm.com> writes:
>
> > On 2026/06/16 05:38 PM, Ritesh Harjani wrote:
> >> Amit Machhiwal <amachhiw@linux.ibm.com> writes:
> >>
> >> >> > diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
> >> >> > index 3449dd2b577d..7472b9522f71 100644
> >> >> > --- a/arch/powerpc/include/asm/reg.h
> >> >> > +++ b/arch/powerpc/include/asm/reg.h
> >> >> > @@ -1356,6 +1356,7 @@
> >> >> > #define PVR_ARCH_300 0x0f000005
> >> >> > #define PVR_ARCH_31 0x0f000006
> >> >> > #define PVR_ARCH_31_P11 0x0f000007
> >> >> > +#define PVR_ARCH_INVALID 0xffffffff
> >> >>
> >> >> Logical processor version is defined as part of the PAPR spec. We should
> >> >> ensure that this invalid PVR is also documented in the PAPR spec.
> >> >>
> >> >> If you have already taken care of that, then please confirm and feel free to add:
> >> >
> >> > Regarding the PAPR specification documentation: The PAPR spec documents
> >> > the valid Processor Version Register (PVR) values for each processor
> >> > generation (POWER8, POWER9, POWER10, POWER11, etc.). However, the
> >> > PVR_ARCH_INVALID value (0xffffffff) introduced in this patch series is a
> >> > KVM implementation detail used internally to mark invalid compatibility
> >> > mode requests - it's not an architectural value that would be defined in
> >> > PAPR itself.
> >> >
> >> > The validation logic and the use of PVR_ARCH_INVALID as a sentinel value
> >> > are documented in the kernel code and commit message.
> >> >
> >>
> >> But that still worries me on what if PAPR wants to re-use this value for
> >> some other purpose in future.
> >
> > This is a valid concern about potential future conflicts with PAPR.
> > However, I'd like to point out that PAPR explicitly specifies:
> >
> > "The first byte of the logical processor version value shall be 0x0F."
> >
> > Since PVR_ARCH_INVALID (0xffffffff) has a first byte of 0xFF, it's
> > explicitly outside the valid PAPR-defined range for logical PVR values.
> > This means there shouldn't be any risk of future conflict with PAPR
> > specifications.
> >
>
> aah ok.. That make sense. Thanks for confirming that.
> Can we please update a small comment in the code and log this info,
> maybe something like:
Sure, Ritesh. I can certainly do that in the next version.
Thanks,
Amit.
>
> /*
> * PAPR specifies that the first byte of a valid logical PVR value is
> * 0x0f. 0xffffffff therefore lies permanently outside the PAPR-defined
> * range and is safe to repurpose as a kernel-internal sentinel. KVM
> * stores it in vc->arch_compat when userspace requests an unsupported
> * compatibility mode (e.g. Power11 on a Power10 compat host);
> * kvmppc_sanity_check() detects this and prevents the vCPU from running
> * until a valid arch_compat is set.
> */
> #define PVR_ARCH_INVALID 0xffffffff
>
>
> -ritesh
>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-06-16 13:38 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-09 5:33 [PATCH v3] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode Amit Machhiwal
2026-06-16 9:47 ` Ritesh Harjani
2026-06-16 10:54 ` Amit Machhiwal
2026-06-16 12:08 ` Ritesh Harjani
2026-06-16 12:59 ` Amit Machhiwal
2026-06-16 13:09 ` Ritesh Harjani
2026-06-16 13:37 ` Amit Machhiwal
2026-06-16 10:19 ` Anushree Mathur
2026-06-16 12:22 ` Gautam Menghani
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox