Skip to content

Commit 7d71755

Browse files
author
Marc Zyngier
committed
KVM: arm64: Reject VM creation when the default IPA size is unsupported
KVM/arm64 has forever used a 40bit default IPA space, partially due to its 32bit heritage (where the only choice is 40bit). However, there are implementations in the wild that have a *cough* much smaller *cough* IPA space, which leads to a misprogramming of VTCR_EL2, and a guest that is stuck on its first memory access if userspace dares to ask for the default IPA setting (which most VMMs do). Instead, blundly reject the creation of such VM, as we can't satisfy the requirements from userspace (with a one-off warning). Also clarify the boot warning, and document that the VM creation will fail when an unsupported IPA size is provided. Although this is an ABI change, it doesn't really change much for userspace: - the guest couldn't run before this change, but no error was returned. At least userspace knows what is happening. - a memory slot that was accepted because it did fit the default IPA space now doesn't even get a chance to be registered. The other thing that is left doing is to convince userspace to actually use the IPA space setting instead of relying on the antiquated default. Fixes: 233a7cb ("kvm: arm64: Allow tuning the physical address size for VM") Signed-off-by: Marc Zyngier <maz@kernel.org> Cc: stable@vger.kernel.org Reviewed-by: Andrew Jones <drjones@redhat.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Link: https://lore.kernel.org/r/20210311100016.3830038-2-maz@kernel.org
1 parent 01dc926 commit 7d71755

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

Documentation/virt/kvm/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ is dependent on the CPU capability and the kernel configuration. The limit can
182182
be retrieved using KVM_CAP_ARM_VM_IPA_SIZE of the KVM_CHECK_EXTENSION
183183
ioctl() at run-time.
184184

185+
Creation of the VM will fail if the requested IPA size (whether it is
186+
implicit or explicit) is unsupported on the host.
187+
185188
Please note that configuring the IPA size does not affect the capability
186189
exposed by the guest CPUs in ID_AA64MMFR0_EL1[PARange]. It only affects
187190
size of the address translated by the stage2 level (guest physical to

arch/arm64/kvm/reset.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,9 @@ int kvm_set_ipa_limit(void)
324324
}
325325

326326
kvm_ipa_limit = id_aa64mmfr0_parange_to_phys_shift(parange);
327-
WARN(kvm_ipa_limit < KVM_PHYS_SHIFT,
328-
"KVM IPA Size Limit (%d bits) is smaller than default size\n",
329-
kvm_ipa_limit);
330-
kvm_info("IPA Size Limit: %d bits\n", kvm_ipa_limit);
327+
kvm_info("IPA Size Limit: %d bits%s\n", kvm_ipa_limit,
328+
((kvm_ipa_limit < KVM_PHYS_SHIFT) ?
329+
" (Reduced IPA size, limited VM/VMM compatibility)" : ""));
331330

332331
return 0;
333332
}
@@ -356,6 +355,11 @@ int kvm_arm_setup_stage2(struct kvm *kvm, unsigned long type)
356355
return -EINVAL;
357356
} else {
358357
phys_shift = KVM_PHYS_SHIFT;
358+
if (phys_shift > kvm_ipa_limit) {
359+
pr_warn_once("%s using unsupported default IPA limit, upgrade your VMM\n",
360+
current->comm);
361+
return -EINVAL;
362+
}
359363
}
360364

361365
mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1);

0 commit comments

Comments
 (0)