Commit 944a1ed8 authored by Vincent Donnefort's avatar Vincent Donnefort Committed by Marc Zyngier
Browse files

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: default avatarVincent Donnefort <vdonnefort@google.com>
Link: https://lore.kernel.org/r/20250521124834.1070650-2-vdonnefort@google.com


Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
parent d5702dd2
Loading
Loading
Loading
Loading
+22 −4
Original line number Diff line number Diff line
@@ -219,14 +219,32 @@ static void guest_s2_put_page(void *addr)

static void clean_dcache_guest_page(void *va, size_t size)
{
	__clean_dcache_guest_page(hyp_fixmap_map(__hyp_pa(va)), size);
	size += va - PTR_ALIGN_DOWN(va, PAGE_SIZE);
	va = PTR_ALIGN_DOWN(va, PAGE_SIZE);
	size = PAGE_ALIGN(size);

	while (size) {
		__clean_dcache_guest_page(hyp_fixmap_map(__hyp_pa(va)),
					  PAGE_SIZE);
		hyp_fixmap_unmap();
		va += PAGE_SIZE;
		size -= PAGE_SIZE;
	}
}

static void invalidate_icache_guest_page(void *va, size_t size)
{
	__invalidate_icache_guest_page(hyp_fixmap_map(__hyp_pa(va)), size);
	size += va - PTR_ALIGN_DOWN(va, PAGE_SIZE);
	va = PTR_ALIGN_DOWN(va, PAGE_SIZE);
	size = PAGE_ALIGN(size);

	while (size) {
		__invalidate_icache_guest_page(hyp_fixmap_map(__hyp_pa(va)),
					       PAGE_SIZE);
		hyp_fixmap_unmap();
		va += PAGE_SIZE;
		size -= PAGE_SIZE;
	}
}

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