Skip to contentSkip to conversation

xen/efi: Fixes

PATCH Superseded Daniel Kiper 3 participants 8 messages Jun 22, 2017 – Jun 23, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover xen/efi: Fixes

Hey,

Two small fixes (v2, minor cleanup) for Xen dom0 running on x86_64 EFI platforms.

I am CC-ing stable maintainers because similar stuff is needed for various stable kernels too. Unfortunately, almost every version needs a bit different set of fixes. So, please treat this email more as head up than real set of patches for your kernel. If you wish to get Xen EFI stuff fixed just drop me a line. Then I will prepare set of patches for your kernel (if needed).

Ard, Andrew, Ingo, thank you for looking at the patches.

Daniel

 arch/x86/xen/efi.c         |   45 ++++++++++++---------------------------------
 drivers/firmware/efi/efi.c |    3 ++-
 2 files changed, 14 insertions(+), 34 deletions(-)

Daniel Kiper (2):
efi: Process MEMATTR table only if EFI_MEMMAP x86/xen/efi: Init only efi struct members used by Xen

#1 lore raw

PATCH v2 1/2 efi: Process MEMATTR table only if EFI_MEMMAP

Otherwise e.g. Xen dom0 on x86_64 EFI platforms crashes.

In theory we can check EFI_PARAVIRT too, however, EFI_MEMMAP looks more generic and covers more cases.

---
 drivers/firmware/efi/efi.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/firmware/efi/efi.c +2 -1
index b372aad..045d6d3 100644
@@ -528,7 +528,8 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,
 		}
 	}
 
-	efi_memattr_init();
+	if (efi_enabled(EFI_MEMMAP))
+		efi_memattr_init();
 
 	/* Parse the EFI Properties table if it exists */
 	if (efi.properties_table != EFI_INVALID_TABLE_ADDR) {
Signature · 1 line
1.7.10.4
#2 lore raw

[tip:efi/core] efi: Process the MEMATTR table only if EFI_MEMMAP is enabled

efi: Process the MEMATTR table only if EFI_MEMMAP is enabled
Commit-ID:  457ea3f7e97881f937136ce0ba1f29f82b9abdb0
Gitweb:     http://git.kernel.org/tip/457ea3f7e97881f937136ce0ba1f29f82b9abdb0
Author:     Daniel Kiper <[email protected]>
AuthorDate: Thu, 22 Jun 2017 12:51:36 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 23 Jun 2017 11:11:02 +0200

efi: Process the MEMATTR table only if EFI_MEMMAP is enabled

Otherwise e.g. Xen dom0 on x86_64 EFI platforms crashes.

In theory we can check EFI_PARAVIRT too, however, EFI_MEMMAP looks more targeted and covers more cases.

---
 drivers/firmware/efi/efi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/firmware/efi/efi.c +2 -1
index b372aad..045d6d3 100644
@@ -528,7 +528,8 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,
 		}
 	}
 
-	efi_memattr_init();
+	if (efi_enabled(EFI_MEMMAP))
+		efi_memattr_init();
 
 	/* Parse the EFI Properties table if it exists */
 	if (efi.properties_table != EFI_INVALID_TABLE_ADDR) {
#3 lore raw

PATCH v2 1/2 efi: Process MEMATTR table only if EFI_MEMMAP

In reply to Daniel Kiper

Otherwise e.g. Xen dom0 on x86_64 EFI platforms crashes.

In theory we can check EFI_PARAVIRT too, however, EFI_MEMMAP looks more generic and covers more cases.

---
 drivers/firmware/efi/efi.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/firmware/efi/efi.c +2 -1
index b372aad..045d6d3 100644
@@ -528,7 +528,8 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,
 		}
 	}
 
-	efi_memattr_init();
+	if (efi_enabled(EFI_MEMMAP))
+		efi_memattr_init();
 
 	/* Parse the EFI Properties table if it exists */
 	if (efi.properties_table != EFI_INVALID_TABLE_ADDR) {
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#4 lore raw

PATCH v2 2/2 x86/xen/efi: Init only efi struct members used by Xen

In reply to Daniel Kiper

Current approach, wholesale efi struct initialization from efi_xen, is not good. Usually if new member is defined then it is properly initialized in drivers/firmware/efi/efi.c but not in arch/x86/xen/efi.c. As I saw it happened a few times until now. So, let's initialize only efi struct members used by Xen to avoid such issues in the future.

--
Align assignments to increase readability. Suggested by Ingo Molnar.

---
 arch/x86/xen/efi.c |   45 ++++++++++++---------------------------------
 1 file changed, 12 insertions(+), 33 deletions(-)
arch/x86/xen/efi.c +12 -33
index 30bb2e8..a18703b 100644
@@ -54,38 +54,6 @@
 	.tables		= EFI_INVALID_TABLE_ADDR  /* Initialized later. */
 };
 
