diff mbox series

[kvm-unit-tests,v2,10/16] x86: Add support for installing large pages

Message ID 20240718124932.114121-11-papaluri@amd.com (mailing list archive)
State New, archived
Headers show
Series Introduce SEV-SNP support | expand

Commit Message

Paluri, PavanKumar July 18, 2024, 12:49 p.m. UTC
Introduce install_large_pages() helper similar to install_pages(), that
is helpful while dealing with more than 1 2M large page mappings. This
helper is useful when running SEV-SNP VMGEXIT PSC tests that deal with
a bunch of 2M pages.

Signed-off-by: Pavan Kumar Paluri <papaluri@amd.com>
---
 lib/x86/vm.c | 14 ++++++++++++++
 lib/x86/vm.h |  1 +
 2 files changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/lib/x86/vm.c b/lib/x86/vm.c
index 078665b2faf4..cfca452bb110 100644
--- a/lib/x86/vm.c
+++ b/lib/x86/vm.c
@@ -128,6 +128,20 @@  void install_pages(pgd_t *cr3, phys_addr_t phys, size_t len, void *virt)
 	}
 }
 
+void install_large_pages(pgd_t *cr3, phys_addr_t phys, size_t len, void *virt)
+{
+	phys_addr_t max = (u64)len + (u64)phys;
+	assert(phys % LARGE_PAGE_SIZE == 0);
+	assert((uintptr_t)virt % LARGE_PAGE_SIZE == 0);
+	assert(len % LARGE_PAGE_SIZE == 0);
+
+	while (phys + LARGE_PAGE_SIZE <= max) {
+		install_large_page(cr3, phys, virt);
+		phys += LARGE_PAGE_SIZE;
+		virt = (char *)virt + LARGE_PAGE_SIZE;
+	}
+}
+
 bool any_present_pages(pgd_t *cr3, void *virt, size_t len)
 {
 	uintptr_t max = (uintptr_t) virt + len;
diff --git a/lib/x86/vm.h b/lib/x86/vm.h
index 9f72c267086d..0216ea1f37f9 100644
--- a/lib/x86/vm.h
+++ b/lib/x86/vm.h
@@ -41,6 +41,7 @@  pteval_t *install_pte(pgd_t *cr3,
 
 pteval_t *install_large_page(pgd_t *cr3, phys_addr_t phys, void *virt);
 void install_pages(pgd_t *cr3, phys_addr_t phys, size_t len, void *virt);
+void install_large_pages(pgd_t *cr3, phys_addr_t phys, size_t len, void *virt);
 bool any_present_pages(pgd_t *cr3, void *virt, size_t len);
 void set_pte_opt_mask(void);
 void reset_pte_opt_mask(void);