tianocore / edk2

EDK II
https://github.com/tianocore/tianocore.github.io/wiki/EDK-II
Other
4.38k stars 2.4k forks source link

UefiCpuPkg/PiSmmCpuDxeSmm: Fix system hang when SmmProfile enable #5864

Closed jiaxinwu closed 3 days ago

jiaxinwu commented 5 days ago

The system hang issue is exposed when SmmProfile feature enabled. Root cause to the error returned from the page table update (PageTableMap) during InitPaging.

The memory range within mProtectionMemRange shall be updated with the correct page table attribute in InitPaging function. But existing code doesn't mark the EFI_MEMORY_RP mask, which leading the attributes setting without the 'Present' attribute. Then, PageTableMap will return RETURN_INVALID_PARAMETER due to below reason (see function IsAttributesAndMaskValidForNonPresentEntry): For non-present range, Mask->Bits.Present is 0 but some other attributes are provided.

The fix is to add the EFI_MEMORY_RP in attribute mask, setting attributes or clearing attributes depends on the 'Present' flag in the mProtectionMemRange.

Note: When mapping a range to present, EFI_MEMORY_RO and EFI_MEMORY_XP must be specified.

Cc: Ray Ni ray.ni@intel.com Cc: Rahul Kumar rahul1.kumar@intel.com Cc: Gerd Hoffmann kraxel@redhat.com

Description

<_Include a description of the change and why this change was made._> <_For each item, place an "x" in between `[` and `]` if true. Example: `[x]` (you can also check items in GitHub UI)_> <_Create the PR as a Draft PR if it is only created to run CI checks._> <_Delete lines in \<\> tags before creating the PR._> - [ ] Breaking change? - **Breaking change** - Will this cause a break in build or boot behavior? - Examples: Add a new library class or move a module to a different repo. - [ ] Impacts security? - **Security** - Does the change have a direct security impact? - Examples: Crypto algorithm change or buffer overflow fix. - [ ] Includes tests? - **Tests** - Does the change include any explicit test code? - Examples: Unit tests or integration tests. ## How This Was Tested <_Describe the test(s) that were run to verify the changes._> ## Integration Instructions <_Describe how these changes should be integrated. Use N/A if nothing is required._>