]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuFeature: Don't assume CpuS3DataDxe alloc RegisterTable
authorRay Ni <ray.ni@intel.com>
Tue, 19 Jan 2021 15:54:37 +0000 (16:54 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 20 Jan 2021 18:20:14 +0000 (18:20 +0000)
There are lots of fields in ACPI_CPU_DATA structure while only
followings are accessed by CpuFeature infra:
* NumberOfCpus
* PreSmmInitRegisterTable // pointer
* RegisterTable  // pointer
* CpuStatus
* ApLocation  // pointer

So it's possible that an implementation of CpuS3DataDxe doesn't
allocate memory for PreSmmInitRegisterTable/RegisterTable/ApLocation.

This patch handles the case when CpuS3DataDxe doesn't allocate
memory for PreSmmInitRegisterTable/RegisterTable.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3159
Signed-off-by: Ray Ni <ray.ni@intel.com>
[lersek@redhat.com: update CC list, add BZ reference, add my S-o-b]
[lersek@redhat.com: deal with RegisterTable and PreSmmInitRegisterTable
 being zero independently of each other; replacing the ASSERT()]
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20210119155440.2262-2-lersek@redhat.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c

index 4063d45760ad4094ce72226abcec6d21e5c7cee4..7bb92404027f08390cce30da30c3eacd5112de0d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   CPU Register Table Library functions.\r
 \r
-  Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -937,45 +937,51 @@ GetAcpiCpuData (
   EFI_PROCESSOR_INFORMATION            ProcessorInfoBuffer;\r
 \r
   AcpiCpuData = (ACPI_CPU_DATA *) (UINTN) PcdGet64 (PcdCpuS3DataAddress);\r
-  if (AcpiCpuData != NULL) {\r
-    return AcpiCpuData;\r
-  }\r
-\r
-  AcpiCpuData  = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (ACPI_CPU_DATA)));\r
-  ASSERT (AcpiCpuData != NULL);\r
+  if (AcpiCpuData == NULL) {\r
+    AcpiCpuData  = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (ACPI_CPU_DATA)));\r
+    ASSERT (AcpiCpuData != NULL);\r
+    ZeroMem (AcpiCpuData, sizeof (ACPI_CPU_DATA));\r
 \r
-  //\r
-  // Set PcdCpuS3DataAddress to the base address of the ACPI_CPU_DATA structure\r
-  //\r
-  Status = PcdSet64S (PcdCpuS3DataAddress, (UINT64)(UINTN)AcpiCpuData);\r
-  ASSERT_EFI_ERROR (Status);\r
+    //\r
+    // Set PcdCpuS3DataAddress to the base address of the ACPI_CPU_DATA structure\r
+    //\r
+    Status = PcdSet64S (PcdCpuS3DataAddress, (UINT64)(UINTN)AcpiCpuData);\r
+    ASSERT_EFI_ERROR (Status);\r
 \r
-  GetNumberOfProcessor (&NumberOfCpus, &NumberOfEnabledProcessors);\r
-  AcpiCpuData->NumberOfCpus = (UINT32)NumberOfCpus;\r
+    GetNumberOfProcessor (&NumberOfCpus, &NumberOfEnabledProcessors);\r
+    AcpiCpuData->NumberOfCpus = (UINT32)NumberOfCpus;\r
+  }\r
 \r
-  //\r
-  // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable for all CPUs\r
-  //\r
-  TableSize = 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE);\r
-  RegisterTable  = AllocatePages (EFI_SIZE_TO_PAGES (TableSize));\r
-  ASSERT (RegisterTable != NULL);\r
+  if (AcpiCpuData->RegisterTable == 0 ||\r
+      AcpiCpuData->PreSmmInitRegisterTable == 0) {\r
+    //\r
+    // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable for all CPUs\r
+    //\r
+    TableSize = 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE);\r
+    RegisterTable  = AllocatePages (EFI_SIZE_TO_PAGES (TableSize));\r
+    ASSERT (RegisterTable != NULL);\r
 \r
-  for (Index = 0; Index < NumberOfCpus; Index++) {\r
-    Status = GetProcessorInformation (Index, &ProcessorInfoBuffer);\r
-    ASSERT_EFI_ERROR (Status);\r
+    for (Index = 0; Index < NumberOfCpus; Index++) {\r
+      Status = GetProcessorInformation (Index, &ProcessorInfoBuffer);\r
+      ASSERT_EFI_ERROR (Status);\r
 \r
-    RegisterTable[Index].InitialApicId      = (UINT32)ProcessorInfoBuffer.ProcessorId;\r
-    RegisterTable[Index].TableLength        = 0;\r
-    RegisterTable[Index].AllocatedSize      = 0;\r
-    RegisterTable[Index].RegisterTableEntry = 0;\r
+      RegisterTable[Index].InitialApicId      = (UINT32)ProcessorInfoBuffer.ProcessorId;\r
+      RegisterTable[Index].TableLength        = 0;\r
+      RegisterTable[Index].AllocatedSize      = 0;\r
+      RegisterTable[Index].RegisterTableEntry = 0;\r
 \r
-    RegisterTable[NumberOfCpus + Index].InitialApicId      = (UINT32)ProcessorInfoBuffer.ProcessorId;\r
-    RegisterTable[NumberOfCpus + Index].TableLength        = 0;\r
-    RegisterTable[NumberOfCpus + Index].AllocatedSize      = 0;\r
-    RegisterTable[NumberOfCpus + Index].RegisterTableEntry = 0;\r
+      RegisterTable[NumberOfCpus + Index].InitialApicId      = (UINT32)ProcessorInfoBuffer.ProcessorId;\r
+      RegisterTable[NumberOfCpus + Index].TableLength        = 0;\r
+      RegisterTable[NumberOfCpus + Index].AllocatedSize      = 0;\r
+      RegisterTable[NumberOfCpus + Index].RegisterTableEntry = 0;\r
+    }\r
+    if (AcpiCpuData->RegisterTable == 0) {\r
+      AcpiCpuData->RegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)RegisterTable;\r
+    }\r
+    if (AcpiCpuData->PreSmmInitRegisterTable == 0) {\r
+      AcpiCpuData->PreSmmInitRegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)(RegisterTable + NumberOfCpus);\r
+    }\r
   }\r
-  AcpiCpuData->RegisterTable           = (EFI_PHYSICAL_ADDRESS)(UINTN)RegisterTable;\r
-  AcpiCpuData->PreSmmInitRegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)(RegisterTable + NumberOfCpus);\r
 \r
   return AcpiCpuData;\r
 }\r