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


 <div width="1" style="color:white;clear:both">_._,_._,_</div> <hr>   Groups.io Links:<p>   You receive all messages sent to this group.    <p> <a target="_blank" href="https://edk2.groups.io/g/devel/message/78619">View/Reply Online (#78619)</a> |    |  <a target="_blank" href="https://groups.io/mt/84303611/1813853">Mute This Topic</a>  | <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>    <a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> | <a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |  <a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>  [edk2-devel-archive@redhat.com]<br> <div width="1" style="color:white;clear:both">_._,_._,_</div>