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.20; helo=mga02.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 0DB4622280C3E for ; Mon, 8 Jan 2018 05:40:38 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Jan 2018 05:45:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,330,1511856000"; d="scan'208";a="191381323" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga005.jf.intel.com with ESMTP; 08 Jan 2018 05:45:46 -0800 Received: from fmsmsx114.amr.corp.intel.com (10.18.116.8) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 8 Jan 2018 05:45:46 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX114.amr.corp.intel.com (10.18.116.8) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 8 Jan 2018 05:45:45 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.189]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.218]) with mapi id 14.03.0319.002; Mon, 8 Jan 2018 21:45:44 +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/zdQAHS4DAAADWQ3gAAYAkIwAAJA2jA= Date: Mon, 8 Jan 2018 13:45:43 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103B9F9191@shsmsx102.ccr.corp.intel.com> References: <0C09AFA07DD0434D9E2A0C6AEB0483103B9F8894@shsmsx102.ccr.corp.intel.com> <0C09AFA07DD0434D9E2A0C6AEB0483103B9F8CA8@shsmsx102.ccr.corp.intel.com> In-Reply-To: Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYTU1MDlkMzMtNjExMy00NzUzLTg2NDItMTQ0YTgwZTQ1YjNhIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjIuNS4xOCIsIlRydXN0ZWRMYWJlbEhhc2giOiJKXC85b3pqZ3d5cVd3cjZQY2tjbzBvTHFucTZveUNQRVFKeHdPUEtxSjNxMkJzMWFzZlBHMHZtZ0tzTU9Za05zUyJ9 dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action 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 13:40:38 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable There are two cases here. Case 1: 1. gDS->AddMemorySpace The memory range is automatically allocated for use by the UEFI memory s= ervices. 2. No any driver allocates memory at this memory range by gBS->AllocatePage= s()/AllocatePool(). 3. gDS->FreeMemorySpace 4. gDS->RemoveMemorySpace Case 2: 1. gDS->AddMemorySpace The memory range is automatically allocated for use by the UEFI memory s= ervices. 2. There are driver(s) allocate memory at this memory range by gBS->Allocat= ePages()/AllocatePool. 3. gDS->FreeMemorySpace 4. gDS->RemoveMemorySpace For case 1, the memory range could be removed safely from UEFI memory map a= t step 3, and step 3 and 4 could return success. For case 2, the memory range could be not removed from UEFI memory map at s= tep3 as the memory range is still been used by drivers, then step 3 and 4 s= hould return failure. Thanks, Star -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Wasi= m Khan Sent: Monday, January 8, 2018 8:48 PM To: Zeng, Star ; edk2-devel@lists.01.org Cc: Gao, Liming Subject: Re: [edk2] Memory space entry is not removed after calling FreeMem= orySpace and RemoveMemorySpace Hi Star, I agree with you that 'gDS->AddMemorySpace' should always pass, but if thes= e functions are made to return the Status, we should ideally check the Stat= us and take necessary actions upon failure. After going through the code, if a memory space for EfiGcdMemoryTypeSystemM= emory (or EfiGcdMemoryTypeMoreReliable) is added then memory range is auto= matically allocated for use by the UEFI memory services by adding a memory = descriptor to gMemoryMap . But when we call 'gDS->FreeMemorySpace' and ''gDS->RemoveMemorySpace' , mem= ory space is only removed from GCD map and it is not removed from UEFI Serv= ices map. So ideally while when a call to gDS->AddMemorySpace (for memory type EfiGcd= MemoryTypeSystemMemory) automatically allocates it for use by UEFI memory s= ervices. It should also free the memory when 'gDS->FreeMemorySpace' call is= made. I have opened a ticket for this issue (https://bugzilla.tianocore.org/show_= bug.cgi?id=3D841) . Regards, Wasim > -----Original Message----- > From: Zeng, Star [mailto:star.zeng@intel.com] > Sent: Monday, January 08, 2018 6:37 AM > To: Wasim Khan ; edk2-devel@lists.01.org > Cc: Gao, Liming ; Zeng, Star=20 > > Subject: RE: Memory space entry is not removed after calling=20 > FreeMemorySpace and RemoveMemorySpace >=20 > Hi Wasim, >=20 > Got the point. >=20 > Yes, gDS->AddMemorySpace should return success normally, you may can=20 > assume it. > Or a little tricky method if you only want the memory space to be used=20 > by OS kernel, but not post, I think you may can hook the=20 > gBS->GetMemoryMap() with your own GetMemoryMap() function, it will=20 > call original GetMemoryMap() function, and then append one entry for=20 > the memory space you want to add for OS kernel. >=20 >=20 >=20 > Thanks, > Star > -----Original Message----- > From: Wasim Khan [mailto:wasim.khan@nxp.com] > 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=20 > FreeMemorySpace and RemoveMemorySpace >=20 > Hi Star, >=20 > Thank you for your reply. >=20 > I cannot add memory space as EfiGcdMemoryTypeReserved because for my=20 > use case, i am exposing memory space of an extended DDR memory to=20 > kernel. If I add this memory space as EfiGcdMemoryTypeReserved, then=20 > linux is not able to allocate memory from this region to applications=20 > (a simple application requesting memory from this region fails). So I=20 > have to add the memory space as EfiGcdMemoryTypeSystemMemory only. >=20 > > What is the usage that the memory space needs to be added first and=20 > > removed > later? > No specific use case, I am checking the status of=20 > 'gDS->AddMemorySpace' and 'gDS->SetMemorySpaceAttributes', if any of=20 > these calls fails, I want to remove the added memory space. Ideally it sh= ould work. >=20 >=20 >=20 > Regards, > Wasim >=20 >=20 >=20 > > -----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 > > > > PI spec has clear description below in AddMemorySpace(). > > > > "If the memory range specified by BaseAddress and Length is of type=20 > > EfiGcdMemoryTypeSystemMemory or EfiGcdMemoryTypeMoreReliable, then > the > > memory range may be *automatically allocated for use by the UEFI=20 > > memory services*." > > > > 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(). > > > > 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? > > > > > > Thanks, > > Star > > -----Original Message----- > > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf=20 > > 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=20 > > FreeMemorySpace and RemoveMemorySpace > > > > Hi All, > > > > 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=20 > > by > 'memmap' > > command. > > > > 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 > > > > Do I need to perform any other steps in order to cleanly remove the=20 > > memory space entry ? > > > > Regards, > > Wasim > > > > > > > > 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. > > > > Status =3D gDS->AddMemorySpace ( > > EfiGcdMemoryTypeSystemMemor= y, > > FixedPcdGet64(PcdSystemMemo= ryExBase), > > SystemMemoryExSize, > > EFI_MEMORY_WC | EFI_MEMORY_= WT | > > EFI_MEMORY_WB > > ); > > > > Logs: > > > > > GCD:AddMemorySpace(Base=3D0000008080000000,Length=3D0000000380000000) > > GcdMemoryType =3D SystemMem > > Capabilities =3D 000000000000000E > > CoreConvertSpace 774 > > Status =3D Success > > GCDMemType Range Capabilities Attribute= s > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=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 > > > > > 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 Attribute= s > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=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 > > > > > > Step2: Free the memory space > > Status =3D gDS->FreeMemorySpace ( > > FixedPcdGet64(PcdSystemMemoryExBase), > > SystemMemoryExSize > > ); > > > > Logs: > > > > > GCD:FreeMemorySpace(Base=3D0000008080000000,Length=3D0000000380000000) > > Status =3D Success > > GCDMemType Range Capabilities Attribute= s > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=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 > > > > > > Step3: Remove the memory space , As we can see that entry 'SystemMem=20 > > 0000008080000000-00000083FFFFFFFF' is removed. > > Status =3D gDS->RemoveMemorySpace ( > > FixedPcdGet64(PcdSystemMemoryExBase), > > SystemMemoryExSize > > ); > > > > Logs: > > > > > GCD:RemoveMemorySpace(Base=3D0000008080000000,Length=3D00000003800000 > > 00) > > Status =3D Success > > GCDMemType Range Capabilities Attribute= s > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=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 > > > > Step4 : Run the 'memmap' command. As we can see that entry is still pre= sent. > > Shell> memmap > > Type Start End # Pages Attribute= s > > 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%2Fl > > is > > 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 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel