* [PATCH] RFC Inform UEFI memory to Linux @ 2017-09-15 14:32 Meenakshi Aggarwal 2017-09-15 10:13 ` Leif Lindholm 2017-09-19 12:32 ` [PATCH v2] PeiLib : " Meenakshi Aggarwal 0 siblings, 2 replies; 19+ messages in thread From: Meenakshi Aggarwal @ 2017-09-15 14:32 UTC (permalink / raw) To: edk2-devel, leif.lindholm, ard.biesheuvel From: Udit Kumar <udit.kumar@nxp.com> While creating Hob list, ArmPlatformPkg is hiding UEFI memory. whereas this memory can be used by OS. This patch, allows OS to use UEFI code area. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> Signed-off-by: Udit Kumar <udit.kumar@nxp.com> --- ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c index 2feb11f..ae6ebc4 100644 --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c @@ -147,24 +147,24 @@ MemoryPeim ( if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) { if (SystemMemoryTop == FdTop) { NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; - } else { - // Create the System Memory HOB for the firmware with the non-present attribute - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, - PcdGet64 (PcdFdBaseAddress), - PcdGet32 (PcdFdSize)); - + } else { + // Create the System Memory HOB for the firmware with the non-present attribute + BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, + ResourceAttributes, + PcdGet64 (PcdFdBaseAddress), + PcdGet32 (PcdFdSize)); + // Top of the FD is system memory available for UEFI NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize); } - } else { - // Create the System Memory HOB for the firmware with the non-present attribute - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, - PcdGet64 (PcdFdBaseAddress), - PcdGet32 (PcdFdSize)); - + } else { + // Create the System Memory HOB for the firmware with the non-present attribute + BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, + ResourceAttributes, + PcdGet64 (PcdFdBaseAddress), + PcdGet32 (PcdFdSize)); + // Update the HOB NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; -- 1.9.1 ^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH] RFC Inform UEFI memory to Linux 2017-09-15 14:32 [PATCH] RFC Inform UEFI memory to Linux Meenakshi Aggarwal @ 2017-09-15 10:13 ` Leif Lindholm 2017-09-15 22:55 ` Ard Biesheuvel 2017-09-19 12:32 ` [PATCH v2] PeiLib : " Meenakshi Aggarwal 1 sibling, 1 reply; 19+ messages in thread From: Leif Lindholm @ 2017-09-15 10:13 UTC (permalink / raw) To: Meenakshi Aggarwal; +Cc: edk2-devel, ard.biesheuvel, udit.kumar On Fri, Sep 15, 2017 at 08:02:34PM +0530, Meenakshi Aggarwal wrote: > From: Udit Kumar <udit.kumar@nxp.com> > > While creating Hob list, ArmPlatformPkg is hiding UEFI memory. > whereas this memory can be used by OS. > > This patch, allows OS to use UEFI code area. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> > Signed-off-by: Udit Kumar <udit.kumar@nxp.com> I will let Ard comment on the technical aspect, since you've been discussing this offline. However, there is something broken in your setup: the patch should look like this: --- iff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c index 2feb11f21d..d3fa894244 100644 --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c @@ -150,7 +150,7 @@ MemoryPeim ( } else { // Create the System Memory HOB for the // firmware with the non-present attribute BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, + ResourceAttributes, PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize)); @@ -161,7 +161,7 @@ MemoryPeim ( } else { // Create the System Memory HOB for the firmware // with the non-present attribute BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, + ResourceAttributes, PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize)); --- I am guessing you have inadvertently modified the line terminations from CRLF to LF (the evidence gets stripped out by SMTP). Please resubmit with this addressed. / Leif > --- > ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 28 ++++++++++++------------- > 1 file changed, 14 insertions(+), 14 deletions(-) > > diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > index 2feb11f..ae6ebc4 100644 > --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > @@ -147,24 +147,24 @@ MemoryPeim ( > if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) { > if (SystemMemoryTop == FdTop) { > NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; > - } else { > - // Create the System Memory HOB for the firmware with the non-present attribute > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > - PcdGet64 (PcdFdBaseAddress), > - PcdGet32 (PcdFdSize)); > - > + } else { > + // Create the System Memory HOB for the firmware with the non-present attribute > + BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > + ResourceAttributes, > + PcdGet64 (PcdFdBaseAddress), > + PcdGet32 (PcdFdSize)); > + > // Top of the FD is system memory available for UEFI > NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); > NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize); > } > - } else { > - // Create the System Memory HOB for the firmware with the non-present attribute > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > - PcdGet64 (PcdFdBaseAddress), > - PcdGet32 (PcdFdSize)); > - > + } else { > + // Create the System Memory HOB for the firmware with the non-present attribute > + BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > + ResourceAttributes, > + PcdGet64 (PcdFdBaseAddress), > + PcdGet32 (PcdFdSize)); > + > // Update the HOB > NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; > > -- > 1.9.1 > ^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH] RFC Inform UEFI memory to Linux 2017-09-15 10:13 ` Leif Lindholm @ 2017-09-15 22:55 ` Ard Biesheuvel 2017-09-18 4:07 ` Udit Kumar 0 siblings, 1 reply; 19+ messages in thread From: Ard Biesheuvel @ 2017-09-15 22:55 UTC (permalink / raw) To: Leif Lindholm; +Cc: Meenakshi Aggarwal, edk2-devel@lists.01.org, Udit Kumar On 15 September 2017 at 03:13, Leif Lindholm <leif.lindholm@linaro.org> wrote: > On Fri, Sep 15, 2017 at 08:02:34PM +0530, Meenakshi Aggarwal wrote: >> From: Udit Kumar <udit.kumar@nxp.com> >> >> While creating Hob list, ArmPlatformPkg is hiding UEFI memory. >> whereas this memory can be used by OS. >> >> This patch, allows OS to use UEFI code area. >> >> Contributed-under: TianoCore Contribution Agreement 1.1 >> Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> >> Signed-off-by: Udit Kumar <udit.kumar@nxp.com> > > I will let Ard comment on the technical aspect, since you've been > discussing this offline. > > However, there is something broken in your setup: the patch should > look like this: > --- > iff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > index 2feb11f21d..d3fa894244 100644 > --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > @@ -150,7 +150,7 @@ MemoryPeim ( > } else { > // Create the System Memory HOB for the > // firmware with the non-present attribute > BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > + ResourceAttributes, > PcdGet64 (PcdFdBaseAddress), > PcdGet32 (PcdFdSize)); > > @@ -161,7 +161,7 @@ MemoryPeim ( > } else { > // Create the System Memory HOB for the firmware > // with the non-present attribute > BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > + ResourceAttributes, > PcdGet64 (PcdFdBaseAddress), > PcdGet32 (PcdFdSize)); > > --- > > I am guessing you have inadvertently modified the line terminations > from CRLF to LF (the evidence gets stripped out by SMTP). > Please resubmit with this addressed. > Thanks for the patch. But please consider carefully what you're doing: in the original code, the entire DRAM region is added, and subsequently split up so the part that overlaps with the FD can be registered with different attributes. After your patch, we carefully isolate the region that overlaps the FD, and subsequently register it with the exact same attributes, which means we didn't have to isolate it in the first place. My point is really that you can just remove lines 124 - 189 instead. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] RFC Inform UEFI memory to Linux 2017-09-15 22:55 ` Ard Biesheuvel @ 2017-09-18 4:07 ` Udit Kumar 2017-09-18 4:30 ` Ard Biesheuvel 0 siblings, 1 reply; 19+ messages in thread From: Udit Kumar @ 2017-09-18 4:07 UTC (permalink / raw) To: Ard Biesheuvel, Leif Lindholm; +Cc: Meenakshi Aggarwal, edk2-devel@lists.01.org Hi Ard, > Thanks for the patch. But please consider carefully what you're doing: > My point is really that you can just remove lines 124 - 189 instead. We want, OS to re-use firmware volume area. Therefore making firmware volume visible. You are right, removing lines 124-189 will do the same, and no need of adding splitting area with same attribute. Also, I am not sure, if we can remove this entirely, therefore we posted this as RFC:) Code comments says // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE // core to overwrite this area we must mark the region with the attribute non-present On our architecture, we start boot from DRAM. And we haven't seen any overwrite by DXE. This work perfectly well for us. Do you think, on other platforms it may add a risk of overwrite ? Regards Udit > -----Original Message----- > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] > Sent: Saturday, September 16, 2017 4:25 AM > To: Leif Lindholm <leif.lindholm@linaro.org> > Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; edk2- > devel@lists.01.org; Udit Kumar <udit.kumar@nxp.com> > Subject: Re: [PATCH] RFC Inform UEFI memory to Linux > > On 15 September 2017 at 03:13, Leif Lindholm <leif.lindholm@linaro.org> > wrote: > > On Fri, Sep 15, 2017 at 08:02:34PM +0530, Meenakshi Aggarwal wrote: > >> From: Udit Kumar <udit.kumar@nxp.com> > >> > >> While creating Hob list, ArmPlatformPkg is hiding UEFI memory. > >> whereas this memory can be used by OS. > >> > >> This patch, allows OS to use UEFI code area. > >> > >> Contributed-under: TianoCore Contribution Agreement 1.1 > >> Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> > >> Signed-off-by: Udit Kumar <udit.kumar@nxp.com> > > > > I will let Ard comment on the technical aspect, since you've been > > discussing this offline. > > > > However, there is something broken in your setup: the patch should > > look like this: > > --- > > iff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > > b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > > index 2feb11f21d..d3fa894244 100644 > > --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > > +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > > @@ -150,7 +150,7 @@ MemoryPeim ( > > } else { > > // Create the System Memory HOB for the > > // firmware with the non-present attribute > > BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > > - ResourceAttributes & > ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > > + ResourceAttributes, > > PcdGet64 (PcdFdBaseAddress), > > PcdGet32 (PcdFdSize)); > > > > @@ -161,7 +161,7 @@ MemoryPeim ( > > } else { > > // Create the System Memory HOB for the firmware > > // with the non-present attribute > > BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > > - ResourceAttributes & > ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > > + ResourceAttributes, > > PcdGet64 (PcdFdBaseAddress), > > PcdGet32 (PcdFdSize)); > > > > --- > > > > I am guessing you have inadvertently modified the line terminations > > from CRLF to LF (the evidence gets stripped out by SMTP). > > Please resubmit with this addressed. > > > > Thanks for the patch. But please consider carefully what you're doing: > in the original code, the entire DRAM region is added, and subsequently split up > so the part that overlaps with the FD can be registered with different attributes. > > After your patch, we carefully isolate the region that overlaps the FD, and > subsequently register it with the exact same attributes, which means we didn't > have to isolate it in the first place. > > My point is really that you can just remove lines 124 - 189 instead. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] RFC Inform UEFI memory to Linux 2017-09-18 4:07 ` Udit Kumar @ 2017-09-18 4:30 ` Ard Biesheuvel 0 siblings, 0 replies; 19+ messages in thread From: Ard Biesheuvel @ 2017-09-18 4:30 UTC (permalink / raw) To: Udit Kumar; +Cc: Leif Lindholm, edk2-devel@lists.01.org On 17 September 2017 at 21:07, Udit Kumar <udit.kumar@nxp.com> wrote: > Hi Ard, > >> Thanks for the patch. But please consider carefully what you're doing: >> My point is really that you can just remove lines 124 - 189 instead. > > We want, OS to re-use firmware volume area. Therefore making firmware volume visible. > You are right, removing lines 124-189 will do the same, and no need of adding splitting area with same > attribute. > > Also, I am not sure, if we can remove this entirely, therefore we posted this as RFC:) > Code comments says > > // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE > // core to overwrite this area we must mark the region with the attribute non-present > > On our architecture, we start boot from DRAM. And we haven't seen any overwrite > by DXE. This work perfectly well for us. > > Do you think, on other platforms it may add a risk of overwrite ? > We wondered about that as well. As far as I can tell, a compressed FV will be decompressed completely into a memory region that is reserved for it before the DXE core is invoked. This means the outer, uncompressed FV could technically be overwritten, but in practice, we never refer back to it in a PrePi build, and we should probably not even build the FV hob for this volume if we can avoid it. ^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v2] PeiLib : Inform UEFI memory to Linux 2017-09-15 14:32 [PATCH] RFC Inform UEFI memory to Linux Meenakshi Aggarwal 2017-09-15 10:13 ` Leif Lindholm @ 2017-09-19 12:32 ` Meenakshi Aggarwal 2017-09-19 8:07 ` Sakar Arora 2017-09-20 14:59 ` Gao, Liming 1 sibling, 2 replies; 19+ messages in thread From: Meenakshi Aggarwal @ 2017-09-19 12:32 UTC (permalink / raw) To: edk2-devel, leif.lindholm, ard.biesheuvel While creating Hob list, ArmPlatformPkg is hiding UEFI memory. whereas this memory can be used by OS. This patch, allows OS to use UEFI code area. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Udit Kumar <udit.kumar@nxp.com> Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> --- ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 69 ------------------------- 1 file changed, 69 deletions(-) diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c index 2feb11f..d03214b 100644 --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c @@ -70,11 +70,7 @@ MemoryPeim ( { ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; - UINT64 ResourceLength; EFI_PEI_HOB_POINTERS NextHob; - EFI_PHYSICAL_ADDRESS FdTop; - EFI_PHYSICAL_ADDRESS SystemMemoryTop; - EFI_PHYSICAL_ADDRESS ResourceTop; BOOLEAN Found; // Get Virtual Memory Map from the Platform Library @@ -121,71 +117,6 @@ MemoryPeim ( ); } - // - // Reserved the memory space occupied by the firmware volume - // - - SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemorySize); - FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); - - // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE - // core to overwrite this area we must mark the region with the attribute non-present - if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) { - Found = FALSE; - - // Search for System Memory Hob that contains the firmware - NextHob.Raw = GetHobList (); - while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { - if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) && - (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor->PhysicalStart) && - (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength)) - { - ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute; - ResourceLength = NextHob.ResourceDescriptor->ResourceLength; - ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength; - - if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) { - if (SystemMemoryTop == FdTop) { - NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; - } else { - // Create the System Memory HOB for the firmware with the non-present attribute - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, - PcdGet64 (PcdFdBaseAddress), - PcdGet32 (PcdFdSize)); - - // Top of the FD is system memory available for UEFI - NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); - NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize); - } - } else { - // Create the System Memory HOB for the firmware with the non-present attribute - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, - PcdGet64 (PcdFdBaseAddress), - PcdGet32 (PcdFdSize)); - - // Update the HOB - NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; - - // If there is some memory available on the top of the FD then create a HOB - if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) { - // Create the System Memory HOB for the remaining region (top of the FD) - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, - ResourceAttributes, - FdTop, - ResourceTop - FdTop); - } - } - Found = TRUE; - break; - } - NextHob.Raw = GET_NEXT_HOB (NextHob); - } - - ASSERT(Found); - } - // Build Memory Allocation Hob InitMmu (MemoryTable); -- 1.9.1 ^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH v2] PeiLib : Inform UEFI memory to Linux 2017-09-19 12:32 ` [PATCH v2] PeiLib : " Meenakshi Aggarwal @ 2017-09-19 8:07 ` Sakar Arora 2017-09-19 10:10 ` Udit Kumar 2017-09-19 12:48 ` Ard Biesheuvel 2017-09-20 14:59 ` Gao, Liming 1 sibling, 2 replies; 19+ messages in thread From: Sakar Arora @ 2017-09-19 8:07 UTC (permalink / raw) To: Meenakshi Aggarwal, edk2-devel@lists.01.org, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org This change will create the possibility for memory space holding the UEFI image to be over-written by the DXE core code, since this space will then be available for allocation. Any such change, if required, should be done just before booting the OS. -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Meenakshi Aggarwal Sent: Tuesday, September 19, 2017 6:02 PM To: edk2-devel@lists.01.org; leif.lindholm@linaro.org; ard.biesheuvel@linaro.org Subject: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux While creating Hob list, ArmPlatformPkg is hiding UEFI memory. whereas this memory can be used by OS. This patch, allows OS to use UEFI code area. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Udit Kumar <udit.kumar@nxp.com> Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> --- ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 69 ------------------------- 1 file changed, 69 deletions(-) diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c index 2feb11f..d03214b 100644 --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c @@ -70,11 +70,7 @@ MemoryPeim ( { ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; - UINT64 ResourceLength; EFI_PEI_HOB_POINTERS NextHob; - EFI_PHYSICAL_ADDRESS FdTop; - EFI_PHYSICAL_ADDRESS SystemMemoryTop; - EFI_PHYSICAL_ADDRESS ResourceTop; BOOLEAN Found; // Get Virtual Memory Map from the Platform Library @@ -121,71 +117,6 @@ MemoryPeim ( ); } - // - // Reserved the memory space occupied by the firmware volume - // - - SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemorySize); - FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); - - // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE - // core to overwrite this area we must mark the region with the attribute non-present - if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) { - Found = FALSE; - - // Search for System Memory Hob that contains the firmware - NextHob.Raw = GetHobList (); - while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { - if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) && - (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor->PhysicalStart) && - (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength)) - { - ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute; - ResourceLength = NextHob.ResourceDescriptor->ResourceLength; - ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength; - - if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) { - if (SystemMemoryTop == FdTop) { - NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; - } else { - // Create the System Memory HOB for the firmware with the non-present attribute - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, - PcdGet64 (PcdFdBaseAddress), - PcdGet32 (PcdFdSize)); - - // Top of the FD is system memory available for UEFI - NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); - NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize); - } - } else { - // Create the System Memory HOB for the firmware with the non-present attribute - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, - PcdGet64 (PcdFdBaseAddress), - PcdGet32 (PcdFdSize)); - - // Update the HOB - NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; - - // If there is some memory available on the top of the FD then create a HOB - if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) { - // Create the System Memory HOB for the remaining region (top of the FD) - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, - ResourceAttributes, - FdTop, - ResourceTop - FdTop); - } - } - Found = TRUE; - break; - } - NextHob.Raw = GET_NEXT_HOB (NextHob); - } - - ASSERT(Found); - } - // Build Memory Allocation Hob InitMmu (MemoryTable); -- 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please 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. ^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH v2] PeiLib : Inform UEFI memory to Linux 2017-09-19 8:07 ` Sakar Arora @ 2017-09-19 10:10 ` Udit Kumar 2017-09-19 11:20 ` Sakar Arora 2017-09-19 12:48 ` Ard Biesheuvel 1 sibling, 1 reply; 19+ messages in thread From: Udit Kumar @ 2017-09-19 10:10 UTC (permalink / raw) To: Sakar Arora, Meenakshi Aggarwal, edk2-devel@lists.01.org, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org Thanks Sakar, I am wondering, how we can add this memory before OS, please suggest. I guess, we cannot add in HobList when we are in DXE or BDS. Regards Udit > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Sakar > Arora > Sent: Tuesday, September 19, 2017 1:37 PM > To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; edk2- > devel@lists.01.org; leif.lindholm@linaro.org; ard.biesheuvel@linaro.org > Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > This change will create the possibility for memory space holding the UEFI image > to be over-written by the DXE core code, since this space will then be available > for allocation. Any such change, if required, should be done just before booting > the OS. > > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Meenakshi Aggarwal > Sent: Tuesday, September 19, 2017 6:02 PM > To: edk2-devel@lists.01.org; leif.lindholm@linaro.org; > ard.biesheuvel@linaro.org > Subject: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > While creating Hob list, ArmPlatformPkg is hiding UEFI memory. > whereas this memory can be used by OS. > > This patch, allows OS to use UEFI code area. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Udit Kumar <udit.kumar@nxp.com> > Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> > --- > ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 69 ------------------------- > 1 file changed, 69 deletions(-) > > diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > index 2feb11f..d03214b 100644 > --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > @@ -70,11 +70,7 @@ MemoryPeim ( > { > ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; > EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; > - UINT64 ResourceLength; > EFI_PEI_HOB_POINTERS NextHob; > - EFI_PHYSICAL_ADDRESS FdTop; > - EFI_PHYSICAL_ADDRESS SystemMemoryTop; > - EFI_PHYSICAL_ADDRESS ResourceTop; > BOOLEAN Found; > > // Get Virtual Memory Map from the Platform Library @@ -121,71 +117,6 @@ > MemoryPeim ( > ); > } > > - // > - // Reserved the memory space occupied by the firmware volume > - // > - > - SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 > (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 > (PcdSystemMemorySize); > - FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + > (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); > - > - // EDK2 does not have the concept of boot firmware copied into DRAM. To > avoid the DXE > - // core to overwrite this area we must mark the region with the attribute non- > present > - if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && > (FdTop <= SystemMemoryTop)) { > - Found = FALSE; > - > - // Search for System Memory Hob that contains the firmware > - NextHob.Raw = GetHobList (); > - while ((NextHob.Raw = GetNextHob > (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { > - if ((NextHob.ResourceDescriptor->ResourceType == > EFI_RESOURCE_SYSTEM_MEMORY) && > - (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor- > >PhysicalStart) && > - (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + > NextHob.ResourceDescriptor->ResourceLength)) > - { > - ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute; > - ResourceLength = NextHob.ResourceDescriptor->ResourceLength; > - ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + > ResourceLength; > - > - if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor- > >PhysicalStart) { > - if (SystemMemoryTop == FdTop) { > - NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes > & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; > - } else { > - // Create the System Memory HOB for the firmware with the non- > present attribute > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes & > ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > - PcdGet64 (PcdFdBaseAddress), > - PcdGet32 (PcdFdSize)); > - > - // Top of the FD is system memory available for UEFI > - NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); > - NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize); > - } > - } else { > - // Create the System Memory HOB for the firmware with the non-present > attribute > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes & > ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > - PcdGet64 (PcdFdBaseAddress), > - PcdGet32 (PcdFdSize)); > - > - // Update the HOB > - NextHob.ResourceDescriptor->ResourceLength = PcdGet64 > (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; > - > - // If there is some memory available on the top of the FD then create a > HOB > - if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + > ResourceLength) { > - // Create the System Memory HOB for the remaining region (top of the > FD) > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes, > - FdTop, > - ResourceTop - FdTop); > - } > - } > - Found = TRUE; > - break; > - } > - NextHob.Raw = GET_NEXT_HOB (NextHob); > - } > - > - ASSERT(Found); > - } > - > // Build Memory Allocation Hob > InitMmu (MemoryTable); > > -- > 1.9.1 > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel > IMPORTANT NOTICE: The contents of this email and any attachments are > confidential and may also be privileged. If you are not the intended recipient, > please 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. > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2] PeiLib : Inform UEFI memory to Linux 2017-09-19 10:10 ` Udit Kumar @ 2017-09-19 11:20 ` Sakar Arora 2017-09-19 12:46 ` Udit Kumar 0 siblings, 1 reply; 19+ messages in thread From: Sakar Arora @ 2017-09-19 11:20 UTC (permalink / raw) To: Udit Kumar, Meenakshi Aggarwal, edk2-devel@lists.01.org, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org You could use the DXE services method gDS->AddMemorySpace to add this memory space to the global gMemoryMap. This is the memory map linux efi stub reads to get information about all the available system memory. Thanks, Sakar -----Original Message----- From: Udit Kumar [mailto:udit.kumar@nxp.com] Sent: Tuesday, September 19, 2017 3:41 PM To: Sakar Arora <Sakar.Arora@arm.com>; Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; edk2-devel@lists.01.org; leif.lindholm@linaro.org; ard.biesheuvel@linaro.org Subject: RE: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux Thanks Sakar, I am wondering, how we can add this memory before OS, please suggest. I guess, we cannot add in HobList when we are in DXE or BDS. Regards Udit > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Sakar Arora > Sent: Tuesday, September 19, 2017 1:37 PM > To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; edk2- > devel@lists.01.org; leif.lindholm@linaro.org; > ard.biesheuvel@linaro.org > Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > This change will create the possibility for memory space holding the > UEFI image to be over-written by the DXE core code, since this space > will then be available for allocation. Any such change, if required, > should be done just before booting the OS. > > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Meenakshi Aggarwal > Sent: Tuesday, September 19, 2017 6:02 PM > To: edk2-devel@lists.01.org; leif.lindholm@linaro.org; > ard.biesheuvel@linaro.org > Subject: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > While creating Hob list, ArmPlatformPkg is hiding UEFI memory. > whereas this memory can be used by OS. > > This patch, allows OS to use UEFI code area. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Udit Kumar <udit.kumar@nxp.com> > Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> > --- > ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 69 > ------------------------- > 1 file changed, 69 deletions(-) > > diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > index 2feb11f..d03214b 100644 > --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > @@ -70,11 +70,7 @@ MemoryPeim ( > { > ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; > EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; > - UINT64 ResourceLength; > EFI_PEI_HOB_POINTERS NextHob; > - EFI_PHYSICAL_ADDRESS FdTop; > - EFI_PHYSICAL_ADDRESS SystemMemoryTop; > - EFI_PHYSICAL_ADDRESS ResourceTop; > BOOLEAN Found; > > // Get Virtual Memory Map from the Platform Library @@ -121,71 > +117,6 @@ MemoryPeim ( > ); > } > > - // > - // Reserved the memory space occupied by the firmware volume > - // > - > - SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 > (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 > (PcdSystemMemorySize); > - FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + > (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); > - > - // EDK2 does not have the concept of boot firmware copied into > DRAM. To avoid the DXE > - // core to overwrite this area we must mark the region with the > attribute non- present > - if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) > && (FdTop <= SystemMemoryTop)) { > - Found = FALSE; > - > - // Search for System Memory Hob that contains the firmware > - NextHob.Raw = GetHobList (); > - while ((NextHob.Raw = GetNextHob > (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { > - if ((NextHob.ResourceDescriptor->ResourceType == > EFI_RESOURCE_SYSTEM_MEMORY) && > - (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor- > >PhysicalStart) && > - (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + > NextHob.ResourceDescriptor->ResourceLength)) > - { > - ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute; > - ResourceLength = NextHob.ResourceDescriptor->ResourceLength; > - ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + > ResourceLength; > - > - if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor- > >PhysicalStart) { > - if (SystemMemoryTop == FdTop) { > - NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes > & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; > - } else { > - // Create the System Memory HOB for the firmware with the non- > present attribute > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes & > ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > - PcdGet64 (PcdFdBaseAddress), > - PcdGet32 (PcdFdSize)); > - > - // Top of the FD is system memory available for UEFI > - NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); > - NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize); > - } > - } else { > - // Create the System Memory HOB for the firmware with the non-present > attribute > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes & > ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > - PcdGet64 (PcdFdBaseAddress), > - PcdGet32 (PcdFdSize)); > - > - // Update the HOB > - NextHob.ResourceDescriptor->ResourceLength = PcdGet64 > (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; > - > - // If there is some memory available on the top of the FD then create a > HOB > - if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + > ResourceLength) { > - // Create the System Memory HOB for the remaining region (top of the > FD) > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes, > - FdTop, > - ResourceTop - FdTop); > - } > - } > - Found = TRUE; > - break; > - } > - NextHob.Raw = GET_NEXT_HOB (NextHob); > - } > - > - ASSERT(Found); > - } > - > // Build Memory Allocation Hob > InitMmu (MemoryTable); > > -- > 1.9.1 > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel > IMPORTANT NOTICE: The contents of this email and any attachments are > confidential and may also be privileged. If you are not the intended > recipient, please 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. > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please 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. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2] PeiLib : Inform UEFI memory to Linux 2017-09-19 11:20 ` Sakar Arora @ 2017-09-19 12:46 ` Udit Kumar 0 siblings, 0 replies; 19+ messages in thread From: Udit Kumar @ 2017-09-19 12:46 UTC (permalink / raw) To: Sakar Arora, Meenakshi Aggarwal, edk2-devel@lists.01.org, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org Thanks for this, If memory is marked as reserved by HobList then gDS->AddMemorySpace will return error 15. No ? Regards Udit > -----Original Message----- > From: Sakar Arora [mailto:Sakar.Arora@arm.com] > Sent: Tuesday, September 19, 2017 4:51 PM > To: Udit Kumar <udit.kumar@nxp.com>; Meenakshi Aggarwal > <meenakshi.aggarwal@nxp.com>; edk2-devel@lists.01.org; > leif.lindholm@linaro.org; ard.biesheuvel@linaro.org > Subject: RE: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > You could use the DXE services method gDS->AddMemorySpace to add this > memory space to the global gMemoryMap. This is the memory map linux efi > stub reads to get information about all the available system memory. > > Thanks, > Sakar > > -----Original Message----- > From: Udit Kumar [mailto:udit.kumar@nxp.com] > Sent: Tuesday, September 19, 2017 3:41 PM > To: Sakar Arora <Sakar.Arora@arm.com>; Meenakshi Aggarwal > <meenakshi.aggarwal@nxp.com>; edk2-devel@lists.01.org; > leif.lindholm@linaro.org; ard.biesheuvel@linaro.org > Subject: RE: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > Thanks Sakar, > I am wondering, how we can add this memory before OS, please suggest. > I guess, we cannot add in HobList when we are in DXE or BDS. > > Regards > Udit > > > -----Original Message----- > > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > > Sakar Arora > > Sent: Tuesday, September 19, 2017 1:37 PM > > To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; edk2- > > devel@lists.01.org; leif.lindholm@linaro.org; > > ard.biesheuvel@linaro.org > > Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > > > This change will create the possibility for memory space holding the > > UEFI image to be over-written by the DXE core code, since this space > > will then be available for allocation. Any such change, if required, > > should be done just before booting the OS. > > > > -----Original Message----- > > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > > Meenakshi Aggarwal > > Sent: Tuesday, September 19, 2017 6:02 PM > > To: edk2-devel@lists.01.org; leif.lindholm@linaro.org; > > ard.biesheuvel@linaro.org > > Subject: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > > > While creating Hob list, ArmPlatformPkg is hiding UEFI memory. > > whereas this memory can be used by OS. > > > > This patch, allows OS to use UEFI code area. > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Udit Kumar <udit.kumar@nxp.com> > > Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> > > --- > > ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 69 > > ------------------------- > > 1 file changed, 69 deletions(-) > > > > diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > > b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > > index 2feb11f..d03214b 100644 > > --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > > +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > > @@ -70,11 +70,7 @@ MemoryPeim ( > > { > > ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; > > EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; > > - UINT64 ResourceLength; > > EFI_PEI_HOB_POINTERS NextHob; > > - EFI_PHYSICAL_ADDRESS FdTop; > > - EFI_PHYSICAL_ADDRESS SystemMemoryTop; > > - EFI_PHYSICAL_ADDRESS ResourceTop; > > BOOLEAN Found; > > > > // Get Virtual Memory Map from the Platform Library @@ -121,71 > > +117,6 @@ MemoryPeim ( > > ); > > } > > > > - // > > - // Reserved the memory space occupied by the firmware volume > > - // > > - > > - SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 > > (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 > > (PcdSystemMemorySize); > > - FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + > > (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); > > - > > - // EDK2 does not have the concept of boot firmware copied into > > DRAM. To avoid the DXE > > - // core to overwrite this area we must mark the region with the > > attribute non- present > > - if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) > > && (FdTop <= SystemMemoryTop)) { > > - Found = FALSE; > > - > > - // Search for System Memory Hob that contains the firmware > > - NextHob.Raw = GetHobList (); > > - while ((NextHob.Raw = GetNextHob > > (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { > > - if ((NextHob.ResourceDescriptor->ResourceType == > > EFI_RESOURCE_SYSTEM_MEMORY) && > > - (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor- > > >PhysicalStart) && > > - (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + > > NextHob.ResourceDescriptor->ResourceLength)) > > - { > > - ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute; > > - ResourceLength = NextHob.ResourceDescriptor->ResourceLength; > > - ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + > > ResourceLength; > > - > > - if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor- > > >PhysicalStart) { > > - if (SystemMemoryTop == FdTop) { > > - NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes > > & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; > > - } else { > > - // Create the System Memory HOB for the firmware with the non- > > present attribute > > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > > - ResourceAttributes & > > ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > > - PcdGet64 (PcdFdBaseAddress), > > - PcdGet32 (PcdFdSize)); > > - > > - // Top of the FD is system memory available for UEFI > > - NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); > > - NextHob.ResourceDescriptor->ResourceLength -= > PcdGet32(PcdFdSize); > > - } > > - } else { > > - // Create the System Memory HOB for the firmware with the non- > present > > attribute > > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > > - ResourceAttributes & > > ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > > - PcdGet64 (PcdFdBaseAddress), > > - PcdGet32 (PcdFdSize)); > > - > > - // Update the HOB > > - NextHob.ResourceDescriptor->ResourceLength = PcdGet64 > > (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; > > - > > - // If there is some memory available on the top of the FD then create a > > HOB > > - if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + > > ResourceLength) { > > - // Create the System Memory HOB for the remaining region (top of the > > FD) > > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > > - ResourceAttributes, > > - FdTop, > > - ResourceTop - FdTop); > > - } > > - } > > - Found = TRUE; > > - break; > > - } > > - NextHob.Raw = GET_NEXT_HOB (NextHob); > > - } > > - > > - ASSERT(Found); > > - } > > - > > // Build Memory Allocation Hob > > InitMmu (MemoryTable); > > > > -- > > 1.9.1 > > > > _______________________________________________ > > edk2-devel mailing list > > edk2-devel@lists.01.org > > https://lists.01.org/mailman/listinfo/edk2-devel > > IMPORTANT NOTICE: The contents of this email and any attachments are > > confidential and may also be privileged. If you are not the intended > > recipient, please 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. > > _______________________________________________ > > edk2-devel mailing list > > edk2-devel@lists.01.org > > https://lists.01.org/mailman/listinfo/edk2-devel > IMPORTANT NOTICE: The contents of this email and any attachments are > confidential and may also be privileged. If you are not the intended recipient, > please 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. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2] PeiLib : Inform UEFI memory to Linux 2017-09-19 8:07 ` Sakar Arora 2017-09-19 10:10 ` Udit Kumar @ 2017-09-19 12:48 ` Ard Biesheuvel 2017-09-20 5:32 ` Sakar Arora 1 sibling, 1 reply; 19+ messages in thread From: Ard Biesheuvel @ 2017-09-19 12:48 UTC (permalink / raw) To: Sakar Arora Cc: Meenakshi Aggarwal, edk2-devel@lists.01.org, leif.lindholm@linaro.org On 19 September 2017 at 01:07, Sakar Arora <Sakar.Arora@arm.com> wrote: > This change will create the possibility for memory space holding the UEFI image to be over-written by the DXE core code, since this space will then be available for allocation. Yes. But why does this matter after the entire payload has been decompressed into memory already? > Any such change, if required, should be done just before booting the OS. > > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Meenakshi Aggarwal > Sent: Tuesday, September 19, 2017 6:02 PM > To: edk2-devel@lists.01.org; leif.lindholm@linaro.org; ard.biesheuvel@linaro.org > Subject: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > While creating Hob list, ArmPlatformPkg is hiding UEFI memory. > whereas this memory can be used by OS. > > This patch, allows OS to use UEFI code area. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Udit Kumar <udit.kumar@nxp.com> > Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> > --- > ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 69 ------------------------- > 1 file changed, 69 deletions(-) > > diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > index 2feb11f..d03214b 100644 > --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > @@ -70,11 +70,7 @@ MemoryPeim ( > { > ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; > EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; > - UINT64 ResourceLength; > EFI_PEI_HOB_POINTERS NextHob; > - EFI_PHYSICAL_ADDRESS FdTop; > - EFI_PHYSICAL_ADDRESS SystemMemoryTop; > - EFI_PHYSICAL_ADDRESS ResourceTop; > BOOLEAN Found; > > // Get Virtual Memory Map from the Platform Library @@ -121,71 +117,6 @@ MemoryPeim ( > ); > } > > - // > - // Reserved the memory space occupied by the firmware volume > - // > - > - SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemorySize); > - FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); > - > - // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE > - // core to overwrite this area we must mark the region with the attribute non-present > - if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) { > - Found = FALSE; > - > - // Search for System Memory Hob that contains the firmware > - NextHob.Raw = GetHobList (); > - while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { > - if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) && > - (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor->PhysicalStart) && > - (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength)) > - { > - ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute; > - ResourceLength = NextHob.ResourceDescriptor->ResourceLength; > - ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength; > - > - if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) { > - if (SystemMemoryTop == FdTop) { > - NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; > - } else { > - // Create the System Memory HOB for the firmware with the non-present attribute > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > - PcdGet64 (PcdFdBaseAddress), > - PcdGet32 (PcdFdSize)); > - > - // Top of the FD is system memory available for UEFI > - NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); > - NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize); > - } > - } else { > - // Create the System Memory HOB for the firmware with the non-present attribute > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > - PcdGet64 (PcdFdBaseAddress), > - PcdGet32 (PcdFdSize)); > - > - // Update the HOB > - NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; > - > - // If there is some memory available on the top of the FD then create a HOB > - if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) { > - // Create the System Memory HOB for the remaining region (top of the FD) > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes, > - FdTop, > - ResourceTop - FdTop); > - } > - } > - Found = TRUE; > - break; > - } > - NextHob.Raw = GET_NEXT_HOB (NextHob); > - } > - > - ASSERT(Found); > - } > - > // Build Memory Allocation Hob > InitMmu (MemoryTable); > > -- > 1.9.1 > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel > IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please 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. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2] PeiLib : Inform UEFI memory to Linux 2017-09-19 12:48 ` Ard Biesheuvel @ 2017-09-20 5:32 ` Sakar Arora 2017-09-20 6:32 ` Ard Biesheuvel 0 siblings, 1 reply; 19+ messages in thread From: Sakar Arora @ 2017-09-20 5:32 UTC (permalink / raw) To: Ard Biesheuvel Cc: Meenakshi Aggarwal, edk2-devel@lists.01.org, leif.lindholm@linaro.org The DXE core dispatcher relies on the available memory to allocate space for loading the rest of the modules from the UEFI image. If we declare the UEFI image memory space (from which DXE dispatcher reads the efi modules) open to allocation, it might lead to data corruption, depending on the location of UEFI image and cumulative size of uncompressed EFI modules. Also, since UEFI allows unloading and loading of drivers at runtime, IMO, there is a need to preserve the UEFI image even after all the modules have been decompressed and loaded in the boot sequence. -----Original Message----- From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] Sent: Tuesday, September 19, 2017 6:18 PM To: Sakar Arora <Sakar.Arora@arm.com> Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; edk2-devel@lists.01.org; leif.lindholm@linaro.org Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux On 19 September 2017 at 01:07, Sakar Arora <Sakar.Arora@arm.com> wrote: > This change will create the possibility for memory space holding the UEFI image to be over-written by the DXE core code, since this space will then be available for allocation. Yes. But why does this matter after the entire payload has been decompressed into memory already? > Any such change, if required, should be done just before booting the OS. > > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Meenakshi Aggarwal > Sent: Tuesday, September 19, 2017 6:02 PM > To: edk2-devel@lists.01.org; leif.lindholm@linaro.org; > ard.biesheuvel@linaro.org > Subject: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > While creating Hob list, ArmPlatformPkg is hiding UEFI memory. > whereas this memory can be used by OS. > > This patch, allows OS to use UEFI code area. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Udit Kumar <udit.kumar@nxp.com> > Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> > --- > ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 69 > ------------------------- > 1 file changed, 69 deletions(-) > > diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > index 2feb11f..d03214b 100644 > --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > @@ -70,11 +70,7 @@ MemoryPeim ( > { > ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; > EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; > - UINT64 ResourceLength; > EFI_PEI_HOB_POINTERS NextHob; > - EFI_PHYSICAL_ADDRESS FdTop; > - EFI_PHYSICAL_ADDRESS SystemMemoryTop; > - EFI_PHYSICAL_ADDRESS ResourceTop; > BOOLEAN Found; > > // Get Virtual Memory Map from the Platform Library @@ -121,71 +117,6 @@ MemoryPeim ( > ); > } > > - // > - // Reserved the memory space occupied by the firmware volume > - // > - > - SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 > (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 > (PcdSystemMemorySize); > - FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + > (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); > - > - // EDK2 does not have the concept of boot firmware copied into > DRAM. To avoid the DXE > - // core to overwrite this area we must mark the region with the > attribute non-present > - if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) { > - Found = FALSE; > - > - // Search for System Memory Hob that contains the firmware > - NextHob.Raw = GetHobList (); > - while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { > - if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) && > - (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor->PhysicalStart) && > - (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength)) > - { > - ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute; > - ResourceLength = NextHob.ResourceDescriptor->ResourceLength; > - ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength; > - > - if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) { > - if (SystemMemoryTop == FdTop) { > - NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; > - } else { > - // Create the System Memory HOB for the firmware with the non-present attribute > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > - PcdGet64 (PcdFdBaseAddress), > - PcdGet32 (PcdFdSize)); > - > - // Top of the FD is system memory available for UEFI > - NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); > - NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize); > - } > - } else { > - // Create the System Memory HOB for the firmware with the non-present attribute > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > - PcdGet64 (PcdFdBaseAddress), > - PcdGet32 (PcdFdSize)); > - > - // Update the HOB > - NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; > - > - // If there is some memory available on the top of the FD then create a HOB > - if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) { > - // Create the System Memory HOB for the remaining region (top of the FD) > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes, > - FdTop, > - ResourceTop - FdTop); > - } > - } > - Found = TRUE; > - break; > - } > - NextHob.Raw = GET_NEXT_HOB (NextHob); > - } > - > - ASSERT(Found); > - } > - > // Build Memory Allocation Hob > InitMmu (MemoryTable); > > -- > 1.9.1 > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel > IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please 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. IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please 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. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2] PeiLib : Inform UEFI memory to Linux 2017-09-20 5:32 ` Sakar Arora @ 2017-09-20 6:32 ` Ard Biesheuvel 2017-09-20 8:20 ` Sakar Arora 0 siblings, 1 reply; 19+ messages in thread From: Ard Biesheuvel @ 2017-09-20 6:32 UTC (permalink / raw) To: Sakar Arora Cc: Meenakshi Aggarwal, edk2-devel@lists.01.org, leif.lindholm@linaro.org On 19 September 2017 at 22:32, Sakar Arora <Sakar.Arora@arm.com> wrote: > The DXE core dispatcher relies on the available memory to allocate space for loading the rest of the modules from the UEFI image. If we declare the UEFI image memory space (from which DXE dispatcher reads the efi modules) open to allocation, it might lead to data corruption, depending on the location of UEFI image and cumulative size of uncompressed EFI modules. > > Also, since UEFI allows unloading and loading of drivers at runtime, IMO, there is a need to preserve the UEFI image even after all the modules have been decompressed and loaded in the boot sequence. > None of this is relevant. The uncompressed firmware volume containing DXE core and everything else is preserved as before. The only thing that gets discarded is the outer FV, which only contains the PrePi SEC module, and the compressed FV, neither of which is ever touched again after DXE core has started executing. So we should not register the FV in the first place, and not reserve the memory so we don't lose it. If you still think this may break anything, could you please elaborate? > -----Original Message----- > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] > Sent: Tuesday, September 19, 2017 6:18 PM > To: Sakar Arora <Sakar.Arora@arm.com> > Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; edk2-devel@lists.01.org; leif.lindholm@linaro.org > Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > On 19 September 2017 at 01:07, Sakar Arora <Sakar.Arora@arm.com> wrote: >> This change will create the possibility for memory space holding the UEFI image to be over-written by the DXE core code, since this space will then be available for allocation. > > Yes. But why does this matter after the entire payload has been decompressed into memory already? > > >> Any such change, if required, should be done just before booting the OS. >> >> -----Original Message----- >> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of >> Meenakshi Aggarwal >> Sent: Tuesday, September 19, 2017 6:02 PM >> To: edk2-devel@lists.01.org; leif.lindholm@linaro.org; >> ard.biesheuvel@linaro.org >> Subject: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux >> >> While creating Hob list, ArmPlatformPkg is hiding UEFI memory. >> whereas this memory can be used by OS. >> >> This patch, allows OS to use UEFI code area. >> >> Contributed-under: TianoCore Contribution Agreement 1.1 >> Signed-off-by: Udit Kumar <udit.kumar@nxp.com> >> Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> >> --- >> ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 69 >> ------------------------- >> 1 file changed, 69 deletions(-) >> >> diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c >> b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c >> index 2feb11f..d03214b 100644 >> --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c >> +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c >> @@ -70,11 +70,7 @@ MemoryPeim ( >> { >> ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; >> EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; >> - UINT64 ResourceLength; >> EFI_PEI_HOB_POINTERS NextHob; >> - EFI_PHYSICAL_ADDRESS FdTop; >> - EFI_PHYSICAL_ADDRESS SystemMemoryTop; >> - EFI_PHYSICAL_ADDRESS ResourceTop; >> BOOLEAN Found; >> >> // Get Virtual Memory Map from the Platform Library @@ -121,71 +117,6 @@ MemoryPeim ( >> ); >> } >> >> - // >> - // Reserved the memory space occupied by the firmware volume >> - // >> - >> - SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 >> (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 >> (PcdSystemMemorySize); >> - FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + >> (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); >> - >> - // EDK2 does not have the concept of boot firmware copied into >> DRAM. To avoid the DXE >> - // core to overwrite this area we must mark the region with the >> attribute non-present >> - if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) { >> - Found = FALSE; >> - >> - // Search for System Memory Hob that contains the firmware >> - NextHob.Raw = GetHobList (); >> - while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { >> - if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) && >> - (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor->PhysicalStart) && >> - (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength)) >> - { >> - ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute; >> - ResourceLength = NextHob.ResourceDescriptor->ResourceLength; >> - ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength; >> - >> - if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) { >> - if (SystemMemoryTop == FdTop) { >> - NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; >> - } else { >> - // Create the System Memory HOB for the firmware with the non-present attribute >> - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, >> - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, >> - PcdGet64 (PcdFdBaseAddress), >> - PcdGet32 (PcdFdSize)); >> - >> - // Top of the FD is system memory available for UEFI >> - NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); >> - NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize); >> - } >> - } else { >> - // Create the System Memory HOB for the firmware with the non-present attribute >> - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, >> - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, >> - PcdGet64 (PcdFdBaseAddress), >> - PcdGet32 (PcdFdSize)); >> - >> - // Update the HOB >> - NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; >> - >> - // If there is some memory available on the top of the FD then create a HOB >> - if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) { >> - // Create the System Memory HOB for the remaining region (top of the FD) >> - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, >> - ResourceAttributes, >> - FdTop, >> - ResourceTop - FdTop); >> - } >> - } >> - Found = TRUE; >> - break; >> - } >> - NextHob.Raw = GET_NEXT_HOB (NextHob); >> - } >> - >> - ASSERT(Found); >> - } >> - >> // Build Memory Allocation Hob >> InitMmu (MemoryTable); >> >> -- >> 1.9.1 >> >> _______________________________________________ >> edk2-devel mailing list >> edk2-devel@lists.01.org >> https://lists.01.org/mailman/listinfo/edk2-devel >> IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please 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. > IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please 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. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2] PeiLib : Inform UEFI memory to Linux 2017-09-20 6:32 ` Ard Biesheuvel @ 2017-09-20 8:20 ` Sakar Arora 2017-09-25 5:47 ` Meenakshi Aggarwal 2017-11-30 10:07 ` Udit Kumar 0 siblings, 2 replies; 19+ messages in thread From: Sakar Arora @ 2017-09-20 8:20 UTC (permalink / raw) To: Ard Biesheuvel Cc: Meenakshi Aggarwal, edk2-devel@lists.01.org, leif.lindholm@linaro.org Thanks for the information. Seems my understanding was not correct in this context. I have no other doubts on this change. -----Original Message----- From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] Sent: Wednesday, September 20, 2017 12:02 PM To: Sakar Arora <Sakar.Arora@arm.com> Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; edk2-devel@lists.01.org; leif.lindholm@linaro.org Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux On 19 September 2017 at 22:32, Sakar Arora <Sakar.Arora@arm.com> wrote: > The DXE core dispatcher relies on the available memory to allocate space for loading the rest of the modules from the UEFI image. If we declare the UEFI image memory space (from which DXE dispatcher reads the efi modules) open to allocation, it might lead to data corruption, depending on the location of UEFI image and cumulative size of uncompressed EFI modules. > > Also, since UEFI allows unloading and loading of drivers at runtime, IMO, there is a need to preserve the UEFI image even after all the modules have been decompressed and loaded in the boot sequence. > None of this is relevant. The uncompressed firmware volume containing DXE core and everything else is preserved as before. The only thing that gets discarded is the outer FV, which only contains the PrePi SEC module, and the compressed FV, neither of which is ever touched again after DXE core has started executing. So we should not register the FV in the first place, and not reserve the memory so we don't lose it. If you still think this may break anything, could you please elaborate? > -----Original Message----- > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] > Sent: Tuesday, September 19, 2017 6:18 PM > To: Sakar Arora <Sakar.Arora@arm.com> > Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; > edk2-devel@lists.01.org; leif.lindholm@linaro.org > Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > On 19 September 2017 at 01:07, Sakar Arora <Sakar.Arora@arm.com> wrote: >> This change will create the possibility for memory space holding the UEFI image to be over-written by the DXE core code, since this space will then be available for allocation. > > Yes. But why does this matter after the entire payload has been decompressed into memory already? > > >> Any such change, if required, should be done just before booting the OS. >> >> -----Original Message----- >> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf >> Of Meenakshi Aggarwal >> Sent: Tuesday, September 19, 2017 6:02 PM >> To: edk2-devel@lists.01.org; leif.lindholm@linaro.org; >> ard.biesheuvel@linaro.org >> Subject: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux >> >> While creating Hob list, ArmPlatformPkg is hiding UEFI memory. >> whereas this memory can be used by OS. >> >> This patch, allows OS to use UEFI code area. >> >> Contributed-under: TianoCore Contribution Agreement 1.1 >> Signed-off-by: Udit Kumar <udit.kumar@nxp.com> >> Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> >> --- >> ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 69 >> ------------------------- >> 1 file changed, 69 deletions(-) >> >> diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c >> b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c >> index 2feb11f..d03214b 100644 >> --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c >> +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c >> @@ -70,11 +70,7 @@ MemoryPeim ( >> { >> ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; >> EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; >> - UINT64 ResourceLength; >> EFI_PEI_HOB_POINTERS NextHob; >> - EFI_PHYSICAL_ADDRESS FdTop; >> - EFI_PHYSICAL_ADDRESS SystemMemoryTop; >> - EFI_PHYSICAL_ADDRESS ResourceTop; >> BOOLEAN Found; >> >> // Get Virtual Memory Map from the Platform Library @@ -121,71 +117,6 @@ MemoryPeim ( >> ); >> } >> >> - // >> - // Reserved the memory space occupied by the firmware volume >> - // >> - >> - SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 >> (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 >> (PcdSystemMemorySize); >> - FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + >> (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); >> - >> - // EDK2 does not have the concept of boot firmware copied into >> DRAM. To avoid the DXE >> - // core to overwrite this area we must mark the region with the >> attribute non-present >> - if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) { >> - Found = FALSE; >> - >> - // Search for System Memory Hob that contains the firmware >> - NextHob.Raw = GetHobList (); >> - while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { >> - if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) && >> - (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor->PhysicalStart) && >> - (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength)) >> - { >> - ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute; >> - ResourceLength = NextHob.ResourceDescriptor->ResourceLength; >> - ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength; >> - >> - if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) { >> - if (SystemMemoryTop == FdTop) { >> - NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; >> - } else { >> - // Create the System Memory HOB for the firmware with the non-present attribute >> - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, >> - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, >> - PcdGet64 (PcdFdBaseAddress), >> - PcdGet32 (PcdFdSize)); >> - >> - // Top of the FD is system memory available for UEFI >> - NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); >> - NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize); >> - } >> - } else { >> - // Create the System Memory HOB for the firmware with the non-present attribute >> - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, >> - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, >> - PcdGet64 (PcdFdBaseAddress), >> - PcdGet32 (PcdFdSize)); >> - >> - // Update the HOB >> - NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; >> - >> - // If there is some memory available on the top of the FD then create a HOB >> - if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) { >> - // Create the System Memory HOB for the remaining region (top of the FD) >> - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, >> - ResourceAttributes, >> - FdTop, >> - ResourceTop - FdTop); >> - } >> - } >> - Found = TRUE; >> - break; >> - } >> - NextHob.Raw = GET_NEXT_HOB (NextHob); >> - } >> - >> - ASSERT(Found); >> - } >> - >> // Build Memory Allocation Hob >> InitMmu (MemoryTable); >> >> -- >> 1.9.1 >> >> _______________________________________________ >> edk2-devel mailing list >> edk2-devel@lists.01.org >> https://lists.01.org/mailman/listinfo/edk2-devel >> IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please 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. > IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please 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. IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please 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. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2] PeiLib : Inform UEFI memory to Linux 2017-09-20 8:20 ` Sakar Arora @ 2017-09-25 5:47 ` Meenakshi Aggarwal 2017-11-30 10:07 ` Udit Kumar 1 sibling, 0 replies; 19+ messages in thread From: Meenakshi Aggarwal @ 2017-09-25 5:47 UTC (permalink / raw) To: Sakar Arora, Ard Biesheuvel Cc: edk2-devel@lists.01.org, leif.lindholm@linaro.org Hi All, Please review the patch and share your comments. Thanks, Meenakshi > -----Original Message----- > From: Sakar Arora [mailto:Sakar.Arora@arm.com] > Sent: Wednesday, September 20, 2017 1:50 PM > To: Ard Biesheuvel <ard.biesheuvel@linaro.org> > Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; edk2- > devel@lists.01.org; leif.lindholm@linaro.org > Subject: RE: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > Thanks for the information. Seems my understanding was not correct in this > context. I have no other doubts on this change. > > -----Original Message----- > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] > Sent: Wednesday, September 20, 2017 12:02 PM > To: Sakar Arora <Sakar.Arora@arm.com> > Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; edk2- > devel@lists.01.org; leif.lindholm@linaro.org > Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > On 19 September 2017 at 22:32, Sakar Arora <Sakar.Arora@arm.com> wrote: > > The DXE core dispatcher relies on the available memory to allocate space > for loading the rest of the modules from the UEFI image. If we declare the > UEFI image memory space (from which DXE dispatcher reads the efi > modules) open to allocation, it might lead to data corruption, depending on > the location of UEFI image and cumulative size of uncompressed EFI > modules. > > > > Also, since UEFI allows unloading and loading of drivers at runtime, IMO, > there is a need to preserve the UEFI image even after all the modules have > been decompressed and loaded in the boot sequence. > > > > None of this is relevant. The uncompressed firmware volume containing DXE > core and everything else is preserved as before. The only thing that gets > discarded is the outer FV, which only contains the PrePi SEC module, and the > compressed FV, neither of which is ever touched again after DXE core has > started executing. So we should not register the FV in the first place, and not > reserve the memory so we don't lose it. > > If you still think this may break anything, could you please elaborate? > > > > > -----Original Message----- > > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] > > Sent: Tuesday, September 19, 2017 6:18 PM > > To: Sakar Arora <Sakar.Arora@arm.com> > > Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; > > edk2-devel@lists.01.org; leif.lindholm@linaro.org > > Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > > > On 19 September 2017 at 01:07, Sakar Arora <Sakar.Arora@arm.com> > wrote: > >> This change will create the possibility for memory space holding the UEFI > image to be over-written by the DXE core code, since this space will then be > available for allocation. > > > > Yes. But why does this matter after the entire payload has been > decompressed into memory already? > > > > > >> Any such change, if required, should be done just before booting the OS. > >> > >> -----Original Message----- > >> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf > >> Of Meenakshi Aggarwal > >> Sent: Tuesday, September 19, 2017 6:02 PM > >> To: edk2-devel@lists.01.org; leif.lindholm@linaro.org; > >> ard.biesheuvel@linaro.org > >> Subject: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > >> > >> While creating Hob list, ArmPlatformPkg is hiding UEFI memory. > >> whereas this memory can be used by OS. > >> > >> This patch, allows OS to use UEFI code area. > >> > >> Contributed-under: TianoCore Contribution Agreement 1.1 > >> Signed-off-by: Udit Kumar <udit.kumar@nxp.com> > >> Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> > >> --- > >> ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 69 > >> ------------------------- > >> 1 file changed, 69 deletions(-) > >> > >> diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > >> b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > >> index 2feb11f..d03214b 100644 > >> --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > >> +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > >> @@ -70,11 +70,7 @@ MemoryPeim ( > >> { > >> ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; > >> EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; > >> - UINT64 ResourceLength; > >> EFI_PEI_HOB_POINTERS NextHob; > >> - EFI_PHYSICAL_ADDRESS FdTop; > >> - EFI_PHYSICAL_ADDRESS SystemMemoryTop; > >> - EFI_PHYSICAL_ADDRESS ResourceTop; > >> BOOLEAN Found; > >> > >> // Get Virtual Memory Map from the Platform Library @@ -121,71 > +117,6 @@ MemoryPeim ( > >> ); > >> } > >> > >> - // > >> - // Reserved the memory space occupied by the firmware volume > >> - // > >> - > >> - SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 > >> (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 > >> (PcdSystemMemorySize); > >> - FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + > >> (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); > >> - > >> - // EDK2 does not have the concept of boot firmware copied into > >> DRAM. To avoid the DXE > >> - // core to overwrite this area we must mark the region with the > >> attribute non-present > >> - if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 > (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) { > >> - Found = FALSE; > >> - > >> - // Search for System Memory Hob that contains the firmware > >> - NextHob.Raw = GetHobList (); > >> - while ((NextHob.Raw = GetNextHob > (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { > >> - if ((NextHob.ResourceDescriptor->ResourceType == > EFI_RESOURCE_SYSTEM_MEMORY) && > >> - (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor- > >PhysicalStart) && > >> - (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + > NextHob.ResourceDescriptor->ResourceLength)) > >> - { > >> - ResourceAttributes = NextHob.ResourceDescriptor- > >ResourceAttribute; > >> - ResourceLength = NextHob.ResourceDescriptor->ResourceLength; > >> - ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + > ResourceLength; > >> - > >> - if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor- > >PhysicalStart) { > >> - if (SystemMemoryTop == FdTop) { > >> - NextHob.ResourceDescriptor->ResourceAttribute = > ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; > >> - } else { > >> - // Create the System Memory HOB for the firmware with the non- > present attribute > >> - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > >> - ResourceAttributes & > ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > >> - PcdGet64 (PcdFdBaseAddress), > >> - PcdGet32 (PcdFdSize)); > >> - > >> - // Top of the FD is system memory available for UEFI > >> - NextHob.ResourceDescriptor->PhysicalStart += > PcdGet32(PcdFdSize); > >> - NextHob.ResourceDescriptor->ResourceLength -= > PcdGet32(PcdFdSize); > >> - } > >> - } else { > >> - // Create the System Memory HOB for the firmware with the non- > present attribute > >> - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > >> - ResourceAttributes & > ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > >> - PcdGet64 (PcdFdBaseAddress), > >> - PcdGet32 (PcdFdSize)); > >> - > >> - // Update the HOB > >> - NextHob.ResourceDescriptor->ResourceLength = PcdGet64 > (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; > >> - > >> - // If there is some memory available on the top of the FD then > create a HOB > >> - if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + > ResourceLength) { > >> - // Create the System Memory HOB for the remaining region (top of > the FD) > >> - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > >> - ResourceAttributes, > >> - FdTop, > >> - ResourceTop - FdTop); > >> - } > >> - } > >> - Found = TRUE; > >> - break; > >> - } > >> - NextHob.Raw = GET_NEXT_HOB (NextHob); > >> - } > >> - > >> - ASSERT(Found); > >> - } > >> - > >> // Build Memory Allocation Hob > >> InitMmu (MemoryTable); > >> > >> -- > >> 1.9.1 > >> > >> _______________________________________________ > >> edk2-devel mailing list > >> edk2-devel@lists.01.org > >> https://lists.01.org/mailman/listinfo/edk2-devel > >> IMPORTANT NOTICE: The contents of this email and any attachments are > confidential and may also be privileged. If you are not the intended recipient, > please 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. > > IMPORTANT NOTICE: The contents of this email and any attachments are > confidential and may also be privileged. If you are not the intended recipient, > please 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. > IMPORTANT NOTICE: The contents of this email and any attachments are > confidential and may also be privileged. If you are not the intended recipient, > please 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. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2] PeiLib : Inform UEFI memory to Linux 2017-09-20 8:20 ` Sakar Arora 2017-09-25 5:47 ` Meenakshi Aggarwal @ 2017-11-30 10:07 ` Udit Kumar 2017-11-30 14:33 ` Ard Biesheuvel 1 sibling, 1 reply; 19+ messages in thread From: Udit Kumar @ 2017-11-30 10:07 UTC (permalink / raw) To: Sakar Arora, Ard Biesheuvel Cc: edk2-devel@lists.01.org, leif.lindholm@linaro.org Hi Ard, Sorry for coming back late on this Are you ok to apply this patch in edk2 Thx Udit > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Sakar > Arora > Sent: Wednesday, September 20, 2017 1:50 PM > To: Ard Biesheuvel <ard.biesheuvel@linaro.org> > Cc: edk2-devel@lists.01.org; leif.lindholm@linaro.org > Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > Thanks for the information. Seems my understanding was not correct in this > context. I have no other doubts on this change. > > -----Original Message----- > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] > Sent: Wednesday, September 20, 2017 12:02 PM > To: Sakar Arora <Sakar.Arora@arm.com> > Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; edk2- > devel@lists.01.org; leif.lindholm@linaro.org > Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > On 19 September 2017 at 22:32, Sakar Arora <Sakar.Arora@arm.com> wrote: > > The DXE core dispatcher relies on the available memory to allocate space for > loading the rest of the modules from the UEFI image. If we declare the UEFI > image memory space (from which DXE dispatcher reads the efi modules) open to > allocation, it might lead to data corruption, depending on the location of UEFI > image and cumulative size of uncompressed EFI modules. > > > > Also, since UEFI allows unloading and loading of drivers at runtime, IMO, there > is a need to preserve the UEFI image even after all the modules have been > decompressed and loaded in the boot sequence. > > > > None of this is relevant. The uncompressed firmware volume containing DXE > core and everything else is preserved as before. The only thing that gets > discarded is the outer FV, which only contains the PrePi SEC module, and the > compressed FV, neither of which is ever touched again after DXE core has > started executing. So we should not register the FV in the first place, and not > reserve the memory so we don't lose it. > > If you still think this may break anything, could you please elaborate? > > > > > -----Original Message----- > > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] > > Sent: Tuesday, September 19, 2017 6:18 PM > > To: Sakar Arora <Sakar.Arora@arm.com> > > Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; > > edk2-devel@lists.01.org; leif.lindholm@linaro.org > > Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > > > On 19 September 2017 at 01:07, Sakar Arora <Sakar.Arora@arm.com> wrote: > >> This change will create the possibility for memory space holding the UEFI > image to be over-written by the DXE core code, since this space will then be > available for allocation. > > > > Yes. But why does this matter after the entire payload has been decompressed > into memory already? > > > > > >> Any such change, if required, should be done just before booting the OS. > >> > >> -----Original Message----- > >> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf > >> Of Meenakshi Aggarwal > >> Sent: Tuesday, September 19, 2017 6:02 PM > >> To: edk2-devel@lists.01.org; leif.lindholm@linaro.org; > >> ard.biesheuvel@linaro.org > >> Subject: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > >> > >> While creating Hob list, ArmPlatformPkg is hiding UEFI memory. > >> whereas this memory can be used by OS. > >> > >> This patch, allows OS to use UEFI code area. > >> > >> Contributed-under: TianoCore Contribution Agreement 1.1 > >> Signed-off-by: Udit Kumar <udit.kumar@nxp.com> > >> Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> > >> --- > >> ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 69 > >> ------------------------- > >> 1 file changed, 69 deletions(-) > >> > >> diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > >> b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > >> index 2feb11f..d03214b 100644 > >> --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > >> +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > >> @@ -70,11 +70,7 @@ MemoryPeim ( > >> { > >> ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; > >> EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; > >> - UINT64 ResourceLength; > >> EFI_PEI_HOB_POINTERS NextHob; > >> - EFI_PHYSICAL_ADDRESS FdTop; > >> - EFI_PHYSICAL_ADDRESS SystemMemoryTop; > >> - EFI_PHYSICAL_ADDRESS ResourceTop; > >> BOOLEAN Found; > >> > >> // Get Virtual Memory Map from the Platform Library @@ -121,71 +117,6 > @@ MemoryPeim ( > >> ); > >> } > >> > >> - // > >> - // Reserved the memory space occupied by the firmware volume > >> - // > >> - > >> - SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 > >> (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 > >> (PcdSystemMemorySize); > >> - FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + > >> (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); > >> - > >> - // EDK2 does not have the concept of boot firmware copied into > >> DRAM. To avoid the DXE > >> - // core to overwrite this area we must mark the region with the > >> attribute non-present > >> - if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) > && (FdTop <= SystemMemoryTop)) { > >> - Found = FALSE; > >> - > >> - // Search for System Memory Hob that contains the firmware > >> - NextHob.Raw = GetHobList (); > >> - while ((NextHob.Raw = GetNextHob > (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { > >> - if ((NextHob.ResourceDescriptor->ResourceType == > EFI_RESOURCE_SYSTEM_MEMORY) && > >> - (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor- > >PhysicalStart) && > >> - (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + > NextHob.ResourceDescriptor->ResourceLength)) > >> - { > >> - ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute; > >> - ResourceLength = NextHob.ResourceDescriptor->ResourceLength; > >> - ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + > ResourceLength; > >> - > >> - if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor- > >PhysicalStart) { > >> - if (SystemMemoryTop == FdTop) { > >> - NextHob.ResourceDescriptor->ResourceAttribute = > ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; > >> - } else { > >> - // Create the System Memory HOB for the firmware with the non- > present attribute > >> - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > >> - ResourceAttributes & > ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > >> - PcdGet64 (PcdFdBaseAddress), > >> - PcdGet32 (PcdFdSize)); > >> - > >> - // Top of the FD is system memory available for UEFI > >> - NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); > >> - NextHob.ResourceDescriptor->ResourceLength -= > PcdGet32(PcdFdSize); > >> - } > >> - } else { > >> - // Create the System Memory HOB for the firmware with the non- > present attribute > >> - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > >> - ResourceAttributes & > ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > >> - PcdGet64 (PcdFdBaseAddress), > >> - PcdGet32 (PcdFdSize)); > >> - > >> - // Update the HOB > >> - NextHob.ResourceDescriptor->ResourceLength = PcdGet64 > (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; > >> - > >> - // If there is some memory available on the top of the FD then create a > HOB > >> - if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + > ResourceLength) { > >> - // Create the System Memory HOB for the remaining region (top of > the FD) > >> - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > >> - ResourceAttributes, > >> - FdTop, > >> - ResourceTop - FdTop); > >> - } > >> - } > >> - Found = TRUE; > >> - break; > >> - } > >> - NextHob.Raw = GET_NEXT_HOB (NextHob); > >> - } > >> - > >> - ASSERT(Found); > >> - } > >> - > >> // Build Memory Allocation Hob > >> InitMmu (MemoryTable); > >> > >> -- > >> 1.9.1 > >> > >> _______________________________________________ > >> edk2-devel mailing list > >> edk2-devel@lists.01.org > >> https://lists.01.org/mailman/listinfo/edk2-devel > >> IMPORTANT NOTICE: The contents of this email and any attachments are > confidential and may also be privileged. If you are not the intended recipient, > please 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. > > IMPORTANT NOTICE: The contents of this email and any attachments are > confidential and may also be privileged. If you are not the intended recipient, > please 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. > IMPORTANT NOTICE: The contents of this email and any attachments are > confidential and may also be privileged. If you are not the intended recipient, > please 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. > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2] PeiLib : Inform UEFI memory to Linux 2017-11-30 10:07 ` Udit Kumar @ 2017-11-30 14:33 ` Ard Biesheuvel 0 siblings, 0 replies; 19+ messages in thread From: Ard Biesheuvel @ 2017-11-30 14:33 UTC (permalink / raw) To: Udit Kumar; +Cc: Sakar Arora, edk2-devel@lists.01.org, leif.lindholm@linaro.org On 30 November 2017 at 10:07, Udit Kumar <udit.kumar@nxp.com> wrote: > Hi Ard, > Sorry for coming back late on this > Are you ok to apply this patch in edk2 > Actually, I recently discovered why this code exists in the first place (I think) The following libraries EmbeddedPkg/Library/LzmaHobCustomDecompressLib EmbeddedPkg/Library/DxeHobPeCoffLib expose code that is part of the PrePi module via HOBs. This was implemented for BeagleBoardPkg, which apparently couldn't keep two copies of that code in its flash. So we can only remove this code if we first clone the existing version into BeagleBoardPkg as a special case. Thanks, Ard. >> -----Original Message----- >> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Sakar >> Arora >> Sent: Wednesday, September 20, 2017 1:50 PM >> To: Ard Biesheuvel <ard.biesheuvel@linaro.org> >> Cc: edk2-devel@lists.01.org; leif.lindholm@linaro.org >> Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux >> >> Thanks for the information. Seems my understanding was not correct in this >> context. I have no other doubts on this change. >> >> -----Original Message----- >> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] >> Sent: Wednesday, September 20, 2017 12:02 PM >> To: Sakar Arora <Sakar.Arora@arm.com> >> Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; edk2- >> devel@lists.01.org; leif.lindholm@linaro.org >> Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux >> >> On 19 September 2017 at 22:32, Sakar Arora <Sakar.Arora@arm.com> wrote: >> > The DXE core dispatcher relies on the available memory to allocate space for >> loading the rest of the modules from the UEFI image. If we declare the UEFI >> image memory space (from which DXE dispatcher reads the efi modules) open to >> allocation, it might lead to data corruption, depending on the location of UEFI >> image and cumulative size of uncompressed EFI modules. >> > >> > Also, since UEFI allows unloading and loading of drivers at runtime, IMO, there >> is a need to preserve the UEFI image even after all the modules have been >> decompressed and loaded in the boot sequence. >> > >> >> None of this is relevant. The uncompressed firmware volume containing DXE >> core and everything else is preserved as before. The only thing that gets >> discarded is the outer FV, which only contains the PrePi SEC module, and the >> compressed FV, neither of which is ever touched again after DXE core has >> started executing. So we should not register the FV in the first place, and not >> reserve the memory so we don't lose it. >> >> If you still think this may break anything, could you please elaborate? >> >> >> >> > -----Original Message----- >> > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] >> > Sent: Tuesday, September 19, 2017 6:18 PM >> > To: Sakar Arora <Sakar.Arora@arm.com> >> > Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; >> > edk2-devel@lists.01.org; leif.lindholm@linaro.org >> > Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux >> > >> > On 19 September 2017 at 01:07, Sakar Arora <Sakar.Arora@arm.com> wrote: >> >> This change will create the possibility for memory space holding the UEFI >> image to be over-written by the DXE core code, since this space will then be >> available for allocation. >> > >> > Yes. But why does this matter after the entire payload has been decompressed >> into memory already? >> > >> > >> >> Any such change, if required, should be done just before booting the OS. >> >> >> >> -----Original Message----- >> >> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf >> >> Of Meenakshi Aggarwal >> >> Sent: Tuesday, September 19, 2017 6:02 PM >> >> To: edk2-devel@lists.01.org; leif.lindholm@linaro.org; >> >> ard.biesheuvel@linaro.org >> >> Subject: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux >> >> >> >> While creating Hob list, ArmPlatformPkg is hiding UEFI memory. >> >> whereas this memory can be used by OS. >> >> >> >> This patch, allows OS to use UEFI code area. >> >> >> >> Contributed-under: TianoCore Contribution Agreement 1.1 >> >> Signed-off-by: Udit Kumar <udit.kumar@nxp.com> >> >> Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> >> >> --- >> >> ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 69 >> >> ------------------------- >> >> 1 file changed, 69 deletions(-) >> >> >> >> diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c >> >> b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c >> >> index 2feb11f..d03214b 100644 >> >> --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c >> >> +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c >> >> @@ -70,11 +70,7 @@ MemoryPeim ( >> >> { >> >> ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; >> >> EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; >> >> - UINT64 ResourceLength; >> >> EFI_PEI_HOB_POINTERS NextHob; >> >> - EFI_PHYSICAL_ADDRESS FdTop; >> >> - EFI_PHYSICAL_ADDRESS SystemMemoryTop; >> >> - EFI_PHYSICAL_ADDRESS ResourceTop; >> >> BOOLEAN Found; >> >> >> >> // Get Virtual Memory Map from the Platform Library @@ -121,71 +117,6 >> @@ MemoryPeim ( >> >> ); >> >> } >> >> >> >> - // >> >> - // Reserved the memory space occupied by the firmware volume >> >> - // >> >> - >> >> - SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 >> >> (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 >> >> (PcdSystemMemorySize); >> >> - FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + >> >> (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); >> >> - >> >> - // EDK2 does not have the concept of boot firmware copied into >> >> DRAM. To avoid the DXE >> >> - // core to overwrite this area we must mark the region with the >> >> attribute non-present >> >> - if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) >> && (FdTop <= SystemMemoryTop)) { >> >> - Found = FALSE; >> >> - >> >> - // Search for System Memory Hob that contains the firmware >> >> - NextHob.Raw = GetHobList (); >> >> - while ((NextHob.Raw = GetNextHob >> (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { >> >> - if ((NextHob.ResourceDescriptor->ResourceType == >> EFI_RESOURCE_SYSTEM_MEMORY) && >> >> - (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor- >> >PhysicalStart) && >> >> - (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + >> NextHob.ResourceDescriptor->ResourceLength)) >> >> - { >> >> - ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute; >> >> - ResourceLength = NextHob.ResourceDescriptor->ResourceLength; >> >> - ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + >> ResourceLength; >> >> - >> >> - if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor- >> >PhysicalStart) { >> >> - if (SystemMemoryTop == FdTop) { >> >> - NextHob.ResourceDescriptor->ResourceAttribute = >> ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; >> >> - } else { >> >> - // Create the System Memory HOB for the firmware with the non- >> present attribute >> >> - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, >> >> - ResourceAttributes & >> ~EFI_RESOURCE_ATTRIBUTE_PRESENT, >> >> - PcdGet64 (PcdFdBaseAddress), >> >> - PcdGet32 (PcdFdSize)); >> >> - >> >> - // Top of the FD is system memory available for UEFI >> >> - NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); >> >> - NextHob.ResourceDescriptor->ResourceLength -= >> PcdGet32(PcdFdSize); >> >> - } >> >> - } else { >> >> - // Create the System Memory HOB for the firmware with the non- >> present attribute >> >> - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, >> >> - ResourceAttributes & >> ~EFI_RESOURCE_ATTRIBUTE_PRESENT, >> >> - PcdGet64 (PcdFdBaseAddress), >> >> - PcdGet32 (PcdFdSize)); >> >> - >> >> - // Update the HOB >> >> - NextHob.ResourceDescriptor->ResourceLength = PcdGet64 >> (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; >> >> - >> >> - // If there is some memory available on the top of the FD then create a >> HOB >> >> - if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + >> ResourceLength) { >> >> - // Create the System Memory HOB for the remaining region (top of >> the FD) >> >> - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, >> >> - ResourceAttributes, >> >> - FdTop, >> >> - ResourceTop - FdTop); >> >> - } >> >> - } >> >> - Found = TRUE; >> >> - break; >> >> - } >> >> - NextHob.Raw = GET_NEXT_HOB (NextHob); >> >> - } >> >> - >> >> - ASSERT(Found); >> >> - } >> >> - >> >> // Build Memory Allocation Hob >> >> InitMmu (MemoryTable); >> >> >> >> -- >> >> 1.9.1 >> >> >> >> _______________________________________________ >> >> edk2-devel mailing list >> >> edk2-devel@lists.01.org >> >> https://lists.01.org/mailman/listinfo/edk2-devel >> >> IMPORTANT NOTICE: The contents of this email and any attachments are >> confidential and may also be privileged. If you are not the intended recipient, >> please 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. >> > IMPORTANT NOTICE: The contents of this email and any attachments are >> confidential and may also be privileged. If you are not the intended recipient, >> please 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. >> IMPORTANT NOTICE: The contents of this email and any attachments are >> confidential and may also be privileged. If you are not the intended recipient, >> please 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. >> _______________________________________________ >> edk2-devel mailing list >> edk2-devel@lists.01.org >> https://lists.01.org/mailman/listinfo/edk2-devel ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2] PeiLib : Inform UEFI memory to Linux 2017-09-19 12:32 ` [PATCH v2] PeiLib : " Meenakshi Aggarwal 2017-09-19 8:07 ` Sakar Arora @ 2017-09-20 14:59 ` Gao, Liming 2017-09-21 5:59 ` Udit Kumar 1 sibling, 1 reply; 19+ messages in thread From: Gao, Liming @ 2017-09-20 14:59 UTC (permalink / raw) To: Meenakshi Aggarwal, edk2-devel@lists.01.org, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org To reserve the memory resource in boot phase and open them for OS phase, after create system resource hob, we can create memory allocation hob to take some range in PEI phase. Then, these ranges will not be allocated in DXE phase, but they will still be reported in UEFI memory map. So, for this case, I suggest to create memory hob instead of resource hob with non present memory attribute. Thanks Liming > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Meenakshi Aggarwal > Sent: Tuesday, September 19, 2017 8:32 PM > To: edk2-devel@lists.01.org; leif.lindholm@linaro.org; ard.biesheuvel@linaro.org > Subject: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > While creating Hob list, ArmPlatformPkg is hiding UEFI memory. > whereas this memory can be used by OS. > > This patch, allows OS to use UEFI code area. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Udit Kumar <udit.kumar@nxp.com> > Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> > --- > ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 69 ------------------------- > 1 file changed, 69 deletions(-) > > diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > index 2feb11f..d03214b 100644 > --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > @@ -70,11 +70,7 @@ MemoryPeim ( > { > ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; > EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; > - UINT64 ResourceLength; > EFI_PEI_HOB_POINTERS NextHob; > - EFI_PHYSICAL_ADDRESS FdTop; > - EFI_PHYSICAL_ADDRESS SystemMemoryTop; > - EFI_PHYSICAL_ADDRESS ResourceTop; > BOOLEAN Found; > > // Get Virtual Memory Map from the Platform Library > @@ -121,71 +117,6 @@ MemoryPeim ( > ); > } > > - // > - // Reserved the memory space occupied by the firmware volume > - // > - > - SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 > (PcdSystemMemorySize); > - FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); > - > - // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE > - // core to overwrite this area we must mark the region with the attribute non-present > - if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) { > - Found = FALSE; > - > - // Search for System Memory Hob that contains the firmware > - NextHob.Raw = GetHobList (); > - while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { > - if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) && > - (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor->PhysicalStart) && > - (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength)) > - { > - ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute; > - ResourceLength = NextHob.ResourceDescriptor->ResourceLength; > - ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength; > - > - if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) { > - if (SystemMemoryTop == FdTop) { > - NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; > - } else { > - // Create the System Memory HOB for the firmware with the non-present attribute > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > - PcdGet64 (PcdFdBaseAddress), > - PcdGet32 (PcdFdSize)); > - > - // Top of the FD is system memory available for UEFI > - NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); > - NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize); > - } > - } else { > - // Create the System Memory HOB for the firmware with the non-present attribute > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > - PcdGet64 (PcdFdBaseAddress), > - PcdGet32 (PcdFdSize)); > - > - // Update the HOB > - NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - > NextHob.ResourceDescriptor->PhysicalStart; > - > - // If there is some memory available on the top of the FD then create a HOB > - if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) { > - // Create the System Memory HOB for the remaining region (top of the FD) > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > - ResourceAttributes, > - FdTop, > - ResourceTop - FdTop); > - } > - } > - Found = TRUE; > - break; > - } > - NextHob.Raw = GET_NEXT_HOB (NextHob); > - } > - > - ASSERT(Found); > - } > - > // Build Memory Allocation Hob > InitMmu (MemoryTable); > > -- > 1.9.1 > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2] PeiLib : Inform UEFI memory to Linux 2017-09-20 14:59 ` Gao, Liming @ 2017-09-21 5:59 ` Udit Kumar 0 siblings, 0 replies; 19+ messages in thread From: Udit Kumar @ 2017-09-21 5:59 UTC (permalink / raw) To: Gao, Liming, Meenakshi Aggarwal, edk2-devel@lists.01.org, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org Hi Liming >So, for this case, I suggest to > create memory hob instead of resource hob with non present memory attribute. ARM package is already creating a memory HoB for the same. Thanks Udit > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Gao, > Liming > Sent: Wednesday, September 20, 2017 8:29 PM > To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; edk2- > devel@lists.01.org; leif.lindholm@linaro.org; ard.biesheuvel@linaro.org > Subject: Re: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > To reserve the memory resource in boot phase and open them for OS phase, > after create system resource hob, we can create memory allocation hob to take > some range in PEI phase. Then, these ranges will not be allocated in DXE phase, > but they will still be reported in UEFI memory map. So, for this case, I suggest to > create memory hob instead of resource hob with non present memory attribute. > > Thanks > Liming > > -----Original Message----- > > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > > Meenakshi Aggarwal > > Sent: Tuesday, September 19, 2017 8:32 PM > > To: edk2-devel@lists.01.org; leif.lindholm@linaro.org; > > ard.biesheuvel@linaro.org > > Subject: [edk2] [PATCH v2] PeiLib : Inform UEFI memory to Linux > > > > While creating Hob list, ArmPlatformPkg is hiding UEFI memory. > > whereas this memory can be used by OS. > > > > This patch, allows OS to use UEFI code area. > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Udit Kumar <udit.kumar@nxp.com> > > Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com> > > --- > > ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 69 > > ------------------------- > > 1 file changed, 69 deletions(-) > > > > diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > > b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > > index 2feb11f..d03214b 100644 > > --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > > +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c > > @@ -70,11 +70,7 @@ MemoryPeim ( > > { > > ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; > > EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; > > - UINT64 ResourceLength; > > EFI_PEI_HOB_POINTERS NextHob; > > - EFI_PHYSICAL_ADDRESS FdTop; > > - EFI_PHYSICAL_ADDRESS SystemMemoryTop; > > - EFI_PHYSICAL_ADDRESS ResourceTop; > > BOOLEAN Found; > > > > // Get Virtual Memory Map from the Platform Library @@ -121,71 > > +117,6 @@ MemoryPeim ( > > ); > > } > > > > - // > > - // Reserved the memory space occupied by the firmware volume > > - // > > - > > - SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 > > (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 > > (PcdSystemMemorySize); > > - FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + > > (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); > > - > > - // EDK2 does not have the concept of boot firmware copied into > > DRAM. To avoid the DXE > > - // core to overwrite this area we must mark the region with the > > attribute non-present > > - if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && > (FdTop <= SystemMemoryTop)) { > > - Found = FALSE; > > - > > - // Search for System Memory Hob that contains the firmware > > - NextHob.Raw = GetHobList (); > > - while ((NextHob.Raw = GetNextHob > (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { > > - if ((NextHob.ResourceDescriptor->ResourceType == > EFI_RESOURCE_SYSTEM_MEMORY) && > > - (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor- > >PhysicalStart) && > > - (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + > NextHob.ResourceDescriptor->ResourceLength)) > > - { > > - ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute; > > - ResourceLength = NextHob.ResourceDescriptor->ResourceLength; > > - ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + > ResourceLength; > > - > > - if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor- > >PhysicalStart) { > > - if (SystemMemoryTop == FdTop) { > > - NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes > & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; > > - } else { > > - // Create the System Memory HOB for the firmware with the non- > present attribute > > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > > - ResourceAttributes & > ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > > - PcdGet64 (PcdFdBaseAddress), > > - PcdGet32 (PcdFdSize)); > > - > > - // Top of the FD is system memory available for UEFI > > - NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); > > - NextHob.ResourceDescriptor->ResourceLength -= > PcdGet32(PcdFdSize); > > - } > > - } else { > > - // Create the System Memory HOB for the firmware with the non- > present attribute > > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > > - ResourceAttributes & > ~EFI_RESOURCE_ATTRIBUTE_PRESENT, > > - PcdGet64 (PcdFdBaseAddress), > > - PcdGet32 (PcdFdSize)); > > - > > - // Update the HOB > > - NextHob.ResourceDescriptor->ResourceLength = PcdGet64 > (PcdFdBaseAddress) - > > NextHob.ResourceDescriptor->PhysicalStart; > > - > > - // If there is some memory available on the top of the FD then create a > HOB > > - if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + > ResourceLength) { > > - // Create the System Memory HOB for the remaining region (top of the > FD) > > - BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, > > - ResourceAttributes, > > - FdTop, > > - ResourceTop - FdTop); > > - } > > - } > > - Found = TRUE; > > - break; > > - } > > - NextHob.Raw = GET_NEXT_HOB (NextHob); > > - } > > - > > - ASSERT(Found); > > - } > > - > > // Build Memory Allocation Hob > > InitMmu (MemoryTable); > > > > -- > > 1.9.1 > > > > _______________________________________________ > > edk2-devel mailing list > > edk2-devel@lists.01.org > > https://lists.01.org/mailman/listinfo/edk2-devel > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel ^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2017-11-30 14:29 UTC | newest] Thread overview: 19+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-09-15 14:32 [PATCH] RFC Inform UEFI memory to Linux Meenakshi Aggarwal 2017-09-15 10:13 ` Leif Lindholm 2017-09-15 22:55 ` Ard Biesheuvel 2017-09-18 4:07 ` Udit Kumar 2017-09-18 4:30 ` Ard Biesheuvel 2017-09-19 12:32 ` [PATCH v2] PeiLib : " Meenakshi Aggarwal 2017-09-19 8:07 ` Sakar Arora 2017-09-19 10:10 ` Udit Kumar 2017-09-19 11:20 ` Sakar Arora 2017-09-19 12:46 ` Udit Kumar 2017-09-19 12:48 ` Ard Biesheuvel 2017-09-20 5:32 ` Sakar Arora 2017-09-20 6:32 ` Ard Biesheuvel 2017-09-20 8:20 ` Sakar Arora 2017-09-25 5:47 ` Meenakshi Aggarwal 2017-11-30 10:07 ` Udit Kumar 2017-11-30 14:33 ` Ard Biesheuvel 2017-09-20 14:59 ` Gao, Liming 2017-09-21 5:59 ` Udit Kumar
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox