Skip to content

Commit e279c25

Browse files
Quentin PerretMarc Zyngier
authored andcommitted
KVM: arm64: Pass walk flags to kvm_pgtable_stage2_relax_perms
kvm_pgtable_stage2_relax_perms currently assumes that it is being called from a 'shared' walker, which will not be true once called from pKVM. To allow for the re-use of that function, make the walk flags one of its parameters. Tested-by: Fuad Tabba <[email protected]> Reviewed-by: Fuad Tabba <[email protected]> Signed-off-by: Quentin Perret <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 5398ddc commit e279c25

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

arch/arm64/include/asm/kvm_pgtable.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ bool kvm_pgtable_stage2_test_clear_young(struct kvm_pgtable *pgt, u64 addr,
707707
* @pgt: Page-table structure initialised by kvm_pgtable_stage2_init*().
708708
* @addr: Intermediate physical address to identify the page-table entry.
709709
* @prot: Additional permissions to grant for the mapping.
710+
* @flags: Flags to control the page-table walk (ex. a shared walk)
710711
*
711712
* The offset of @addr within a page is ignored.
712713
*
@@ -719,7 +720,8 @@ bool kvm_pgtable_stage2_test_clear_young(struct kvm_pgtable *pgt, u64 addr,
719720
* Return: 0 on success, negative error code on failure.
720721
*/
721722
int kvm_pgtable_stage2_relax_perms(struct kvm_pgtable *pgt, u64 addr,
722-
enum kvm_pgtable_prot prot);
723+
enum kvm_pgtable_prot prot,
724+
enum kvm_pgtable_walk_flags flags);
723725

724726
/**
725727
* kvm_pgtable_stage2_flush_range() - Clean and invalidate data cache to Point

arch/arm64/kvm/hyp/pgtable.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ bool kvm_pgtable_stage2_test_clear_young(struct kvm_pgtable *pgt, u64 addr,
13071307
}
13081308

13091309
int kvm_pgtable_stage2_relax_perms(struct kvm_pgtable *pgt, u64 addr,
1310-
enum kvm_pgtable_prot prot)
1310+
enum kvm_pgtable_prot prot, enum kvm_pgtable_walk_flags flags)
13111311
{
13121312
int ret;
13131313
s8 level;
@@ -1325,9 +1325,7 @@ int kvm_pgtable_stage2_relax_perms(struct kvm_pgtable *pgt, u64 addr,
13251325
if (prot & KVM_PGTABLE_PROT_X)
13261326
clr |= KVM_PTE_LEAF_ATTR_HI_S2_XN;
13271327

1328-
ret = stage2_update_leaf_attrs(pgt, addr, 1, set, clr, NULL, &level,
1329-
KVM_PGTABLE_WALK_HANDLE_FAULT |
1330-
KVM_PGTABLE_WALK_SHARED);
1328+
ret = stage2_update_leaf_attrs(pgt, addr, 1, set, clr, NULL, &level, flags);
13311329
if (!ret || ret == -EAGAIN)
13321330
kvm_call_hyp(__kvm_tlb_flush_vmid_ipa_nsh, pgt->mmu, addr, level);
13331331
return ret;

arch/arm64/kvm/mmu.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
14521452
enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R;
14531453
struct kvm_pgtable *pgt;
14541454
struct page *page;
1455+
enum kvm_pgtable_walk_flags flags = KVM_PGTABLE_WALK_HANDLE_FAULT | KVM_PGTABLE_WALK_SHARED;
14551456

14561457
if (fault_is_perm)
14571458
fault_granule = kvm_vcpu_trap_get_perm_fault_granule(vcpu);
@@ -1695,13 +1696,11 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
16951696
* PTE, which will be preserved.
16961697
*/
16971698
prot &= ~KVM_NV_GUEST_MAP_SZ;
1698-
ret = kvm_pgtable_stage2_relax_perms(pgt, fault_ipa, prot);
1699+
ret = kvm_pgtable_stage2_relax_perms(pgt, fault_ipa, prot, flags);
16991700
} else {
17001701
ret = kvm_pgtable_stage2_map(pgt, fault_ipa, vma_pagesize,
17011702
__pfn_to_phys(pfn), prot,
1702-
memcache,
1703-
KVM_PGTABLE_WALK_HANDLE_FAULT |
1704-
KVM_PGTABLE_WALK_SHARED);
1703+
memcache, flags);
17051704
}
17061705

17071706
out_unlock:

0 commit comments

Comments
 (0)