From: Laszlo Ersek <lersek@redhat.com>
To: Jeff Fan <jeff.fan@intel.com>, edk2-devel@ml01.01.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Jiewen Yao <jiewen.yao@intel.com>,
Feng Tian <feng.tian@intel.com>,
Michael D Kinney <michael.d.kinney@intel.com>
Subject: Re: [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Add volatile for mNumberToFinish
Date: Tue, 15 Nov 2016 03:27:28 +0100 [thread overview]
Message-ID: <f443f499-2d2b-4713-3f4c-567a2001656b@redhat.com> (raw)
In-Reply-To: <20161115021839.3984-2-jeff.fan@intel.com>
On 11/15/16 03:18, Jeff Fan wrote:
> The GCC 5.4 will optimize mNumberToFinish in EarlyInitializeCpu(). It will cause
> S3 resume failure.
>
> Adding *volatile* could make sure compiler does not so such optimization.
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Jiewen Yao <jiewen.yao@intel.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/PiSmmCpuDxeSmm/CpuS3.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c
> index 3fb6864..f13ff3e 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c
> @@ -55,7 +55,7 @@ AsmGetAddressMap (
> #define LEGACY_REGION_BASE (0xA0000 - LEGACY_REGION_SIZE)
>
> ACPI_CPU_DATA mAcpiCpuData;
> -UINT32 mNumberToFinish;
> +volatile UINT32 mNumberToFinish;
> MP_CPU_EXCHANGE_INFO *mExchangeInfo;
> BOOLEAN mRestoreSmmConfigurationInS3 = FALSE;
> VOID *mGdtForAp = NULL;
> @@ -371,7 +371,7 @@ EarlyMPRendezvousProcedure (
> //
> // Count down the number with lock mechanism.
> //
> - InterlockedDecrement (&mNumberToFinish);
> + InterlockedDecrement ((UINT32 *) &mNumberToFinish);
> }
>
> /**
> @@ -406,7 +406,7 @@ MPRendezvousProcedure (
> TopOfStack = (UINT32) (UINTN) Stack + sizeof (Stack);
> TopOfStack &= ~(UINT32) (CPU_STACK_ALIGNMENT - 1);
> CopyMem ((VOID *) (UINTN) mApHltLoopCode, mApHltLoopCodeTemplate, sizeof (mApHltLoopCodeTemplate));
> - TransferApToSafeState ((UINT32) (UINTN) mApHltLoopCode, TopOfStack, &mNumberToFinish);
> + TransferApToSafeState ((UINT32) (UINTN) mApHltLoopCode, TopOfStack, (UINT32 *) &mNumberToFinish);
> }
>
> /**
>
I think I understand the idea, but the current solution requires you to
cast away "volatile" in two places. That's not nice, normally it is
undefined behavior.
I recommend to extend this patch, with more patches: please change the
prototype of TransferApToSafeState() so that it takes a pointer-to-volatile.
I also suggest to change the prototype of InterlockedDecrement(). (You
won't have to update all other call sites: it is fine to take/access a
non-volatile object as a volatile, but not the other way around.)
I agree this increases the scope of the patch quite a bit, so maybe
others should chime in as well.
Thanks!
Laszlo
next prev parent reply other threads:[~2016-11-15 2:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-15 2:18 [PATCH] UefiCpuPkg/DxeMpLib: Remove sizeof() that is not necessary Jeff Fan
2016-11-15 2:18 ` [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Add volatile for mNumberToFinish Jeff Fan
2016-11-15 2:27 ` Laszlo Ersek [this message]
2016-11-15 3:02 ` Fan, Jeff
2016-11-15 10:49 ` Gao, Liming
2016-11-15 13:35 ` Fan, Jeff
2016-11-15 15:24 ` Laszlo Ersek
2016-11-15 2:18 ` [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Free SmramRanges to save SMM space Jeff Fan
2016-11-15 2:28 ` [PATCH] UefiCpuPkg/DxeMpLib: Remove sizeof() that is not necessary Laszlo Ersek
-- strict thread matches above, loose matches on Subject: below --
2016-11-15 2:23 Jeff Fan
2016-11-15 2:23 ` [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Add volatile for mNumberToFinish Jeff Fan
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=f443f499-2d2b-4713-3f4c-567a2001656b@redhat.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