Skip to contentSkip to conversation

KVM: arm64: Fix protected VM fault on system with pages larger than 4K

PATCH In review Vincent Donnefort 3 participants 4 messages Sep 15 – Sep 17

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 KVM: arm64: Fix protected VM fault on system with pages larger than 4K

Just like commit 08f97454b7fa ("KVM: arm64: Fix protected mode handling of pages larger than 4kB") fixed the boot of non-protected VMs on system larger than 4K pages, align the fault IPA down to the page-size for protected VMs.

To paraphrase Marc, pkvm_pgtable_stage2_map() assumes the address passed as a parameter is aligned to the size of the intended mapping, while HPFAR_EL2 gives the IPA minus the bottom 12 bits, regardless of the system page size configuration.

Add a check at the start of pkvm_pgtable_stage2_map() as we do not support !PAGE_ALIGNED arguments and ensure callers pass a page-aligned IPA.

Fixes ea03466e806f ("KVM: arm64: Handle aborts from protected VMs")
---
 arch/arm64/kvm/mmu.c  | 12 +++++++-----
 arch/arm64/kvm/pkvm.c |  3 +++
 2 files changed, 10 insertions(+), 5 deletions(-)

Changelog:

v3:
- Fix nested case in gmem_abort() (Sashiko)

v2: https://lore.kernel.org/all/[email protected]/

- Use gfn_to_gpa(gfn)
- Drop "phys" from the PAGE_ALIGNED check, it isn't a requirement.
- Fix gmem_abort() as well (Sashiko)

v1: https://lore.kernel.org/all/[email protected]/

arch/arm64/kvm/mmu.c +7 -5
index 9ba86450fe4a..e199dd339583 100644
@@ -1610,6 +1610,7 @@ static int gmem_abort(const struct kvm_s2_fault_desc *s2fd)
 	bool write_fault, exec_fault;
 	bool perm_fault = kvm_vcpu_trap_is_permission_fault(s2fd->vcpu);
 	enum kvm_pgtable_walk_flags flags = KVM_PGTABLE_WALK_SHARED;
+	phys_addr_t ipa = ALIGN_DOWN(s2fd->fault_ipa, PAGE_SIZE);
 	enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R;
 	struct kvm_pgtable *pgt = s2fd->vcpu->arch.hw_mmu->pgt;
 	unsigned long mmu_seq;
@@ -1672,12 +1673,12 @@ static int gmem_abort(const struct kvm_s2_fault_desc *s2fd)
 		 * PTE, which will be preserved.
 		 */
 		prot &= ~KVM_NV_GUEST_MAP_SZ;
-		ret = KVM_PGT_FN(kvm_pgtable_stage2_relax_perms)(pgt, s2fd->fault_ipa,
+		ret = KVM_PGT_FN(kvm_pgtable_stage2_relax_perms)(pgt, ipa,
 								 prot, flags);
 	} else {
-		ret = KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, s2fd->fault_ipa, PAGE_SIZE,
-							 __pfn_to_phys(pfn), prot,
-							 memcache, flags);
+		ret = KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, ipa, PAGE_SIZE,
+							 __pfn_to_phys(pfn),
+							 prot, memcache, flags);
 	}
 
 out_unlock:
@@ -1710,6 +1711,7 @@ static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
 	unsigned int flags = FOLL_HWPOISON | FOLL_LONGTERM | FOLL_WRITE;
 	struct kvm_vcpu *vcpu = s2fd->vcpu;
 	struct kvm_pgtable *pgt = vcpu->arch.hw_mmu->pgt;
+	gfn_t gfn = gpa_to_gfn(s2fd->fault_ipa);
 	struct mm_struct *mm = current->mm;
 	struct kvm *kvm = vcpu->kvm;
 	void *hyp_memcache;
@@ -1756,7 +1758,7 @@ static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
 	}
 
 	write_lock(&kvm->mmu_lock);
-	ret = pkvm_pgtable_stage2_map(pgt, s2fd->fault_ipa, PAGE_SIZE,
+	ret = pkvm_pgtable_stage2_map(pgt, gfn_to_gpa(gfn), PAGE_SIZE,
 				      page_to_phys(page), KVM_PGTABLE_PROT_RWX,
 				      hyp_memcache, 0);
 	write_unlock(&kvm->mmu_lock);
arch/arm64/kvm/pkvm.c +3 -0
index 8e4c6e4bec12..b7340c430ed6 100644
@@ -414,6 +414,9 @@ int pkvm_pgtable_stage2_map(struct kvm_pgtable *pgt, u64 addr, u64 size,
 	u64 end = addr + size;
 	int ret;
 
+	if (!PAGE_ALIGNED(addr | size))
+		return -EINVAL;
+
 	lockdep_assert_held_write(&kvm->mmu_lock);
 	mapping = pkvm_mapping_iter_first(&pgt->pkvm_mappings, addr, end - 1);
 

base-commit: df2908090cda368b01ff43709f51890076c56157

Signature · 1 line
2.55.0.1032.g73a4cd73de-goog
reviewer Tested-by Reviewed-by on v3 1/1
#1 lore raw

Hi Vincent,

Quoted 6 lines · Vincent Donnefort' via kernel-team

Just like commit 08f97454b7fa ("KVM: arm64: Fix protected mode handling of pages larger than 4kB") fixed the boot of non-protected VMs on system larger than 4K pages, align the fault IPA down to the page-size for protected VMs.

Quoted 8 lines

To paraphrase Marc, pkvm_pgtable_stage2_map() assumes the address passed as a parameter is aligned to the size of the intended mapping, while HPFAR_EL2 gives the IPA minus the bottom 12 bits, regardless of the system page size configuration.

Add a check at the start of pkvm_pgtable_stage2_map() as we do not support !PAGE_ALIGNED arguments and ensure callers pass a page-aligned IPA.

The fix is correct, and I can reproduce the bug. On a 16K-page host an unpatched v7.3-rc2 never gets a pVM to a prompt: no guest console output at all, a core pegged at 100% when I sampled it a minute in, killed at the 120s timeout. A guest_memfd-backed non-protected VM times out the same way, while one without guest_memfd boots fine, which puts the failure on the two paths you fix. With the patch all three boot clean, and 4K still boots both. That is QEMU with kvmtool guests; the same three 16K legs also pass on an M4 running pKVM at EL2 on the silicon.

Quoted 1 line
Fixes ea03466e806f ("KVM: arm64: Handle aborts from protected VMs")

A second Fixes: for the gmem_abort() half? a7b57e099592 ("KVM: arm64:
Handle guest_memfd-backed guest page faults") added that call site, and the ranges differ: ea03466e806f is in v7.1, a7b57e099592 in v6.18.

Should this carry Cc: [email protected]? 08f97454b7fa, the fix this one follows, did, and 16K-page hosts are a shipping Android configuration.

Quoted 24 lines
---
 arch/arm64/kvm/mmu.c  | 12 +++++++-----
 arch/arm64/kvm/pkvm.c |  3 +++
 2 files changed, 10 insertions(+), 5 deletions(-)

Changelog:

v3:
- Fix nested case in gmem_abort() (Sashiko)

v2: https://lore.kernel.org/all/[email protected]/

- Use gfn_to_gpa(gfn)
- Drop "phys" from the PAGE_ALIGNED check, it isn't a requirement.
- Fix gmem_abort() as well (Sashiko)

v1: https://lore.kernel.org/all/[email protected]/

arch/arm64/kvm/mmu.c +0 -0
index 9ba86450fe4a..e199dd339583 100644

arch/arm64/kvm/mmu.c static int gmem_abort(const struct kvm_s2_fault_desc *s2fd) · line 1616

Quoted 7 lines
arch/arm64/kvm/mmu.c +1 -0
@@ -1610,6 +1610,7 @@ static int gmem_abort(const struct kvm_s2_fault_desc *s2fd)
        bool write_fault, exec_fault;
        bool perm_fault = kvm_vcpu_trap_is_permission_fault(s2fd->vcpu);
        enum kvm_pgtable_walk_flags flags = KVM_PGTABLE_WALK_SHARED;
+       phys_addr_t ipa = ALIGN_DOWN(s2fd->fault_ipa, PAGE_SIZE);
        enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R;
        struct kvm_pgtable *pgt = s2fd->vcpu->arch.hw_mmu->pgt;
        unsigned long mmu_seq;

One more in gmem_abort(): the memory fault exit at mmu.c:1647 still reports the unaligned address, and that one is userspace-visible.

    kvm_prepare_memory_fault_exit(s2fd->vcpu, s2fd->fault_ipa, PAGE_SIZE,
         write_fault, exec_fault, false);

api.rst defines the range as [gpa, gpa + size), so on a 16K host it starts mid-page. gfn_to_gpa(gfn) is the one to use: gfn is what kvm_gmem_get_pfn() failed on, and the L1 IPA in the nested case. x86 passes fault->gfn << PAGE_SHIFT.

Quoted 39 lines
arch/arm64/kvm/mmu.c +6 -5
@@ -1672,12 +1673,12 @@ static int gmem_abort(const struct kvm_s2_fault_desc *s2fd)
                 * PTE, which will be preserved.
                 */
                prot &= ~KVM_NV_GUEST_MAP_SZ;
-               ret = KVM_PGT_FN(kvm_pgtable_stage2_relax_perms)(pgt, s2fd->fault_ipa,
+               ret = KVM_PGT_FN(kvm_pgtable_stage2_relax_perms)(pgt, ipa,
                                                                 prot, flags);
        } else {
-               ret = KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, s2fd->fault_ipa, PAGE_SIZE,
-                                                        __pfn_to_phys(pfn), prot,
-                                                        memcache, flags);
+               ret = KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, ipa, PAGE_SIZE,
+                                                        __pfn_to_phys(pfn),
+                                                        prot, memcache, flags);
        }
 
 out_unlock:
@@ -1710,6 +1711,7 @@ static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
        unsigned int flags = FOLL_HWPOISON | FOLL_LONGTERM | FOLL_WRITE;
        struct kvm_vcpu *vcpu = s2fd->vcpu;
        struct kvm_pgtable *pgt = vcpu->arch.hw_mmu->pgt;
+       gfn_t gfn = gpa_to_gfn(s2fd->fault_ipa);
        struct mm_struct *mm = current->mm;
        struct kvm *kvm = vcpu->kvm;
        void *hyp_memcache;
@@ -1756,7 +1758,7 @@ static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
        }
 
        write_lock(&kvm->mmu_lock);
-       ret = pkvm_pgtable_stage2_map(pgt, s2fd->fault_ipa, PAGE_SIZE,
+       ret = pkvm_pgtable_stage2_map(pgt, gfn_to_gpa(gfn), PAGE_SIZE,
                                      page_to_phys(page), KVM_PGTABLE_PROT_RWX,
                                      hyp_memcache, 0);
        write_unlock(&kvm->mmu_lock);
arch/arm64/kvm/pkvm.c +0 -0
index 8e4c6e4bec12..b7340c430ed6 100644

arch/arm64/kvm/pkvm.c int pkvm_pgtable_stage2_map(struct kvm_pgtable *pgt, u64 addr, u64 size, · line 419

Quoted 6 lines
arch/arm64/kvm/pkvm.c +3 -0
@@ -414,6 +414,9 @@ int pkvm_pgtable_stage2_map(struct kvm_pgtable *pgt, u64 addr, u64 size,
        u64 end = addr + size;
        int ret;
 
+       if (!PAGE_ALIGNED(addr | size))
+               return -EINVAL;
+

Could this be if (WARN_ON_ONCE(!PAGE_ALIGNED(addr | size)))? The three checks just below WARN on the same class of caller bug, and this one runs first, so a bad size now returns -EINVAL with no splat.

With the memory fault exit fixed:

Cheers,
/fuad

Quoted 10 lines
arch/arm64/kvm/pkvm.c +0 -0
        lockdep_assert_held_write(&kvm->mmu_lock);
        mapping = pkvm_mapping_iter_first(&pgt->pkvm_mappings, addr, end - 1);
 

base-commit: df2908090cda368b01ff43709f51890076c56157 --
2.55.0.1032.g73a4cd73de-goog

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

#2 lore raw
Quoted 134 lines · Fuad Tabba

Hi Vincent,

Quoted 6 lines · Vincent Donnefort' via kernel-team

Just like commit 08f97454b7fa ("KVM: arm64: Fix protected mode handling of pages larger than 4kB") fixed the boot of non-protected VMs on system larger than 4K pages, align the fault IPA down to the page-size for protected VMs.

Quoted 8 lines

To paraphrase Marc, pkvm_pgtable_stage2_map() assumes the address passed as a parameter is aligned to the size of the intended mapping, while HPFAR_EL2 gives the IPA minus the bottom 12 bits, regardless of the system page size configuration.

Add a check at the start of pkvm_pgtable_stage2_map() as we do not support !PAGE_ALIGNED arguments and ensure callers pass a page-aligned IPA.

The fix is correct, and I can reproduce the bug. On a 16K-page host an unpatched v7.3-rc2 never gets a pVM to a prompt: no guest console output at all, a core pegged at 100% when I sampled it a minute in, killed at the 120s timeout. A guest_memfd-backed non-protected VM times out the same way, while one without guest_memfd boots fine, which puts the failure on the two paths you fix. With the patch all three boot clean, and 4K still boots both. That is QEMU with kvmtool guests; the same three 16K legs also pass on an M4 running pKVM at EL2 on the silicon.

Quoted 1 line
Fixes ea03466e806f ("KVM: arm64: Handle aborts from protected VMs")

A second Fixes: for the gmem_abort() half? a7b57e099592 ("KVM: arm64:
Handle guest_memfd-backed guest page faults") added that call site, and the ranges differ: ea03466e806f is in v7.1, a7b57e099592 in v6.18.

Should this carry Cc: [email protected]? 08f97454b7fa, the fix this one follows, did, and 16K-page hosts are a shipping Android configuration.

Quoted 24 lines
---
 arch/arm64/kvm/mmu.c  | 12 +++++++-----
 arch/arm64/kvm/pkvm.c |  3 +++
 2 files changed, 10 insertions(+), 5 deletions(-)

Changelog:

v3:
- Fix nested case in gmem_abort() (Sashiko)

v2: https://lore.kernel.org/all/[email protected]/

- Use gfn_to_gpa(gfn)
- Drop "phys" from the PAGE_ALIGNED check, it isn't a requirement.
- Fix gmem_abort() as well (Sashiko)

v1: https://lore.kernel.org/all/[email protected]/

arch/arm64/kvm/mmu.c +0 -0
index 9ba86450fe4a..e199dd339583 100644

arch/arm64/kvm/mmu.c static int gmem_abort(const struct kvm_s2_fault_desc *s2fd) · line 1616

Quoted 7 lines
arch/arm64/kvm/mmu.c +1 -0
@@ -1610,6 +1610,7 @@ static int gmem_abort(const struct kvm_s2_fault_desc *s2fd)
        bool write_fault, exec_fault;
        bool perm_fault = kvm_vcpu_trap_is_permission_fault(s2fd->vcpu);
        enum kvm_pgtable_walk_flags flags = KVM_PGTABLE_WALK_SHARED;
+       phys_addr_t ipa = ALIGN_DOWN(s2fd->fault_ipa, PAGE_SIZE);
        enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R;
        struct kvm_pgtable *pgt = s2fd->vcpu->arch.hw_mmu->pgt;
        unsigned long mmu_seq;

One more in gmem_abort(): the memory fault exit at mmu.c:1647 still reports the unaligned address, and that one is userspace-visible.

    kvm_prepare_memory_fault_exit(s2fd->vcpu, s2fd->fault_ipa, PAGE_SIZE,
         write_fault, exec_fault, false);

api.rst defines the range as [gpa, gpa + size), so on a 16K host it starts mid-page. gfn_to_gpa(gfn) is the one to use: gfn is what kvm_gmem_get_pfn() failed on, and the L1 IPA in the nested case. x86 passes fault->gfn << PAGE_SHIFT.

Quoted 39 lines
arch/arm64/kvm/mmu.c +6 -5
@@ -1672,12 +1673,12 @@ static int gmem_abort(const struct kvm_s2_fault_desc *s2fd)
                 * PTE, which will be preserved.
                 */
                prot &= ~KVM_NV_GUEST_MAP_SZ;
-               ret = KVM_PGT_FN(kvm_pgtable_stage2_relax_perms)(pgt, s2fd->fault_ipa,
+               ret = KVM_PGT_FN(kvm_pgtable_stage2_relax_perms)(pgt, ipa,
                                                                 prot, flags);
        } else {
-               ret = KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, s2fd->fault_ipa, PAGE_SIZE,
-                                                        __pfn_to_phys(pfn), prot,
-                                                        memcache, flags);
+               ret = KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, ipa, PAGE_SIZE,
+                                                        __pfn_to_phys(pfn),
+                                                        prot, memcache, flags);
        }
 
 out_unlock:
@@ -1710,6 +1711,7 @@ static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
        unsigned int flags = FOLL_HWPOISON | FOLL_LONGTERM | FOLL_WRITE;
        struct kvm_vcpu *vcpu = s2fd->vcpu;
        struct kvm_pgtable *pgt = vcpu->arch.hw_mmu->pgt;
+       gfn_t gfn = gpa_to_gfn(s2fd->fault_ipa);
        struct mm_struct *mm = current->mm;
        struct kvm *kvm = vcpu->kvm;
        void *hyp_memcache;
@@ -1756,7 +1758,7 @@ static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
        }
 
        write_lock(&kvm->mmu_lock);
-       ret = pkvm_pgtable_stage2_map(pgt, s2fd->fault_ipa, PAGE_SIZE,
+       ret = pkvm_pgtable_stage2_map(pgt, gfn_to_gpa(gfn), PAGE_SIZE,
                                      page_to_phys(page), KVM_PGTABLE_PROT_RWX,
                                      hyp_memcache, 0);
        write_unlock(&kvm->mmu_lock);
arch/arm64/kvm/pkvm.c +0 -0
index 8e4c6e4bec12..b7340c430ed6 100644

arch/arm64/kvm/pkvm.c int pkvm_pgtable_stage2_map(struct kvm_pgtable *pgt, u64 addr, u64 size, · line 419

Quoted 6 lines
arch/arm64/kvm/pkvm.c +3 -0
@@ -414,6 +414,9 @@ int pkvm_pgtable_stage2_map(struct kvm_pgtable *pgt, u64 addr, u64 size,
        u64 end = addr + size;
        int ret;
 
+       if (!PAGE_ALIGNED(addr | size))
+               return -EINVAL;
+

Could this be if (WARN_ON_ONCE(!PAGE_ALIGNED(addr | size)))? The three checks just below WARN on the same class of caller bug, and this one runs first, so a bad size now returns -EINVAL with no splat.

Quoted 5 lines

With the memory fault exit fixed:

Cheers,
/fuad

Thanks Fuad,

I'll modify that. Although in the new respin I will also add support for kvm_s2_fault_vma_info(), which should naturally fix that issue, just like Marc suggested [1]

[1] https://lore.kernel.org/all/[email protected]/

Signature · 1 line
Vincent
Quoted 14 lines
Quoted 11 lines
arch/arm64/kvm/pkvm.c +0 -0
        lockdep_assert_held_write(&kvm->mmu_lock);
        mapping = pkvm_mapping_iter_first(&pgt->pkvm_mappings, addr, end - 1);
 

base-commit: df2908090cda368b01ff43709f51890076c56157 --
2.55.0.1032.g73a4cd73de-goog

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

reviewer Reviewed-by on v3 1/1
#3 lore raw
In reply to Vincent Donnefort
Quoted 64 lines · Vincent Donnefort

Just like commit 08f97454b7fa ("KVM: arm64: Fix protected mode handling of pages larger than 4kB") fixed the boot of non-protected VMs on system larger than 4K pages, align the fault IPA down to the page-size for protected VMs.

To paraphrase Marc, pkvm_pgtable_stage2_map() assumes the address passed as a parameter is aligned to the size of the intended mapping, while HPFAR_EL2 gives the IPA minus the bottom 12 bits, regardless of the system page size configuration.

Add a check at the start of pkvm_pgtable_stage2_map() as we do not support !PAGE_ALIGNED arguments and ensure callers pass a page-aligned IPA.

Fixes ea03466e806f ("KVM: arm64: Handle aborts from protected VMs")
---
  arch/arm64/kvm/mmu.c  | 12 +++++++-----
  arch/arm64/kvm/pkvm.c |  3 +++
  2 files changed, 10 insertions(+), 5 deletions(-)

Changelog:

v3:
- Fix nested case in gmem_abort() (Sashiko)

v2: https://lore.kernel.org/all/[email protected]/

- Use gfn_to_gpa(gfn)
- Drop "phys" from the PAGE_ALIGNED check, it isn't a requirement.
- Fix gmem_abort() as well (Sashiko)

v1: https://lore.kernel.org/all/[email protected]/

arch/arm64/kvm/mmu.c +5 -4
index 9ba86450fe4a..e199dd339583 100644
@@ -1610,6 +1610,7 @@ static int gmem_abort(const struct kvm_s2_fault_desc *s2fd)
  	bool write_fault, exec_fault;
  	bool perm_fault = kvm_vcpu_trap_is_permission_fault(s2fd->vcpu);
  	enum kvm_pgtable_walk_flags flags = KVM_PGTABLE_WALK_SHARED;
+	phys_addr_t ipa = ALIGN_DOWN(s2fd->fault_ipa, PAGE_SIZE);
  	enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R;
  	struct kvm_pgtable *pgt = s2fd->vcpu->arch.hw_mmu->pgt;
  	unsigned long mmu_seq;
@@ -1672,12 +1673,12 @@ static int gmem_abort(const struct kvm_s2_fault_desc *s2fd)
  		 * PTE, which will be preserved.
  		 */
  		prot &= ~KVM_NV_GUEST_MAP_SZ;
-		ret = KVM_PGT_FN(kvm_pgtable_stage2_relax_perms)(pgt, s2fd->fault_ipa,
+		ret = KVM_PGT_FN(kvm_pgtable_stage2_relax_perms)(pgt, ipa,
  								 prot, flags);
  	} else {
-		ret = KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, s2fd->fault_ipa, PAGE_SIZE,
-							 __pfn_to_phys(pfn), prot,
-							 memcache, flags);
+		ret = KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, ipa, PAGE_SIZE,
+							 __pfn_to_phys(pfn),
+							 prot, memcache, flags);
  	}
 
  out_unlock:

arch/arm64/kvm/mmu.c static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd) · line 1714

Quoted 4 lines
arch/arm64/kvm/mmu.c +1 -0
@@ -1710,6 +1711,7 @@ static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
  	unsigned int flags = FOLL_HWPOISON | FOLL_LONGTERM | FOLL_WRITE;
  	struct kvm_vcpu *vcpu = s2fd->vcpu;
  	struct kvm_pgtable *pgt = vcpu->arch.hw_mmu->pgt;
+	gfn_t gfn = gpa_to_gfn(s2fd->fault_ipa);

minor nit: Is there any reason why this is not consistent with the gmem_abort() ? i.e., using gfn instead of "ipa" ?

The patch as such looks correct to me. So, either way :

Quoted 28 lines
arch/arm64/kvm/mmu.c +1 -1
  	struct mm_struct *mm = current->mm;
  	struct kvm *kvm = vcpu->kvm;
  	void *hyp_memcache;
@@ -1756,7 +1758,7 @@ static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
  	}
 
  	write_lock(&kvm->mmu_lock);
-	ret = pkvm_pgtable_stage2_map(pgt, s2fd->fault_ipa, PAGE_SIZE,
+	ret = pkvm_pgtable_stage2_map(pgt, gfn_to_gpa(gfn), PAGE_SIZE,
  				      page_to_phys(page), KVM_PGTABLE_PROT_RWX,
  				      hyp_memcache, 0);
  	write_unlock(&kvm->mmu_lock);
arch/arm64/kvm/pkvm.c +3 -0
index 8e4c6e4bec12..b7340c430ed6 100644
@@ -414,6 +414,9 @@ int pkvm_pgtable_stage2_map(struct kvm_pgtable *pgt, u64 addr, u64 size,
  	u64 end = addr + size;
  	int ret;
 
+	if (!PAGE_ALIGNED(addr | size))
+		return -EINVAL;
+
  	lockdep_assert_held_write(&kvm->mmu_lock);
  	mapping = pkvm_mapping_iter_first(&pgt->pkvm_mappings, addr, end - 1);
 

base-commit: df2908090cda368b01ff43709f51890076c56157