OSDN Git Service

KVM: arm64: Fix kvm init failure when mode!=vhe and VA_BITS=52.
authorRyan Roberts <ryan.roberts@arm.com>
Thu, 3 Nov 2022 15:05:06 +0000 (15:05 +0000)
committerMarc Zyngier <maz@kernel.org>
Thu, 10 Nov 2022 19:22:51 +0000 (19:22 +0000)
commit579d7ebe90a332cc5b6c02db9250fd0816a64f63
tree1fe1e4afbc2308c5a6539d2464c7be8df2f4f1cf
parent30a0b95b1335e12efef89dd78518ed3e4a71a763
KVM: arm64: Fix kvm init failure when mode!=vhe and VA_BITS=52.

For nvhe and protected modes, the hyp stage 1 page-tables were previously
configured to have the same number of VA bits as the kernel's idmap.
However, for kernel configs with VA_BITS=52 and where the kernel is
loaded in physical memory below 48 bits, the idmap VA bits is actually
smaller than the kernel's normal stage 1 VA bits. This can lead to
kernel addresses that can't be mapped into the hypervisor, leading to
kvm initialization failure during boot:

  kvm [1]: IPA Size Limit: 48 bits
  kvm [1]: Cannot map world-switch code
  kvm [1]: error initializing Hyp mode: -34

Fix this by ensuring that the hyp stage 1 VA size is the maximum of
what's used for the idmap and the regular kernel stage 1. At the same
time, refactor the code so that the hyp VA bits is only calculated in
one place.

Prior to 7ba8f2b2d652, the idmap was always 52 bits for a 52 VA bits
kernel and therefore the hyp stage1 was also always 52 bits.

Fixes: 7ba8f2b2d652 ("arm64: mm: use a 48-bit ID map when possible on 52-bit VA builds")
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
[maz: commit message fixes]
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20221103150507.32948-2-ryan.roberts@arm.com
arch/arm64/kvm/arm.c
arch/arm64/kvm/mmu.c