public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2] UefiCpuPkg: Cpu feature data stored in memory may be migrated
@ 2021-09-30  6:26 Jason Lou
  2021-09-30  6:29 ` [edk2-devel] " Jason Lou
  2021-09-30  7:21 ` Ni, Ray
  0 siblings, 2 replies; 3+ messages in thread
From: Jason Lou @ 2021-09-30  6:26 UTC (permalink / raw)
  To: devel; +Cc: Jason, Ray Ni, Eric Dong, Laszlo Ersek, Rahul Kumar

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3634

The memory allocated through "PeiAllocatePool" is located in HOB, and
in DXE phase, the HOB will be migrated to a different location.
After the migration, the data stored in the HOB stays the same, but the
address of pointer to the memory(such as the pointers in ACPI_CPU_DATA
structure) changes, which may cause "PiSmmCpuDxeSmm" driver can't find
the memory(the pointers in ACPI_CPU_DATA structure) that allocated in
"PeiRegisterCpuFeaturesLib", so use "PeiAllocatePages" to allocate
memory instead.

Signed-off-by: Jason Lou <yun.lou@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
---
 UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
index 6e2ab79518..a6534436a7 100644
--- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
+++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
@@ -153,8 +153,9 @@ CpuInitDataInitialize (
   CpuFeaturesData->AcpiCpuData= AcpiCpuData;
 
   CpuStatus = &AcpiCpuData->CpuFeatureInitData.CpuStatus;
-  Location = AllocateZeroPool (sizeof (EFI_CPU_PHYSICAL_LOCATION) * NumberOfCpus);
+  Location = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (EFI_CPU_PHYSICAL_LOCATION) * NumberOfCpus));
   ASSERT (Location != NULL);
+  ZeroMem (Location, sizeof (EFI_CPU_PHYSICAL_LOCATION) * NumberOfCpus);
   AcpiCpuData->CpuFeatureInitData.ApLocation = (EFI_PHYSICAL_ADDRESS)(UINTN)Location;
 
   for (ProcessorNumber = 0; ProcessorNumber < NumberOfCpus; ProcessorNumber++) {
@@ -205,12 +206,14 @@ CpuInitDataInitialize (
   //
   // Collect valid core count in each package because not all cores are valid.
   //
-  ThreadCountPerPackage = AllocateZeroPool (sizeof (UINT32) * CpuStatus->PackageCount);
+  ThreadCountPerPackage = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (UINT32) * CpuStatus->PackageCount));
   ASSERT (ThreadCountPerPackage != NULL);
+  ZeroMem (ThreadCountPerPackage, sizeof (UINT32) * CpuStatus->PackageCount);
   CpuStatus->ThreadCountPerPackage = (EFI_PHYSICAL_ADDRESS)(UINTN)ThreadCountPerPackage;
 
-  ThreadCountPerCore = AllocateZeroPool (sizeof (UINT8) * CpuStatus->PackageCount * CpuStatus->MaxCoreCount);
+  ThreadCountPerCore = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (UINT8) * CpuStatus->PackageCount * CpuStatus->MaxCoreCount));
   ASSERT (ThreadCountPerCore != NULL);
+  ZeroMem (ThreadCountPerCore, sizeof (UINT8) * CpuStatus->PackageCount * CpuStatus->MaxCoreCount);
   CpuStatus->ThreadCountPerCore = (EFI_PHYSICAL_ADDRESS)(UINTN)ThreadCountPerCore;
 
   for (ProcessorNumber = 0; ProcessorNumber < NumberOfCpus; ProcessorNumber++) {
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] [PATCH v2] UefiCpuPkg: Cpu feature data stored in memory may be migrated
  2021-09-30  6:26 [PATCH v2] UefiCpuPkg: Cpu feature data stored in memory may be migrated Jason Lou
@ 2021-09-30  6:29 ` Jason Lou
  2021-09-30  7:21 ` Ni, Ray
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Lou @ 2021-09-30  6:29 UTC (permalink / raw)
  To: Jason Lou, devel

[-- Attachment #1: Type: text/plain, Size: 79 bytes --]

This new patch adds memory pages initialization( ZeroMem ) based on patch v1.

[-- Attachment #2: Type: text/html, Size: 121 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] UefiCpuPkg: Cpu feature data stored in memory may be migrated
  2021-09-30  6:26 [PATCH v2] UefiCpuPkg: Cpu feature data stored in memory may be migrated Jason Lou
  2021-09-30  6:29 ` [edk2-devel] " Jason Lou
@ 2021-09-30  7:21 ` Ni, Ray
  1 sibling, 0 replies; 3+ messages in thread
From: Ni, Ray @ 2021-09-30  7:21 UTC (permalink / raw)
  To: Lou, Yun, devel@edk2.groups.io; +Cc: Dong, Eric, Laszlo Ersek, Kumar, Rahul1

Reviewed-by: Ray Ni <ray.ni@intel.com>

> -----Original Message-----
> From: Lou, Yun <yun.lou@intel.com>
> Sent: Thursday, September 30, 2021 2:26 PM
> To: devel@edk2.groups.io
> Cc: Lou, Yun <yun.lou@intel.com>; Ni, Ray <ray.ni@intel.com>; Dong, Eric <eric.dong@intel.com>; Laszlo Ersek
> <lersek@redhat.com>; Kumar, Rahul1 <rahul1.kumar@intel.com>
> Subject: [PATCH v2] UefiCpuPkg: Cpu feature data stored in memory may be migrated
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3634
> 
> The memory allocated through "PeiAllocatePool" is located in HOB, and
> in DXE phase, the HOB will be migrated to a different location.
> After the migration, the data stored in the HOB stays the same, but the
> address of pointer to the memory(such as the pointers in ACPI_CPU_DATA
> structure) changes, which may cause "PiSmmCpuDxeSmm" driver can't find
> the memory(the pointers in ACPI_CPU_DATA structure) that allocated in
> "PeiRegisterCpuFeaturesLib", so use "PeiAllocatePages" to allocate
> memory instead.
> 
> Signed-off-by: Jason Lou <yun.lou@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> ---
>  UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
> b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
> index 6e2ab79518..a6534436a7 100644
> --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
> +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
> @@ -153,8 +153,9 @@ CpuInitDataInitialize (
>    CpuFeaturesData->AcpiCpuData= AcpiCpuData;
> 
> 
> 
>    CpuStatus = &AcpiCpuData->CpuFeatureInitData.CpuStatus;
> 
> -  Location = AllocateZeroPool (sizeof (EFI_CPU_PHYSICAL_LOCATION) * NumberOfCpus);
> 
> +  Location = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (EFI_CPU_PHYSICAL_LOCATION) * NumberOfCpus));
> 
>    ASSERT (Location != NULL);
> 
> +  ZeroMem (Location, sizeof (EFI_CPU_PHYSICAL_LOCATION) * NumberOfCpus);
> 
>    AcpiCpuData->CpuFeatureInitData.ApLocation = (EFI_PHYSICAL_ADDRESS)(UINTN)Location;
> 
> 
> 
>    for (ProcessorNumber = 0; ProcessorNumber < NumberOfCpus; ProcessorNumber++) {
> 
> @@ -205,12 +206,14 @@ CpuInitDataInitialize (
>    //
> 
>    // Collect valid core count in each package because not all cores are valid.
> 
>    //
> 
> -  ThreadCountPerPackage = AllocateZeroPool (sizeof (UINT32) * CpuStatus->PackageCount);
> 
> +  ThreadCountPerPackage = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (UINT32) * CpuStatus->PackageCount));
> 
>    ASSERT (ThreadCountPerPackage != NULL);
> 
> +  ZeroMem (ThreadCountPerPackage, sizeof (UINT32) * CpuStatus->PackageCount);
> 
>    CpuStatus->ThreadCountPerPackage = (EFI_PHYSICAL_ADDRESS)(UINTN)ThreadCountPerPackage;
> 
> 
> 
> -  ThreadCountPerCore = AllocateZeroPool (sizeof (UINT8) * CpuStatus->PackageCount * CpuStatus->MaxCoreCount);
> 
> +  ThreadCountPerCore = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (UINT8) * CpuStatus->PackageCount * CpuStatus-
> >MaxCoreCount));
> 
>    ASSERT (ThreadCountPerCore != NULL);
> 
> +  ZeroMem (ThreadCountPerCore, sizeof (UINT8) * CpuStatus->PackageCount * CpuStatus->MaxCoreCount);
> 
>    CpuStatus->ThreadCountPerCore = (EFI_PHYSICAL_ADDRESS)(UINTN)ThreadCountPerCore;
> 
> 
> 
>    for (ProcessorNumber = 0; ProcessorNumber < NumberOfCpus; ProcessorNumber++) {
> 
> --
> 2.28.0.windows.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-30  7:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-30  6:26 [PATCH v2] UefiCpuPkg: Cpu feature data stored in memory may be migrated Jason Lou
2021-09-30  6:29 ` [edk2-devel] " Jason Lou
2021-09-30  7:21 ` Ni, Ray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox