audk/UefiCpuPkg/CpuDxe
Jian J Wang 54efcfea81 UefiCpuPkg/CpuDxe: prevent recursive calling of InitializePageTablePool
The freed-memory guard feature will cause a recursive calling
of InitializePageTablePool(). This is due to a fact that
AllocateAlignedPages() is used to allocate page table pool memory.
This function will most likely call gBS->FreePages to free unaligned
pages and then cause another round of page attributes change, like
below (freed pages will be always marked not-present if freed-memory
guard is enabled)

   FreePages() <===============|
=> CpuSetMemoryAttributes()    |
=> <if out of page table>      |
=> InitializePageTablePool()   |
=> AllocateAlignedPages()      |
=> FreePages() ================|

The solution is add a global variable as a lock in page table pool
allocation function and fail any other requests if it has not been
done.

Since this issue will only happen if free-memory guard is enabled,
it won't affect CpuSetMemoryAttributes() in default build of a BIOS.

If free-memory guard is enabled, it only affect the pages
(failed to mark them as not-present) freed in AllocateAlignedPages().

Since those freed pages haven't been used yet (their addresses not
yet exposed to code outside AllocateAlignedPages), it won't compromise
the freed-memory guard feature.

This change will just fail the CpuSetMemoryAttributes() called from
FreePages() but it won't fail the FreePages(). So the error status
won't be propagated upper layer of code.

Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
2018-10-26 10:30:34 +08:00
..
Ia32 UefiCpuPkg: Remove X86 ASM and S files 2018-06-07 15:27:36 +08:00
X64 UefiCpuPkg: Remove X86 ASM and S files 2018-06-07 15:27:36 +08:00
CpuDxe.c UefiCpuPkg/CpuDxe: change level of DEBUG message 2018-08-30 07:43:56 +08:00
CpuDxe.h UefiCpuPkg/CpuDxe: consider freed-memory guard in non-stop mode 2018-10-26 10:27:21 +08:00
CpuDxe.inf UefiCpuPkg/CpuDxe: implement non-stop mode for uefi 2018-08-30 07:22:30 +08:00
CpuDxe.uni UefiCpuPkg: Clean up source files 2018-06-28 11:19:53 +08:00
CpuDxeExtra.uni UefiCpuPkg: Clean up source files 2018-06-28 11:19:53 +08:00
CpuGdt.c UefiCpuPkg: CpuDxe: Update GDT to be consistent with DxeIplPeim 2015-10-30 17:32:27 +00:00
CpuGdt.h UefiCpuPkg: CpuDxe: Update GDT to be consistent with DxeIplPeim 2015-10-30 17:32:27 +00:00
CpuMp.c UefiCpuPkg/CpuDxe: implement non-stop mode for uefi 2018-08-30 07:22:30 +08:00
CpuMp.h UefiCpuPkg CpuDxe: Update return status to follow spec. 2017-07-07 08:54:10 +08:00
CpuPageTable.c UefiCpuPkg/CpuDxe: prevent recursive calling of InitializePageTablePool 2018-10-26 10:30:34 +08:00
CpuPageTable.h UefiCpuPkg/CpuDxe: Enable protection for newly added page table 2017-12-12 10:14:51 +08:00