public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2] UefiPayloadPkg: Always split page table entry to 4K if it covers stack.
@ 2022-06-17  8:28 Zhiguang Liu
  2022-06-20  1:53 ` Ni, Ray
  2022-06-20 10:43 ` [edk2-devel] " Gerd Hoffmann
  0 siblings, 2 replies; 3+ messages in thread
From: Zhiguang Liu @ 2022-06-17  8:28 UTC (permalink / raw)
  To: devel
  Cc: Zhiguang Liu, Guo Dong, Ray Ni, Maurice Ma, Benjamin You,
	Sean Rhodes, Gerd Hoffmann

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 <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
 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) {
-- 
2.16.2.windows.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] UefiPayloadPkg: Always split page table entry to 4K if it covers stack.
  2022-06-17  8:28 [PATCH v2] UefiPayloadPkg: Always split page table entry to 4K if it covers stack Zhiguang Liu
@ 2022-06-20  1:53 ` Ni, Ray
  2022-06-20 10:43 ` [edk2-devel] " Gerd Hoffmann
  1 sibling, 0 replies; 3+ messages in thread
From: Ni, Ray @ 2022-06-20  1:53 UTC (permalink / raw)
  To: Liu, Zhiguang, devel@edk2.groups.io
  Cc: Dong, Guo, Maurice Ma, You, Benjamin, Rhodes, Sean, Gerd Hoffmann

Reviewed-by: Ray Ni <ray.ni@intel.com>

> -----Original Message-----
> From: Liu, Zhiguang <zhiguang.liu@intel.com>
> Sent: Friday, June 17, 2022 4:28 PM
> To: devel@edk2.groups.io
> Cc: Liu, Zhiguang <zhiguang.liu@intel.com>; Dong, Guo
> <guo.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Maurice Ma
> <maurice.ma@intel.com>; You, Benjamin <benjamin.you@intel.com>;
> Rhodes, Sean <sean@starlabs.systems>; Gerd Hoffmann
> <kraxel@redhat.com>
> Subject: [PATCH v2] 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 <guo.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Maurice Ma <maurice.ma@intel.com>
> Cc: Benjamin You <benjamin.you@intel.com>
> Cc: Sean Rhodes <sean@starlabs.systems>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
> ---
>  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) {
> --
> 2.16.2.windows.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] [PATCH v2] UefiPayloadPkg: Always split page table entry to 4K if it covers stack.
  2022-06-17  8:28 [PATCH v2] UefiPayloadPkg: Always split page table entry to 4K if it covers stack Zhiguang Liu
  2022-06-20  1:53 ` Ni, Ray
@ 2022-06-20 10:43 ` Gerd Hoffmann
  1 sibling, 0 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2022-06-20 10:43 UTC (permalink / raw)
  To: devel, zhiguang.liu
  Cc: Guo Dong, Ray Ni, Maurice Ma, Benjamin You, Sean Rhodes

On Fri, Jun 17, 2022 at 04:28:03PM +0800, Zhiguang Liu wrote:
> 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

Acked-by: Gerd Hoffmann <kraxel@redhat.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-20 10:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-17  8:28 [PATCH v2] UefiPayloadPkg: Always split page table entry to 4K if it covers stack Zhiguang Liu
2022-06-20  1:53 ` Ni, Ray
2022-06-20 10:43 ` [edk2-devel] " Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox