Skip to content

Commit 7cc1d21

Browse files
willdeaconMarc Zyngier
authored andcommitted
KVM: arm64: Avoid BBM when changing only s/w bits in Stage-2 PTE
Break-before-make (BBM) can be expensive, as transitioning via an invalid mapping (i.e. the "break" step) requires the completion of TLB invalidation and can also cause other agents to fault concurrently on the invalid mapping. Since BBM is not required when changing only the software bits of a PTE, avoid the sequence in this case and just update the PTE directly. Signed-off-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-9-tabba@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 96171cf commit 7cc1d21

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

arch/arm64/kvm/hyp/pgtable.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,21 @@ static int stage2_map_walker_try_leaf(const struct kvm_pgtable_visit_ctx *ctx,
972972
if (!stage2_pte_needs_update(ctx->old, new))
973973
return -EAGAIN;
974974

975+
/* If we're only changing software bits, then store them and go! */
976+
if (!kvm_pgtable_walk_shared(ctx) &&
977+
!((ctx->old ^ new) & ~KVM_PTE_LEAF_ATTR_HI_SW)) {
978+
bool old_is_counted = stage2_pte_is_counted(ctx->old);
979+
980+
if (old_is_counted != stage2_pte_is_counted(new)) {
981+
if (old_is_counted)
982+
mm_ops->put_page(ctx->ptep);
983+
else
984+
mm_ops->get_page(ctx->ptep);
985+
}
986+
WARN_ON_ONCE(!stage2_try_set_pte(ctx, new));
987+
return 0;
988+
}
989+
975990
if (!stage2_try_break_pte(ctx, data->mmu))
976991
return -EAGAIN;
977992

0 commit comments

Comments
 (0)