[U-Boot] [PATCH v2 2/9] efi_loader: fix efi_find_free_memory()

Heinrich Schuchardt xypron.glpk at gmx.de
Tue Nov 13 21:21:12 UTC 2018


On 11/13/18 9:56 PM, Alexander Graf wrote:
> 
> 
> On 12.11.18 18:55, Heinrich Schuchardt wrote:
>> In efi_find_free_memory() the sandbox uses its virtual address space.
>> Add the missing mapping.
>>
>> Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
> 
> The real bug here is much worse. According to 2.3.4 "x64 Platforms" of
> the UEFI spec:
> 
> ===
> Paging mode is enabled and any memory space defined by the UEFI memory
> map is identity mapped (virtual address equals physical address),
> although the attributes of certain regions may not have all read, write,
> and execute attributes or be unmarked for purposes of platform
> protection. The mappings to other regions are undefined and may vary
> from implementation to implementation.
> ===
> 
> This means we can't have virtual != physical. We need to go with all
> physical (pointers) instead. Anything else violates the spec.
> 
> 
> Alex

The sandbox runs inside of Linux. In user space we will never have
access to physical memory addresses (see the mmap() man page).

My understanding is that for sandbox testing to run smoothly all
addresses seen on the sandbox in the user interface are neither physical
nor virtual addresses in the CPU sense but exist in a 3rd address space
only known to the sandbox.

Without implementing a virtual machine we will never implement
SetVirtualAddressMap() on the sandbox. And with a virtual machine we
would loose all the advantages of the sandbox.

With the current setup we should be able to run the EFI shell and even
SCT on the sandbox as long as SetVirtualAddressMap() is not reached. But
we will never boot an operating system on the sandbox.

Best regards

Heinrich

> 
>> ---
>> v2:
>> 	no change
>> ---
>>  lib/efi_loader/efi_memory.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
>> index dc282fe249f..c0277355056 100644
>> --- a/lib/efi_loader/efi_memory.c
>> +++ b/lib/efi_loader/efi_memory.c
>> @@ -294,6 +294,9 @@ static uint64_t efi_find_free_memory(uint64_t len, uint64_t max_addr)
>>  {
>>  	struct list_head *lhandle;
>>  
>> +	/* Map to virtual address on sandbox */
>> +	max_addr = map_to_sysmem((void *)(uintptr_t)max_addr);
>> +
>>  	/*
>>  	 * Prealign input max address, so we simplify our matching
>>  	 * logic below and can just reuse it as return pointer.
>>
> 



More information about the U-Boot mailing list