From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 A4ED32096FAA0 for ; Wed, 20 Jun 2018 20:06:14 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Jun 2018 20:06:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,249,1526367600"; d="scan'208";a="65005102" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga004.fm.intel.com with ESMTP; 20 Jun 2018 20:06:14 -0700 Received: from fmsmsx101.amr.corp.intel.com (10.18.124.199) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 20 Jun 2018 20:06:13 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx101.amr.corp.intel.com (10.18.124.199) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 20 Jun 2018 20:06:13 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.87]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.116]) with mapi id 14.03.0319.002; Thu, 21 Jun 2018 11:06:11 +0800 From: "Ni, Ruiyu" To: Andrew Fish , edk2-devel Thread-Topic: [edk2] Is the PEI Core MP Safe? UefiCpuPkg seems to think so calling GetFirstGuidHob on the APs? Thread-Index: AQHUCLtnlbkBeiv3sEKMsmVZQhO3VaRqAPkg Date: Thu, 21 Jun 2018 03:06:10 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5BD3F73E@SHSMSX104.ccr.corp.intel.com> References: <31C6D3FB-91D3-491B-8059-4B6DEA11BDF9@apple.com> In-Reply-To: <31C6D3FB-91D3-491B-8059-4B6DEA11BDF9@apple.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: Is the PEI Core MP Safe? UefiCpuPkg seems to think so calling GetFirstGuidHob on the APs? X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jun 2018 03:06:14 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Andrew, Good catch! It does break the rule that AP shouldn't call PEI services. But considering the specific case, it should be safe. Because: 1. HOB only stores a pointer to the buffer that contains all the MP informa= tion. 2. BSP modifies the HOB by only appending data to the end. It may modifies = some HOB content. But MpInitLib implementation itself doesn't modify the pointer value stored in HOB. In PEI environment where global variable is read-only, it's hard to not rel= y on HOB. I guess that's the reason of today's tricky implementation. Thanks/Ray > -----Original Message----- > From: edk2-devel On Behalf Of Andrew > Fish > Sent: Thursday, June 21, 2018 1:23 AM > To: edk2-devel > Subject: [edk2] Is the PEI Core MP Safe? UefiCpuPkg seems to think so cal= ling > GetFirstGuidHob on the APs? >=20 > Is there some MP safe contract with the PEI Core implementation I don't > know about? >=20 > Looks like the APs are calling PeiServicesGetHobList() to figure out "who= they > are"? How does this work? Or am I missing something? >=20 >=20 > https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/Library/MpIni > tLib/MpLib.c#L1945 >=20 > /** > This return the handle number for the calling processor. This service = may be > called from the BSP and APs. > @param[out] ProcessorNumber Pointer to the handle number of AP. > The range is from 0 to the total number of > logical processors minus 1. The total numb= er of > logical processors can be retrieved by > MpInitLibGetNumberOfProcessors(). > @retval EFI_SUCCESS The current processor handle number was > returned > in ProcessorNumber. > @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL. > @retval EFI_NOT_READY MP Initialize Library is not initialize= d. > **/ > EFI_STATUS > EFIAPI > MpInitLibWhoAmI ( > OUT UINTN *ProcessorNumber > ) > { > CPU_MP_DATA *CpuMpData; >=20 > if (ProcessorNumber =3D=3D NULL) { > return EFI_INVALID_PARAMETER; > } >=20 > CpuMpData =3D GetCpuMpData (); >=20 > return GetProcessorNumber (CpuMpData, ProcessorNumber); } >=20 >=20 > https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/Library/MpIni > tLib/PeiMpLib.c#L34 >=20 > /** > Get pointer to CPU MP Data structure. > @return The pointer to CPU MP Data structure. > **/ > CPU_MP_DATA * > GetCpuMpData ( > VOID > ) > { > CPU_MP_DATA *CpuMpData; >=20 > CpuMpData =3D GetCpuMpDataFromGuidedHob (); > ASSERT (CpuMpData !=3D NULL); > return CpuMpData; > } >=20 > https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/Library/MpIni > tLib/MpLib.c#L2302 >=20 >=20 > /** > Get pointer to CPU MP Data structure from GUIDed HOB. > @return The pointer to CPU MP Data structure. > **/ > CPU_MP_DATA * > GetCpuMpDataFromGuidedHob ( > VOID > ) > { > EFI_HOB_GUID_TYPE *GuidHob; > VOID *DataInHob; > CPU_MP_DATA *CpuMpData; >=20 > CpuMpData =3D NULL; > GuidHob =3D GetFirstGuidHob (&mCpuInitMpLibHobGuid); > if (GuidHob !=3D NULL) { > DataInHob =3D GET_GUID_HOB_DATA (GuidHob); > CpuMpData =3D (CPU_MP_DATA *) (*(UINTN *) DataInHob); > } > return CpuMpData; > } >=20 > Thanks, >=20 > Andrew Fish > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel