From 92e002641e0e16d39c28fc3e83567222c20f4b85 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 12 Mar 2025 12:20:27 -0400 Subject: [PATCH] kernel/x86_64: Clear the lower half of the kernel PML4 in LA57 mode. It also has an identity mapping that needs to be removed, same as the PML5. --- .../x86/paging/64bit/X86PagingMethod64Bit.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/system/kernel/arch/x86/paging/64bit/X86PagingMethod64Bit.cpp b/src/system/kernel/arch/x86/paging/64bit/X86PagingMethod64Bit.cpp index 81127174a3..2353941716 100644 --- a/src/system/kernel/arch/x86/paging/64bit/X86PagingMethod64Bit.cpp +++ b/src/system/kernel/arch/x86/paging/64bit/X86PagingMethod64Bit.cpp @@ -67,15 +67,20 @@ X86PagingMethod64Bit::Init(kernel_args* args, if (x86_check_feature(IA32_FEATURE_AMD_EXT_NX, FEATURE_EXT_AMD)) call_all_cpus_sync(&_EnableExecutionDisable, NULL); - // Ensure that the user half of the address space is clear. This removes - // the temporary identity mapping made by the boot loader. - memset(fKernelVirtualPMLTop, 0, sizeof(uint64) * 256); - arch_cpu_global_TLB_invalidate(); - // Create the physical page mapper. mapped_physical_page_ops_init(args, fPhysicalPageMapper, fKernelPhysicalPageMapper); + // Ensure that the user half of the address space is clear. This removes + // the temporary identity mapping made by the boot loader. + if (la57) { + uint64* virtualPML4 = (uint64*)fKernelPhysicalPageMapper->GetPageTableAt( + *fKernelVirtualPMLTop & X86_64_PML5E_ADDRESS_MASK); + memset(virtualPML4, 0, sizeof(uint64) * 256); + } + memset(fKernelVirtualPMLTop, 0, sizeof(uint64) * 256); + arch_cpu_global_TLB_invalidate(); + *_physicalPageMapper = fPhysicalPageMapper; return B_ERROR; }