public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch 1/1] UefiCpuPkg: Remove redundant alignment check when calculate microcode patch size.
@ 2020-01-03  7:14 Siyuan, Fu
  2020-01-06  6:14 ` Wu, Hao A
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Siyuan, Fu @ 2020-01-03  7:14 UTC (permalink / raw)
  To: devel; +Cc: Eric Dong, Ray Ni, Hao A Wu

This patch removes the unnecessary alignment check on microcode patch TotalSize
introduced by commit d786a172. The TotalSize has already been checked with 1K
alignment and MAX_ADDRESS in previous code as below:

    if ( (UINTN)MicrocodeEntryPoint > (MAX_ADDRESS - TotalSize) ||
         ((UINTN)MicrocodeEntryPoint + TotalSize) > MicrocodeEnd ||
         (DataSize & 0x3) != 0 ||
         (TotalSize & (SIZE_1KB - 1)) != 0 ||
         TotalSize < DataSize
       ) {

Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Signed-off-by: Siyuan Fu <siyuan.fu@intel.com>
---
 UefiCpuPkg/Library/MpInitLib/Microcode.c | 24 +++++-------------------
 UefiCpuPkg/Library/MpInitLib/MpLib.h     |  3 +--
 2 files changed, 6 insertions(+), 21 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c b/UefiCpuPkg/Library/MpInitLib/Microcode.c
index 3da5bfb9cf2f..a9d06dd4099a 100644
--- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
+++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
@@ -1,7 +1,7 @@
 /** @file
   Implementation of loading microcode on processors.
 
-  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -397,16 +397,7 @@ LoadMicrocodePatchWorker (
       Patches[Index].Size
       );
 
-    //
-    // Zero-fill the padding area
-    // Please note that AlignedSize will be no less than Size
-    //
-    ZeroMem (
-      Walker + Patches[Index].Size,
-      Patches[Index].AlignedSize - Patches[Index].Size
-      );
-
-    Walker += Patches[Index].AlignedSize;
+    Walker += Patches[Index].Size;
   }
 
   //
@@ -578,14 +569,9 @@ LoadMicrocodePatch (
       //
       // Store the information of this microcode patch
       //
-      if (TotalSize > ALIGN_VALUE (TotalSize, SIZE_1KB) ||
-          ALIGN_VALUE (TotalSize, SIZE_1KB) > MAX_UINTN - TotalLoadSize) {
-        goto OnExit;
-      }
-      PatchInfoBuffer[PatchCount - 1].Address     = (UINTN) MicrocodeEntryPoint;
-      PatchInfoBuffer[PatchCount - 1].Size        = TotalSize;
-      PatchInfoBuffer[PatchCount - 1].AlignedSize = ALIGN_VALUE (TotalSize, SIZE_1KB);
-      TotalLoadSize += PatchInfoBuffer[PatchCount - 1].AlignedSize;
+      PatchInfoBuffer[PatchCount - 1].Address = (UINTN) MicrocodeEntryPoint;
+      PatchInfoBuffer[PatchCount - 1].Size    = TotalSize;
+      TotalLoadSize += TotalSize;
     }
 
     //
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 6609c958ce8a..b6e5a1afab00 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -1,7 +1,7 @@
 /** @file
   Common header file for MP Initialize Library.
 
-  Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -54,7 +54,6 @@
 typedef struct {
   UINTN    Address;
   UINTN    Size;
-  UINTN    AlignedSize;
 } MICROCODE_PATCH_INFO;
 
 //
-- 
2.19.1.windows.1


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

* Re: [Patch 1/1] UefiCpuPkg: Remove redundant alignment check when calculate microcode patch size.
  2020-01-03  7:14 [Patch 1/1] UefiCpuPkg: Remove redundant alignment check when calculate microcode patch size Siyuan, Fu
@ 2020-01-06  6:14 ` Wu, Hao A
  2020-01-07  2:43 ` Dong, Eric
  2020-01-07  3:04 ` Ni, Ray
  2 siblings, 0 replies; 4+ messages in thread
From: Wu, Hao A @ 2020-01-06  6:14 UTC (permalink / raw)
  To: Fu, Siyuan, devel@edk2.groups.io; +Cc: Dong, Eric, Ni, Ray

