linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86, efi: Only print warning when desc_size is smaller than defined one.
@ 2011-04-26 22:42 Yinghai Lu
  2011-04-27 11:39 ` Matt Fleming
  0 siblings, 1 reply; 4+ messages in thread
From: Yinghai Lu @ 2011-04-26 22:42 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Huang Ying; +Cc: linux-kernel


One system get warning:
	Kernel-defined memdesc doesn't match the one from EFI!

UEFI spec allows GetMemoryMap() return bigger desc_size and desc_ver for future
extension.
And desc_size is already used to get offset of next memory entry.

Only need to check if desc_size is smaller than defined struct.

Also print the size in warning if it happens.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/platform/efi/efi.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Index: linux-2.6/arch/x86/platform/efi/efi.c
===================================================================
--- linux-2.6.orig/arch/x86/platform/efi/efi.c
+++ linux-2.6/arch/x86/platform/efi/efi.c
@@ -448,9 +448,10 @@ void __init efi_init(void)
 		printk(KERN_ERR "Could not map the EFI memory map!\n");
 	memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);
 
-	if (memmap.desc_size != sizeof(efi_memory_desc_t))
+	if (memmap.desc_size < sizeof(efi_memory_desc_t))
 		printk(KERN_WARNING
-		  "Kernel-defined memdesc doesn't match the one from EFI!\n");
+		  "Kernel-defined memdesc size is bigger than the one from EFI! %ld > %ld\n",
+			 sizeof(efi_memory_desc_t), memmap.desc_size);
 
 	if (add_efi_memmap)
 		do_add_efi_memmap();

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86, efi: Only print warning when desc_size is smaller than defined one.
  2011-04-26 22:42 [PATCH] x86, efi: Only print warning when desc_size is smaller than defined one Yinghai Lu
@ 2011-04-27 11:39 ` Matt Fleming
  2011-04-27 17:22   ` Yinghai Lu
  0 siblings, 1 reply; 4+ messages in thread
From: Matt Fleming @ 2011-04-27 11:39 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Huang Ying, linux-kernel

On Tue, 26 Apr 2011 15:42:24 -0700
Yinghai Lu <yinghai@kernel.org> wrote:

> 
> One system get warning:
> 	Kernel-defined memdesc doesn't match the one from EFI!
> 
> UEFI spec allows GetMemoryMap() return bigger desc_size and desc_ver for future
> extension.
> And desc_size is already used to get offset of next memory entry.
> 
> Only need to check if desc_size is smaller than defined struct.
> 
> Also print the size in warning if it happens.
> 
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> 
> ---
>  arch/x86/platform/efi/efi.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> Index: linux-2.6/arch/x86/platform/efi/efi.c
> ===================================================================
> --- linux-2.6.orig/arch/x86/platform/efi/efi.c
> +++ linux-2.6/arch/x86/platform/efi/efi.c
> @@ -448,9 +448,10 @@ void __init efi_init(void)
>  		printk(KERN_ERR "Could not map the EFI memory map!\n");
>  	memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);
>  
> -	if (memmap.desc_size != sizeof(efi_memory_desc_t))
> +	if (memmap.desc_size < sizeof(efi_memory_desc_t))
>  		printk(KERN_WARNING
> -		  "Kernel-defined memdesc doesn't match the one from EFI!\n");
> +		  "Kernel-defined memdesc size is bigger than the one from EFI! %ld > %ld\n",
> +			 sizeof(efi_memory_desc_t), memmap.desc_size);

Does it make sense for this to just be a warning? If
sizeof(efi_memory_desec_t) > sizeof(memmap.desc_size) aren't we going
to run into some pretty serious problems when we start accessing
memory descriptors?

Would it not make more sense for this to be a BUG_ON()? In the unlikely
event that the kernel's efi_memory_desc_t is too large I really don't
see how we can recover from that.

-- 
Matt Fleming, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86, efi: Only print warning when desc_size is smaller than defined one.
  2011-04-27 11:39 ` Matt Fleming
@ 2011-04-27 17:22   ` Yinghai Lu
  2011-04-28 13:05     ` Matthew Garrett
  0 siblings, 1 reply; 4+ messages in thread
From: Yinghai Lu @ 2011-04-27 17:22 UTC (permalink / raw)
  To: Matt Fleming
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Huang Ying, linux-kernel

On 04/27/2011 04:39 AM, Matt Fleming wrote:
> On Tue, 26 Apr 2011 15:42:24 -0700
> Yinghai Lu <yinghai@kernel.org> wrote:
> 
>>
>> One system get warning:
>> 	Kernel-defined memdesc doesn't match the one from EFI!
>>
>> UEFI spec allows GetMemoryMap() return bigger desc_size and desc_ver for future
>> extension.
>> And desc_size is already used to get offset of next memory entry.
>>
>> Only need to check if desc_size is smaller than defined struct.
>>
>> Also print the size in warning if it happens.
>>
>> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
>>
>> ---
>>  arch/x86/platform/efi/efi.c |    5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> Index: linux-2.6/arch/x86/platform/efi/efi.c
>> ===================================================================
>> --- linux-2.6.orig/arch/x86/platform/efi/efi.c
>> +++ linux-2.6/arch/x86/platform/efi/efi.c
>> @@ -448,9 +448,10 @@ void __init efi_init(void)
>>  		printk(KERN_ERR "Could not map the EFI memory map!\n");
>>  	memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);
>>  
>> -	if (memmap.desc_size != sizeof(efi_memory_desc_t))
>> +	if (memmap.desc_size < sizeof(efi_memory_desc_t))
>>  		printk(KERN_WARNING
>> -		  "Kernel-defined memdesc doesn't match the one from EFI!\n");
>> +		  "Kernel-defined memdesc size is bigger than the one from EFI! %ld > %ld\n",
>> +			 sizeof(efi_memory_desc_t), memmap.desc_size);
> 
> Does it make sense for this to just be a warning? If
> sizeof(efi_memory_desec_t) > sizeof(memmap.desc_size) aren't we going
> to run into some pretty serious problems when we start accessing
> memory descriptors?
> 
> Would it not make more sense for this to be a BUG_ON()? In the unlikely
> event that the kernel's efi_memory_desc_t is too large I really don't
> see how we can recover from that.

Using WARNING is ok here.

1. bootloader aka grub.efi will convert efi memmap to e820 memmap and pass it in boot params.
   and current grub.efi does not compare desc_size and struct size.
2. kernel efi.c will only need to use desc_size when
   a. do_add_efi_memmap when "add_efi_memmap" is appended. it will add more entries in case bootloader miss some.
   b. for print_efi_memmap() debug purpose.

So if that efi_memmap is broken, those code can not be reached.

other case: if efi_memmap is broken or bootloader does not convert it properly. user could specify mem= or memmap= to pass info to boot.
if they can boot, print_efi_memmap could print out the messed up memmap for them.
if you change to BUG_ON, they can not boot anymore.

Thanks

Yinghai Lu

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86, efi: Only print warning when desc_size is smaller than defined one.
  2011-04-27 17:22   ` Yinghai Lu
@ 2011-04-28 13:05     ` Matthew Garrett
  0 siblings, 0 replies; 4+ messages in thread
From: Matthew Garrett @ 2011-04-28 13:05 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Matt Fleming, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	Huang Ying, linux-kernel

On Wed, Apr 27, 2011 at 10:22:25AM -0700, Yinghai Lu wrote:

> 1. bootloader aka grub.efi will convert efi memmap to e820 memmap and pass it in boot params.
>    and current grub.efi does not compare desc_size and struct size.

So we'll already have crashed and burned before we got here, and so this 
check will never fire. I sent a patch to just remove the message on the 
28th of March.

There's no way someody could ship a system with a desc_size that's 
smaller than sizeof(memdesc). It wouldn't boot anything.

-- 
Matthew Garrett | mjg59@srcf.ucam.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-04-28 13:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-26 22:42 [PATCH] x86, efi: Only print warning when desc_size is smaller than defined one Yinghai Lu
2011-04-27 11:39 ` Matt Fleming
2011-04-27 17:22   ` Yinghai Lu
2011-04-28 13:05     ` Matthew Garrett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).