From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=104.47.2.88; helo=eur01-db5-obe.outbound.protection.outlook.com; envelope-from=wasim.khan@nxp.com; receiver=edk2-devel@lists.01.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0088.outbound.protection.outlook.com [104.47.2.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8E1F0222275AA for ; Sun, 7 Jan 2018 10:58:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=a82p3Es59L6lYemjvbNGnqflao3g6t9tInpind7xSRY=; b=dIFklolZdw/Z9dv4FvLnZ5EvDIxPfd7TxVzWdwEP0YA8cuSXEVasVNx4twU4v9fMPB8AneBqwjcPB0uxo+rRnY4FF1PrJ+d4++uJoDPztvA5OtJd2lnZnyCCxRB3wM8xc3T01s9VnO6MsyMm2qmNgZ2xIc2FOFauSD/9CKlheFE= Received: from DB6PR0401MB2342.eurprd04.prod.outlook.com (10.168.54.155) by DB6PR0401MB2342.eurprd04.prod.outlook.com (10.168.54.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.366.8; Sun, 7 Jan 2018 19:03:21 +0000 Received: from DB6PR0401MB2342.eurprd04.prod.outlook.com ([fe80::fd7b:6470:427c:aea8]) by DB6PR0401MB2342.eurprd04.prod.outlook.com ([fe80::fd7b:6470:427c:aea8%17]) with mapi id 15.20.0366.011; Sun, 7 Jan 2018 19:03:21 +0000 From: Wasim Khan To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: "Gao, Liming" Thread-Topic: Memory space entry is not removed after calling FreeMemorySpace and RemoveMemorySpace Thread-Index: AdOGC9ELVQ4yvX0oRxySz+o11ogX7AAB/zdQAHS4DAA= Date: Sun, 7 Jan 2018 19:03:21 +0000 Message-ID: References: <0C09AFA07DD0434D9E2A0C6AEB0483103B9F8894@shsmsx102.ccr.corp.intel.com> In-Reply-To: <0C09AFA07DD0434D9E2A0C6AEB0483103B9F8894@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=wasim.khan@nxp.com; x-originating-ip: [110.172.150.254] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB6PR0401MB2342; 7:Tlrmz7Ad4CsrlZxWv/qrzDbiKCsGhRFvJm61TORBcP4DWXyRo3hF9JvuI2Xorc5fPi+yeKg5o5gY9iUH5tDVPMbnzqKN6zzGrBWSv/dl/beceB3RHSLFi17ebAlQxI65jjpmvhGIaFA8Vjpl90jP/RMrUukC8iKslJSxN2y3C3vzAPPH1gZICwe5R62GKSThiyJIFipNZge3fygGDnHkngCdA0w8xVJzGq+CJ03DnJRXg63bYRpvMVLDrWC/63zN x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: b3324be2-6efb-4860-74a2-08d556015242 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(3008032)(2017052603307)(7153060)(7193020); SRVR:DB6PR0401MB2342; x-ms-traffictypediagnostic: DB6PR0401MB2342: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(278428928389397)(189930954265078)(185117386973197)(162533806227266)(45079756050767)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(3231023)(944501075)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041268)(20161123560045)(20161123558120)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:DB6PR0401MB2342; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:DB6PR0401MB2342; x-forefront-prvs: 0545EFAC9A x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(396003)(376002)(346002)(39380400002)(366004)(189003)(199004)(57704003)(53754006)(13464003)(6116002)(97736004)(2900100001)(6246003)(3660700001)(6436002)(305945005)(74316002)(7736002)(106356001)(3280700002)(316002)(3846002)(229853002)(66066001)(105586002)(345774005)(33656002)(2906002)(4326008)(9686003)(55016002)(110136005)(6306002)(25786009)(81166006)(14454004)(6506007)(45080400002)(2501003)(7696005)(76176011)(575784001)(5660300001)(966005)(53546011)(5250100002)(8936002)(68736007)(478600001)(102836004)(99286004)(2950100002)(53936002)(81156014)(8676002)(59450400001)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0401MB2342; H:DB6PR0401MB2342.eurprd04.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: YDknDQWfi1uCn/6LKrkEzZrVXyU2SIyLfZZ6l7BMuC/nWX8BRoWGDApcPLfPZ8+ga2VFGtgcUAzettqpf8iL9A== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b3324be2-6efb-4860-74a2-08d556015242 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Jan 2018 19:03:21.6429 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0401MB2342 Subject: Re: Memory space entry is not removed after calling FreeMemorySpace and RemoveMemorySpace X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Jan 2018 18:58:21 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Star, Thank you for your reply. I cannot add memory space as EfiGcdMemoryTypeReserved because for my use ca= se, i am exposing memory space of an extended DDR memory to kernel. If I ad= d this memory space as EfiGcdMemoryTypeReserved, then linux is not able to = allocate memory from this region to applications (a simple application requ= esting memory from this region fails). So I have to add the memory space as= EfiGcdMemoryTypeSystemMemory only. > What is the usage that the memory space needs to be added first and remov= ed later? No specific use case, I am checking the status of 'gDS->AddMemorySpace' and= 'gDS->SetMemorySpaceAttributes', if any of these calls fails, I want to re= move the added memory space. Ideally it should work. Regards, Wasim > -----Original Message----- > From: Zeng, Star [mailto:star.zeng@intel.com] > Sent: Friday, January 05, 2018 4:35 PM > To: Wasim Khan ; edk2-devel@lists.01.org > Cc: Zeng, Star ; Gao, Liming > Subject: RE: Memory space entry is not removed after calling FreeMemorySp= ace > and RemoveMemorySpace >=20 > PI spec has clear description below in AddMemorySpace(). >=20 > "If the memory range specified by BaseAddress and Length is of type > EfiGcdMemoryTypeSystemMemory or EfiGcdMemoryTypeMoreReliable, then > the memory range may be *automatically allocated for use by the UEFI memo= ry > services*." >=20 > But PI spec has no clear description about removing the use from the UEFI > memory services in FreeMemorySpace() and RemoveMemorySpace(). > I think it is very hard (may be not possible) as the added memory space m= ay have > been used by UEFI memory (page) services for drivers after the memory spa= ce is > added by AddMemorySpace(). >=20 > What is the usage that the memory space needs to be added first and remov= ed > later? > Could the memory space be added as EfiGcdMemoryTypeReserved type instead > of EfiGcdMemoryTypeSystemMemory type? >=20 >=20 > Thanks, > Star > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Wasim Khan > Sent: Friday, January 5, 2018 5:59 PM > To: edk2-devel@lists.01.org > Subject: [edk2] Memory space entry is not removed after calling > FreeMemorySpace and RemoveMemorySpace >=20 > Hi All, >=20 > I am facing a problem that if a add a memory space using 'gDS- > >AddMemorySpace' and then remove it using 'gDS->FreeMemorySpace' > followed by 'gDS->RemoveMemorySpace'. > I can still see the entry of added memory space in the table shown by 'me= mmap' > command. >=20 > I enabled DEBUG_GCD and as per logs , the entry is removed from > GcdMemorySpaceMap , but when I run 'memmap' command which gets the > memory map using 'gBS->GetMemoryMap', I can see that entry for the added > memory space is still present. Steps and Logs are below for reference >=20 > Do I need to perform any other steps in order to cleanly remove the memor= y > space entry ? >=20 > Regards, > Wasim >=20 >=20 >=20 > Below are the steps and GCD debug logs. > Steps 1 : Add a memory space . We can see that an entry from system memor= y is > added. >=20 > Status =3D gDS->AddMemorySpace ( > EfiGcdMemoryTypeSystemMemory, > FixedPcdGet64(PcdSystemMemory= ExBase), > SystemMemoryExSize, > EFI_MEMORY_WC | EFI_MEMORY_WT= | > EFI_MEMORY_WB > ); >=20 > Logs: >=20 > GCD:AddMemorySpace(Base=3D0000008080000000,Length=3D0000000380000000) > GcdMemoryType =3D SystemMem > Capabilities =3D 000000000000000E > CoreConvertSpace 774 > Status =3D Success > GCDMemType Range Capabilities Attributes > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > NonExist 0000000000000000-000000009FFFFFFF 0000000000000000 > 0000000000000000 > SystemMem 00000000A0000000-00000000DFFFFFFF 800000000000000E > 0000000000000008* > NonExist 00000000E0000000-00000000E01BFFFF 0000000000000000 > 0000000000000000 > SystemMem 00000000E01C0000-00000000FFFFFFFF 800000000000000E > 0000000000000008* > NonExist 0000000100000000-000000807FFFFFFF 0000000000000000 > 0000000000000000 > SystemMem 0000008080000000-00000083FFFFFFFF 800000000000000E > 0000000000000000 > NonExist 0000008400000000-0000FFFFFFFFFFFF 0000000000000000 > 0000000000000000 >=20 > GCD:AllocateMemorySpace(Base=3D0000008080000000,Length=3D00000003800000 > 00) > GcdAllocateType =3D AtAddress > GcdMemoryType =3D SystemMem > Alignment =3D 0000000000001000 > ImageHandle =3D FED1FF98 > DeviceHandle =3D 0 > Status =3D Success (BaseAddress =3D 0000008080000000) > GCDMemType Range Capabilities Attributes > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > NonExist 0000000000000000-000000009FFFFFFF 0000000000000000 > 0000000000000000 > SystemMem 00000000A0000000-00000000DFFFFFFF 800000000000000E > 0000000000000008* > NonExist 00000000E0000000-00000000E01BFFFF 0000000000000000 > 0000000000000000 > SystemMem 00000000E01C0000-00000000FFFFFFFF 800000000000000E > 0000000000000008* > NonExist 0000000100000000-000000807FFFFFFF 0000000000000000 > 0000000000000000 > SystemMem 0000008080000000-00000083FFFFFFFF 800000000000000E > 0000000000000000* > NonExist 0000008400000000-0000FFFFFFFFFFFF 0000000000000000 > 0000000000000000 >=20 >=20 > Step2: Free the memory space > Status =3D gDS->FreeMemorySpace ( > FixedPcdGet64(PcdSystemMemoryExBase), > SystemMemoryExSize > ); >=20 > Logs: >=20 > GCD:FreeMemorySpace(Base=3D0000008080000000,Length=3D0000000380000000) > Status =3D Success > GCDMemType Range Capabilities Attributes > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > NonExist 0000000000000000-000000009FFFFFFF 0000000000000000 > 0000000000000000 > SystemMem 00000000A0000000-00000000DFFFFFFF 800000000000000E > 0000000000000008* > NonExist 00000000E0000000-00000000E01BFFFF 0000000000000000 > 0000000000000000 > SystemMem 00000000E01C0000-00000000FFFFFFFF 800000000000000E > 0000000000000008* > NonExist 0000000100000000-000000807FFFFFFF 0000000000000000 > 0000000000000000 > SystemMem 0000008080000000-00000083FFFFFFFF 800000000000000E > 0000000000000000 > NonExist 0000008400000000-0000FFFFFFFFFFFF 0000000000000000 > 0000000000000000 >=20 >=20 > Step3: Remove the memory space , As we can see that entry 'SystemMem > 0000008080000000-00000083FFFFFFFF' is removed. > Status =3D gDS->RemoveMemorySpace ( > FixedPcdGet64(PcdSystemMemoryExBase), > SystemMemoryExSize > ); >=20 > Logs: >=20 > GCD:RemoveMemorySpace(Base=3D0000008080000000,Length=3D00000003800000 > 00) > Status =3D Success > GCDMemType Range Capabilities Attributes > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > NonExist 0000000000000000-000000009FFFFFFF 0000000000000000 > 0000000000000000 > SystemMem 00000000A0000000-00000000DFFFFFFF 800000000000000E > 0000000000000008* > NonExist 00000000E0000000-00000000E01BFFFF 0000000000000000 > 0000000000000000 > SystemMem 00000000E01C0000-00000000FFFFFFFF 800000000000000E > 0000000000000008* > NonExist 0000000100000000-0000FFFFFFFFFFFF 0000000000000000 > 0000000000000000 >=20 > Step4 : Run the 'memmap' command. As we can see that entry is still prese= nt. > Shell> memmap > Type Start End # Pages Attributes > Available 00000000A0000000-00000000DFFFFFFF 0000000000040000 > 000000000000000E Available 00000000E01C0000-00000000E53C0FFF > 0000000000005201 000000000000000E > BS_Data 00000000E53C1000-00000000E5D99FFF 00000000000009D9 > 000000000000000E > ... > Available 0000008080000000-00000083FFFFFFFF 0000000000380000 > 000000000000000E > ... > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://emea01.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Flist= s.01 > .org%2Fmailman%2Flistinfo%2Fedk2- > devel&data=3D02%7C01%7Cwasim.khan%40nxp.com%7C2be1d44f45084e831b92 > 08d5542c1b7f%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C636507 > 470804351379&sdata=3DB4v0K9MGZEWiSNYinRtWPGB%2F85biiU5iqpHmAE3YxsQ > %3D&reserved=3D0