Skip to content

Commit 39bc95b

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: Infer PA offset from VA in hyp map walker
Similar to the recently fixed stage-2 walker, the hyp map walker increments the PA and VA of a walk separately. Unlike stage-2, there is no bug here as the map walker has exclusive access to the stage-1 page tables. Nonetheless, in the interest of continuity throughout the page table code, tweak the hyp map walker to avoid incrementing the PA and instead use the VA as the authoritative source of how far along a table walk has gotten. Calculate the PA to use for a leaf PTE by adding the offset of the VA from the start of the walk to the starting PA. Signed-off-by: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20230421071606.1603916-3-oliver.upton@linux.dev
1 parent 1f0f4a2 commit 39bc95b

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

arch/arm64/kvm/hyp/pgtable.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,12 @@ enum kvm_pgtable_prot kvm_pgtable_hyp_pte_prot(kvm_pte_t pte)
410410
static bool hyp_map_walker_try_leaf(const struct kvm_pgtable_visit_ctx *ctx,
411411
struct hyp_map_data *data)
412412
{
413+
u64 phys = data->phys + (ctx->addr - ctx->start);
413414
kvm_pte_t new;
414-
u64 granule = kvm_granule_size(ctx->level), phys = data->phys;
415415

416416
if (!kvm_block_mapping_supported(ctx, phys))
417417
return false;
418418

419-
data->phys += granule;
420419
new = kvm_init_valid_leaf_pte(phys, data->attr, ctx->level);
421420
if (ctx->old == new)
422421
return true;

0 commit comments

Comments
 (0)