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@xxxxxxx> --- lib/x86/vm.c | 14 ++++++++++++++ lib/x86/vm.h | 1 + 2 files changed, 15 insertions(+) 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); -- 2.34.1