public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations
@ 2020-07-04 15:52 Pankaj Bansal
  2020-07-23 13:41 ` Pankaj Bansal
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Pankaj Bansal @ 2020-07-04 15:52 UTC (permalink / raw)
  To: devel, Eric Jin, G Edhaya Chandran
  Cc: Pankaj Bansal, Paul Yang, Samer El-Haj-Mahmoud, Gaurav Jain

From: Pankaj Bansal <pankaj.bansal@nxp.com>

The BBTestAllocatePagesInterfaceTest tries to allocate pages for
different memory types.
While doing so, it tries to fix up the Start and PageNum for 64K
Page size. There are multiple issues with this:

1. 64K alignment is being done regardless of Processor type and Memory
   type. while this is correct for ARM64 Processor, it might not be so
   for other Processor types. Also 64K alignment for ARM64 Processor
   is needed for some Memory types not all.
2. The Start is being incremented by 64K, even if Start is already 64K
   aligned.
3. PageNum is being decreased by 16 pages indiscriminately, which might
   not be needed in all cases.

fix all these issues by correctly doing the alignment in all needed
cases.

Cc: Paul Yang <Paul.Yang@arm.com>
Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
Cc: Gaurav Jain <gaurav.jain@nxp.com>
Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
---
 .../MemoryAllocationServicesBBTestFunction.c  | 148 +++++++++++++-----
 1 file changed, 106 insertions(+), 42 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 d18fe1fc2b94..9ed9e6e0de74 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
@@ -354,6 +354,7 @@ BBTestAllocatePagesInterfaceTest (
   EFI_TPL                              OldTpl;
   EFI_MEMORY_DESCRIPTOR                Descriptor;
   UINTN                                PageNum;
+  UINTN                                Alignment;
 
   //
   // Get the Standard Library Interface
@@ -700,14 +701,23 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;
 
-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
+
+        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
+             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
+             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
+             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesData) {
+
+          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
+        }
+
+        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
+        PageNum -= EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart);
+
+        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
+        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
           break;
         }
-        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
 
         Memory  = Start;
 
@@ -830,14 +840,23 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;
 
-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
+
+        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
+             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
+             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
+             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesData) {
+
+          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
+        }
+
+        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
+        PageNum -= EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart);
+
+        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
+        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
           break;
         }
-        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
 
         Memory  = Start;
 
@@ -953,14 +972,23 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;
 
-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
+
+        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
+             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
+             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
+             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesData) {
+
+          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
+        }
+
+        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
+        PageNum -= EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart);
+
+        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
+        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
           break;
         }
-        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
 
         Memory = Start + (SctLShiftU64 (PageNum/3, EFI_PAGE_SHIFT) & 0xFFFFFFFFFFFF0000);
 
@@ -1076,14 +1104,23 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;
 
-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
+
+        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
+             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
+             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
+             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesData) {
+
+          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
+        }
+
+        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
+        PageNum -= EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart);
+
+        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
+        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
           break;
         }
-        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
 
         Memory  = Start + (SctLShiftU64 (PageNum * 2 / 3, EFI_PAGE_SHIFT) & 0xFFFFFFFFFFFF0000);
 
@@ -1206,14 +1243,23 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;
 
-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
+
+        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
+             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
+             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
+             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesData) {
+
+          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
+        }
+
+        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
+        PageNum -= EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart);
+
+        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
+        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
           break;
         }
-        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
 
         Memory  = Start;
 
@@ -1329,14 +1375,23 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;
 
-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
+
+        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
+             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
+             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
+             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesData) {
+
+          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
+        }
+
+        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
+        PageNum -= EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart);
+
+        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
+        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
           break;
         }
-        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
 
         Memory  = Start;
 
@@ -1468,14 +1523,23 @@ BBTestAllocatePagesInterfaceTest (
         PageNum = (UINTN)Descriptor.NumberOfPages;
         Start   = Descriptor.PhysicalStart;
 
-        //
-        // Some memory types need more alignment than 4K, so
-        //
-        if (PageNum <= 0x10) {
+        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
+
+        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
+             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
+             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
+             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesData) {
+
+          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
+        }
+
+        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
+        PageNum -= EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart);
+
+        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
+        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
           break;
         }
-        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
-        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
 
         Memory  = Start;
 
-- 
2.17.1


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

* Re: [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations
  2020-07-04 15:52 [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations Pankaj Bansal
@ 2020-07-23 13:41 ` Pankaj Bansal
  2020-07-24  2:32 ` Samer El-Haj-Mahmoud
       [not found] ` <16248F836B15C59B.28930@groups.io>
  2 siblings, 0 replies; 6+ messages in thread
