* [PATCH] x86/efi: page align EFI ROM image ranges
@ 2017-08-02 16:41 Stuart Hayes
2017-08-04 12:06 ` Matt Fleming
0 siblings, 1 reply; 7+ messages in thread
From: Stuart Hayes @ 2017-08-02 16:41 UTC (permalink / raw)
To: Matt Fleming
Cc: Ard Biesheuvel, H. Peter Anvin,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-efi-u79uwXL29TY76Z2rM5mHXA, x86-DgEjT+Ai2ygdnm+yROfE0A
(Resend because I mistyped the maintainer's email address the first time.)
The kernel's EFI stub locates and copies EFI ROM images into memory, which it allocates using the byte-granular EFI allocate_pool function. These memory ranges are then added to setup_data, and later to e820 (in e820__reserve_setup_data()). The e820 ranges are parsed to create nosave regions (in e820__register_nosave_regions()), but when non-page-aligned e820 regions are parsed, a nosave page is added at the beginning and end of each non-page-aligned region, which results in data not getting saved or restored during a hibernate/resume. This can result in random failures after a hibernate/resume.
Round up the allocation size to a whole number of pages, and use EFI allocate_pages to ensure that the EFI ROM copy regions are page-aligned.
On a system with six EFI ROM images, before the patch:
e820: update [mem 0x64866020-0x6486e05f] usable ==> usable
e820: update [mem 0x6147a020-0x61499c5f] usable ==> usable
e820: update [mem 0x60fff020-0x6105785f] usable ==> usable
e820: update [mem 0x60fa6020-0x60ffe85f] usable ==> usable
e820: update [mem 0x60f4d020-0x60fa585f] usable ==> usable
e820: update [mem 0x60ef4020-0x60f4c85f] usable ==> usable
...
PM: Registered nosave memory: [mem 0x00000000-0x00000fff]
PM: Registered nosave memory: [mem 0x000a0000-0x000fffff]
PM: Registered nosave memory: [mem 0x60ef4000-0x60ef4fff]
PM: Registered nosave memory: [mem 0x60f4c000-0x60f4cfff]
PM: Registered nosave memory: [mem 0x60f4d000-0x60f4dfff]
PM: Registered nosave memory: [mem 0x60fa5000-0x60fa5fff]
PM: Registered nosave memory: [mem 0x60fa6000-0x60fa6fff]
PM: Registered nosave memory: [mem 0x60ffe000-0x60ffefff]
PM: Registered nosave memory: [mem 0x60fff000-0x60ffffff]
PM: Registered nosave memory: [mem 0x61057000-0x61057fff]
PM: Registered nosave memory: [mem 0x6147a000-0x6147afff]
PM: Registered nosave memory: [mem 0x61499000-0x61499fff]
PM: Registered nosave memory: [mem 0x64866000-0x64866fff]
PM: Registered nosave memory: [mem 0x6486e000-0x6486efff]
PM: Registered nosave memory: [mem 0x6cf6e000-0x6f3ccfff]
After the patch:
e820: update [mem 0x64866000-0x6486efff] usable ==> usable
e820: update [mem 0x6147a000-0x61499fff] usable ==> usable
e820: update [mem 0x60fff000-0x61057fff] usable ==> usable
e820: update [mem 0x60fa6000-0x60ffefff] usable ==> usable
e820: update [mem 0x60f4d000-0x60fa5fff] usable ==> usable
e820: update [mem 0x60ef4000-0x60f4cfff] usable ==> usable
...
PM: Registered nosave memory: [mem 0x00000000-0x00000fff]
PM: Registered nosave memory: [mem 0x000a0000-0x000fffff]
PM: Registered nosave memory: [mem 0x6cf6e000-0x6f3ccfff]
Signed-off-by: Stuart Hayes <stuart.w.hayes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
--- linux-4.13-rc2/arch/x86/boot/compressed/eboot.c.orig 2017-08-01 12:12:04.696049106 -0400
+++ linux-4.13-rc2/arch/x86/boot/compressed/eboot.c 2017-08-01 12:11:33.120182236 -0400
@@ -235,7 +235,12 @@ __setup_efi_pci64(efi_pci_io_protocol_64
size = pci->romsize + sizeof(*rom);
- status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom);
+ /*
+ * Get whole pages because this will be added to e820.
+ */
+ size = PAGE_ALIGN(size);
+ status = efi_call_early(allocate_pages, EFI_ALLOCATE_ANY_PAGES,
+ EFI_LOADER_DATA, (size >> PAGE_SHIFT), &rom);
if (status != EFI_SUCCESS) {
efi_printk(sys_table, "Failed to alloc mem for rom\n");
return status;
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] x86/efi: page align EFI ROM image ranges 2017-08-02 16:41 [PATCH] x86/efi: page align EFI ROM image ranges Stuart Hayes @ 2017-08-04 12:06 ` Matt Fleming [not found] ` <20170804120650.GE8187-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Matt Fleming @ 2017-08-04 12:06 UTC (permalink / raw) To: Stuart Hayes; +Cc: Ard Biesheuvel, H. Peter Anvin, linux-kernel, linux-efi, x86 On Wed, 02 Aug, at 11:41:38AM, Stuart Hayes wrote: > (Resend because I mistyped the maintainer's email address the first time.) > > The kernel's EFI stub locates and copies EFI ROM images into memory, > which it allocates using the byte-granular EFI allocate_pool > function. These memory ranges are then added to setup_data, and > later to e820 (in e820__reserve_setup_data()). The e820 ranges are > parsed to create nosave regions (in > e820__register_nosave_regions()), but when non-page-aligned e820 > regions are parsed, a nosave page is added at the beginning and end > of each non-page-aligned region, which results in data not getting > saved or restored during a hibernate/resume. This can result in > random failures after a hibernate/resume. > > Round up the allocation size to a whole number of pages, and use EFI > allocate_pages to ensure that the EFI ROM copy regions are > page-aligned. > > On a system with six EFI ROM images, before the patch: > > e820: update [mem 0x64866020-0x6486e05f] usable ==> usable > e820: update [mem 0x6147a020-0x61499c5f] usable ==> usable > e820: update [mem 0x60fff020-0x6105785f] usable ==> usable > e820: update [mem 0x60fa6020-0x60ffe85f] usable ==> usable > e820: update [mem 0x60f4d020-0x60fa585f] usable ==> usable > e820: update [mem 0x60ef4020-0x60f4c85f] usable ==> usable > ... > PM: Registered nosave memory: [mem 0x00000000-0x00000fff] > PM: Registered nosave memory: [mem 0x000a0000-0x000fffff] > PM: Registered nosave memory: [mem 0x60ef4000-0x60ef4fff] > PM: Registered nosave memory: [mem 0x60f4c000-0x60f4cfff] > PM: Registered nosave memory: [mem 0x60f4d000-0x60f4dfff] > PM: Registered nosave memory: [mem 0x60fa5000-0x60fa5fff] > PM: Registered nosave memory: [mem 0x60fa6000-0x60fa6fff] > PM: Registered nosave memory: [mem 0x60ffe000-0x60ffefff] > PM: Registered nosave memory: [mem 0x60fff000-0x60ffffff] > PM: Registered nosave memory: [mem 0x61057000-0x61057fff] > PM: Registered nosave memory: [mem 0x6147a000-0x6147afff] > PM: Registered nosave memory: [mem 0x61499000-0x61499fff] > PM: Registered nosave memory: [mem 0x64866000-0x64866fff] > PM: Registered nosave memory: [mem 0x6486e000-0x6486efff] > PM: Registered nosave memory: [mem 0x6cf6e000-0x6f3ccfff] > > After the patch: > > e820: update [mem 0x64866000-0x6486efff] usable ==> usable > e820: update [mem 0x6147a000-0x61499fff] usable ==> usable > e820: update [mem 0x60fff000-0x61057fff] usable ==> usable > e820: update [mem 0x60fa6000-0x60ffefff] usable ==> usable > e820: update [mem 0x60f4d000-0x60fa5fff] usable ==> usable > e820: update [mem 0x60ef4000-0x60f4cfff] usable ==> usable > ... > PM: Registered nosave memory: [mem 0x00000000-0x00000fff] > PM: Registered nosave memory: [mem 0x000a0000-0x000fffff] > PM: Registered nosave memory: [mem 0x6cf6e000-0x6f3ccfff] > > Signed-off-by: Stuart Hayes <stuart.w.hayes@gmail.com> > --- > > --- linux-4.13-rc2/arch/x86/boot/compressed/eboot.c.orig 2017-08-01 12:12:04.696049106 -0400 > +++ linux-4.13-rc2/arch/x86/boot/compressed/eboot.c 2017-08-01 12:11:33.120182236 -0400 > @@ -235,7 +235,12 @@ __setup_efi_pci64(efi_pci_io_protocol_64 > > size = pci->romsize + sizeof(*rom); > > - status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom); > + /* > + * Get whole pages because this will be added to e820. > + */ > + size = PAGE_ALIGN(size); > + status = efi_call_early(allocate_pages, EFI_ALLOCATE_ANY_PAGES, > + EFI_LOADER_DATA, (size >> PAGE_SHIFT), &rom); > if (status != EFI_SUCCESS) { > efi_printk(sys_table, "Failed to alloc mem for rom\n"); > return status; > Nice catch. The comment could do with a little more information, including the fact that it's the e820 nosave code that expects page-aligned ROM regions. Also, you'll need the same fix for __setup_efi_pci32(). ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <20170804120650.GE8187-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>]
* Re: [PATCH] x86/efi: page align EFI ROM image ranges [not found] ` <20170804120650.GE8187-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org> @ 2017-08-10 14:46 ` Ingo Molnar [not found] ` <20170810144637.qpqqr5rs3lhag6av-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Ingo Molnar @ 2017-08-10 14:46 UTC (permalink / raw) To: Matt Fleming Cc: Stuart Hayes, Ard Biesheuvel, H. Peter Anvin, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-efi-u79uwXL29TY76Z2rM5mHXA, x86-DgEjT+Ai2ygdnm+yROfE0A * Matt Fleming <matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org> wrote: > On Wed, 02 Aug, at 11:41:38AM, Stuart Hayes wrote: > > (Resend because I mistyped the maintainer's email address the first time.) > > > > The kernel's EFI stub locates and copies EFI ROM images into memory, > > which it allocates using the byte-granular EFI allocate_pool > > function. These memory ranges are then added to setup_data, and > > later to e820 (in e820__reserve_setup_data()). The e820 ranges are > > parsed to create nosave regions (in > > e820__register_nosave_regions()), but when non-page-aligned e820 > > regions are parsed, a nosave page is added at the beginning and end > > of each non-page-aligned region, which results in data not getting > > saved or restored during a hibernate/resume. This can result in > > random failures after a hibernate/resume. > > > > Round up the allocation size to a whole number of pages, and use EFI > > allocate_pages to ensure that the EFI ROM copy regions are > > page-aligned. > > > > On a system with six EFI ROM images, before the patch: > > > > e820: update [mem 0x64866020-0x6486e05f] usable ==> usable > > e820: update [mem 0x6147a020-0x61499c5f] usable ==> usable > > e820: update [mem 0x60fff020-0x6105785f] usable ==> usable > > e820: update [mem 0x60fa6020-0x60ffe85f] usable ==> usable > > e820: update [mem 0x60f4d020-0x60fa585f] usable ==> usable > > e820: update [mem 0x60ef4020-0x60f4c85f] usable ==> usable > > ... > > PM: Registered nosave memory: [mem 0x00000000-0x00000fff] > > PM: Registered nosave memory: [mem 0x000a0000-0x000fffff] > > PM: Registered nosave memory: [mem 0x60ef4000-0x60ef4fff] > > PM: Registered nosave memory: [mem 0x60f4c000-0x60f4cfff] > > PM: Registered nosave memory: [mem 0x60f4d000-0x60f4dfff] > > PM: Registered nosave memory: [mem 0x60fa5000-0x60fa5fff] > > PM: Registered nosave memory: [mem 0x60fa6000-0x60fa6fff] > > PM: Registered nosave memory: [mem 0x60ffe000-0x60ffefff] > > PM: Registered nosave memory: [mem 0x60fff000-0x60ffffff] > > PM: Registered nosave memory: [mem 0x61057000-0x61057fff] > > PM: Registered nosave memory: [mem 0x6147a000-0x6147afff] > > PM: Registered nosave memory: [mem 0x61499000-0x61499fff] > > PM: Registered nosave memory: [mem 0x64866000-0x64866fff] > > PM: Registered nosave memory: [mem 0x6486e000-0x6486efff] > > PM: Registered nosave memory: [mem 0x6cf6e000-0x6f3ccfff] > > > > After the patch: > > > > e820: update [mem 0x64866000-0x6486efff] usable ==> usable > > e820: update [mem 0x6147a000-0x61499fff] usable ==> usable > > e820: update [mem 0x60fff000-0x61057fff] usable ==> usable > > e820: update [mem 0x60fa6000-0x60ffefff] usable ==> usable > > e820: update [mem 0x60f4d000-0x60fa5fff] usable ==> usable > > e820: update [mem 0x60ef4000-0x60f4cfff] usable ==> usable > > ... > > PM: Registered nosave memory: [mem 0x00000000-0x00000fff] > > PM: Registered nosave memory: [mem 0x000a0000-0x000fffff] > > PM: Registered nosave memory: [mem 0x6cf6e000-0x6f3ccfff] > > > > Signed-off-by: Stuart Hayes <stuart.w.hayes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > --- > > > > --- linux-4.13-rc2/arch/x86/boot/compressed/eboot.c.orig 2017-08-01 12:12:04.696049106 -0400 > > +++ linux-4.13-rc2/arch/x86/boot/compressed/eboot.c 2017-08-01 12:11:33.120182236 -0400 > > @@ -235,7 +235,12 @@ __setup_efi_pci64(efi_pci_io_protocol_64 > > > > size = pci->romsize + sizeof(*rom); > > > > - status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom); > > + /* > > + * Get whole pages because this will be added to e820. > > + */ > > + size = PAGE_ALIGN(size); > > + status = efi_call_early(allocate_pages, EFI_ALLOCATE_ANY_PAGES, > > + EFI_LOADER_DATA, (size >> PAGE_SHIFT), &rom); > > if (status != EFI_SUCCESS) { > > efi_printk(sys_table, "Failed to alloc mem for rom\n"); > > return status; > > > > Nice catch. The comment could do with a little more information, > including the fact that it's the e820 nosave code that expects > page-aligned ROM regions. > > Also, you'll need the same fix for __setup_efi_pci32(). Just a quick ping: is this fix being worked on? Thanks, Ingo ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <20170810144637.qpqqr5rs3lhag6av-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>]
* [PATCH v2] x86/efi: page align EFI ROM image ranges [not found] ` <20170810144637.qpqqr5rs3lhag6av-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> @ 2017-08-10 15:05 ` Stuart Hayes [not found] ` <a215cd33-bbd2-8efa-8acf-8b504e625a46-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2017-08-11 2:42 ` [PATCH] " Stuart Hayes 1 sibling, 1 reply; 7+ messages in thread From: Stuart Hayes @ 2017-08-10 15:05 UTC (permalink / raw) To: Ingo Molnar, Matt Fleming Cc: Ard Biesheuvel, H. Peter Anvin, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-efi-u79uwXL29TY76Z2rM5mHXA, x86-DgEjT+Ai2ygdnm+yROfE0A The kernel's EFI stub locates and copies EFI ROM images into memory, which it allocates using the byte-granular EFI allocate_pool function. These memory ranges are then added to setup_data, and later to e820 (in e820__reserve_setup_data()). The e820 ranges are parsed to create nosave regions (in e820__register_nosave_regions()), but when non-page-aligned e820 regions are parsed, a nosave page is added at the beginning and end of each non-page-aligned region, which results in data not getting saved or restored during a hibernate/resume. This can result in random failures after a hibernate/resume. Round up the allocation size to a whole number of pages, and use EFI allocate_pages to ensure that the EFI ROM copy regions are page-aligned. On a system with six EFI ROM images, before the patch: e820: update [mem 0x64866020-0x6486e05f] usable ==> usable e820: update [mem 0x6147a020-0x61499c5f] usable ==> usable e820: update [mem 0x60fff020-0x6105785f] usable ==> usable e820: update [mem 0x60fa6020-0x60ffe85f] usable ==> usable e820: update [mem 0x60f4d020-0x60fa585f] usable ==> usable e820: update [mem 0x60ef4020-0x60f4c85f] usable ==> usable ... PM: Registered nosave memory: [mem 0x00000000-0x00000fff] PM: Registered nosave memory: [mem 0x000a0000-0x000fffff] PM: Registered nosave memory: [mem 0x60ef4000-0x60ef4fff] PM: Registered nosave memory: [mem 0x60f4c000-0x60f4cfff] PM: Registered nosave memory: [mem 0x60f4d000-0x60f4dfff] PM: Registered nosave memory: [mem 0x60fa5000-0x60fa5fff] PM: Registered nosave memory: [mem 0x60fa6000-0x60fa6fff] PM: Registered nosave memory: [mem 0x60ffe000-0x60ffefff] PM: Registered nosave memory: [mem 0x60fff000-0x60ffffff] PM: Registered nosave memory: [mem 0x61057000-0x61057fff] PM: Registered nosave memory: [mem 0x6147a000-0x6147afff] PM: Registered nosave memory: [mem 0x61499000-0x61499fff] PM: Registered nosave memory: [mem 0x64866000-0x64866fff] PM: Registered nosave memory: [mem 0x6486e000-0x6486efff] PM: Registered nosave memory: [mem 0x6cf6e000-0x6f3ccfff] After the patch: e820: update [mem 0x64866000-0x6486efff] usable ==> usable e820: update [mem 0x6147a000-0x61499fff] usable ==> usable e820: update [mem 0x60fff000-0x61057fff] usable ==> usable e820: update [mem 0x60fa6000-0x60ffefff] usable ==> usable e820: update [mem 0x60f4d000-0x60fa5fff] usable ==> usable e820: update [mem 0x60ef4000-0x60f4cfff] usable ==> usable ... PM: Registered nosave memory: [mem 0x00000000-0x00000fff] PM: Registered nosave memory: [mem 0x000a0000-0x000fffff] PM: Registered nosave memory: [mem 0x6cf6e000-0x6f3ccfff] Signed-off-by: Stuart Hayes <stuart.w.hayes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> --- Changes in V2: Update the comments in the code. Add same fix to __setup_efi_pci32() --- linux-4.13-rc2/arch/x86/boot/compressed/eboot.c.orig 2017-08-01 12:12:04.696049106 -0400 +++ linux-4.13-rc2/arch/x86/boot/compressed/eboot.c 2017-08-07 13:00:15.165374388 -0400 @@ -127,7 +127,13 @@ __setup_efi_pci32(efi_pci_io_protocol_32 size = pci->romsize + sizeof(*rom); - status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom); + /* + * Get whole pages because this will be added to e820, and + * e820__register_nosave_regions() expects page-aligned regions. + */ + size = PAGE_ALIGN(size); + status = efi_call_early(allocate_pages, EFI_ALLOCATE_ANY_PAGES, + EFI_LOADER_DATA, (size >> PAGE_SHIFT), &rom); if (status != EFI_SUCCESS) { efi_printk(sys_table, "Failed to alloc mem for rom\n"); return status; @@ -235,7 +241,13 @@ __setup_efi_pci64(efi_pci_io_protocol_64 size = pci->romsize + sizeof(*rom); - status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom); + /* + * Get whole pages because this will be added to e820, and + * e820__register_nosave_regions() expects page-aligned regions. + */ + size = PAGE_ALIGN(size); + status = efi_call_early(allocate_pages, EFI_ALLOCATE_ANY_PAGES, + EFI_LOADER_DATA, (size >> PAGE_SHIFT), &rom); if (status != EFI_SUCCESS) { efi_printk(sys_table, "Failed to alloc mem for rom\n"); return status; ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <a215cd33-bbd2-8efa-8acf-8b504e625a46-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>]
* Re: [PATCH v2] x86/efi: page align EFI ROM image ranges [not found] ` <a215cd33-bbd2-8efa-8acf-8b504e625a46-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> @ 2017-08-11 12:54 ` Ingo Molnar 0 siblings, 0 replies; 7+ messages in thread From: Ingo Molnar @ 2017-08-11 12:54 UTC (permalink / raw) To: Stuart Hayes Cc: Matt Fleming, Ard Biesheuvel, H. Peter Anvin, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-efi-u79uwXL29TY76Z2rM5mHXA, x86-DgEjT+Ai2ygdnm+yROfE0A * Stuart Hayes <stuart.w.hayes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > The kernel's EFI stub locates and copies EFI ROM images into memory, which it allocates using the byte-granular EFI allocate_pool function. These memory ranges are then added to setup_data, and later to e820 (in e820__reserve_setup_data()). The e820 ranges are parsed to create nosave regions (in e820__register_nosave_regions()), but when non-page-aligned e820 regions are parsed, a nosave page is added at the beginning and end of each non-page-aligned region, which results in data not getting saved or restored during a hibernate/resume. This can result in random failures after a hibernate/resume. > > Round up the allocation size to a whole number of pages, and use EFI allocate_pages to ensure that the EFI ROM copy regions are page-aligned. > > On a system with six EFI ROM images, before the patch: > > e820: update [mem 0x64866020-0x6486e05f] usable ==> usable > e820: update [mem 0x6147a020-0x61499c5f] usable ==> usable > e820: update [mem 0x60fff020-0x6105785f] usable ==> usable > e820: update [mem 0x60fa6020-0x60ffe85f] usable ==> usable > e820: update [mem 0x60f4d020-0x60fa585f] usable ==> usable > e820: update [mem 0x60ef4020-0x60f4c85f] usable ==> usable > ... > PM: Registered nosave memory: [mem 0x00000000-0x00000fff] > PM: Registered nosave memory: [mem 0x000a0000-0x000fffff] > PM: Registered nosave memory: [mem 0x60ef4000-0x60ef4fff] > PM: Registered nosave memory: [mem 0x60f4c000-0x60f4cfff] > PM: Registered nosave memory: [mem 0x60f4d000-0x60f4dfff] > PM: Registered nosave memory: [mem 0x60fa5000-0x60fa5fff] > PM: Registered nosave memory: [mem 0x60fa6000-0x60fa6fff] > PM: Registered nosave memory: [mem 0x60ffe000-0x60ffefff] > PM: Registered nosave memory: [mem 0x60fff000-0x60ffffff] > PM: Registered nosave memory: [mem 0x61057000-0x61057fff] > PM: Registered nosave memory: [mem 0x6147a000-0x6147afff] > PM: Registered nosave memory: [mem 0x61499000-0x61499fff] > PM: Registered nosave memory: [mem 0x64866000-0x64866fff] > PM: Registered nosave memory: [mem 0x6486e000-0x6486efff] > PM: Registered nosave memory: [mem 0x6cf6e000-0x6f3ccfff] > > After the patch: > > e820: update [mem 0x64866000-0x6486efff] usable ==> usable > e820: update [mem 0x6147a000-0x61499fff] usable ==> usable > e820: update [mem 0x60fff000-0x61057fff] usable ==> usable > e820: update [mem 0x60fa6000-0x60ffefff] usable ==> usable > e820: update [mem 0x60f4d000-0x60fa5fff] usable ==> usable > e820: update [mem 0x60ef4000-0x60f4cfff] usable ==> usable > ... > PM: Registered nosave memory: [mem 0x00000000-0x00000fff] > PM: Registered nosave memory: [mem 0x000a0000-0x000fffff] > PM: Registered nosave memory: [mem 0x6cf6e000-0x6f3ccfff] > > Signed-off-by: Stuart Hayes <stuart.w.hayes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > --- > Changes in V2: > Update the comments in the code. > Add same fix to __setup_efi_pci32() > > --- linux-4.13-rc2/arch/x86/boot/compressed/eboot.c.orig 2017-08-01 12:12:04.696049106 -0400 > +++ linux-4.13-rc2/arch/x86/boot/compressed/eboot.c 2017-08-07 13:00:15.165374388 -0400 > @@ -127,7 +127,13 @@ __setup_efi_pci32(efi_pci_io_protocol_32 > > size = pci->romsize + sizeof(*rom); > > - status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom); > + /* > + * Get whole pages because this will be added to e820, and > + * e820__register_nosave_regions() expects page-aligned regions. BTW., could we please also do a separate robustness fix to e820__register_nosave_regions(), which complains about regions that have bad alignment, and fixes them up if possible? That way if with just the robustness fix applied we'd get the warning on your system - and hibernation should work - and with this second fix we'd get a silent bootup and a working system. Or something like that? Thanks, Ingo ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/efi: page align EFI ROM image ranges [not found] ` <20170810144637.qpqqr5rs3lhag6av-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2017-08-10 15:05 ` [PATCH v2] " Stuart Hayes @ 2017-08-11 2:42 ` Stuart Hayes 1 sibling, 0 replies; 7+ messages in thread From: Stuart Hayes @ 2017-08-11 2:42 UTC (permalink / raw) To: Ingo Molnar, Matt Fleming Cc: Ard Biesheuvel, H. Peter Anvin, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-efi-u79uwXL29TY76Z2rM5mHXA, x86-DgEjT+Ai2ygdnm+yROfE0A On 8/10/2017 9:46 AM, Ingo Molnar wrote: > > * Matt Fleming <matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org> wrote: > >> On Wed, 02 Aug, at 11:41:38AM, Stuart Hayes wrote: >>> (Resend because I mistyped the maintainer's email address the first time.) >>> >>> The kernel's EFI stub locates and copies EFI ROM images into memory, >>> which it allocates using the byte-granular EFI allocate_pool >>> function. These memory ranges are then added to setup_data, and >>> later to e820 (in e820__reserve_setup_data()). The e820 ranges are >>> parsed to create nosave regions (in >>> e820__register_nosave_regions()), but when non-page-aligned e820 >>> regions are parsed, a nosave page is added at the beginning and end >>> of each non-page-aligned region, which results in data not getting >>> saved or restored during a hibernate/resume. This can result in >>> random failures after a hibernate/resume. >>> >>> Round up the allocation size to a whole number of pages, and use EFI >>> allocate_pages to ensure that the EFI ROM copy regions are >>> page-aligned. >>> >>> On a system with six EFI ROM images, before the patch: >>> >>> e820: update [mem 0x64866020-0x6486e05f] usable ==> usable >>> e820: update [mem 0x6147a020-0x61499c5f] usable ==> usable >>> e820: update [mem 0x60fff020-0x6105785f] usable ==> usable >>> e820: update [mem 0x60fa6020-0x60ffe85f] usable ==> usable >>> e820: update [mem 0x60f4d020-0x60fa585f] usable ==> usable >>> e820: update [mem 0x60ef4020-0x60f4c85f] usable ==> usable >>> ... >>> PM: Registered nosave memory: [mem 0x00000000-0x00000fff] >>> PM: Registered nosave memory: [mem 0x000a0000-0x000fffff] >>> PM: Registered nosave memory: [mem 0x60ef4000-0x60ef4fff] >>> PM: Registered nosave memory: [mem 0x60f4c000-0x60f4cfff] >>> PM: Registered nosave memory: [mem 0x60f4d000-0x60f4dfff] >>> PM: Registered nosave memory: [mem 0x60fa5000-0x60fa5fff] >>> PM: Registered nosave memory: [mem 0x60fa6000-0x60fa6fff] >>> PM: Registered nosave memory: [mem 0x60ffe000-0x60ffefff] >>> PM: Registered nosave memory: [mem 0x60fff000-0x60ffffff] >>> PM: Registered nosave memory: [mem 0x61057000-0x61057fff] >>> PM: Registered nosave memory: [mem 0x6147a000-0x6147afff] >>> PM: Registered nosave memory: [mem 0x61499000-0x61499fff] >>> PM: Registered nosave memory: [mem 0x64866000-0x64866fff] >>> PM: Registered nosave memory: [mem 0x6486e000-0x6486efff] >>> PM: Registered nosave memory: [mem 0x6cf6e000-0x6f3ccfff] >>> >>> After the patch: >>> >>> e820: update [mem 0x64866000-0x6486efff] usable ==> usable >>> e820: update [mem 0x6147a000-0x61499fff] usable ==> usable >>> e820: update [mem 0x60fff000-0x61057fff] usable ==> usable >>> e820: update [mem 0x60fa6000-0x60ffefff] usable ==> usable >>> e820: update [mem 0x60f4d000-0x60fa5fff] usable ==> usable >>> e820: update [mem 0x60ef4000-0x60f4cfff] usable ==> usable >>> ... >>> PM: Registered nosave memory: [mem 0x00000000-0x00000fff] >>> PM: Registered nosave memory: [mem 0x000a0000-0x000fffff] >>> PM: Registered nosave memory: [mem 0x6cf6e000-0x6f3ccfff] >>> >>> Signed-off-by: Stuart Hayes <stuart.w.hayes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>> --- >>> >>> --- linux-4.13-rc2/arch/x86/boot/compressed/eboot.c.orig 2017-08-01 12:12:04.696049106 -0400 >>> +++ linux-4.13-rc2/arch/x86/boot/compressed/eboot.c 2017-08-01 12:11:33.120182236 -0400 >>> @@ -235,7 +235,12 @@ __setup_efi_pci64(efi_pci_io_protocol_64 >>> >>> size = pci->romsize + sizeof(*rom); >>> >>> - status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom); >>> + /* >>> + * Get whole pages because this will be added to e820. >>> + */ >>> + size = PAGE_ALIGN(size); >>> + status = efi_call_early(allocate_pages, EFI_ALLOCATE_ANY_PAGES, >>> + EFI_LOADER_DATA, (size >> PAGE_SHIFT), &rom); >>> if (status != EFI_SUCCESS) { >>> efi_printk(sys_table, "Failed to alloc mem for rom\n"); >>> return status; >>> >> >> Nice catch. The comment could do with a little more information, >> including the fact that it's the e820 nosave code that expects >> page-aligned ROM regions. >> >> Also, you'll need the same fix for __setup_efi_pci32(). > > Just a quick ping: is this fix being worked on? > > Thanks, > > Ingo > Yes... I sent a v2 patch earlier today. Sorry for the delay. Thanks Stuart ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] x86/efi: page align EFI ROM image ranges
@ 2017-08-02 16:28 Stuart Hayes
0 siblings, 0 replies; 7+ messages in thread
From: Stuart Hayes @ 2017-08-02 16:28 UTC (permalink / raw)
To: Matt Fleming; +Cc: linux-kernel, linux-efi, x86, Ard Biesheuvel, H. Peter Anvin
The kernel's EFI stub locates and copies EFI ROM images into memory, which it allocates using the byte-granular EFI allocate_pool function. These memory ranges are then added to setup_data, and later to e820 (in e820__reserve_setup_data()). The e820 ranges are parsed to create nosave regions (in e820__register_nosave_regions()), but when non-page-aligned e820 regions are parsed, a nosave page is added at the beginning and end of each non-page-aligned region, which results in data not getting saved or restored during a hibernate/resume. This can result in random failures after a hibernate/resume.
Round up the allocation size to a whole number of pages, and use EFI allocate_pages to ensure that the EFI ROM copy regions are page-aligned.
On a system with six EFI ROM images, before the patch:
e820: update [mem 0x64866020-0x6486e05f] usable ==> usable
e820: update [mem 0x6147a020-0x61499c5f] usable ==> usable
e820: update [mem 0x60fff020-0x6105785f] usable ==> usable
e820: update [mem 0x60fa6020-0x60ffe85f] usable ==> usable
e820: update [mem 0x60f4d020-0x60fa585f] usable ==> usable
e820: update [mem 0x60ef4020-0x60f4c85f] usable ==> usable
...
PM: Registered nosave memory: [mem 0x00000000-0x00000fff]
PM: Registered nosave memory: [mem 0x000a0000-0x000fffff]
PM: Registered nosave memory: [mem 0x60ef4000-0x60ef4fff]
PM: Registered nosave memory: [mem 0x60f4c000-0x60f4cfff]
PM: Registered nosave memory: [mem 0x60f4d000-0x60f4dfff]
PM: Registered nosave memory: [mem 0x60fa5000-0x60fa5fff]
PM: Registered nosave memory: [mem 0x60fa6000-0x60fa6fff]
PM: Registered nosave memory: [mem 0x60ffe000-0x60ffefff]
PM: Registered nosave memory: [mem 0x60fff000-0x60ffffff]
PM: Registered nosave memory: [mem 0x61057000-0x61057fff]
PM: Registered nosave memory: [mem 0x6147a000-0x6147afff]
PM: Registered nosave memory: [mem 0x61499000-0x61499fff]
PM: Registered nosave memory: [mem 0x64866000-0x64866fff]
PM: Registered nosave memory: [mem 0x6486e000-0x6486efff]
PM: Registered nosave memory: [mem 0x6cf6e000-0x6f3ccfff]
After the patch:
e820: update [mem 0x64866000-0x6486efff] usable ==> usable
e820: update [mem 0x6147a000-0x61499fff] usable ==> usable
e820: update [mem 0x60fff000-0x61057fff] usable ==> usable
e820: update [mem 0x60fa6000-0x60ffefff] usable ==> usable
e820: update [mem 0x60f4d000-0x60fa5fff] usable ==> usable
e820: update [mem 0x60ef4000-0x60f4cfff] usable ==> usable
...
PM: Registered nosave memory: [mem 0x00000000-0x00000fff]
PM: Registered nosave memory: [mem 0x000a0000-0x000fffff]
PM: Registered nosave memory: [mem 0x6cf6e000-0x6f3ccfff]
Signed-off-by: Stuart Hayes <stuart.w.hayes@gmail.com>
---
--- linux-4.13-rc2/arch/x86/boot/compressed/eboot.c.orig 2017-08-01 12:12:04.696049106 -0400
+++ linux-4.13-rc2/arch/x86/boot/compressed/eboot.c 2017-08-01 12:11:33.120182236 -0400
@@ -235,7 +235,12 @@ __setup_efi_pci64(efi_pci_io_protocol_64
size = pci->romsize + sizeof(*rom);
- status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom);
+ /*
+ * Get whole pages because this will be added to e820.
+ */
+ size = PAGE_ALIGN(size);
+ status = efi_call_early(allocate_pages, EFI_ALLOCATE_ANY_PAGES,
+ EFI_LOADER_DATA, (size >> PAGE_SHIFT), &rom);
if (status != EFI_SUCCESS) {
efi_printk(sys_table, "Failed to alloc mem for rom\n");
return status;
^ permalink raw reply [flat|nested] 7+ messages in threadend of thread, other threads:[~2017-08-11 12:54 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-02 16:41 [PATCH] x86/efi: page align EFI ROM image ranges Stuart Hayes
2017-08-04 12:06 ` Matt Fleming
[not found] ` <20170804120650.GE8187-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2017-08-10 14:46 ` Ingo Molnar
[not found] ` <20170810144637.qpqqr5rs3lhag6av-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-08-10 15:05 ` [PATCH v2] " Stuart Hayes
[not found] ` <a215cd33-bbd2-8efa-8acf-8b504e625a46-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-08-11 12:54 ` Ingo Molnar
2017-08-11 2:42 ` [PATCH] " Stuart Hayes
-- strict thread matches above, loose matches on Subject: below --
2017-08-02 16:28 Stuart Hayes
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox