From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com []) by mx.groups.io with SMTP id smtpd.web10.2068.1587718061391966965 for ; Fri, 24 Apr 2020 01:47:41 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: eric.dong@intel.com) IronPort-SDR: g2IC3vxY3ehjnYOCYkXO1rXF05eTyVAvUApC9RqByRqGZ1pIY1TUQXWNPKx/3IErwxGFEBZh3B dBtG4uZOReIA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2020 01:47:39 -0700 IronPort-SDR: yqB3rUwz6FKEpFjO2Ofb9edVDjkqpp47kUfxA/W90baoDMRwCKn9hNxqnuDa2gPQflxfeFOSmE XrMMDHZok+/w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,311,1583222400"; d="scan'208";a="457837073" Received: from ydong10-desktop.ccr.corp.intel.com ([10.239.158.133]) by fmsmga006.fm.intel.com with ESMTP; 24 Apr 2020 01:47:20 -0700 From: "Dong, Eric" To: devel@edk2.groups.io Cc: Ray Ni , Laszlo Ersek , Chandana Kumar Subject: [PATCH v3 1/2] UefiCpuPkg/MpInitLib: Restore IDT context for APs. Date: Fri, 24 Apr 2020 16:47:15 +0800 Message-Id: <20200424084716.877-2-eric.dong@intel.com> X-Mailer: git-send-email 2.23.0.windows.1 In-Reply-To: <20200424084716.877-1-eric.dong@intel.com> References: <20200424084716.877-1-eric.dong@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2683 This patch fixes an assertion because AP can't find the CpuMpData. When AP is waken up through Init-Sipi-Sipi, AP's IDT should be restored to pre-allocated buffer so AP can get the CpuMpData through the IDT base address. Current code already has logic to handle this when CpuMpData-> InitFlag is ApInitConfig but misses the logic when CpuMpData->InitFlag is ApInitReconfig. This patch fixes this gap. Cc: Ray Ni Cc: Laszlo Ersek Cc: Chandana Kumar Signed-off-by: Eric Dong ---=0D V3:=0D Remove invalid save volatile registers process. Refine restore=0D volatile registers process.=0D =0D V2: =0D Enhance code to remove CpuMpData->ApLoopMode =3D=3D ApInHltLoop check. =0D UefiCpuPkg/Library/MpInitLib/MpLib.c | 34 +++++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 64a4c3546e..7fd757b428 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -686,18 +686,31 @@ ApWakeupFunction ( WAKEUP_AP_SIGNAL,=0D 0=0D );=0D - if (CpuMpData->ApLoopMode =3D=3D ApInHltLoop) {=0D - //=0D - // Restore AP's volatile registers saved=0D - //=0D - RestoreVolatileRegisters (&CpuMpData->CpuData[ProcessorNumber].Vol= atileRegisters, TRUE);=0D - } else {=0D +=0D + if (CpuMpData->InitFlag =3D=3D ApInitReconfig) {=0D //=0D - // The CPU driver might not flush TLB for APs on spot after updati= ng=0D - // page attributes. AP in mwait loop mode needs to take care of it= when=0D - // woken up.=0D + // ApInitReconfig happens when:=0D + // 1. AP is re-enabled after it's disabled, in either PEI or DXE p= hase.=0D + // 2. AP is initialized in DXE phase. =0D + // In either case, use the volatile registers value derived from B= SP.=0D + // NOTE: IDTR.BASE stored in CpuMpData->CpuData[0].VolatileRegiste= rs points to a=0D + // different IDT shared by all APs.=0D //=0D - CpuFlushTlb ();=0D + RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters= , FALSE);=0D + } else {=0D + if (CpuMpData->ApLoopMode =3D=3D ApInHltLoop) {=0D + //=0D + // Restore AP's volatile registers saved before AP is halted=0D + //=0D + RestoreVolatileRegisters (&CpuMpData->CpuData[ProcessorNumber].V= olatileRegisters, TRUE);=0D + } else {=0D + //=0D + // The CPU driver might not flush TLB for APs on spot after upda= ting=0D + // page attributes. AP in mwait loop mode needs to take care of = it when=0D + // woken up.=0D + //=0D + CpuFlushTlb ();=0D + }=0D }=0D =0D if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) =3D=3D CpuStat= eReady) {=0D @@ -1780,7 +1793,6 @@ MpInitLibInitialize ( InitializeSpinLock(&CpuMpData->CpuData[Index].ApLock);=0D CpuMpData->CpuData[Index].CpuHealthy =3D (CpuInfoInHob[Index].Health= =3D=3D 0)? TRUE:FALSE;=0D CpuMpData->CpuData[Index].ApFunction =3D 0;=0D - CopyMem (&CpuMpData->CpuData[Index].VolatileRegisters, &VolatileRegi= sters, sizeof (CPU_VOLATILE_REGISTERS));=0D }=0D }=0D =0D --=20 2.23.0.windows.1