> -----Original Message-----
> From: Fu, Siyuan
> Sent: Friday, January 03, 2020 3:14 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric; Ni, Ray; Wu, Hao A
> Subject: [Patch 1/1] UefiCpuPkg: Remove redundant alignment check when
> calculate microcode patch size.
> 
> This patch removes the unnecessary alignment check on microcode patch
> TotalSize
> introduced by commit d786a172. The TotalSize has already been checked
> with 1K
> alignment and MAX_ADDRESS in previous code as below:
> 
>     if ( (UINTN)MicrocodeEntryPoint > (MAX_ADDRESS - TotalSize) ||
>          ((UINTN)MicrocodeEntryPoint + TotalSize) > MicrocodeEnd ||
>          (DataSize & 0x3) != 0 ||
>          (TotalSize & (SIZE_1KB - 1)) != 0 ||
>          TotalSize < DataSize
>        ) {
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Signed-off-by: Siyuan Fu <siyuan.fu@intel.com>
> ---
>  UefiCpuPkg/Library/MpInitLib/Microcode.c | 24 +++++-------------------
>  UefiCpuPkg/Library/MpInitLib/MpLib.h     |  3 +--
>  2 files changed, 6 insertions(+), 21 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c
> b/UefiCpuPkg/Library/MpInitLib/Microcode.c
> index 3da5bfb9cf2f..a9d06dd4099a 100644
> --- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
> +++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Implementation of loading microcode on processors.
> 
> -  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -397,16 +397,7 @@ LoadMicrocodePatchWorker (
>        Patches[Index].Size
>        );
> 
> -    //
> -    // Zero-fill the padding area
> -    // Please note that AlignedSize will be no less than Size
> -    //
> -    ZeroMem (
> -      Walker + Patches[Index].Size,
> -      Patches[Index].AlignedSize - Patches[Index].Size
> -      );
> -
> -    Walker += Patches[Index].AlignedSize;
> +    Walker += Patches[Index].Size;
>    }
> 
>    //
> @@ -578,14 +569,9 @@ LoadMicrocodePatch (
>        //
>        // Store the information of this microcode patch
>        //
> -      if (TotalSize > ALIGN_VALUE (TotalSize, SIZE_1KB) ||
> -          ALIGN_VALUE (TotalSize, SIZE_1KB) > MAX_UINTN - TotalLoadSize) {
> -        goto OnExit;
> -      }
> -      PatchInfoBuffer[PatchCount - 1].Address     = (UINTN)
> MicrocodeEntryPoint;
> -      PatchInfoBuffer[PatchCount - 1].Size        = TotalSize;
> -      PatchInfoBuffer[PatchCount - 1].AlignedSize = ALIGN_VALUE (TotalSize,
> SIZE_1KB);
> -      TotalLoadSize += PatchInfoBuffer[PatchCount - 1].AlignedSize;
> +      PatchInfoBuffer[PatchCount - 1].Address = (UINTN)
> MicrocodeEntryPoint;
> +      PatchInfoBuffer[PatchCount - 1].Size    = TotalSize;
> +      TotalLoadSize += TotalSize;
>      }
> 
>      //
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h
> b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> index 6609c958ce8a..b6e5a1afab00 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> @@ -1,7 +1,7 @@
>  /** @file
>    Common header file for MP Initialize Library.
> 
> -  Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -54,7 +54,6 @@
>  typedef struct {
>    UINTN    Address;
>    UINTN    Size;
> -  UINTN    AlignedSize;
>  } MICROCODE_PATCH_INFO;


Thanks for the catch.
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>

Best Regards,
Hao Wu


> 
>  //
> --
> 2.19.1.windows.1


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

* Re: [Patch 1/1] UefiCpuPkg: Remove redundant alignment check when calculate microcode patch size.
  2020-01-03  7:14 [Patch 1/1] UefiCpuPkg: Remove redundant alignment check when calculate microcode patch size Siyuan, Fu
  2020-01-06  6:14 ` Wu, Hao A
@ 2020-01-07  2:43 ` Dong, Eric
  2020-01-07  3:04 ` Ni, Ray
  2 siblings, 0 replies; 4+ messages in thread
From: Dong, Eric @ 2020-01-07  2:43 UTC (permalink / raw)
  To: Fu, Siyuan, devel@edk2.groups.io; +Cc: Ni, Ray, Wu, Hao A

Reviewed-by: Eric Dong <eric.dong@intel.com>

> -----Original Message-----
> From: Fu, Siyuan
> Sent: Friday, January 3, 2020 3:14 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Wu, Hao A
> <hao.a.wu@intel.com>
> Subject: [Patch 1/1] UefiCpuPkg: Remove redundant alignment check when
> calculate microcode patch size.
> 
> This patch removes the unnecessary alignment check on microcode patch
> TotalSize introduced by commit d786a172. The TotalSize has already been
> checked with 1K alignment and MAX_ADDRESS in previous code as below:
> 
>     if ( (UINTN)MicrocodeEntryPoint > (MAX_ADDRESS - TotalSize) ||
>          ((UINTN)MicrocodeEntryPoint + TotalSize) > MicrocodeEnd ||
>          (DataSize & 0x3) != 0 ||
>          (TotalSize & (SIZE_1KB - 1)) != 0 ||
>          TotalSize < DataSize
>        ) {
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Signed-off-by: Siyuan Fu <siyuan.fu@intel.com>
> ---
>  UefiCpuPkg/Library/MpInitLib/Microcode.c | 24 +++++-------------------
>  UefiCpuPkg/Library/MpInitLib/MpLib.h     |  3 +--
>  2 files changed, 6 insertions(+), 21 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c
> b/UefiCpuPkg/Library/MpInitLib/Microcode.c
> index 3da5bfb9cf2f..a9d06dd4099a 100644
> --- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
> +++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Implementation of loading microcode on processors.
> 
> -  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2015 - 2020, Intel Corporation. All rights
> + reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -397,16 +397,7 @@ LoadMicrocodePatchWorker (
>        Patches[Index].Size
>        );
> 
> -    //
> -    // Zero-fill the padding area
> -    // Please note that AlignedSize will be no less than Size
> -    //
> -    ZeroMem (
> -      Walker + Patches[Index].Size,
> -      Patches[Index].AlignedSize - Patches[Index].Size
> -      );
> -
> -    Walker += Patches[Index].AlignedSize;
> +    Walker += Patches[Index].Size;
>    }
> 
>    //
> @@ -578,14 +569,9 @@ LoadMicrocodePatch (
>        //
>        // Store the information of this microcode patch
>        //
> -      if (TotalSize > ALIGN_VALUE (TotalSize, SIZE_1KB) ||
> -          ALIGN_VALUE (TotalSize, SIZE_1KB) > MAX_UINTN - TotalLoadSize) {
> -        goto OnExit;
> -      }
> -      PatchInfoBuffer[PatchCount - 1].Address     = (UINTN)
> MicrocodeEntryPoint;
> -      PatchInfoBuffer[PatchCount - 1].Size        = TotalSize;
> -      PatchInfoBuffer[PatchCount - 1].AlignedSize = ALIGN_VALUE (TotalSize,
> SIZE_1KB);
> -      TotalLoadSize += PatchInfoBuffer[PatchCount - 1].AlignedSize;
> +      PatchInfoBuffer[PatchCount - 1].Address = (UINTN)
> MicrocodeEntryPoint;
> +      PatchInfoBuffer[PatchCount - 1].Size    = TotalSize;
> +      TotalLoadSize += TotalSize;
>      }
> 
>      //
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h
> b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> index 6609c958ce8a..b6e5a1afab00 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> @@ -1,7 +1,7 @@
>  /** @file
>    Common header file for MP Initialize Library.
> 
> -  Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2016 - 2020, Intel Corporation. All rights
> + reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -54,7 +54,6 @@
>  typedef struct {
>    UINTN    Address;
>    UINTN    Size;
> -  UINTN    AlignedSize;
>  } MICROCODE_PATCH_INFO;
> 
>  //
> --
> 2.19.1.windows.1


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

* Re: [Patch 1/1] UefiCpuPkg: Remove redundant alignment check when calculate microcode patch size.
  2020-01-03  7:14 [Patch 1/1] UefiCpuPkg: Remove redundant alignment check when calculate microcode patch size Siyuan, Fu
  2020-01-06  6:14 ` Wu, Hao A
  2020-01-07  2:43 ` Dong, Eric
@ 2020-01-07  3:04 ` Ni, Ray
  2 siblings, 0 replies; 4+ messages in thread
From: Ni, Ray @ 2020-01-07  3:04 UTC (permalink / raw)
  To: Fu, Siyuan, devel@edk2.groups.io; +Cc: Dong, Eric, Wu, Hao A

Reviewed-by: Ray Ni <ray.ni@intel.com>

> -----Original Message-----
> From: Fu, Siyuan <siyuan.fu@intel.com>
> Sent: Friday, January 3, 2020 3:14 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Wu, Hao A
> <hao.a.wu@intel.com>
> Subject: [Patch 1/1] UefiCpuPkg: Remove redundant alignment check when
> calculate microcode patch size.
> 
> This patch removes the unnecessary alignment check on microcode patch
> TotalSize
> introduced by commit d786a172. The TotalSize has already been checked
> with 1K
> alignment and MAX_ADDRESS in previous code as below:
> 
>     if ( (UINTN)MicrocodeEntryPoint > (MAX_ADDRESS - TotalSize) ||
>          ((UINTN)MicrocodeEntryPoint + TotalSize) > MicrocodeEnd ||
>          (DataSize & 0x3) != 0 ||
>          (TotalSize & (SIZE_1KB - 1)) != 0 ||
>          TotalSize < DataSize
>        ) {
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Signed-off-by: Siyuan Fu <siyuan.fu@intel.com>
> ---
>  UefiCpuPkg/Library/MpInitLib/Microcode.c | 24 +++++-------------------
>  UefiCpuPkg/Library/MpInitLib/MpLib.h     |  3 +--
>  2 files changed, 6 insertions(+), 21 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c
> b/UefiCpuPkg/Library/MpInitLib/Microcode.c
> index 3da5bfb9cf2f..a9d06dd4099a 100644
> --- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
> +++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Implementation of loading microcode on processors.
> 
> -  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -397,16 +397,7 @@ LoadMicrocodePatchWorker (
>        Patches[Index].Size
>        );
> 
> -    //
> -    // Zero-fill the padding area
> -    // Please note that AlignedSize will be no less than Size
> -    //
> -    ZeroMem (
> -      Walker + Patches[Index].Size,
> -      Patches[Index].AlignedSize - Patches[Index].Size
> -      );
> -
> -    Walker += Patches[Index].AlignedSize;
> +    Walker += Patches[Index].Size;
>    }
> 
>    //
> @@ -578,14 +569,9 @@ LoadMicrocodePatch (
>        //
>        // Store the information of this microcode patch
>        //
> -      if (TotalSize > ALIGN_VALUE (TotalSize, SIZE_1KB) ||
> -          ALIGN_VALUE (TotalSize, SIZE_1KB) > MAX_UINTN - TotalLoadSize) {
> -        goto OnExit;
> -      }
> -      PatchInfoBuffer[PatchCount - 1].Address     = (UINTN)
> MicrocodeEntryPoint;
> -      PatchInfoBuffer[PatchCount - 1].Size        = TotalSize;
> -      PatchInfoBuffer[PatchCount - 1].AlignedSize = ALIGN_VALUE (TotalSize,
> SIZE_1KB);
> -      TotalLoadSize += PatchInfoBuffer[PatchCount - 1].AlignedSize;
> +      PatchInfoBuffer[PatchCount - 1].Address = (UINTN)
> MicrocodeEntryPoint;
> +      PatchInfoBuffer[PatchCount - 1].Size    = TotalSize;
> +      TotalLoadSize += TotalSize;
>      }
> 
>      //
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h
> b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> index 6609c958ce8a..b6e5a1afab00 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> @@ -1,7 +1,7 @@
>  /** @file
>    Common header file for MP Initialize Library.
> 
> -  Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -54,7 +54,6 @@
>  typedef struct {
>    UINTN    Address;
>    UINTN    Size;
> -  UINTN    AlignedSize;
>  } MICROCODE_PATCH_INFO;
> 
>  //
> --
> 2.19.1.windows.1


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

end of thread, other threads:[~2020-01-07  3:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-03  7:14 [Patch 1/1] UefiCpuPkg: Remove redundant alignment check when calculate microcode patch size Siyuan, Fu
2020-01-06  6:14 ` Wu, Hao A
2020-01-07  2:43 ` Dong, Eric
2020-01-07  3:04 ` Ni, Ray

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