From nobody Sun Apr 28 20:14:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1514536597297786.9443480826205; Fri, 29 Dec 2017 00:36:37 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1A27722280C44; Fri, 29 Dec 2017 00:31:38 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4431C221DB297 for ; Fri, 29 Dec 2017 00:31:37 -0800 (PST) Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Dec 2017 00:36:34 -0800 Received: from jwang36-mobl2.ccr.corp.intel.com ([10.239.192.38]) by fmsmga007.fm.intel.com with ESMTP; 29 Dec 2017 00:36:33 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,475,1508828400"; d="scan'208";a="5756088" From: Jian J Wang To: edk2-devel@lists.01.org Date: Fri, 29 Dec 2017 16:36:31 +0800 Message-Id: <20171229083631.16652-1-jian.j.wang@intel.com> X-Mailer: git-send-email 2.15.1.windows.2 Subject: [edk2] [PATCH] UefiCpuPkg/MpInitLib: fix wrong base address set as Stack Guard X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laszlo Ersek , Jiewen Yao , Eric Dong MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The reason is that DXE part initialization will reuse the stack allocated at PEI phase, if MP was initialized before. Some code added to check this situation and use stack base address saved in HOB passed from PEI. Cc: Jiewen Yao Cc: Eric Dong Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index 40c1bf407a..05484c9ff3 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -295,6 +295,7 @@ InitMpGlobalData ( UINTN Index; EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc; UINTN StackBase; + CPU_INFO_IN_HOB *CpuInfoInHob; =20 SaveCpuMpData (CpuMpData); =20 @@ -314,9 +315,18 @@ InitMpGlobalData ( ASSERT (FALSE); } =20 - for (Index =3D 0; Index < CpuMpData->CpuCount; ++Index) { - StackBase =3D CpuMpData->Buffer + Index * CpuMpData->CpuApStackSize; + // + // DXE will reuse stack allocated for APs at PEI phase if it's availab= le. + // Let's check it here. + // + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; + if (CpuInfoInHob !=3D NULL && CpuInfoInHob->ApTopOfStack !=3D 0) { + StackBase =3D CpuInfoInHob->ApTopOfStack; + } else { + StackBase =3D CpuMpData->Buffer; + } =20 + for (Index =3D 0; Index < CpuMpData->CpuCount; ++Index) { Status =3D gDS->GetMemorySpaceDescriptor (StackBase, &MemDesc); ASSERT_EFI_ERROR (Status); =20 @@ -326,6 +336,9 @@ InitMpGlobalData ( MemDesc.Attributes | EFI_MEMORY_RP ); ASSERT_EFI_ERROR (Status); + + DEBUG ((DEBUG_VERBOSE, "Stack Guard set at %x [cpu%d]!\n", StackBase= , Index)); + StackBase +=3D CpuMpData->CpuApStackSize; } } =20 --=20 2.15.1.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel