]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Fix the risk of AP stack conflict.
authorxli24 <xli24@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 30 Jul 2010 01:49:51 +0000 (01:49 +0000)
committerxli24 <xli24@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 30 Jul 2010 01:49:51 +0000 (01:49 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10714 6f19259b-4bc3-4df7-8a09-765794883524

EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/IA32/AsmInclude.inc
EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/IA32/MpFuncs.S
EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/IA32/MpFuncs.asm
EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/MpServicesOnFrameworkMpServicesThunk.c
EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/MpServicesOnFrameworkMpServicesThunk.h
EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/X64/AsmInclude.inc
EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/X64/MpFuncs.S
EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/X64/MpFuncs.asm

index d396726bfead36425346a4eb96396fc17a8bd875..ab2443c79e514fdf2f2c1fbf66ff739aa1369dce 100644 (file)
@@ -22,5 +22,5 @@ RendezvousProc      equ        LockLocation + 0Ch
 GdtrProfile         equ        LockLocation + 10h\r
 IdtrProfile         equ        LockLocation + 16h\r
 BufferStart         equ        LockLocation + 1Ch\r
-\r
+ProcessorNumber     equ        LockLocation + 20h\r
 ;-------------------------------------------------------------------------------\r
index 1ddf11518f3787f5ef5651773a2402f4e56c37a1..f1b6bc391ae4852e4254d0cda5a731f16437d386 100644 (file)
@@ -22,6 +22,7 @@
 #define GdtrProfile      RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x10\r
 #define IdtrProfile      RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x16\r
 #define BufferStart      RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x1C\r
+#define ProcessorNumber, RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x20\r
 \r
 #-------------------------------------------------------------------------------------\r
 #RendezvousFunnelProc  procedure follows. All APs execute their procedure. This\r
@@ -94,30 +95,33 @@ ProtectedModeStart:                   # protected mode entry point
         .byte       0x66\r
         movw        %ax,%ss           # Flat mode setup.\r
 \r
-\r
+        #\r
+        # ProgramStack\r
+        #\r
+        movl        $0x1b, %ecx\r
+        rdmsr\r
+        andl        $0xfffff000, %eax\r
+        addl        $0x20, %eax\r
+        movl        (%eax), %ebx\r
+        shrl        $24, %ebx\r
+        \r
+        xorl        %ecx, %ecx\r
         movl        %esi,%edi\r
-        addl        $LockLocation, %edi\r
-        movb        $NotVacantFlag, %al\r
-TestLock:\r
-        xchgb       (%edi), %al\r
-        cmpb        $NotVacantFlag, %al\r
-        jz          TestLock\r
-\r
-ProgramStack:\r
+        addl        $ProcessorNumber, %edi\r
+        movl        (%edi, %ebx, 4), %ecx\r
+\r
         movl        %esi,%edi\r
         addl        $StackSize, %edi\r
         movl        (%edi), %eax\r
+        incl        %ecx\r
+        mull        %ecx\r
+\r
         movl        %esi,%edi\r
         addl        $StackStart, %edi\r
-        addl        (%edi), %eax\r
-        movl        %eax,%esp\r
-        movl        %eax, (%edi)\r
+        movl        (%edi), %ebx\r
+        addl        %ebx, %eax\r
 \r
-Releaselock:\r
-        movb        $VacantFlag, %al\r
-        movl        %esi,%edi\r
-        addl        $LockLocation, %edi\r
-        xchgb       (%edi), %al\r
+        movl        %eax, %esp\r
 \r
         #\r
         # Call C Function\r
index e5f38a6bbe41835269d08a7afd8ad463e0e6fbeb..13f2bb74d283017afb95609f22d3372e82269a1c 100644 (file)
@@ -85,31 +85,33 @@ ProtectedModeStart::                  ; protected mode entry point
         mov         gs,  ax\r
         mov         ss,  ax           ; Flat mode setup.\r
 \r
-\r
+        ;\r
+        ; ProgramStack\r
+        ;\r
+        mov         ecx, 1bh                          ; Read IA32_APIC_BASE MSR\r
+        rdmsr\r
+        and         eax, 0fffff000h\r
+        add         eax, 20h\r
+        mov         ebx, dword ptr [eax]\r
+        shr         ebx, 24\r
+        \r
+        xor         ecx, ecx\r
         mov         edi, esi\r
-        add         edi, LockLocation\r
-        mov         al,  NotVacantFlag\r
-TestLock::\r
-        xchg        byte ptr [edi], al\r
-        cmp         al,  NotVacantFlag\r
-        jz          TestLock\r
-\r
-ProgramStack::\r
+        add         edi, ProcessorNumber\r
+        mov         ecx, dword ptr [edi + 4 * ebx]    ; ECX = CpuNumber\r
 \r
         mov         edi, esi\r
         add         edi, StackSize\r
         mov         eax, dword ptr [edi]\r
+        inc         ecx\r
+        mul         ecx                               ; EAX = StackSize * (CpuNumber + 1)\r
+\r
         mov         edi, esi\r
         add         edi, StackStart\r
-        add         eax, dword ptr [edi]\r
-        mov         esp, eax\r
-        mov         dword ptr [edi], eax\r
+        mov         ebx, dword ptr [edi]\r
+        add         eax, ebx                          ; EAX = StackStart + StackSize * (CpuNumber + 1)\r
 \r
-Releaselock::\r
-        mov         al,  VacantFlag\r
-        mov         edi, esi\r
-        add         edi, LockLocation\r
-        xchg        byte ptr [edi], al\r
+        mov         esp, eax\r
 \r
         ;\r
         ; Call C Function\r
index f3db9f6b7c01b11037047a2e24d27507199bbed4..479362dd8704fcf045b8aad2f04ae5b15b012d21 100644 (file)
@@ -22,7 +22,6 @@ EFI_HANDLE                          mHandle = NULL;
 MP_SYSTEM_DATA                      mMPSystemData;\r
 EFI_PHYSICAL_ADDRESS                mStartupVector;\r
 MP_CPU_EXCHANGE_INFO                *mExchangeInfo;\r
-VOID                                *mStackStartAddress;\r
 BOOLEAN                             mStopCheckAPsStatus = FALSE;\r
 UINTN                               mNumberOfProcessors;\r
 EFI_GENERIC_MEMORY_TEST_PROTOCOL    *mGenMemoryTest;\r
@@ -1254,14 +1253,14 @@ ApProcWrapper (
 \r
   This function sends INIT-SIPI-SIPI to AP, and assign procedure specified by ApFunction.\r
 \r
-  @param  Broadcast   If TRUE, broadcase IPI to all APs; otherwise, send to specified AP.\r
-  @param  ApicID      The Local APIC ID of the specified AP. If Broadcast is TRUE, it is ignored.\r
-  @param  ApFunction  The procedure for AP to work on.\r
+  @param  ProcessorNumber The processor number of the specified AP.\r
+  @param  ApicID          The Local APIC ID of the specified AP.\r
+  @param  ApFunction      The procedure for AP to work on.\r
 \r
 **/\r
 VOID\r
 SendInitSipiSipi (\r
-  IN BOOLEAN            Broadcast,\r
+  IN UINTN              ProcessorNumber,\r
   IN UINT32             ApicID,\r
   IN VOID               *ApFunction\r
   )\r
@@ -1274,15 +1273,10 @@ SendInitSipiSipi (
   UINT32                DeliveryMode;\r
 \r
   mExchangeInfo->ApFunction = ApFunction;\r
-  mExchangeInfo->StackStart = mStackStartAddress;\r
+  mExchangeInfo->ProcessorNumber[ApicID] = (UINT32) ProcessorNumber;\r
 \r
-  if (Broadcast) {\r
-    ICRHigh = 0;\r
-    ICRLow  = BROADCAST_MODE_ALL_EXCLUDING_SELF_BIT | TRIGGER_MODE_LEVEL_BIT | ASSERT_BIT;\r
-  } else {\r
-    ICRHigh = ApicID << 24;\r
-    ICRLow  = SPECIFY_CPU_MODE_BIT | TRIGGER_MODE_LEVEL_BIT | ASSERT_BIT;\r
-  }\r
+  ICRHigh = ApicID << 24;\r
+  ICRLow  = SPECIFY_CPU_MODE_BIT | TRIGGER_MODE_LEVEL_BIT | ASSERT_BIT;\r
 \r
   VectorNumber = 0;\r
   DeliveryMode = DELIVERY_MODE_INIT;\r
@@ -1300,11 +1294,7 @@ SendInitSipiSipi (
 \r
   VectorNumber = (UINT32) RShiftU64 (mStartupVector, 12);\r
   DeliveryMode = DELIVERY_MODE_SIPI;\r
-  if (Broadcast) {\r
-    ICRLow = BROADCAST_MODE_ALL_EXCLUDING_SELF_BIT | TRIGGER_MODE_LEVEL_BIT | ASSERT_BIT;\r
-  } else {\r
-    ICRLow = SPECIFY_CPU_MODE_BIT | TRIGGER_MODE_LEVEL_BIT | ASSERT_BIT;\r
-  }\r
+  ICRLow = SPECIFY_CPU_MODE_BIT | TRIGGER_MODE_LEVEL_BIT | ASSERT_BIT;\r
 \r
   ICRLow |= VectorNumber | (DeliveryMode << 8);\r
 \r
@@ -1358,7 +1348,7 @@ WakeUpAp (
   ASSERT_EFI_ERROR (Status);\r
 \r
   SendInitSipiSipi (\r
-    FALSE,\r
+    ProcessorNumber,\r
     (UINT32) ProcessorInfoBuffer.ProcessorId,\r
     (VOID *) (UINTN) ApProcWrapper\r
     );\r
@@ -1390,7 +1380,7 @@ ResetProcessorToIdleState (
   ASSERT_EFI_ERROR (Status);\r
 \r
   SendInitSipiSipi (\r
-    FALSE,\r
+    ProcessorNumber,\r
     (UINT32) ProcessorInfoBuffer.ProcessorId,\r
     NULL\r
     );\r
@@ -1601,7 +1591,7 @@ PrepareAPStartupVector (
 \r
   ZeroMem ((VOID *) mExchangeInfo, sizeof (MP_CPU_EXCHANGE_INFO));\r
 \r
-  mStackStartAddress = AllocatePages (EFI_SIZE_TO_PAGES (MAX_CPU_NUMBER * AP_STACK_SIZE));\r
+  mExchangeInfo->StackStart  = AllocatePages (EFI_SIZE_TO_PAGES (mNumberOfProcessors * AP_STACK_SIZE));\r
   mExchangeInfo->StackSize  = AP_STACK_SIZE;\r
 \r
   AsmReadGdtr (&GdtrForBSP);\r
@@ -1711,8 +1701,6 @@ InitializeMpServicesProtocol (
 {\r
   EFI_STATUS Status;\r
 \r
-  PrepareMemoryForConfiguration ();\r
-\r
   //\r
   // Locates Framework version MP Services Protocol\r
   //\r
@@ -1734,6 +1722,8 @@ InitializeMpServicesProtocol (
   ASSERT_EFI_ERROR (Status);\r
   ASSERT (mNumberOfProcessors < MAX_CPU_NUMBER);\r
 \r
+  PrepareMemoryForConfiguration ();\r
+\r
   //\r
   // Create timer event to check AP state for non-blocking execution.\r
   //\r
index 8c98300a75f8de0e4b3827823b343ee629c0d2db..28be5b17d38494657bff24608c541839c5ce9fb3 100644 (file)
@@ -72,6 +72,7 @@ typedef struct {
   IA32_DESCRIPTOR   IdtrProfile;\r
   UINT32            BufferStart;\r
   UINT32            Cr3;\r
+  UINT32            ProcessorNumber[MAX_CPU_NUMBER];\r
 } MP_CPU_EXCHANGE_INFO;\r
 \r
 typedef struct {\r
index d0269760a6212d70780b58c4bc0caf553c536a34..b0e611108f4ef4211098246f3d1f3471bac1bc75 100644 (file)
@@ -23,5 +23,6 @@ GdtrLocation                  equ        LockLocation + 20h
 IdtrLocation                  equ        LockLocation + 2Ah\r
 BufferStartLocation           equ        LockLocation + 34h\r
 Cr3OffsetLocation             equ        LockLocation + 38h\r
+ProcessorNumberLocation       equ        LockLocation + 3Ch\r
 \r
 ;-------------------------------------------------------------------------------\r
index 8efd2d183ed73fd0a76828ed466f8201fe569849..5ec90bdaac54db7f49576cbed8374c120b09f278 100644 (file)
@@ -24,6 +24,7 @@
 .equ                   IdtrLocation,              RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x2A\r
 .equ                   BufferStartLocation,       RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x34\r
 .equ                   Cr3OffsetLocation,         RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x38\r
+.equ                   ProcessorNumberLocation,   RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x38\r
 \r
 #-------------------------------------------------------------------------------------\r
 \r
@@ -128,31 +129,33 @@ LongModeStart:
         .byte       0x66\r
         movw        %ax,%ss\r
 \r
-        movl        %esi, %edi\r
-        addl        $LockLocation, %edi\r
-        movb        $NotVacantFlag, %al\r
-TestLock:\r
-        xchgb       (%edi), %al\r
-        cmpb        $NotVacantFlag, %al\r
-        jz          TestLock\r
-\r
-ProgramStack:\r
+        #\r
+        # ProgramStack\r
+        #\r
+        movl        $0x1b, %ecx\r
+        rdmsr\r
+        andl        $0xfffff000, %eax\r
+        addl        $0x20, %eax\r
+        movl        (%eax), %ebx\r
+        shrl        $24, %ebx\r
+        \r
+        xorq        %rcx, %rcx\r
+        movl        %esi,%edi\r
+        addl        $ProcessorNumberLocation, %edi\r
+        movl        (%edi, %ebx, 4), %ecx\r
 \r
-        movl        %esi, %edi\r
-        addl        $StackSizeLocation, %edi \r
+        movl        %esi,%edi\r
+        addl        $StackSizeLocation, %edi\r
         movq        (%edi), %rax\r
-        movl        %esi, %edi\r
-        addl        $StackStartAddressLocation, %edi\r
-        addq        (%edi), %rax\r
-        movq        %rax, %rsp\r
-        movq        %rax, (%edi) \r
+        incq        %rcx\r
+        mulq        %rcx\r
 \r
-Releaselock:\r
+        movl        %esi,%edi\r
+        addl        $StackStartAddressLocation, %edi\r
+        movq        (%edi), %rbx\r
+        addq        %rbx, %rax\r
 \r
-        movb        $VacantFlag, %al\r
-        movl        %esi, %edi\r
-        addl        $LockLocation, %edi\r
-        xchgb       (%edi), %al\r
+        movq        %rax, %rsp\r
 \r
         #\r
         # Call C Function\r
index 91bdb224512410df8a18889798442d4add0460a6..5666322486f9aea6bb2792af638a86989915e147 100644 (file)
@@ -112,31 +112,33 @@ LongModeStart::
         mov         es,  ax\r
         mov         ss,  ax\r
 \r
+        ;\r
+        ; ProgramStack\r
+        ;\r
+        mov         ecx, 1bh                          ; Read IA32_APIC_BASE MSR\r
+        rdmsr\r
+        and         eax, 0fffff000h\r
+        add         eax, 20h\r
+        mov         ebx, dword ptr [eax]\r
+        shr         ebx, 24\r
+        \r
+        xor         rcx, rcx\r
         mov         edi, esi\r
-        add         edi, LockLocation\r
-        mov         al,  NotVacantFlag\r
-TestLock::\r
-        xchg        byte ptr [edi], al\r
-        cmp         al, NotVacantFlag\r
-        jz          TestLock\r
-\r
-ProgramStack::\r
+        add         edi, ProcessorNumberLocation\r
+        mov         ecx, dword ptr [edi + 4 * ebx]    ; RCX = CpuNumber\r
 \r
         mov         edi, esi\r
         add         edi, StackSizeLocation\r
         mov         rax, qword ptr [edi]\r
+        inc         rcx\r
+        mul         rcx                               ; RAX = StackSize * (CpuNumber + 1)\r
+\r
         mov         edi, esi\r
         add         edi, StackStartAddressLocation\r
-        add         rax, qword ptr [edi]\r
-        mov         rsp, rax\r
-        mov         qword ptr [edi], rax\r
-\r
-Releaselock::\r
+        mov         rbx, qword ptr [edi]\r
+        add         rax, rbx                          ; RAX = StackStart + StackSize * (CpuNumber + 1)\r
 \r
-        mov         al,  VacantFlag\r
-        mov         edi, esi\r
-        add         edi, LockLocation\r
-        xchg        byte ptr [edi], al\r
+        mov         rsp, rax\r
 \r
         ;\r
         ; Call C Function\r