Skip to content

Commit 378e6a9

Browse files
YananWang-hubMarc Zyngier
authored andcommitted
KVM: arm64: Tweak parameters of guest cache maintenance functions
Adjust the parameter "kvm_pfn_t pfn" of __clean_dcache_guest_page and __invalidate_icache_guest_page to "void *va", which paves the way for converting these two guest CMO functions into callbacks in structure kvm_pgtable_mm_ops. No functional change. Reviewed-by: Fuad Tabba <tabba@google.com> Signed-off-by: Yanan Wang <wangyanan55@huawei.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20210617105824.31752-4-wangyanan55@huawei.com
1 parent a4d5ca5 commit 378e6a9

2 files changed

Lines changed: 17 additions & 20 deletions

File tree

arch/arm64/include/asm/kvm_mmu.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,8 @@ static inline bool vcpu_has_cache_enabled(struct kvm_vcpu *vcpu)
187187
return (vcpu_read_sys_reg(vcpu, SCTLR_EL1) & 0b101) == 0b101;
188188
}
189189

190-
static inline void __clean_dcache_guest_page(kvm_pfn_t pfn, unsigned long size)
190+
static inline void __clean_dcache_guest_page(void *va, size_t size)
191191
{
192-
void *va = page_address(pfn_to_page(pfn));
193-
194192
/*
195193
* With FWB, we ensure that the guest always accesses memory using
196194
* cacheable attributes, and we don't have to clean to PoC when
@@ -203,16 +201,13 @@ static inline void __clean_dcache_guest_page(kvm_pfn_t pfn, unsigned long size)
203201
kvm_flush_dcache_to_poc(va, size);
204202
}
205203

206-
static inline void __invalidate_icache_guest_page(kvm_pfn_t pfn,
207-
unsigned long size)
204+
static inline void __invalidate_icache_guest_page(void *va, size_t size)
208205
{
209206
if (icache_is_aliasing()) {
210207
/* any kind of VIPT cache */
211208
__flush_icache_all();
212209
} else if (is_kernel_in_hyp_mode() || !icache_is_vpipt()) {
213210
/* PIPT or VPIPT at EL2 (see comment in __kvm_tlb_flush_vmid_ipa) */
214-
void *va = page_address(pfn_to_page(pfn));
215-
216211
invalidate_icache_range((unsigned long)va,
217212
(unsigned long)va + size);
218213
}

arch/arm64/kvm/mmu.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ static void *kvm_host_va(phys_addr_t phys)
126126
return __va(phys);
127127
}
128128

129+
static void clean_dcache_guest_page(void *va, size_t size)
130+
{
131+
__clean_dcache_guest_page(va, size);
132+
}
133+
134+
static void invalidate_icache_guest_page(void *va, size_t size)
135+
{
136+
__invalidate_icache_guest_page(va, size);
137+
}
138+
129139
/*
130140
* Unmapping vs dcache management:
131141
*
@@ -693,16 +703,6 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm,
693703
kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, mask);
694704
}
695705

696-
static void clean_dcache_guest_page(kvm_pfn_t pfn, unsigned long size)
697-
{
698-
__clean_dcache_guest_page(pfn, size);
699-
}
700-
701-
static void invalidate_icache_guest_page(kvm_pfn_t pfn, unsigned long size)
702-
{
703-
__invalidate_icache_guest_page(pfn, size);
704-
}
705-
706706
static void kvm_send_hwpoison_signal(unsigned long address, short lsb)
707707
{
708708
send_sig_mceerr(BUS_MCEERR_AR, (void __user *)address, lsb, current);
@@ -972,11 +972,13 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
972972
prot |= KVM_PGTABLE_PROT_W;
973973

974974
if (fault_status != FSC_PERM && !device)
975-
clean_dcache_guest_page(pfn, vma_pagesize);
975+
clean_dcache_guest_page(page_address(pfn_to_page(pfn)),
976+
vma_pagesize);
976977

977978
if (exec_fault) {
978979
prot |= KVM_PGTABLE_PROT_X;
979-
invalidate_icache_guest_page(pfn, vma_pagesize);
980+
invalidate_icache_guest_page(page_address(pfn_to_page(pfn)),
981+
vma_pagesize);
980982
}
981983

982984
if (device)
@@ -1178,7 +1180,7 @@ bool kvm_set_spte_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
11781180
* We've moved a page around, probably through CoW, so let's treat it
11791181
* just like a translation fault and clean the cache to the PoC.
11801182
*/
1181-
clean_dcache_guest_page(pfn, PAGE_SIZE);
1183+
clean_dcache_guest_page(page_address(pfn_to_page(pfn)), PAGE_SIZE);
11821184

11831185
/*
11841186
* The MMU notifiers will have unmapped a huge PMD before calling

0 commit comments

Comments
 (0)