From 9059d7330a4ff02ee5f1d8bcbe6f18cae787c2c9 Mon Sep 17 00:00:00 2001 From: Mikhail Krichanov Date: Mon, 20 May 2024 11:34:40 +0300 Subject: [PATCH] Ring3: Defined CpuGetMemoryAttributes(), DisableSMAP(), EnableSMAP() for AARCH64. --- ArmPkg/Library/CpuArchLib/AArch64/Mmu.c | 6 +++++ ArmPkg/Library/CpuArchLib/CpuDxe.c | 1 + ArmPkg/Library/CpuArchLib/CpuDxe.h | 8 ++++++ ArmPkg/Library/CpuArchLib/CpuMmuCommon.c | 25 +++++++++++++++++++ .../Dxe/SysCall/AARCH64/CoreBootServices.S | 20 --------------- .../Core/Dxe/SysCall/AARCH64/InitializeMsr.c | 18 +++++++++++++ 6 files changed, 58 insertions(+), 20 deletions(-) diff --git a/ArmPkg/Library/CpuArchLib/AArch64/Mmu.c b/ArmPkg/Library/CpuArchLib/AArch64/Mmu.c index 922fdbbb14..c1f80aa612 100644 --- a/ArmPkg/Library/CpuArchLib/AArch64/Mmu.c +++ b/ArmPkg/Library/CpuArchLib/AArch64/Mmu.c @@ -95,6 +95,12 @@ PageAttributeToGcdAttribute ( GcdAttributes |= EFI_MEMORY_XP; } + if (((PageAttributes & TT_AP_MASK) == TT_AP_RW_RW) || + ((PageAttributes & TT_AP_MASK) == TT_AP_RO_RO)) + { + GcdAttributes |= EFI_MEMORY_USER; + } + return GcdAttributes; } diff --git a/ArmPkg/Library/CpuArchLib/CpuDxe.c b/ArmPkg/Library/CpuArchLib/CpuDxe.c index 4dd428d9c5..6dd313a069 100644 --- a/ArmPkg/Library/CpuArchLib/CpuDxe.c +++ b/ArmPkg/Library/CpuArchLib/CpuDxe.c @@ -278,6 +278,7 @@ STATIC EFI_CPU_ARCH_PROTOCOL mCpu = { CpuSetMemoryAttributes, 0, // NumberOfTimers 2048, // DmaBufferAlignment + CpuGetMemoryAttributes }; STATIC diff --git a/ArmPkg/Library/CpuArchLib/CpuDxe.h b/ArmPkg/Library/CpuArchLib/CpuDxe.h index a86de6800f..b80ba2d0d3 100644 --- a/ArmPkg/Library/CpuArchLib/CpuDxe.h +++ b/ArmPkg/Library/CpuArchLib/CpuDxe.h @@ -96,6 +96,14 @@ CpuSetMemoryAttributes ( IN UINT64 Attributes ); +EFI_STATUS +EFIAPI +CpuGetMemoryAttributes ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS Address, + OUT UINT64 *Attributes + ); + EFI_STATUS InitializeExceptions ( VOID diff --git a/ArmPkg/Library/CpuArchLib/CpuMmuCommon.c b/ArmPkg/Library/CpuArchLib/CpuMmuCommon.c index 489c0a17a4..97db7672e8 100644 --- a/ArmPkg/Library/CpuArchLib/CpuMmuCommon.c +++ b/ArmPkg/Library/CpuArchLib/CpuMmuCommon.c @@ -266,3 +266,28 @@ CpuSetMemoryAttributes ( return EFI_SUCCESS; } } + +EFI_STATUS +EFIAPI +CpuGetMemoryAttributes ( + IN EFI_CPU_ARCH_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS Address, + OUT UINT64 *Attributes + ) +{ + EFI_STATUS Status; + UINTN RegionBaseAddress; + UINTN RegionLength; + UINTN RegionArmAttributes; + + RegionBaseAddress = Address; + Status = GetMemoryRegion (&RegionBaseAddress, &RegionLength, &RegionArmAttributes); + + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + + *Attributes = RegionAttributeToGcdAttribute (RegionArmAttributes); + + return Status; +} diff --git a/MdeModulePkg/Core/Dxe/SysCall/AARCH64/CoreBootServices.S b/MdeModulePkg/Core/Dxe/SysCall/AARCH64/CoreBootServices.S index 1d26d79473..35e0c3f6c9 100644 --- a/MdeModulePkg/Core/Dxe/SysCall/AARCH64/CoreBootServices.S +++ b/MdeModulePkg/Core/Dxe/SysCall/AARCH64/CoreBootServices.S @@ -7,26 +7,6 @@ #include -//------------------------------------------------------------------------------ -// VOID -// EFIAPI -// DisableSMAP ( -// VOID -// ); -//------------------------------------------------------------------------------ -ASM_FUNC(DisableSMAP) - ret - -//------------------------------------------------------------------------------ -// VOID -// EFIAPI -// EnableSMAP ( -// VOID -// ); -//------------------------------------------------------------------------------ -ASM_FUNC(EnableSMAP) - ret - //------------------------------------------------------------------------------ // EFI_STATUS // EFIAPI diff --git a/MdeModulePkg/Core/Dxe/SysCall/AARCH64/InitializeMsr.c b/MdeModulePkg/Core/Dxe/SysCall/AARCH64/InitializeMsr.c index a6466e0cf2..470773a19a 100644 --- a/MdeModulePkg/Core/Dxe/SysCall/AARCH64/InitializeMsr.c +++ b/MdeModulePkg/Core/Dxe/SysCall/AARCH64/InitializeMsr.c @@ -41,3 +41,21 @@ InitializeMsr ( ASSERT (FALSE); } } + +VOID +EFIAPI +DisableSMAP ( + VOID + ) +{ + ArmClearPan (); +} + +VOID +EFIAPI +EnableSMAP ( + VOID + ) +{ + ArmSetPan (); +}