public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] UefiCpuPkg/CpuMpPei: suppress compiler complaining
@ 2018-09-11  4:47 Jian J Wang
  2018-09-11 14:55 ` Laszlo Ersek
  0 siblings, 1 reply; 3+ messages in thread
From: Jian J Wang @ 2018-09-11  4:47 UTC (permalink / raw)
  To: edk2-devel; +Cc: Dandan Bi, Hao A Wu

BZ#: https://bugzilla.tianocore.org/show_bug.cgi?id=1166

Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
---
 UefiCpuPkg/CpuMpPei/CpuPaging.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/UefiCpuPkg/CpuMpPei/CpuPaging.c b/UefiCpuPkg/CpuMpPei/CpuPaging.c
index bcb942a8e5..a63421a1af 100644
--- a/UefiCpuPkg/CpuMpPei/CpuPaging.c
+++ b/UefiCpuPkg/CpuMpPei/CpuPaging.c
@@ -517,7 +517,7 @@ GetStackBase (
   IN OUT VOID *Buffer
   )
 {
-  EFI_PHYSICAL_ADDRESS    StackBase;
+  volatile EFI_PHYSICAL_ADDRESS   StackBase;
 
   StackBase = (EFI_PHYSICAL_ADDRESS)(UINTN)&StackBase;
   StackBase += BASE_4KB;
@@ -554,6 +554,8 @@ SetupStackGuardPage (
   MpInitLibGetNumberOfProcessors(&NumberOfProcessors, NULL);
   MpInitLibWhoAmI (&Bsp);
   for (Index = 0; Index < NumberOfProcessors; ++Index) {
+    StackBase = 0;
+
     if (Index == Bsp) {
       Hob.Raw = GetHobList ();
       while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {
@@ -570,12 +572,19 @@ SetupStackGuardPage (
       //
       MpInitLibStartupThisAP(GetStackBase, Index, NULL, 0, (VOID *)&StackBase, NULL);
     }
-    //
-    // Set Guard page at stack base address.
-    //
-    ConvertMemoryPageAttributes(StackBase, EFI_PAGE_SIZE, 0);
-    DEBUG ((DEBUG_INFO, "Stack Guard set at %lx [cpu%lu]!\n",
-            (UINT64)StackBase, (UINT64)Index));
+
+    if (StackBase == 0) {
+      DEBUG ((DEBUG_ERROR, "Stack base address was not found for [cpu%lu]!\n",
+              (UINT64)Index));
+      ASSERT(StackBase != 0);
+    } else {
+      //
+      // Set Guard page at stack base address.
+      //
+      ConvertMemoryPageAttributes(StackBase, EFI_PAGE_SIZE, 0);
+      DEBUG ((DEBUG_INFO, "Stack Guard set at %lx [cpu%lu]!\n",
+              (UINT64)StackBase, (UINT64)Index));
+    }
   }
 
   //
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] UefiCpuPkg/CpuMpPei: suppress compiler complaining
  2018-09-11  4:47 [PATCH] UefiCpuPkg/CpuMpPei: suppress compiler complaining Jian J Wang
@ 2018-09-11 14:55 ` Laszlo Ersek
  2018-09-12  0:23   ` Wang, Jian J
  0 siblings, 1 reply; 3+ messages in thread
From: Laszlo Ersek @ 2018-09-11 14:55 UTC (permalink / raw)
  To: Jian J Wang, edk2-devel; +Cc: Hao A Wu, Dandan Bi, Eric Dong

Jian,

On 09/11/18 06:47, Jian J Wang wrote:
> BZ#: https://bugzilla.tianocore.org/show_bug.cgi?id=1166
> 
> Cc: Dandan Bi <dandan.bi@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
> ---
>  UefiCpuPkg/CpuMpPei/CpuPaging.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)

(1) Please remember to CC the package maintainers / reviewers on
patches. "Maintainers.txt" lists Eric (M) and myself (R) for UefiCpuPkg.
It's OK to CC other people as well, of course.

(2) Bug 1166 mentions "warning C4701: potentially uninitialized local
variable 'StackBase' used".

If that warning is invalid (= the variable can never be read
unassigned), then we have some suggested language for that; please see
<https://bugzilla.tianocore.org/show_bug.cgi?id=607>.

Furthermore:

> 
> diff --git a/UefiCpuPkg/CpuMpPei/CpuPaging.c b/UefiCpuPkg/CpuMpPei/CpuPaging.c
> index bcb942a8e5..a63421a1af 100644
> --- a/UefiCpuPkg/CpuMpPei/CpuPaging.c
> +++ b/UefiCpuPkg/CpuMpPei/CpuPaging.c
> @@ -517,7 +517,7 @@ GetStackBase (
>    IN OUT VOID *Buffer
>    )
>  {
> -  EFI_PHYSICAL_ADDRESS    StackBase;
> +  volatile EFI_PHYSICAL_ADDRESS   StackBase;

(3) "volatile" seems unrelated; I suggest dropping it.

(Especially without the comment mentioned in TianoCore#607, "volatile"
is totally unjustified and confusing.)

>  
>    StackBase = (EFI_PHYSICAL_ADDRESS)(UINTN)&StackBase;
>    StackBase += BASE_4KB;
> @@ -554,6 +554,8 @@ SetupStackGuardPage (
>    MpInitLibGetNumberOfProcessors(&NumberOfProcessors, NULL);
>    MpInitLibWhoAmI (&Bsp);
>    for (Index = 0; Index < NumberOfProcessors; ++Index) {
> +    StackBase = 0;
> +
>      if (Index == Bsp) {
>        Hob.Raw = GetHobList ();
>        while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {
> @@ -570,12 +572,19 @@ SetupStackGuardPage (
>        //
>        MpInitLibStartupThisAP(GetStackBase, Index, NULL, 0, (VOID *)&StackBase, NULL);
>      }
> -    //
> -    // Set Guard page at stack base address.
> -    //
> -    ConvertMemoryPageAttributes(StackBase, EFI_PAGE_SIZE, 0);
> -    DEBUG ((DEBUG_INFO, "Stack Guard set at %lx [cpu%lu]!\n",
> -            (UINT64)StackBase, (UINT64)Index));
> +
> +    if (StackBase == 0) {
> +      DEBUG ((DEBUG_ERROR, "Stack base address was not found for [cpu%lu]!\n",
> +              (UINT64)Index));
> +      ASSERT(StackBase != 0);

(4) On the other hand, if it *can* happen in practice that the stack
base is not found (and in that case, we should halt), then:

* the subject line is wrong, because the compiler warning is *valid*,
and we don't suppress it, but fix the issue caught by the compiler;

* we must not proceed in a RELEASE build either, therefore an ASSERT is
insufficient. A CpuDeadLoop() is necessary.

(Again, this only applies if StackBase may be zero here by design.)

Thanks
Laszlo


> +    } else {
> +      //
> +      // Set Guard page at stack base address.
> +      //
> +      ConvertMemoryPageAttributes(StackBase, EFI_PAGE_SIZE, 0);
> +      DEBUG ((DEBUG_INFO, "Stack Guard set at %lx [cpu%lu]!\n",
> +              (UINT64)StackBase, (UINT64)Index));
> +    }
>    }
>  
>    //
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] UefiCpuPkg/CpuMpPei: suppress compiler complaining
  2018-09-11 14:55 ` Laszlo Ersek
