Skip to content

Commit 4c36a15

Browse files
willdeaconoupton
authored andcommitted
KVM: arm64: Ensure target address is granule-aligned for range TLBI
When zapping a table entry in stage2_try_break_pte(), we issue range TLB invalidation for the region that was mapped by the table. However, we neglect to align the base address down to the granule size and so if we ended up reaching the table entry via a misaligned address then we will accidentally skip invalidation for some prefix of the affected address range. Align 'ctx->addr' down to the granule size when performing TLB invalidation for an unmapped table in stage2_try_break_pte(). Cc: Raghavendra Rao Ananta <[email protected]> Cc: Gavin Shan <[email protected]> Cc: Shaoqin Huang <[email protected]> Cc: Quentin Perret <[email protected]> Fixes: defc8cc ("KVM: arm64: Invalidate the table entries upon a range") Signed-off-by: Will Deacon <[email protected]> Reviewed-by: Shaoqin Huang <[email protected]> Reviewed-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 0f0ff09 commit 4c36a15

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

arch/arm64/kvm/hyp/pgtable.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -843,12 +843,15 @@ static bool stage2_try_break_pte(const struct kvm_pgtable_visit_ctx *ctx,
843843
* Perform the appropriate TLB invalidation based on the
844844
* evicted pte value (if any).
845845
*/
846-
if (kvm_pte_table(ctx->old, ctx->level))
847-
kvm_tlb_flush_vmid_range(mmu, ctx->addr,
848-
kvm_granule_size(ctx->level));
849-
else if (kvm_pte_valid(ctx->old))
846+
if (kvm_pte_table(ctx->old, ctx->level)) {
847+
u64 size = kvm_granule_size(ctx->level);
848+
u64 addr = ALIGN_DOWN(ctx->addr, size);
849+
850+
kvm_tlb_flush_vmid_range(mmu, addr, size);
851+
} else if (kvm_pte_valid(ctx->old)) {
850852
kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, mmu,
851853
ctx->addr, ctx->level);
854+
}
852855
}
853856

854857
if (stage2_pte_is_counted(ctx->old))

0 commit comments

Comments
 (0)