]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/PiSmmCpuDxeSmm: patch "gSmiStack" with PatchInstructionX86()
authorLaszlo Ersek <lersek@redhat.com>
Thu, 1 Feb 2018 22:23:59 +0000 (23:23 +0100)
committerLaszlo Ersek <lersek@redhat.com>
Wed, 4 Apr 2018 14:44:04 +0000 (16:44 +0200)
Rename the variable to "gPatchSmiStack" so that its association with
PatchInstructionX86() is clear from the declaration. Also change its type
to X86_ASSEMBLY_PATCH_LABEL.

Unlike "gSmbase" in the previous patch, "gSmiStack"'s patched value is
also de-referenced by C code (in other words, it is read back after
patching): the InstallSmiHandler() function stores "CpuIndex" to the given
CPU's SMI stack through "gSmiStack". Introduce the local variable
"CpuSmiStack" in InstallSmiHandler() for calculating the stack location
separately, then use this variable for both patching into the assembly
code, and for storing "CpuIndex" through it.

It's assumed that "volatile" stood in the declaration of "gSmiStack"
because we used to read "gSmiStack" back for de-referencing; with that use
gone, we can remove "volatile" too. (Note that the *target* of the pointer
was never volatile-qualified.)

Finally, replace the binary (DB) encoding of "mov esp, imm32" in
"SmiEntry.nasm".

Cc: Eric Dong <eric.dong@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=866
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm
UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c
UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm

index e6e29128e64eb9ebb40094f632e75f259091e33b..0ea3c1e4498dbc1f434267c53abea02eb3dc828c 100644 (file)
@@ -45,7 +45,7 @@ extern ASM_PFX(CpuSmmDebugExit)
 global ASM_PFX(gcSmiHandlerTemplate)\r
 global ASM_PFX(gcSmiHandlerSize)\r
 global ASM_PFX(gSmiCr3)\r
 global ASM_PFX(gcSmiHandlerTemplate)\r
 global ASM_PFX(gcSmiHandlerSize)\r
 global ASM_PFX(gSmiCr3)\r
-global ASM_PFX(gSmiStack)\r
+global ASM_PFX(gPatchSmiStack)\r
 global ASM_PFX(gPatchSmbase)\r
 global ASM_PFX(mXdSupported)\r
 extern ASM_PFX(gSmiHandlerIdtr)\r
 global ASM_PFX(gPatchSmbase)\r
 global ASM_PFX(mXdSupported)\r
 extern ASM_PFX(gSmiHandlerIdtr)\r
@@ -86,8 +86,8 @@ o16 mov     es, ax
 o16 mov     fs, ax\r
 o16 mov     gs, ax\r
 o16 mov     ss, ax\r
 o16 mov     fs, ax\r
 o16 mov     gs, ax\r
 o16 mov     ss, ax\r
-    DB      0xbc                   ; mov esp, imm32\r
-ASM_PFX(gSmiStack): DD 0\r
+    mov esp, strict dword 0               ; source operand will be patched\r
+ASM_PFX(gPatchSmiStack):\r
     mov     eax, ASM_PFX(gSmiHandlerIdtr)\r
     lidt    [eax]\r
     jmp     ProtFlatMode\r
     mov     eax, ASM_PFX(gSmiHandlerIdtr)\r
     lidt    [eax]\r
     jmp     ProtFlatMode\r
index d34345d5ff8034515165fd782c10402a69f88cea..f0c289254330d3949a0f00dcd3fcc98818c13b9f 100644 (file)
@@ -106,7 +106,7 @@ typedef struct {
 /// Variables from SMI Handler\r
 ///\r
 X86_ASSEMBLY_PATCH_LABEL gPatchSmbase;\r
 /// Variables from SMI Handler\r
 ///\r
 X86_ASSEMBLY_PATCH_LABEL gPatchSmbase;\r
-extern volatile UINT32   gSmiStack;\r
+X86_ASSEMBLY_PATCH_LABEL gPatchSmiStack;\r
 extern UINT32            gSmiCr3;\r
 extern volatile UINT8    gcSmiHandlerTemplate[];\r
 extern CONST UINT16      gcSmiHandlerSize;\r
 extern UINT32            gSmiCr3;\r
 extern volatile UINT8    gcSmiHandlerTemplate[];\r
 extern CONST UINT16      gcSmiHandlerSize;\r
@@ -686,6 +686,7 @@ InstallSmiHandler (
   )\r
 {\r
   PROCESSOR_SMM_DESCRIPTOR  *Psd;\r
   )\r
 {\r
   PROCESSOR_SMM_DESCRIPTOR  *Psd;\r
+  UINT32                    CpuSmiStack;\r
 \r
   //\r
   // Initialize PROCESSOR_SMM_DESCRIPTOR\r
 \r
   //\r
   // Initialize PROCESSOR_SMM_DESCRIPTOR\r
@@ -716,7 +717,8 @@ InstallSmiHandler (
   //\r
   // Initialize values in template before copy\r
   //\r
   //\r
   // Initialize values in template before copy\r
   //\r
-  gSmiStack             = (UINT32)((UINTN)SmiStack + StackSize - sizeof (UINTN));\r
+  CpuSmiStack = (UINT32)((UINTN)SmiStack + StackSize - sizeof (UINTN));\r
+  PatchInstructionX86 (gPatchSmiStack, CpuSmiStack, 4);\r
   gSmiCr3               = Cr3;\r
   PatchInstructionX86 (gPatchSmbase, SmBase, 4);\r
   gSmiHandlerIdtr.Base  = IdtBase;\r
   gSmiCr3               = Cr3;\r
   PatchInstructionX86 (gPatchSmbase, SmBase, 4);\r
   gSmiHandlerIdtr.Base  = IdtBase;\r
@@ -725,7 +727,7 @@ InstallSmiHandler (
   //\r
   // Set the value at the top of the CPU stack to the CPU Index\r
   //\r
   //\r
   // Set the value at the top of the CPU stack to the CPU Index\r
   //\r
-  *(UINTN*)(UINTN)gSmiStack = CpuIndex;\r
+  *(UINTN*)(UINTN)CpuSmiStack = CpuIndex;\r
 \r
   //\r
   // Copy template to CPU specific SMI handler location\r
 \r
   //\r
   // Copy template to CPU specific SMI handler location\r
index 0e314279a54136883526bdc34f66ff3206a8bfb3..9cfa8e7fc8f49c56057d2502a2b095e2e35d9701 100644 (file)
@@ -55,7 +55,7 @@ extern ASM_PFX(CpuSmmDebugExit)
 \r
 global ASM_PFX(gPatchSmbase)\r
 global ASM_PFX(mXdSupported)\r
 \r
 global ASM_PFX(gPatchSmbase)\r
 global ASM_PFX(mXdSupported)\r
-global ASM_PFX(gSmiStack)\r
+global ASM_PFX(gPatchSmiStack)\r
 global ASM_PFX(gSmiCr3)\r
 global ASM_PFX(gcSmiHandlerTemplate)\r
 global ASM_PFX(gcSmiHandlerSize)\r
 global ASM_PFX(gSmiCr3)\r
 global ASM_PFX(gcSmiHandlerTemplate)\r
 global ASM_PFX(gcSmiHandlerSize)\r
@@ -96,8 +96,8 @@ o16 mov     es, ax
 o16 mov     fs, ax\r
 o16 mov     gs, ax\r
 o16 mov     ss, ax\r
 o16 mov     fs, ax\r
 o16 mov     gs, ax\r
 o16 mov     ss, ax\r
-    DB      0xbc                   ; mov esp, imm32\r
-ASM_PFX(gSmiStack): DD 0\r
+    mov esp, strict dword 0               ; source operand will be patched\r
+ASM_PFX(gPatchSmiStack):\r
     jmp     ProtFlatMode\r
 \r
 BITS 64\r
     jmp     ProtFlatMode\r
 \r
 BITS 64\r