From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web11.5318.1672974731051931705 for ; Thu, 05 Jan 2023 19:12:11 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=Rc9aVrrI; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: yuanhao.xie@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672974731; x=1704510731; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8bHqCKBzG0OsXB3gdOBTDaNP+7jL52mEpgIPc/Ijp34=; b=Rc9aVrrIq+Fss7d3RVDLv8WXPnlecNzuosb4GFJ3031xj6oJ7zOKpNjv T4KL9Iqa746Nd2RbSWIyhP6P6N1pFkinSVqBVhoTJpmgWV0WV827NQw/k vJh09IhZRWaygvcQl3fuMwREF5cojy+s5ybm6YMnH4L/g9/JxXXaMrzZv uHrhBMCmry252zdSQDhA5LzyQKwCpDDpJzHtUj87OMAS3kikx6INFav1I PfPD0Ghku4v7sprcdRMAPRNxqJWHnsF8nuOvjOXHijxnV+NwOhfVf0mFe Y4fs6u3jL2dMViI3K1vkdFt4HbnMYxAsPkpS+4w28KuDOlLewT08ROBtk Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10581"; a="323642150" X-IronPort-AV: E=Sophos;i="5.96,304,1665471600"; d="scan'208";a="323642150" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2023 19:11:59 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10581"; a="686338628" X-IronPort-AV: E=Sophos;i="5.96,304,1665471600"; d="scan'208";a="686338628" Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.182.166]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2023 19:11:57 -0800 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar Subject: [Patch V2 2/2] UefiCpuPkg: Keep 4GB limitation of memory allocation Date: Fri, 6 Jan 2023 11:11:41 +0800 Message-Id: <20230106031141.460-2-yuanhao.xie@intel.com> X-Mailer: git-send-email 2.36.1.windows.1 In-Reply-To: <20230106031141.460-1-yuanhao.xie@intel.com> References: <20230106031141.460-1-yuanhao.xie@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Keep 4GB limitation of memory allocation if APs need transferring to 32bit mode before handoff to the OS. Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=4234 Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Signed-off-by: Yuanhao Xie --- UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c index acbbf155c0..e4c42e34ce 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -480,6 +480,7 @@ InitMpGlobalData ( EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc; UINTN StackBase; CPU_INFO_IN_HOB *CpuInfoInHob; + EFI_PHYSICAL_ADDRESS Address; SaveCpuMpData (CpuMpData); @@ -561,13 +562,25 @@ InitMpGlobalData ( ASSERT ((AP_SAFE_STACK_SIZE & (CPU_STACK_ALIGNMENT - 1)) == 0); mReservedApLoopFunc = (VOID *)(mReservedTopOfApStack + CpuMpData->CpuCount * AP_SAFE_STACK_SIZE); - if (StandardSignatureIsAuthenticAMD ()) { + if (StandardSignatureIsAuthenticAMD () && (sizeof (UINTN) == sizeof (UINT64))) { + Address = BASE_4GB - 1; + Status = gBS->AllocatePages ( + AllocateMaxAddress, + EfiReservedMemoryType, + EFI_SIZE_TO_PAGES (ApSafeBufferSize), + &Address + ); + ASSERT_EFI_ERROR (Status); + mReservedApLoopFunc = (VOID *)((UINTN)Address + CpuMpData->CpuCount * AP_SAFE_STACK_SIZE); CopyMem ( mReservedApLoopFunc, CpuMpData->AddressMap.RelocateApLoopFuncAddressAmd, CpuMpData->AddressMap.RelocateApLoopFuncSizeAmd ); } else { + Address = (UINTN)AllocateReservedPages (EFI_SIZE_TO_PAGES (ApSafeBufferSize)); + ASSERT (Address != 0); + mReservedApLoopFunc = (VOID *)((UINTN)Address + CpuMpData->CpuCount * AP_SAFE_STACK_SIZE); CopyMem ( mReservedApLoopFunc, CpuMpData->AddressMap.RelocateApLoopFuncAddress, @@ -575,12 +588,14 @@ InitMpGlobalData ( ); mApPageTable = CreatePageTable ( - mReservedTopOfApStack, + (UINTN)Address, ApSafeBufferSize ); } - mReservedTopOfApStack += CpuMpData->CpuCount * AP_SAFE_STACK_SIZE; + mReservedTopOfApStack = (UINTN)Address + CpuMpData->CpuCount * AP_SAFE_STACK_SIZE; + ASSERT ((mReservedTopOfApStack & (UINTN)(CPU_STACK_ALIGNMENT - 1)) == 0); + ASSERT ((AP_SAFE_STACK_SIZE & (CPU_STACK_ALIGNMENT - 1)) == 0); Status = gBS->CreateEvent ( EVT_TIMER | EVT_NOTIFY_SIGNAL, -- 2.36.1.windows.1