x86/efi: Reserve EFI properties table
PATCH 1/1 x86/efi: Reserve EFI properties table
Some EFI firmware implementations may place the EFI properties table in RAM marked as BootServicesData, which Xen does not consider as reserved. When dom0 tries to access the EFI properties table (which Linux >= 4.4 does), it crashes with a page fault. Fix this by unconditionally marking the EFI properties table as reserved in the E820, much like is done with the dmi regions.
--- xen/arch/x86/efi/efi-boot.h | 8 ++++++++ xen/common/efi/boot.c | 20 ++++++++++++++++++++ xen/common/efi/efi.h | 4 ++++ 3 files changed, 32 insertions(+)
xen/arch/x86/efi/efi-boot.h +8 -0
@@ -209,6 +209,14 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable, } } +if ( efi_properties_tbl_addr && efi_properties_tbl_size ) + { + ++e; + e->addr = efi_properties_tbl_addr; + e->size = efi_properties_tbl_size; + e->type =E820_RESERVED ; + ++e820_raw.nr_map; + } }static void *__init efi_arch_allocate_mmap_buffer (UINTN map_size)
xen/common/efi/boot.c +20 -0
@@ -40,6 +40,8 @@ { 0x605dab50, 0xe046, 0x4300, {0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23} } #define APPLE_PROPERTIES_PROTOCOL_GUID \ { 0x91bd12fe, 0xf6c3, 0x44fb, { 0xa5, 0xb7, 0x51, 0x22, 0xab, 0x30, 0x3a, 0xe0} } +#define EFI_PROPERTIES_TABLE_GUID \ + { 0x880aaca3, 0x4adc, 0x4a04, { 0x90, 0x79, 0xb7, 0x47, 0x34, 0x08, 0x25, 0xe5} } typedef EFI_STATUS (/* _not_ EFIAPI */ *EFI_SHIM_LOCK_VERIFY) (
@@ -171,6 +173,15 @@ static char __section(".bss.page_aligned") __aligned(PAGE_SIZE) ebmalloc_mem[EBMALLOC_SIZE ];static unsigned long __initdata ebmalloc_allocated; +struct efi_properties_table { +u32 version; +u32 length; +u64 memory_protection_attribute; +}; + +u64 __initdata efi_properties_tbl_addr; +u32 __initdata efi_properties_tbl_size; +/* EFI boot allocator. */ static void __init __maybe_unused *ebmalloc (size_t size) {
@@ -809,6 +820,7 @@ static void __init efi_tables(void)static EFI_GUID __initdata mps_guid =MPS_TABLE_GUID ;static EFI_GUID __initdata smbios_guid =SMBIOS_TABLE_GUID ;static EFI_GUID __initdata smbios3_guid =SMBIOS3_TABLE_GUID ; +static EFI_GUID __initdata properties_guid =EFI_PROPERTIES_TABLE_GUID ;if (match_guid (&acpi2_guid, &efi_ct[i].VendorGuid) ) efi.acpi20 = (long )efi_ct[i].VendorTable;
@@ -820,6 +832,14 @@ static void __init efi_tables(void) efi.smbios = (long )efi_ct[i].VendorTable;if (match_guid (&smbios3_guid, &efi_ct[i].VendorGuid) ) efi.smbios3 = (long )efi_ct[i].VendorTable; +if (match_guid (&properties_guid, &efi_ct[i].VendorGuid) ) + { +struct efi_properties_table *properties; + + efi_properties_tbl_addr = (long )efi_ct[i].VendorTable; + properties = (struct efi_properties_table *)efi_properties_tbl_addr; + efi_properties_tbl_size = properties->length; + } }#ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */
xen/common/efi/efi.h +4 -0
@@ -5,6 +5,7 @@#include <efi/efidevp.h> #include <efi/eficapsule.h> #include <efi/efiapi.h> +#include <xen/init.h> #include <xen/efi.h> #include <xen/spinlock.h> #include <asm/page.h>
@@ -39,3 +40,6 @@ extern UINT64 efi_boot_max_var_store_size, efi_boot_remain_var_store_size,extern UINT64 efi_apple_properties_addr;extern UINTN efi_apple_properties_len; + +extern u64 __initdata efi_properties_tbl_addr; +extern u32 __initdata efi_properties_tbl_size;
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 4 lines · Ross Lagerwall
Some EFI firmware implementations may place the EFI properties table in RAM marked as BootServicesData, which Xen does not consider as reserved. When dom0 tries to access the EFI properties table (which Linux >= 4.4 does), it crashes with a page fault.
The pagefault is just a side effect of Linux blindly assuming that the ioremap() request succeeded.
From Xen's point of view, Dom0 tries to map a page which doesn't belong to dom_xen, resulting a permission failure.
Quoted 5 lines
Fix this by unconditionally
marking the EFI properties table as reserved in the E820, much like is done with the dmi regions.Signed-off-by Ross Lagerwall <[email protected]>
This is probably also 4.9 material.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Hi Andrew,
Quoted 16 lines · Andrew Cooper
Quoted 4 lines · Ross Lagerwall
Some EFI firmware implementations may place the EFI properties table in RAM marked as BootServicesData, which Xen does not consider as reserved. When dom0 tries to access the EFI properties table (which Linux >= 4.4 does), it crashes with a page fault.
The pagefault is just a side effect of Linux blindly assuming that the
ioremap()request succeeded.From Xen's point of view, Dom0 tries to map a page which doesn't belong to
dom_xen, resulting a permission failure.Quoted 4 lines
Fix this by unconditionally
marking the EFI properties table as reserved in the E820, much like is done with the dmi regions.
Quoted 5 lines
Quoted 1 line
Signed-off-by Ross Lagerwall <[email protected]>Reviewed-by Andrew Cooper <[email protected]>This is probably also 4.9 material.
It looks like Jan had some comments on this patch. I haven't seen any reply from Ross, I will wait before looking from a release perspective.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 19 lines · Julien Grall
Hi Andrew,
Quoted 16 lines · Andrew Cooper
Quoted 4 lines · Ross Lagerwall
Some EFI firmware implementations may place the EFI properties table in RAM marked as BootServicesData, which Xen does not consider as reserved. When dom0 tries to access the EFI properties table (which Linux >= 4.4 does), it crashes with a page fault.
The pagefault is just a side effect of Linux blindly assuming that the
ioremap()request succeeded.From Xen's point of view, Dom0 tries to map a page which doesn't belong to
dom_xen, resulting a permission failure.Quoted 4 lines
Fix this by unconditionally
marking the EFI properties table as reserved in the E820, much like is done with the dmi regions.
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Ross Lagerwall <[email protected]>Reviewed-by Andrew Cooper <[email protected]>This is probably also 4.9 material.
It looks like Jan had some comments on this patch. I haven't seen any reply from Ross, I will wait before looking from a release perspective.
Jan had some comments on that patch but essentially NAKed it on principle so I don't think it will be going into 4.9.
Thanks,
Signature · 6 lines
Ross Lagerwall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 17.05.17 at 18:21, <[email protected]> wrote:
Quoted 23 lines · Julien Grall
Hi Andrew,
Quoted 20 lines · Andrew Cooper
Quoted 4 lines · Ross Lagerwall
Some EFI firmware implementations may place the EFI properties table in RAM marked as BootServicesData, which Xen does not consider as reserved. When dom0 tries to access the EFI properties table (which Linux >= 4.4 does), it crashes with a page fault.
The pagefault is just a side effect of Linux blindly assuming that the
ioremap()request succeeded.From Xen's point of view, Dom0 tries to map a page which doesn't belong to
dom_xen, resulting a permission failure.Quoted 5 lines
Fix this by unconditionally
marking the EFI properties table as reserved in the E820, much like is done with the dmi regions.Signed-off-by Ross Lagerwall <[email protected]>Reviewed-by Andrew Cooper <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This is probably also 4.9 material.
It looks like Jan had some comments on this patch. I haven't seen any reply from Ross, I will wait before looking from a release perspective.
Jan had some comments on that patch but essentially NAKed it on principle so I don't think it will be going into 4.9.
Let me clarify the NAK a little: Besides there having been no opposition to it (indicating to me that the grounds on which I gave it are acceptable), I'd revisit this if a serious attempt was made to make Linux behave sanely here, and that attempt was (bogusly) rejected. After all Linux is already prepared to deal with there not being any EFI memory map, so it would seem pretty strange to me if they didn't accept a (presumably small) change to skip retrieving the properties table in that case (and perhaps at once the memory attributes one). (And btw, I seem to recall indication that the Dom0 boot problem was due to an unchecked ioremap() or alike call, but afaict 4.11 does have a check there, so I'm currently at a loss to see where the boot failure would come from.)
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 6 lines · Ross Lagerwall
Some EFI firmware implementations may place the EFI properties table in RAM marked as BootServicesData, which Xen does not consider as reserved. When dom0 tries to access the EFI properties table (which Linux >= 4.4 does), it crashes with a page fault. Fix this by unconditionally marking the EFI properties table as reserved in the E820, much like is done with the dmi regions.
And also found who sets this:
https://github.com/tianocore/edk2/blob/1860cb00c18c6f0c58336ea15a63889dabd31d15/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c
Don't know if you want to include that in the blurb so somebody can also look up why it is being set.
Quoted 106 lines
Signed-off-by Ross Lagerwall <[email protected]>--- xen/arch/x86/efi/efi-boot.h | 8 ++++++++ xen/common/efi/boot.c | 20 ++++++++++++++++++++ xen/common/efi/efi.h | 4 ++++ 3 files changed, 32 insertions(+)xen/arch/x86/efi/efi-boot.h +8
-0@@ -209,6 +209,14 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable, } } +if ( efi_properties_tbl_addr && efi_properties_tbl_size ) + { + ++e; + e->addr = efi_properties_tbl_addr; + e->size = efi_properties_tbl_size; + e->type =E820_RESERVED ; + ++e820_raw.nr_map; + } }static void *__init efi_arch_allocate_mmap_buffer (UINTN map_size)xen/common/efi/boot.c +20
-0@@ -40,6 +40,8 @@ { 0x605dab50, 0xe046, 0x4300, {0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23} } #define APPLE_PROPERTIES_PROTOCOL_GUID \ { 0x91bd12fe, 0xf6c3, 0x44fb, { 0xa5, 0xb7, 0x51, 0x22, 0xab, 0x30, 0x3a, 0xe0} } +#define EFI_PROPERTIES_TABLE_GUID \ + { 0x880aaca3, 0x4adc, 0x4a04, { 0x90, 0x79, 0xb7, 0x47, 0x34, 0x08, 0x25, 0xe5} } typedef EFI_STATUS (/* _not_ EFIAPI */ *EFI_SHIM_LOCK_VERIFY) (@@ -171,6 +173,15 @@ static char __section(".bss.page_aligned") __aligned(PAGE_SIZE) ebmalloc_mem[EBMALLOC_SIZE ];static unsigned long __initdata ebmalloc_allocated; +struct efi_properties_table { +u32 version; +u32 length; +u64 memory_protection_attribute; +}; + +u64 __initdata efi_properties_tbl_addr; +u32 __initdata efi_properties_tbl_size; +/* EFI boot allocator. */ static void __init __maybe_unused *ebmalloc (size_t size) {@@ -809,6 +820,7 @@ static void __init efi_tables(void)static EFI_GUID __initdata mps_guid =MPS_TABLE_GUID ;static EFI_GUID __initdata smbios_guid =SMBIOS_TABLE_GUID ;static EFI_GUID __initdata smbios3_guid =SMBIOS3_TABLE_GUID ; +static EFI_GUID __initdata properties_guid =EFI_PROPERTIES_TABLE_GUID ;if (match_guid (&acpi2_guid, &efi_ct[i].VendorGuid) ) efi.acpi20 = (long )efi_ct[i].VendorTable;@@ -820,6 +832,14 @@ static void __init efi_tables(void) efi.smbios = (long )efi_ct[i].VendorTable;if (match_guid (&smbios3_guid, &efi_ct[i].VendorGuid) ) efi.smbios3 = (long )efi_ct[i].VendorTable; +if (match_guid (&properties_guid, &efi_ct[i].VendorGuid) ) + { +struct efi_properties_table *properties; + + efi_properties_tbl_addr = (long )efi_ct[i].VendorTable; + properties = (struct efi_properties_table *)efi_properties_tbl_addr; + efi_properties_tbl_size = properties->length; + } }#ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */ xen/common/efi/efi.h +4
-0@@ -5,6 +5,7 @@#include <efi/efidevp.h> #include <efi/eficapsule.h> #include <efi/efiapi.h> +#include <xen/init.h> #include <xen/efi.h> #include <xen/spinlock.h> #include <asm/page.h> @@ -39,3 +40,6 @@ extern UINT64 efi_boot_max_var_store_size, efi_boot_remain_var_store_size,extern UINT64 efi_apple_properties_addr;extern UINTN efi_apple_properties_len; + +extern u64 __initdata efi_properties_tbl_addr; +extern u32 __initdata efi_properties_tbl_size;Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.05.17 at 18:17, <[email protected]> wrote:
Some EFI firmware implementations may place the EFI properties table in RAM marked as BootServicesData, which Xen does not consider as reserved.
And which is correct. Hence ...
Quoted 3 lines
When dom0 tries to access the EFI properties table (which Linux >= 4.4 does), it crashes with a page fault. Fix this by unconditionally marking the EFI properties table as reserved in the E820,
... "fix this by" is the wrong term, "work around this by" would be more suitable.
But what's worse - Linux has no business looking at the sole bit defined in MemoryProtectionAttribute, as that's relevant to Xen (as the exclusive entity dealing with the machine memory map) only. While I view this by itself as a reason to NAK this patch, I'll nevertheless give a few comments below.
Quoted 1 line
much like is done with the dmi regions.
??? efi_arch_process_memory_map() doesn't have any DMI specific code, and you don't even come close to introducing behavior similar to dmi_efi_get_table() / dmi_get_table(), which results in a proper call to reserve_e820_ram() as opposed to ...
Quoted 4 lines
xen/arch/x86/efi/efi-boot.h +0
-0@@ -209,6 +209,14 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable, }
xen/arch/x86/efi/efi-boot.h static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable, · line 219
Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +8
-0} +if ( efi_properties_tbl_addr && efi_properties_tbl_size ) + { + ++e; + e->addr = efi_properties_tbl_addr; + e->size = efi_properties_tbl_size; + e->type =E820_RESERVED ; + ++e820_raw.nr_map; + }
... you creating an (in the case you want to deal with) overlapping entry, which we should really avoid.
xen/arch/x86/efi/efi-boot.h static char __section(".bss.page_aligned") __aligned(PAGE_SIZE) · line 183
Quoted 12 lines
xen/arch/x86/efi/efi-boot.h +8
-0@@ -171,6 +173,15 @@ static char __section(".bss.page_aligned") __aligned(PAGE_SIZE) ebmalloc_mem[EBMALLOC_SIZE ];static unsigned long __initdata ebmalloc_allocated; +struct efi_properties_table { +u32 version; +u32 length; +u64 memory_protection_attribute; +}; + +u64 __initdata efi_properties_tbl_addr; +u32 __initdata efi_properties_tbl_size;
No new uses of u32 / u64 please. Namely considering the patch context of the header change, it should have occurred to you to use UINT64 / UINT32 / UINTN here.
Also please use the properly spelled structure tag and field names, as per the UEFI spec. Eventually I'd expect these to appear in one of the canonical EFI headers, at which time it should be possible to simply drop the definition here without the need to adjust any other code.
xen/arch/x86/efi/efi-boot.h static void __init efi_tables(void) · line 837
Quoted 7 lines
xen/arch/x86/efi/efi-boot.h +3
-0@@ -820,6 +832,14 @@ static void __init efi_tables(void) efi.smbios = (long )efi_ct[i].VendorTable;if (match_guid (&smbios3_guid, &efi_ct[i].VendorGuid) ) efi.smbios3 = (long )efi_ct[i].VendorTable; +if (match_guid (&properties_guid, &efi_ct[i].VendorGuid) ) + { +struct efi_properties_table *properties;
const
xen/arch/x86/efi/efi-boot.h static void __init efi_tables(void) · line 839
Quoted 2 lines
xen/arch/x86/efi/efi-boot.h +2
-0+ efi_properties_tbl_addr = (long )efi_ct[i].VendorTable; + properties = (struct efi_properties_table *)efi_properties_tbl_addr;
This second cast could be easily avoided if you assigned from efi_ct[i].VendorTable, which is VOID *.
xen/arch/x86/efi/efi-boot.h extern UINT64 efi_boot_max_var_store_size, efi_boot_remain_var_store_size, · line 45
Quoted 7 lines
xen/arch/x86/efi/efi-boot.h +3
-0@@ -39,3 +40,6 @@ extern UINT64 efi_boot_max_var_store_size, efi_boot_remain_var_store_size,extern UINT64 efi_apple_properties_addr;extern UINTN efi_apple_properties_len; + +extern u64 __initdata efi_properties_tbl_addr; +extern u32 __initdata efi_properties_tbl_size;
__initdata does not belong onto declarations. Only for definitions this annotation is meaningful.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel