* [PATCH v2 1/1] UefiCpuPkg/MpInitLib: Reduce reset vector memory pressure @ 2020-09-23 18:04 Lendacky, Thomas 2020-09-24 6:22 ` Laszlo Ersek 0 siblings, 1 reply; 9+ messages in thread From: Lendacky, Thomas @ 2020-09-23 18:04 UTC (permalink / raw) To: devel Cc: Eric Dong, Ray Ni, Laszlo Ersek, Rahul Kumar, Brijesh Singh, Garrett Kirkendall From: Tom Lendacky <thomas.lendacky@amd.com> The AP reset vector stack allocation is only required if running as an SEV-ES guest. Since the reset vector allocation is below 1MB in memory, eliminate the requirement for bare-metal systems and non SEV-ES guests to allocate the extra stack area, which can be large if the PcdCpuMaxLogicalProcessorNumber value is large, and also remove the CPU_STACK_ALIGNMENT alignment. Fixes: 7b7508ad784d ("UefiCpuPkg: Allow AP booting under SEV-ES") Cc: Garrett Kirkendall <garrett.kirkendall@amd.com> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 36 +++++++++----------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c index 07426274f639..a9708c6479d2 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -1141,20 +1141,6 @@ RestoreWakeupBuffer( ); } -/** - Calculate the size of the reset stack. - - @return Total amount of memory required for stacks -**/ -STATIC -UINTN -GetApResetStackSize ( - VOID - ) -{ - return AP_RESET_STACK_SIZE * PcdGet32(PcdCpuMaxLogicalProcessorNumber); -} - /** Calculate the size of the reset vector. @@ -1170,11 +1156,23 @@ GetApResetVectorSize ( { UINTN Size; - Size = ALIGN_VALUE (AddressMap->RendezvousFunnelSize + - AddressMap->SwitchToRealSize + - sizeof (MP_CPU_EXCHANGE_INFO), - CPU_STACK_ALIGNMENT); - Size += GetApResetStackSize (); + Size = AddressMap->RendezvousFunnelSize + + AddressMap->SwitchToRealSize + + sizeof (MP_CPU_EXCHANGE_INFO); + + // + // The AP reset stack is only used by SEV-ES guests. Do not add to the + // allocation if SEV-ES is not enabled. + // + if (PcdGetBool (PcdSevEsIsEnabled)) { + // + // Stack location is based on APIC ID, so use the total number of + // processors for calculating the total stack area. + // + Size += AP_RESET_STACK_SIZE * PcdGet32(PcdCpuMaxLogicalProcessorNumber); + + Size = ALIGN_VALUE (Size, CPU_STACK_ALIGNMENT); + } return Size; } -- 2.28.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/1] UefiCpuPkg/MpInitLib: Reduce reset vector memory pressure 2020-09-23 18:04 [PATCH v2 1/1] UefiCpuPkg/MpInitLib: Reduce reset vector memory pressure Lendacky, Thomas @ 2020-09-24 6:22 ` Laszlo Ersek 2020-09-24 13:30 ` Lendacky, Thomas 2020-09-25 16:09 ` [edk2-devel] " Brian J. Johnson 0 siblings, 2 replies; 9+ messages in thread From: Laszlo Ersek @ 2020-09-24 6:22 UTC (permalink / raw) To: Tom Lendacky, devel Cc: Eric Dong, Ray Ni, Rahul Kumar, Brijesh Singh, Garrett Kirkendall On 09/23/20 20:04, Tom Lendacky wrote: > From: Tom Lendacky <thomas.lendacky@amd.com> > > The AP reset vector stack allocation is only required if running as an > SEV-ES guest. Since the reset vector allocation is below 1MB in memory, > eliminate the requirement for bare-metal systems and non SEV-ES guests > to allocate the extra stack area, which can be large if the > PcdCpuMaxLogicalProcessorNumber value is large, and also remove the > CPU_STACK_ALIGNMENT alignment. > > Fixes: 7b7508ad784d ("UefiCpuPkg: Allow AP booting under SEV-ES") > Cc: Garrett Kirkendall <garrett.kirkendall@amd.com> > Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> > --- > UefiCpuPkg/Library/MpInitLib/MpLib.c | 36 +++++++++----------- > 1 file changed, 17 insertions(+), 19 deletions(-) > > diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c > index 07426274f639..a9708c6479d2 100644 > --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c > +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c > @@ -1141,20 +1141,6 @@ RestoreWakeupBuffer( > ); > } > > -/** > - Calculate the size of the reset stack. > - > - @return Total amount of memory required for stacks > -**/ > -STATIC > -UINTN > -GetApResetStackSize ( > - VOID > - ) > -{ > - return AP_RESET_STACK_SIZE * PcdGet32(PcdCpuMaxLogicalProcessorNumber); > -} > - > /** > Calculate the size of the reset vector. > > @@ -1170,11 +1156,23 @@ GetApResetVectorSize ( > { > UINTN Size; > > - Size = ALIGN_VALUE (AddressMap->RendezvousFunnelSize + > - AddressMap->SwitchToRealSize + > - sizeof (MP_CPU_EXCHANGE_INFO), > - CPU_STACK_ALIGNMENT); > - Size += GetApResetStackSize (); > + Size = AddressMap->RendezvousFunnelSize + > + AddressMap->SwitchToRealSize + > + sizeof (MP_CPU_EXCHANGE_INFO); > + > + // > + // The AP reset stack is only used by SEV-ES guests. Do not add to the > + // allocation if SEV-ES is not enabled. > + // > + if (PcdGetBool (PcdSevEsIsEnabled)) { > + // > + // Stack location is based on APIC ID, so use the total number of > + // processors for calculating the total stack area. > + // > + Size += AP_RESET_STACK_SIZE * PcdGet32(PcdCpuMaxLogicalProcessorNumber); > + > + Size = ALIGN_VALUE (Size, CPU_STACK_ALIGNMENT); > + } > > return Size; > } > - I don't remember if it's required that the APIC ID space be densely populated. For example, if we have a topology with 7 possible (= maximum) logical CPUs, I'm unsure if a spec forbids any of those CPUs from having APIC ID 7. That could cause a problem in MpInitLibSevEsAPReset(), I assume. Anyway: that's a different topic. This patch looks OK to me because it only spells out the existent assumption wrt. APIC IDs vs. PcdCpuMaxLogicalProcessorNumber, plus it does solve the problem it wants to solve. - I was a bit surprised at first upon seeing the reordering of alignment vs. addition. But AP_RESET_STACK_SIZE is a whole multiple of CPU_STACK_ALIGNMENT. So adding AP_RESET_STACK_SIZE to Size n times as first step, does not change the congruence class of Size modulo CPU_STACK_ALIGNMENT. Therefore ALIGN_VALUE() will increment Size by the same value, regardless of whether it's done before or after the AP_RESET_STACK_SIZE additions. - We should insert a space character after "PcdGet32", before merging this patch. I think Ray or Eric could do this without a repost. Reviewed-by: Laszlo Ersek <lersek@redhat.com> Thanks Laszlo ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/1] UefiCpuPkg/MpInitLib: Reduce reset vector memory pressure 2020-09-24 6:22 ` Laszlo Ersek @ 2020-09-24 13:30 ` Lendacky, Thomas 2020-09-24 15:03 ` Laszlo Ersek 2020-09-25 16:09 ` [edk2-devel] " Brian J. Johnson 1 sibling, 1 reply; 9+ messages in thread From: Lendacky, Thomas @ 2020-09-24 13:30 UTC (permalink / raw) To: Laszlo Ersek, devel Cc: Eric Dong, Ray Ni, Rahul Kumar, Brijesh Singh, Garrett Kirkendall On 9/24/20 1:22 AM, Laszlo Ersek wrote: > On 09/23/20 20:04, Tom Lendacky wrote: >> From: Tom Lendacky <thomas.lendacky@amd.com> >> >> The AP reset vector stack allocation is only required if running as an >> SEV-ES guest. Since the reset vector allocation is below 1MB in memory, >> eliminate the requirement for bare-metal systems and non SEV-ES guests >> to allocate the extra stack area, which can be large if the >> PcdCpuMaxLogicalProcessorNumber value is large, and also remove the >> CPU_STACK_ALIGNMENT alignment. >> >> Fixes: 7b7508ad784d ("UefiCpuPkg: Allow AP booting under SEV-ES") >> Cc: Garrett Kirkendall <garrett.kirkendall@amd.com> >> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> >> --- >> UefiCpuPkg/Library/MpInitLib/MpLib.c | 36 +++++++++----------- >> 1 file changed, 17 insertions(+), 19 deletions(-) >> >> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c >> index 07426274f639..a9708c6479d2 100644 >> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c >> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c >> @@ -1141,20 +1141,6 @@ RestoreWakeupBuffer( >> ); >> } >> >> -/** >> - Calculate the size of the reset stack. >> - >> - @return Total amount of memory required for stacks >> -**/ >> -STATIC >> -UINTN >> -GetApResetStackSize ( >> - VOID >> - ) >> -{ >> - return AP_RESET_STACK_SIZE * PcdGet32(PcdCpuMaxLogicalProcessorNumber); >> -} >> - >> /** >> Calculate the size of the reset vector. >> >> @@ -1170,11 +1156,23 @@ GetApResetVectorSize ( >> { >> UINTN Size; >> >> - Size = ALIGN_VALUE (AddressMap->RendezvousFunnelSize + >> - AddressMap->SwitchToRealSize + >> - sizeof (MP_CPU_EXCHANGE_INFO), >> - CPU_STACK_ALIGNMENT); >> - Size += GetApResetStackSize (); >> + Size = AddressMap->RendezvousFunnelSize + >> + AddressMap->SwitchToRealSize + >> + sizeof (MP_CPU_EXCHANGE_INFO); >> + >> + // >> + // The AP reset stack is only used by SEV-ES guests. Do not add to the >> + // allocation if SEV-ES is not enabled. >> + // >> + if (PcdGetBool (PcdSevEsIsEnabled)) { >> + // >> + // Stack location is based on APIC ID, so use the total number of >> + // processors for calculating the total stack area. >> + // >> + Size += AP_RESET_STACK_SIZE * PcdGet32(PcdCpuMaxLogicalProcessorNumber); >> + >> + Size = ALIGN_VALUE (Size, CPU_STACK_ALIGNMENT); >> + } >> >> return Size; >> } >> > > - I don't remember if it's required that the APIC ID space be densely > populated. For example, if we have a topology with 7 possible (= > maximum) logical CPUs, I'm unsure if a spec forbids any of those CPUs > from having APIC ID 7. That could cause a problem in > MpInitLibSevEsAPReset(), I assume. > > Anyway: that's a different topic. This patch looks OK to me because it > only spells out the existent assumption wrt. APIC IDs vs. > PcdCpuMaxLogicalProcessorNumber, plus it does solve the problem it wants > to solve. > > - I was a bit surprised at first upon seeing the reordering of alignment > vs. addition. But AP_RESET_STACK_SIZE is a whole multiple of > CPU_STACK_ALIGNMENT. So adding AP_RESET_STACK_SIZE to Size n times as > first step, does not change the congruence class of Size modulo > CPU_STACK_ALIGNMENT. Therefore ALIGN_VALUE() will increment Size by the > same value, regardless of whether it's done before or after the > AP_RESET_STACK_SIZE additions. Ah, yes, I did change that order. I could submit one more version that puts the ALIGN_VALUE back to the original position and fix the PcdGet32 space if that is desired (but, as you determined, it doesn't change the resulting value). I'm surprised that PatchCheck.py didn't pick up on the spacing with PcdGet32. Thanks, Tom > > - We should insert a space character after "PcdGet32", before merging > this patch. I think Ray or Eric could do this without a repost. > > Reviewed-by: Laszlo Ersek <lersek@redhat.com> > > Thanks > Laszlo > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/1] UefiCpuPkg/MpInitLib: Reduce reset vector memory pressure 2020-09-24 13:30 ` Lendacky, Thomas @ 2020-09-24 15:03 ` Laszlo Ersek 2020-10-02 16:42 ` Lendacky, Thomas 0 siblings, 1 reply; 9+ messages in thread From: Laszlo Ersek @ 2020-09-24 15:03 UTC (permalink / raw) To: Tom Lendacky, devel Cc: Eric Dong, Ray Ni, Rahul Kumar, Brijesh Singh, Garrett Kirkendall On 09/24/20 15:30, Tom Lendacky wrote: > On 9/24/20 1:22 AM, Laszlo Ersek wrote: >> On 09/23/20 20:04, Tom Lendacky wrote: >>> From: Tom Lendacky <thomas.lendacky@amd.com> >>> >>> The AP reset vector stack allocation is only required if running as an >>> SEV-ES guest. Since the reset vector allocation is below 1MB in memory, >>> eliminate the requirement for bare-metal systems and non SEV-ES guests >>> to allocate the extra stack area, which can be large if the >>> PcdCpuMaxLogicalProcessorNumber value is large, and also remove the >>> CPU_STACK_ALIGNMENT alignment. >>> >>> Fixes: 7b7508ad784d ("UefiCpuPkg: Allow AP booting under SEV-ES") >>> Cc: Garrett Kirkendall <garrett.kirkendall@amd.com> >>> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> >>> --- >>> UefiCpuPkg/Library/MpInitLib/MpLib.c | 36 +++++++++----------- >>> 1 file changed, 17 insertions(+), 19 deletions(-) >>> >>> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c >>> b/UefiCpuPkg/Library/MpInitLib/MpLib.c >>> index 07426274f639..a9708c6479d2 100644 >>> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c >>> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c >>> @@ -1141,20 +1141,6 @@ RestoreWakeupBuffer( >>> ); >>> } >>> -/** >>> - Calculate the size of the reset stack. >>> - >>> - @return Total amount of memory required for stacks >>> -**/ >>> -STATIC >>> -UINTN >>> -GetApResetStackSize ( >>> - VOID >>> - ) >>> -{ >>> - return AP_RESET_STACK_SIZE * >>> PcdGet32(PcdCpuMaxLogicalProcessorNumber); >>> -} >>> - >>> /** >>> Calculate the size of the reset vector. >>> @@ -1170,11 +1156,23 @@ GetApResetVectorSize ( >>> { >>> UINTN Size; >>> - Size = ALIGN_VALUE (AddressMap->RendezvousFunnelSize + >>> - AddressMap->SwitchToRealSize + >>> - sizeof (MP_CPU_EXCHANGE_INFO), >>> - CPU_STACK_ALIGNMENT); >>> - Size += GetApResetStackSize (); >>> + Size = AddressMap->RendezvousFunnelSize + >>> + AddressMap->SwitchToRealSize + >>> + sizeof (MP_CPU_EXCHANGE_INFO); >>> + >>> + // >>> + // The AP reset stack is only used by SEV-ES guests. Do not add to >>> the >>> + // allocation if SEV-ES is not enabled. >>> + // >>> + if (PcdGetBool (PcdSevEsIsEnabled)) { >>> + // >>> + // Stack location is based on APIC ID, so use the total number of >>> + // processors for calculating the total stack area. >>> + // >>> + Size += AP_RESET_STACK_SIZE * >>> PcdGet32(PcdCpuMaxLogicalProcessorNumber); >>> + >>> + Size = ALIGN_VALUE (Size, CPU_STACK_ALIGNMENT); >>> + } >>> return Size; >>> } >>> >> >> - I don't remember if it's required that the APIC ID space be densely >> populated. For example, if we have a topology with 7 possible (= >> maximum) logical CPUs, I'm unsure if a spec forbids any of those CPUs >> from having APIC ID 7. That could cause a problem in >> MpInitLibSevEsAPReset(), I assume. >> >> Anyway: that's a different topic. This patch looks OK to me because it >> only spells out the existent assumption wrt. APIC IDs vs. >> PcdCpuMaxLogicalProcessorNumber, plus it does solve the problem it wants >> to solve. >> >> - I was a bit surprised at first upon seeing the reordering of alignment >> vs. addition. But AP_RESET_STACK_SIZE is a whole multiple of >> CPU_STACK_ALIGNMENT. So adding AP_RESET_STACK_SIZE to Size n times as >> first step, does not change the congruence class of Size modulo >> CPU_STACK_ALIGNMENT. Therefore ALIGN_VALUE() will increment Size by the >> same value, regardless of whether it's done before or after the >> AP_RESET_STACK_SIZE additions. > > Ah, yes, I did change that order. I could submit one more version that > puts the ALIGN_VALUE back to the original position and fix the PcdGet32 > space if that is desired (but, as you determined, it doesn't change the > resulting value). Given that the stack grows down, one could plausibly claim that the variant seen in this patch (= align at last) is *more* intuitive. I'm OK with this version merged (with the whitespace fixed up). > I'm surprised that PatchCheck.py didn't pick up on the > spacing with PcdGet32. Or maybe ECC should warn about it in CI?... Thanks Laszlo ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/1] UefiCpuPkg/MpInitLib: Reduce reset vector memory pressure 2020-09-24 15:03 ` Laszlo Ersek @ 2020-10-02 16:42 ` Lendacky, Thomas 2020-10-19 15:02 ` Lendacky, Thomas 0 siblings, 1 reply; 9+ messages in thread From: Lendacky, Thomas @ 2020-10-02 16:42 UTC (permalink / raw) To: Laszlo Ersek, devel Cc: Eric Dong, Ray Ni, Rahul Kumar, Brijesh Singh, Garrett Kirkendall On 9/24/20 10:03 AM, Laszlo Ersek wrote: > On 09/24/20 15:30, Tom Lendacky wrote: >> On 9/24/20 1:22 AM, Laszlo Ersek wrote: >>> On 09/23/20 20:04, Tom Lendacky wrote: >>>> From: Tom Lendacky <thomas.lendacky@amd.com> >>>> >>>> The AP reset vector stack allocation is only required if running as an >>>> SEV-ES guest. Since the reset vector allocation is below 1MB in memory, >>>> eliminate the requirement for bare-metal systems and non SEV-ES guests >>>> to allocate the extra stack area, which can be large if the >>>> PcdCpuMaxLogicalProcessorNumber value is large, and also remove the >>>> CPU_STACK_ALIGNMENT alignment. >>>> >>>> Fixes: 7b7508ad784d ("UefiCpuPkg: Allow AP booting under SEV-ES") >>>> Cc: Garrett Kirkendall <garrett.kirkendall@amd.com> >>>> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> >>>> --- >>>> UefiCpuPkg/Library/MpInitLib/MpLib.c | 36 +++++++++----------- >>>> 1 file changed, 17 insertions(+), 19 deletions(-) >>>> >>>> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c >>>> b/UefiCpuPkg/Library/MpInitLib/MpLib.c >>>> index 07426274f639..a9708c6479d2 100644 >>>> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c >>>> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c >>>> @@ -1141,20 +1141,6 @@ RestoreWakeupBuffer( >>>> ); >>>> } >>>> -/** >>>> - Calculate the size of the reset stack. >>>> - >>>> - @return Total amount of memory required for stacks >>>> -**/ >>>> -STATIC >>>> -UINTN >>>> -GetApResetStackSize ( >>>> - VOID >>>> - ) >>>> -{ >>>> - return AP_RESET_STACK_SIZE * >>>> PcdGet32(PcdCpuMaxLogicalProcessorNumber); >>>> -} >>>> - >>>> /** >>>> Calculate the size of the reset vector. >>>> @@ -1170,11 +1156,23 @@ GetApResetVectorSize ( >>>> { >>>> UINTN Size; >>>> - Size = ALIGN_VALUE (AddressMap->RendezvousFunnelSize + >>>> - AddressMap->SwitchToRealSize + >>>> - sizeof (MP_CPU_EXCHANGE_INFO), >>>> - CPU_STACK_ALIGNMENT); >>>> - Size += GetApResetStackSize (); >>>> + Size = AddressMap->RendezvousFunnelSize + >>>> + AddressMap->SwitchToRealSize + >>>> + sizeof (MP_CPU_EXCHANGE_INFO); >>>> + >>>> + // >>>> + // The AP reset stack is only used by SEV-ES guests. Do not add to >>>> the >>>> + // allocation if SEV-ES is not enabled. >>>> + // >>>> + if (PcdGetBool (PcdSevEsIsEnabled)) { >>>> + // >>>> + // Stack location is based on APIC ID, so use the total number of >>>> + // processors for calculating the total stack area. >>>> + // >>>> + Size += AP_RESET_STACK_SIZE * >>>> PcdGet32(PcdCpuMaxLogicalProcessorNumber); >>>> + >>>> + Size = ALIGN_VALUE (Size, CPU_STACK_ALIGNMENT); >>>> + } >>>> return Size; >>>> } >>>> >>> >>> - I don't remember if it's required that the APIC ID space be densely >>> populated. For example, if we have a topology with 7 possible (= >>> maximum) logical CPUs, I'm unsure if a spec forbids any of those CPUs >>> from having APIC ID 7. That could cause a problem in >>> MpInitLibSevEsAPReset(), I assume. >>> >>> Anyway: that's a different topic. This patch looks OK to me because it >>> only spells out the existent assumption wrt. APIC IDs vs. >>> PcdCpuMaxLogicalProcessorNumber, plus it does solve the problem it wants >>> to solve. >>> >>> - I was a bit surprised at first upon seeing the reordering of alignment >>> vs. addition. But AP_RESET_STACK_SIZE is a whole multiple of >>> CPU_STACK_ALIGNMENT. So adding AP_RESET_STACK_SIZE to Size n times as >>> first step, does not change the congruence class of Size modulo >>> CPU_STACK_ALIGNMENT. Therefore ALIGN_VALUE() will increment Size by the >>> same value, regardless of whether it's done before or after the >>> AP_RESET_STACK_SIZE additions. >> >> Ah, yes, I did change that order. I could submit one more version that >> puts the ALIGN_VALUE back to the original position and fix the PcdGet32 >> space if that is desired (but, as you determined, it doesn't change the >> resulting value). > > Given that the stack grows down, one could plausibly claim that the > variant seen in this patch (= align at last) is *more* intuitive. > > I'm OK with this version merged (with the whitespace fixed up). Any concern from the maintainers on this? Are you waiting on me for anything? Just want to check... Thanks, Tom > >> I'm surprised that PatchCheck.py didn't pick up on the >> spacing with PcdGet32. > > Or maybe ECC should warn about it in CI?... > > Thanks > Laszlo > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/1] UefiCpuPkg/MpInitLib: Reduce reset vector memory pressure 2020-10-02 16:42 ` Lendacky, Thomas @ 2020-10-19 15:02 ` Lendacky, Thomas 2020-10-19 21:51 ` Laszlo Ersek 0 siblings, 1 reply; 9+ messages in thread From: Lendacky, Thomas @ 2020-10-19 15:02 UTC (permalink / raw) To: devel, Eric Dong, Ray Ni Cc: Laszlo Ersek, Rahul Kumar, Brijesh Singh, Garrett Kirkendall On 10/2/20 11:42 AM, Tom Lendacky wrote: > On 9/24/20 10:03 AM, Laszlo Ersek wrote: >> On 09/24/20 15:30, Tom Lendacky wrote: >>> On 9/24/20 1:22 AM, Laszlo Ersek wrote: >>>> On 09/23/20 20:04, Tom Lendacky wrote: >>>>> From: Tom Lendacky <thomas.lendacky@amd.com> >>>>> >>>>> The AP reset vector stack allocation is only required if running as an >>>>> SEV-ES guest. Since the reset vector allocation is below 1MB in memory, >>>>> eliminate the requirement for bare-metal systems and non SEV-ES guests >>>>> to allocate the extra stack area, which can be large if the >>>>> PcdCpuMaxLogicalProcessorNumber value is large, and also remove the >>>>> CPU_STACK_ALIGNMENT alignment. >>>>> >>>>> Fixes: 7b7508ad784d ("UefiCpuPkg: Allow AP booting under SEV-ES") >>>>> Cc: Garrett Kirkendall <garrett.kirkendall@amd.com> >>>>> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> >>>>> --- >>>>> UefiCpuPkg/Library/MpInitLib/MpLib.c | 36 +++++++++----------- >>>>> 1 file changed, 17 insertions(+), 19 deletions(-) >>>>> >>>>> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c >>>>> b/UefiCpuPkg/Library/MpInitLib/MpLib.c >>>>> index 07426274f639..a9708c6479d2 100644 >>>>> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c >>>>> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c >>>>> @@ -1141,20 +1141,6 @@ RestoreWakeupBuffer( >>>>> ); >>>>> } >>>>> -/** >>>>> - Calculate the size of the reset stack. >>>>> - >>>>> - @return Total amount of memory required for stacks >>>>> -**/ >>>>> -STATIC >>>>> -UINTN >>>>> -GetApResetStackSize ( >>>>> - VOID >>>>> - ) >>>>> -{ >>>>> - return AP_RESET_STACK_SIZE * >>>>> PcdGet32(PcdCpuMaxLogicalProcessorNumber); >>>>> -} >>>>> - >>>>> /** >>>>> Calculate the size of the reset vector. >>>>> @@ -1170,11 +1156,23 @@ GetApResetVectorSize ( >>>>> { >>>>> UINTN Size; >>>>> - Size = ALIGN_VALUE (AddressMap->RendezvousFunnelSize + >>>>> - AddressMap->SwitchToRealSize + >>>>> - sizeof (MP_CPU_EXCHANGE_INFO), >>>>> - CPU_STACK_ALIGNMENT); >>>>> - Size += GetApResetStackSize (); >>>>> + Size = AddressMap->RendezvousFunnelSize + >>>>> + AddressMap->SwitchToRealSize + >>>>> + sizeof (MP_CPU_EXCHANGE_INFO); >>>>> + >>>>> + // >>>>> + // The AP reset stack is only used by SEV-ES guests. Do not add to >>>>> the >>>>> + // allocation if SEV-ES is not enabled. >>>>> + // >>>>> + if (PcdGetBool (PcdSevEsIsEnabled)) { >>>>> + // >>>>> + // Stack location is based on APIC ID, so use the total number of >>>>> + // processors for calculating the total stack area. >>>>> + // >>>>> + Size += AP_RESET_STACK_SIZE * >>>>> PcdGet32(PcdCpuMaxLogicalProcessorNumber); >>>>> + >>>>> + Size = ALIGN_VALUE (Size, CPU_STACK_ALIGNMENT); >>>>> + } >>>>> return Size; >>>>> } >>>>> >>>> >>>> - I don't remember if it's required that the APIC ID space be densely >>>> populated. For example, if we have a topology with 7 possible (= >>>> maximum) logical CPUs, I'm unsure if a spec forbids any of those CPUs >>>> from having APIC ID 7. That could cause a problem in >>>> MpInitLibSevEsAPReset(), I assume. >>>> >>>> Anyway: that's a different topic. This patch looks OK to me because it >>>> only spells out the existent assumption wrt. APIC IDs vs. >>>> PcdCpuMaxLogicalProcessorNumber, plus it does solve the problem it wants >>>> to solve. >>>> >>>> - I was a bit surprised at first upon seeing the reordering of alignment >>>> vs. addition. But AP_RESET_STACK_SIZE is a whole multiple of >>>> CPU_STACK_ALIGNMENT. So adding AP_RESET_STACK_SIZE to Size n times as >>>> first step, does not change the congruence class of Size modulo >>>> CPU_STACK_ALIGNMENT. Therefore ALIGN_VALUE() will increment Size by the >>>> same value, regardless of whether it's done before or after the >>>> AP_RESET_STACK_SIZE additions. >>> >>> Ah, yes, I did change that order. I could submit one more version that >>> puts the ALIGN_VALUE back to the original position and fix the PcdGet32 >>> space if that is desired (but, as you determined, it doesn't change the >>> resulting value). >> >> Given that the stack grows down, one could plausibly claim that the >> variant seen in this patch (= align at last) is *more* intuitive. >> >> I'm OK with this version merged (with the whitespace fixed up). > > Any concern from the maintainers on this? Are you waiting on me for > anything? Just want to check... Another ping to see what the status of this patch is... Thanks, Tom > > Thanks, > Tom > >> >>> I'm surprised that PatchCheck.py didn't pick up on the >>> spacing with PcdGet32. >> >> Or maybe ECC should warn about it in CI?... >> >> Thanks >> Laszlo >> ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/1] UefiCpuPkg/MpInitLib: Reduce reset vector memory pressure 2020-10-19 15:02 ` Lendacky, Thomas @ 2020-10-19 21:51 ` Laszlo Ersek 0 siblings, 0 replies; 9+ messages in thread From: Laszlo Ersek @ 2020-10-19 21:51 UTC (permalink / raw) To: Tom Lendacky, devel, Eric Dong, Ray Ni Cc: Rahul Kumar, Brijesh Singh, Garrett Kirkendall On 10/19/20 17:02, Tom Lendacky wrote: > On 10/2/20 11:42 AM, Tom Lendacky wrote: >> On 9/24/20 10:03 AM, Laszlo Ersek wrote: >>> On 09/24/20 15:30, Tom Lendacky wrote: >>>> On 9/24/20 1:22 AM, Laszlo Ersek wrote: >>>>> On 09/23/20 20:04, Tom Lendacky wrote: >>>>>> From: Tom Lendacky <thomas.lendacky@amd.com> >>>>>> >>>>>> The AP reset vector stack allocation is only required if running as an >>>>>> SEV-ES guest. Since the reset vector allocation is below 1MB in memory, >>>>>> eliminate the requirement for bare-metal systems and non SEV-ES guests >>>>>> to allocate the extra stack area, which can be large if the >>>>>> PcdCpuMaxLogicalProcessorNumber value is large, and also remove the >>>>>> CPU_STACK_ALIGNMENT alignment. >>>>>> >>>>>> Fixes: 7b7508ad784d ("UefiCpuPkg: Allow AP booting under SEV-ES") >>>>>> Cc: Garrett Kirkendall <garrett.kirkendall@amd.com> >>>>>> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> >>>>>> --- >>>>>> UefiCpuPkg/Library/MpInitLib/MpLib.c | 36 +++++++++----------- >>>>>> 1 file changed, 17 insertions(+), 19 deletions(-) >>>>>> >>>>>> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c >>>>>> b/UefiCpuPkg/Library/MpInitLib/MpLib.c >>>>>> index 07426274f639..a9708c6479d2 100644 >>>>>> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c >>>>>> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c >>>>>> @@ -1141,20 +1141,6 @@ RestoreWakeupBuffer( >>>>>> ); >>>>>> } >>>>>> -/** >>>>>> - Calculate the size of the reset stack. >>>>>> - >>>>>> - @return Total amount of memory required for stacks >>>>>> -**/ >>>>>> -STATIC >>>>>> -UINTN >>>>>> -GetApResetStackSize ( >>>>>> - VOID >>>>>> - ) >>>>>> -{ >>>>>> - return AP_RESET_STACK_SIZE * >>>>>> PcdGet32(PcdCpuMaxLogicalProcessorNumber); >>>>>> -} >>>>>> - >>>>>> /** >>>>>> Calculate the size of the reset vector. >>>>>> @@ -1170,11 +1156,23 @@ GetApResetVectorSize ( >>>>>> { >>>>>> UINTN Size; >>>>>> - Size = ALIGN_VALUE (AddressMap->RendezvousFunnelSize + >>>>>> - AddressMap->SwitchToRealSize + >>>>>> - sizeof (MP_CPU_EXCHANGE_INFO), >>>>>> - CPU_STACK_ALIGNMENT); >>>>>> - Size += GetApResetStackSize (); >>>>>> + Size = AddressMap->RendezvousFunnelSize + >>>>>> + AddressMap->SwitchToRealSize + >>>>>> + sizeof (MP_CPU_EXCHANGE_INFO); >>>>>> + >>>>>> + // >>>>>> + // The AP reset stack is only used by SEV-ES guests. Do not add to >>>>>> the >>>>>> + // allocation if SEV-ES is not enabled. >>>>>> + // >>>>>> + if (PcdGetBool (PcdSevEsIsEnabled)) { >>>>>> + // >>>>>> + // Stack location is based on APIC ID, so use the total number of >>>>>> + // processors for calculating the total stack area. >>>>>> + // >>>>>> + Size += AP_RESET_STACK_SIZE * >>>>>> PcdGet32(PcdCpuMaxLogicalProcessorNumber); >>>>>> + >>>>>> + Size = ALIGN_VALUE (Size, CPU_STACK_ALIGNMENT); >>>>>> + } >>>>>> return Size; >>>>>> } >>>>>> >>>>> >>>>> - I don't remember if it's required that the APIC ID space be densely >>>>> populated. For example, if we have a topology with 7 possible (= >>>>> maximum) logical CPUs, I'm unsure if a spec forbids any of those CPUs >>>>> from having APIC ID 7. That could cause a problem in >>>>> MpInitLibSevEsAPReset(), I assume. >>>>> >>>>> Anyway: that's a different topic. This patch looks OK to me because it >>>>> only spells out the existent assumption wrt. APIC IDs vs. >>>>> PcdCpuMaxLogicalProcessorNumber, plus it does solve the problem it wants >>>>> to solve. >>>>> >>>>> - I was a bit surprised at first upon seeing the reordering of alignment >>>>> vs. addition. But AP_RESET_STACK_SIZE is a whole multiple of >>>>> CPU_STACK_ALIGNMENT. So adding AP_RESET_STACK_SIZE to Size n times as >>>>> first step, does not change the congruence class of Size modulo >>>>> CPU_STACK_ALIGNMENT. Therefore ALIGN_VALUE() will increment Size by the >>>>> same value, regardless of whether it's done before or after the >>>>> AP_RESET_STACK_SIZE additions. >>>> >>>> Ah, yes, I did change that order. I could submit one more version that >>>> puts the ALIGN_VALUE back to the original position and fix the PcdGet32 >>>> space if that is desired (but, as you determined, it doesn't change the >>>> resulting value). >>> >>> Given that the stack grows down, one could plausibly claim that the >>> variant seen in this patch (= align at last) is *more* intuitive. >>> >>> I'm OK with this version merged (with the whitespace fixed up). >> >> Any concern from the maintainers on this? Are you waiting on me for >> anything? Just want to check... > > Another ping to see what the status of this patch is... ... I guess we might as well break the process for a noble purpose, every once in a while, so I went ahead and merged this... with just my R-b. - [lersek@redhat.com: supply missing space character after "PcdGet32"] - commit 93edd1887e34 - https://github.com/tianocore/edk2/pull/1031 Thanks Laszlo >>>> I'm surprised that PatchCheck.py didn't pick up on the >>>> spacing with PcdGet32. >>> >>> Or maybe ECC should warn about it in CI?... >>> >>> Thanks >>> Laszlo >>> > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [edk2-devel] [PATCH v2 1/1] UefiCpuPkg/MpInitLib: Reduce reset vector memory pressure 2020-09-24 6:22 ` Laszlo Ersek 2020-09-24 13:30 ` Lendacky, Thomas @ 2020-09-25 16:09 ` Brian J. Johnson 2020-09-25 16:52 ` Lendacky, Thomas 1 sibling, 1 reply; 9+ messages in thread From: Brian J. Johnson @ 2020-09-25 16:09 UTC (permalink / raw) To: devel, lersek, Tom Lendacky Cc: Eric Dong, Ray Ni, Rahul Kumar, Brijesh Singh, Garrett Kirkendall On 9/24/20 1:22 AM, Laszlo Ersek wrote: > - I don't remember if it's required that the APIC ID space be densely > populated. For example, if we have a topology with 7 possible (= > maximum) logical CPUs, I'm unsure if a spec forbids any of those CPUs > from having APIC ID 7. That could cause a problem in > MpInitLibSevEsAPReset(), I assume. FWIW, there are many bare metal processors with non-contiguous APIC IDs. Intel puts the socket ID in the upper bits of the APIC ID. So if the socket doesn't have a power-of-two number of cores, there is always a gap. Plus, the BSP doesn't always have APIC ID 0 -- it depends on which physical cores passed the manufacturing tests for that particular part. That has broken various kernels, BIOSes, and other software at times. So it's best not to make assumptions. I don't know if that applies to VMs, though. The standards may be different (if there are any standards at all in that area.) -- Brian J. Johnson Enterprise X86 Lab Hewlett Packard Enterprise ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [edk2-devel] [PATCH v2 1/1] UefiCpuPkg/MpInitLib: Reduce reset vector memory pressure 2020-09-25 16:09 ` [edk2-devel] " Brian J. Johnson @ 2020-09-25 16:52 ` Lendacky, Thomas 0 siblings, 0 replies; 9+ messages in thread From: Lendacky, Thomas @ 2020-09-25 16:52 UTC (permalink / raw) To: Brian J. Johnson, devel, lersek Cc: Eric Dong, Ray Ni, Rahul Kumar, Brijesh Singh, Garrett Kirkendall On 9/25/20 11:09 AM, Brian J. Johnson wrote: > On 9/24/20 1:22 AM, Laszlo Ersek wrote: >> - I don't remember if it's required that the APIC ID space be densely >> populated. For example, if we have a topology with 7 possible (= >> maximum) logical CPUs, I'm unsure if a spec forbids any of those CPUs >> from having APIC ID 7. That could cause a problem in >> MpInitLibSevEsAPReset(), I assume. > > FWIW, there are many bare metal processors with non-contiguous APIC IDs. > Intel puts the socket ID in the upper bits of the APIC ID. So if the > socket doesn't have a power-of-two number of cores, there is always a > gap. Plus, the BSP doesn't always have APIC ID 0 -- it depends on which > physical cores passed the manufacturing tests for that particular part. > That has broken various kernels, BIOSes, and other software at times. So > it's best not to make assumptions. > > I don't know if that applies to VMs, though. The standards may be > different (if there are any standards at all in that area.) Yes, I'm working on a patch to use GetProcessorNumber() instead of using the APIC ID. Thanks, Tom > ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-10-19 21:51 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-09-23 18:04 [PATCH v2 1/1] UefiCpuPkg/MpInitLib: Reduce reset vector memory pressure Lendacky, Thomas 2020-09-24 6:22 ` Laszlo Ersek 2020-09-24 13:30 ` Lendacky, Thomas 2020-09-24 15:03 ` Laszlo Ersek 2020-10-02 16:42 ` Lendacky, Thomas 2020-10-19 15:02 ` Lendacky, Thomas 2020-10-19 21:51 ` Laszlo Ersek 2020-09-25 16:09 ` [edk2-devel] " Brian J. Johnson 2020-09-25 16:52 ` Lendacky, Thomas
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox