Jordan,

I think we could ASSERT() if the actually processors number is larger than 
maximum number supported in system. 

Otherwise, send broadcast SMI or IPI may break the system.

Jeff
-----Original Message-----
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Jordan 
Justen
Sent: Thursday, October 29, 2015 9:33 AM
To: edk2-devel@lists.01.org
Cc: Justen, Jordan L; Laszlo Ersek; Fan, Jeff
Subject: [edk2] [PATCH 2/6] UefiCpuPkg/CpuDxe: Ignore extra APs in the system

The PcdCpuMaxLogicalProcessorNumber specifies the maximum number of logical 
processors which are expected to be seen by the system. If more APs actually 
are available in the system, we should prevent them from being used.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.jus...@intel.com>
Cc: Jeff Fan <jeff....@intel.com>
Cc: Laszlo Ersek <ler...@redhat.com>
---
 UefiCpuPkg/CpuDxe/CpuMp.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c index 
98fdfdf..e80835f 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.c
+++ b/UefiCpuPkg/CpuDxe/CpuMp.c
@@ -1196,6 +1196,17 @@ WhoAmI (
     }
   }
 
+  if (Index >= mMpSystemData.NumberOfProcessors) {
+    //
+    // This is not a valid error for the WhoAmI function, but it should never
+    // happen from outside the driver. It could only happen if more APs
+    // started than the PcdCpuMaxLogicalProcessorNumber was set to. This call
+    // would come from ApEntryPointInC, and we use this error to prevent the
+    // AP from being used by MP services.
+    //
+    return EFI_DEVICE_ERROR;
+  }
+
   *ProcessorNumber = Index;
   return EFI_SUCCESS;
 }
@@ -1446,10 +1457,15 @@ ApEntryPointInC (
   VOID
   )
 {
+  EFI_STATUS      Status;
   VOID*           TopOfApStack;
   UINTN           ProcessorNumber;
 
   if (!mAPsAlreadyInitFinished) {
+    if (mMpSystemData.NumberOfProcessors >= gMaxLogicalProcessorNumber) {
+      return;
+    }
+
     FillInProcessorInformation (FALSE, mMpSystemData.NumberOfProcessors);
     TopOfApStack  = (UINT8*)mApStackStart + gApStackSize;
     mApStackStart = TopOfApStack;
@@ -1461,7 +1477,11 @@ ApEntryPointInC (
     mMpSystemData.NumberOfProcessors++;
     mMpSystemData.NumberOfEnabledProcessors++;
   } else {
-    WhoAmI (&mMpServicesTemplate, &ProcessorNumber);
+    Status = WhoAmI (&mMpServicesTemplate, &ProcessorNumber);
+    if (EFI_ERROR (Status)) {
+      return;
+    }
+
     //
     // Get the original stack address.
     //
--
2.5.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to