From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 3EDB2AC10F6 for ; Thu, 23 May 2024 09:26:20 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=2HL3hlEngIzrnzIr7W228IgC9Mldsavdy0BOf1KNNYA=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1716456378; v=1; b=T5+8cjvYIq2eCGymGjwmrWeGOgx8v1958XIwSbv2gXtyJw5Z8lDEIWq4nvcn1CN2Ud8DIGKO eXu2xxKnVPit8jtT3wNyttDU1yLV5+YzdZbP4kpOWRnSOsgWV+jZsjOMLzNdHC0kp7iqIhzVNMy VmonCdrBHJoxduRiUMItoXG9sNYHn/u5/IusJikty0lfDsMU4Uy5HXBAzN6Tn8ngUL7R+FCHBCB WsM/zqZl/UqEtmw8j0HN7uvhEi5urf8fZjtIGgq+UDBH2fcGLCFKir3da0OsrgAbj32qxsda3tt Sb4G8kQgGbF4Jkt88CojoPUyS/4FJfNjnuH410dqzYIJQ== X-Received: by 127.0.0.2 with SMTP id 8fHoYY7687511xCeAMTUxjRr; Thu, 23 May 2024 02:26:18 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) by mx.groups.io with SMTP id smtpd.web11.12684.1716456378036498618 for ; Thu, 23 May 2024 02:26:18 -0700 X-CSE-ConnectionGUID: RNi+fm8JQuuuFhFVaDorGQ== X-CSE-MsgGUID: nyMa+YJ5T+yR0/v4EWO1FQ== X-IronPort-AV: E=McAfee;i="6600,9927,11080"; a="15708793" X-IronPort-AV: E=Sophos;i="6.08,182,1712646000"; d="scan'208";a="15708793" X-Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2024 02:26:18 -0700 X-CSE-ConnectionGUID: a9uy4nBTQaysHb1/6VBC5g== X-CSE-MsgGUID: Ah7MZMISQ5eRSORk+e0CXA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,182,1712646000"; d="scan'208";a="34070225" X-Received: from unknown (HELO shsse002.sh.intel.com) ([10.239.132.247]) by orviesa006.jf.intel.com with ESMTP; 23 May 2024 02:26:16 -0700 From: "Ning Feng" To: devel@edk2.groups.io Cc: Ning Feng , Ray Ni Subject: [edk2-devel] [PATCH] Pkg-Module:UefiCpuPkg/MpLib Date: Thu, 23 May 2024 13:51:08 -0400 Message-Id: <20240523175108.3820008-1-ning.feng@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Thu, 23 May 2024 02:26:18 -0700 Resent-From: ning.feng@intel.com Reply-To: devel@edk2.groups.io,ning.feng@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: H3vevO6LZsCPtybTaDInhTFKx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=T5+8cjvY; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D4778 MPInitlib have wrong expectation that bsp id should always be 0 in MpInitLibInitialize(), SwitchBsp(),ApWakeupFunction(). That will cause the data mismatch, if the initial bsp is not 0. Use CpuMpData->BspNumber insted of index 0 to avoid the issue. Cc: Ray Ni Signed-off-by: Ning Feng --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 34 ++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index d724456502..ae279c6ceb 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -114,6 +114,10 @@ FutureBSPProc ( SaveVolatileRegisters (&DataInHob->APInfo.VolatileRegisters);=0D AsmExchangeRole (&DataInHob->APInfo, &DataInHob->BSPInfo);=0D RestoreVolatileRegisters (&DataInHob->APInfo.VolatileRegisters, FALSE);= =0D + //=0D + // Restore VolatileReg saved in CpuMpData->CpuData=0D + //=0D + CopyMem (&DataInHob->CpuData[DataInHob->BspNumber].VolatileRegisters, &D= ataInHob->APInfo.VolatileRegisters, sizeof (CPU_VOLATILE_REGISTERS));=0D }=0D =0D /**=0D @@ -761,11 +765,11 @@ ApWakeupFunction ( BistData =3D (UINT32)ApStackData->Bist;=0D =0D //=0D - // CpuMpData->CpuData[0].VolatileRegisters is initialized based on B= SP environment,=0D + // CpuMpData->CpuData[BspNumber].VolatileRegisters is initialized ba= sed on BSP environment,=0D // to initialize AP in InitConfig path.=0D - // NOTE: IDTR.BASE stored in CpuMpData->CpuData[0].VolatileRegisters= points to a different IDT shared by all APs.=0D + // NOTE: IDTR.BASE stored in CpuMpData->CpuData[BspNumber].VolatileR= egisters points to a different IDT shared by all APs.=0D //=0D - RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, = FALSE);=0D + RestoreVolatileRegisters (&CpuMpData->CpuData[CpuMpData->BspNumber].= VolatileRegisters, FALSE);=0D InitializeApData (CpuMpData, ProcessorNumber, BistData, ApTopOfStack= );=0D ApStartupSignalBuffer =3D CpuMpData->CpuData[ProcessorNumber].Startu= pApSignal;=0D } else {=0D @@ -798,10 +802,10 @@ ApWakeupFunction ( // 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 + // NOTE: IDTR.BASE stored in CpuMpData->CpuData[BspNumber].Volatil= eRegisters points to a=0D // different IDT shared by all APs.=0D //=0D - RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters= , FALSE);=0D + RestoreVolatileRegisters (&CpuMpData->CpuData[CpuMpData->BspNumber= ].VolatileRegisters, FALSE);=0D } else {=0D if (CpuMpData->ApLoopMode =3D=3D ApInHltLoop) {=0D //=0D @@ -927,7 +931,7 @@ DxeApEntryPoint ( AsmWriteMsr64 (MSR_IA32_EFER, EferMsr.Uint64);=0D }=0D =0D - RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, FALS= E);=0D + RestoreVolatileRegisters (&CpuMpData->CpuData[CpuMpData->BspNumber].Vola= tileRegisters, FALSE);=0D InterlockedIncrement ((UINT32 *)&CpuMpData->FinishedCount);=0D PlaceAPInMwaitLoopOrRunLoop (=0D CpuMpData->ApLoopMode,=0D @@ -2151,7 +2155,12 @@ MpInitLibInitialize ( CpuMpData->BackupBufferSize =3D ApResetVectorSizeBelow1Mb;=0D CpuMpData->WakeupBuffer =3D (UINTN)-1;=0D CpuMpData->CpuCount =3D 1;=0D - CpuMpData->BspNumber =3D 0;=0D + if (MpHandOff =3D=3D NULL) {=0D + CpuMpData->BspNumber =3D 0;=0D + } else {=0D + CpuMpData->BspNumber =3D GetBspNumber (MpHandOff);=0D + }=0D +=0D CpuMpData->WaitEvent =3D NULL;=0D CpuMpData->SwitchBspFlag =3D FALSE;=0D CpuMpData->CpuData =3D (CPU_AP_DATA *)(CpuMpData + 1);=0D @@ -2186,11 +2195,11 @@ MpInitLibInitialize ( // Don't pass BSP's TR to APs to avoid AP init failure.=0D //=0D VolatileRegisters.Tr =3D 0;=0D - CopyMem (&CpuMpData->CpuData[0].VolatileRegisters, &VolatileRegisters, s= izeof (VolatileRegisters));=0D + CopyMem (&CpuMpData->CpuData[CpuMpData->BspNumber].VolatileRegisters, &V= olatileRegisters, sizeof (VolatileRegisters));=0D //=0D // Set BSP basic information=0D //=0D - InitializeApData (CpuMpData, 0, 0, CpuMpData->Buffer + ApStackSize);=0D + InitializeApData (CpuMpData, CpuMpData->BspNumber, 0, CpuMpData->Buffer = + ApStackSize * (CpuMpData->BspNumber + 1));=0D //=0D // Save assembly code information=0D //=0D @@ -2615,7 +2624,12 @@ SwitchBSPWorker ( SaveVolatileRegisters (&CpuMpData->BSPInfo.VolatileRegisters);=0D AsmExchangeRole (&CpuMpData->BSPInfo, &CpuMpData->APInfo);=0D RestoreVolatileRegisters (&CpuMpData->BSPInfo.VolatileRegisters, FALSE);= =0D -=0D + //=0D + // Restore VolatileRegs saved in CpuMpData->CpuData=0D + // Don't pass BSP's TR to APs to avoid AP init failure.=0D + //=0D + CopyMem (&CpuMpData->CpuData[CpuMpData->NewBspNumber].VolatileRegisters,= &CpuMpData->BSPInfo.VolatileRegisters, sizeof (CPU_VOLATILE_REGISTERS));=0D + CpuMpData->CpuData[CpuMpData->NewBspNumber].VolatileRegisters.Tr =3D 0;= =0D //=0D // Set the BSP bit of MSR_IA32_APIC_BASE on new BSP=0D //=0D --=20 2.25.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#119139): https://edk2.groups.io/g/devel/message/119139 Mute This Topic: https://groups.io/mt/106256300/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-