UefiCpuPkg/CpuFeature: Don't assume CpuS3DataDxe alloc RegisterTable

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>
This commit is contained in:
Ray Ni 2021-01-19 16:54:37 +01:00 committed by mergify[bot]
parent e843a21e23
commit cefad282fb

View File

@ -1,7 +1,7 @@
/** @file /** @file
CPU Register Table Library functions. CPU Register Table Library functions.
Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.<BR> Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
@ -937,12 +937,10 @@ GetAcpiCpuData (
EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer; EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer;
AcpiCpuData = (ACPI_CPU_DATA *) (UINTN) PcdGet64 (PcdCpuS3DataAddress); AcpiCpuData = (ACPI_CPU_DATA *) (UINTN) PcdGet64 (PcdCpuS3DataAddress);
if (AcpiCpuData != NULL) { if (AcpiCpuData == NULL) {
return AcpiCpuData;
}
AcpiCpuData = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (ACPI_CPU_DATA))); AcpiCpuData = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (ACPI_CPU_DATA)));
ASSERT (AcpiCpuData != NULL); ASSERT (AcpiCpuData != NULL);
ZeroMem (AcpiCpuData, sizeof (ACPI_CPU_DATA));
// //
// Set PcdCpuS3DataAddress to the base address of the ACPI_CPU_DATA structure // Set PcdCpuS3DataAddress to the base address of the ACPI_CPU_DATA structure
@ -952,7 +950,10 @@ GetAcpiCpuData (
GetNumberOfProcessor (&NumberOfCpus, &NumberOfEnabledProcessors); GetNumberOfProcessor (&NumberOfCpus, &NumberOfEnabledProcessors);
AcpiCpuData->NumberOfCpus = (UINT32)NumberOfCpus; AcpiCpuData->NumberOfCpus = (UINT32)NumberOfCpus;
}
if (AcpiCpuData->RegisterTable == 0 ||
AcpiCpuData->PreSmmInitRegisterTable == 0) {
// //
// Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable for all CPUs // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable for all CPUs
// //
@ -974,8 +975,13 @@ GetAcpiCpuData (
RegisterTable[NumberOfCpus + Index].AllocatedSize = 0; RegisterTable[NumberOfCpus + Index].AllocatedSize = 0;
RegisterTable[NumberOfCpus + Index].RegisterTableEntry = 0; RegisterTable[NumberOfCpus + Index].RegisterTableEntry = 0;
} }
if (AcpiCpuData->RegisterTable == 0) {
AcpiCpuData->RegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)RegisterTable; AcpiCpuData->RegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)RegisterTable;
}
if (AcpiCpuData->PreSmmInitRegisterTable == 0) {
AcpiCpuData->PreSmmInitRegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)(RegisterTable + NumberOfCpus); AcpiCpuData->PreSmmInitRegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)(RegisterTable + NumberOfCpus);
}
}
return AcpiCpuData; return AcpiCpuData;
} }