Skip to content

Commit 944a1ed

Browse files
vdonnefortMarc Zyngier
authored andcommitted
KVM: arm64: Handle huge mappings for np-guest CMOs
clean_dcache_guest_page() and invalidate_icache_guest_page() accept a size as an argument. But they also rely on fixmap, which can only map a single PAGE_SIZE page. With the upcoming stage-2 huge mappings for pKVM np-guests, those callbacks will get size > PAGE_SIZE. Loop the CMOs on a PAGE_SIZE basis until the whole range is done. Signed-off-by: Vincent Donnefort <vdonnefort@google.com> Link: https://lore.kernel.org/r/20250521124834.1070650-2-vdonnefort@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent d5702dd commit 944a1ed

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

arch/arm64/kvm/hyp/nvhe/mem_protect.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,32 @@ static void guest_s2_put_page(void *addr)
219219

220220
static void clean_dcache_guest_page(void *va, size_t size)
221221
{
222-
__clean_dcache_guest_page(hyp_fixmap_map(__hyp_pa(va)), size);
223-
hyp_fixmap_unmap();
222+
size += va - PTR_ALIGN_DOWN(va, PAGE_SIZE);
223+
va = PTR_ALIGN_DOWN(va, PAGE_SIZE);
224+
size = PAGE_ALIGN(size);
225+
226+
while (size) {
227+
__clean_dcache_guest_page(hyp_fixmap_map(__hyp_pa(va)),
228+
PAGE_SIZE);
229+
hyp_fixmap_unmap();
230+
va += PAGE_SIZE;
231+
size -= PAGE_SIZE;
232+
}
224233
}
225234

226235
static void invalidate_icache_guest_page(void *va, size_t size)
227236
{
228-
__invalidate_icache_guest_page(hyp_fixmap_map(__hyp_pa(va)), size);
229-
hyp_fixmap_unmap();
237+
size += va - PTR_ALIGN_DOWN(va, PAGE_SIZE);
238+
va = PTR_ALIGN_DOWN(va, PAGE_SIZE);
239+
size = PAGE_ALIGN(size);
240+
241+
while (size) {
242+
__invalidate_icache_guest_page(hyp_fixmap_map(__hyp_pa(va)),
243+
PAGE_SIZE);
244+
hyp_fixmap_unmap();
245+
va += PAGE_SIZE;
246+
size -= PAGE_SIZE;
247+
}
230248
}
231249

232250
int kvm_guest_prepare_stage2(struct pkvm_hyp_vm *vm, void *pgd)

0 commit comments

Comments
 (0)