From nobody Sun May 19 01:26:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106460+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106460+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1687942153; cv=none; d=zohomail.com; s=zohoarc; b=H4+TES/HH1fbMi4d9BF9/uTCnmo040Ln1YWEsY9r/+BPehJeW4ojiv8ATGnPiKTiIUwhw4iXfPcENf3M6ko1BKS7x9LolOPbCJxbm2JdlNzXWeUBRCUBLKdGdfR2bC6vTLH0mfCTcsbHdfWLqvtw7/RtjBGjuUSMNcBHiEB7r1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687942153; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=zjcwtMv5MTQqP6bTyiPrPkPsGoxy0bZ5G6dZULRmWt8=; b=M6vnnLCgP4iNozv3utNm+PikvMpkPgYPKts/lrW0vuVZNMyzBmHFocbQy1tiQAXlt/QCAR6VinrNxlCEab0I/sIupx6Ox23stqrH7cbIcMIDYGXXnitp0cvPcR++ACNazZSKLpDcACsh34ZEwlIWcgkTM+bn5/uPmIRiCKwolIo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106460+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1687942153314582.6181309203615; Wed, 28 Jun 2023 01:49:13 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id vnIUYY1788612xRFB3kcKh2D; Wed, 28 Jun 2023 01:49:13 -0700 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.11788.1687942151408549511 for ; Wed, 28 Jun 2023 01:49:11 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="341373507" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="341373507" X-Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 01:47:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="890964557" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="890964557" X-Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.55]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 01:47:45 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Eric Dong , Ray Ni , Rahul Kumar , Tom Lendacky , Yuanhao Xie Subject: [edk2-devel] [Patch V4 1/5] UefiCpuPkg: Refactor the logic for placing APs in HltLoop. Date: Wed, 28 Jun 2023 16:47:20 +0800 Message-Id: <20230628084724.57574-2-yuanhao.xie@intel.com> In-Reply-To: <20230628084724.57574-1-yuanhao.xie@intel.com> References: <20230628084724.57574-1-yuanhao.xie@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yuanhao.xie@intel.com X-Gm-Message-State: 5JVKpXuNOYWpbAPSmq5dwBhqx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1687942153; bh=ZGP1DuJ/wBZ+0Pj9hpBKkffd5zAP3Gjz+BXwGyzRcQ4=; h=Cc:Date:From:Reply-To:Subject:To; b=upB4sHPSvukikDwob3+Td8h0y5zhYlsVIVE1td1CbhxG+db2plsC/psw1tCbaBmbiC6 0VRP/OGa9cwmyiyu5Itngd/yIEbngVreez3YLpyJlbmMRNK/Ziz/JkWAjsWuV5rsQwDEl Y8KZx6QM76wkUwAIchTjmG93velize7k8OE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1687942153753100002 Content-Type: text/plain; charset="utf-8" Refactor the logic for placing APs in HltLoop into a separate function. Cc: Gerd Hoffmann Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Tom Lendacky Signed-off-by: Yuanhao Xie Reviewed-by: Ray Ni --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 35 ++++++++++++++++++++++++--------= --- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index f1f2840714..9560b39220 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -636,6 +636,28 @@ InitializeApData ( SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle); } =20 +/** + This function place APs in Halt loop. + + @param[in] CpuMpData Pointer to CPU MP Data +**/ +VOID +PlaceAPInHltLoop ( + IN CPU_MP_DATA *CpuMpData + ) +{ + while (TRUE) { + DisableInterrupts (); + if (CpuMpData->UseSevEsAPMethod) { + SevEsPlaceApHlt (CpuMpData); + } else { + CpuSleep (); + } + + CpuPause (); + } +} + /** This function will be called from AP reset code if BSP uses WakeUpAP. =20 @@ -812,19 +834,10 @@ ApWakeupFunction ( // Place AP is specified loop mode // if (CpuMpData->ApLoopMode =3D=3D ApInHltLoop) { + PlaceAPInHltLoop (CpuMpData); // - // Place AP in HLT-loop + // Never run here // - while (TRUE) { - DisableInterrupts (); - if (CpuMpData->UseSevEsAPMethod) { - SevEsPlaceApHlt (CpuMpData); - } else { - CpuSleep (); - } - - CpuPause (); - } } =20 while (TRUE) { --=20 2.36.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106460): https://edk2.groups.io/g/devel/message/106460 Mute This Topic: https://groups.io/mt/99826555/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 01:26:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106461+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106461+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1687942153; cv=none; d=zohomail.com; s=zohoarc; b=QV6OVDvdilSeRlbeN4xJLzTPQb7AsLYT1k3yvvgx13SUhM/jWKU7dJzdWsJzBY8Bx1pvllaCgnujeNCSvHPAeMRb2DyeUrX8T8zGTfBkykqs8Kpi3Nc+Sqoh2W4s9KGsG/KLRB9ERAG3fMkM4Eu+zEubHM6y6QWsGdtKLEndk6w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687942153; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=wRem3iD7grm/VbnfLYVcIBrDJADVtfX0f+LEeFVofeM=; b=GZHR9kDU9NycB+UzgnQOhIEtY9C2FCwv4TNu7HlP7tTilEeZei16iRDB4UHqN4oCdGkxSNbw992y4XQI9hz4dkBpIMlXFP8OWCcwfK+X0VWjERjwze3P7OHOQI4cMHs5wBEn5fslYtiv68krIqnSNitHXb/+6Iicv1SfYOSjgB4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106461+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1687942153761295.54348751326734; Wed, 28 Jun 2023 01:49:13 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id dr6nYY1788612xynzo1YPizU; Wed, 28 Jun 2023 01:49:13 -0700 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.11788.1687942151408549511 for ; Wed, 28 Jun 2023 01:49:12 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="341373528" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="341373528" X-Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 01:47:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="890964578" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="890964578" X-Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.55]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 01:47:53 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Eric Dong , Ray Ni , Rahul Kumar , Tom Lendacky , Yuanhao Xie Subject: [edk2-devel] [Patch V4 2/5] UefiCpuPkg: Refactor the logic for placing APs in Mwait/Runloop. Date: Wed, 28 Jun 2023 16:47:21 +0800 Message-Id: <20230628084724.57574-3-yuanhao.xie@intel.com> In-Reply-To: <20230628084724.57574-1-yuanhao.xie@intel.com> References: <20230628084724.57574-1-yuanhao.xie@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yuanhao.xie@intel.com X-Gm-Message-State: vjvoNBd5culJZANsAuKMTYwjx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1687942153; bh=bzNE+z/b/ce2VxmPBS/L32TQdcuMirn9zziziBmlcmY=; h=Cc:Date:From:Reply-To:Subject:To; b=sBx71miZc5ol4QFnRC4Ha8muKOy/GYcXbGWjegCyr/NJlw9agQ73/kdWAH83VW8OiMQ xkzhdX+wm5KnmL5GT5vcUUe1qG6xSPJd2NY8TfpLW8O+E9FkTGvsg/UlhxxuddTrWPQOD b5NuEw1b3DM/rC+wWhon/2ligQwVylB5PR8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1687942155719100019 Content-Type: text/plain; charset="utf-8" Refactor the logic for placing APs in Mwait/Runloop into a separate function. Cc: Gerd Hoffmann Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Tom Lendacky Signed-off-by: Yuanhao Xie Reviewed-by: Ray Ni --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 83 ++++++++++++++++++++++++++++++++= ++++++++++++++++++--------------------------------- 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 9560b39220..e8dd640f9b 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -658,6 +658,54 @@ PlaceAPInHltLoop ( } } =20 +/** + This function place APs in Mwait or Run loop. + + @param[in] ApLoopMode Ap Loop Mode + @param[in] ApStartupSignalBuffer Pointer to Ap Startup Signal Buf= fer + @param[in] ApTargetCState Ap Target CState +**/ +VOID +PlaceAPInMwaitLoopOrRunLoop ( + IN UINT8 ApLoopMode, + IN volatile UINT32 *ApStartupSignalBuffer, + IN UINT8 ApTargetCState + ) +{ + while (TRUE) { + DisableInterrupts (); + if (ApLoopMode =3D=3D ApInMwaitLoop) { + // + // Place AP in MWAIT-loop + // + AsmMonitor ((UINTN)ApStartupSignalBuffer, 0, 0); + if (*ApStartupSignalBuffer !=3D WAKEUP_AP_SIGNAL) { + // + // Check AP start-up signal again. + // If AP start-up signal is not set, place AP into + // the specified C-state + // + AsmMwait (ApTargetCState << 4, 0); + } + } else if (ApLoopMode =3D=3D ApInRunLoop) { + // + // Place AP in Run-loop + // + CpuPause (); + } else { + ASSERT (FALSE); + } + + // + // If AP start-up signal is written, AP is waken up + // otherwise place AP in loop again + // + if (*ApStartupSignalBuffer =3D=3D WAKEUP_AP_SIGNAL) { + break; + } + } +} + /** This function will be called from AP reset code if BSP uses WakeUpAP. =20 @@ -838,39 +886,8 @@ ApWakeupFunction ( // // Never run here // - } - - while (TRUE) { - DisableInterrupts (); - if (CpuMpData->ApLoopMode =3D=3D ApInMwaitLoop) { - // - // Place AP in MWAIT-loop - // - AsmMonitor ((UINTN)ApStartupSignalBuffer, 0, 0); - if (*ApStartupSignalBuffer !=3D WAKEUP_AP_SIGNAL) { - // - // Check AP start-up signal again. - // If AP start-up signal is not set, place AP into - // the specified C-state - // - AsmMwait (CpuMpData->ApTargetCState << 4, 0); - } - } else if (CpuMpData->ApLoopMode =3D=3D ApInRunLoop) { - // - // Place AP in Run-loop - // - CpuPause (); - } else { - ASSERT (FALSE); - } - - // - // If AP start-up signal is written, AP is waken up - // otherwise place AP in loop again - // - if (*ApStartupSignalBuffer =3D=3D WAKEUP_AP_SIGNAL) { - break; - } + } else { + PlaceAPInMwaitLoopOrRunLoop (CpuMpData->ApLoopMode, ApStartupSignalB= uffer, CpuMpData->ApTargetCState); } } } --=20 2.36.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106461): https://edk2.groups.io/g/devel/message/106461 Mute This Topic: https://groups.io/mt/99826556/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 01:26:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106462+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106462+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1687942154; cv=none; d=zohomail.com; s=zohoarc; b=YkcquQccKC1D9xFa7WUwXgcieMQnxTyNrZE5CuS84pfivDw2YcaNFrDGDufbFLqAflluFDsBOrp6XXXaoVykrzNnxro8BpGy8405bB6ap76P8/fv6icurPw5z96PMhUd/ipcO8bcMPaKEuUxozKmG7rwWVvei/f05LEran8MTAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687942154; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=3ORb0D+8igjf2tMliIRu+xJ2ohSj0bxUKeUGZkHVHX0=; b=eVcxdqQYW3jguKQHFtyyZ3mC7DK+WnoB9F0hLLBZ7uTJ+5mH0DwOD8pHKeMooI6QhEojqNW4PbdRZEnKRY56gnM9wEkw8RskWoCR/L6Ca2wnQDhlXJAFJOd5jKIXwO5qQpwYQ2fIOFGR/j3soO/BtGzG5OA+3PK3g5YtXM7jJhM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106462+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1687942154531701.1358918419699; Wed, 28 Jun 2023 01:49:14 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ILGsYY1788612x8itnZ1w5EC; Wed, 28 Jun 2023 01:49:14 -0700 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.11788.1687942151408549511 for ; Wed, 28 Jun 2023 01:49:12 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="341373551" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="341373551" X-Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 01:48:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="890964594" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="890964594" X-Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.55]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 01:47:58 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Eric Dong , Ray Ni , Rahul Kumar , Tom Lendacky , Yuanhao Xie Subject: [edk2-devel] [Patch V4 3/5] UefiCpuPkg: Create MpHandOff. Date: Wed, 28 Jun 2023 16:47:22 +0800 Message-Id: <20230628084724.57574-4-yuanhao.xie@intel.com> In-Reply-To: <20230628084724.57574-1-yuanhao.xie@intel.com> References: <20230628084724.57574-1-yuanhao.xie@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yuanhao.xie@intel.com X-Gm-Message-State: iXetL04Icirg4WkBsRcVg2Emx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1687942154; bh=r+Dl+RA8tIqILkpe5E5T+QJiooH2h8vOdYyws2d2/10=; h=Cc:Date:From:Reply-To:Subject:To; b=k+MkF8OE54M2J2OdKaVJjT6vmOyOLtCCYF58ecDK/v0f8JYsahHjXo1EpdeZmY7RS7v lB/VaYBKXZSldHxLjW6JPsIFtCa+OCHFN9mlkaiLex3GoYLYBXe6gut00Vz8/tCqdaDF/ tv5nTAsVA3rWT5oxzfBCn57aGAdUZBrsmSw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1687942155108100013 Content-Type: text/plain; charset="utf-8" Initially, the purpose of the Hob was twofold: it served as a way to transfer information from PEI to DXE. However, during the DXE phase, only a few fields from the CPU_MP_DATA which collected in PEI phase were needed. A new Hob was specifically created to transfer information to the DXE phase. This new Hob contained only the essential fields required for reuse in DXE. For instance, instead of directly including the BspNumber in MpHandOff, the DXE phase introduced the use of GetBspNumber() to collect the BspNumber from ApicID and CpuCount. The SaveCpuMpData() function was updated to construct the MP_HAND_OFF Hob. Additionally, the function introduced the MP_HAND_OFF_SIGNAL, which solely served the purpose of awakening the APs and transitioning their context from PEI to DXE. The WaitLoopExecutionMode field indicated whether the bit mode of PEI matched that of DXE. Both of them were filled only if the ApLoopMode was not ApInHltLoop. In the case of ApInHltLoop, it remained necessary to wake up the APs using the init-sipi-sipi sequence. This improvement still allow INIT-SIPI-SIPI even APs are wait in Run/Mwait loop mode. The function GetMpHandOffHob() was added to facilitate access to the collected MpHandOff in the DXE phase. The CpuMpData in the DXE phase was updated by gathering information from MpHandOff. Since MpHandOff replaced the usage of OldCpuMpData and contained essential information from the PEI phase to the DXE phase. AmdSevUpdateCpuMpData was included to maintain the original implementation of AmdSev, ensuring that OldCpuMpData->NewCpuMpData pointed to CpuMpData. Cc: Gerd Hoffmann Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Tom Lendacky Signed-off-by: Yuanhao Xie Reviewed-by: Ray Ni --- UefiCpuPkg/Library/MpInitLib/AmdSev.c | 17 +++++++++++++++++ UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 1 + UefiCpuPkg/Library/MpInitLib/MpHandOff.h | 47 +++++++++++++++++++++++= ++++++++++++++++++++++++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 83 +++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++------------- UefiCpuPkg/Library/MpInitLib/MpLib.h | 19 +++++++++++++++++++ UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 2 +- UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 32 +++++++++++++++++++++++= ++++++++- 7 files changed, 186 insertions(+), 15 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/AmdSev.c b/UefiCpuPkg/Library/MpI= nitLib/AmdSev.c index ca9bfed7f3..bda4960f6f 100644 --- a/UefiCpuPkg/Library/MpInitLib/AmdSev.c +++ b/UefiCpuPkg/Library/MpInitLib/AmdSev.c @@ -260,3 +260,20 @@ FillExchangeInfoDataSevEs ( ExchangeInfo->ExtTopoAvail =3D !!ExtTopoEbx.Bits.LogicalProcessors; } } + +/** + Get pointer to CPU MP Data structure from GUIDed HOB. + + @param[in] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +AmdSevUpdateCpuMpData ( + IN CPU_MP_DATA *CpuMpData + ) +{ + CPU_MP_DATA *OldCpuMpData; + + OldCpuMpData =3D GetCpuMpDataFromGuidedHob (); + + OldCpuMpData->NewCpuMpData =3D CpuMpData; +} diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/DxeMpInitLib.inf index 67ebf7254c..7d45d3ad4d 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf @@ -38,6 +38,7 @@ MpLib.c MpLib.h Microcode.c + MpHandOff.h =20 [Packages] MdePkg/MdePkg.dec diff --git a/UefiCpuPkg/Library/MpInitLib/MpHandOff.h b/UefiCpuPkg/Library/= MpInitLib/MpHandOff.h new file mode 100644 index 0000000000..83e4055ec9 --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/MpHandOff.h @@ -0,0 +1,47 @@ +/** @file + Defines the HOB GUID used to describe the MSEG memory region allocated i= n PEI. + Copyright (c) 2015 - 2023, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef MP_HANDOFF_H_ +#define MP_HANDOFF_H_ + +#define MP_HANDOFF_GUID \ + { \ + 0x11e2bd88, 0xed38, 0x4abd, {0xa3, 0x99, 0x21, 0xf2, 0x5f, 0xd0, 0x7a,= 0x60 } \ + } + +extern EFI_GUID mMpHandOffGuid; + +// +// The information required to transfer from the PEI phase to the +// DXE phase is contained within the MP_HAND_OFF and PROCESSOR_HAND_OFF. +// If the SizeOfPointer (WaitLoopExecutionMode) of both phases are equal, +// and the APs is not in halt mode, +// then the APs can be awakened by triggering the start-up +// signal, rather than using INIT-SIPI-SIPI. +// To trigger the start-up signal, BSP writes the specified +// StartupSignalValue to the StartupSignalAddress of each processor. +// This address is monitored by the APs. +// +typedef struct { + UINT32 ApicId; + UINT32 Health; + UINT64 StartupSignalAddress; + UINT64 StartupProcedureAddress; +} PROCESSOR_HAND_OFF; + +typedef struct { + // + // The ProcessorIndex indicates the range of processors. If it is set to= 0, it signifies + // processors from 0 to CpuCount - 1. Multiple instances in the HOB list= describe + // processors from ProcessorIndex to ProcessorIndex + CpuCount - 1. + // + UINT32 ProcessorIndex; + UINT32 CpuCount; + UINT32 WaitLoopExecutionMode; + UINT32 StartupSignalValue; + PROCESSOR_HAND_OFF Info[]; +} MP_HAND_OFF; +#endif diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index e8dd640f9b..ccc01859f0 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -14,6 +14,7 @@ #include =20 EFI_GUID mCpuInitMpLibHobGuid =3D CPU_INIT_MP_LIB_HOB_GUID; +EFI_GUID mMpHandOffGuid =3D MP_HANDOFF_GUID; =20 /** Save the volatile registers required to be restored following INIT IPI. @@ -1814,6 +1815,59 @@ CheckAllAPs ( return EFI_NOT_READY; } =20 +/** + This function Get BspNumber. + + @param[in] MpHandOff Pointer to MpHandOff + @return BspNumber +**/ +UINT32 +GetBspNumber ( + IN CONST MP_HAND_OFF *MpHandOff + ) +{ + UINT32 ApicId; + UINT32 BspNumber; + UINT32 Index; + + // + // Get the processor number for the BSP + // + BspNumber =3D MAX_UINT32; + ApicId =3D GetInitialApicId (); + for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { + if (MpHandOff->Info[Index].ApicId =3D=3D ApicId) { + BspNumber =3D Index; + } + } + + ASSERT (BspNumber !=3D MAX_UINT32); + + return BspNumber; +} + +/** + Get pointer to MP_HAND_OFF GUIDed HOB. + + @return The pointer to MP_HAND_OFF structure. +**/ +MP_HAND_OFF * +GetMpHandOffHob ( + VOID + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + MP_HAND_OFF *MpHandOff; + + MpHandOff =3D NULL; + GuidHob =3D GetFirstGuidHob (&mMpHandOffGuid); + if (GuidHob !=3D NULL) { + MpHandOff =3D (MP_HAND_OFF *)GET_GUID_HOB_DATA (GuidHob); + } + + return MpHandOff; +} + /** MP Initialize Library initialization. =20 @@ -1833,7 +1887,7 @@ MpInitLibInitialize ( VOID ) { - CPU_MP_DATA *OldCpuMpData; + MP_HAND_OFF *MpHandOff; CPU_INFO_IN_HOB *CpuInfoInHob; UINT32 MaxLogicalProcessorNumber; UINT32 ApStackSize; @@ -1852,11 +1906,11 @@ MpInitLibInitialize ( UINTN BackupBufferAddr; UINTN ApIdtBase; =20 - OldCpuMpData =3D GetCpuMpDataFromGuidedHob (); - if (OldCpuMpData =3D=3D NULL) { + MpHandOff =3D GetMpHandOffHob (); + if (MpHandOff =3D=3D NULL) { MaxLogicalProcessorNumber =3D PcdGet32 (PcdCpuMaxLogicalProcessorNumbe= r); } else { - MaxLogicalProcessorNumber =3D OldCpuMpData->CpuCount; + MaxLogicalProcessorNumber =3D MpHandOff->CpuCount; } =20 ASSERT (MaxLogicalProcessorNumber !=3D 0); @@ -2000,7 +2054,7 @@ MpInitLibInitialize ( // ProgramVirtualWireMode (); =20 - if (OldCpuMpData =3D=3D NULL) { + if (MpHandOff =3D=3D NULL) { if (MaxLogicalProcessorNumber > 1) { // // Wakeup all APs and calculate the processor count in system @@ -2012,15 +2066,18 @@ MpInitLibInitialize ( // APs have been wakeup before, just get the CPU Information // from HOB // - OldCpuMpData->NewCpuMpData =3D CpuMpData; - CpuMpData->CpuCount =3D OldCpuMpData->CpuCount; - CpuMpData->BspNumber =3D OldCpuMpData->BspNumber; - CpuMpData->CpuInfoInHob =3D OldCpuMpData->CpuInfoInHob; - CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->Cp= uInfoInHob; + AmdSevUpdateCpuMpData (CpuMpData); + CpuMpData->CpuCount =3D MpHandOff->CpuCount; + CpuMpData->BspNumber =3D GetBspNumber (MpHandOff); + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoI= nHob; for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { InitializeSpinLock (&CpuMpData->CpuData[Index].ApLock); - CpuMpData->CpuData[Index].CpuHealthy =3D (CpuInfoInHob[Index].Health= =3D=3D 0) ? TRUE : FALSE; + CpuMpData->CpuData[Index].CpuHealthy =3D (MpHandOff->Info[Index].Hea= lth =3D=3D 0) ? TRUE : FALSE; CpuMpData->CpuData[Index].ApFunction =3D 0; + CpuInfoInHob[Index].InitialApicId =3D MpHandOff->Info[Index].Apic= Id; + CpuInfoInHob[Index].ApTopOfStack =3D CpuMpData->Buffer + (Index = + 1) * CpuMpData->CpuApStackSize; + CpuInfoInHob[Index].ApicId =3D MpHandOff->Info[Index].Apic= Id; + CpuInfoInHob[Index].Health =3D MpHandOff->Info[Index].Heal= th; } } =20 @@ -2049,7 +2106,7 @@ MpInitLibInitialize ( // Wakeup APs to do some AP initialize sync (Microcode & MTRR) // if (CpuMpData->CpuCount > 1) { - if (OldCpuMpData !=3D NULL) { + if (MpHandOff !=3D NULL) { // // Only needs to use this flag for DXE phase to update the wake up // buffer. Wakeup buffer allocated in PEI phase is no longer valid @@ -2066,7 +2123,7 @@ MpInitLibInitialize ( CpuPause (); } =20 - if (OldCpuMpData !=3D NULL) { + if (MpHandOff !=3D NULL) { CpuMpData->InitFlag =3D ApInitDone; } =20 diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index b694c7b40f..a7f36d323b 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -39,8 +39,17 @@ #include =20 #include +#include "MpHandOff.h" =20 #define WAKEUP_AP_SIGNAL SIGNATURE_32 ('S', 'T', 'A', 'P') +// +// To trigger the start-up signal, BSP writes the specified +// StartupSignalValue to the StartupSignalAddress of each processor. +// This address is monitored by the APs, and as soon as they receive +// the value that matches the MP_HAND_OFF_SIGNAL, they will wake up +// and switch the context from PEI to DXE phase. +// +#define MP_HAND_OFF_SIGNAL SIGNATURE_32 ('M', 'P', 'H', 'O') =20 #define CPU_INIT_MP_LIB_HOB_GUID \ { \ @@ -891,4 +900,14 @@ SevSnpCreateAP ( IN INTN ProcessorNumber ); =20 +/** + Get pointer to CPU MP Data structure from GUIDed HOB. + + @param[in] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +AmdSevUpdateCpuMpData ( + IN CPU_MP_DATA *CpuMpData + ); + #endif diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/PeiMpInitLib.inf index 78eded96bf..83e9028d0f 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -36,7 +36,7 @@ MpLib.c MpLib.h Microcode.c - + MpHandOff.h [Packages] MdePkg/MdePkg.dec UefiCpuPkg/UefiCpuPkg.dec diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c b/UefiCpuPkg/Library/M= pInitLib/PeiMpLib.c index 013f89b197..f80e00edcf 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c @@ -126,7 +126,37 @@ SaveCpuMpData ( IN CPU_MP_DATA *CpuMpData ) { - UINT64 Data64; + UINT64 Data64; + UINTN Index; + CPU_INFO_IN_HOB *CpuInfoInHob; + MP_HAND_OFF *MpHandOff; + UINTN MpHandOffSize; + + // + // When APs are in a state that can be waken up by a store operation to = a memory address, + // report the MP_HAND_OFF data for DXE to use. + // + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; + MpHandOffSize =3D sizeof (MP_HAND_OFF) + sizeof (PROCESSOR_HAND_OFF) * C= puMpData->CpuCount; + MpHandOff =3D (MP_HAND_OFF *)BuildGuidHob (&mMpHandOffGuid, MpHandOf= fSize); + ASSERT (MpHandOff !=3D NULL); + ZeroMem (MpHandOff, MpHandOffSize); + MpHandOff->ProcessorIndex =3D 0; + + MpHandOff->CpuCount =3D CpuMpData->CpuCount; + if (CpuMpData->ApLoopMode !=3D ApInHltLoop) { + MpHandOff->StartupSignalValue =3D MP_HAND_OFF_SIGNAL; + MpHandOff->WaitLoopExecutionMode =3D sizeof (VOID *); + } + + for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { + MpHandOff->Info[Index].ApicId =3D CpuInfoInHob[Index].ApicId; + MpHandOff->Info[Index].Health =3D CpuInfoInHob[Index].Health; + if (CpuMpData->ApLoopMode !=3D ApInHltLoop) { + MpHandOff->Info[Index].StartupSignalAddress =3D (UINT64)(UINTN)Cp= uMpData->CpuData[Index].StartupApSignal; + MpHandOff->Info[Index].StartupProcedureAddress =3D (UINT64)(UINTN)&C= puMpData->CpuData[Index].ApFunction; + } + } =20 // // Build location of CPU MP DATA buffer in HOB --=20 2.36.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106462): https://edk2.groups.io/g/devel/message/106462 Mute This Topic: https://groups.io/mt/99826557/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 01:26:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106463+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106463+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1687942154; cv=none; d=zohomail.com; s=zohoarc; b=niv3fSu5VuyRYYdxoqejRmNXZ1x42XbDENzQt603HzaA+gYs4yd3MOvFj8dfRN/ssi2reaAn7L55pVWtlmQjrR6/OFhF5kGzL48JHyPVNVjmKL0RVK5huhaYvjkFPLIsnSIpuoB2+DPiFBvTlVnMSZVwSeAAldO0JGuSX8ncKPY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687942154; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=/W81TMvyI9XOSmx6HN+LxcDFF0FXAvHiQ9InBdRgVf0=; b=WWTsQSW8mf04huacxOmxBzpsuGl1YzXnvyBxrmulS0BHfy0TLm2o1/+R3+CXbMy4wEphMT4ZR6wk4KTeku+++e9wyYtQ6ttz8h2Yjx8bXWJlozgAGDIv0VaFCYY2/kaZYuGdM4O7d78zURLGpPZEdmgKDsodNOri9EfVHYKlUwk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106463+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1687942154126980.5829559737341; Wed, 28 Jun 2023 01:49:14 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id eeF9YY1788612xcAZeqwIJEa; Wed, 28 Jun 2023 01:49:13 -0700 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.11789.1687942152264937624 for ; Wed, 28 Jun 2023 01:49:12 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="341373574" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="341373574" X-Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 01:48:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="890964606" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="890964606" X-Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.55]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 01:48:03 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Eric Dong , Ray Ni , Rahul Kumar , Tom Lendacky , Yuanhao Xie Subject: [edk2-devel] [Patch V4 4/5] UefiCpuPkg: ApWakeupFunction directly use CpuMpData. Date: Wed, 28 Jun 2023 16:47:23 +0800 Message-Id: <20230628084724.57574-5-yuanhao.xie@intel.com> In-Reply-To: <20230628084724.57574-1-yuanhao.xie@intel.com> References: <20230628084724.57574-1-yuanhao.xie@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yuanhao.xie@intel.com X-Gm-Message-State: 0GI15Jn58yvBAKtJFuJsB7rVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1687942153; bh=LJGJ/fyLWUGqUiIY4hJnQxX8k4G5/HTgZPg53HWy2Hg=; h=Cc:Date:From:Reply-To:Subject:To; b=dgQ5nnqcOd5aMZQO+dOefc9XcL2vZs3qJuHGm6waOaL+1UEOgyWjgAMNTyGtkV+tTmX ebDSBCu3mNR8pZyPhwwP43iW+Ybyx9xduvm3dfmStlJefjpuERem4wazo8TfT/W5itEsK pm3bGxqC/HXYoLCqSRye+yDYG8LXYRdPn1Y= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1687942155061100011 Content-Type: text/plain; charset="utf-8" In the original design, once the APs finished executing their assembly code and switched to executing C code, they would enter a continuous loop within a function. In this function, they would collect CpuMpData using the MP_CPU_EXCHANGE_INFO mechanism. However, in the updated approach, CpuMpData can now be passed directly to the ApWakeUpFunction, bypassing the need for MP_CPU_EXCHANGE_INFO. This modification is made in preparation for eliminating the requirement of a second INIT-SIPI-SIPI sequence in the DXE phase. Cc: Gerd Hoffmann Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Tom Lendacky Signed-off-by: Yuanhao Xie Reviewed-by: Ray Ni --- UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm | 4 ++-- UefiCpuPkg/Library/MpInitLib/MpLib.c | 12 +++--------- UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 3 +-- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm b/UefiCpuPkg/Li= brary/MpInitLib/Ia32/MpFuncs.nasm index 59db4081d6..d117f09ef5 100644 --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm @@ -197,8 +197,8 @@ CProcedureInvoke: =20 push ebx ; Push ApIndex mov eax, esi - add eax, MP_CPU_EXCHANGE_INFO_OFFSET - push eax ; push address of exchange info data buff= er + add eax, MP_CPU_EXCHANGE_INFO_FIELD (CpuMpData) + push dword [eax] ; push address of CpuMpData =20 mov edi, esi add edi, MP_CPU_EXCHANGE_INFO_FIELD (CFunction) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index ccc01859f0..f904751b0d 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -710,17 +710,16 @@ PlaceAPInMwaitLoopOrRunLoop ( /** This function will be called from AP reset code if BSP uses WakeUpAP. =20 - @param[in] ExchangeInfo Pointer to the MP exchange info buffer + @param[in] CpuMpData Pointer to CPU MP Data @param[in] ApIndex Number of current executing AP **/ VOID EFIAPI ApWakeupFunction ( - IN MP_CPU_EXCHANGE_INFO *ExchangeInfo, - IN UINTN ApIndex + IN CPU_MP_DATA *CpuMpData, + IN UINTN ApIndex ) { - CPU_MP_DATA *CpuMpData; UINTN ProcessorNumber; EFI_AP_PROCEDURE Procedure; VOID *Parameter; @@ -731,11 +730,6 @@ ApWakeupFunction ( UINTN CurrentApicMode; AP_STACK_DATA *ApStackData; =20 - // - // AP finished assembly code and begin to execute C code - // - CpuMpData =3D ExchangeInfo->CpuMpData; - // // AP's local APIC settings will be lost after received INIT IPI // We need to re-initialize them at here diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Lib= rary/MpInitLib/X64/MpFuncs.nasm index 5bcdf7726b..40e80ffab4 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm @@ -259,8 +259,7 @@ CProcedureInvoke: add rsp, 20h =20 mov edx, ebx ; edx is ApIndex - mov ecx, esi - add ecx, MP_CPU_EXCHANGE_INFO_OFFSET ; rcx is address of exchan= ge info data buffer + mov rcx, qword [esi + MP_CPU_EXCHANGE_INFO_FIELD (CpuMpData)] =20 mov edi, esi add edi, MP_CPU_EXCHANGE_INFO_FIELD (CFunction) --=20 2.36.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106463): https://edk2.groups.io/g/devel/message/106463 Mute This Topic: https://groups.io/mt/99826558/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 01:26:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106464+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106464+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1687942154; cv=none; d=zohomail.com; s=zohoarc; b=lykIQHbdHzVxMPtAjh19WLb2ojiH7VayWGfZWPNZOxWX8/ebIdfCL2L/UmZz++z/zvPRSugjTeVk9aVctxkDzwyLHh8ZGh1Hj0qIiDtniIQm3imXViKiFQQaBdbIonQq7ZAQGJuTqH6MEjoFVxEnfQXLZj3tdH7OTGgXfOvVx8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687942154; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Dm6eWPSGq625Gba3/WpnuVJHOZ+uOnEeWzXDfmt0HOk=; b=igKcyrJsFU0v3mJkHXqvAtGMO97SslW18ZMjjSZfT+cRSqk0jWw5I90hqCUvhghIC/bTHEn66VM5/6NHy62cw0fcyZ4Kc07yQykXuZ68wol3Tym63WaK1o9vOjAUOIA5dJeM2SsjtWOS5Uv7LX2qzNeqo30uLkBDC54OuaWgrZE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106464+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1687942154976684.8397704477256; Wed, 28 Jun 2023 01:49:14 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id syfTYY1788612xwdphFcH3Ck; Wed, 28 Jun 2023 01:49:14 -0700 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.11788.1687942151408549511 for ; Wed, 28 Jun 2023 01:49:12 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="341373601" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="341373601" X-Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 01:48:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="890964619" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="890964619" X-Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.55]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 01:48:08 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Eric Dong , Ray Ni , Rahul Kumar , Tom Lendacky , Yuanhao Xie Subject: [edk2-devel] [Patch V4 5/5] UefiCpuPkg: Eliminate the second INIT-SIPI-SIPI sequence. Date: Wed, 28 Jun 2023 16:47:24 +0800 Message-Id: <20230628084724.57574-6-yuanhao.xie@intel.com> In-Reply-To: <20230628084724.57574-1-yuanhao.xie@intel.com> References: <20230628084724.57574-1-yuanhao.xie@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yuanhao.xie@intel.com X-Gm-Message-State: aOEMcbVctBKYFMvYK6oaguR2x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1687942154; bh=H0sNJK4qUskJFmXn9FQO9YsrXc+RmkuzeHFQf0nHxUE=; h=Cc:Date:From:Reply-To:Subject:To; b=BKAZMPy+DvYHAW6OaszReQcEpomW0Dg41zRIPnO2lq0NpZPWvXUFCLrL5BurBvu85Ls zKWEoi+oRDKwh3mUGBKS2U27ot2+rLlPwIjX8t4E6GHTFeIoFqGqFqM9uDUc8jKHedPnM G6rpeWlLsT0QEDbd8DpCkBqbsjyZouThL8Q= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1687942155475100017 Content-Type: text/plain; charset="utf-8" When both the PEI and DXE phases operate in the same execution mode(32-bit/64-bit), the BSP send a special start-up signal during the DXE phase to awaken the Application APs. To eliminate the need for the INIT-SIPI-SIPI sequence at the beginning of the DXE phase, the BSP call the SwitchApContext function to trigger the special start-up signal. By writing the specified StartupSignalValue to the designated StartupSignalAddress, the BSP wakes up the APs from mwait mode. Once the APs receive the MP_HAND_OFF_SIGNAL value, they are awakened and proceed to execute the SwitchContextPerAp procedure. They enter another while loop, transitioning their context from the PEI phase to the DXE phase. The original state transitions for an AP during the procedure are as follows: Idle ----> Ready ----> Busy ----> Idle [BSP] [AP] [AP] Instead of init-sipi-sipi sequence, we make use of a start-up signal to awaken the APs and transfer their context from PEI to DXE. Consequently, APs, rather than the BSP, to set their state to CpuStateReady. Cc: Gerd Hoffmann Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Tom Lendacky Signed-off-by: Yuanhao Xie Reviewed-by: Ray Ni --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 138 +++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++-- UefiCpuPkg/Library/MpInitLib/MpLib.h | 9 +++++++++ 2 files changed, 145 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index f904751b0d..737e03ffc5 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -680,7 +680,7 @@ PlaceAPInMwaitLoopOrRunLoop ( // Place AP in MWAIT-loop // AsmMonitor ((UINTN)ApStartupSignalBuffer, 0, 0); - if (*ApStartupSignalBuffer !=3D WAKEUP_AP_SIGNAL) { + if ((*ApStartupSignalBuffer !=3D WAKEUP_AP_SIGNAL) && (*ApStartupSig= nalBuffer !=3D MP_HAND_OFF_SIGNAL)) { // // Check AP start-up signal again. // If AP start-up signal is not set, place AP into @@ -701,7 +701,7 @@ PlaceAPInMwaitLoopOrRunLoop ( // If AP start-up signal is written, AP is waken up // otherwise place AP in loop again // - if (*ApStartupSignalBuffer =3D=3D WAKEUP_AP_SIGNAL) { + if ((*ApStartupSignalBuffer =3D=3D WAKEUP_AP_SIGNAL) || (*ApStartupSig= nalBuffer =3D=3D MP_HAND_OFF_SIGNAL)) { break; } } @@ -729,6 +729,7 @@ ApWakeupFunction ( UINT64 ApTopOfStack; UINTN CurrentApicMode; AP_STACK_DATA *ApStackData; + UINT32 OriginalValue; =20 // // AP's local APIC settings will be lost after received INIT IPI @@ -769,6 +770,15 @@ ApWakeupFunction ( // Clear AP start-up signal when AP waken up // ApStartupSignalBuffer =3D CpuMpData->CpuData[ProcessorNumber].Startu= pApSignal; + OriginalValue =3D InterlockedCompareExchange32 ( + (UINT32 *)ApStartupSignalBuffer, + MP_HAND_OFF_SIGNAL, + 0 + ); + if (OriginalValue =3D=3D MP_HAND_OFF_SIGNAL) { + SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateReady); + } + InterlockedCompareExchange32 ( (UINT32 *)ApStartupSignalBuffer, WAKEUP_AP_SIGNAL, @@ -887,6 +897,32 @@ ApWakeupFunction ( } } =20 +/** + This function serves as the entry point for APs when + they are awakened by the stores in the memory address + indicated by the MP_HANDOFF_INFO structure. + + @param[in] CpuMpData Pointer to PEI CPU MP Data +**/ +VOID +EFIAPI +DxeApEntryPoint ( + CPU_MP_DATA *CpuMpData + ) +{ + UINTN ProcessorNumber; + + GetProcessorNumber (CpuMpData, &ProcessorNumber); + InterlockedIncrement ((UINT32 *)&CpuMpData->FinishedCount); + RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, FALS= E); + PlaceAPInMwaitLoopOrRunLoop ( + CpuMpData->ApLoopMode, + CpuMpData->CpuData[ProcessorNumber].StartupApSignal, + CpuMpData->ApTargetCState + ); + ApWakeupFunction (CpuMpData, ProcessorNumber); +} + /** Wait for AP wakeup and write AP start-up signal till AP is waken up. =20 @@ -1457,6 +1493,32 @@ CalculateTimeout ( } } =20 +/** + Switch Context for each AP. + +**/ +VOID +EFIAPI +SwitchContextPerAp ( + VOID + ) +{ + UINTN ProcessorNumber; + CPU_MP_DATA *CpuMpData; + CPU_INFO_IN_HOB *CpuInfoInHob; + + CpuMpData =3D GetCpuMpData (); + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; + GetProcessorNumber (CpuMpData, &ProcessorNumber); + + SwitchStack ( + (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeApEntryPoint, + (VOID *)(UINTN)CpuMpData, + NULL, + (VOID *)((UINTN)CpuInfoInHob[ProcessorNumber].ApTopOfStack) + ); +} + /** Checks whether timeout expires. =20 @@ -1840,6 +1902,44 @@ GetBspNumber ( return BspNumber; } =20 +/** + This function is intended to be invoked by the BSP in order + to wake up the AP. The BSP accomplishes this by triggering a + start-up signal, which in turn causes any APs that are + currently in a loop on the PEI-prepared memory to awaken and + begin running the procedure called SwitchContextPerAp. + This procedure allows the AP to switch to another section of + memory and continue its loop there. + + @param[in] MpHandOff Pointer to MP hand-off data structure. +**/ +VOID +SwitchApContext ( + IN MP_HAND_OFF *MpHandOff + ) +{ + UINTN Index; + UINT32 BspNumber; + + BspNumber =3D GetBspNumber (MpHandOff); + + for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { + if (Index !=3D BspNumber) { + *(UINTN *)(UINTN)MpHandOff->Info[Index].StartupProcedureAddress =3D = (UINTN)SwitchContextPerAp; + *(UINT32 *)(UINTN)MpHandOff->Info[Index].StartupSignalAddress =3D = MpHandOff->StartupSignalValue; + } + } + + // + // Wait all APs waken up if this is not the 1st broadcast of SIPI + // + for (Index =3D 0; Index < MpHandOff->CpuCount; Index++) { + if (Index !=3D BspNumber) { + WaitApWakeup ((UINT32 *)(UINTN)(MpHandOff->Info[Index].StartupSignal= Address)); + } + } +} + /** Get pointer to MP_HAND_OFF GUIDed HOB. =20 @@ -2073,6 +2173,40 @@ MpInitLibInitialize ( CpuInfoInHob[Index].ApicId =3D MpHandOff->Info[Index].Apic= Id; CpuInfoInHob[Index].Health =3D MpHandOff->Info[Index].Heal= th; } + + DEBUG ((DEBUG_INFO, "MpHandOff->WaitLoopExecutionMode: %04d, sizeof (V= OID *): %04d\n", MpHandOff->WaitLoopExecutionMode, sizeof (VOID *))); + if (MpHandOff->WaitLoopExecutionMode =3D=3D sizeof (VOID *)) { + ASSERT (CpuMpData->ApLoopMode !=3D ApInHltLoop); + + CpuMpData->FinishedCount =3D 0; + CpuMpData->InitFlag =3D ApInitDone; + SaveCpuMpData (CpuMpData); + // + // In scenarios where both the PEI and DXE phases run in the same + // execution mode (32bit or 64bit), the BSP triggers + // a start-up signal during the DXE phase to wake up the APs. This c= auses any + // APs that are currently in a loop on the memory prepared during th= e PEI + // phase to awaken and run the SwitchContextPerAp procedure. This pr= ocedure + // enables the APs to switch to a different memory section and conti= nue their + // looping process there. + // + SwitchApContext (MpHandOff); + ASSERT (CpuMpData->FinishedCount =3D=3D (CpuMpData->CpuCount - 1)); + + // + // Set Apstate as Idle, otherwise Aps cannot be waken-up again. + // If any enabled AP is not idle, return EFI_NOT_READY during waken-= up. + // + for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { + SetApState (&CpuMpData->CpuData[Index], CpuStateIdle); + } + + // + // Initialize global data for MP support + // + InitMpGlobalData (CpuMpData); + return EFI_SUCCESS; + } } =20 if (!GetMicrocodePatchInfoFromHob ( diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index a7f36d323b..763db4963d 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -474,6 +474,15 @@ GetWakeupBuffer ( IN UINTN WakeupBufferSize ); =20 +/** + Switch Context for each AP. + +**/ +VOID +SwitchApContext ( + IN MP_HAND_OFF *MpHandOff + ); + /** Get available EfiBootServicesCode memory below 4GB by specified size. =20 --=20 2.36.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106464): https://edk2.groups.io/g/devel/message/106464 Mute This Topic: https://groups.io/mt/99826559/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-