From: Pankaj Bansal @ 2020-07-23 13:41 UTC (permalink / raw)
  To: Pankaj Bansal (OSS), devel@edk2.groups.io, Eric Jin,
	G Edhaya Chandran
  Cc: Pankaj Bansal, Paul Yang, Samer El-Haj-Mahmoud, Gaurav Jain

ping!!

> -----Original Message-----
> From: Pankaj Bansal (OSS) <pankaj.bansal@oss.nxp.com>
> Sent: Saturday, July 4, 2020 9:22 PM
> To: devel@edk2.groups.io; Eric Jin <eric.jin@intel.com>; G Edhaya Chandran
> <Edhaya.Chandran@arm.com>
> Cc: Pankaj Bansal <pankaj.bansal@nxp.com>; Paul Yang <Paul.Yang@arm.com>;
> Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>; Gaurav Jain
> <gaurav.jain@nxp.com>
> Subject: [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations
> 
> From: Pankaj Bansal <pankaj.bansal@nxp.com>
> 
> The BBTestAllocatePagesInterfaceTest tries to allocate pages for
> different memory types.
> While doing so, it tries to fix up the Start and PageNum for 64K
> Page size. There are multiple issues with this:
> 
> 1. 64K alignment is being done regardless of Processor type and Memory
>    type. while this is correct for ARM64 Processor, it might not be so
>    for other Processor types. Also 64K alignment for ARM64 Processor
>    is needed for some Memory types not all.
> 2. The Start is being incremented by 64K, even if Start is already 64K
>    aligned.
> 3. PageNum is being decreased by 16 pages indiscriminately, which might
>    not be needed in all cases.
> 
> fix all these issues by correctly doing the alignment in all needed
> cases.
> 
> Cc: Paul Yang <Paul.Yang@arm.com>
> Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
> Cc: Gaurav Jain <gaurav.jain@nxp.com>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> ---
>  .../MemoryAllocationServicesBBTestFunction.c  | 148 +++++++++++++-----
>  1 file changed, 106 insertions(+), 42 deletions(-)
> 
> diff --git a/uefi-
> sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackB
> oxTest/MemoryAllocationServicesBBTestFunction.c b/uefi-
> sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackB
> oxTest/MemoryAllocationServicesBBTestFunction.c
> index d18fe1fc2b94..9ed9e6e0de74 100644
> --- a/uefi-
> sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackB
> oxTest/MemoryAllocationServicesBBTestFunction.c
> +++ b/uefi-
> sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackB
> oxTest/MemoryAllocationServicesBBTestFunction.c
> @@ -354,6 +354,7 @@ BBTestAllocatePagesInterfaceTest (
>    EFI_TPL                              OldTpl;
>    EFI_MEMORY_DESCRIPTOR                Descriptor;
>    UINTN                                PageNum;
> +  UINTN                                Alignment;
> 
>    //
>    // Get the Standard Library Interface
> @@ -700,14 +701,23 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
> 
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> +
> +        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesData) {
> +
> +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> +        }
> +
> +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> +        PageNum -= EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart);
> +
> +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
>            break;
>          }
> -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> 
>          Memory  = Start;
> 
> @@ -830,14 +840,23 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
> 
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> +
> +        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesData) {
> +
> +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> +        }
> +
> +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> +        PageNum -= EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart);
> +
> +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
>            break;
>          }
> -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> 
>          Memory  = Start;
> 
> @@ -953,14 +972,23 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
> 
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> +
> +        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesData) {
> +
> +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> +        }
> +
> +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> +        PageNum -= EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart);
> +
> +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
>            break;
>          }
> -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> 
>          Memory = Start + (SctLShiftU64 (PageNum/3, EFI_PAGE_SHIFT) &
> 0xFFFFFFFFFFFF0000);
> 
> @@ -1076,14 +1104,23 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
> 
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> +
> +        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesData) {
> +
> +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> +        }
> +
> +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> +        PageNum -= EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart);
> +
> +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
>            break;
>          }
> -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> 
>          Memory  = Start + (SctLShiftU64 (PageNum * 2 / 3, EFI_PAGE_SHIFT) &
> 0xFFFFFFFFFFFF0000);
> 
> @@ -1206,14 +1243,23 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
> 
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> +
> +        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesData) {
> +
> +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> +        }
> +
> +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> +        PageNum -= EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart);
> +
> +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
>            break;
>          }
> -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> 
>          Memory  = Start;
> 
> @@ -1329,14 +1375,23 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
> 
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> +
> +        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesData) {
> +
> +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> +        }
> +
> +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> +        PageNum -= EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart);
> +
> +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
>            break;
>          }
> -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> 
>          Memory  = Start;
> 
> @@ -1468,14 +1523,23 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
> 
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> +
> +        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesData) {
> +
> +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> +        }
> +
> +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> +        PageNum -= EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart);
> +
> +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
>            break;
>          }
> -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> 
>          Memory  = Start;
> 
> --
> 2.17.1


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

* Re: [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations
  2020-07-04 15:52 [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations Pankaj Bansal
  2020-07-23 13:41 ` Pankaj Bansal
@ 2020-07-24  2:32 ` Samer El-Haj-Mahmoud
       [not found] ` <16248F836B15C59B.28930@groups.io>
  2 siblings, 0 replies; 6+ messages in thread
From: Samer El-Haj-Mahmoud @ 2020-07-24  2:32 UTC (permalink / raw)
  To: Pankaj Bansal, devel@edk2.groups.io, Eric Jin, G Edhaya Chandran
  Cc: Pankaj Bansal, Paul Yang, Gaurav Jain, Samer El-Haj-Mahmoud

Acked-by: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>

> -----Original Message-----
> From: Pankaj Bansal <pankaj.bansal@oss.nxp.com>
> Sent: Saturday, July 4, 2020 11:52 AM
> To: devel@edk2.groups.io; Eric Jin <eric.jin@intel.com>; G Edhaya Chandran
> <Edhaya.Chandran@arm.com>
> Cc: Pankaj Bansal <pankaj.bansal@nxp.com>; Paul Yang
> <Paul.Yang@arm.com>; Samer El-Haj-Mahmoud <Samer.El-Haj-
> Mahmoud@arm.com>; Gaurav Jain <gaurav.jain@nxp.com>
> Subject: [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations
>
> From: Pankaj Bansal <pankaj.bansal@nxp.com>
>
> The BBTestAllocatePagesInterfaceTest tries to allocate pages for different
> memory types.
> While doing so, it tries to fix up the Start and PageNum for 64K Page size. There
> are multiple issues with this:
>
> 1. 64K alignment is being done regardless of Processor type and Memory
>    type. while this is correct for ARM64 Processor, it might not be so
>    for other Processor types. Also 64K alignment for ARM64 Processor
>    is needed for some Memory types not all.
> 2. The Start is being incremented by 64K, even if Start is already 64K
>    aligned.
> 3. PageNum is being decreased by 16 pages indiscriminately, which might
>    not be needed in all cases.
>
> fix all these issues by correctly doing the alignment in all needed cases.
>
> Cc: Paul Yang <Paul.Yang@arm.com>
> Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
> Cc: Gaurav Jain <gaurav.jain@nxp.com>
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> ---
>  .../MemoryAllocationServicesBBTestFunction.c  | 148 +++++++++++++-----
>  1 file changed, 106 insertions(+), 42 deletions(-)
>
> diff --git a/uefi-
> sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackBo
> xTest/MemoryAllocationServicesBBTestFunction.c b/uefi-
> sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackBo
> xTest/MemoryAllocationServicesBBTestFunction.c
> index d18fe1fc2b94..9ed9e6e0de74 100644
> --- a/uefi-
> sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/BlackBo
> xTest/MemoryAllocationServicesBBTestFunction.c
> +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationSer
> +++ vices/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c
> @@ -354,6 +354,7 @@ BBTestAllocatePagesInterfaceTest (
>    EFI_TPL                              OldTpl;
>    EFI_MEMORY_DESCRIPTOR                Descriptor;
>    UINTN                                PageNum;
> +  UINTN                                Alignment;
>
>    //
>    // Get the Standard Library Interface @@ -700,14 +701,23 @@
> BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
>
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> +
> +        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
> +             AllocatePagesMemoryType[TypeIndex] ==
> + EfiRuntimeServicesData) {
> +
> +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> +        }
> +
> +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> +        PageNum -= EFI_SIZE_TO_PAGES (Start -
> + Descriptor.PhysicalStart);
> +
> +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
>            break;
>          }
> -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
>
>          Memory  = Start;
>
> @@ -830,14 +840,23 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
>
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> +
> +        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
> +             AllocatePagesMemoryType[TypeIndex] ==
> + EfiRuntimeServicesData) {
> +
> +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> +        }
> +
> +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> +        PageNum -= EFI_SIZE_TO_PAGES (Start -
> + Descriptor.PhysicalStart);
> +
> +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
>            break;
>          }
> -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
>
>          Memory  = Start;
>
> @@ -953,14 +972,23 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
>
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> +
> +        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
> +             AllocatePagesMemoryType[TypeIndex] ==
> + EfiRuntimeServicesData) {
> +
> +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> +        }
> +
> +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> +        PageNum -= EFI_SIZE_TO_PAGES (Start -
> + Descriptor.PhysicalStart);
> +
> +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
>            break;
>          }
> -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
>
>          Memory = Start + (SctLShiftU64 (PageNum/3, EFI_PAGE_SHIFT) &
> 0xFFFFFFFFFFFF0000);
>
> @@ -1076,14 +1104,23 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
>
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> +
> +        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
> +             AllocatePagesMemoryType[TypeIndex] ==
> + EfiRuntimeServicesData) {
> +
> +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> +        }
> +
> +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> +        PageNum -= EFI_SIZE_TO_PAGES (Start -
> + Descriptor.PhysicalStart);
> +
> +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
>            break;
>          }
> -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
>
>          Memory  = Start + (SctLShiftU64 (PageNum * 2 / 3, EFI_PAGE_SHIFT) &
> 0xFFFFFFFFFFFF0000);
>
> @@ -1206,14 +1243,23 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
>
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> +
> +        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
> +             AllocatePagesMemoryType[TypeIndex] ==
> + EfiRuntimeServicesData) {
> +
> +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> +        }
> +
> +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> +        PageNum -= EFI_SIZE_TO_PAGES (Start -
> + Descriptor.PhysicalStart);
> +
> +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
>            break;
>          }
> -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
>
>          Memory  = Start;
>
> @@ -1329,14 +1375,23 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
>
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> +
> +        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
> +             AllocatePagesMemoryType[TypeIndex] ==
> + EfiRuntimeServicesData) {
> +
> +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> +        }
> +
> +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> +        PageNum -= EFI_SIZE_TO_PAGES (Start -
> + Descriptor.PhysicalStart);
> +
> +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
>            break;
>          }
> -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
>
>          Memory  = Start;
>
> @@ -1468,14 +1523,23 @@ BBTestAllocatePagesInterfaceTest (
>          PageNum = (UINTN)Descriptor.NumberOfPages;
>          Start   = Descriptor.PhysicalStart;
>
> -        //
> -        // Some memory types need more alignment than 4K, so
> -        //
> -        if (PageNum <= 0x10) {
> +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> +
> +        if  (AllocatePagesMemoryType[TypeIndex] == EfiACPIReclaimMemory   ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS       ||
> +             AllocatePagesMemoryType[TypeIndex] == EfiRuntimeServicesCode ||
> +             AllocatePagesMemoryType[TypeIndex] ==
> + EfiRuntimeServicesData) {
> +
> +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> +        }
> +
> +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> +        PageNum -= EFI_SIZE_TO_PAGES (Start -
> + Descriptor.PhysicalStart);
> +
> +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
>            break;
>          }
> -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
>
>          Memory  = Start;
>
> --
> 2.17.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] [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations
       [not found] ` <16248F836B15C59B.28930@groups.io>
@ 2020-08-04 11:28   ` Samer El-Haj-Mahmoud
  2020-08-04 16:56     ` G Edhaya Chandran
  0 siblings, 1 reply; 6+ messages in thread
From: Samer El-Haj-Mahmoud @ 2020-08-04 11:28 UTC (permalink / raw)
  To: devel@edk2.groups.io, Samer El-Haj-Mahmoud, Pankaj Bansal,
	Eric Jin, G Edhaya Chandran
  Cc: Pankaj Bansal, Paul Yang, Gaurav Jain, Samer El-Haj-Mahmoud

I verified that this works on multiple platforms

Tested-by: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Samer
> El-Haj-Mahmoud via groups.io
> Sent: Thursday, July 23, 2020 10:33 PM
> To: Pankaj Bansal <pankaj.bansal@oss.nxp.com>; devel@edk2.groups.io;
> Eric Jin <eric.jin@intel.com>; G Edhaya Chandran
> <Edhaya.Chandran@arm.com>
> Cc: Pankaj Bansal <pankaj.bansal@nxp.com>; Paul Yang
> <Paul.Yang@arm.com>; Gaurav Jain <gaurav.jain@nxp.com>; Samer El-Haj-
> Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
> Subject: Re: [edk2-devel] [PATCH edk2-test 1/1] SctPkg: fix page alignment
> calculations
>
> Acked-by: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
>
> > -----Original Message-----
> > From: Pankaj Bansal <pankaj.bansal@oss.nxp.com>
> > Sent: Saturday, July 4, 2020 11:52 AM
> > To: devel@edk2.groups.io; Eric Jin <eric.jin@intel.com>; G Edhaya
> > Chandran <Edhaya.Chandran@arm.com>
> > Cc: Pankaj Bansal <pankaj.bansal@nxp.com>; Paul Yang
> > <Paul.Yang@arm.com>; Samer El-Haj-Mahmoud <Samer.El-Haj-
> > Mahmoud@arm.com>; Gaurav Jain <gaurav.jain@nxp.com>
> > Subject: [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations
> >
> > From: Pankaj Bansal <pankaj.bansal@nxp.com>
> >
> > The BBTestAllocatePagesInterfaceTest tries to allocate pages for
> > different memory types.
> > While doing so, it tries to fix up the Start and PageNum for 64K Page
> > size. There are multiple issues with this:
> >
> > 1. 64K alignment is being done regardless of Processor type and Memory
> >    type. while this is correct for ARM64 Processor, it might not be so
> >    for other Processor types. Also 64K alignment for ARM64 Processor
> >    is needed for some Memory types not all.
> > 2. The Start is being incremented by 64K, even if Start is already 64K
> >    aligned.
> > 3. PageNum is being decreased by 16 pages indiscriminately, which might
> >    not be needed in all cases.
> >
> > fix all these issues by correctly doing the alignment in all needed cases.
> >
> > Cc: Paul Yang <Paul.Yang@arm.com>
> > Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
> > Cc: Gaurav Jain <gaurav.jain@nxp.com>
> > Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> > ---
> >  .../MemoryAllocationServicesBBTestFunction.c  | 148
> > +++++++++++++-----
> >  1 file changed, 106 insertions(+), 42 deletions(-)
> >
> > diff --git a/uefi-
> >
> sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/Bla
> > ckBo xTest/MemoryAllocationServicesBBTestFunction.c b/uefi-
> >
> sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/Bla
> > ckBo xTest/MemoryAllocationServicesBBTestFunction.c
> > index d18fe1fc2b94..9ed9e6e0de74 100644
> > --- a/uefi-
> >
> sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServices/Bla
> > ckBo xTest/MemoryAllocationServicesBBTestFunction.c
> > +++ b/uefi-
> sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationS
> > +++ er vices/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c
> > @@ -354,6 +354,7 @@ BBTestAllocatePagesInterfaceTest (
> >    EFI_TPL                              OldTpl;
> >    EFI_MEMORY_DESCRIPTOR                Descriptor;
> >    UINTN                                PageNum;
> > +  UINTN                                Alignment;
> >
> >    //
> >    // Get the Standard Library Interface @@ -700,14 +701,23 @@
> > BBTestAllocatePagesInterfaceTest (
> >          PageNum = (UINTN)Descriptor.NumberOfPages;
> >          Start   = Descriptor.PhysicalStart;
> >
> > -        //
> > -        // Some memory types need more alignment than 4K, so
> > -        //
> > -        if (PageNum <= 0x10) {
> > +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> > +
> > +        if  (AllocatePagesMemoryType[TypeIndex] ==
> EfiACPIReclaimMemory   ||
> > +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS
> ||
> > +             AllocatePagesMemoryType[TypeIndex] ==
> EfiRuntimeServicesCode ||
> > +             AllocatePagesMemoryType[TypeIndex] ==
> > + EfiRuntimeServicesData) {
> > +
> > +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> > +        }
> > +
> > +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> > +        PageNum -= EFI_SIZE_TO_PAGES (Start -
> > + Descriptor.PhysicalStart);
> > +
> > +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> > +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
> >            break;
> >          }
> > -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> > -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> >
> >          Memory  = Start;
> >
> > @@ -830,14 +840,23 @@ BBTestAllocatePagesInterfaceTest (
> >          PageNum = (UINTN)Descriptor.NumberOfPages;
> >          Start   = Descriptor.PhysicalStart;
> >
> > -        //
> > -        // Some memory types need more alignment than 4K, so
> > -        //
> > -        if (PageNum <= 0x10) {
> > +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> > +
> > +        if  (AllocatePagesMemoryType[TypeIndex] ==
> EfiACPIReclaimMemory   ||
> > +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS
> ||
> > +             AllocatePagesMemoryType[TypeIndex] ==
> EfiRuntimeServicesCode ||
> > +             AllocatePagesMemoryType[TypeIndex] ==
> > + EfiRuntimeServicesData) {
> > +
> > +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> > +        }
> > +
> > +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> > +        PageNum -= EFI_SIZE_TO_PAGES (Start -
> > + Descriptor.PhysicalStart);
> > +
> > +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> > +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
> >            break;
> >          }
> > -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> > -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> >
> >          Memory  = Start;
> >
> > @@ -953,14 +972,23 @@ BBTestAllocatePagesInterfaceTest (
> >          PageNum = (UINTN)Descriptor.NumberOfPages;
> >          Start   = Descriptor.PhysicalStart;
> >
> > -        //
> > -        // Some memory types need more alignment than 4K, so
> > -        //
> > -        if (PageNum <= 0x10) {
> > +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> > +
> > +        if  (AllocatePagesMemoryType[TypeIndex] ==
> EfiACPIReclaimMemory   ||
> > +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS
> ||
> > +             AllocatePagesMemoryType[TypeIndex] ==
> EfiRuntimeServicesCode ||
> > +             AllocatePagesMemoryType[TypeIndex] ==
> > + EfiRuntimeServicesData) {
> > +
> > +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> > +        }
> > +
> > +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> > +        PageNum -= EFI_SIZE_TO_PAGES (Start -
> > + Descriptor.PhysicalStart);
> > +
> > +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> > +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
> >            break;
> >          }
> > -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> > -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> >
> >          Memory = Start + (SctLShiftU64 (PageNum/3, EFI_PAGE_SHIFT) &
> > 0xFFFFFFFFFFFF0000);
> >
> > @@ -1076,14 +1104,23 @@ BBTestAllocatePagesInterfaceTest (
> >          PageNum = (UINTN)Descriptor.NumberOfPages;
> >          Start   = Descriptor.PhysicalStart;
> >
> > -        //
> > -        // Some memory types need more alignment than 4K, so
> > -        //
> > -        if (PageNum <= 0x10) {
> > +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> > +
> > +        if  (AllocatePagesMemoryType[TypeIndex] ==
> EfiACPIReclaimMemory   ||
> > +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS
> ||
> > +             AllocatePagesMemoryType[TypeIndex] ==
> EfiRuntimeServicesCode ||
> > +             AllocatePagesMemoryType[TypeIndex] ==
> > + EfiRuntimeServicesData) {
> > +
> > +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> > +        }
> > +
> > +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> > +        PageNum -= EFI_SIZE_TO_PAGES (Start -
> > + Descriptor.PhysicalStart);
> > +
> > +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> > +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
> >            break;
> >          }
> > -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> > -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> >
> >          Memory  = Start + (SctLShiftU64 (PageNum * 2 / 3,
> > EFI_PAGE_SHIFT) & 0xFFFFFFFFFFFF0000);
> >
> > @@ -1206,14 +1243,23 @@ BBTestAllocatePagesInterfaceTest (
> >          PageNum = (UINTN)Descriptor.NumberOfPages;
> >          Start   = Descriptor.PhysicalStart;
> >
> > -        //
> > -        // Some memory types need more alignment than 4K, so
> > -        //
> > -        if (PageNum <= 0x10) {
> > +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> > +
> > +        if  (AllocatePagesMemoryType[TypeIndex] ==
> EfiACPIReclaimMemory   ||
> > +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS
> ||
> > +             AllocatePagesMemoryType[TypeIndex] ==
> EfiRuntimeServicesCode ||
> > +             AllocatePagesMemoryType[TypeIndex] ==
> > + EfiRuntimeServicesData) {
> > +
> > +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> > +        }
> > +
> > +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> > +        PageNum -= EFI_SIZE_TO_PAGES (Start -
> > + Descriptor.PhysicalStart);
> > +
> > +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> > +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
> >            break;
> >          }
> > -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> > -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> >
> >          Memory  = Start;
> >
> > @@ -1329,14 +1375,23 @@ BBTestAllocatePagesInterfaceTest (
> >          PageNum = (UINTN)Descriptor.NumberOfPages;
> >          Start   = Descriptor.PhysicalStart;
> >
> > -        //
> > -        // Some memory types need more alignment than 4K, so
> > -        //
> > -        if (PageNum <= 0x10) {
> > +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> > +
> > +        if  (AllocatePagesMemoryType[TypeIndex] ==
> EfiACPIReclaimMemory   ||
> > +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS
> ||
> > +             AllocatePagesMemoryType[TypeIndex] ==
> EfiRuntimeServicesCode ||
> > +             AllocatePagesMemoryType[TypeIndex] ==
> > + EfiRuntimeServicesData) {
> > +
> > +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> > +        }
> > +
> > +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> > +        PageNum -= EFI_SIZE_TO_PAGES (Start -
> > + Descriptor.PhysicalStart);
> > +
> > +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> > +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
> >            break;
> >          }
> > -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> > -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> >
> >          Memory  = Start;
> >
> > @@ -1468,14 +1523,23 @@ BBTestAllocatePagesInterfaceTest (
> >          PageNum = (UINTN)Descriptor.NumberOfPages;
> >          Start   = Descriptor.PhysicalStart;
> >
> > -        //
> > -        // Some memory types need more alignment than 4K, so
> > -        //
> > -        if (PageNum <= 0x10) {
> > +        Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
> > +
> > +        if  (AllocatePagesMemoryType[TypeIndex] ==
> EfiACPIReclaimMemory   ||
> > +             AllocatePagesMemoryType[TypeIndex] == EfiACPIMemoryNVS
> ||
> > +             AllocatePagesMemoryType[TypeIndex] ==
> EfiRuntimeServicesCode ||
> > +             AllocatePagesMemoryType[TypeIndex] ==
> > + EfiRuntimeServicesData) {
> > +
> > +          Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
> > +        }
> > +
> > +        Start   = (Start + Alignment - 1) & ~(Alignment - 1);
> > +        PageNum -= EFI_SIZE_TO_PAGES (Start -
> > + Descriptor.PhysicalStart);
> > +
> > +        PageNum &= ~(EFI_SIZE_TO_PAGES (Alignment) - 1);
> > +        if (PageNum <= EFI_SIZE_TO_PAGES (Alignment)) {
> >            break;
> >          }
> > -        Start   = (Start + 0x10000) & 0xFFFFFFFFFFFF0000;
> > -        PageNum = PageNum - EFI_SIZE_TO_PAGES(0x10000);
> >
> >          Memory  = Start;
> >
> > --
> > 2.17.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.
>
> 

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] [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations
  2020-08-04 11:28   ` [edk2-devel] " Samer El-Haj-Mahmoud
@ 2020-08-04 16:56     ` G Edhaya Chandran
  2020-08-12 13:25       ` G Edhaya Chandran
  0 siblings, 1 reply; 6+ messages in thread
From: G Edhaya Chandran @ 2020-08-04 16:56 UTC (permalink / raw)
  To: Samer El-Haj-Mahmoud, devel

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

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

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

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

* Re: [edk2-devel] [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations
  2020-08-04 16:56     ` G Edhaya Chandran
@ 2020-08-12 13:25       ` G Edhaya Chandran
  0 siblings, 0 replies; 6+ messages in thread
From: G Edhaya Chandran @ 2020-08-12 13:25 UTC (permalink / raw)
  To: G Edhaya Chandran, devel

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

Upstreamed by Commit-ID: 93f402cfacc25a4fd422172e879024210c2ddc5b

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

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

end of thread, other threads:[~2020-08-12 13:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-04 15:52 [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations Pankaj Bansal
2020-07-23 13:41 ` Pankaj Bansal
2020-07-24  2:32 ` Samer El-Haj-Mahmoud
     [not found] ` <16248F836B15C59B.28930@groups.io>
2020-08-04 11:28   ` [edk2-devel] " Samer El-Haj-Mahmoud
2020-08-04 16:56     ` G Edhaya Chandran
2020-08-12 13:25       ` 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