KVM: PPC: Book3S PR: Allow KVM_PPC_CONFIGURE_V3_MMU to succeed

Message ID 20180530100946.GA6466@fergus.ozlabs.ibm.com
State Accepted
Headers show
Series
  • KVM: PPC: Book3S PR: Allow KVM_PPC_CONFIGURE_V3_MMU to succeed
Related show

Commit Message

Paul Mackerras May 30, 2018, 10:09 a.m.
Currently, PR KVM does not implement the configure_mmu operation, and
so the KVM_PPC_CONFIGURE_V3_MMU ioctl always fails with an EINVAL
error.  This causes recent kernels to fail to boot as a PR KVM guest
on POWER9, since recent kernels booted in HPT mode do the
H_REGISTER_PROC_TBL hypercall, which causes userspace (QEMU) to do
KVM_PPC_CONFIGURE_V3_MMU, which fails.

This implements a minimal configure_mmu operation for PR KVM.  It
succeeds only if the MMU is being configured for HPT mode and no
process table is being registered.  This is enough to get recent
kernels to boot as a PR KVM guest.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
---
 arch/powerpc/kvm/book3s_pr.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Greg Kurz May 30, 2018, 11:17 a.m. | #1
On Wed, 30 May 2018 20:09:46 +1000
Paul Mackerras <paulus@ozlabs.org> wrote:

> Currently, PR KVM does not implement the configure_mmu operation, and
> so the KVM_PPC_CONFIGURE_V3_MMU ioctl always fails with an EINVAL
> error.  This causes recent kernels to fail to boot as a PR KVM guest
> on POWER9, since recent kernels booted in HPT mode do the
> H_REGISTER_PROC_TBL hypercall, which causes userspace (QEMU) to do
> KVM_PPC_CONFIGURE_V3_MMU, which fails.
> 
> This implements a minimal configure_mmu operation for PR KVM.  It
> succeeds only if the MMU is being configured for HPT mode and no
> process table is being registered.  This is enough to get recent
> kernels to boot as a PR KVM guest.
> 
> Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
> ---

Reviewed-by: Greg Kurz <groug@kaod.org>
Tested-by: Greg Kurz <groug@kaod.org>

Thanks Paul !

>  arch/powerpc/kvm/book3s_pr.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
> index c74a8885427d..b1aff9f83ed0 100644
> --- a/arch/powerpc/kvm/book3s_pr.c
> +++ b/arch/powerpc/kvm/book3s_pr.c
> @@ -1687,6 +1687,17 @@ static int kvm_vm_ioctl_get_smmu_info_pr(struct kvm *kvm,
>  
>  	return 0;
>  }
> +
> +static int kvm_configure_mmu_pr(struct kvm *kvm, struct kvm_ppc_mmuv3_cfg *cfg)
> +{
> +	if (!cpu_has_feature(CPU_FTR_ARCH_300))
> +		return -ENODEV;
> +	/* Require flags and process table base and size to all be zero. */
> +	if (cfg->flags || cfg->process_table)
> +		return -EINVAL;
> +	return 0;
> +}
> +
>  #else
>  static int kvm_vm_ioctl_get_smmu_info_pr(struct kvm *kvm,
>  					 struct kvm_ppc_smmu_info *info)
> @@ -1788,6 +1799,7 @@ static struct kvmppc_ops kvm_ops_pr = {
>  	.arch_vm_ioctl  = kvm_arch_vm_ioctl_pr,
>  #ifdef CONFIG_PPC_BOOK3S_64
>  	.hcall_implemented = kvmppc_hcall_impl_pr,
> +	.configure_mmu = kvm_configure_mmu_pr,
>  #endif
>  	.giveup_ext = kvmppc_giveup_ext,
>  };

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index c74a8885427d..b1aff9f83ed0 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -1687,6 +1687,17 @@  static int kvm_vm_ioctl_get_smmu_info_pr(struct kvm *kvm,
 
 	return 0;
 }
+
+static int kvm_configure_mmu_pr(struct kvm *kvm, struct kvm_ppc_mmuv3_cfg *cfg)
+{
+	if (!cpu_has_feature(CPU_FTR_ARCH_300))
+		return -ENODEV;
+	/* Require flags and process table base and size to all be zero. */
+	if (cfg->flags || cfg->process_table)
+		return -EINVAL;
+	return 0;
+}
+
 #else
 static int kvm_vm_ioctl_get_smmu_info_pr(struct kvm *kvm,
 					 struct kvm_ppc_smmu_info *info)
@@ -1788,6 +1799,7 @@  static struct kvmppc_ops kvm_ops_pr = {
 	.arch_vm_ioctl  = kvm_arch_vm_ioctl_pr,
 #ifdef CONFIG_PPC_BOOK3S_64
 	.hcall_implemented = kvmppc_hcall_impl_pr,
+	.configure_mmu = kvm_configure_mmu_pr,
 #endif
 	.giveup_ext = kvmppc_giveup_ext,
 };