[if gte mso 9]>
Subject: Re: [edk2] [PATCH] MdeModulePkg/Dxe: Fixed the function FindFreePages() when a free region is found at 0x0
From: "Olivier Martin" <email@example.com>
To: "'Sun, Rui'" <firstname.lastname@example.org>, <email@example.com>
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.
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?
Yes, it is correct the use case is using gBS->AllocatePages() with AllocateAnyPages or AllocateMaxAddress when the only memory available is located at 0x0.
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.
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.