KVM: PPC: Handle CPU compatibility mode for nested guests
Subsystems (4)
cover KVM: PPC: Handle CPU compatibility mode for nested guests
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 a problem for nested virtualization. When booting a nested KVM guest (L2) inside a host KVM guest (L1) running in a compatibility mode, userspace (e.g., QEMU) may derive the CPU model from the raw hardware PVR and attempt to configure the nested guest accordingly. However, the L1 partition is constrained by the compatibility level negotiated with the hypervisor (L0), and requests exceeding that level are rejected, leading to guest boot failures such as:
KVM-NESTEDv2: couldn't set guest wide elements
This series addresses the issue in two steps:
1. Detect and reject invalid compatibility requests early in KVM to avoid late failures.
2. Provide a mechanism for userspace to query the effective CPU compatibility modes supported by the host, so it can select an appropriate CPU model for nested guests.
To achieve this, the series introduces a new KVM capability and ioctl (KVM_CAP_PPC_COMPAT_CAPS / KVM_PPC_GET_COMPAT_CAPS) that expose the compatibility modes supported by the host.
The implementation supports both:
- PowerVM (nested API v2), where compatibility information is obtained via the H_GUEST_GET_CAPABILITIES hypercall.
- PowerNV (nested API v1), where compatibility is derived from the device tree ("cpu-version") representing the effective processor compatibility level.
This allows userspace (e.g., QEMU) to select a CPU model consistent with the host compatibility mode, avoiding mismatches and enabling successful nested guest boot.
Patch summary:
[1/6] Validate arch_compat against host compatibility mode [2/6] Introduce KVM_CAP_PPC_COMPAT_CAPS and ioctl [3/6] Wire up ioctl handling
[4/6] Implement capability retrieval for PowerVM (API v2) [5/6] Add PowerNV support (API v1)
[6/6] Document the new ioctl
Tested on:
- Power11 pSeries LPAR in Power10 compatibility mode (nested API v2)
- Power10 PowerNV system (and QEMU TCG PowerNV 11) with nested virtualization (API v1) with various combinations of KVM L1/L2 guests in various supported compatibility modes.
With this series, nested guests boot successfully in configurations where they previously failed due to compatibility mismatches.
Amit Machhiwal (6):
KVM: PPC: Book3S HV: Validate arch_compat against host compatibility
mode
KVM: PPC: Introduce KVM_CAP_PPC_COMPAT_CAPS and
KVM_PPC_GET_COMPAT_CAPS
KVM: PPC: Wire up KVM_PPC_GET_COMPAT_CAPS ioctl
KVM: PPC: Book3S HV: Implement compat CPU capability retrieval for KVM
on PowerVM
KVM: PPC: Book3S HV: Add support for compat CPU capabilities for KVM
on PowerNV
KVM: PPC: Document KVM_PPC_GET_COMPAT_CAPS ioctl
Documentation/virt/kvm/api.rst | 35 +++++++++++++++++ arch/powerpc/include/asm/kvm_ppc.h | 1 + arch/powerpc/include/uapi/asm/kvm.h | 6 +++ arch/powerpc/kvm/book3s_hv.c | 58 +++++++++++++++++++++++++++++ arch/powerpc/kvm/powerpc.c | 19 ++++++++++ include/uapi/linux/kvm.h | 4 ++ 6 files changed, 123 insertions(+)
base-commit: dca922e019dd758b4c1b4bec8f1d509efddeaab4 --
2.50.1
PATCH 1/6 KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
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_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_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.
--- arch/powerpc/kvm/book3s_hv.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/powerpc/kvm/book3s_hv.c +6 -0
@@ -446,7 +446,13 @@ 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 : +if ((PVR_ARCH_31 & cur_cpu_spec->pvr_mask) == + cur_cpu_spec->pvr_value) { +return -EINVAL ; + } guest_pcr_bit =PCR_ARCH_31 ;break ;default :
Signature · 1 line
2.50.1
Re: [PATCH 1/6] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
Quoted 39 lines · Amit Machhiwal
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 (viamfspr()), which reflects the physical processor generation (Power11), rather than the effective compatibility mode (Power10).As a result, userspace may request a Power11
arch_compatfor the L2 guest. However, the L1 partition, running in Power10 compatibility, has only negotiated support up to Power10 with the Power Hypervisor (L0). WhenH_SET_STATEis 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 invalidH_SET_STATEhcall 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-EINVALearly instead of deferring the failure to the hypervisor.Signed-off-by Amit Machhiwal <[email protected]>--- arch/powerpc/kvm/book3s_hv.c | 6 ++++++ 1 file changed, 6 insertions(+)arch/powerpc/kvm/book3s_hv.c +0
-0
arch/powerpc/kvm/book3s_hv.c static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat) · line 455
Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c +6
-0@@ -446,7 +446,13 @@ 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 : +if ((PVR_ARCH_31 & cur_cpu_spec->pvr_mask) == + cur_cpu_spec->pvr_value) { +return -EINVAL ; + }
Is it possible to keep the check generic for applicable ISA versions (ISA 3.1 onwards?) instead of keeping it specific for P11 ? Also need to add a comment, why it's not applicable for older ISAs.
Quoted 3 lines
arch/powerpc/kvm/book3s_hv.c +0
-0guest_pcr_bit =PCR_ARCH_31 ;break ;default :
Re: [PATCH 1/6] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
Hi Harsh,
Thanks for looking at the series and your review. Please find my comments inline.
Quoted 48 lines · Harsh Prateek Bora
Quoted 45 lines · Amit Machhiwal
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 (viamfspr()), which reflects the physical processor generation (Power11), rather than the effective compatibility mode (Power10).As a result, userspace may request a Power11
arch_compatfor the L2 guest. However, the L1 partition, running in Power10 compatibility, has only negotiated support up to Power10 with the Power Hypervisor (L0). WhenH_SET_STATEis 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 invalidH_SET_STATEhcall 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-EINVALearly instead of deferring the failure to the hypervisor.Signed-off-by Amit Machhiwal <[email protected]>--- arch/powerpc/kvm/book3s_hv.c | 6 ++++++ 1 file changed, 6 insertions(+)arch/powerpc/kvm/book3s_hv.c +2
-0@@ -446,7 +446,13 @@ 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 :
Quoted 8 lines
arch/powerpc/kvm/book3s_hv.c static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat) · line 455
Quoted 4 lines
arch/powerpc/kvm/book3s_hv.c +4
-0+if ((PVR_ARCH_31 & cur_cpu_spec->pvr_mask) == + cur_cpu_spec->pvr_value) { +return -EINVAL ; + }Is it possible to keep the check generic for applicable ISA versions (ISA 3.1 onwards?) instead of keeping it specific for P11 ?
Also need to add a comment, why it's not applicable for older ISAs.
I believe the check is only required for ISA 3.1, the reason being that Power10 and Power11 share the same PCR value. For newer ISA versions, that might not necessarily be the case. For any subsequent ISA versions, this check would already be taken care of by the below check in kvmppc_set_arch_compat():
if (guest_pcr_bit > host_pcr_bit) return -EINVAL;
Its mostly implicit but I'm okay to include a comment mentioning the same.
Thanks,
Amit
Quoted 5 lines
Quoted 4 lines
arch/powerpc/kvm/book3s_hv.c +0
-0guest_pcr_bit =PCR_ARCH_31 ;break ;default :
PATCH 2/6 KVM: PPC: Introduce KVM_CAP_PPC_COMPAT_CAPS and KVM_PPC_GET_COMPAT_CAPS
In reply to Amit MachhiwalIntroduce a new capability and ioctl to expose CPU compatibility modes supported by the host processor for nested guests.
Introduce a new KVM capability, KVM_CAP_PPC_COMPAT_CAPS, and a corresponding vm ioctl, KVM_PPC_GET_COMPAT_CAPS, to expose processor compatibility modes supported by the host.
On IBM POWER systems, newer processor generations (N) can operate in compatibility modes corresponding to earlier generations, like (N-1) and (N-2). This is particularly relevant for nested virtualization, where nested KVM guests may need to run with a specific processor compatibility level.
The new ioctl returns a bitmap describing the compatibility modes supported by the host in respective bit numbers. This allows userspace to select an appropriate compatibility level when configuring nested KVM guests.
--- arch/powerpc/include/uapi/asm/kvm.h | 6 ++++++ include/uapi/linux/kvm.h | 4 ++++ 2 files changed, 10 insertions(+)
arch/powerpc/include/uapi/asm/kvm.h +6 -0
@@ -437,6 +437,12 @@ struct kvm_ppc_cpu_char {__u64 behaviour_mask;/* valid bits in behaviour */ }; +/* For KVM_PPC_GET_COMPAT_CAPS */ +struct kvm_ppc_compat_caps { +__u32 flags; +__u64 compat_capabilities;/* Capabilities supported by the host */ +}; +/* * Values for character and character_mask. * These are identical to the values used by H_GET_CPU_CHARACTERISTICS.
include/uapi/linux/kvm.h +4 -0
@@ -996,6 +996,7 @@ struct kvm_enable_cap {#define KVM_CAP_S390_USER_OPEREXEC 246#define KVM_CAP_S390_KEYOP 247#define KVM_CAP_S390_VSIE_ESAMODE 248 +#define KVM_CAP_PPC_COMPAT_CAPS 249struct kvm_irq_routing_irqchip {__u32 irqchip;
@@ -1349,6 +1350,9 @@ struct kvm_s390_keyop {#define KVM_GET_DEVICE_ATTR _IOW(KVMIO, 0xe2, struct kvm_device_attr)#define KVM_HAS_DEVICE_ATTR _IOW(KVMIO, 0xe3, struct kvm_device_attr) +/* Available with KVM_CAP_PPC_COMPAT_CAPS */ +#define KVM_PPC_GET_COMPAT_CAPS _IOR(KVMIO, 0xe4, struct kvm_ppc_compat_caps) +/* * ioctls for vcpu fds */
Signature · 1 line
2.50.1
Re: [PATCH 2/6] KVM: PPC: Introduce KVM_CAP_PPC_COMPAT_CAPS and KVM_PPC_GET_COMPAT_CAPS
Quoted 29 lines · Amit Machhiwal
Introduce a new capability and ioctl to expose CPU compatibility modes supported by the host processor for nested guests.
Introduce a new KVM capability,
KVM_CAP_PPC_COMPAT_CAPS, and a corresponding vm ioctl,KVM_PPC_GET_COMPAT_CAPS, to expose processor compatibility modes supported by the host.On IBM POWER systems, newer processor generations (N) can operate in compatibility modes corresponding to earlier generations, like (N-1) and (N-2). This is particularly relevant for nested virtualization, where nested KVM guests may need to run with a specific processor compatibility level.
The new ioctl returns a bitmap describing the compatibility modes supported by the host in respective bit numbers. This allows userspace to select an appropriate compatibility level when configuring nested KVM guests.
Signed-off-by Amit Machhiwal <[email protected]>--- arch/powerpc/include/uapi/asm/kvm.h | 6 ++++++ include/uapi/linux/kvm.h | 4 ++++ 2 files changed, 10 insertions(+)arch/powerpc/include/uapi/asm/kvm.h +0
-0
arch/powerpc/include/uapi/asm/kvm.h struct kvm_ppc_cpu_char { · line 442
Quoted 6 lines
arch/powerpc/include/uapi/asm/kvm.h +3
-0@@ -437,6 +437,12 @@ struct kvm_ppc_cpu_char {__u64 behaviour_mask;/* valid bits in behaviour */ }; +/* For KVM_PPC_GET_COMPAT_CAPS */ +struct kvm_ppc_compat_caps { +__u32 flags;
You may either want flags to be __u64, or rearrange to keep variables in descending order of size or add padding as appropriate. Also, if we are not using flags with this series, we need to document comment as /* reserved for future use */
Quoted 19 lines
arch/powerpc/include/uapi/asm/kvm.h +3
-0+__u64 compat_capabilities;/* Capabilities supported by the host */ +}; +/* * Values for character and character_mask. * These are identical to the values used by H_GET_CPU_CHARACTERISTICS. include/uapi/linux/kvm.h +1
-0@@ -996,6 +996,7 @@ struct kvm_enable_cap {#define KVM_CAP_S390_USER_OPEREXEC 246#define KVM_CAP_S390_KEYOP 247#define KVM_CAP_S390_VSIE_ESAMODE 248 +#define KVM_CAP_PPC_COMPAT_CAPS 249struct kvm_irq_routing_irqchip {__u32 irqchip;
include/uapi/linux/kvm.h struct kvm_s390_keyop { · line 1355
Quoted 6 lines
include/uapi/linux/kvm.h +3
-0@@ -1349,6 +1350,9 @@ struct kvm_s390_keyop {#define KVM_GET_DEVICE_ATTR _IOW(KVMIO, 0xe2, struct kvm_device_attr)#define KVM_HAS_DEVICE_ATTR _IOW(KVMIO, 0xe3, struct kvm_device_attr) +/* Available with KVM_CAP_PPC_COMPAT_CAPS */ +#define KVM_PPC_GET_COMPAT_CAPS _IOR(KVMIO, 0xe4, struct kvm_ppc_compat_caps) +
This patch can actually be squashed with next patch where the struct, macros are actually being used.
Quoted 3 lines
include/uapi/linux/kvm.h +0
-0/* * ioctls for vcpu fds */
Re: [PATCH 2/6] KVM: PPC: Introduce KVM_CAP_PPC_COMPAT_CAPS and KVM_PPC_GET_COMPAT_CAPS
Quoted 27 lines · Harsh Prateek Bora
Quoted 24 lines · Amit Machhiwal
Introduce a new capability and ioctl to expose CPU compatibility modes supported by the host processor for nested guests.
Introduce a new KVM capability,
KVM_CAP_PPC_COMPAT_CAPS, and a corresponding vm ioctl,KVM_PPC_GET_COMPAT_CAPS, to expose processor compatibility modes supported by the host.On IBM POWER systems, newer processor generations (N) can operate in compatibility modes corresponding to earlier generations, like (N-1) and (N-2). This is particularly relevant for nested virtualization, where nested KVM guests may need to run with a specific processor compatibility level.
The new ioctl returns a bitmap describing the compatibility modes supported by the host in respective bit numbers. This allows userspace to select an appropriate compatibility level when configuring nested KVM guests.
Signed-off-by Amit Machhiwal <[email protected]>--- arch/powerpc/include/uapi/asm/kvm.h | 6 ++++++ include/uapi/linux/kvm.h | 4 ++++ 2 files changed, 10 insertions(+)
Quoted 15 lines
arch/powerpc/include/uapi/asm/kvm.h struct kvm_ppc_cpu_char { · line 441
Quoted 10 lines
arch/powerpc/include/uapi/asm/kvm.h +3
-0@@ -437,6 +437,12 @@ struct kvm_ppc_cpu_char {__u64 behaviour_mask;/* valid bits in behaviour */ }; +/* For KVM_PPC_GET_COMPAT_CAPS */ +struct kvm_ppc_compat_caps { +__u32 flags;You may either want flags to be
__u64, or rearrange to keep variables in descending order of size or add padding as appropriate. Also, if we are not using flags with this series, we need to document comment as /* reserved for future use */
Good catch. Sure, will do in the next version.
Quoted 20 lines
Quoted 20 lines
arch/powerpc/include/uapi/asm/kvm.h +3
-0+__u64 compat_capabilities;/* Capabilities supported by the host */ +}; +/* * Values for character and character_mask. * These are identical to the values used by H_GET_CPU_CHARACTERISTICS. include/uapi/linux/kvm.h +1
-0@@ -996,6 +996,7 @@ struct kvm_enable_cap {#define KVM_CAP_S390_USER_OPEREXEC 246#define KVM_CAP_S390_KEYOP 247#define KVM_CAP_S390_VSIE_ESAMODE 248 +#define KVM_CAP_PPC_COMPAT_CAPS 249struct kvm_irq_routing_irqchip {__u32 irqchip;@@ -1349,6 +1350,9 @@ struct kvm_s390_keyop {#define KVM_GET_DEVICE_ATTR _IOW(KVMIO, 0xe2, struct kvm_device_attr)
Quoted 8 lines
include/uapi/linux/kvm.h struct kvm_s390_keyop { · line 1355
Quoted 4 lines
include/uapi/linux/kvm.h +3
-0#define KVM_HAS_DEVICE_ATTR _IOW(KVMIO, 0xe3, struct kvm_device_attr) +/* Available with KVM_CAP_PPC_COMPAT_CAPS */ +#define KVM_PPC_GET_COMPAT_CAPS _IOR(KVMIO, 0xe4, struct kvm_ppc_compat_caps) +This patch can actually be squashed with next patch where the struct, macros are actually being used.
Sure, I can do that. I had split the uAPI addition and ioctl wiring as separate logical steps, but they are tightly coupled and the split may not add much value. I’ll squash patches 2 and 3 in the next revision.”
Thanks,
Amit
Quoted 4 lines
Quoted 3 lines
include/uapi/linux/kvm.h +0
-0/* * ioctls for vcpu fds */
PATCH 3/6 KVM: PPC: Wire up KVM_PPC_GET_COMPAT_CAPS ioctl
In reply to Amit MachhiwalAdd handling for KVM_PPC_GET_COMPAT_CAPS in kvm_arch_vm_ioctl() and advertise support via KVM_CAP_PPC_COMPAT_CAPS.
The ioctl retrieves host CPU compatibility capabilities via a PowerPC-specific backend implementation when available. If the capability is not supported, the ioctl returns success with no capabilities set, allowing userspace to fall back gracefully.
--- arch/powerpc/include/asm/kvm_ppc.h | 1 + arch/powerpc/kvm/powerpc.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+)
arch/powerpc/include/asm/kvm_ppc.h +1 -0
@@ -319,6 +319,7 @@ struct kvmppc_ops {bool (*hash_v3_possible)(void );int (*create_vm_debugfs)(struct kvm *kvm);int (*create_vcpu_debugfs)(struct kvm_vcpu *vcpu,struct dentry *debugfs_dentry); +int (*get_compat_cpu_ver)(struct kvm_ppc_compat_caps *host_caps); };extern struct kvmppc_ops *kvmppc_hv_ops;
arch/powerpc/kvm/powerpc.c +19 -0
@@ -697,6 +697,12 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) } }break ; +#if defined(CONFIG_KVM_BOOK3S_HV_POSSIBLE ) +case KVM_CAP_PPC_COMPAT_CAPS : +if (kvmhv_on_pseries ()) + r =1 ; +break ; +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ default : r =0 ;break ;
@@ -2463,6 +2469,19 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) r = kvm->arch.kvm_ops->svm_off (kvm);break ; } +case KVM_PPC_GET_COMPAT_CAPS : { +struct kvm_ppc_compat_caps host_caps; + +memset (&host_caps,0 ,sizeof (host_caps)); +if (!kvm->arch.kvm_ops->get_compat_cpu_ver) + goto out; + + r = kvm->arch.kvm_ops->get_compat_cpu_ver (&host_caps); +if (!r &©_to_user (argp, &host_caps, +sizeof (host_caps))) + r = -EFAULT ; +break ; + }default : {struct kvm *kvm = filp->private_data; r = kvm->arch.kvm_ops->arch_vm_ioctl (filp, ioctl, arg);
Signature · 1 line
2.50.1
Re: [PATCH 3/6] KVM: PPC: Wire up KVM_PPC_GET_COMPAT_CAPS ioctl
Quoted 31 lines · Amit Machhiwal
Add handling for
KVM_PPC_GET_COMPAT_CAPSinkvm_arch_vm_ioctl()and advertise support viaKVM_CAP_PPC_COMPAT_CAPS.The ioctl retrieves host CPU compatibility capabilities via a PowerPC-specific backend implementation when available. If the capability is not supported, the ioctl returns success with no capabilities set, allowing userspace to fall back gracefully.
Signed-off-by Amit Machhiwal <[email protected]>--- arch/powerpc/include/asm/kvm_ppc.h | 1 + arch/powerpc/kvm/powerpc.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+)arch/powerpc/include/asm/kvm_ppc.h +1
-0@@ -319,6 +319,7 @@ struct kvmppc_ops {bool (*hash_v3_possible)(void );int (*create_vm_debugfs)(struct kvm *kvm);int (*create_vcpu_debugfs)(struct kvm_vcpu *vcpu,struct dentry *debugfs_dentry); +int (*get_compat_cpu_ver)(struct kvm_ppc_compat_caps *host_caps); };extern struct kvmppc_ops *kvmppc_hv_ops;arch/powerpc/kvm/powerpc.c +0
-0
arch/powerpc/kvm/powerpc.c int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) · line 702
Quoted 6 lines
arch/powerpc/kvm/powerpc.c +3
-0@@ -697,6 +697,12 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) } }break ; +#if defined(CONFIG_KVM_BOOK3S_HV_POSSIBLE ) +case KVM_CAP_PPC_COMPAT_CAPS : +if (kvmhv_on_pseries ())
What about PowerNV ?
Also, can't we just check if get_compat_cpu_ver is initialized and return accordingly ?
Quoted 7 lines
arch/powerpc/kvm/powerpc.c +3
-0+ r =1 ; +break ; +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ default : r =0 ;break ;
arch/powerpc/kvm/powerpc.c int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) · line 2477
Quoted 9 lines
arch/powerpc/kvm/powerpc.c +6
-0@@ -2463,6 +2469,19 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) r = kvm->arch.kvm_ops->svm_off (kvm);break ; } +case KVM_PPC_GET_COMPAT_CAPS : { +struct kvm_ppc_compat_caps host_caps; + +memset (&host_caps,0 ,sizeof (host_caps)); +if (!kvm->arch.kvm_ops->get_compat_cpu_ver) + goto out;
I guess we want to init r = 0 before returning in this case. Also prefer break over goto unless really needed.
Quoted 10 lines
arch/powerpc/kvm/powerpc.c +7
-0+ + r = kvm->arch.kvm_ops->get_compat_cpu_ver (&host_caps); +if (!r &©_to_user (argp, &host_caps, +sizeof (host_caps))) + r = -EFAULT ; +break ; + }default : {struct kvm *kvm = filp->private_data; r = kvm->arch.kvm_ops->arch_vm_ioctl (filp, ioctl, arg);
Re: [PATCH 3/6] KVM: PPC: Wire up KVM_PPC_GET_COMPAT_CAPS ioctl
Quoted 33 lines · Harsh Prateek Bora
Quoted 30 lines · Amit Machhiwal
Add handling for
KVM_PPC_GET_COMPAT_CAPSinkvm_arch_vm_ioctl()and advertise support viaKVM_CAP_PPC_COMPAT_CAPS.The ioctl retrieves host CPU compatibility capabilities via a PowerPC-specific backend implementation when available. If the capability is not supported, the ioctl returns success with no capabilities set, allowing userspace to fall back gracefully.
Signed-off-by Amit Machhiwal <[email protected]>--- arch/powerpc/include/asm/kvm_ppc.h | 1 + arch/powerpc/kvm/powerpc.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+)arch/powerpc/include/asm/kvm_ppc.h +1
-0@@ -319,6 +319,7 @@ struct kvmppc_ops {bool (*hash_v3_possible)(void );int (*create_vm_debugfs)(struct kvm *kvm);int (*create_vcpu_debugfs)(struct kvm_vcpu *vcpu,struct dentry *debugfs_dentry); +int (*get_compat_cpu_ver)(struct kvm_ppc_compat_caps *host_caps); };extern struct kvmppc_ops *kvmppc_hv_ops;arch/powerpc/kvm/powerpc.c +0
-0@@ -697,6 +697,12 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
Quoted 8 lines
arch/powerpc/kvm/powerpc.c int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) · line 702
Quoted 6 lines
arch/powerpc/kvm/powerpc.c +3
-0} }break ; +#if defined(CONFIG_KVM_BOOK3S_HV_POSSIBLE ) +case KVM_CAP_PPC_COMPAT_CAPS : +if (kvmhv_on_pseries ())What about PowerNV ?
I'm not sure if understand the question completely. The goal is to handle the compatibility mode for a nested guest, i.e., an L2 KVM guest booted inside a pSeries KVM L1 booted on a PowerNV host with HV compatibilities and as well as on a Logical Parition booted on PowerVM, hence the check. Does that answer your question?
Quoted 13 lines
Also, can't we just check if
get_compat_cpu_veris initialized and return accordingly ?Quoted 10 lines
arch/powerpc/kvm/powerpc.c +3
-0+ r =1 ; +break ; +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ default : r =0 ;break ;@@ -2463,6 +2469,19 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) r = kvm->arch.kvm_ops->svm_off (kvm);break ; }
Quoted 8 lines
arch/powerpc/kvm/powerpc.c int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) · line 2477
Quoted 6 lines
arch/powerpc/kvm/powerpc.c +6
-0+case KVM_PPC_GET_COMPAT_CAPS : { +struct kvm_ppc_compat_caps host_caps; + +memset (&host_caps,0 ,sizeof (host_caps)); +if (!kvm->arch.kvm_ops->get_compat_cpu_ver) + goto out;I guess we want to init r = 0 before returning in this case.
Sure, will do in the next version.
Quoted 1 line
Also prefer break over goto unless really needed.
I used goto out; to stay consistent with the existing exit paths in this function, where similar branches go through the same out label. I do not have a strong preference either way. Please let me know your views.
Thanks,
Amit
Quoted 12 lines
Quoted 11 lines
arch/powerpc/kvm/powerpc.c +7
-0+ + r = kvm->arch.kvm_ops->get_compat_cpu_ver (&host_caps); +if (!r &©_to_user (argp, &host_caps, +sizeof (host_caps))) + r = -EFAULT ; +break ; + }default : {struct kvm *kvm = filp->private_data; r = kvm->arch.kvm_ops->arch_vm_ioctl (filp, ioctl, arg);
PATCH 4/6 KVM: PPC: Book3S HV: Implement compat CPU capability retrieval for KVM on PowerVM
In reply to Amit MachhiwalOn 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 derives the host CPU type using mfpvr(), which reflects the physical processor version. This can result in a mismatch between the CPU model selected by QEMU and the compatibility mode enforced by the host, leading to guest boot failures.
For example, booting a nested guest on a Power11 LPAR configured in Power10 compatibility mode fails with:
KVM-NESTEDv2: couldn't set guest wide elements
[..KVM reg dump..]
This occurs because QEMU selects a CPU model corresponding to the physical processor (via mfpvr()), while the host operates in a lower compatibility mode. As a result, KVM rejects the requested compatibility level during guest initialization.
Add support for retrieving host CPU compatibility capabilities for nested guests on PowerVM (PAPR nested API v2). The hypervisor provides the effective compatibility levels via the H_GUEST_GET_CAPABILITIES hcall, which reflects the processor modes negotiated between the Power hypervisor (L0) and the host partition (L1).
On pseries systems, obtain the capability bitmap using plpar_guest_get_capabilities() and return it via struct kvm_ppc_compat_caps. This information is then exposed to userspace through the KVM_PPC_GET_COMPAT_CAPS ioctl.
Hook the implementation into the Book3S HV kvmppc_ops so that it can be invoked by the generic KVM ioctl handling code.
--- arch/powerpc/kvm/book3s_hv.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
arch/powerpc/kvm/book3s_hv.c +17 -0
@@ -6516,6 +6516,22 @@ static bool kvmppc_hash_v3_possible(void)return true; } + +static int kvmppc_get_compat_cpu_caps (struct kvm_ppc_compat_caps *host_caps) +{ + +unsigned long capabilities =0 ; +long rc = -EINVAL ; + +if (kvmhv_on_pseries ()) { +if (kvmhv_is_nestedv2 ()) + rc =plpar_guest_get_capabilities (0 , &capabilities); + host_caps->compat_capabilities = capabilities; + } + +return rc; +} +static struct kvmppc_ops kvm_ops_hv = { .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_hv, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_hv,
@@ -6558,6 +6574,7 @@ static struct kvmppc_ops kvm_ops_hv = { .hash_v3_possible = kvmppc_hash_v3_possible, .create_vcpu_debugfs = kvmppc_arch_create_vcpu_debugfs_hv, .create_vm_debugfs = kvmppc_arch_create_vm_debugfs_hv, + .get_compat_cpu_ver = kvmppc_get_compat_cpu_caps, };static int kvm_init_subcore_bitmap (void )
Signature · 1 line
2.50.1
Re: [PATCH 4/6] KVM: PPC: Book3S HV: Implement compat CPU capability retrieval for KVM on PowerVM
Quoted 47 lines · Amit Machhiwal
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 derives the host CPU type using
mfpvr(), which reflects the physical processor version. This can result in a mismatch between the CPU model selected by QEMU and the compatibility mode enforced by the host, leading to guest boot failures.For example, booting a nested guest on a Power11 LPAR configured in Power10 compatibility mode fails with:
KVM-NESTEDv2: couldn't set guest wide elements
[..KVM reg dump..]This occurs because QEMU selects a CPU model corresponding to the physical processor (via
mfpvr()), while the host operates in a lower compatibility mode. As a result, KVM rejects the requested compatibility level during guest initialization.Add support for retrieving host CPU compatibility capabilities for nested guests on PowerVM (PAPR nested API v2). The hypervisor provides the effective compatibility levels via the
H_GUEST_GET_CAPABILITIEShcall, which reflects the processor modes negotiated between the Power hypervisor (L0) and the host partition (L1).On pseries systems, obtain the capability bitmap using
plpar_guest_get_capabilities()and return it via structkvm_ppc_compat_caps. This information is then exposed to userspace through theKVM_PPC_GET_COMPAT_CAPSioctl.Hook the implementation into the Book3S HV
kvmppc_opsso that it can be invoked by the generic KVM ioctl handling code.Signed-off-by Amit Machhiwal <[email protected]>--- arch/powerpc/kvm/book3s_hv.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)arch/powerpc/kvm/book3s_hv.c +0
-0@@ -6516,6 +6516,22 @@ static bool kvmppc_hash_v3_possible(void)return true; }
arch/powerpc/kvm/book3s_hv.c static bool kvmppc_hash_v3_possible(void) · line 6527
Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c +9
-0+ +static int kvmppc_get_compat_cpu_caps (struct kvm_ppc_compat_caps *host_caps) +{ + +unsigned long capabilities =0 ; +long rc = -EINVAL ; + +if (kvmhv_on_pseries ()) { +if (kvmhv_is_nestedv2 ())
If this is only intended for nested APIv2, it should reflect in commit log/title, otherwise, we need to return success with capabilities set to 0 for non-nestedv2 case.
Also, better to have combined check for pseries and nestedv2 if we are not handling other cases.
arch/powerpc/kvm/book3s_hv.c static bool kvmppc_hash_v3_possible(void) · line 6529
Quoted 2 lines
arch/powerpc/kvm/book3s_hv.c +2
-0+ rc =plpar_guest_get_capabilities (0 , &capabilities); + host_caps->compat_capabilities = capabilities;
Do we need to take care of PowerNV case ?
Quoted 16 lines
arch/powerpc/kvm/book3s_hv.c +6
-0+ } + +return rc; +} +static struct kvmppc_ops kvm_ops_hv = { .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_hv, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_hv,@@ -6558,6 +6574,7 @@ static struct kvmppc_ops kvm_ops_hv = { .hash_v3_possible = kvmppc_hash_v3_possible, .create_vcpu_debugfs = kvmppc_arch_create_vcpu_debugfs_hv, .create_vm_debugfs = kvmppc_arch_create_vm_debugfs_hv, + .get_compat_cpu_ver = kvmppc_get_compat_cpu_caps, };static int kvm_init_subcore_bitmap (void )
Re: [PATCH 4/6] KVM: PPC: Book3S HV: Implement compat CPU capability retrieval for KVM on PowerVM
Quoted 55 lines · Harsh Prateek Bora
Quoted 52 lines · Amit Machhiwal
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 derives the host CPU type using
mfpvr(), which reflects the physical processor version. This can result in a mismatch between the CPU model selected by QEMU and the compatibility mode enforced by the host, leading to guest boot failures.For example, booting a nested guest on a Power11 LPAR configured in Power10 compatibility mode fails with:
KVM-NESTEDv2: couldn't set guest wide elements
[..KVM reg dump..]This occurs because QEMU selects a CPU model corresponding to the physical processor (via
mfpvr()), while the host operates in a lower compatibility mode. As a result, KVM rejects the requested compatibility level during guest initialization.Add support for retrieving host CPU compatibility capabilities for nested guests on PowerVM (PAPR nested API v2). The hypervisor provides the effective compatibility levels via the
H_GUEST_GET_CAPABILITIEShcall, which reflects the processor modes negotiated between the Power hypervisor (L0) and the host partition (L1).On pseries systems, obtain the capability bitmap using
plpar_guest_get_capabilities()and return it via structkvm_ppc_compat_caps. This information is then exposed to userspace through theKVM_PPC_GET_COMPAT_CAPSioctl.Hook the implementation into the Book3S HV
kvmppc_opsso that it can be invoked by the generic KVM ioctl handling code.Signed-off-by Amit Machhiwal <[email protected]>--- arch/powerpc/kvm/book3s_hv.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)arch/powerpc/kvm/book3s_hv.c +5
-0@@ -6516,6 +6516,22 @@ static bool kvmppc_hash_v3_possible(void)return true; } + +static int kvmppc_get_compat_cpu_caps (struct kvm_ppc_compat_caps *host_caps) +{ + +unsigned long capabilities =0 ;
Quoted 8 lines
arch/powerpc/kvm/book3s_hv.c static bool kvmppc_hash_v3_possible(void) · line 6527
Quoted 4 lines
arch/powerpc/kvm/book3s_hv.c +4
-0+long rc = -EINVAL ; + +if (kvmhv_on_pseries ()) { +if (kvmhv_is_nestedv2 ())If this is only intended for nested APIv2, it should reflect in commit log/title, otherwise, we need to return success with capabilities set to 0 for non-nestedv2 case.
This patch is specific to nested API v2. I tried to convey that through the “KVM on PowerVM” in the commit title, and I also described the API v2 scope in the commit log. If that is still not explicit enough, I can update the title and commit log in the next revision to make the limitation clearer.
Quoted 3 lines
Also, better to have combined check for pseries and nestedv2 if we are not handling other cases.
We are, in the next patch.
Quoted 5 lines
arch/powerpc/kvm/book3s_hv.c static bool kvmppc_hash_v3_possible(void) · line 6529
Quoted 3 lines
arch/powerpc/kvm/book3s_hv.c +2
-0+ rc =plpar_guest_get_capabilities (0 , &capabilities); + host_caps->compat_capabilities = capabilities;Do we need to take care of PowerNV case ?
Next patch takes care of it.
Thanks,
Amit
Quoted 16 lines
Quoted 15 lines
arch/powerpc/kvm/book3s_hv.c +6
-0+ } + +return rc; +} +static struct kvmppc_ops kvm_ops_hv = { .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_hv, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_hv,@@ -6558,6 +6574,7 @@ static struct kvmppc_ops kvm_ops_hv = { .hash_v3_possible = kvmppc_hash_v3_possible, .create_vcpu_debugfs = kvmppc_arch_create_vcpu_debugfs_hv, .create_vm_debugfs = kvmppc_arch_create_vm_debugfs_hv, + .get_compat_cpu_ver = kvmppc_get_compat_cpu_caps, };static int kvm_init_subcore_bitmap (void )
PATCH 5/6 KVM: PPC: Book3S HV: Add support for compat CPU capabilities for KVM on PowerNV
In reply to Amit MachhiwalCurrently, when booting a compatibility-mode KVM guest (L1) on a PowerNV hypervisor (L0), the guest runs with the expected processor compatibility level. However, when booting a nested KVM guest (L2) inside the L1, QEMU derives the CPU model from the raw host PVR and attempts to run the nested guest at that level, instead of honoring the compatibility mode of the L1.
Extend host CPU compatibility capability reporting to support nested virtualization on PowerNV systems (PAPR nested API v1).
For nested API v2 (PowerVM), compatibility capabilities are obtained from the hypervisor via the H_GUEST_GET_CAPABILITIES hcall. This information is not available on PowerNV systems.
For nested API v1, derive the compatibility capabilities from the L1 guest by reading the "cpu-version" property from the device tree, which reflects the effective (logical) processor compatibility level. Map this value to the corresponding compatibility capability bitmap.
Introduce a helper to translate CPU version values into compatibility capability bits and integrate it into kvmppc_get_compat_cpu_caps().
This allows userspace to query host CPU compatibility modes on both PowerVM and PowerNV platforms via the KVM_PPC_GET_COMPAT_CAPS ioctl.
--- arch/powerpc/kvm/book3s_hv.c | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_hv.c +36 -1
@@ -6516,16 +6516,51 @@ static bool kvmppc_hash_v3_possible(void)return true; } +static int kvmppc_map_compat_capabilities (const __be32 cpu_version, +unsigned long *capabilities) +{ +switch (cpu_version) { +case PVR_ARCH_31_P11 : + *capabilities |=H_GUEST_CAP_POWER11 ; +break ; +case PVR_ARCH_31 : + *capabilities |=H_GUEST_CAP_POWER10 ; +break ; +case PVR_ARCH_300 : + *capabilities |=H_GUEST_CAP_POWER9 ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +}static int kvmppc_get_compat_cpu_caps (struct kvm_ppc_compat_caps *host_caps) { +struct device_node *np;unsigned long capabilities =0 ; +const __be32 *prop =NULL ;long rc = -EINVAL ; +u32 cpu_version;if (kvmhv_on_pseries ()) { -if (kvmhv_is_nestedv2 ()) +if (kvmhv_is_nestedv2 ()) { rc =plpar_guest_get_capabilities (0 , &capabilities); + }else { +for_each_node_by_type (np,"cpu" ) { + prop =of_get_property (np,"cpu-version" ,NULL ); +if (prop) { + cpu_version =be32_to_cpup (prop); +break ; + } + } +if (!prop) +return -EINVAL ; + rc =kvmppc_map_compat_capabilities (cpu_version, + &capabilities); + } host_caps->compat_capabilities = capabilities; }
Signature · 1 line
2.50.1
Re: [PATCH 5/6] KVM: PPC: Book3S HV: Add support for compat CPU capabilities for KVM on PowerNV
Quoted 35 lines · Amit Machhiwal
Currently, when booting a compatibility-mode KVM guest (L1) on a PowerNV hypervisor (L0), the guest runs with the expected processor compatibility level. However, when booting a nested KVM guest (L2) inside the L1, QEMU derives the CPU model from the raw host PVR and attempts to run the nested guest at that level, instead of honoring the compatibility mode of the L1.
Extend host CPU compatibility capability reporting to support nested virtualization on PowerNV systems (PAPR nested API v1).
For nested API v2 (PowerVM), compatibility capabilities are obtained from the hypervisor via the
H_GUEST_GET_CAPABILITIEShcall. This information is not available on PowerNV systems.For nested API v1, derive the compatibility capabilities from the L1 guest by reading the "cpu-version" property from the device tree, which reflects the effective (logical) processor compatibility level. Map this value to the corresponding compatibility capability bitmap.
Introduce a helper to translate CPU version values into compatibility capability bits and integrate it into
kvmppc_get_compat_cpu_caps().This allows userspace to query host CPU compatibility modes on both PowerVM and PowerNV platforms via the
KVM_PPC_GET_COMPAT_CAPSioctl.Signed-off-by Amit Machhiwal <[email protected]>--- arch/powerpc/kvm/book3s_hv.c | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-)arch/powerpc/kvm/book3s_hv.c +0
-0
arch/powerpc/kvm/book3s_hv.c static bool kvmppc_hash_v3_possible(void) · line 6524
Quoted 9 lines
arch/powerpc/kvm/book3s_hv.c +6
-0@@ -6516,16 +6516,51 @@ static bool kvmppc_hash_v3_possible(void)return true; } +static int kvmppc_map_compat_capabilities (const __be32 cpu_version, +unsigned long *capabilities) +{ +switch (cpu_version) { +case PVR_ARCH_31_P11 : + *capabilities |=H_GUEST_CAP_POWER11 ;
Should this be:
+ *capabilities |= H_GUEST_CAP_POWER11 |
+ H_GUEST_CAP_POWER10 |
+ H_GUEST_CAP_POWER9;
Likewise, the remaining as applicable?
Quoted 14 lines
arch/powerpc/kvm/book3s_hv.c +13
-0+break ; +case PVR_ARCH_31 : + *capabilities |=H_GUEST_CAP_POWER10 ; +break ; +case PVR_ARCH_300 : + *capabilities |=H_GUEST_CAP_POWER9 ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +}
arch/powerpc/kvm/book3s_hv.c static bool kvmppc_hash_v3_possible(void) · line 6548
Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c +3
-0static int kvmppc_get_compat_cpu_caps (struct kvm_ppc_compat_caps *host_caps) { +struct device_node *np;unsigned long capabilities =0 ; +const __be32 *prop =NULL ;long rc = -EINVAL ; +u32 cpu_version;if (kvmhv_on_pseries ()) {
Commit title says PowerNV, but here were are doing only for PowerVM?
Quoted 19 lines
arch/powerpc/kvm/book3s_hv.c +14
-1-if (kvmhv_is_nestedv2 ()) +if (kvmhv_is_nestedv2 ()) { rc =plpar_guest_get_capabilities (0 , &capabilities); + }else { +for_each_node_by_type (np,"cpu" ) { + prop =of_get_property (np,"cpu-version" ,NULL ); +if (prop) { + cpu_version =be32_to_cpup (prop); +break ; + } + } +if (!prop) +return -EINVAL ; + rc =kvmppc_map_compat_capabilities (cpu_version, + &capabilities); + } host_caps->compat_capabilities = capabilities; }
Re: [PATCH 5/6] KVM: PPC: Book3S HV: Add support for compat CPU capabilities for KVM on PowerNV
Quoted 53 lines · Harsh Prateek Bora
Quoted 35 lines · Amit Machhiwal
Currently, when booting a compatibility-mode KVM guest (L1) on a PowerNV hypervisor (L0), the guest runs with the expected processor compatibility level. However, when booting a nested KVM guest (L2) inside the L1, QEMU derives the CPU model from the raw host PVR and attempts to run the nested guest at that level, instead of honoring the compatibility mode of the L1.
Extend host CPU compatibility capability reporting to support nested virtualization on PowerNV systems (PAPR nested API v1).
For nested API v2 (PowerVM), compatibility capabilities are obtained from the hypervisor via the
H_GUEST_GET_CAPABILITIEShcall. This information is not available on PowerNV systems.For nested API v1, derive the compatibility capabilities from the L1 guest by reading the "cpu-version" property from the device tree, which reflects the effective (logical) processor compatibility level. Map this value to the corresponding compatibility capability bitmap.
Introduce a helper to translate CPU version values into compatibility capability bits and integrate it into
kvmppc_get_compat_cpu_caps().This allows userspace to query host CPU compatibility modes on both PowerVM and PowerNV platforms via the
KVM_PPC_GET_COMPAT_CAPSioctl.Signed-off-by Amit Machhiwal <[email protected]>--- arch/powerpc/kvm/book3s_hv.c | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-)arch/powerpc/kvm/book3s_hv.c +0
-0arch/powerpc/kvm/book3s_hv.c static bool kvmppc_hash_v3_possible(void) · line 6523
Quoted 8 lines
arch/powerpc/kvm/book3s_hv.c +6
-0@@ -6516,16 +6516,51 @@ static bool kvmppc_hash_v3_possible(void)return true; } +static int kvmppc_map_compat_capabilities (const __be32 cpu_version, +unsigned long *capabilities) +{ +switch (cpu_version) { +case PVR_ARCH_31_P11 : + *capabilities |=H_GUEST_CAP_POWER11 ;Should this be:
(quoted diff) +3
-0+ *capabilities |= H_GUEST_CAP_POWER11 | + H_GUEST_CAP_POWER10 | + H_GUEST_CAP_POWER9;
Quoted 1 line
Likewise, the remaining as applicable?
Not necessarily. This function will be called only when we are booting a nested KVM guest (L2) on KVM on PowerNV. So, when the L1 KVM guest is booted in a compat mode, L2 is supposed to boot with the same PVR version as that of the L1 which is already taken care of with the current changes, unless L2 as well booted with a max-cpu-compat - which would anyway take a different path for setting the compat.
Quoted 16 lines
Quoted 16 lines
arch/powerpc/kvm/book3s_hv.c +13
-0+break ; +case PVR_ARCH_31 : + *capabilities |=H_GUEST_CAP_POWER10 ; +break ; +case PVR_ARCH_300 : + *capabilities |=H_GUEST_CAP_POWER9 ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +}static int kvmppc_get_compat_cpu_caps (struct kvm_ppc_compat_caps *host_caps) {
Quoted 8 lines
arch/powerpc/kvm/book3s_hv.c static bool kvmppc_hash_v3_possible(void) · line 6548
Quoted 6 lines
arch/powerpc/kvm/book3s_hv.c +3
-0+struct device_node *np;unsigned long capabilities =0 ; +const __be32 *prop =NULL ;long rc = -EINVAL ; +u32 cpu_version;if (kvmhv_on_pseries ()) {Commit title says PowerNV, but here were are doing only for PowerVM?
Not really. This would take of both the cases. The else part specifically takes care of the API v1 nested guests on PowerNV platforms.
Thanks,
Amit
Quoted 19 lines
Quoted 18 lines
arch/powerpc/kvm/book3s_hv.c +14
-1-if (kvmhv_is_nestedv2 ()) +if (kvmhv_is_nestedv2 ()) { rc =plpar_guest_get_capabilities (0 , &capabilities); + }else { +for_each_node_by_type (np,"cpu" ) { + prop =of_get_property (np,"cpu-version" ,NULL ); +if (prop) { + cpu_version =be32_to_cpup (prop); +break ; + } + } +if (!prop) +return -EINVAL ; + rc =kvmppc_map_compat_capabilities (cpu_version, + &capabilities); + } host_caps->compat_capabilities = capabilities; }
PATCH 6/6 KVM: PPC: Document KVM_PPC_GET_COMPAT_CAPS ioctl
In reply to Amit MachhiwalAdd documentation for the KVM_PPC_GET_COMPAT_CAPS ioctl to the KVM API documentation.
The ioctl exposes host processor compatibility modes supported for nested KVM guests on PowerPC systems.
--- Documentation/virt/kvm/api.rst | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
Documentation/virt/kvm/api.rst +35 -0
@@ -6555,6 +6555,41 @@ KVM_S390_KEYOP_SSKE .. _kvm_run: +4.145 KVM_PPC_GET_COMPAT_CAPS +----------------------------- +:Capability: KVM_CAP_PPC_COMPAT_CAPS +:Architectures: powerpc +:Type: vm ioctl +:Parameters: struct kvm_ppc_compat_caps (out) +:Returns: + 0 on successful completion, + -EFAULT if ``struct kvm_ppc_compat_caps`` cannot be written + +IBM POWER system server-based processors provide a compatibility mode feature +where an Nth generation processor can operate in modes consistent with earlier +generations such as (N-1) and (N-2). + +This ioctl provides userspace with information about the CPU compatibility modes +supported by the current host processor for booting the nested KVM guests on +PowerNV (KVM nested APIv1) and PowerVM (KVM nested APIv2) platforms. + +:: + + struct kvm_ppc_compat_caps { + __u32 flags; + __u64 compat_capabilities; /* Capabilities supported by the host */ + }; + +The ``compat_capabilities`` bit field describes the processor compatibility +modes supported by the host. For example, the following bits indicate support +for specific processor modes. + +:: + + bit 1: KVM guests can run in Power9 processor mode + bit 2: KVM guests can run in Power10 processor mode + bit 3: KVM guests can run in Power11 processor mode + 5. The kvm_run structure ========================
Signature · 1 line
2.50.1
Re: [PATCH 6/6] KVM: PPC: Document KVM_PPC_GET_COMPAT_CAPS ioctl
Quoted 18 lines · Amit Machhiwal
Add documentation for the
KVM_PPC_GET_COMPAT_CAPSioctl to the KVM API documentation.The ioctl exposes host processor compatibility modes supported for nested KVM guests on PowerPC systems.
Signed-off-by Amit Machhiwal <[email protected]>--- Documentation/virt/kvm/api.rst | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)Documentation/virt/kvm/api.rst +0
-0@@ -6555,6 +6555,41 @@ KVM_S390_KEYOP_SSKE .. _kvm_run:
Documentation/virt/kvm/api.rst KVM_S390_KEYOP_SSKE · line 6566
Quoted 10 lines
Documentation/virt/kvm/api.rst +9
-0+4.145 KVM_PPC_GET_COMPAT_CAPS +----------------------------- +:Capability: KVM_CAP_PPC_COMPAT_CAPS +:Architectures: powerpc +:Type: vm ioctl +:Parameters: struct kvm_ppc_compat_caps (out) +:Returns: + 0 on successful completion, + -EFAULT if ``struct kvm_ppc_compat_caps`` cannot be written
-EINVAL also needs to be documented?
Quoted 15 lines
Documentation/virt/kvm/api.rst +15
-0+ +IBM POWER system server-based processors provide a compatibility mode feature +where an Nth generation processor can operate in modes consistent with earlier +generations such as (N-1) and (N-2). + +This ioctl provides userspace with information about the CPU compatibility modes +supported by the current host processor for booting the nested KVM guests on +PowerNV (KVM nested APIv1) and PowerVM (KVM nested APIv2) platforms. + +:: + + struct kvm_ppc_compat_caps { + __u32 flags; + __u64 compat_capabilities; /* Capabilities supported by the host */ + };
Documentation/virt/kvm/api.rst KVM_S390_KEYOP_SSKE · line 6591
Quoted 10 lines
Documentation/virt/kvm/api.rst +10
-0+ +The ``compat_capabilities`` bit field describes the processor compatibility +modes supported by the host. For example, the following bits indicate support +for specific processor modes. + +:: + + bit 1: KVM guests can run in Power9 processor mode + bit 2: KVM guests can run in Power10 processor mode + bit 3: KVM guests can run in Power11 processor mode
May be use H_GUEST_CAP_POWER9 and friends ?
Quoted 4 lines
Documentation/virt/kvm/api.rst +1
-0+ 5. The kvm_run structure ========================
Re: [PATCH 6/6] KVM: PPC: Document KVM_PPC_GET_COMPAT_CAPS ioctl
Quoted 23 lines · Harsh Prateek Bora
Quoted 20 lines · Amit Machhiwal
Add documentation for the
KVM_PPC_GET_COMPAT_CAPSioctl to the KVM API documentation.The ioctl exposes host processor compatibility modes supported for nested KVM guests on PowerPC systems.
Signed-off-by Amit Machhiwal <[email protected]>--- Documentation/virt/kvm/api.rst | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)Documentation/virt/kvm/api.rst +3
-0@@ -6555,6 +6555,41 @@ KVM_S390_KEYOP_SSKE .. _kvm_run: +4.145 KVM_PPC_GET_COMPAT_CAPS +----------------------------- +:Capability: KVM_CAP_PPC_COMPAT_CAPS
Quoted 8 lines
Documentation/virt/kvm/api.rst KVM_S390_KEYOP_SSKE · line 6566
Quoted 6 lines
Documentation/virt/kvm/api.rst +6
-0+:Architectures: powerpc +:Type: vm ioctl +:Parameters: struct kvm_ppc_compat_caps (out) +:Returns: + 0 on successful completion, + -EFAULT if ``struct kvm_ppc_compat_caps`` cannot be written
-EINVALalso needs to be documented?
We do not currently return -EINVAL for this ioctl, so I did not document it. As implemented, the only explicit error documented here is -EFAULT when struct kvm_ppc_compat_caps cannot be written. Please let me know if I am missing a case where -EINVAL should be returned.
Quoted 20 lines
Quoted 20 lines
Documentation/virt/kvm/api.rst +19
-0+ +IBM POWER system server-based processors provide a compatibility mode feature +where an Nth generation processor can operate in modes consistent with earlier +generations such as (N-1) and (N-2). + +This ioctl provides userspace with information about the CPU compatibility modes +supported by the current host processor for booting the nested KVM guests on +PowerNV (KVM nested APIv1) and PowerVM (KVM nested APIv2) platforms. + +:: + + struct kvm_ppc_compat_caps { + __u32 flags; + __u64 compat_capabilities; /* Capabilities supported by the host */ + }; + +The ``compat_capabilities`` bit field describes the processor compatibility +modes supported by the host. For example, the following bits indicate support +for specific processor modes.
Quoted 8 lines
Documentation/virt/kvm/api.rst KVM_S390_KEYOP_SSKE · line 6591
Quoted 6 lines
Documentation/virt/kvm/api.rst +6
-0+ +:: + + bit 1: KVM guests can run in Power9 processor mode + bit 2: KVM guests can run in Power10 processor mode + bit 3: KVM guests can run in Power11 processor modeMay be use
H_GUEST_CAP_POWER9and friends ?
I used the bit descriptions directly since this is documenting the uAPI bitmap layout, which felt clearer for userspace than using only H_GUEST_CAP_POWER9 and friends. But I’m happy to mention those macros as well if you think that improves clarity.
Thanks again for reviewing the series. I will wait a little longer for any further feedback before posting v2.
Thanks,
Amit
Quoted 5 lines
Quoted 4 lines
Documentation/virt/kvm/api.rst +1
-0+ 5. The kvm_run structure ========================