Currently, the DXE IPL relies on permanent memory being available, but does not DEPEX on the associated PPI. Instead, it registers for PEIM shadowing, and only proceeds when running shadowed, and this implies that permanent memory has been installed.
While PEIM shadowing is typically good for performance, there are reasons why we might prefer to avoid it, e.g., when running under virtualization in a mode where the write protection of the ROM is an advantage from a safety PoV, and where the performance is identical. This is especially true when code executing from ordinary RAM needs some additional work to be executable, like when enabling WXN on ARM, which only permits execution from memory that is mapped read-only. So permit DXE IPL to run unshadowed, based on the existing PCD that decides whether or not shadowing is preferred. While making this behavior depend on this PCD is strictly redundant (as the IPL PEIM will be shadowed anyway, even if RegisterForShadow() is not called), let's test it anyway to avoid modifying the behavior on existing platforms. Signed-off-by: Ard Biesheuvel <a...@kernel.org> --- MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 5 +++- MdeModulePkg/Core/DxeIplPeim/DxeLoad.c | 24 +++++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf index 052ea0ec1a6f..62821477d012 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf @@ -112,6 +112,9 @@ [FeaturePcd.X64] [FeaturePcd] gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSupportUefiDecompress ## CONSUMES +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnBoot ## CONSUMES + [Pcd.IA32,Pcd.X64] gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ## CONSUMES @@ -128,7 +131,7 @@ [Pcd.IA32,Pcd.X64,Pcd.ARM,Pcd.AARCH64] gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIMES_CONSUMES [Depex] - gEfiPeiLoadFilePpiGuid AND gEfiPeiMasterBootModePpiGuid + gEfiPeiLoadFilePpiGuid AND gEfiPeiMasterBootModePpiGuid AND gEfiPeiMemoryDiscoveredPpiGuid # # [BootMode] diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c b/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c index 2c19f1a507ba..228d39a618d3 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c +++ b/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c @@ -77,18 +77,20 @@ PeimInitializeDxeIpl ( BootMode = GetBootModeHob (); if (BootMode != BOOT_ON_S3_RESUME) { - Status = PeiServicesRegisterForShadow (FileHandle); - if (Status == EFI_SUCCESS) { - // - // EFI_SUCESS means it is the first time to call register for shadow. - // - return Status; - } + if (PcdGetBool (PcdShadowPeimOnBoot)) { + Status = PeiServicesRegisterForShadow (FileHandle); + if (Status == EFI_SUCCESS) { + // + // EFI_SUCESS means it is the first time to call register for shadow. + // + return Status; + } - // - // Ensure that DXE IPL is shadowed to permanent memory. - // - ASSERT (Status == EFI_ALREADY_STARTED); + // + // Ensure that DXE IPL is shadowed to permanent memory. + // + ASSERT (Status == EFI_ALREADY_STARTED); + } // // DXE core load requires permanent memory. -- 2.39.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#100091): https://edk2.groups.io/g/devel/message/100091 Mute This Topic: https://groups.io/mt/96937478/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-