[edk2-devel] [PATCH v1] UefiCpuPkg: Cpu feature data stored in memory may be migrated

Jason Lou posted 1 patch 2 years, 7 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/edk2 tags/patchew/20210929115329.1220-1-yun.lou@intel.com
There is a newer version of this series
UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[edk2-devel] [PATCH v1] UefiCpuPkg: Cpu feature data stored in memory may be migrated
Posted by Jason Lou 2 years, 7 months ago
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 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
index 6e2ab79518..e9eba64914 100644
--- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
+++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
@@ -153,7 +153,7 @@ 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);
   AcpiCpuData->CpuFeatureInitData.ApLocation = (EFI_PHYSICAL_ADDRESS)(UINTN)Location;
 
@@ -205,11 +205,11 @@ 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);
   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);
   CpuStatus->ThreadCountPerCore = (EFI_PHYSICAL_ADDRESS)(UINTN)ThreadCountPerCore;
 
-- 
2.28.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#81279): https://edk2.groups.io/g/devel/message/81279
Mute This Topic: https://groups.io/mt/85946317/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH v1] UefiCpuPkg: Cpu feature data stored in memory may be migrated
Posted by Ni, Ray 2 years, 7 months ago
Thanks for providing a very clear commit message.

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


> -----Original Message-----
> From: Lou, Yun <yun.lou@intel.com>
> Sent: Wednesday, September 29, 2021 7:53 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 v1] 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 | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
> b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
> index 6e2ab79518..e9eba64914 100644
> --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
> +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
> @@ -153,7 +153,7 @@ 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);
> 
>    AcpiCpuData->CpuFeatureInitData.ApLocation = (EFI_PHYSICAL_ADDRESS)(UINTN)Location;
> 
> 
> 
> @@ -205,11 +205,11 @@ 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);
> 
>    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);
> 
>    CpuStatus->ThreadCountPerCore = (EFI_PHYSICAL_ADDRESS)(UINTN)ThreadCountPerCore;
> 
> 
> 
> --
> 2.28.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#81284): https://edk2.groups.io/g/devel/message/81284
Mute This Topic: https://groups.io/mt/85946317/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH v1] UefiCpuPkg: Cpu feature data stored in memory may be migrated
Posted by Dong, Eric 2 years, 7 months ago
Hi,

Can you help to explain more why PeiAllocatePages does not have the problem while PeiAllocatePool has?

Thanks,
Eric

-----Original Message-----
From: Lou, Yun <yun.lou@intel.com> 
Sent: Wednesday, September 29, 2021 7:53 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 v1] 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 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
index 6e2ab79518..e9eba64914 100644
--- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
+++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
@@ -153,7 +153,7 @@ 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);

   AcpiCpuData->CpuFeatureInitData.ApLocation = (EFI_PHYSICAL_ADDRESS)(UINTN)Location;

 

@@ -205,11 +205,11 @@ 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);

   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);

   CpuStatus->ThreadCountPerCore = (EFI_PHYSICAL_ADDRESS)(UINTN)ThreadCountPerCore;

 

-- 
2.28.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#81287): https://edk2.groups.io/g/devel/message/81287
Mute This Topic: https://groups.io/mt/85946317/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH v1] UefiCpuPkg: Cpu feature data stored in memory may be migrated
Posted by Ni, Ray 2 years, 7 months ago
Eric,
it's related to how pool/page memory is allocated in PEI.

The PEI pool is allocated in HOB. HOB data is migrated by DXE core to a new location. The migration guarantees the HOB data is kept but doesn't fix up the ACPI_CPU_DATA pointer that points to the HOB data.

The PEI page is allocated between Phit->FreeMemoryTop and Phit->MemoryTop. The location is not changed in DXE.

Thanks,
Ray

> -----Original Message-----
> From: Dong, Eric <eric.dong@intel.com>
> Sent: Wednesday, September 29, 2021 10:36 PM
> To: Lou, Yun <yun.lou@intel.com>; devel@edk2.groups.io
> Cc: Ni, Ray <ray.ni@intel.com>; Laszlo Ersek <lersek@redhat.com>; Kumar, Rahul1 <rahul1.kumar@intel.com>
> Subject: RE: [PATCH v1] UefiCpuPkg: Cpu feature data stored in memory may be migrated
> 
> Hi,
> 
> Can you help to explain more why PeiAllocatePages does not have the problem while PeiAllocatePool has?
> 
> Thanks,
> Eric
> 
> -----Original Message-----
> From: Lou, Yun <yun.lou@intel.com>
> Sent: Wednesday, September 29, 2021 7:53 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 v1] 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 | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
> b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
> index 6e2ab79518..e9eba64914 100644
> --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
> +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c
> @@ -153,7 +153,7 @@ 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);
> 
>    AcpiCpuData->CpuFeatureInitData.ApLocation = (EFI_PHYSICAL_ADDRESS)(UINTN)Location;
> 
> 
> 
> @@ -205,11 +205,11 @@ 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);
> 
>    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);
> 
>    CpuStatus->ThreadCountPerCore = (EFI_PHYSICAL_ADDRESS)(UINTN)ThreadCountPerCore;
> 
> 
> 
> --
> 2.28.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#81322): https://edk2.groups.io/g/devel/message/81322
Mute This Topic: https://groups.io/mt/85946317/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-