From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3047221F833D7 for ; Sun, 7 Jan 2018 17:01:56 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jan 2018 17:07:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,328,1511856000"; d="scan'208";a="22174925" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga001.jf.intel.com with ESMTP; 07 Jan 2018 17:07:04 -0800 Received: from FMSMSX110.amr.corp.intel.com (10.18.116.10) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sun, 7 Jan 2018 17:07:04 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx110.amr.corp.intel.com (10.18.116.10) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sun, 7 Jan 2018 17:07:03 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.189]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.213]) with mapi id 14.03.0319.002; Mon, 8 Jan 2018 09:07:02 +0800 From: "Zeng, Star" To: Wasim Khan , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zeng, Star" Thread-Topic: Memory space entry is not removed after calling FreeMemorySpace and RemoveMemorySpace Thread-Index: AdOGC9ELVQ4yvX0oRxySz+o11ogX7AAB/zdQAHS4DAAADWQ3gA== Date: Mon, 8 Jan 2018 01:07:02 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103B9F8CA8@shsmsx102.ccr.corp.intel.com> References: <0C09AFA07DD0434D9E2A0C6AEB0483103B9F8894@shsmsx102.ccr.corp.intel.com> In-Reply-To: Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 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: Mon, 08 Jan 2018 01:01:56 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Wasim, Got the point. Yes, gDS->AddMemorySpace should return success normally, you may can assume= it. Or a little tricky method if you only want the memory space to be used by O= S kernel, but not post, I think you may can hook the gBS->GetMemoryMap() wi= th your own GetMemoryMap() function, it will call original GetMemoryMap() f= unction, and then append one entry for the memory space you want to add for= OS kernel. Thanks, Star -----Original Message----- From: Wasim Khan [mailto:wasim.khan@nxp.com]=20 Sent: Monday, January 8, 2018 3:03 AM To: Zeng, Star ; edk2-devel@lists.01.org Cc: Gao, Liming Subject: RE: Memory space entry is not removed after calling FreeMemorySpac= e and RemoveMemorySpace 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=20 > > Subject: RE: Memory space entry is not removed after calling=20 > FreeMemorySpace and RemoveMemorySpace >=20 > PI spec has clear description below in AddMemorySpace(). >=20 > "If the memory range specified by BaseAddress and Length is of type=20 > EfiGcdMemoryTypeSystemMemory or EfiGcdMemoryTypeMoreReliable, then the=20 > memory range may be *automatically allocated for use by the UEFI=20 > memory services*." >=20 > But PI spec has no clear description about removing the use from the=20 > UEFI memory services in FreeMemorySpace() and RemoveMemorySpace(). > I think it is very hard (may be not possible) as the added memory=20 > space may have been used by UEFI memory (page) services for drivers=20 > after the memory space is added by AddMemorySpace(). >=20 > What is the usage that the memory space needs to be added first and=20 > removed later? > Could the memory space be added as EfiGcdMemoryTypeReserved type=20 > instead of EfiGcdMemoryTypeSystemMemory type? >=20 >=20 > Thanks, > Star > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of=20 > 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=20 > 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=20 > GcdMemorySpaceMap , but when I run 'memmap' command which gets the=20 > memory map using 'gBS->GetMemoryMap', I can see that entry for the=20 > added memory space is still present. Steps and Logs are below for=20 > reference >=20 > Do I need to perform any other steps in order to cleanly remove the=20 > memory 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=20 > memory 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=20 > =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=20 > =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=20 > =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=20 > 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=20 > =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=20 > 000000000000000E Available 00000000E01C0000-00000000E53C0FFF > 0000000000005201 000000000000000E > BS_Data 00000000E53C1000-00000000E5D99FFF 00000000000009D9 > 000000000000000E > ... > Available 0000008080000000-00000083FFFFFFFF 0000000000380000=20 > 000000000000000E > ... > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://emea01.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Flis > ts.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