From e8034b534ab51635b62dca631514bb6305850a5a Mon Sep 17 00:00:00 2001 From: "Liu, Zhiguang" Date: Fri, 17 Jun 2022 16:28:03 +0800 Subject: UefiPayloadPkg: Always split page table entry to 4K if it covers stack. We observed page fault in the following situation: 1.PayloadEntry uses 2M entry in page table to cover DXE stack range. 2.In DXE phase, image protection code needs to mark some sub-range in this 2M entry as readonly. So the the 2M page table entry is split to 512 4K entries, and some of the entries are marked as readonly. (the entries covering stack still remain R/W) 3.Page fault exception happens when trying to access stack. Always split the page table entry to 4K if it covers stack to avoid this issue. More discussion about this issue can be seen at below link https://edk2.groups.io/g/devel/topic/91446026 Cc: Guo Dong Reviewed-by: Ray Ni Cc: Maurice Ma Cc: Benjamin You Cc: Sean Rhodes Cc: Gerd Hoffmann Signed-off-by: Zhiguang Liu --- UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c b/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c index ac0d58e685..74b667a62a 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c +++ b/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c @@ -218,16 +218,8 @@ ToSplitPageTable ( return TRUE; } - if (PcdGetBool (PcdCpuStackGuard)) { - if ((StackBase >= Address) && (StackBase < (Address + Size))) { - return TRUE; - } - } - - if (PcdGetBool (PcdSetNxForStack)) { - if ((Address < StackBase + StackSize) && ((Address + Size) > StackBase)) { - return TRUE; - } + if ((Address < StackBase + StackSize) && ((Address + Size) > StackBase)) { + return TRUE; } if (GhcbBase != 0) { -- cgit v1.2.3