linux-efi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* New EFI thunk alignment WARN_ON in 5.6 triggers multiple times
@ 2020-02-12 11:44 Hans de Goede
  2020-02-12 11:53 ` Ard Biesheuvel
  0 siblings, 1 reply; 12+ messages in thread
From: Hans de Goede @ 2020-02-12 11:44 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: linux-efi

Hi Ard,

While booting 5.6-rc1 on one of my test machines I noticed the WARN_ON
on line 198 of arch/x86/platform/efi/efi_64.c trigger many times.

I've done some debugging on this an this is caused by the following
call path:

drivers/firmware/efi/vars.c: efivar_init():

         unsigned long variable_name_size = 1024;
         efi_char16_t *variable_name;
         efi_guid_t vendor_guid;

         variable_name = kzalloc(variable_name_size, GFP_KERNEL);
         if (!variable_name) {
                 printk(KERN_ERR "efivars: Memory allocation failed.\n");
                 return -ENOMEM;
         }

	...


         do {
                 variable_name_size = 1024;

                 status = ops->get_next_variable(&variable_name_size,
                                                 variable_name,
                                                 &vendor_guid);
	...

arch/x86/platform/efi/efi_64.c: efi_thunk_get_next_variable()

	...
         phys_vendor = virt_to_phys_or_null(vendor);
	...

arch/x86/platform/efi/efi_64.c: virt_to_phys_or_null_size()

	...
	WARN_ON(!IS_ALIGNED((unsigned long)va, size) || bad_size);
	...

Specifically the problem is that the efi_guid_t vendor_guid has an 8 bytes
aligned address and the WARN_ON checks for it being aligned to\
sizeof(efi_guid_t) which is 16 bytes.

I've fixed this for now with the following local fix, but I'm not sure
what the alignment rules actually are so I'm not sure this is correct:

--- a/arch/x86/platform/efi/efi_64.c
+++ b/arch/x86/platform/efi/efi_64.c
@@ -181,6 +181,7 @@ static inline phys_addr_t
  virt_to_phys_or_null_size(void *va, unsigned long size)
  {
  	bool bad_size;
+	int alignment;

  	if (!va)
  		return 0;
@@ -195,7 +196,8 @@ virt_to_phys_or_null_size(void *va, unsigned long size)
  	 */
  	bad_size = size > PAGE_SIZE || !is_power_of_2(size);

-	WARN_ON(!IS_ALIGNED((unsigned long)va, size) || bad_size);
+	alignment = size > 8 ? 8 : size;
+	WARN_ON(!IS_ALIGNED((unsigned long)va, alignment) || bad_size);

  	return slow_virt_to_phys(va);
  }


I have a feeling that this is the right thing to do, but as said I'm not 100%
sure. If you can confirm that this is the right fix, then I can submit this
upstream.

Regards,

Hans


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

end of thread, other threads:[~2020-02-13 10:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-12 11:44 New EFI thunk alignment WARN_ON in 5.6 triggers multiple times Hans de Goede
2020-02-12 11:53 ` Ard Biesheuvel
2020-02-12 15:00   ` Hans de Goede
2020-02-12 21:08     ` Ard Biesheuvel
2020-02-13  7:36       ` Hans de Goede
2020-02-13  8:03         ` Ard Biesheuvel
2020-02-13  8:55           ` Ard Biesheuvel
2020-02-13 10:03             ` Hans de Goede
2020-02-13 10:18               ` Ard Biesheuvel
2020-02-12 21:57     ` Arvind Sankar
2020-02-13  0:34       ` Arvind Sankar
2020-02-13  7:34         ` Hans de Goede

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).