From: "Fan, Jeff" <jeff.fan@intel.com>
To: Laszlo Ersek <lersek@redhat.com>,
"edk2-devel@ml01.01.org" <edk2-devel@ml01.01.org>
Cc: "Tian, Feng" <feng.tian@intel.com>,
"Kinney, Michael D" <michael.d.kinney@intel.com>
Subject: Re: [PATCH 3/3] UefiCpuPkg/DxeMpLib: Make sure APs in safe loop code
Date: Thu, 24 Nov 2016 02:37:57 +0000 [thread overview]
Message-ID: <542CF652F8836A4AB8DBFAAD40ED192A4A2E68B7@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <6250a0f2-9431-1e5b-3ef0-0485826acc94@redhat.com>
Laszlo,
I added my feedback in [Jeff].
-----Original Message-----
From: Laszlo Ersek [mailto:lersek@redhat.com]
Sent: Thursday, November 24, 2016 2:52 AM
To: Fan, Jeff; edk2-devel@ml01.01.org
Cc: Tian, Feng; Kinney, Michael D
Subject: Re: [PATCH 3/3] UefiCpuPkg/DxeMpLib: Make sure APs in safe loop code
On 11/23/16 15:01, Jeff Fan wrote:
> Add one semaphore to make sure BSP to wait till all APs run in AP safe
> loop code.
>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Feng Tian <feng.tian@intel.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jeff Fan <jeff.fan@intel.com>
> ---
> UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 8 +++++++-
> UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm | 2 ++
> UefiCpuPkg/Library/MpInitLib/MpLib.h | 3 ++-
> UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 2 ++
> 4 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> index d0f9f7e..64c0c52 100644
> --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> @@ -27,6 +27,7 @@ EFI_EVENT mLegacyBootEvent = NULL;
> volatile BOOLEAN mStopCheckAllApsStatus = TRUE;
> VOID *mReservedApLoopFunc = NULL;
> UINTN mReservedTopOfApStack;
> +volatile UINT32 mNumberToFinish = 0;
>
> /**
> Get the pointer to CPU MP Data structure.
> @@ -253,7 +254,8 @@ RelocateApLoop (
> MwaitSupport,
> CpuMpData->ApTargetCState,
> CpuMpData->PmCodeSegment,
> - mReservedTopOfApStack - ProcessorNumber * AP_SAFT_STACK_SIZE
> + mReservedTopOfApStack - ProcessorNumber * AP_SAFT_STACK_SIZE,
> + (UINTN) &mNumberToFinish
> );
> //
> // It should never reach here
> @@ -282,8 +284,12 @@ MpInitChangeApLoopCallback (
> CpuMpData->SaveRestoreFlag = TRUE;
> CpuMpData->PmCodeSegment = GetProtectedModeCS ();
> CpuMpData->ApLoopMode = PcdGet8 (PcdCpuApLoopMode);
> + mNumberToFinish = CpuMpData->CpuCount - 1;
> WakeUpAP (CpuMpData, TRUE, 0, RelocateApLoop, NULL);
> DEBUG ((DEBUG_INFO, "%a() done!\n", __FUNCTION__));
> + while (mNumberToFinish > 0) {
> + CpuPause ();
> + }
> }
(1) Can you hoist the counting above the "done" message?
[Jeff] Agree.
>
> /**
> diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
> b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
> index 4e55760..6235748 100644
> --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
> +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm
> @@ -222,6 +222,8 @@ AsmRelocateApLoopStart:
> mov ecx, [ebp + 8] ; MwaitSupport
> mov ebx, [ebp + 12] ; ApTargetCState
> mov esp, [ebp + 20] ; TopOfApStack
> + mov eax, [ebp + 24] ; CountTofinish
> + lock dec dword [eax] ; CountTofinish--
(2) The comments should say
; NumberToFinish
; (*NumberToFinish)--
[Jeff] Agree.
> cmp cl, 1 ; Check mwait-monitor support
> jnz HltLoop
> MwaitLoop:
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h
> b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> index e6dea18..49305ad 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> @@ -251,7 +251,8 @@ VOID
> IN BOOLEAN MwaitSupport,
> IN UINTN ApTargetCState,
> IN UINTN PmCodeSegment,
> - IN UINTN TopOfApStack
> + IN UINTN TopOfApStack,
> + IN UINTN NumberToFinish
> );
>
> /**
> diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
> b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
> index 7c8fa45..deaee9e 100644
> --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
> +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm
> @@ -227,6 +227,8 @@ AsmRelocateApLoopStart:
> push rbp
> mov rbp, rsp
> mov rsp, r9
> + mov rax, [rbp + 48] ; CountTofinish
> + lock dec dword [rax] ; CountTofinish--
> push rcx
> push rdx
>
>
Hmmm, in the X64 case, this decrement seems to be pretty far from the actual loop; a window still remains. On the other hand, if we wanted to do the decrement from protected mode, then the semaphore would have to be moved into the specially allocated area too.
[Jeff] There is no window on this case. After "move rsp, r9" all AP code will be updated in safe code / safe stack. And it is in long mode.
Anyway, the point is that we are on the new stack, and will make no further accesses to BootServicesData type memory.
(3) The comments should say
; NumberToFinish
; (*NumberToFinish)--
[Jeff] Agree.
I think I'll postpone testing until the next version (if you decide to post v3).
Thanks!
Laszlo
prev parent reply other threads:[~2016-11-24 2:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-23 14:01 [PATCH 0/3] UefiCpuPkg/DxeMpLib: Allocate new safe stack < 4GB Jeff Fan
2016-11-23 14:01 ` [PATCH 1/3] UefiCpuPkg/DxeMpLib: Get safe AP loop handler from global variable Jeff Fan
2016-11-23 17:08 ` Laszlo Ersek
2016-11-23 14:01 ` [PATCH 2/3] UefiCpuPkg/DxeMpLib: Allocate new safe stack < 4GB Jeff Fan
2016-11-23 18:31 ` Laszlo Ersek
2016-11-24 2:23 ` Fan, Jeff
2016-11-24 9:20 ` Laszlo Ersek
2016-11-24 13:48 ` Fan, Jeff
2016-11-24 21:13 ` Laszlo Ersek
2016-11-23 14:01 ` [PATCH 3/3] UefiCpuPkg/DxeMpLib: Make sure APs in safe loop code Jeff Fan
2016-11-23 18:52 ` Laszlo Ersek
2016-11-24 2:37 ` Fan, Jeff [this message]
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=542CF652F8836A4AB8DBFAAD40ED192A4A2E68B7@shsmsx102.ccr.corp.intel.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