summaryrefslogtreecommitdiffstats
path: root/StandaloneMmPkg/Core
Commit message (Collapse)AuthorAgeFilesLines
* StandaloneMmPkg: Introduce a PCD to disable shadow boot FVLevi Yun2025-01-202-10/+33
| | | | | | | | | | | | | | | | On some Arm platforms the boot firmware volume passed in the HOB by the secure world firmware (TF-A) is never freed and is always mapped as read-only. On such platforms the heap memory can be saved by disabling the shadow copy of the boot firmware volume. This is useful as on some platforms the amount of memory available is limited. Therefore, introduce a PCD PcdShadowBfv that platforms can configure to disable the shadow boot FV. This PCD is set to TRUE by default. Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
* StandaloneMmCore: Change log level when mCommunicationBuffer is NULLLevi Yun2025-01-171-1/+1
| | | | | | | | | | | | | | | | | | On Arm all requests are handled as Asynchronous events by the Root MMI handler. Since the communication data is conveyed using either the NS shared buffer or the Secure shared buffer, the Arm implementation does not setup the mCommunicationBuffer. Therefore, the mCommunicationBuffer being NULL is not an error case. Moreover, the existing code switches to Asynchronous event processing when the mCommunicationBuffer is NULL, which means that the log is an info log rather than an error. Therefore, change the log level from ERROR to INFO when the mCommunicationBuffer is NULL. Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
* StandaloneMmPkg: Call PeCoffLoaderUnloadImage When Unloading ImageOliver Smith-Denny2025-01-091-29/+42
| | | | | | | | | | | | | | | | | | | | | | | | Today, StandaloneMmCore calls PeCoffLoaderRelocateImage() when loading images, which calls PeCoffLoaderRelocateImageExtraAction(). On AARCH64, this sets the image memory protections accordingly, RO + E on code sections, RW + NX on data sections. However, if an image fails to start (i.e. its entry point returns a failure) StandaloneMmCore does not call the corresponding PeCoffLoaderUnloadImage, which calls PeCoffLoaderUnloadImageExtraAction, which on AARCH64 undoes the memory protections on the image, setting the whole memory region back to RW + NX. The core then frees this memory and the next allocation attempts to use it, which results in a data abort if a read only memory region is attempted to be written to. Theoretically, other instances of the PeCoffExtraActionLib could take other actions and so regardless of architecture, the contract with the PeCoffLoader should be maintained. This patch calls PeCoffLoaderUnloadImage when an image's entry point returns a failure, before freeing the image memory. This meets the contract and follows the DXE core behavior. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
* StandaloneMmPkg: Assert if dispatcher fails memory allocationGirish Mahadevan2025-01-091-0/+1
| | | | | | | | | If the Dispatcher fails to allocate memory for the driver that it is trying to load then ASSERT, else the Dispatcher silently stops loading subsequent drivers from the FV. Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com> Reviewed-by: Jeff Brasen <jbrasen@nvidia.com>
* StandaloneMmPkg/Core: Support to dispatch multiple standalone MM FVsWei6 Xu2024-12-204-39/+134
| | | | | | | Add support to dispatch multiple standalone MM FVs for StandaloneMmCore. Set the maximum supported FV count to 2. Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg/Core: Check Resource HOB and Mmram rangesDun Tan2024-11-051-4/+36
| | | | | | | | | Check if the all the resource HOB in the input HOB list of MmCore entry only covers non-Mmram ranges. The Resource HOB is to describe the accessible non-Mmram range. All Resource HOB should not overlap with any Mmram range. Signed-off-by: Dun Tan <dun.tan@intel.com>
* StandaloneMmPkg/Core: add a new InitializeMmHobList()Dun Tan2024-11-051-20/+27
| | | | | | | | Separate a function called InitializeMmHobList() to gather all the operations related to initializing HOB. It doesn't change any code logic. Signed-off-by: Dun Tan <dun.tan@intel.com>
* StandaloneMmPkg/Core: Remove unneeded checkDun Tan2024-11-051-7/+1
| | | | | | | | | | | | | | | | | | | | Remove unneeded check MmIsBufferOutsideMmValid() when StandaloneMmCore checks if the BS data memory described by a memory allocation HOB needs to be migrated to Mmram. Currently, the API MmIsBufferOutsideMmValid() return TRUE when input memory range belongs to non-Mmram memory. Now the API will be changed in following 5 commits to return TRUE when a memory range belongs to non-Mmram memroy and the memory is inside a range described by resource HOB. This may cause PF when some SMI handler access the memory from a memory allocation HOB that is not migrated. To solve this issue, we can directly remove the check MmIsBufferOutsideMmValid() and always migrate the BS data memory described by a memory allocation HOB to Mmram. Signed-off-by: Dun Tan <dun.tan@intel.com>
* StandaloneMmPkg/Core: Shadow Standalone BFV into MMRAMWei6 Xu2024-10-303-9/+28
| | | | | | | | | | | | | | | | BFV is outside the MMRAM. Currently, StandaloneMmIplPei uses the API MmUnblockMemoryRequest() to unblock the access for the BFV. However, the BFV's memory might be gone after ExitBootService event. If any access to the memory, unexpected error would happen. To fix the above issue, StandaloneMmCore should shadow standalone BFV into MMRAM before processing it, then free the shadowed BFV after MM driver dispatch is done. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg/Core: Reset IsCommBufferValid to FALSE before MMI exitsWei6 Xu2024-10-291-4/+5
| | | | | | | | | | | | | | | | | | | In current implementation of MmCommunication, caller (StandaloneMmIplPei or MmCommunicationDxe) sets the IsCommBufferValid to TRUE and triggers synchronous MMI, then caller resets IsCommBufferValid to FLASE after MMI exits. If asynchronous MMI happens before caller resets the IsCommBufferValid to FALSE, StandaloneMmCore will mistakenly thought there is still a synchronous MMI and then update incorrect values into ReturnStatus and ReturnBufferSize. To fix the above issue, StandaloneMmCore should reset IsCommBufferValid to FALSE before MMI exits. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg: CodeQL Fixes.Michael Kubacki2024-10-031-1/+4
| | | | | | | | | | | Makes changes to comply with alerts raised by CodeQL. Most of the issues here fall into the following two categories: 1. Potential use of uninitialized pointer 2. Inconsistent integer width used in loop comparison Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
* StandaloneMmPkg/Core: Migrate Memory Allocation Hob into MMRAMWei6 Xu2024-08-281-0/+61
| | | | | | | | | | | | If a Memory Allocation Hob with EfiBootServicesData memory type is reported into MM Hob List and it also has a non-zero GUID name, then the HOB is used by MM driver and needs to migrate the memory into MMRAM. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg/Core: Add MemoryAttributes supportWei6 Xu2024-08-286-24/+1235
| | | | | | | | | | | | | | | | | | | | | | | The MM memory attribute table is ported from SMM Core. The new file StandaloneMmPkg/Core/MemoryAttributesTable.c, the new code in StandaloneMmPkg/Core/Page.c and StandaloneMmPkg/Core/Pool.c are almost identical to MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c, MdeModulePkg/Core/PiSmmCore/Page.c and MdeModulePkg/Core/PiSmmCore/Pool.c, but changing the word 'SMM' to 'MM'. Different from SMM Core, Standalone MM Core produces MM MemoryAttributes table at the end of MmDriverDispatchHandler() when all the drivers are dispatched, rather than at the MmEndOfDxe event. Then the MM CPU driver will consumes the table to set memory attribute in page table. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg/Core: Install protocol to notify MmEndOfPei eventWei6 Xu2024-08-283-0/+65
| | | | | | | | | | | When the EndOfPei event is signaled, installs the MM EndOfPei Protocol so MM Drivers are informed that EndOfPei event is signaled. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg: Support using gEfiSmmSmramMemoryGuid to get MMRAM rangeWei6 Xu2024-08-282-2/+6
| | | | | | | | | | | | Add the support using gEfiSmmSmramMemoryGuid to get MMRAM ranges. If gEfiSmmSmramMemoryGuid HOB is not found, then try to get MMRAM ranges from gEfiMmPeiMmramMemoryReserveGuid HOB. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg/Core: Restart dispatcher once MmEntryPoint is registeredWei6 Xu2024-08-284-1/+75
| | | | | | | | | | | | | | | | | | | Defer the dispatch of the remaining MM drivers once the CPU driver has been dispatched. In MmDispatcher, return immediately if the MM Entry Point was registered. Then the MM IPL will reinvoke the MM Core Dispatcher. This is required so MM Mode may be enabled as soon as all the dependent MM Drivers for MM Mode have been dispatched. Introduce a FeatureFlag PCD to control if MmDispatcher returns or not when MmEntryPointPoint is registered. Default value is FALSE. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg/Core: Remove unused mMmramRanges and mMmramRangeCountWei6 Xu2024-08-281-15/+3
| | | | | | | | | | | | mMmramRanges and mMmramRangeCount are the global variables that are used to cache the MMRAM Ranges info, but they are not used in MM Core. Therefore, remove mMmramRanges and mMmramRangeCount. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg/Core: Drop MM_CORE_PRIVATE_DATAWei6 Xu2024-08-284-97/+30
| | | | | | | | | | | MM_CORE_PRIVATE_DATA is not used as shared structures between MM IPL and MM Core, therefore clean up the code related to gMmCorePrivate. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg/Core: Introduce MM Communication BufferWei6 Xu2024-08-283-24/+120
| | | | | | | | | | | | | | | | Get the MM Communication context from the MM Communication Buffer, instead of the pointer inside gMmCorePrivate. In the MmEntryPoint, check IsCommBufferValid from MM_COMM_BUFFER to decide whether the MMI is Synchronous MMI or Asynchronous MMI. If it is a Synchronous MMI, MM Core shadows the communication buffer into a internal copy, then invokes the MMI handlers, lastly copies data back to the MM Communication Buffer and set the return status. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg/Core: Switch to MM HobList after MM HostList is readyWei6 Xu2024-08-281-0/+1
| | | | | | | | | | | Switch to MM HobList as soon as MM HostList is initialized to avoid StandaloneMmCore still using the HobList which is outside of MMRAM. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg/Core: Install Loaded Image Protocol for MM CoreWei6 Xu2024-08-281-0/+85
| | | | | | | | | | | | Retrieves the MM Core image info from Memory Allocation HOB reported by MM IPL. Then install Loaded Image Protocol for MM Core with the image info from HOB. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg/Core: Install Loaded Image Protocol for MM driversWei6 Xu2024-08-282-1/+33
| | | | | | | | | | | | | | Install Loaded Image Protocol into MM handle database for each MM driver. Change EFI_MM_DRIVER_ENTRY structure definition to hold the Loaded Image Protocol data directly, instead a pointer to the protocol, to avoid allocating pool for each MM driver. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg/Core: Remove traditional MM driver supportWei6 Xu2024-08-285-88/+14
| | | | | | | | | | | | StandaloneMmCore should not support dispatching traditional MM driver which has dependency on UEFI services. Therefore, remove the related code that supports traditional MM driver. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg/Core: Dump all HOB info in entrypointWei6 Xu2024-07-073-1/+6
| | | | | | | | | | Print HOB information at top of StandaloneMmMain(). Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
* StandaloneMmPkg: Initialize 'WillReturn' variableZhiguang Liu2024-05-301-0/+1
| | | | | | | | | The local variable 'WillReturn' was being used without prior initialization in some code paths. This patch ensures that 'WillReturn' is properly initialized to prevent undefined behavior. Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
* StandaloneMmPkg: Support to unregister MMI handler in MMI handlersZhiguang Liu2024-04-161-25/+136
| | | | | | | | | | | | | | | | | | | | | This patch fix a use-after-free issue where unregistering an MMI handler could lead to the deletion of the MMI_HANDLER while it is still in use by MmiManage(). The fix involves modifying MmiHandlerUnRegister() to detect whether it is being called from within the MmiManage() stack. If so, the removal of the MMI_HANDLER is deferred until MmiManage() has finished executing. Additionally, due to the possibility of recursive MmiManage() calls, the unregistration and subsequent removal of the MMI_HANDLER are ensured to occur only after the outermost MmiManage() invocation has completed. Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
* Revert 049ff6c39c73edd3709c05bd0e46184320471358Zhiguang Liu2024-04-161-7/+2
| | | | | | | | | | | | | | | This reverts commit "StandaloneMmPkg: Support to unregister MMI handler inside MMI handler" for better design later. Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
* Revert 2ec8f0c6407f062441b205b900038933865c7b3cZhiguang Liu2024-04-161-23/+9
| | | | | | | | | | | | | | | This reverts commit "StandaloneMmPkg: Disallow unregister MMI handler in other MMI handler" for better design later. Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
* StandaloneMmPkg: Disallow unregister MMI handler in other MMI handlerZhiguang Liu2024-03-011-9/+23
| | | | | | | | | | | | | | | | | | | In last patch, we add code support to unregister MMI handler inside itself. However, the code doesn't support unregister MMI handler insider other MMI handler. While this is not a must-have usage. So add check to disallow unregister MMI handler in other MMI handler. Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com> Message-Id: <20240301030133.628-5-zhiguang.liu@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* StandaloneMmPkg: Support to unregister MMI handler inside MMI handlerZhiguang Liu2024-03-011-2/+7
| | | | | | | | | | | | | | | | To support unregister MMI handler inside MMI handler itself, get next node before MMI handler is executed, since LIST_ENTRY that Link points to may be freed if unregister MMI handler in MMI handler itself. Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com> Message-Id: <20240301030133.628-4-zhiguang.liu@intel.com>
* StandaloneMmPkg/Core: Output status in MMI handler assertionMichael Kubacki2024-02-031-1/+1
| | | | | | | | | | Currently, if a MMI handler returns an unexpected failure status code, ASSERT (FALSE) is used. It is more useful to use ASSERT_EFI_ERROR() which also outputs the status code value. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Ray Ni <ray.ni@intel.com>
* StandaloneMmPkg/Core: Remove optimization for depex evaluationLaszlo Ersek2024-01-231-30/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current dependency evaluator violates the memory access permission when patching depex grammar directly in the read-only depex memory area. Laszlo pointed out the optimization issue in the thread (1) "Memory Attribute for depex section" and provided suggested patch to remove the perf optimization. In my testing, removing the optimization does not make significant perf reduction. That makes sense that StandaloneMM dispatcher only searches in MM protocol database and does not depend on UEFI/DXE protocol database. Also, we don't have many protocols in StandaloneMM like UEFI/DXE. From Laszlo, "The patch removes the EFI_DEP_REPLACE_TRUE handling altogether, plus it CONST-ifies the Iterator pointer (which points into the DEPEX section), so that the compiler catch any possible accesses at *build time* that would write to the write-protected DEPEX memory area." (1) https://edk2.groups.io/g/devel/message/113531 Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com> Tested-by: levi.yun <yeoreum.yun@arm.com> Reviewed-by: levi.yun <yeoreum.yun@arm.com> Reviewed-by: Ray Ni <ray.ni@intel.com>
* StandaloneMmPkg/Core: Remove dead codeRay Ni2023-12-252-184/+0
| | | | | | | | | | | Load-module-at-fixed-address feature does not work in standalone MM core. The patch removes the 2 dead functions and related global variables that are related to the feature. Signed-off-by: Ray Ni <ray.ni@intel.com> Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com>
* StandaloneMmPkg/Core: Fix the failure to find uncompressed inner FVWei6 Xu2023-12-191-0/+22
| | | | | | | | | | | | | | | The MmCoreFfsFindMmDriver only checks for encapsulated compressed FVs. When an inner FV is uncompressed, StandaloneMmCore will miss the FV and all the MM drivers in the FV will not be dispatched. Add checks for uncompressed inner FV to fix this issue. Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* StandaloneMmPkg/Core: Fix issue that offset calculation might be wrongWei6 Xu2023-12-191-14/+15
| | | | | | | | | | | | | | | | | | | MmCoreFfsFindMmDriver() assumes FileHeader is EFI_FFS_FILE_HEADER. If FileHeader is an EFI_FFS_FILE_HEADER2, 'FileHeader + 1' will get a wrong section address. Use FfsFindSection to get the section directly, instead of 'FileHeader + 1' to avoid this issue. MmCoreFfsFindMmDriver() also assumes section is EFI_COMMON_SECTION_HEADER. If Section is EFI_COMMON_SECTION_HEADER2, 'Section + 1' will get a wrong wrong InnerFvHeader adress. Add section head detection and calculate the address accordingly. Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* StandaloneMmPkg/Core: Fix potential memory leak issueWei6 Xu2023-12-191-9/+22
| | | | | | | | | | | | | | | | | | | | In MmCoreFfsFindMmDriver(), - ScratchBuffer is not freed in the error return path that DstBuffer page allocation fails. Free ScratchBuffer before return with error. - If the decoded buffer is identical to the data in InputSection, ExtractGuidedSectionDecode() will change the value of DstBuffer rather than changing the contents of the buffer that DstBuffer points at, in which case freeing DstBuffer is wrong. Introduce a local variable AllocatedDstBuffer for buffer free, free AllocatedDstBuffer immediately if it is not used. Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* StandaloneMmPkg/Core: Limit FwVol encapsulation section recursionWei6 Xu2023-12-195-13/+44
| | | | | | | | | | | | | | | MmCoreFfsFindMmDriver() is called recursively for encapsulation sections. Currently this recursion is not limited. Introduce a new PCD (fixed-at-build, or patchable-in-module), and make MmCoreFfsFindMmDriver() track the section nesting depth against that PCD. Cc: Laszlo Ersek <lersek@redhat.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Ray Ni <ray.ni@intel.com> Signed-off-by: Wei6 Xu <wei6.xu@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
* StandaloneMmPkg: Apply uncrustify changesMichael Kubacki2021-12-0713-744/+836
| | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737 Apply uncrustify changes to .c/.h files in the StandaloneMmPkg package Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
* StandaloneMmPkg: Change OPTIONAL keyword usage styleMichael D Kinney2021-12-072-18/+18
| | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3760 Update all use of ', OPTIONAL' to ' OPTIONAL,' for function params. Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael Kubacki <michael.kubacki@microsoft.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
* StandaloneMmPkg: Support CLANGPDB buildsMarvin Häuser2021-10-181-2/+10
| | | | | | | | | | | | | Currently, the flag "-fpie" is passed for all builds with a GCC family toolchain, including CLANGPDB. CLANGPDB however does not support this flag as it generates PE/COFF files directly. As the flag is mostly required for ARM-specific self-relocation, drop it for other architectures and document the limitation to enable e.g. X64 CLANGPDB builds of StandaloneMmCore. Signed-off-by: Marvin Häuser <mhaeuser@posteo.de> Acked-by: Shi Steven <steven.shi@intel.com>
* StandaloneMmPkg: build for 32bit arm machinesEtienne Carriere2021-08-111-1/+1
| | | | | | | | | | | | | This change allows to build StandaloneMmPkg components for 32bit Arm StandaloneMm firmware. This change mainly moves AArch64/ source files to Arm/ side directory for several components: StandaloneMmCpu, StandaloneMmCoreEntryPoint and StandaloneMmMemLib. The source file is built for both 32b and 64b Arm targets. Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
* StandaloneMmPkg: Core: Spelling error in commentSean Brogan2021-06-161-1/+1
| | | | | | | | | | | | | | | | REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3445 This change fixed a misspelling that was not caught by spell check. Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Signed-off-by: Sean Brogan <sean.brogan@microsoft.com> Signed-off-by: Kun Qin <kuqin12@gmail.com> Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
* StandaloneMmPkg/StandaloneMmCore: Fix compiler warningMichael Kubacki2021-02-111-4/+4
| | | | | | | | | | | | | | | | REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3204 Fixes the following compiler warning in VS2019 by changing defining the MmramRangeCount variable to be UINTN and type casting prior to value assignment. \edk2\StandaloneMmPkg\Core\StandaloneMmCore.c(570): error C2220: the following warning is treated as an error \edk2\StandaloneMmPkg\Core\StandaloneMmCore.c(570): warning C4244: '=': conversion from 'UINT64' to 'UINT32', possible loss of data Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
* StandaloneMmPkg: Fix ECC error 9001 in Standalone MM CoreSami Mujawar2021-01-071-4/+5
| | | | | | | | | | | | Bugzilla: 3150 (https://bugzilla.tianocore.org/show_bug.cgi?id=3150) Fix the ECC reported error "[9001] The file headers should follow Doxygen special documentation blocks in section 2.3.5" Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Acked-by: Jiewen Yao <Jiewen.yao@intel.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
* StandaloneMmPkg: Fix ECC error 4002 and 9002 in StandaloneMmCoreSami Mujawar2021-01-071-5/+18
| | | | | | | | | | | | | | | Bugzilla: 3150 (https://bugzilla.tianocore.org/show_bug.cgi?id=3150) Add doxygen style function documentation headers to fix the ECC reported errors: - [4002] Function header doesn't exist. - [9002] The function headers should follow Doxygen special documentation blocks in section 2.3.5. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Acked-by: Jiewen Yao <Jiewen.yao@intel.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
* StandaloneMmPkg: Fix ECC error 5007 in StandaloneMmCoreSami Mujawar2021-01-071-2/+4
| | | | | | | | | | | | Bugzilla: 3150 (https://bugzilla.tianocore.org/show_bug.cgi?id=3150) Fix ECC error "[5007] There should be no initialization of a variable as part of its declaration Variable." Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Acked-by: Jiewen Yao <Jiewen.yao@intel.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
* StandaloneMmPkg: Fix ECC error 4002 in FwVol helperSami Mujawar2021-01-071-13/+14
| | | | | | | | | | | | | Bugzilla: 3150 (https://bugzilla.tianocore.org/show_bug.cgi?id=3150) Fix ECC Error "[4002] Function header doesn't exist Function [MmCoreFfsFindMmDriver] has NO comment immediately preceding it." Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Acked-by: Jiewen Yao <Jiewen.yao@intel.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
* StandaloneMmPkg: Fix ECC error 1001 in SMM Memory pool managementSami Mujawar2021-01-071-3/+3
| | | | | | | | | | | | | Bugzilla: 3150 (https://bugzilla.tianocore.org/show_bug.cgi?id=3150) Fix the following error reported by the Ecc tool: [1001] 'TAB' character is not allowed in source code, please replace each 'TAB' with two spaces. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Acked-by: Jiewen Yao <Jiewen.yao@intel.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
* StandaloneMmPkg: Fix ECC error 9002 in Core dispatcherSami Mujawar2021-01-071-10/+6
| | | | | | | | | | | | Bugzilla: 3150 (https://bugzilla.tianocore.org/show_bug.cgi?id=3150) Fix the ECC reported error "[9002] The function headers should follow Doxygen special documentation blocks in section 2.3.5 in Comment" Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Acked-by: Jiewen Yao <Jiewen.yao@intel.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
* StandaloneMmPkg: Fix spell check reported errorsSami Mujawar2021-01-076-34/+35
| | | | | | | | | | | | Bugzilla: 3150 (https://bugzilla.tianocore.org/show_bug.cgi?id=3150) Fix the spelling mistakes reported by the spell check utility that is run as part of the Core CI. Signed-off-by: Sami Mujawar <sami.mujawar@arm.com> Acked-by: Jiewen Yao <Jiewen.yao@intel.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>