Skip to content

Commit 96171cf

Browse files
author
Marc Zyngier
committed
KVM: arm64: Check for PTE validity when checking for executable/cacheable
Don't just assume that the PTE is valid when checking whether it describes an executable or cacheable mapping. This makes sure that we don't issue CMOs for invalid mappings. Suggested-by: Will Deacon <will@kernel.org> Signed-off-by: Fuad Tabba <tabba@google.com> Acked-by: Oliver Upton <oliver.upton@linux.dev> Link: https://lore.kernel.org/r/20240423150538.2103045-8-tabba@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 02949f3 commit 96171cf

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

arch/arm64/kvm/hyp/pgtable.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -907,12 +907,12 @@ static void stage2_unmap_put_pte(const struct kvm_pgtable_visit_ctx *ctx,
907907
static bool stage2_pte_cacheable(struct kvm_pgtable *pgt, kvm_pte_t pte)
908908
{
909909
u64 memattr = pte & KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR;
910-
return memattr == KVM_S2_MEMATTR(pgt, NORMAL);
910+
return kvm_pte_valid(pte) && memattr == KVM_S2_MEMATTR(pgt, NORMAL);
911911
}
912912

913913
static bool stage2_pte_executable(kvm_pte_t pte)
914914
{
915-
return !(pte & KVM_PTE_LEAF_ATTR_HI_S2_XN);
915+
return kvm_pte_valid(pte) && !(pte & KVM_PTE_LEAF_ATTR_HI_S2_XN);
916916
}
917917

918918
static u64 stage2_map_walker_phys_addr(const struct kvm_pgtable_visit_ctx *ctx,
@@ -1363,7 +1363,7 @@ static int stage2_flush_walker(const struct kvm_pgtable_visit_ctx *ctx,
13631363
struct kvm_pgtable *pgt = ctx->arg;
13641364
struct kvm_pgtable_mm_ops *mm_ops = pgt->mm_ops;
13651365

1366-
if (!kvm_pte_valid(ctx->old) || !stage2_pte_cacheable(pgt, ctx->old))
1366+
if (!stage2_pte_cacheable(pgt, ctx->old))
13671367
return 0;
13681368

13691369
if (mm_ops->dcache_clean_inval_poc)

0 commit comments

Comments
 (0)