From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web09.8858.1632983198807559275 for ; Wed, 29 Sep 2021 23:26:38 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: yun.lou@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10122"; a="204596615" X-IronPort-AV: E=Sophos;i="5.85,335,1624345200"; d="scan'208";a="204596615" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2021 23:26:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,335,1624345200"; d="scan'208";a="520225581" Received: from shwdeopenlab102.ccr.corp.intel.com ([10.239.183.74]) by fmsmga008.fm.intel.com with ESMTP; 29 Sep 2021 23:26:31 -0700 From: "Jason Lou" To: devel@edk2.groups.io Cc: Jason , Ray Ni , Eric Dong , Laszlo Ersek , Rahul Kumar Subject: [PATCH v2] UefiCpuPkg: Cpu feature data stored in memory may be migrated Date: Thu, 30 Sep 2021 14:26:24 +0800 Message-Id: <20210930062624.1425-1-yun.lou@intel.com> X-Mailer: git-send-email 2.28.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3634 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 Cc: Ray Ni Cc: Eric Dong Cc: Laszlo Ersek Cc: Rahul Kumar --- UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c | 9 ++++= ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitializ= e.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=3D AcpiCpuData;=0D =0D CpuStatus =3D &AcpiCpuData->CpuFeatureInitData.CpuStatus;=0D - Location =3D AllocateZeroPool (sizeof (EFI_CPU_PHYSICAL_LOCATION) * Numb= erOfCpus);=0D + Location =3D AllocatePages (EFI_SIZE_TO_PAGES (sizeof (EFI_CPU_PHYSICAL_= LOCATION) * NumberOfCpus));=0D ASSERT (Location !=3D NULL);=0D + ZeroMem (Location, sizeof (EFI_CPU_PHYSICAL_LOCATION) * NumberOfCpus);=0D AcpiCpuData->CpuFeatureInitData.ApLocation =3D (EFI_PHYSICAL_ADDRESS)(UI= NTN)Location;=0D =0D for (ProcessorNumber =3D 0; ProcessorNumber < NumberOfCpus; ProcessorNum= ber++) {=0D @@ -205,12 +206,14 @@ CpuInitDataInitialize ( //=0D // Collect valid core count in each package because not all cores are va= lid.=0D //=0D - ThreadCountPerPackage =3D AllocateZeroPool (sizeof (UINT32) * CpuStatus-= >PackageCount);=0D + ThreadCountPerPackage =3D AllocatePages (EFI_SIZE_TO_PAGES (sizeof (UINT= 32) * CpuStatus->PackageCount));=0D ASSERT (ThreadCountPerPackage !=3D NULL);=0D + ZeroMem (ThreadCountPerPackage, sizeof (UINT32) * CpuStatus->PackageCoun= t);=0D CpuStatus->ThreadCountPerPackage =3D (EFI_PHYSICAL_ADDRESS)(UINTN)Thread= CountPerPackage;=0D =0D - ThreadCountPerCore =3D AllocateZeroPool (sizeof (UINT8) * CpuStatus->Pac= kageCount * CpuStatus->MaxCoreCount);=0D + ThreadCountPerCore =3D AllocatePages (EFI_SIZE_TO_PAGES (sizeof (UINT8) = * CpuStatus->PackageCount * CpuStatus->MaxCoreCount));=0D ASSERT (ThreadCountPerCore !=3D NULL);=0D + ZeroMem (ThreadCountPerCore, sizeof (UINT8) * CpuStatus->PackageCount * = CpuStatus->MaxCoreCount);=0D CpuStatus->ThreadCountPerCore =3D (EFI_PHYSICAL_ADDRESS)(UINTN)ThreadCou= ntPerCore;=0D =0D for (ProcessorNumber =3D 0; ProcessorNumber < NumberOfCpus; ProcessorNum= ber++) {=0D --=20 2.28.0.windows.1