From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR03-VE1-obe.outbound.protection.outlook.com (EUR03-VE1-obe.outbound.protection.outlook.com [40.107.5.77]) by mx.groups.io with SMTP id smtpd.web12.21416.1593877968787884081 for ; Sat, 04 Jul 2020 08:52:50 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nxp1.onmicrosoft.com header.s=selector2-nxp1-onmicrosoft-com header.b=GdFuB2iQ; spf=pass (domain: oss.nxp.com, ip: 40.107.5.77, mailfrom: pankaj.bansal@oss.nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ny8Gfry67wTmqslbWrOwEA2QVGpwsaiA1TSK4jGin65icJ+0j4ZrMODq4HSXYSxktCWn0/r54kweXx1j82VDcifZVCUS/vufU60cN6rCF4JbcKUB+QcQ6yfoCGU7w970BN2gePT3tuFAiA63Xfm08QERR/BhchRgB6+85PVXnVIXHMcuqM6OCK5tLAfjYNVu4O+DptI2ZhqQVRjUfyifuo+B0QbFYO+efocEw5SjIIT9HDB1bcaK55rsfKBQz0OJDlTVyTk2I9ZZxfezG0SksSIpjB/oP7mx+Af2cERAZEF0PgH9MsW9dlOt4TwkUR2BbrHxWKtI4R0vPAaf/ImZAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dxZxQazVER+YCo+Sx/dQ9bv9mg+WxLUk4MOWUqoQVvA=; b=KNaU85fNGfNkUiceSYUYuQnhNSAiock/2RUQFsFI1yo6qn4cTpqEe7U0kddJMQCESHnHXoS7ZXP07BUcyDuttEyaWC6aYLn/ly9Ld+/OBRke0zWzz5/b+JxXOGJG/T789k9wDi1xCG88f6JMj21vmt/Ed++M+jrg4ieHourzFpYv+oqaY9KHyzhDFhiXo007JFJSe6XmIMotcbT8fsZjZf7FR5SEYFX6UzzG9xCCiR5ZoRZ7PTYPFoZkgFh5wd+eopYk3XVw9Azs8BSqT+uAmDdlybNNC3Au8SCzcdacynEFSZC2UVVaTvk8yJVmBVFy3Wja3RCboo3HqNwB2m+LKQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dxZxQazVER+YCo+Sx/dQ9bv9mg+WxLUk4MOWUqoQVvA=; b=GdFuB2iQ1CxUd2knJcZjzt97KA3tCETfDQTN4Dvt42zPBDIuLP7VEdg8ZirSg1x5WkWjCFUnMpN4+xU+c1xwhBFU42oD5u+JzOSlvJanGuQ7e+H/j+xyONcRiOTxtvEErWeFOqkk5WCpL8OrCHBezlkhw3QfzKAyB1c7SVZ350c= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=oss.nxp.com; Received: from VI1PR04MB5933.eurprd04.prod.outlook.com (2603:10a6:803:ec::16) by VI1PR04MB5438.eurprd04.prod.outlook.com (2603:10a6:803:d3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.21; Sat, 4 Jul 2020 15:52:45 +0000 Received: from VI1PR04MB5933.eurprd04.prod.outlook.com ([fe80::4521:b667:cf06:b79b]) by VI1PR04MB5933.eurprd04.prod.outlook.com ([fe80::4521:b667:cf06:b79b%7]) with mapi id 15.20.3153.029; Sat, 4 Jul 2020 15:52:45 +0000 From: "Pankaj Bansal" To: devel@edk2.groups.io, Eric Jin , G Edhaya Chandran CC: Pankaj Bansal , Paul Yang , Samer El-Haj-Mahmoud , Gaurav Jain Subject: [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations Date: Sat, 4 Jul 2020 10:52:24 -0500 Message-ID: <20200704155224.28526-1-pankaj.bansal@oss.nxp.com> X-Mailer: git-send-email 2.17.1 X-ClientProxiedBy: BYAPR03CA0005.namprd03.prod.outlook.com (2603:10b6:a02:a8::18) To VI1PR04MB5933.eurprd04.prod.outlook.com (2603:10a6:803:ec::16) Return-Path: pankaj.bansal@oss.nxp.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from TFTPTOUEFI.am.freescale.net (64.157.242.222) by BYAPR03CA0005.namprd03.prod.outlook.com (2603:10b6:a02:a8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.20 via Frontend Transport; Sat, 4 Jul 2020 15:52:42 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [64.157.242.222] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 04c41199-9dbe-48b3-0956-08d820324ab8 X-MS-TrafficTypeDiagnostic: VI1PR04MB5438: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-Forefront-PRVS: 0454444834 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JlxhEa+KFJZ5p7kXTfv9aJ1gTSoJRiNvtd7lPpGWe3aZ73Boam14Bt9kLUA/bxqOwzM4bLMsznIBTN+rL6mO5tzg6JzAOF6j9avpYmQ20kybfM+HDZzt8PLzLe4bvsR00Pl36rh9G0oAAvkHjl+x+g+Nr358GgE4FNg5CHgkwIUzm9EBl3RdX8ewDcAtfXq7d4h6aNEzyoc31w93t5A2iqEvYpK6N2sNMmDjpjdxzwzXQUvN4blQ5pWdzMyOSfkk+5sDi9dMhuS7eMpXA96m+/x8LMPA5yHxCRKw8G4sHRt/q15InTT+0SYE91Yb8xlb04AHWt7IIHb0Bv3iTxsl8g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5933.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(136003)(376002)(396003)(39860400002)(346002)(366004)(186003)(2906002)(5660300002)(44832011)(6666004)(6512007)(54906003)(6486002)(956004)(2616005)(8676002)(66556008)(66476007)(83380400001)(26005)(16526019)(1076003)(316002)(110136005)(4326008)(6506007)(52116002)(478600001)(66946007)(8936002)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: x94m1R9Q2eV/5lpccj29Iqj3aNq0v2kLVXXItPWWrrGThCPziYCvqeDwr98CLikYQHv3ViqByQhmFMwy8LLeLHbiZ2MSMH+dNJ6HqK78VIazphK9ksOC2QxWRnYfnboQVXh33dLcQDdJCajmB3pxPRectegCOEvsSSmihxooKhyLZANgHrgiA6a9BjTUmFvLcBgvWkdVEVmr91TCAzT7T++M/Nz1m2CIp8SJ9uyxaM2HENm4DstuVWP/B/ggO5SGCDu5dzoPQgMqOMl67vQ1IXPXpRpmQdMMUKAuLhQlq/yQ/1qxd+tTTq4JXQ/izj6/KplQafkBp5R6kMvId2si5Uh2gTIyJmGwbZ/pH9nIhwhok4voFYaEpYgDoO21zNqbXYxvVeUzjJLEYsO1777qeGd47rByTf0c4VplFWE5UVava+oeZrNb+RODffTn+3b7CbwVT6tzrWdwzUnu7ExqhtfLVMz6nAqhJBYT6qwJ/BY7F7Z+hTWPMs7CNbcOHz7V X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04c41199-9dbe-48b3-0956-08d820324ab8 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5933.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jul 2020 15:52:45.1301 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lX6R46l0hZscajiiJZvMyE2Da7SjtHow7HoOlc7J7Wi+vOVR9/e6c3xIfmoje/s1Me9UrKXT7XGX7rHCpeTueA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5438 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Pankaj Bansal 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 Cc: Samer El-Haj-Mahmoud Cc: Gaurav Jain Signed-off-by: Pankaj Bansal --- .../MemoryAllocationServicesBBTestFunction.c | 148 +++++++++++++----- 1 file changed, 106 insertions(+), 42 deletions(-) diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocatio= nServices/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/MemoryAllocationServic= es/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MemoryAllocationServic= es/BlackBoxTest/MemoryAllocationServicesBBTestFunction.c @@ -354,6 +354,7 @@ BBTestAllocatePagesInterfaceTest ( EFI_TPL OldTpl; EFI_MEMORY_DESCRIPTOR Descriptor; UINTN PageNum; + UINTN Alignment; =20 // // Get the Standard Library Interface @@ -700,14 +701,23 @@ BBTestAllocatePagesInterfaceTest ( PageNum =3D (UINTN)Descriptor.NumberOfPages; Start =3D Descriptor.PhysicalStart; =20 - // - // Some memory types need more alignment than 4K, so - // - if (PageNum <=3D 0x10) { + Alignment =3D DEFAULT_PAGE_ALLOCATION_GRANULARITY; + + if (AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIReclaimMemor= y || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIMemoryNVS = || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeServicesC= ode || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeServicesD= ata) { + + Alignment =3D RUNTIME_PAGE_ALLOCATION_GRANULARITY; + } + + Start =3D (Start + Alignment - 1) & ~(Alignment - 1); + PageNum -=3D EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart); + + PageNum &=3D ~(EFI_SIZE_TO_PAGES (Alignment) - 1); + if (PageNum <=3D EFI_SIZE_TO_PAGES (Alignment)) { break; } - Start =3D (Start + 0x10000) & 0xFFFFFFFFFFFF0000; - PageNum =3D PageNum - EFI_SIZE_TO_PAGES(0x10000); =20 Memory =3D Start; =20 @@ -830,14 +840,23 @@ BBTestAllocatePagesInterfaceTest ( PageNum =3D (UINTN)Descriptor.NumberOfPages; Start =3D Descriptor.PhysicalStart; =20 - // - // Some memory types need more alignment than 4K, so - // - if (PageNum <=3D 0x10) { + Alignment =3D DEFAULT_PAGE_ALLOCATION_GRANULARITY; + + if (AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIReclaimMemor= y || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIMemoryNVS = || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeServicesC= ode || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeServicesD= ata) { + + Alignment =3D RUNTIME_PAGE_ALLOCATION_GRANULARITY; + } + + Start =3D (Start + Alignment - 1) & ~(Alignment - 1); + PageNum -=3D EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart); + + PageNum &=3D ~(EFI_SIZE_TO_PAGES (Alignment) - 1); + if (PageNum <=3D EFI_SIZE_TO_PAGES (Alignment)) { break; } - Start =3D (Start + 0x10000) & 0xFFFFFFFFFFFF0000; - PageNum =3D PageNum - EFI_SIZE_TO_PAGES(0x10000); =20 Memory =3D Start; =20 @@ -953,14 +972,23 @@ BBTestAllocatePagesInterfaceTest ( PageNum =3D (UINTN)Descriptor.NumberOfPages; Start =3D Descriptor.PhysicalStart; =20 - // - // Some memory types need more alignment than 4K, so - // - if (PageNum <=3D 0x10) { + Alignment =3D DEFAULT_PAGE_ALLOCATION_GRANULARITY; + + if (AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIReclaimMemor= y || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIMemoryNVS = || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeServicesC= ode || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeServicesD= ata) { + + Alignment =3D RUNTIME_PAGE_ALLOCATION_GRANULARITY; + } + + Start =3D (Start + Alignment - 1) & ~(Alignment - 1); + PageNum -=3D EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart); + + PageNum &=3D ~(EFI_SIZE_TO_PAGES (Alignment) - 1); + if (PageNum <=3D EFI_SIZE_TO_PAGES (Alignment)) { break; } - Start =3D (Start + 0x10000) & 0xFFFFFFFFFFFF0000; - PageNum =3D PageNum - EFI_SIZE_TO_PAGES(0x10000); =20 Memory =3D Start + (SctLShiftU64 (PageNum/3, EFI_PAGE_SHIFT) & 0xF= FFFFFFFFFFF0000); =20 @@ -1076,14 +1104,23 @@ BBTestAllocatePagesInterfaceTest ( PageNum =3D (UINTN)Descriptor.NumberOfPages; Start =3D Descriptor.PhysicalStart; =20 - // - // Some memory types need more alignment than 4K, so - // - if (PageNum <=3D 0x10) { + Alignment =3D DEFAULT_PAGE_ALLOCATION_GRANULARITY; + + if (AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIReclaimMemor= y || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIMemoryNVS = || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeServicesC= ode || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeServicesD= ata) { + + Alignment =3D RUNTIME_PAGE_ALLOCATION_GRANULARITY; + } + + Start =3D (Start + Alignment - 1) & ~(Alignment - 1); + PageNum -=3D EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart); + + PageNum &=3D ~(EFI_SIZE_TO_PAGES (Alignment) - 1); + if (PageNum <=3D EFI_SIZE_TO_PAGES (Alignment)) { break; } - Start =3D (Start + 0x10000) & 0xFFFFFFFFFFFF0000; - PageNum =3D PageNum - EFI_SIZE_TO_PAGES(0x10000); =20 Memory =3D Start + (SctLShiftU64 (PageNum * 2 / 3, EFI_PAGE_SHIFT= ) & 0xFFFFFFFFFFFF0000); =20 @@ -1206,14 +1243,23 @@ BBTestAllocatePagesInterfaceTest ( PageNum =3D (UINTN)Descriptor.NumberOfPages; Start =3D Descriptor.PhysicalStart; =20 - // - // Some memory types need more alignment than 4K, so - // - if (PageNum <=3D 0x10) { + Alignment =3D DEFAULT_PAGE_ALLOCATION_GRANULARITY; + + if (AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIReclaimMemor= y || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIMemoryNVS = || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeServicesC= ode || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeServicesD= ata) { + + Alignment =3D RUNTIME_PAGE_ALLOCATION_GRANULARITY; + } + + Start =3D (Start + Alignment - 1) & ~(Alignment - 1); + PageNum -=3D EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart); + + PageNum &=3D ~(EFI_SIZE_TO_PAGES (Alignment) - 1); + if (PageNum <=3D EFI_SIZE_TO_PAGES (Alignment)) { break; } - Start =3D (Start + 0x10000) & 0xFFFFFFFFFFFF0000; - PageNum =3D PageNum - EFI_SIZE_TO_PAGES(0x10000); =20 Memory =3D Start; =20 @@ -1329,14 +1375,23 @@ BBTestAllocatePagesInterfaceTest ( PageNum =3D (UINTN)Descriptor.NumberOfPages; Start =3D Descriptor.PhysicalStart; =20 - // - // Some memory types need more alignment than 4K, so - // - if (PageNum <=3D 0x10) { + Alignment =3D DEFAULT_PAGE_ALLOCATION_GRANULARITY; + + if (AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIReclaimMemor= y || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIMemoryNVS = || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeServicesC= ode || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeServicesD= ata) { + + Alignment =3D RUNTIME_PAGE_ALLOCATION_GRANULARITY; + } + + Start =3D (Start + Alignment - 1) & ~(Alignment - 1); + PageNum -=3D EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart); + + PageNum &=3D ~(EFI_SIZE_TO_PAGES (Alignment) - 1); + if (PageNum <=3D EFI_SIZE_TO_PAGES (Alignment)) { break; } - Start =3D (Start + 0x10000) & 0xFFFFFFFFFFFF0000; - PageNum =3D PageNum - EFI_SIZE_TO_PAGES(0x10000); =20 Memory =3D Start; =20 @@ -1468,14 +1523,23 @@ BBTestAllocatePagesInterfaceTest ( PageNum =3D (UINTN)Descriptor.NumberOfPages; Start =3D Descriptor.PhysicalStart; =20 - // - // Some memory types need more alignment than 4K, so - // - if (PageNum <=3D 0x10) { + Alignment =3D DEFAULT_PAGE_ALLOCATION_GRANULARITY; + + if (AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIReclaimMemor= y || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIMemoryNVS = || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeServicesC= ode || + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeServicesD= ata) { + + Alignment =3D RUNTIME_PAGE_ALLOCATION_GRANULARITY; + } + + Start =3D (Start + Alignment - 1) & ~(Alignment - 1); + PageNum -=3D EFI_SIZE_TO_PAGES (Start - Descriptor.PhysicalStart); + + PageNum &=3D ~(EFI_SIZE_TO_PAGES (Alignment) - 1); + if (PageNum <=3D EFI_SIZE_TO_PAGES (Alignment)) { break; } - Start =3D (Start + 0x10000) & 0xFFFFFFFFFFFF0000; - PageNum =3D PageNum - EFI_SIZE_TO_PAGES(0x10000); =20 Memory =3D Start; =20 --=20 2.17.1