@ 2018-09-12  0:23   ` Wang, Jian J
  0 siblings, 0 replies; 3+ messages in thread
From: Wang, Jian J @ 2018-09-12  0:23 UTC (permalink / raw)
  To: Laszlo Ersek, edk2-devel@lists.01.org; +Cc: Wu, Hao A, Bi, Dandan, Dong, Eric

Laszlo,

Thanks for the comments.


(1)    Sure. My fault. I thought it’s just very small change for compiler warning.

(2)    From language point view, it’s a valid warning. But from code logic, it’s invalid.

(3)    Agree. It’ll be dropped.

(4)    Agree. I’ll change it.


Regards,
Jian

From: Laszlo Ersek [mailto:lersek@redhat.com]
Sent: Tuesday, September 11, 2018 10:56 PM
To: Wang, Jian J <jian.j.wang@intel.com>; edk2-devel@lists.01.org
Cc: Wu, Hao A <hao.a.wu@intel.com>; Bi, Dandan <dandan.bi@intel.com>; Dong, Eric <eric.dong@intel.com>
Subject: Re: [edk2] [PATCH] UefiCpuPkg/CpuMpPei: suppress compiler complaining

Jian,

On 09/11/18 06:47, Jian J Wang wrote:
> BZ#: https://bugzilla.tianocore.org/show_bug.cgi?id=1166
>
> Cc: Dandan Bi <dandan.bi@intel.com<mailto:dandan.bi@intel.com>>
> Cc: Hao A Wu <hao.a.wu@intel.com<mailto:hao.a.wu@intel.com>>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Jian J Wang <jian.j.wang@intel.com<mailto:jian.j.wang@intel.com>>
> ---
>  UefiCpuPkg/CpuMpPei/CpuPaging.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)

(1) Please remember to CC the package maintainers / reviewers on
patches. "Maintainers.txt" lists Eric (M) and myself (R) for UefiCpuPkg.
It's OK to CC other people as well, of course.

(2) Bug 1166 mentions "warning C4701: potentially uninitialized local
variable 'StackBase' used".

If that warning is invalid (= the variable can never be read
unassigned), then we have some suggested language for that; please see
<https://bugzilla.tianocore.org/show_bug.cgi?id=607>.

Furthermore:

>
> diff --git a/UefiCpuPkg/CpuMpPei/CpuPaging.c b/UefiCpuPkg/CpuMpPei/CpuPaging.c
> index bcb942a8e5..a63421a1af 100644
> --- a/UefiCpuPkg/CpuMpPei/CpuPaging.c
> +++ b/UefiCpuPkg/CpuMpPei/CpuPaging.c
> @@ -517,7 +517,7 @@ GetStackBase (
>    IN OUT VOID *Buffer
>    )
>  {
> -  EFI_PHYSICAL_ADDRESS    StackBase;
> +  volatile EFI_PHYSICAL_ADDRESS   StackBase;

(3) "volatile" seems unrelated; I suggest dropping it.

(Especially without the comment mentioned in TianoCore#607, "volatile"
is totally unjustified and confusing.)

>
>    StackBase = (EFI_PHYSICAL_ADDRESS)(UINTN)&StackBase;
>    StackBase += BASE_4KB;
> @@ -554,6 +554,8 @@ SetupStackGuardPage (
>    MpInitLibGetNumberOfProcessors(&NumberOfProcessors, NULL);
>    MpInitLibWhoAmI (&Bsp);
>    for (Index = 0; Index < NumberOfProcessors; ++Index) {
> +    StackBase = 0;
> +
>      if (Index == Bsp) {
>        Hob.Raw = GetHobList ();
>        while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {
> @@ -570,12 +572,19 @@ SetupStackGuardPage (
>        //
>        MpInitLibStartupThisAP(GetStackBase, Index, NULL, 0, (VOID *)&StackBase, NULL);
>      }
> -    //
> -    // Set Guard page at stack base address.
> -    //
> -    ConvertMemoryPageAttributes(StackBase, EFI_PAGE_SIZE, 0);
> -    DEBUG ((DEBUG_INFO, "Stack Guard set at %lx [cpu%lu]!\n",
> -            (UINT64)StackBase, (UINT64)Index));
> +
> +    if (StackBase == 0) {
> +      DEBUG ((DEBUG_ERROR, "Stack base address was not found for [cpu%lu]!\n",
> +              (UINT64)Index));
> +      ASSERT(StackBase != 0);

(4) On the other hand, if it *can* happen in practice that the stack
base is not found (and in that case, we should halt), then:

* the subject line is wrong, because the compiler warning is *valid*,
and we don't suppress it, but fix the issue caught by the compiler;

* we must not proceed in a RELEASE build either, therefore an ASSERT is
insufficient. A CpuDeadLoop() is necessary.

(Again, this only applies if StackBase may be zero here by design.)

Thanks
Laszlo


> +    } else {
> +      //
> +      // Set Guard page at stack base address.
> +      //
> +      ConvertMemoryPageAttributes(StackBase, EFI_PAGE_SIZE, 0);
> +      DEBUG ((DEBUG_INFO, "Stack Guard set at %lx [cpu%lu]!\n",
> +              (UINT64)StackBase, (UINT64)Index));
> +    }
>    }
>
>    //
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-09-12  0:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-11  4:47 [PATCH] UefiCpuPkg/CpuMpPei: suppress compiler complaining Jian J Wang
2018-09-11 14:55 ` Laszlo Ersek
2018-09-12  0:23   ` Wang, Jian J

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox