public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Update page alignment calculations
@ 2021-07-19  8:07 Sunny Wang
  2021-07-27  6:12 ` [edk2-devel] " G Edhaya Chandran
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Sunny Wang @ 2021-07-19  8:07 UTC (permalink / raw)
  To: devel
  Cc: Sunny Wang, Samer El-Haj-Mahmoud, G Edhaya Chandran, Barton Gao,
	Sunny Wang

This is to fix the SCT BS.AllocatePages failures (not found) with the
case that the Start address is not aligned to 64k.
For example,
  The following is available memory region for testing:
    0000000082012000-00000000EB6D9FFF 00000000000696C8
  With the current page alignment calculation, we will get:
    Start address is 0x82020000
    PageNum is 0x696B8
  In BS.AllocatePages, it will make the end address align with 64k,
  so PageNum will be changed from 0x696B8 to 0x696C0. Therefore, the
  end address will become 0xEB6E0000 which is larger than 0xEB6D9FFF,
  so we get not found error in the end.

Therefore, the calculation for getting the PageNum should be updated
to PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000)) so that we won't get a
wrong PageNum to allocate a memory with a size larger than available
space's size.

With this solution, the example above will get 0x696A8 as calculated
PageNum. Then, in BS.AllocatePages, the PageNum will be changed from
0x696A8 to 0x696B0. Therefore, the end address will become 0xEB6D0000
that is smaller than 0xEB6D9FFF, so we get not found error in the end.

I also tested this solution on two ARM platforms (NXP1046A and RPi4).

Cc: Samer El-Haj-Mahmoud <samer.el-haj-mahmoud@arm.com>
Cc: G Edhaya Chandran <edhaya.chandran@arm.com>
Cc: Barton Gao <gaojie@byosoft.com.cn>
Signed-off-by: Sunny Wang <sunny.wang@arm.com>
---
 .../MemoryAllocationServicesBBTestFunction.c  | 110 +++++++++++-------
 1 file changed, 66 insertions(+), 44 deletions(-)

diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c
index bf8cd3b3..cdfac992 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c
@@ -2,6 +2,7 @@
 
   Copyright 2006 - 2013 Unified EFI, Inc.<BR>
   Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2021, ARM Limited. All rights reserved.
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -24,7 +25,7 @@ Abstract:
 
 --*/
 
-#include "SctLib.h"
+#include "SctLib.h"
 #include "MemoryAllocationServicesBBTestMain.h"
 
 #define ALLOCATEPAGES_MEMORYTYPE_NUM 16
@@ -700,14 +701,17 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;
 
-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        //
+        // Calculate New Start address and PageNum with 64k alignment to
+        // cover the case that some memory types' alignment is more than
+        // 4k. If the available memory is less than 192k, the memory
+        // allocation call will be skipped.
+        //
+        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
           break;
         }
-        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
+        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
+        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
 
         Memory  = Start;
 
@@ -830,14 +834,17 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;
 
-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        //
+        // Calculate New Start address and PageNum with 64k alignment to
+        // cover the case that some memory types' alignment is more than
+        // 4k. If the available memory is less than 192k, the memory
+        // allocation call will be skipped.
+        //
+        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
           break;
         }
-        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
+        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
+        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
 
         Memory  = Start;
 
@@ -953,14 +960,17 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;
 
-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        //
+        // Calculate New Start address and PageNum with 64k alignment to
+        // cover the case that some memory types' alignment is more than
+        // 4k. If the available memory is less than 192k, the memory
+        // allocation call will be skipped.
+        //
+        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
           break;
         }
-        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
+        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
+        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
 
         Memory = Start + (SctLShiftU64 (PageNum/3, EFI_PAGE_SHIFT) & 0xFFFFFFFFFFFF0000);
 
@@ -1076,14 +1086,17 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;
 
-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        //
+        // Calculate New Start address and PageNum with 64k alignment to
+        // cover the case that some memory types' alignment is more than
+        // 4k. If the available memory is less than 192k, the memory
+        // allocation call will be skipped.
+        //
+        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
           break;
         }
-        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
+        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
+        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
 
         Memory  = Start + (SctLShiftU64 (PageNum * 2 / 3, EFI_PAGE_SHIFT) & 0xFFFFFFFFFFFF0000);
 
@@ -1206,14 +1219,17 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;
 
-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        //
+        // Calculate New Start address and PageNum with 64k alignment to
+        // cover the case that some memory types' alignment is more than
+        // 4k. If the available memory is less than 192k, the memory
+        // allocation call will be skipped.
+        //
+        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
           break;
         }
-        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
+        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
+        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
 
         Memory  = Start;
 
@@ -1329,14 +1345,17 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;
 
-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        //
+        // Calculate New Start address and PageNum with 64k alignment to
+        // cover the case that some memory types' alignment is more than
+        // 4k. If the available memory is less than 192k, the memory
+        // allocation call will be skipped.
+        //
+        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
           break;
         }
-        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
+        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
+        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
 
         Memory  = Start;
 
@@ -1468,14 +1487,17 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;
 
-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        //
+        // Calculate New Start address and PageNum with 64k alignment to
+        // cover the case that some memory types' alignment is more than
+        // 4k. If the available memory is less than 192k, the memory
+        // allocation call will be skipped.
+        //
+        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
           break;
         }
-        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
+        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
+        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
 
         Memory  = Start;
 
@@ -1923,4 +1945,4 @@ BBTestFreePoolInterfaceTest (
 
   FreeMemoryMap ();
   return EFI_SUCCESS;
-}
+}
-- 
2.31.0.windows.1


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

* Re: [edk2-devel] [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Update page alignment calculations
  2021-07-19  8:07 [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Update page alignment calculations Sunny Wang
@ 2021-07-27  6:12 ` G Edhaya Chandran
  2021-08-03 13:10 ` Samer El-Haj-Mahmoud
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: G Edhaya Chandran @ 2021-07-27  6:12 UTC (permalink / raw)
  To: Sunny Wang, devel

[-- Attachment #1: Type: text/plain, Size: 57 bytes --]

Reviewed-by: G Edhaya Chandran<edhaya.chandran@arm.com>

[-- Attachment #2: Type: text/html, Size: 63 bytes --]

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

* Re: [edk2-devel] [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Update page alignment calculations
  2021-07-19  8:07 [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Update page alignment calculations Sunny Wang
  2021-07-27  6:12 ` [edk2-devel] " G Edhaya Chandran
@ 2021-08-03 13:10 ` Samer El-Haj-Mahmoud
  2021-08-03 21:40 ` tuanphan
       [not found] ` <DB8PR08MB3993FC8E3E4847842808B1C185F19@DB8PR08MB3993.eurprd08.prod.outlook.com>
  3 siblings, 0 replies; 6+ messages in thread
From: Samer El-Haj-Mahmoud @ 2021-08-03 13:10 UTC (permalink / raw)
  To: devel@edk2.groups.io, Sunny Wang
  Cc: G Edhaya Chandran, Barton Gao, Heinrich Schuchardt,
	Samer El-Haj-Mahmoud

+Heinrich

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Sunny
> Wang via groups.io
> Sent: Monday, July 19, 2021 4:08 AM
> To: devel@edk2.groups.io
> Cc: Sunny Wang <Sunny.Wang@arm.com>; Samer El-Haj-Mahmoud
> <Samer.El-Haj-Mahmoud@arm.com>; G Edhaya Chandran
> <Edhaya.Chandran@arm.com>; Barton Gao <gaojie@byosoft.com.cn>;
> Sunny Wang <Sunny.Wang@arm.com>
> Subject: [edk2-devel] [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Update
> page alignment calculations
>
> This is to fix the SCT BS.AllocatePages failures (not found) with the
> case that the Start address is not aligned to 64k.
> For example,
>   The following is available memory region for testing:
>     0000000082012000-00000000EB6D9FFF 00000000000696C8
>   With the current page alignment calculation, we will get:
>     Start address is 0x82020000
>     PageNum is 0x696B8
>   In BS.AllocatePages, it will make the end address align with 64k,
>   so PageNum will be changed from 0x696B8 to 0x696C0. Therefore, the
>   end address will become 0xEB6E0000 which is larger than 0xEB6D9FFF,
>   so we get not found error in the end.
>
> Therefore, the calculation for getting the PageNum should be updated
> to PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000)) so that we won't get a
> wrong PageNum to allocate a memory with a size larger than available
> space's size.
>
> With this solution, the example above will get 0x696A8 as calculated
> PageNum. Then, in BS.AllocatePages, the PageNum will be changed from
> 0x696A8 to 0x696B0. Therefore, the end address will become 0xEB6D0000
> that is smaller than 0xEB6D9FFF, so we get not found error in the end.
>
> I also tested this solution on two ARM platforms (NXP1046A and RPi4).
>
> Cc: Samer El-Haj-Mahmoud <samer.el-haj-mahmoud@arm.com>
> Cc: G Edhaya Chandran <edhaya.chandran@arm.com>
> Cc: Barton Gao <gaojie@byosoft.com.cn>
> Signed-off-by: Sunny Wang <sunny.wang@arm.com>
> ---
>  .../MemoryAllocationServicesBBTestFunction.c  | 110 +++++++++++-------
>  1 file changed, 66 insertions(+), 44 deletions(-)
>
> diff --git a/uefi-
> sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/Blac
> kBoxTest/MemoryAllocationServicesBBTestFunction.c b/uefi-
> sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/Blac
> kBoxTest/MemoryAllocationServicesBBTestFunction.c
> index bf8cd3b3..cdfac992 100644
> --- a/uefi-
> sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/Blac
> kBoxTest/MemoryAllocationServicesBBTestFunction.c
> +++ b/uefi-
> sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/Blac
> kBoxTest/MemoryAllocationServicesBBTestFunction.c
> @@ -2,6 +2,7 @@
>
>    Copyright 2006 - 2013 Unified EFI, Inc.<BR>
>    Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2021, ARM Limited. All rights reserved.
>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
> @@ -24,7 +25,7 @@ Abstract:
>
>  --*/
>
> -#include "SctLib.h"
> +#include "SctLib.h"
>  #include "MemoryAllocationServicesBBTestMain.h"
>
>  #define ALLOCATEPAGES_MEMORYTYPE_NUM 16
> @@ -700,14 +701,17 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
>
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        //
> +        // Calculate New Start address and PageNum with 64k alignment to
> +        // cover the case that some memory types' alignment is more than
> +        // 4k. If the available memory is less than 192k, the memory
> +        // allocation call will be skipped.
> +        //
> +        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
>            break;
>          }
> -        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> +        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> +        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
>
>          Memory  = Start;
>
> @@ -830,14 +834,17 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
>
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        //
> +        // Calculate New Start address and PageNum with 64k alignment to
> +        // cover the case that some memory types' alignment is more than
> +        // 4k. If the available memory is less than 192k, the memory
> +        // allocation call will be skipped.
> +        //
> +        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
>            break;
>          }
> -        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> +        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> +        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
>
>          Memory  = Start;
>
> @@ -953,14 +960,17 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
>
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        //
> +        // Calculate New Start address and PageNum with 64k alignment to
> +        // cover the case that some memory types' alignment is more than
> +        // 4k. If the available memory is less than 192k, the memory
> +        // allocation call will be skipped.
> +        //
> +        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
>            break;
>          }
> -        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> +        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> +        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
>
>          Memory = Start + (SctLShiftU64 (PageNum/3, EFI_PAGE_SHIFT) &
> 0xFFFFFFFFFFFF0000);
>
> @@ -1076,14 +1086,17 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
>
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        //
> +        // Calculate New Start address and PageNum with 64k alignment to
> +        // cover the case that some memory types' alignment is more than
> +        // 4k. If the available memory is less than 192k, the memory
> +        // allocation call will be skipped.
> +        //
> +        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
>            break;
>          }
> -        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> +        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> +        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
>
>          Memory  = Start + (SctLShiftU64 (PageNum * 2 / 3, EFI_PAGE_SHIFT) &
> 0xFFFFFFFFFFFF0000);
>
> @@ -1206,14 +1219,17 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
>
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        //
> +        // Calculate New Start address and PageNum with 64k alignment to
> +        // cover the case that some memory types' alignment is more than
> +        // 4k. If the available memory is less than 192k, the memory
> +        // allocation call will be skipped.
> +        //
> +        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
>            break;
>          }
> -        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> +        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> +        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
>
>          Memory  = Start;
>
> @@ -1329,14 +1345,17 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
>
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        //
> +        // Calculate New Start address and PageNum with 64k alignment to
> +        // cover the case that some memory types' alignment is more than
> +        // 4k. If the available memory is less than 192k, the memory
> +        // allocation call will be skipped.
> +        //
> +        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
>            break;
>          }
> -        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> +        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> +        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
>
>          Memory  = Start;
>
> @@ -1468,14 +1487,17 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
>
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        //
> +        // Calculate New Start address and PageNum with 64k alignment to
> +        // cover the case that some memory types' alignment is more than
> +        // 4k. If the available memory is less than 192k, the memory
> +        // allocation call will be skipped.
> +        //
> +        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
>            break;
>          }
> -        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> +        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> +        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
>
>          Memory  = Start;
>
> @@ -1923,4 +1945,4 @@ BBTestFreePoolInterfaceTest (
>
>    FreeMemoryMap ();
>    return EFI_SUCCESS;
> -}
> +}
> --
> 2.31.0.windows.1
>
>
>
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#77876): https://edk2.groups.io/g/devel/message/77876
> Mute This Topic: https://groups.io/mt/84303611/1945644
> Group Owner: devel+owner@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub [samer.el-haj-
> mahmoud@arm.com]
> -=-=-=-=-=-=
>

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

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

* Re: [edk2-devel] [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Update page alignment calculations
  2021-07-19  8:07 [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Update page alignment calculations Sunny Wang
  2021-07-27  6:12 ` [edk2-devel] " G Edhaya Chandran
  2021-08-03 13:10 ` Samer El-Haj-Mahmoud
@ 2021-08-03 21:40 ` tuanphan
       [not found] ` <DB8PR08MB3993FC8E3E4847842808B1C185F19@DB8PR08MB3993.eurprd08.prod.outlook.com>
  3 siblings, 0 replies; 6+ messages in thread
From: tuanphan @ 2021-08-03 21:40 UTC (permalink / raw)
  To: devel, Sunny Wang; +Cc: Samer El-Haj-Mahmoud, G Edhaya Chandran, Barton Gao

[-- Attachment #1: Type: text/plain, Size: 10032 bytes --]

Reviewed-By: Tuan Phan <tuanphan@os.amperecomputing.com>

> On Jul 19, 2021, at 1:07 AM, Sunny Wang via groups.io <Sunny.Wang=arm.com@groups.io> wrote:
> 
> This is to fix the SCT BS.AllocatePages failures (not found) with the
> case that the Start address is not aligned to 64k.
> For example,
>  The following is available memory region for testing:
>    0000000082012000-00000000EB6D9FFF 00000000000696C8
>  With the current page alignment calculation, we will get:
>    Start address is 0x82020000
>    PageNum is 0x696B8
>  In BS.AllocatePages, it will make the end address align with 64k,
>  so PageNum will be changed from 0x696B8 to 0x696C0. Therefore, the
>  end address will become 0xEB6E0000 which is larger than 0xEB6D9FFF,
>  so we get not found error in the end.
> 
> Therefore, the calculation for getting the PageNum should be updated
> to PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000)) so that we won't get a
> wrong PageNum to allocate a memory with a size larger than available
> space's size.
> 
> With this solution, the example above will get 0x696A8 as calculated
> PageNum. Then, in BS.AllocatePages, the PageNum will be changed from
> 0x696A8 to 0x696B0. Therefore, the end address will become 0xEB6D0000
> that is smaller than 0xEB6D9FFF, so we get not found error in the end.
> 
> I also tested this solution on two ARM platforms (NXP1046A and RPi4).
> 
> Cc: Samer El-Haj-Mahmoud <samer.el-haj-mahmoud@arm.com>
> Cc: G Edhaya Chandran <edhaya.chandran@arm.com>
> Cc: Barton Gao <gaojie@byosoft.com.cn>
> Signed-off-by: Sunny Wang <sunny.wang@arm.com>
> ---
> .../MemoryAllocationServicesBBTestFunction.c  | 110 +++++++++++-------
> 1 file changed, 66 insertions(+), 44 deletions(-)
> 
> diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c
> index bf8cd3b3..cdfac992 100644
> --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c
> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c
> @@ -2,6 +2,7 @@
> 
>   Copyright 2006 - 2013 Unified EFI, Inc.<BR>
>   Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2021, ARM Limited. All rights reserved.
> 
>   This program and the accompanying materials
>   are licensed and made available under the terms and conditions of the BSD License
> @@ -24,7 +25,7 @@ Abstract:
> 
> --*/
> 
> -#include "SctLib.h"
> +#include "SctLib.h"
> #include "MemoryAllocationServicesBBTestMain.h"
> 
> #define ALLOCATEPAGES_MEMORYTYPE_NUM 16
> @@ -700,14 +701,17 @@ BBTestAllocatePagesInterfaceTest (
>         PageNum = (UINTN)Descriptor.NumberOfPages;
>         Start   = Descriptor.PhysicalStart;
> 
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        //
> +        // Calculate New Start address and PageNum with 64k alignment to
> +        // cover the case that some memory types' alignment is more than
> +        // 4k. If the available memory is less than 192k, the memory
> +        // allocation call will be skipped.
> +        //
> +        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
>           break;
>         }
> -        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> +        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> +        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
> 
>         Memory  = Start;
> 
> @@ -830,14 +834,17 @@ BBTestAllocatePagesInterfaceTest (
>         PageNum = (UINTN)Descriptor.NumberOfPages;
>         Start   = Descriptor.PhysicalStart;
> 
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        //
> +        // Calculate New Start address and PageNum with 64k alignment to
> +        // cover the case that some memory types' alignment is more than
> +        // 4k. If the available memory is less than 192k, the memory
> +        // allocation call will be skipped.
> +        //
> +        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
>           break;
>         }
> -        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> +        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> +        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
> 
>         Memory  = Start;
> 
> @@ -953,14 +960,17 @@ BBTestAllocatePagesInterfaceTest (
>         PageNum = (UINTN)Descriptor.NumberOfPages;
>         Start   = Descriptor.PhysicalStart;
> 
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        //
> +        // Calculate New Start address and PageNum with 64k alignment to
> +        // cover the case that some memory types' alignment is more than
> +        // 4k. If the available memory is less than 192k, the memory
> +        // allocation call will be skipped.
> +        //
> +        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
>           break;
>         }
> -        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> +        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> +        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
> 
>         Memory = Start + (SctLShiftU64 (PageNum/3, EFI_PAGE_SHIFT) & 0xFFFFFFFFFFFF0000);
> 
> @@ -1076,14 +1086,17 @@ BBTestAllocatePagesInterfaceTest (
>         PageNum = (UINTN)Descriptor.NumberOfPages;
>         Start   = Descriptor.PhysicalStart;
> 
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        //
> +        // Calculate New Start address and PageNum with 64k alignment to
> +        // cover the case that some memory types' alignment is more than
> +        // 4k. If the available memory is less than 192k, the memory
> +        // allocation call will be skipped.
> +        //
> +        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
>           break;
>         }
> -        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> +        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> +        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
> 
>         Memory  = Start + (SctLShiftU64 (PageNum * 2 / 3, EFI_PAGE_SHIFT) & 0xFFFFFFFFFFFF0000);
> 
> @@ -1206,14 +1219,17 @@ BBTestAllocatePagesInterfaceTest (
>         PageNum = (UINTN)Descriptor.NumberOfPages;
>         Start   = Descriptor.PhysicalStart;
> 
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        //
> +        // Calculate New Start address and PageNum with 64k alignment to
> +        // cover the case that some memory types' alignment is more than
> +        // 4k. If the available memory is less than 192k, the memory
> +        // allocation call will be skipped.
> +        //
> +        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
>           break;
>         }
> -        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> +        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> +        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
> 
>         Memory  = Start;
> 
> @@ -1329,14 +1345,17 @@ BBTestAllocatePagesInterfaceTest (
>         PageNum = (UINTN)Descriptor.NumberOfPages;
>         Start   = Descriptor.PhysicalStart;
> 
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        //
> +        // Calculate New Start address and PageNum with 64k alignment to
> +        // cover the case that some memory types' alignment is more than
> +        // 4k. If the available memory is less than 192k, the memory
> +        // allocation call will be skipped.
> +        //
> +        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
>           break;
>         }
> -        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> +        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> +        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
> 
>         Memory  = Start;
> 
> @@ -1468,14 +1487,17 @@ BBTestAllocatePagesInterfaceTest (
>         PageNum = (UINTN)Descriptor.NumberOfPages;
>         Start   = Descriptor.PhysicalStart;
> 
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        //
> +        // Calculate New Start address and PageNum with 64k alignment to
> +        // cover the case that some memory types' alignment is more than
> +        // 4k. If the available memory is less than 192k, the memory
> +        // allocation call will be skipped.
> +        //
> +        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
>           break;
>         }
> -        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> +        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
> +        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));
> 
>         Memory  = Start;
> 
> @@ -1923,4 +1945,4 @@ BBTestFreePoolInterfaceTest (
> 
>   FreeMemoryMap ();
>   return EFI_SUCCESS;
> -}
> +}
> -- 
> 2.31.0.windows.1
> 
> 
> 
> 
> 
> 


[-- Attachment #2: Type: text/html, Size: 18784 bytes --]

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

* Re: [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Update page alignment calculations
       [not found] ` <DB8PR08MB3993FC8E3E4847842808B1C185F19@DB8PR08MB3993.eurprd08.prod.outlook.com>
@ 2021-08-04  8:13   ` Paul Yang
  2021-08-09 10:35     ` [edk2-devel] " G Edhaya Chandran
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Yang @ 2021-08-04  8:13 UTC (permalink / raw)
  To: devel@edk2.groups.io
  Cc: Sunny Wang, Samer El-Haj-Mahmoud, G Edhaya Chandran, Barton Gao


I tested this patch on Ampere Altra system.
Tested-by: Paul Yang <Paul.Yang@arm.com>

-----Original Message-----
From: Sunny Wang <Sunny.Wang@arm.com>
Sent: Monday, July 19, 2021 4:08 PM
To: devel@edk2.groups.io
Cc: Sunny Wang <Sunny.Wang@arm.com>; Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>; G Edhaya Chandran <Edhaya.Chandran@arm.com>; Barton Gao <gaojie@byosoft.com.cn>; Sunny Wang <Sunny.Wang@arm.com>
Subject: [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Update page alignment calculations

This is to fix the SCT BS.AllocatePages failures (not found) with the case that the Start address is not aligned to 64k.
For example,
  The following is available memory region for testing:
    0000000082012000-00000000EB6D9FFF 00000000000696C8
  With the current page alignment calculation, we will get:
    Start address is 0x82020000
    PageNum is 0x696B8
  In BS.AllocatePages, it will make the end address align with 64k,
  so PageNum will be changed from 0x696B8 to 0x696C0. Therefore, the
  end address will become 0xEB6E0000 which is larger than 0xEB6D9FFF,
  so we get not found error in the end.

Therefore, the calculation for getting the PageNum should be updated to PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000)) so that we won't get a wrong PageNum to allocate a memory with a size larger than available space's size.

With this solution, the example above will get 0x696A8 as calculated PageNum. Then, in BS.AllocatePages, the PageNum will be changed from
0x696A8 to 0x696B0. Therefore, the end address will become 0xEB6D0000 that is smaller than 0xEB6D9FFF, so we get not found error in the end.

I also tested this solution on two ARM platforms (NXP1046A and RPi4).

Cc: Samer El-Haj-Mahmoud <samer.el-haj-mahmoud@arm.com>
Cc: G Edhaya Chandran <edhaya.chandran@arm.com>
Cc: Barton Gao <gaojie@byosoft.com.cn>
Signed-off-by: Sunny Wang <sunny.wang@arm.com>
---
 .../MemoryAllocationServicesBBTestFunction.c  | 110 +++++++++++-------
 1 file changed, 66 insertions(+), 44 deletions(-)

diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c
index bf8cd3b3..cdfac992 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationSer
+++ vices/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c
@@ -2,6 +2,7 @@

   Copyright 2006 - 2013 Unified EFI, Inc.<BR>
   Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2021, ARM Limited. All rights reserved.

   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License @@ -24,7 +25,7 @@ Abstract:

 --*/

-#include "SctLib.h"
+#include "SctLib.h"
 #include "MemoryAllocationServicesBBTestMain.h"

 #define ALLOCATEPAGES_MEMORYTYPE_NUM 16 @@ -700,14 +701,17 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;

-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        //
+        // Calculate New Start address and PageNum with 64k alignment to
+        // cover the case that some memory types' alignment is more than
+        // 4k. If the available memory is less than 192k, the memory
+        // allocation call will be skipped.
+        //
+        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
           break;
         }
-        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
+        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
+        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));

         Memory  = Start;

@@ -830,14 +834,17 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;

-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        //
+        // Calculate New Start address and PageNum with 64k alignment to
+        // cover the case that some memory types' alignment is more than
+        // 4k. If the available memory is less than 192k, the memory
+        // allocation call will be skipped.
+        //
+        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
           break;
         }
-        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
+        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
+        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));

         Memory  = Start;

@@ -953,14 +960,17 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;

-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        //
+        // Calculate New Start address and PageNum with 64k alignment to
+        // cover the case that some memory types' alignment is more than
+        // 4k. If the available memory is less than 192k, the memory
+        // allocation call will be skipped.
+        //
+        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
           break;
         }
-        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
+        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
+        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));

         Memory = Start + (SctLShiftU64 (PageNum/3, EFI_PAGE_SHIFT) & 0xFFFFFFFFFFFF0000);

@@ -1076,14 +1086,17 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;

-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        //
+        // Calculate New Start address and PageNum with 64k alignment to
+        // cover the case that some memory types' alignment is more than
+        // 4k. If the available memory is less than 192k, the memory
+        // allocation call will be skipped.
+        //
+        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
           break;
         }
-        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
+        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
+        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));

         Memory  = Start + (SctLShiftU64 (PageNum * 2 / 3, EFI_PAGE_SHIFT) & 0xFFFFFFFFFFFF0000);

@@ -1206,14 +1219,17 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;

-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        //
+        // Calculate New Start address and PageNum with 64k alignment to
+        // cover the case that some memory types' alignment is more than
+        // 4k. If the available memory is less than 192k, the memory
+        // allocation call will be skipped.
+        //
+        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
           break;
         }
-        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
+        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
+        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));

         Memory  = Start;

@@ -1329,14 +1345,17 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;

-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        //
+        // Calculate New Start address and PageNum with 64k alignment to
+        // cover the case that some memory types' alignment is more than
+        // 4k. If the available memory is less than 192k, the memory
+        // allocation call will be skipped.
+        //
+        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
           break;
         }
-        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
+        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
+        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));

         Memory  = Start;

@@ -1468,14 +1487,17 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;

-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        //
+        // Calculate New Start address and PageNum with 64k alignment to
+        // cover the case that some memory types' alignment is more than
+        // 4k. If the available memory is less than 192k, the memory
+        // allocation call will be skipped.
+        //
+        if (PageNum < (3 * EFI_SIZE_TO_PAGES(0x10000))) {
           break;
         }
