[if gte mso 9]>

Re: [edk2] [PATCH] MdeModulePkg/Dxe: Fixed the function FindFreePages() when a free region is found at 0x0

Subject: Re: [edk2] [PATCH] MdeModulePkg/Dxe: Fixed the function FindFreePages() when a free region is found at 0x0

From: "Olivier Martin" <olivier.martin@arm.com>

To: "'Sun, Rui'" <rui.sun@intel.com>, <edk2-devel@lists.sourceforge.net>

Date: 2012-02-21 20:14:56

Thanks Sun for your response,

I understand your concern to change AllocatePages() behaviour. I am also aware that enable the ‘0x0’ address as a valid address for some platforms could have some consequences on using some functions (eg: use of ZeroMem())

 

To explain you the context, some legacy ARM Linux kernels requires the Linux kernel arguments to be located in the first 16KiB of RAM.  I do not know in advance how big are going to be the arguments, so I use gBS->AllocatePages(AllocateMaxAddress, SizeOfMyArguments).

I could add a workaround in this use case in case AllocatePages() returns EFI_OUT_OF_MEMORY and the System Memory starts at 0x0 to allocate gBS->AllocatePages(AllocateAddress, Base:0x0, Size:16KiB) but this solution is not really elegant but I guess I have to go for that.

 

 

From: Sun, Rui [mailto:rui.sun@intel.com]
Sent: 15 February 2012 03:10
To: Olivier Martin; edk2-devel@lists.sourceforge.net
Subject: RE: [edk2] [PATCH] MdeModulePkg/Dxe: Fixed the function FindFreePages() when a free region is found at 0x0

 

Olivier,

 

If gBS->AllocatePages() with AllocateAnyPages or AllocateMaxAddress can return address 0, it will conflict with NULL in current code base and break existing code. For example, the AllocatePages() of MemoryAllocationLib will break because returning NULL indicates failed allocation. A lot of functions treat a parameter of NULL address as invalid, it may have problem if passing the allocated page address returned from gBS->AllocatePages() to such functions. For example, pass result from gBS->AllocatePages() to ZeroMem() function will cause an ASSERT if the buffer address is 0.

 

For platforms that address 0 is reserved for architectural usage, gBS->AllocatePages() using AllocateAddress for address 0x0 is appropriate. For platforms that address 0 is not reserved and is free for any allocation, is it possible to reserve the page starting at 0 in the memory map and keep the current implementation?

 

 

From: Olivier Martin [mailto:olivier.martin@arm.com]
Sent: Wednesday, February 15, 2012 12:16 AM
To: edk2-devel@lists.sourceforge.net; Sun, Rui
Subject: RE: [edk2] [PATCH] MdeModulePkg/Dxe: Fixed the function FindFreePages() when a free region is found at 0x0

 

Mike,

 

Yes, it is correct the use case is using gBS->AllocatePages() with AllocateAnyPages or AllocateMaxAddress when the only memory available is located at 0x0.

 

Best Regards,

Olivier

 

From: Kinney, Michael D [mailto:michael.d.kinney@intel.com]
Sent: 30 January 2012 16:55
To: edk2-devel@lists.sourceforge.net; Sun, Rui
Subject: Re: [edk2] [PATCH] MdeModulePkg/Dxe: Fixed the function FindFreePages() when a free region is found at 0x0

 

Olivier,

 

Is the use case here a call to gBS->AllocatePages() using AllocateAnyPages or AllocateMaxAddress, and the only free memory range available to satisfy the request starts at address 0x0?

 

I expect that gBS->AllocatePages() using AllocateAddress for address 0x0 works without this change.

 

Thanks,

 

Mike

 

From: Olivier Martin [mailto:olivier.martin@arm.com]
Sent: Thursday, January 26, 2012 2:18 PM
To: Sun, Rui
Cc: edk2-devel@lists.sourceforge.net
Subject: [edk2] [PATCH] MdeModulePkg/Dxe: Fixed the function FindFreePages() when a free region is found at 0x0

 

Dear EDK2 community and MdeModulePkg maintainer,

 

Please find the attached patch to fix FindFreePages() when a free region is found at 0x0.

FindFreePages() is returning 0x0 when no free region was found.

But it could be possible the region at 0x0 might be the only possible region returned by FindFreePages() on platforms with system memory that starts at 0x0.

In this case, it should be possible to make the difference between the region 0x0 and the 'not found' error.

 

The direct and indirect callers of FindFreePages() have also be modified to handle the change.

 

Bets Regards,

Olivier