diff mbox series

[5/5] KVM: arm64: Consistently use KVM's types/helpers in kvm_age_gfn()

Message ID 20230111000300.2034799-6-oliver.upton@linux.dev (mailing list archive)
State New, archived
Headers show
Series KVM: arm64: Handle unaligned memslots in kvm_(test_)_age_gfn() | expand

Commit Message

Oliver Upton Jan. 11, 2023, 12:03 a.m. UTC
There's no real need for indirection through the kernel's PTE types
here. Add a new helper to test if the access flag is set on a PTE and
use it to roll over kvm_age_gfn() to only using kvm_pte_t.

No functional change intended.

Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
---
 arch/arm64/include/asm/kvm_pgtable.h |  5 +++++
 arch/arm64/kvm/hyp/pgtable.c         |  2 +-
 arch/arm64/kvm/mmu.c                 | 12 +++++-------
 3 files changed, 11 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h
index 81e04a24cc76..a81cd1ea64cb 100644
--- a/arch/arm64/include/asm/kvm_pgtable.h
+++ b/arch/arm64/include/asm/kvm_pgtable.h
@@ -86,6 +86,11 @@  static inline bool kvm_pte_valid(kvm_pte_t pte)
 	return pte & KVM_PTE_VALID;
 }
 
+static inline bool kvm_pte_young(kvm_pte_t pte)
+{
+	return pte & KVM_PTE_LEAF_ATTR_LO_S2_AF;
+}
+
 static inline u64 kvm_pte_to_phys(kvm_pte_t pte)
 {
 	u64 pa = pte & KVM_PTE_ADDR_MASK;
diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
index 791f7e81671e..19f5094dfd93 100644
--- a/arch/arm64/kvm/hyp/pgtable.c
+++ b/arch/arm64/kvm/hyp/pgtable.c
@@ -1085,7 +1085,7 @@  bool kvm_pgtable_stage2_is_young(struct kvm_pgtable *pgt, u64 addr, u64 size)
 {
 	kvm_pte_t attr_old = 0;
 	stage2_update_leaf_attrs(pgt, addr, size, 0, 0, &attr_old, NULL, 0);
-	return attr_old & KVM_PTE_LEAF_ATTR_LO_S2_AF;
+	return kvm_pte_young(attr_old);
 }
 
 int kvm_pgtable_stage2_relax_perms(struct kvm_pgtable *pgt, u64 addr,
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 0b8e2a57f81a..3297475dcfcc 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -1607,17 +1607,15 @@  bool kvm_set_spte_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
 bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
 {
 	u64 size = (range->end - range->start) << PAGE_SHIFT;
-	kvm_pte_t kpte;
-	pte_t pte;
+	kvm_pte_t pte;
 
 	if (!kvm->arch.mmu.pgt)
 		return false;
 
-	kpte = kvm_pgtable_stage2_mkold(kvm->arch.mmu.pgt,
-					range->start << PAGE_SHIFT,
-					size);
-	pte = __pte(kpte);
-	return pte_young(pte);
+	pte = kvm_pgtable_stage2_mkold(kvm->arch.mmu.pgt,
+				       range->start << PAGE_SHIFT,
+				       size);
+	return kvm_pte_young(pte);
 }
 
 bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)