@@ -172,6 +172,11 @@ static kvm_pte_t kvm_init_invalid_leaf_owner(u8 owner_id)
return FIELD_PREP(KVM_INVALID_PTE_OWNER_MASK, owner_id);
}
+static u8 kvm_invalid_pte_owner(kvm_pte_t pte)
+{
+ return FIELD_GET(KVM_INVALID_PTE_OWNER_MASK, pte);
+}
+
static int kvm_pgtable_visitor_cb(struct kvm_pgtable_walk_data *data, u64 addr,
u32 level, kvm_pte_t *ptep,
enum kvm_pgtable_walk_flags flag)
@@ -679,7 +684,7 @@ static bool stage2_pte_is_counted(kvm_pte_t pte)
* encode ownership of a page to another entity than the page-table
* owner, whose id is 0.
*/
- return !!pte;
+ return kvm_pte_valid(pte) || kvm_invalid_pte_owner(pte);
}
static void stage2_put_pte(kvm_pte_t *ptep, struct kvm_s2_mmu *mmu, u64 addr,
A subsequent change to KVM will make use of additional bits in invalid ptes. Prepare for said change by explicitly checking the valid bit and owner fields in stage2_pte_is_counted() Signed-off-by: Oliver Upton <oliver.upton@linux.dev> --- arch/arm64/kvm/hyp/pgtable.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)