-        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
+        Start   = (Start + 0xFFFF) & 0xFFFFFFFFFFFF0000;
+        PageNum = PageNum - (2 * EFI_SIZE_TO_PAGES(0x10000));

         Memory  = Start;

@@ -1923,4 +1945,4 @@ BBTestFreePoolInterfaceTest (

   FreeMemoryMap ();
   return EFI_SUCCESS;
-}
+}
--
2.31.0.windows.1


IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

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

* Re: [edk2-devel] [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Update page alignment calculations
  2021-08-04  8:13   ` Paul Yang
@ 2021-08-09 10:35     ` G Edhaya Chandran
  0 siblings, 0 replies; 6+ messages in thread
From: G Edhaya Chandran @ 2021-08-09 10:35 UTC (permalink / raw)
  To: Paul Yang, devel

[-- Attachment #1: Type: text/plain, Size: 148 bytes --]

Thank you all.

The solution is upstream by the commit : https://github.com/tianocore/edk2-test/commit/e4be30440f081454d5d6f047510f484ee5bb8a88

[-- Attachment #2: Type: text/html, Size: 166 bytes --]

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

end of thread, other threads:[~2021-08-09 10:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-19  8:07 [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Update page alignment calculations Sunny Wang
2021-07-27  6:12 ` [edk2-devel] " G Edhaya Chandran
2021-08-03 13:10 ` Samer El-Haj-Mahmoud
2021-08-03 21:40 ` tuanphan
     [not found] ` <DB8PR08MB3993FC8E3E4847842808B1C185F19@DB8PR08MB3993.eurprd08.prod.outlook.com>
2021-08-04  8:13   ` Paul Yang
2021-08-09 10:35     ` [edk2-devel] " G Edhaya Chandran

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