From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web10.15979.1677651005289052489 for ; Tue, 28 Feb 2023 22:10:13 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=QTDoxn27; spf=pass (domain: intel.com, ip: 192.55.52.43, 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=1677651013; x=1709187013; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yifdom1Ro4qvnbV4deXm8yksU6CctMFW7Xuzs7K7qH0=; b=QTDoxn27DmEGidEaVBLPXYE1YXZppZBszwsg4DvMQRWoIFmRFOHW/01E zPwa/h9DU4dpa8HpzSkTrxTaU5QNdkIxqC3yd5bNd8bzJmwtzLbqNBRO3 QUo2NpjptfkWtI0sHV+PlFl+P2XoVW+qlrbBUhvZx4LWLrl0ZcRTD9As+ dkCpgi7bsXMk7I+Z4Ns1yH8OzxZ0sRvZjsabadsnB/pn0JPdtIy+DxyKl UgaHmsMH31n/UjIBjLNXEaoNTsPdyHL66XZgHFGjmFEBUoVD0F36dA7P3 aU+lYDNwuwshzR6uaJy3FXA7vEX21T1a3vF7LnF24xxWHMIFrcHnTKGUA Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10635"; a="420590682" X-IronPort-AV: E=Sophos;i="5.98,224,1673942400"; d="scan'208";a="420590682" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 22:10:13 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10635"; a="1003533726" X-IronPort-AV: E=Sophos;i="5.98,224,1673942400"; d="scan'208";a="1003533726" Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.55]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 22:10:11 -0800 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Guo Dong , Ray Ni , Sean Rhodes , James Lu , Gua Guo Subject: [Patch V4 3/8] UefiCpuPkg: Allocate contiguous memory for stacks and APs loop. Date: Wed, 1 Mar 2023 14:09:49 +0800 Message-Id: <20230301060954.1464-4-yuanhao.xie@intel.com> X-Mailer: git-send-email 2.36.1.windows.1 In-Reply-To: <20230301060954.1464-1-yuanhao.xie@intel.com> References: <20230301060954.1464-1-yuanhao.xie@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Guo Dong Cc: Ray Ni Cc: Sean Rhodes Cc: James Lu Cc: Gua Guo Signed-off-by: Yuanhao Xie --- UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c index e9ac858f4f..224215878c 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -480,11 +480,12 @@ InitMpGlobalData ( { EFI_STATUS Status; EFI_PHYSICAL_ADDRESS Address; - UINTN ApSafeBufferSize; UINTN Index; EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc; UINTN StackBase; CPU_INFO_IN_HOB *CpuInfoInHob; + UINTN StackPages; + UINTN FuncPages; SaveCpuMpData (CpuMpData); @@ -547,16 +548,23 @@ InitMpGlobalData ( // Allocating it in advance since memory services are not available in // Exit Boot Services callback function. // - ApSafeBufferSize = EFI_PAGES_TO_SIZE ( - EFI_SIZE_TO_PAGES ( - CpuMpData->AddressMap.RelocateApLoopFuncSize - ) - ); + // +------------+ (TopOfApStack) + // | Stack * N | + // +------------+ (stack base, 4k aligned) + // | Padding | + // +------------+ + // | Ap Loop | + // +------------+ ((low address, 4k-aligned) + // + + StackPages = EFI_SIZE_TO_PAGES (CpuMpData->CpuCount * AP_SAFE_STACK_SIZE); + FuncPages = EFI_SIZE_TO_PAGES (CpuMpData->AddressMap.RelocateApLoopFuncSize); + Address = BASE_4GB - 1; Status = gBS->AllocatePages ( AllocateMaxAddress, EfiReservedMemoryType, - EFI_SIZE_TO_PAGES (ApSafeBufferSize), + StackPages + FuncPages, &Address ); ASSERT_EFI_ERROR (Status); @@ -575,26 +583,12 @@ InitMpGlobalData ( if (!EFI_ERROR (Status)) { gDS->SetMemorySpaceAttributes ( Address, - ApSafeBufferSize, + EFI_PAGES_TO_SIZE (FuncPages), MemDesc.Attributes & (~EFI_MEMORY_XP) ); } - ApSafeBufferSize = EFI_PAGES_TO_SIZE ( - EFI_SIZE_TO_PAGES ( - CpuMpData->CpuCount * AP_SAFE_STACK_SIZE - ) - ); - Address = BASE_4GB - 1; - Status = gBS->AllocatePages ( - AllocateMaxAddress, - EfiReservedMemoryType, - EFI_SIZE_TO_PAGES (ApSafeBufferSize), - &Address - ); - ASSERT_EFI_ERROR (Status); - - mReservedTopOfApStack = (UINTN)Address + ApSafeBufferSize; + mReservedTopOfApStack = (UINTN)Address + EFI_PAGES_TO_SIZE (StackPages+FuncPages); ASSERT ((mReservedTopOfApStack & (UINTN)(CPU_STACK_ALIGNMENT - 1)) == 0); CopyMem ( mReservedApLoop.Data, -- 2.36.1.windows.1