From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web12.31726.1611544488847248285 for ; Sun, 24 Jan 2021 19:14:48 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=v847WbuY; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: star.zeng@intel.com) IronPort-SDR: VRvfyU6CI30az8Y0GHH5vC2t+6ZO2NfPVkThdcr8/QbGpt7+QfFNkD/ti8dxSzUMX9w77wSnS8 QdTkMpR0064g== X-IronPort-AV: E=McAfee;i="6000,8403,9874"; a="158833517" X-IronPort-AV: E=Sophos;i="5.79,372,1602572400"; d="scan'208";a="158833517" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2021 19:14:47 -0800 IronPort-SDR: S1zXId/TvuiKdna0+RlvWnk4Ddi96QYmA4UmQolU9BxyXXR94vSa7i3AfcyI+0FVJnvJ64TfID ROoPtLKPOujA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,372,1602572400"; d="scan'208";a="350003113" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by fmsmga007.fm.intel.com with ESMTP; 24 Jan 2021 19:14:46 -0800 Received: from fmsmsx608.amr.corp.intel.com (10.18.126.88) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Sun, 24 Jan 2021 19:14:45 -0800 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx608.amr.corp.intel.com (10.18.126.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Sun, 24 Jan 2021 19:14:45 -0800 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2 via Frontend Transport; Sun, 24 Jan 2021 19:14:45 -0800 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.171) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Sun, 24 Jan 2021 19:14:44 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UcOBhuNZY5L26PaB2yGv4ynxZayLump39jzsTMFd3Hw8iqOmQOEKRp57Ma4KebsVsWlkuv+c5hOEhKOhTCB8Ok9mp5drf7c6xKRPcdT4gaU7CktowWc4MusuT3uEZIABqF0L4cBmBaFZbSs1sRoSYcMeSfYxdzk7uFvFjgroCEqOWG0WRxyi8fVV1je/uxc0m16TAtDAVcduz8M4seaZihMj2npyCrCNOSRmDYQ0/Hhq3DTRKRa0G+AxRfqP7zGULTRJMNO0f+iTc+sPFcVwxp4StLoUTHGbNtmIkDPv3Z1LAMgA5G1lnsDbfr1NcFbA1oXLwH95IsRQOKGu5sFSLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wa/00TlA1Bx7EU39wLG88Rm8/BbJ7LxXDCdrvugyoww=; b=n2RNnpn/ghv0of5XX2CoYZZ/ZU0wlHH9NVvfmxMI8OhIdyo0hMgFHFQy6j6BXc4rMUrG1OlWBahrhLlNDvWjd2Nb9byI2eCL5qYhpPu8jBeUIMh0dRDcOiUu6dlBnfKP7BSUO2yciKjFMVt8/qonxrV/WVQvB0ErGYfAd6NbiI4TkolGZ1LeRAeLxpZ61DD5HvkusnKx3MPSBriunbi/K+aFFTFPMX/3hiyQqcGOaUH3rZAOqoc0F6VY0lqJX+DFxq4NtVBHvML8QETXj8XeDPGjaYj2EBQVTA4rMvvhLBlMLgqNofDGT9/lJldFpfvxkNfzqtPgZPZYCxibHTfgFA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wa/00TlA1Bx7EU39wLG88Rm8/BbJ7LxXDCdrvugyoww=; b=v847WbuYEEk4LJHS+oCaRXS8F5c7JpOdLSz+V0IE3kffAbdc9x97gKKHbEr6kG6L6GQwHgE7cpe7LcMmwGtCZmCqaxoAjWJZcNP61TQ4cLYBGRvTN5SdkKPRmI6Vkj1bN+rX9fuCeYh1HKoN7wmw6w4sBZCaBhYaWR07b+0VXtE= Received: from DM6PR11MB4058.namprd11.prod.outlook.com (2603:10b6:5:193::13) by DM6PR11MB3785.namprd11.prod.outlook.com (2603:10b6:5:13f::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.14; Mon, 25 Jan 2021 03:14:44 +0000 Received: from DM6PR11MB4058.namprd11.prod.outlook.com ([fe80::29e6:77f7:8834:9f88]) by DM6PR11MB4058.namprd11.prod.outlook.com ([fe80::29e6:77f7:8834:9f88%7]) with mapi id 15.20.3784.019; Mon, 25 Jan 2021 03:14:43 +0000 From: "Zeng, Star" To: "devel@edk2.groups.io" , "Kinney, Michael D" CC: "Dong, Eric" , "Ni, Ray" , "Laszlo Ersek" , "Kumar, Rahul1" , "Zeng, Star" Subject: Re: [edk2-devel] [Patch 1/1] UefiCpuPkg/Library/MpInitLib: Fix AP VolatileRegisters race condition Thread-Topic: [edk2-devel] [Patch 1/1] UefiCpuPkg/Library/MpInitLib: Fix AP VolatileRegisters race condition Thread-Index: AQHW8OGMsMigToHqg0Wn9wjGvm6/8Ko3rmYQ Date: Mon, 25 Jan 2021 03:14:43 +0000 Message-ID: References: <20210122171020.589-1-michael.d.kinney@intel.com> In-Reply-To: <20210122171020.589-1-michael.d.kinney@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.202] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 51216643-a245-4383-0eda-08d8c0df5ccb x-ms-traffictypediagnostic: DM6PR11MB3785: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5236; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: nM+zvW3JAPTuewgMfx0LhdwB2EFuGNMQAnvD/RRhS9O6JeelzTJd8OCVmm0ccYYJx5sX0jm50Rktqoi3vHAvnoEPxc4siEtTh7OWK7QLW204J70+KSzl6HHwiywA45JOK4uzS8QLG7jHgFE83pEeFVWcZhWtxeQbK9oz8wDui08rDbMt3yFI5MLW/xp+Sv27MI8ne4TUPI5B4tL74qZrDnVxfKyCTEIAVL3S5B1FHSZ+/X7fhItI0FuT5GXIhH52jHros/IBv9Q9RotdT79ESP0aLV1W1vReums0UOvZPyZz8u7ZIdj/zMk9x4dWF2sOFmtO33HwRNnfxiDtmt/QSN5m8Exwx/zj/cGBfNY4gpxAb0/bhixMBrfjDWPCAS2f5gIuMuW4J8k/yozsZD8Qhwotuchk6YNMK015j+d32DJInhqnu0FTxK2HI7e/yXKlgWMkgOsBnpWHDEwrRUxD4uB92W5U1fURr2TSBzOCjo8ebf+SZ910WDwN1fyt4BdtzckB+rsuTZUsUmS+PeKF6F//6U9hlEuVX5LWm8vtZFT0EPe+ZbL+sHw+jWHxf98IZgT5doJboYZu9bJ8+YLYnFtMhCCzS/a3+bTp43L5ZUs= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR11MB4058.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(6029001)(4636009)(366004)(376002)(136003)(39860400002)(346002)(396003)(76116006)(186003)(55016002)(107886003)(8936002)(9686003)(66946007)(26005)(64756008)(66446008)(966005)(2906002)(4326008)(478600001)(66476007)(66556008)(8676002)(83380400001)(54906003)(7696005)(110136005)(52536014)(316002)(6506007)(53546011)(5660300002)(71200400001)(86362001)(6636002)(33656002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?+5RzMjHeGWFLb0GVfXuwZLIC74xob0CdQc6PCw2qvJsJvDrQYAac5JsC8miA?= =?us-ascii?Q?xnHjO3W9iSYG04EGSJkr+HfGXjeftD5yzl/SgVp+/ypXNMyRUL074hQ60OQe?= =?us-ascii?Q?L3i7TcaozA+MHZS211An+5XBuMHrpkvbcgD7SUeX0Qhmi78vrUlhT5hmCwDk?= =?us-ascii?Q?olPOXClmWD4YtCKpOazkNlb+JJnEq9XH8qf7F0U5lj2ru5kkzx+w5CdJxyPE?= =?us-ascii?Q?M+8jdhmfOxY55vrE3GBJj88mmAhDkSK7ODQdaCxp2pHN+cUxNLUbwFQZ8DkF?= =?us-ascii?Q?GdT9b+9+riTo9aIgp5OHu9kFB68OCSP5kSJflrvHQze2Wwn54mEtDOBK+FTM?= =?us-ascii?Q?jzc/1GpwVS5UhSmheVPjKTEn1Wk4Vcb7aNRxm2I1FWOfVH2P9h8p+/RVgYWg?= =?us-ascii?Q?cJtwApkzeYs2rEJsUip50r5N4ulEsqyJsS9HIXjcsvwI9TtPlYev/EdwFhYQ?= =?us-ascii?Q?5F1gFef9Fj7Xr8223O/hQ7gA28nLR561QTXqSnu0A/HQPU0Cy0FO9Er1sZPG?= =?us-ascii?Q?dPaH9uR09gEwS/iQacPgH6uqAbq75N7NeXcWlT6uHw7OQ4mOkBl8oG90oHM1?= =?us-ascii?Q?97zAK5Y41SJrdiYlRjYPUL8s+6+8ZRt4OPVbNXcbKXGKSVVGB/9J/bALoj0t?= =?us-ascii?Q?XcvqAIVnVWJUEyb+RPUa1kO1T6XT7OmeJ31g21MyhGj8veTarLc9DDupwE9I?= =?us-ascii?Q?twTB1v67Rp04L/WWPomPKM+g8Sda68/wAgsJICeFX/gcYh0F5fJNi5Fk6dJL?= =?us-ascii?Q?kfpytJ7RgV9XflFTtGabvBRM9DkDedcdIEic1R3/vAFW+fzFITirWFeUTwo+?= =?us-ascii?Q?nuu1XkpIeftMkisidPzkvrXXH/Or6tXo4lTT0gFC2TpbpUWDowThdRs8fGHO?= =?us-ascii?Q?cNbVdgj8Nv+TqoTOn8z6ZCbObR1X+nqSNAhg9abO+SEMPNc3hXss4ugLbWG6?= =?us-ascii?Q?cbHWKY4gzNX1tO0NhB7HPOucuEo9zkYtyd7isPq+Zu4=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4058.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51216643-a245-4383-0eda-08d8c0df5ccb X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Jan 2021 03:14:43.7997 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ylvzKLeQenT+r4d2yVrOGbeWHIAhWd2ILauPFM+CsjetXtNVZZRSwtu7ZIPzXtOKfIIEJUoWzqXMdNRvfdppvA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB3785 Return-Path: star.zeng@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Does https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/Library/MpIni= tLib/MpLib.c#L909 (also decrements NumApsExecuting) also need be handled? Thanks, Star > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Michael > D Kinney > Sent: Saturday, January 23, 2021 1:10 AM > To: devel@edk2.groups.io > Cc: Dong, Eric ; Ni, Ray ; Laszlo > Ersek ; Kumar, Rahul1 > Subject: [edk2-devel] [Patch 1/1] UefiCpuPkg/Library/MpInitLib: Fix AP > VolatileRegisters race condition >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3182 >=20 > Fix the order of operations in ApWakeupFunction() when > PcdCpuApLoopMode > is set to HLT mode that uses INIT-SIPI-SIPI to wake APs. In this mode, > volatile state is restored and saved each time a INIT-SIPI-SIPI is sent > to an AP to request a function to be executed on the AP. When the > function is completed the volatile state of the AP is saved. However, > the counters NumApsExecuting and FinishedCount are updated before > the volatile state is saved. This allows for a race condition window > for the BSP that is waiting on these counters to request a new > INIT-SIPI-SIPI before all the APs have completely saved their volatile > state. The fix is to save the AP volatile state before updating the > NumApsExecuting and FinishedCount counters. >=20 > Cc: Eric Dong > Cc: Ray Ni > Cc: Laszlo Ersek > Cc: Rahul Kumar > Signed-off-by: Michael D Kinney > --- > UefiCpuPkg/Library/MpInitLib/MpLib.c | 31 ++++++++++++++++------------ > 1 file changed, 18 insertions(+), 13 deletions(-) >=20 > diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c > b/UefiCpuPkg/Library/MpInitLib/MpLib.c > index 681fa79b4cff..8b1f7f84bad6 100644 > --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c > +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c > @@ -769,15 +769,6 @@ ApWakeupFunction ( > RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegister= s, > FALSE); > InitializeApData (CpuMpData, ProcessorNumber, BistData, > ApTopOfStack); > ApStartupSignalBuffer =3D CpuMpData- > >CpuData[ProcessorNumber].StartupApSignal; > - > - // > - // Delay decrementing the APs executing count when SEV-ES is enab= led > - // to allow the APs to issue an AP_RESET_HOLD before the BSP poss= ibly > - // performs another INIT-SIPI-SIPI sequence. > - // > - if (!CpuMpData->SevEsIsEnabled) { > - InterlockedDecrement ((UINT32 *) &CpuMpData- > >MpCpuExchangeInfo->NumApsExecuting); > - } > } else { > // > // Execute AP function if AP is ready > @@ -866,19 +857,33 @@ ApWakeupFunction ( > } > } >=20 > + if (CpuMpData->ApLoopMode =3D=3D ApInHltLoop) { > + // > + // Save AP volatile registers > + // > + SaveVolatileRegisters (&CpuMpData- > >CpuData[ProcessorNumber].VolatileRegisters); > + } > + > // > // AP finished executing C code > // > InterlockedIncrement ((UINT32 *) &CpuMpData->FinishedCount); >=20 > + if (CpuMpData->InitFlag =3D=3D ApInitConfig) { > + // > + // Delay decrementing the APs executing count when SEV-ES is enab= led > + // to allow the APs to issue an AP_RESET_HOLD before the BSP poss= ibly > + // performs another INIT-SIPI-SIPI sequence. > + // > + if (!CpuMpData->SevEsIsEnabled) { > + InterlockedDecrement ((UINT32 *) &CpuMpData- > >MpCpuExchangeInfo->NumApsExecuting); > + } > + } > + > // > // Place AP is specified loop mode > // > if (CpuMpData->ApLoopMode =3D=3D ApInHltLoop) { > - // > - // Save AP volatile registers > - // > - SaveVolatileRegisters (&CpuMpData- > >CpuData[ProcessorNumber].VolatileRegisters); > // > // Place AP in HLT-loop > // > -- > 2.29.2.windows.2 >=20 >=20 >=20 >=20 >=20