From: Andrew Fish <afish@apple.com>
To: "Ni, Ruiyu" <ruiyu.ni@intel.com>
Cc: edk2-devel <edk2-devel@lists.01.org>
Subject: Re: Is the PEI Core MP Safe? UefiCpuPkg seems to think so calling GetFirstGuidHob on the APs?
Date: Wed, 20 Jun 2018 20:24:56 -0700 [thread overview]
Message-ID: <1800C800-ED89-4C23-89CB-E8E5E1CCE672@apple.com> (raw)
In-Reply-To: <734D49CCEBEEF84792F5B80ED585239D5BD3F73E@SHSMSX104.ccr.corp.intel.com>
> On Jun 20, 2018, at 8:06 PM, Ni, Ruiyu <ruiyu.ni@intel.com> wrote:
>
> 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 information.
> 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.
>
Ray,
I think the should be safe is also making assumptions about the debug and a few other library instances that got tested against. It is not really an architectural guaranty against the library classes that could be linked. We don't use the default
It would be good to use an IDT entry, or optionally a global variable if memory is present, longer term.
Thanks,
Andrew Fish
> In PEI environment where global variable is read-only, it's hard to not rely on HOB.
> I guess that's the reason of today's tricky implementation.
>
> Thanks/Ray
>
>> -----Original Message-----
>> From: edk2-devel <edk2-devel-bounces@lists.01.org> On Behalf Of Andrew
>> Fish
>> Sent: Thursday, June 21, 2018 1:23 AM
>> To: edk2-devel <edk2-devel@lists.01.org>
>> Subject: [edk2] Is the PEI Core MP Safe? UefiCpuPkg seems to think so calling
>> GetFirstGuidHob on the APs?
>>
>> Is there some MP safe contract with the PEI Core implementation I don't
>> know about?
>>
>> Looks like the APs are calling PeiServicesGetHobList() to figure out "who they
>> are"? How does this work? Or am I missing something?
>>
>>
>> https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/Library/MpIni
>> tLib/MpLib.c#L1945
>>
>> /**
>> 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 number 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 initialized.
>> **/
>> EFI_STATUS
>> EFIAPI
>> MpInitLibWhoAmI (
>> OUT UINTN *ProcessorNumber
>> )
>> {
>> CPU_MP_DATA *CpuMpData;
>>
>> if (ProcessorNumber == NULL) {
>> return EFI_INVALID_PARAMETER;
>> }
>>
>> CpuMpData = GetCpuMpData ();
>>
>> return GetProcessorNumber (CpuMpData, ProcessorNumber); }
>>
>>
>> https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/Library/MpIni
>> tLib/PeiMpLib.c#L34
>>
>> /**
>> Get pointer to CPU MP Data structure.
>> @return The pointer to CPU MP Data structure.
>> **/
>> CPU_MP_DATA *
>> GetCpuMpData (
>> VOID
>> )
>> {
>> CPU_MP_DATA *CpuMpData;
>>
>> CpuMpData = GetCpuMpDataFromGuidedHob ();
>> ASSERT (CpuMpData != NULL);
>> return CpuMpData;
>> }
>>
>> https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/Library/MpIni
>> tLib/MpLib.c#L2302
>>
>>
>> /**
>> 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;
>>
>> CpuMpData = NULL;
>> GuidHob = GetFirstGuidHob (&mCpuInitMpLibHobGuid);
>> if (GuidHob != NULL) {
>> DataInHob = GET_GUID_HOB_DATA (GuidHob);
>> CpuMpData = (CPU_MP_DATA *) (*(UINTN *) DataInHob);
>> }
>> return CpuMpData;
>> }
>>
>> Thanks,
>>
>> Andrew Fish
>> _______________________________________________
>> edk2-devel mailing list
>> edk2-devel@lists.01.org
>> https://lists.01.org/mailman/listinfo/edk2-devel
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
next prev parent reply other threads:[~2018-06-21 3:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-20 17:23 Is the PEI Core MP Safe? UefiCpuPkg seems to think so calling GetFirstGuidHob on the APs? Andrew Fish
2018-06-21 3:06 ` Ni, Ruiyu
2018-06-21 3:24 ` Andrew Fish [this message]
2018-06-21 3:34 ` Ni, Ruiyu
2018-06-21 5:57 ` Dong, Eric
2018-06-22 6:52 ` 答复: " Fan Jeff
2018-06-22 17:32 ` Andrew Fish
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1800C800-ED89-4C23-89CB-E8E5E1CCE672@apple.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox