Skip to content

Commit 946fbfd

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: Make leaf->leaf PTE changes parallel-aware
Convert stage2_map_walker_try_leaf() to use the new break-before-make helpers, thereby making the handler parallel-aware. As before, avoid the break-before-make if recreating the existing mapping. Additionally, retry execution if another vCPU thread is modifying the same PTE. Signed-off-by: Oliver Upton <[email protected]> Reviewed-by: Ben Gardon <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0ab12f3 commit 946fbfd

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

arch/arm64/kvm/hyp/pgtable.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -804,18 +804,17 @@ static int stage2_map_walker_try_leaf(const struct kvm_pgtable_visit_ctx *ctx,
804804
else
805805
new = kvm_init_invalid_leaf_owner(data->owner_id);
806806

807-
if (stage2_pte_is_counted(ctx->old)) {
808-
/*
809-
* Skip updating the PTE if we are trying to recreate the exact
810-
* same mapping or only change the access permissions. Instead,
811-
* the vCPU will exit one more time from guest if still needed
812-
* and then go through the path of relaxing permissions.
813-
*/
814-
if (!stage2_pte_needs_update(ctx->old, new))
815-
return -EAGAIN;
807+
/*
808+
* Skip updating the PTE if we are trying to recreate the exact
809+
* same mapping or only change the access permissions. Instead,
810+
* the vCPU will exit one more time from guest if still needed
811+
* and then go through the path of relaxing permissions.
812+
*/
813+
if (!stage2_pte_needs_update(ctx->old, new))
814+
return -EAGAIN;
816815

817-
stage2_put_pte(ctx, data->mmu, mm_ops);
818-
}
816+
if (!stage2_try_break_pte(ctx, data->mmu))
817+
return -EAGAIN;
819818

820819
/* Perform CMOs before installation of the guest stage-2 PTE */
821820
if (mm_ops->dcache_clean_inval_poc && stage2_pte_cacheable(pgt, new))
@@ -825,9 +824,8 @@ static int stage2_map_walker_try_leaf(const struct kvm_pgtable_visit_ctx *ctx,
825824
if (mm_ops->icache_inval_pou && stage2_pte_executable(new))
826825
mm_ops->icache_inval_pou(kvm_pte_follow(new, mm_ops), granule);
827826

828-
smp_store_release(ctx->ptep, new);
829-
if (stage2_pte_is_counted(new))
830-
mm_ops->get_page(ctx->ptep);
827+
stage2_make_pte(ctx, new);
828+
831829
if (kvm_phys_is_valid(phys))
832830
data->phys += granule;
833831
return 0;

0 commit comments

Comments
 (0)