public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] UefiCpuPkg/CpuExceptionHandlerLib: Code optimization to allow bigger stack
@ 2022-09-28  1:51 duntan
  2022-09-28  5:43 ` Ni, Ray
  2022-09-29  1:04 ` [edk2-devel] " Chang, Abner
  0 siblings, 2 replies; 4+ messages in thread
From: duntan @ 2022-09-28  1:51 UTC (permalink / raw)
  To: devel; +Cc: Eric Dong, Ray Ni, Rahul Kumar

This commit is a code optimization to allow bigger seperate stack size in
ArchSetupExceptionStack. In previous code logic, CPU_STACK_ALIGNMENT bytes
will be wasted if StackTop is already CPU_STACK_ALIGNMENT aligned.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
---
 UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c | 2 +-
 UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
index 8c398ebc5b..c8fa30a32f 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
@@ -215,7 +215,7 @@ ArchSetupExceptionStack (
   // Fixup exception task descriptor and task-state segment
   //
   AsmGetTssTemplateMap (&TemplateMap);
-  StackTop = StackTop - CPU_STACK_ALIGNMENT;
+  StackTop = StackTop - CPU_STACK_ALIGNMENT + 1;
   StackTop = (UINTN)ALIGN_POINTER (StackTop, CPU_STACK_ALIGNMENT);
   IdtTable = (IA32_IDT_GATE_DESCRIPTOR  *)Idtr.Base;
   for (Index = 0; Index < CPU_STACK_SWITCH_EXCEPTION_NUMBER; ++Index) {
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
index 80e9f08e5b..74b2193cb0 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
@@ -223,7 +223,7 @@ ArchSetupExceptionStack (
   // Fixup exception task descriptor and task-state segment
   //
   ZeroMem (Tss, sizeof (*Tss));
-  StackTop = StackTop - CPU_STACK_ALIGNMENT;
+  StackTop = StackTop - CPU_STACK_ALIGNMENT + 1;
   StackTop = (UINTN)ALIGN_POINTER (StackTop, CPU_STACK_ALIGNMENT);
   IdtTable = (IA32_IDT_GATE_DESCRIPTOR  *)Idtr.Base;
   for (Index = 0; Index < CPU_STACK_SWITCH_EXCEPTION_NUMBER; ++Index) {
-- 
2.31.1.windows.1


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

* Re: [PATCH] UefiCpuPkg/CpuExceptionHandlerLib: Code optimization to allow bigger stack
  2022-09-28  1:51 [PATCH] UefiCpuPkg/CpuExceptionHandlerLib: Code optimization to allow bigger stack duntan
@ 2022-09-28  5:43 ` Ni, Ray
  2022-09-29  1:04 ` [edk2-devel] " Chang, Abner
  1 sibling, 0 replies; 4+ messages in thread
From: Ni, Ray @ 2022-09-28  5:43 UTC (permalink / raw)
  To: Tan, Dun, devel@edk2.groups.io; +Cc: Dong, Eric, Kumar, Rahul R

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

> -----Original Message-----
> From: Tan, Dun <dun.tan@intel.com>
> Sent: Wednesday, September 28, 2022 9:52 AM
> To: devel@edk2.groups.io
> Cc: Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Kumar,
> Rahul R <rahul.r.kumar@intel.com>
> Subject: [PATCH] UefiCpuPkg/CpuExceptionHandlerLib: Code optimization to
> allow bigger stack
> 
> This commit is a code optimization to allow bigger seperate stack size in
> ArchSetupExceptionStack. In previous code logic, CPU_STACK_ALIGNMENT
> bytes
> will be wasted if StackTop is already CPU_STACK_ALIGNMENT aligned.
> 
> Signed-off-by: Dun Tan <dun.tan@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> ---
>  UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c |
> 2 +-
>  UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c  |
> 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.
> c
> index 8c398ebc5b..c8fa30a32f 100644
> ---
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
> +++
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.
> c
> @@ -215,7 +215,7 @@ ArchSetupExceptionStack (
>    // Fixup exception task descriptor and task-state segment
>    //
>    AsmGetTssTemplateMap (&TemplateMap);
> -  StackTop = StackTop - CPU_STACK_ALIGNMENT;
> +  StackTop = StackTop - CPU_STACK_ALIGNMENT + 1;
>    StackTop = (UINTN)ALIGN_POINTER (StackTop, CPU_STACK_ALIGNMENT);
>    IdtTable = (IA32_IDT_GATE_DESCRIPTOR  *)Idtr.Base;
>    for (Index = 0; Index < CPU_STACK_SWITCH_EXCEPTION_NUMBER;
> ++Index) {
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
> index 80e9f08e5b..74b2193cb0 100644
> ---
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
> +++
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
> @@ -223,7 +223,7 @@ ArchSetupExceptionStack (
>    // Fixup exception task descriptor and task-state segment
>    //
>    ZeroMem (Tss, sizeof (*Tss));
> -  StackTop = StackTop - CPU_STACK_ALIGNMENT;
> +  StackTop = StackTop - CPU_STACK_ALIGNMENT + 1;
>    StackTop = (UINTN)ALIGN_POINTER (StackTop, CPU_STACK_ALIGNMENT);
>    IdtTable = (IA32_IDT_GATE_DESCRIPTOR  *)Idtr.Base;
>    for (Index = 0; Index < CPU_STACK_SWITCH_EXCEPTION_NUMBER;
> ++Index) {
> --
> 2.31.1.windows.1


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

* Re: [edk2-devel] [PATCH] UefiCpuPkg/CpuExceptionHandlerLib: Code optimization to allow bigger stack
  2022-09-28  1:51 [PATCH] UefiCpuPkg/CpuExceptionHandlerLib: Code optimization to allow bigger stack duntan
  2022-09-28  5:43 ` Ni, Ray
@ 2022-09-29  1:04 ` Chang, Abner
  2022-09-29  9:02   ` duntan
  1 sibling, 1 reply; 4+ messages in thread
From: Chang, Abner @ 2022-09-29  1:04 UTC (permalink / raw)
  To: devel@edk2.groups.io, dun.tan@intel.com; +Cc: Eric Dong, Ray Ni, Rahul Kumar

[AMD Official Use Only - General]



> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
> via groups.io
> Sent: Wednesday, September 28, 2022 9:52 AM
> To: devel@edk2.groups.io
> Cc: Eric Dong <eric.dong@intel.com>; Ray Ni <ray.ni@intel.com>; Rahul
> Kumar <rahul1.kumar@intel.com>
> Subject: [edk2-devel] [PATCH] UefiCpuPkg/CpuExceptionHandlerLib: Code
> optimization to allow bigger stack
> 
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
> 
> 
> This commit is a code optimization to allow bigger seperate stack size in
> ArchSetupExceptionStack. In previous code logic, CPU_STACK_ALIGNMENT
> bytes will be wasted if StackTop is already CPU_STACK_ALIGNMENT aligned.
> 
> Signed-off-by: Dun Tan <dun.tan@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> ---
>  UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c |
> 2 +-
> UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c  |
> 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.
> c
> index 8c398ebc5b..c8fa30a32f 100644
> ---
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
> +++
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandle
> +++ r.c
> @@ -215,7 +215,7 @@ ArchSetupExceptionStack (
>    // Fixup exception task descriptor and task-state segment
>    //
>    AsmGetTssTemplateMap (&TemplateMap);
> -  StackTop = StackTop - CPU_STACK_ALIGNMENT;
> +  StackTop = StackTop - CPU_STACK_ALIGNMENT + 1;
Hi Dun,
Could you please add a comment on this change says the change is for the compact stack layout?
Thanks
Abner

>    StackTop = (UINTN)ALIGN_POINTER (StackTop, CPU_STACK_ALIGNMENT);
>    IdtTable = (IA32_IDT_GATE_DESCRIPTOR  *)Idtr.Base;
>    for (Index = 0; Index < CPU_STACK_SWITCH_EXCEPTION_NUMBER;
> ++Index) { diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
> index 80e9f08e5b..74b2193cb0 100644
> ---
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
> +++
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler
> +++ .c
> @@ -223,7 +223,7 @@ ArchSetupExceptionStack (
>    // Fixup exception task descriptor and task-state segment
>    //
>    ZeroMem (Tss, sizeof (*Tss));
> -  StackTop = StackTop - CPU_STACK_ALIGNMENT;
> +  StackTop = StackTop - CPU_STACK_ALIGNMENT + 1;
>    StackTop = (UINTN)ALIGN_POINTER (StackTop, CPU_STACK_ALIGNMENT);
>    IdtTable = (IA32_IDT_GATE_DESCRIPTOR  *)Idtr.Base;
>    for (Index = 0; Index < CPU_STACK_SWITCH_EXCEPTION_NUMBER;
> ++Index) {
> --
> 2.31.1.windows.1
> 
> 
> 
> 
> 

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

* Re: [edk2-devel] [PATCH] UefiCpuPkg/CpuExceptionHandlerLib: Code optimization to allow bigger stack
  2022-09-29  1:04 ` [edk2-devel] " Chang, Abner
@ 2022-09-29  9:02   ` duntan
  0 siblings, 0 replies; 4+ messages in thread
From: duntan @ 2022-09-29  9:02 UTC (permalink / raw)
  To: devel@edk2.groups.io, abner.chang@amd.com
  Cc: Dong, Eric, Ni, Ray, Kumar, Rahul R

Hi Abner,

Thanks for the comments. I'll add comments on this code change to explain it in V2 patch.

Thanks,
Dun
-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Chang, Abner via groups.io
Sent: Thursday, September 29, 2022 9:05 AM
To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
Cc: Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>
Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg/CpuExceptionHandlerLib: Code optimization to allow bigger stack

[AMD Official Use Only - General]



> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan 
> via groups.io
> Sent: Wednesday, September 28, 2022 9:52 AM
> To: devel@edk2.groups.io
> Cc: Eric Dong <eric.dong@intel.com>; Ray Ni <ray.ni@intel.com>; Rahul 
> Kumar <rahul1.kumar@intel.com>
> Subject: [edk2-devel] [PATCH] UefiCpuPkg/CpuExceptionHandlerLib: Code 
> optimization to allow bigger stack
> 
> Caution: This message originated from an External Source. Use proper 
> caution when opening attachments, clicking links, or responding.
> 
> 
> This commit is a code optimization to allow bigger seperate stack size 
> in ArchSetupExceptionStack. In previous code logic, 
> CPU_STACK_ALIGNMENT bytes will be wasted if StackTop is already CPU_STACK_ALIGNMENT aligned.
> 
> Signed-off-by: Dun Tan <dun.tan@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> ---
>  UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c 
> |
> 2 +-
> UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c  
> |
> 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.
> c 
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.
> c
> index 8c398ebc5b..c8fa30a32f 100644
> ---
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.
> c
> +++
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandle
> +++ r.c
> @@ -215,7 +215,7 @@ ArchSetupExceptionStack (
>    // Fixup exception task descriptor and task-state segment
>    //
>    AsmGetTssTemplateMap (&TemplateMap);
> -  StackTop = StackTop - CPU_STACK_ALIGNMENT;
> +  StackTop = StackTop - CPU_STACK_ALIGNMENT + 1;
Hi Dun,
Could you please add a comment on this change says the change is for the compact stack layout?
Thanks
Abner

>    StackTop = (UINTN)ALIGN_POINTER (StackTop, CPU_STACK_ALIGNMENT);
>    IdtTable = (IA32_IDT_GATE_DESCRIPTOR  *)Idtr.Base;
>    for (Index = 0; Index < CPU_STACK_SWITCH_EXCEPTION_NUMBER;
> ++Index) { diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
> index 80e9f08e5b..74b2193cb0 100644
> ---
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
> +++
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler
> +++ .c
> @@ -223,7 +223,7 @@ ArchSetupExceptionStack (
>    // Fixup exception task descriptor and task-state segment
>    //
>    ZeroMem (Tss, sizeof (*Tss));
> -  StackTop = StackTop - CPU_STACK_ALIGNMENT;
> +  StackTop = StackTop - CPU_STACK_ALIGNMENT + 1;
>    StackTop = (UINTN)ALIGN_POINTER (StackTop, CPU_STACK_ALIGNMENT);
>    IdtTable = (IA32_IDT_GATE_DESCRIPTOR  *)Idtr.Base;
>    for (Index = 0; Index < CPU_STACK_SWITCH_EXCEPTION_NUMBER;
> ++Index) {
> --
> 2.31.1.windows.1
> 
> 
> 
> 
> 






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

end of thread, other threads:[~2022-09-29  9:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-28  1:51 [PATCH] UefiCpuPkg/CpuExceptionHandlerLib: Code optimization to allow bigger stack duntan
2022-09-28  5:43 ` Ni, Ray
2022-09-29  1:04 ` [edk2-devel] " Chang, Abner
2022-09-29  9:02   ` duntan

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