From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (EUR01-VE1-obe.outbound.protection.outlook.com [40.107.14.88]) by mx.groups.io with SMTP id smtpd.web11.50137.1669914706746376020 for ; Thu, 01 Dec 2022 09:11:47 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=MEPW0fiD; spf=pass (domain: arm.com, ip: 40.107.14.88, mailfrom: sunny.wang@arm.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hy5c39ZWCI9NnxopiTqPKZIorY2IxsNgxCSSEflQ5WCSAXsOXMQQXEPwY4lR+OpiEOcA+7wTMDF8tYizuKtTUONH8hfLTmOZYFA3DvEZIa0bKiJ0bk6xsT+UhARWPK1o45PotrPobbBPw9RarHTOiTXo6FWx2LZyFPLzvTYPwg7xpqGzgZbUAs4UqRqePRuV1m/Z0pRdMaiB+xW6QG89n9HZTV9hrSARLBoQapaQhUY2Wp++fGap01k8QKvmpeOWC4mCAG5o/TFLn6rkxm7yRdvpZnObgDtLBxE+DjorCB4UXM/OZIy++RJmUhtg4gm43kjLeeK11YR/qvx8N3KXPg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Xndkybw4apfUBINnHD+Xc/kc3Mh0lh4RqrtM1VjU21A=; b=h4fUiNWBwPumXASWZaVtiERWsV79TiDKeH29goKaCrGZFPBkYkzelwOZ0ATlkODblog7aJqpRwzI2brO8HoawP+JsBoQBLF9YFxiS5TuY7Mo+WiO3IDd/0yc1l1weGhHuKiHsXys7od7FD2U66lMTldTW8dzikTMrENqpT/QTpzRSfbt0qaq/WY2niNUrQnN4AGd86bAoYW7nWzDdbbesbzb0DMrZtOfMa260VdIHK6IRfFeo6RGbUAP+banN9kgnXXJBdc5AytvoMccRkeUigGkU/rhm8TVPGtEP4ZePDnXTX5dEWRTj2bPY0CopTu8pG6X3I8UmhTWGr5dVB7m9w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Xndkybw4apfUBINnHD+Xc/kc3Mh0lh4RqrtM1VjU21A=; b=MEPW0fiDyQ+GbcWuVrHYOSxS4EXm9HReVtXTuMxbKoH2q3Tv9u3/9id3OExxWnFR3vBW8Y4zFiVWTCZM9DN/cbSCc/ISnN7b95Y1ekes1uvS4/px7EQv+XGZtYYpTYo+cr6GGTIR/+nLr/F3/3LKUEoYGkdbIw/oYBzbz3I8Qvk= Received: from AS8PR08MB7791.eurprd08.prod.outlook.com (2603:10a6:20b:52d::6) by AM0PR08MB5300.eurprd08.prod.outlook.com (2603:10a6:208:18e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8; Thu, 1 Dec 2022 17:11:35 +0000 Received: from AS8PR08MB7791.eurprd08.prod.outlook.com ([fe80::b530:a9ab:535a:4b9c]) by AS8PR08MB7791.eurprd08.prod.outlook.com ([fe80::b530:a9ab:535a:4b9c%3]) with mapi id 15.20.5880.008; Thu, 1 Dec 2022 17:11:35 +0000 From: "Sunny Wang" To: Dimitrije Pavlov , "devel@edk2.groups.io" CC: G Edhaya Chandran , Jeff Booher-Kaeding , Samer El-Haj-Mahmoud , Sunny Wang , Stuart Yoder Subject: Re: [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Check for memory below 4G Thread-Topic: [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Check for memory below 4G Thread-Index: AQHY3EzU7LqYwSEDqk+36+uHSwpmta5Zk7yw Date: Thu, 1 Dec 2022 17:11:35 +0000 Message-ID: References: <20221010020530.1261275-1-dimitrije.pavlov@arm.com> In-Reply-To: <20221010020530.1261275-1-dimitrije.pavlov@arm.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: AS8PR08MB7791:EE_|AM0PR08MB5300:EE_ x-ms-office365-filtering-correlation-id: 01debc85-99d5-4c2b-a175-08dad3bf19fb nodisclaimer: true x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: pEuZkwJFOAM3mBlfanOm5u1CHapYyjTyyIUDI+iv2cdmgLL6puyw1JwriiDudfA0m7dQa9QrwG7TEsf/YstQuTYcWP4gB3kFAIwZadzn+JEReHLM+2P1D02isgB/Lh6Qv8mQvnRtd+sGupSdcujjEvIU5du86nPu4F9CHmRIjSsjVghRQabhIHP7MTrufJs2y04JAOnLtnN7pW1JWxj+qWpx/Mq65TD25rXSGuFyshbCTy7Lkc+QbmoqG7vD9bpiLgFcstboTT5J3H6KQTcIFDXFasiJ9U4/8DxdTpdj85YHplCY8Hl7qyTYZVniP8RXNmxvhF3P2363CmU4mSXDwAKQOBPwGs02swCci2LgdGnP+pOM4FoRUbrYU5CnhEY+Tg692poR5FZS7S7doldLNvXKDKVZ3Lw8I5/VDz37tXOyIBQOw5sf1qeVcdg5QJfo1iaeLal5sAlTF99qpmQBmNQAe3/azLCYOVorD/iheqja5FkfTJE7GFMTcxjZrnEq8aeksV98YNzgBtg4mx/Q6FQWiMru0zZK0mBUUkMENWgW6FJhxRk2nBWxJnAXGlSFMvZ2Qu4EC2IOvdBF/Q99TLFBtCn/AyJwjD2epK0hxELEmiupecRkMxsV4i3eJKEih2ZN72AyWYw1/+k8r53bamKNDwCNGy/F7JL4s+h75m6DrbGq+ufF5pEJAhokNIU/wPkX4r4aI2QhpFEq0pKqkSq0WQ1Xgay7lJiNQ0kbPAQ= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR08MB7791.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(396003)(39860400002)(136003)(366004)(451199015)(966005)(71200400001)(53546011)(6506007)(122000001)(478600001)(66946007)(38100700002)(66476007)(33656002)(26005)(64756008)(8676002)(7696005)(66446008)(76116006)(66556008)(9686003)(316002)(4326008)(86362001)(19627235002)(55016003)(38070700005)(54906003)(110136005)(52536014)(41300700001)(5660300002)(8936002)(186003)(83380400001)(2906002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?PW+/vFC+CWOaUbS+OYcB9U+kT1uIoV+TE1602Vpd5Dt2B548fUFTei9sHHF8?= =?us-ascii?Q?aQaOhgv3BF2GDo1JbtysTm/7lKX8tJm9SVtesWEB109We5Xl0GpFHuRX1RyQ?= =?us-ascii?Q?Ws78O2wdilX+sdj0qzfonAPXVpT7LFWAIF0zCCSIbwoQIE0S7EpbReU/optw?= =?us-ascii?Q?WXcNI+C5dAvOeeGCzUVvG58+a+R7c154bbDyvz3e3CUWOgC07DUcPNCO/Iyq?= =?us-ascii?Q?kAWdH4bxZRASwZ2LBwllINjiLXA1VzIhl7n40KLwncZ1WkNe3kRJzYoocICu?= =?us-ascii?Q?tyL44NW3NqDEWsgZlqoEBcxYq1nv2DrjSLwn32S97VpMALw61ttbtzdk22tZ?= =?us-ascii?Q?GSX9gLxejcVliM80jioaSrewO4b8JM4JEDT8WJ+Til7dTS7yspbPXJdxZO+V?= =?us-ascii?Q?kftR+6DnhLRHf+sY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?us-ascii?Q?Wyq8hXvu0TDaZOm31rRSObSizXEksPne/YIqpCDtSeaFXh51FJY8QjkRYRNl?= =?us-ascii?Q?RaxPgvdeTmp5U1Q4vit8lBA1TUsoVxtjIC3w1iyNiBcbKbTbV//wiSEi6TAm?= =?us-ascii?Q?4XalW1uZDZjXnMoeis0zXloq2GHAYwo3vo43sdzwHlUY0A/Oua6Y4u/9cexa?= =?us-ascii?Q?/bLbbC1vJp3lLi+48pAilTuuX6SRML4IjNDo48W6tuvFhrza9mhMVQubZZaT?= =?us-ascii?Q?/RgSPsvMPkJU/mBiLbg=3D?= MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7791.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 01debc85-99d5-4c2b-a175-08dad3bf19fb X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Dec 2022 17:11:35.4013 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: GMmERH8H+b4UScZGyUksTNg9AaAIvUuNkBfQb1M2+8KY2a9tfhOyPneS5grHUAIyDFJAcObJwjyYQc9Cx9KPcg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB5300 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed the patch with Stuart and Edhaya in edk2-test monthly meeting. The= patch looks good to me. Thanks, Dimitrije. Reviewed-by: Sunny Wang -----Original Message----- From: Dimitrije Pavlov Sent: 10 October 2022 03:06 To: devel@edk2.groups.io Cc: G Edhaya Chandran ; Jeff Booher-Kaeding ; Samer El-Haj-Mahmoud ; Sunny Wang Subject: [edk2-test][PATCH v1 1/1] uefi-sct/SctPkg: Check for memory below = 4G REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4009 Check if there is usable memory below 4 GiB before testing for allocation without the EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE attribute. Cc: G Edhaya Chandran Cc: Jeff Booher-Kaeding Cc: Samer El-Haj-Mahmoud Cc: Sunny Wang Signed-off-by: Dimitrije Pavlov --- uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/PciRootBridgeIo/BlackBoxTest/Pc= iRootBridgeIoBBTestFunction_2.c | 142 +++++++++++++++++++- 1 file changed, 140 insertions(+), 2 deletions(-) diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/PciRootBridgeIo/Bla= ckBoxTest/PciRootBridgeIoBBTestFunction_2.c b/uefi-sct/SctPkg/TestCase/UEFI= /EFI/Protocol/PciRootBridgeIo/BlackBoxTest/PciRootBridgeIoBBTestFunction_2.= c index 89adcba91e70..fafbf62f77c6 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/PciRootBridgeIo/BlackBoxTe= st/PciRootBridgeIoBBTestFunction_2.c +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/PciRootBridgeIo/BlackBoxTe= st/PciRootBridgeIoBBTestFunction_2.c @@ -4118,7 +4118,69 @@ AllocateBuffer_Func ( UINTN AttributesNum; EFI_PCI_ROOT_BRIDGE_IO_DEVICE *RBDev; EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *RootBridgeIo; + EFI_MEMORY_DESCRIPTOR *MemoryMap; + EFI_MEMORY_DESCRIPTOR *Entry; + UINTN MemoryMapSize; + UINTN MapKey; + UINTN DescriptorSize; + UINT32 DescriptorVersion; + UINTN Iterator; + BOOLEAN UsableMemoryBelow4G; + // + // Obtain the memory map size + // + MemoryMapSize =3D 0; + Status =3D gBS->GetMemoryMap ( + &MemoryMapSize, + NULL, + &MapKey, + &DescriptorSize, + &DescriptorVersion + ); + ASSERT (Status =3D=3D EFI_BUFFER_TOO_SMALL); + // + // Allocating a buffer for the memory map will change + // the memory map, so we increase the size here just in case + // + MemoryMapSize +=3D EFI_PAGE_SIZE; + Status =3D gBS->AllocatePool ( + EfiLoaderData, + MemoryMapSize, + (VOID **)&MemoryMap + ); + if (EFI_ERROR (Status)) { + return Status; + } + // + // Get the actual memory map + // + Status =3D gBS->GetMemoryMap ( + &MemoryMapSize, + MemoryMap, + &MapKey, + &DescriptorSize, + &DescriptorVersion + ); + if (EFI_ERROR (Status)) { + gBS->FreePool (MemoryMap); + } + + // + // Check each entry in the memory map for free memory below 4 GiB and se= t + // UsableMemoryBelow4G accordingly + // + UsableMemoryBelow4G =3D FALSE; + for (Iterator =3D 0; Iterator < MemoryMapSize; Iterator +=3D DescriptorS= ize) { + Entry =3D (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemoryMap + Iterator); + if ( Entry->PhysicalStart < (EFI_PHYSICAL_ADDRESS)SIZE_4GB + && ( Entry->Type =3D=3D EfiConventionalMemory || Entry->Type =3D=3D = EfiPersistentMemory)) + { + UsableMemoryBelow4G =3D TRUE; + break; + } + } + gBS->FreePool (MemoryMap); AllocateType =3D 0; @@ -4188,7 +4250,14 @@ AllocateBuffer_Func ( for (MemoryTypeNum =3D 0; MemoryTypeNum < 2; MemoryTypeNum++) { for (AttributesNum =3D 0; AttributesNum < 8; AttributesNum++) { - + // + // If there is no usable memory below 4 GiB, skip 32-bit allocations + // + if ( !UsableMemoryBelow4G + && !(Attributes[AttributesNum] & EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CY= CLE)) + { + continue; + } Status =3D RootBridgeIo->AllocateBuffer ( RootBridgeIo, AllocateType, @@ -4298,7 +4367,69 @@ FreeBuffer_Func ( UINTN AttributesNum; EFI_PCI_ROOT_BRIDGE_IO_DEVICE *RBDev; EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *RootBridgeIo; + EFI_MEMORY_DESCRIPTOR *MemoryMap; + EFI_MEMORY_DESCRIPTOR *Entry; + UINTN MemoryMapSize; + UINTN MapKey; + UINTN DescriptorSize; + UINT32 DescriptorVersion; + UINTN Iterator; + BOOLEAN UsableMemoryBelow4G; + // + // Obtain the memory map size + // + MemoryMapSize =3D 0; + Status =3D gBS->GetMemoryMap ( + &MemoryMapSize, + NULL, + &MapKey, + &DescriptorSize, + &DescriptorVersion + ); + ASSERT (Status =3D=3D EFI_BUFFER_TOO_SMALL); + // + // Allocating a buffer for the memory map will change + // the memory map, so we increase the size here just in case + // + MemoryMapSize +=3D EFI_PAGE_SIZE; + Status =3D gBS->AllocatePool ( + EfiLoaderData, + MemoryMapSize, + (VOID **)&MemoryMap + ); + if (EFI_ERROR (Status)) { + return Status; + } + // + // Get the actual memory map + // + Status =3D gBS->GetMemoryMap ( + &MemoryMapSize, + MemoryMap, + &MapKey, + &DescriptorSize, + &DescriptorVersion + ); + if (EFI_ERROR (Status)) { + gBS->FreePool (MemoryMap); + } + + // + // Check each entry in the memory map for free memory below 4 GiB and se= t + // UsableMemoryBelow4G accordingly + // + UsableMemoryBelow4G =3D FALSE; + for (Iterator =3D 0; Iterator < MemoryMapSize; Iterator +=3D DescriptorS= ize) { + Entry =3D (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemoryMap + Iterator); + if ( Entry->PhysicalStart < (EFI_PHYSICAL_ADDRESS)SIZE_4GB + && ( Entry->Type =3D=3D EfiConventionalMemory || Entry->Type =3D=3D = EfiPersistentMemory)) + { + UsableMemoryBelow4G =3D TRUE; + break; + } + } + gBS->FreePool (MemoryMap); AllocateType =3D 0 ; @@ -4368,7 +4499,14 @@ FreeBuffer_Func ( for (MemoryTypeNum =3D 0; MemoryTypeNum < 2; MemoryTypeNum++) { for (AttributesNum =3D 0; AttributesNum < 8; AttributesNum++) { - + // + // If there is no usable memory below 4 GiB, skip 32-bit allocations + // + if ( !UsableMemoryBelow4G + && !(Attributes[AttributesNum] & EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CY= CLE)) + { + continue; + } Status =3D RootBridgeIo->AllocateBuffer ( RootBridgeIo, AllocateType, -- 2.37.3 IMPORTANT NOTICE: The contents of this email and any attachments are confid= ential and may also be privileged. If you are not the intended recipient, p= lease 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.