-static const struct efi efi_xen __initconst = {
-	.systab                   = NULL, /* Initialized later. */
-	.runtime_version	  = 0,    /* Initialized later. */
-	.mps                      = EFI_INVALID_TABLE_ADDR,
-	.acpi                     = EFI_INVALID_TABLE_ADDR,
-	.acpi20                   = EFI_INVALID_TABLE_ADDR,
-	.smbios                   = EFI_INVALID_TABLE_ADDR,
-	.smbios3                  = EFI_INVALID_TABLE_ADDR,
-	.sal_systab               = EFI_INVALID_TABLE_ADDR,
-	.boot_info                = EFI_INVALID_TABLE_ADDR,
-	.hcdp                     = EFI_INVALID_TABLE_ADDR,
-	.uga                      = EFI_INVALID_TABLE_ADDR,
-	.uv_systab                = EFI_INVALID_TABLE_ADDR,
-	.fw_vendor                = EFI_INVALID_TABLE_ADDR,
-	.runtime                  = EFI_INVALID_TABLE_ADDR,
-	.config_table             = EFI_INVALID_TABLE_ADDR,
-	.get_time                 = xen_efi_get_time,
-	.set_time                 = xen_efi_set_time,
-	.get_wakeup_time          = xen_efi_get_wakeup_time,
-	.set_wakeup_time          = xen_efi_set_wakeup_time,
-	.get_variable             = xen_efi_get_variable,
-	.get_next_variable        = xen_efi_get_next_variable,
-	.set_variable             = xen_efi_set_variable,
-	.query_variable_info      = xen_efi_query_variable_info,
-	.update_capsule           = xen_efi_update_capsule,
-	.query_capsule_caps       = xen_efi_query_capsule_caps,
-	.get_next_high_mono_count = xen_efi_get_next_high_mono_count,
-	.reset_system             = xen_efi_reset_system,
-	.set_virtual_address_map  = NULL, /* Not used under Xen. */
-	.flags			  = 0     /* Initialized later. */
-};
-
 static efi_system_table_t __init *xen_efi_probe(void)
 {
 	struct xen_platform_op op = {
@@ -102,7 +70,18 @@ static efi_system_table_t __init *xen_efi_probe(void)
 
 	/* Here we know that Xen runs on EFI platform. */
 
-	efi = efi_xen;
+	efi.get_time                 = xen_efi_get_time;
+	efi.set_time                 = xen_efi_set_time;
+	efi.get_wakeup_time          = xen_efi_get_wakeup_time;
+	efi.set_wakeup_time          = xen_efi_set_wakeup_time;
+	efi.get_variable             = xen_efi_get_variable;
+	efi.get_next_variable        = xen_efi_get_next_variable;
+	efi.set_variable             = xen_efi_set_variable;
+	efi.query_variable_info      = xen_efi_query_variable_info;
+	efi.update_capsule           = xen_efi_update_capsule;
+	efi.query_capsule_caps       = xen_efi_query_capsule_caps;
+	efi.get_next_high_mono_count = xen_efi_get_next_high_mono_count;
+	efi.reset_system             = xen_efi_reset_system;
 
 	efi_systab_xen.tables = info->cfg.addr;
 	efi_systab_xen.nr_tables = info->cfg.nent;
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
reviewer Reviewed-by on v2 2/2
#5 lore raw

Re: [PATCH v2 2/2] x86/xen/efi: Init only efi struct members used by Xen

Quoted 8 lines · Daniel Kiper

Current approach, wholesale efi struct initialization from efi_xen, is not good. Usually if new member is defined then it is properly initialized in drivers/firmware/efi/efi.c but not in arch/x86/xen/efi.c. As I saw it happened a few times until now. So, let's initialize only efi struct members used by Xen to avoid such issues in the future.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

reviewer Reviewed-by on v2 2/2
#6 lore raw

Re: [PATCH v2 2/2] x86/xen/efi: Init only efi struct members used by Xen

In reply to Daniel Kiper
Quoted 8 lines · Daniel Kiper

Current approach, wholesale efi struct initialization from efi_xen, is not good. Usually if new member is defined then it is properly initialized in drivers/firmware/efi/efi.c but not in arch/x86/xen/efi.c. As I saw it happened a few times until now. So, let's initialize only efi struct members used by Xen to avoid such issues in the future.

#7 lore raw

[tip:efi/core] x86/xen/efi: Initialize only the EFI struct members used by Xen

In reply to Daniel Kiper
x86/xen/efi: Initialize only the EFI struct members used by Xen
Commit-ID:  6c64447ec58b0bac612732303f7ab04562124587
Gitweb:     http://git.kernel.org/tip/6c64447ec58b0bac612732303f7ab04562124587
Author:     Daniel Kiper <[email protected]>
AuthorDate: Thu, 22 Jun 2017 12:51:37 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 23 Jun 2017 11:11:03 +0200

x86/xen/efi: Initialize only the EFI struct members used by Xen

The current approach, which is the wholesale efi struct initialization from a 'efi_xen' local template is not robust. Usually if new member is defined then it is properly initialized in drivers/firmware/efi/efi.c, but not in arch/x86/xen/efi.c.

The effect is that the Xen initialization clears any fields the generic code might have set and the Xen code does not know about yet.

I saw this happen a few times, so let's initialize only the EFI struct members used by Xen and maintain no local duplicate, to avoid such issues in the future.

---
 arch/x86/xen/efi.c | 45 ++++++++++++---------------------------------
 1 file changed, 12 insertions(+), 33 deletions(-)
arch/x86/xen/efi.c +12 -33
index 30bb2e8..a18703b 100644
@@ -54,38 +54,6 @@ static efi_system_table_t efi_systab_xen __initdata = {
 	.tables		= EFI_INVALID_TABLE_ADDR  /* Initialized later. */
 };
 
-static const struct efi efi_xen __initconst = {
-	.systab                   = NULL, /* Initialized later. */
-	.runtime_version	  = 0,    /* Initialized later. */
-	.mps                      = EFI_INVALID_TABLE_ADDR,
-	.acpi                     = EFI_INVALID_TABLE_ADDR,
-	.acpi20                   = EFI_INVALID_TABLE_ADDR,
-	.smbios                   = EFI_INVALID_TABLE_ADDR,
-	.smbios3                  = EFI_INVALID_TABLE_ADDR,
-	.sal_systab               = EFI_INVALID_TABLE_ADDR,
-	.boot_info                = EFI_INVALID_TABLE_ADDR,
-	.hcdp                     = EFI_INVALID_TABLE_ADDR,
-	.uga                      = EFI_INVALID_TABLE_ADDR,
-	.uv_systab                = EFI_INVALID_TABLE_ADDR,
-	.fw_vendor                = EFI_INVALID_TABLE_ADDR,
-	.runtime                  = EFI_INVALID_TABLE_ADDR,
-	.config_table             = EFI_INVALID_TABLE_ADDR,
-	.get_time                 = xen_efi_get_time,
-	.set_time                 = xen_efi_set_time,
-	.get_wakeup_time          = xen_efi_get_wakeup_time,
-	.set_wakeup_time          = xen_efi_set_wakeup_time,
-	.get_variable             = xen_efi_get_variable,
-	.get_next_variable        = xen_efi_get_next_variable,
-	.set_variable             = xen_efi_set_variable,
-	.query_variable_info      = xen_efi_query_variable_info,
-	.update_capsule           = xen_efi_update_capsule,
-	.query_capsule_caps       = xen_efi_query_capsule_caps,
-	.get_next_high_mono_count = xen_efi_get_next_high_mono_count,
-	.reset_system             = xen_efi_reset_system,
-	.set_virtual_address_map  = NULL, /* Not used under Xen. */
-	.flags			  = 0     /* Initialized later. */
-};
-
 static efi_system_table_t __init *xen_efi_probe(void)
 {
 	struct xen_platform_op op = {
@@ -102,7 +70,18 @@ static efi_system_table_t __init *xen_efi_probe(void)
 
 	/* Here we know that Xen runs on EFI platform. */
 
-	efi = efi_xen;
+	efi.get_time                 = xen_efi_get_time;
+	efi.set_time                 = xen_efi_set_time;
+	efi.get_wakeup_time          = xen_efi_get_wakeup_time;
+	efi.set_wakeup_time          = xen_efi_set_wakeup_time;
+	efi.get_variable             = xen_efi_get_variable;
+	efi.get_next_variable        = xen_efi_get_next_variable;
+	efi.set_variable             = xen_efi_set_variable;
+	efi.query_variable_info      = xen_efi_query_variable_info;
+	efi.update_capsule           = xen_efi_update_capsule;
+	efi.query_capsule_caps       = xen_efi_query_capsule_caps;
+	efi.get_next_high_mono_count = xen_efi_get_next_high_mono_count;
+	efi.reset_system             = xen_efi_reset_system;
 
 	efi_systab_xen.tables = info->cfg.addr;
 	efi_systab_xen.nr_tables = info->cfg.nent;