From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (EUR05-AM6-obe.outbound.protection.outlook.com [40.107.22.85]) by mx.groups.io with SMTP id smtpd.web11.12405.1595511703952428053 for ; Thu, 23 Jul 2020 06:41:45 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nxp1.onmicrosoft.com header.s=selector2-nxp1-onmicrosoft-com header.b=d9qcQzy8; spf=pass (domain: oss.nxp.com, ip: 40.107.22.85, mailfrom: pankaj.bansal@oss.nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nk53qtNAiQH8d0+ovU/mB0KdFo9s+zhkc+0eAnB1EP3RZDlphCFUPtPskwZAbf3E/VpR8vjbclxdI0gy070s7mv8ax32ovd4nIGb7TkXdU0zuwU0qfd3JfD33j91Jwc+i3q9rF4PNp2o4q9rsW9mcGNnX4OjGqgEUCh1vl7/qRWb3rdb0Ag/4+MwYlMp4iqaZypLNyZ4DqHi2tBJYMWWNz308w1C5Ghe5nEWclPv6aAZKK9vFdOZk4aixsQ2KgJ7GrSQ99tbBQNUawrLkmS4eUVOarWzBuvXw5fpTA2Gy41n+cUuOjSbRdcp4VZdcURMK/1krq+U8wSpeRDOKN5ueA== 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=6CuqXfTHC95qNW0hvr5Xu/oiCbogb9ftpAnzBYRvvEw=; b=IkjNDUeoddnmFeRWa/KaTN66fTArrvrGr8AFCrqaKFHQdtte5n0PHzHM+2Lhx4dG1HaYDrKhjQ4PgKLUN+/5CTHWKJmcngQR5VB8YpHozXCRB7B78W/HORmkOHo7vcp8S1zraXBHDFAdIfWK+wxrdZzlgR+80aJ5qpVwvBXXfK/FTTHYLM73iHofF2JoB5nHB4QBiE89QhRtTBmUGg8w2G3ukBeYrupF3YAiTFfcwIrsB0hDkVfFfkIgSoFxpDFKBOMFLoSZ7xu1u462ZSXVE3omO12wx4CyzPM2PxzuV7yZ3WqeS8IWZjNsqp8etRsX2SfoX4d5Mh1MG/P9O1KMNg== 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=6CuqXfTHC95qNW0hvr5Xu/oiCbogb9ftpAnzBYRvvEw=; b=d9qcQzy80+gow+5ODGCSo8CVJC/LnR1lMjVrx+2c+iB1K4rBHuANde9daAsSDLoojFGoggp1GuHOiXEQg1XPNRzpS4LRKVTfxamAcbQWMr5LwNVcisvdwFX6zy1lKw5wee8a9Gge/ATPaBsdT1Yp624tFz83WbwlcIg7srD/qv4= Received: from VI1PR04MB5933.eurprd04.prod.outlook.com (2603:10a6:803:ec::16) by VI1PR0401MB2558.eurprd04.prod.outlook.com (2603:10a6:800:5c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20; Thu, 23 Jul 2020 13:41:41 +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.3216.024; Thu, 23 Jul 2020 13:41:41 +0000 From: "Pankaj Bansal" To: "Pankaj Bansal (OSS)" , "devel@edk2.groups.io" , Eric Jin , G Edhaya Chandran CC: Pankaj Bansal , Paul Yang , Samer El-Haj-Mahmoud , Gaurav Jain Subject: Re: [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations Thread-Topic: [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations Thread-Index: AQHWUhsooFnxolAx4ECvv6jYnkozwKkVScJA Date: Thu, 23 Jul 2020 13:41:41 +0000 Message-ID: References: <20200704155224.28526-1-pankaj.bansal@oss.nxp.com> In-Reply-To: <20200704155224.28526-1-pankaj.bansal@oss.nxp.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: oss.nxp.com; dkim=none (message not signed) header.d=none;oss.nxp.com; dmarc=none action=none header.from=oss.nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [103.217.117.179] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 3be2bcf9-0469-476a-66cc-08d82f0e21da x-ms-traffictypediagnostic: VI1PR0401MB2558: 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-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: hyhQqZTdslrNWiRQhEHZ5GewXP/X1RsnnoauLZVHzpXiw8vUUZuUqz12GBEYOBwFVwmsdAWPDcj3UFEQ4FwAcL878zzr+7EYb6IwqSpAPSKjRfNOwoCboTPsd/NC9Q9JBgDKLPLq2z4imytm3i7kZ77CsDWbzfm5pYf+/9FKFZmp/dSW0L6l1W3SlvxJqFtPzpbKXbRr6lewO++jCi36NgZErng3vXoZESjmI9n9bP/1Xt5zr/Be8LMQTn0XqDNdf2Ld27nCoSGoWd1voRre3h/dNQHltb5xwY+lZP4eWWQ0ExL3vJsbRgUuRT6QkX8n 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)(376002)(346002)(136003)(39860400002)(366004)(396003)(6506007)(53546011)(8676002)(110136005)(83380400001)(54906003)(9686003)(71200400001)(316002)(55016002)(4326008)(5660300002)(7696005)(33656002)(8936002)(52536014)(86362001)(66946007)(64756008)(186003)(76116006)(66476007)(66556008)(2906002)(478600001)(26005)(66446008);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata: NG8rVY4ZPljo9HfZFkKItcwK5y0v2lHK1xe4EUH50D9gSy0gtTYyKAqfM1IROGkVYx/1Pew6614u98nXtlqk027ingSFOjp0CH7OjwbvFOQ4T1KeIy14+SNOpPJlHeUb6RwpTs2BNEnCiq5R3kauaNc0p4D0RQMXi3x3NCPYDA7F40lF142fOGT8uTjhoMqJsr4MiujIBMuRCPvkLVjFmPbODPZhLQ/dN9FWQNo5IiZY+SEbK+UWYFuv9W7kgRmng4XDDxF9IN3++5xZSs6hdvns2ErPVQNpBuoHrItEWRM+Gqy5Fo6K4S58gQYeoyKm3khPDaR+ah707fauOeTf5iPnCv9JQC1th6bmL1EY1i4ygFrox9H+nly3zMJtEbm1y9vPdXG171Vv1DVOreO9uMatIZDnVku5dYsPTVp5cJLEBvM66Gb/Ndz7cTBGpRcMITB0SFU9Qe76yly/l0Z1Buaw4wbZIDUHY1KlcM2zLy7e/Gb3Tgqu1ob0j/jpwDJn MIME-Version: 1.0 X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5933.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3be2bcf9-0469-476a-66cc-08d82f0e21da X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Jul 2020 13:41:41.5954 (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: DxXmJYYrydzlDTYexzFN+RWz5yXyRAUOekBfjrk1JDyyf0KSIDIf+FObQ3OuJwyiMHG5tm+Q0XZsDp9EgKZfsw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2558 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable ping!! > -----Original Message----- > From: Pankaj Bansal (OSS) > Sent: Saturday, July 4, 2020 9:22 PM > To: devel@edk2.groups.io; Eric Jin ; G Edhaya Chandra= n > > Cc: Pankaj Bansal ; Paul Yang ; > Samer El-Haj-Mahmoud ; Gaurav Jain > > Subject: [PATCH edk2-test 1/1] SctPkg: fix page alignment calculations >=20 > From: Pankaj Bansal >=20 > 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: >=20 > 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. >=20 > fix all these issues by correctly doing the alignment in all needed > cases. >=20 > 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(-) >=20 > 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; >=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 EfiACPIReclaimMem= ory || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIMemoryNVS = || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeService= sCode || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeService= sData) { > + > + 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 EfiACPIReclaimMem= ory || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIMemoryNVS = || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeService= sCode || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeService= sData) { > + > + 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 EfiACPIReclaimMem= ory || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIMemoryNVS = || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeService= sCode || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeService= sData) { > + > + 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) & > 0xFFFFFFFFFFFF0000); >=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 EfiACPIReclaimMem= ory || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIMemoryNVS = || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeService= sCode || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeService= sData) { > + > + 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_SHI= FT) & > 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 EfiACPIReclaimMem= ory || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIMemoryNVS = || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeService= sCode || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeService= sData) { > + > + 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 EfiACPIReclaimMem= ory || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIMemoryNVS = || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeService= sCode || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeService= sData) { > + > + 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 EfiACPIReclaimMem= ory || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiACPIMemoryNVS = || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeService= sCode || > + AllocatePagesMemoryType[TypeIndex] =3D=3D EfiRuntimeService= sData) { > + > + 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 > -- > 2.17.1