All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: arm64: Ensure canonical IPA is hugepage-aligned when handling fault
@ 2024-08-22  7:17 Oliver Upton
  2024-08-22  7:33 ` Marc Zyngier
  2024-08-22  7:41 ` Oliver Upton
  0 siblings, 2 replies; 3+ messages in thread
From: Oliver Upton @ 2024-08-22  7:17 UTC (permalink / raw)
  To: kvmarm
  Cc: Marc Zyngier, James Morse, Suzuki K Poulose, Zenghui Yu,
	Oliver Upton

Zenghui reports that VMs backed by hugetlb pages are no longer booting
after commit fd276e71d1e7 ("KVM: arm64: nv: Handle shadow stage 2 page
faults").

Support for shadow stage-2 MMUs introduced the concept of a fault IPA
and canonical IPA to stage-2 fault handling. These are identical in the
non-nested case, as the hardware stage-2 context is always that of the
canonical IPA space.

Both addresses need to be hugepage-aligned when preparing to install a
hugepage mapping to ensure that KVM uses the correct GFN->PFN translation
and installs that at the correct IPA for the current stage-2.

And now I'm feeling thirsty after all this talk of IPAs...

Fixes: fd276e71d1e7 ("KVM: arm64: nv: Handle shadow stage 2 page faults")
Reported-by: Zenghui Yu <yuzenghui@huawei.com>
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
---

Tested w/ non-nested and nested (well, protected mode) VMs backed
using hugepages.

 arch/arm64/kvm/mmu.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 6981b1bc0946..a509b63bd4dd 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -1540,8 +1540,15 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 		vma_pagesize = min(vma_pagesize, (long)max_map_size);
 	}
 
-	if (vma_pagesize == PMD_SIZE || vma_pagesize == PUD_SIZE)
+	/*
+	 * Both the canonical IPA and fault IPA must be hugepage-aligned to
+	 * ensure we find the right PFN and lay down the mapping in the right
+	 * place.
+	 */
+	if (vma_pagesize == PMD_SIZE || vma_pagesize == PUD_SIZE) {
 		fault_ipa &= ~(vma_pagesize - 1);
+		ipa &= ~(vma_pagesize - 1);
+	}
 
 	gfn = ipa >> PAGE_SHIFT;
 	mte_allowed = kvm_vma_mte_allowed(vma);
-- 
2.46.0.295.g3b9ea8a38a-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: arm64: Ensure canonical IPA is hugepage-aligned when handling fault
  2024-08-22  7:17 [PATCH] KVM: arm64: Ensure canonical IPA is hugepage-aligned when handling fault Oliver Upton
@ 2024-08-22  7:33 ` Marc Zyngier
  2024-08-22  7:41 ` Oliver Upton
  1 sibling, 0 replies; 3+ messages in thread
From: Marc Zyngier @ 2024-08-22  7:33 UTC (permalink / raw)
  To: Oliver Upton; +Cc: kvmarm, James Morse, Suzuki K Poulose, Zenghui Yu

On Thu, 22 Aug 2024 08:17:09 +0100,
Oliver Upton <oliver.upton@linux.dev> wrote:
> 
> Zenghui reports that VMs backed by hugetlb pages are no longer booting
> after commit fd276e71d1e7 ("KVM: arm64: nv: Handle shadow stage 2 page
> faults").
> 
> Support for shadow stage-2 MMUs introduced the concept of a fault IPA
> and canonical IPA to stage-2 fault handling. These are identical in the
> non-nested case, as the hardware stage-2 context is always that of the
> canonical IPA space.
> 
> Both addresses need to be hugepage-aligned when preparing to install a
> hugepage mapping to ensure that KVM uses the correct GFN->PFN translation
> and installs that at the correct IPA for the current stage-2.
> 
> And now I'm feeling thirsty after all this talk of IPAs...
> 
> Fixes: fd276e71d1e7 ("KVM: arm64: nv: Handle shadow stage 2 page faults")
> Reported-by: Zenghui Yu <yuzenghui@huawei.com>
> Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
> ---
> 
> Tested w/ non-nested and nested (well, protected mode) VMs backed
> using hugepages.
> 
>  arch/arm64/kvm/mmu.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index 6981b1bc0946..a509b63bd4dd 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c
> @@ -1540,8 +1540,15 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
>  		vma_pagesize = min(vma_pagesize, (long)max_map_size);
>  	}
>  
> -	if (vma_pagesize == PMD_SIZE || vma_pagesize == PUD_SIZE)
> +	/*
> +	 * Both the canonical IPA and fault IPA must be hugepage-aligned to
> +	 * ensure we find the right PFN and lay down the mapping in the right
> +	 * place.
> +	 */
> +	if (vma_pagesize == PMD_SIZE || vma_pagesize == PUD_SIZE) {
>  		fault_ipa &= ~(vma_pagesize - 1);
> +		ipa &= ~(vma_pagesize - 1);
> +	}
>  
>  	gfn = ipa >> PAGE_SHIFT;
>  	mte_allowed = kvm_vma_mte_allowed(vma);

Rather obvious in retrospect, and I should add some hugetlb-based
testing to my setup. Thanks both for spotting and fixing it.

Reviewed-by: Marc Zyngier <maz@kernel.org>

	M.

-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: arm64: Ensure canonical IPA is hugepage-aligned when handling fault
  2024-08-22  7:17 [PATCH] KVM: arm64: Ensure canonical IPA is hugepage-aligned when handling fault Oliver Upton
  2024-08-22  7:33 ` Marc Zyngier
@ 2024-08-22  7:41 ` Oliver Upton
  1 sibling, 0 replies; 3+ messages in thread
From: Oliver Upton @ 2024-08-22  7:41 UTC (permalink / raw)
  To: Oliver Upton, kvmarm
  Cc: Suzuki K Poulose, Zenghui Yu, James Morse, Marc Zyngier

On Thu, 22 Aug 2024 07:17:09 +0000, Oliver Upton wrote:
> Zenghui reports that VMs backed by hugetlb pages are no longer booting
> after commit fd276e71d1e7 ("KVM: arm64: nv: Handle shadow stage 2 page
> faults").
> 
> Support for shadow stage-2 MMUs introduced the concept of a fault IPA
> and canonical IPA to stage-2 fault handling. These are identical in the
> non-nested case, as the hardware stage-2 context is always that of the
> canonical IPA space.
> 
> [...]

Applied to kvmarm/fixes, thanks!

[1/1] KVM: arm64: Ensure canonical IPA is hugepage-aligned when handling fault
      https://git.kernel.org/kvmarm/kvmarm/c/1d8c3c23a6bc

--
Best,
Oliver

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-22  7:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-22  7:17 [PATCH] KVM: arm64: Ensure canonical IPA is hugepage-aligned when handling fault Oliver Upton
2024-08-22  7:33 ` Marc Zyngier
2024-08-22  7:41 ` Oliver Upton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.