Skip to contentSkip to conversation

kexec kernel efi runtime support

PATCH Superseded [email protected] 6 participants 39 messages Nov 5, 2013 – Nov 19, 2013

Subsystems (4)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 cover kexec kernel efi runtime support

Hi,

Here is the V2 for supporting kexec kernel efi runtime. Per pervious discussion I pass the 1st kernel efi runtime mapping via setup_data to 2nd kernel. Besides of the runtime mapping info I also pass the fw_vendor, runtime, config table, smbios physical address in setup_data. EFI spec mentioned fw_vendor, runtime, config table addresses will be converted to virt address after entering virtual mode, but we will use it as physical address in efi_init. For smbios EFI spec did not mention about the address updating, but during my test on a HP workstation, the bios will convert it to Virt addr, thus pass it in setup_data as well.

For fw_vendor, runtime, config table, I export them in /sys/firmware/ efi/systab, smbios is already in that file.

For efi runtime mapping I add a new directory /sys/firmware/efi/ efi-runtime-map/ like below
[dave@darkstar ~]$ tree /sys/firmware/efi/efi-runtime-map/ /sys/firmware/efi/efi-runtime-map/

├── 0
│   ├── attribute
│   ├── num_pages
│   ├── phys_addr
│   ├── type
│   └── virt_addr
├── 1
│   ├── attribute
│   ├── num_pages
│   ├── phys_addr
│   ├── type
│   └── virt_addr

[snip]

kexec-tools will assemble them as setup_data and pass to 2nd kernel. I will send userspace patches as well.

Limitation is I only write support for x86_64, test on below machines:
Lenovo thinkpad t420
Dell inspiron 14 - 3421
HP Z420 workstation
Qemu + OVMF

Please help to review the patches.

The patches are based on matt's efi master tree

Changes from v1:
add one flag in xloadflags, so kexec-tools can safely load old kernel without efi support.
coding style fixes
function name for map phys_addr to fixed virt_addr
Add ABI documentation for sysfs files
--
Thanks
Dave

_______________________________________________
kexec mailing list [email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#1 lore raw

PATCH v2 1/7 Add function efi_remap_region for remapping to saved virt address

Kexec kernel will use saved runtime virtual mapping, so add a new function efi_remap_region to remapping it directly without calculate the virt addr from efi_va.

The md is passed in from 1st kernel, the virtual addr is saved in md->virt_addr.

---
 arch/x86/include/asm/efi.h     |    1 +
 arch/x86/platform/efi/efi_32.c |    3 +++
 arch/x86/platform/efi/efi_64.c |   19 +++++++++++++++++++
 3 files changed, 23 insertions(+)
arch/x86/include/asm/efi.h +1 -0
@@ -128,6 +128,7 @@ extern void efi_call_phys_epilog(void);
 extern void efi_unmap_memmap(void);
 extern void efi_memory_uc(u64 addr, unsigned long size);
 extern void __init efi_map_region(efi_memory_desc_t *md);
+extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
 extern void efi_sync_low_kernel_mappings(void);
 extern void efi_setup_page_tables(void);
 extern void __init old_map_region(efi_memory_desc_t *md);
arch/x86/platform/efi/efi_64.c +19 -0
@@ -203,6 +203,25 @@ void __init efi_map_region(efi_memory_de
 	md->virt_addr = efi_va;
 }
 
+/*
+ * kexec kernel will use efi_map_region_fixed to map efi
+ * runtime memory ranges. md->virt_addr is the original virtual
+ * address which had been mapped in kexec 1st kernel.
+ */
+void __init efi_map_region_fixed(efi_memory_desc_t *md)
+{
+	pgd_t *pgd = (pgd_t *)__va(real_mode_header->trampoline_pgd);
+	unsigned long pf = 0;
+
+	if (!(md->attribute & EFI_MEMORY_WB))
+		pf |= _PAGE_PCD;
+
+	if (kernel_map_pages_in_pgd(pgd, md->phys_addr, md->virt_addr,
+			md->num_pages, pf))
+		pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
+			   md->phys_addr, md->virt_addr);
+}
+
 void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size,
 				 u32 type, u64 attribute)
 {
arch/x86/platform/efi/efi_32.c +3 -0
@@ -47,6 +47,9 @@ void __init efi_map_region(efi_memory_de
 	old_map_region(md);
 }
 
+void __init efi_map_region_fixed(efi_memory_desc_t *md)
+{}
+
 void efi_call_phys_prelog(void)
 {
 	struct desc_ptr gdt_descr;
#2 lore raw

Re: [patch 1/7 v2] Add function efi_remap_region for remapping to saved virt address

Quoted 13 lines · On Tue, 05 Nov, at 04:20:08PM, [email protected]…

Kexec kernel will use saved runtime virtual mapping, so add a new function efi_remap_region to remapping it directly without calculate the virt addr from efi_va.

The md is passed in from 1st kernel, the virtual addr is saved in md->virt_addr.

---
 arch/x86/include/asm/efi.h     |    1 +
 arch/x86/platform/efi/efi_32.c |    3 +++
 arch/x86/platform/efi/efi_64.c |   19 +++++++++++++++++++
 3 files changed, 23 insertions(+)

[...]

Quoted 13 lines
arch/x86/platform/efi/efi_64.c +9 -0
@@ -203,6 +203,25 @@ void __init efi_map_region(efi_memory_de
 	md->virt_addr = efi_va;
 }
 
+/*
+ * kexec kernel will use efi_map_region_fixed to map efi
+ * runtime memory ranges. md->virt_addr is the original virtual
+ * address which had been mapped in kexec 1st kernel.
+ */
+void __init efi_map_region_fixed(efi_memory_desc_t *md)
+{
+	pgd_t *pgd = (pgd_t *)__va(real_mode_header->trampoline_pgd);
+	unsigned long pf = 0;

arch/x86/platform/efi/efi_64.c void __init efi_map_region(efi_memory_de · line 224

Quoted 10 lines
arch/x86/platform/efi/efi_64.c +10 -0
+
+	if (!(md->attribute & EFI_MEMORY_WB))
+		pf |= _PAGE_PCD;
+
+	if (kernel_map_pages_in_pgd(pgd, md->phys_addr, md->virt_addr,
+			md->num_pages, pf))
+		pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
+			   md->phys_addr, md->virt_addr);
+}
+

This function is almost identical to __map_region(). Please implement efi_map_region_fixed() in terms of __map_region(), e.g.

void __init efi_map_region_fixed(efi_memory_desc_t *md)

{
	__map_region(md, md->virt_addr);
}

arch/x86/platform/efi/efi_32.c void __init efi_map_region(efi_memory_de · line 52

Quoted 7 lines
arch/x86/platform/efi/efi_32.c +3 -0
@@ -47,6 +47,9 @@ void __init efi_map_region(efi_memory_de
 	old_map_region(md);
 }
 
+void __init efi_map_region_fixed(efi_memory_desc_t *md)
+{}
+

The braces should be on the same line as the rest of the function prototype. Look at how it's done elsewhere in this file.

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
author
#3 lore raw

Re: [patch 1/7 v2] Add function efi_remap_region for remapping to saved virt address

Quoted 44 lines · Matt Fleming
Quoted 13 lines · On Tue, 05 Nov, at 04:20:08PM, [email protected]…

Kexec kernel will use saved runtime virtual mapping, so add a new function efi_remap_region to remapping it directly without calculate the virt addr from efi_va.

The md is passed in from 1st kernel, the virtual addr is saved in md->virt_addr.

---
 arch/x86/include/asm/efi.h     |    1 +
 arch/x86/platform/efi/efi_32.c |    3 +++
 arch/x86/platform/efi/efi_64.c |   19 +++++++++++++++++++
 3 files changed, 23 insertions(+)

[...]

Quoted 13 lines
arch/x86/platform/efi/efi_64.c +9 -0
@@ -203,6 +203,25 @@ void __init efi_map_region(efi_memory_de
 	md->virt_addr = efi_va;
 }
 
+/*
+ * kexec kernel will use efi_map_region_fixed to map efi
+ * runtime memory ranges. md->virt_addr is the original virtual
+ * address which had been mapped in kexec 1st kernel.
+ */
+void __init efi_map_region_fixed(efi_memory_desc_t *md)
+{
+	pgd_t *pgd = (pgd_t *)__va(real_mode_header->trampoline_pgd);
+	unsigned long pf = 0;

arch/x86/platform/efi/efi_64.c void __init efi_map_region(efi_memory_de · line 224

Quoted 10 lines
arch/x86/platform/efi/efi_64.c +10 -0
+
+	if (!(md->attribute & EFI_MEMORY_WB))
+		pf |= _PAGE_PCD;
+
+	if (kernel_map_pages_in_pgd(pgd, md->phys_addr, md->virt_addr,
+			md->num_pages, pf))
+		pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
+			   md->phys_addr, md->virt_addr);
+}
+

This function is almost identical to __map_region(). Please implement efi_map_region_fixed() in terms of __map_region(), e.g.

Quoted 4 lines

void __init efi_map_region_fixed(efi_memory_desc_t *md)

{
	__map_region(md, md->virt_addr);
}

Good suggestion, will do

Quoted 11 lines

arch/x86/platform/efi/efi_32.c void __init efi_map_region(efi_memory_de · line 52

Quoted 8 lines
arch/x86/platform/efi/efi_32.c +3 -0
@@ -47,6 +47,9 @@ void __init efi_map_region(efi_memory_de
 	old_map_region(md);
 }
 
+void __init efi_map_region_fixed(efi_memory_desc_t *md)
+{}
+

The braces should be on the same line as the rest of the function prototype. Look at how it's done elsewhere in this file.

Ok, will do

Quoted 3 lines
Signature · 2 lines
-- 
Matt Fleming, Intel Open Source Technology Center
#4 lore raw

Re: [patch 1/7 v2] Add function efi_remap_region for remapping to saved virt address

In reply to [email protected]
Quoted 6 lines · On Tue, 2013-11-05 at 16:20 +0800, [email protected]…

Kexec kernel will use saved runtime virtual mapping, so add a new function efi_remap_region to remapping it directly without calculate the virt addr from efi_va.

The md is passed in from 1st kernel, the virtual addr is saved in md->virt_addr.

:

arch/x86/platform/efi/efi_64.c void __init efi_map_region(efi_memory_de · line 211

Quoted 6 lines
arch/x86/platform/efi/efi_64.c +6 -0
+/*
+ * kexec kernel will use efi_map_region_fixed to map efi
+ * runtime memory ranges. md->virt_addr is the original virtual
+ * address which had been mapped in kexec 1st kernel.
+ */
+void __init efi_map_region_fixed(efi_memory_desc_t *md)

Can you simply use __map_region() instead of creating this function? Both functions seem to do the same thing. (In __map_region(), size and end are not used.)

Thanks,
-Toshi

author
#5 lore raw

Re: [patch 1/7 v2] Add function efi_remap_region for remapping to saved virt address

Quoted 10 lines · Toshi Kani
Quoted 6 lines · On Tue, 2013-11-05 at 16:20 +0800, [email protected]…

Kexec kernel will use saved runtime virtual mapping, so add a new function efi_remap_region to remapping it directly without calculate the virt addr from efi_va.

The md is passed in from 1st kernel, the virtual addr is saved in md->virt_addr.

:

Quoted 10 lines

arch/x86/platform/efi/efi_64.c void __init efi_map_region(efi_memory_de · line 211

Quoted 6 lines
arch/x86/platform/efi/efi_64.c +6 -0
+/*
+ * kexec kernel will use efi_map_region_fixed to map efi
+ * runtime memory ranges. md->virt_addr is the original virtual
+ * address which had been mapped in kexec 1st kernel.
+ */
+void __init efi_map_region_fixed(efi_memory_desc_t *md)

Can you simply use __map_region() instead of creating this function? Both functions seem to do the same thing. (In __map_region(), size and end are not used.)

Matt also suggest to reuse __map_region in another apply, will do.

--
Thanks for review
Dave

author
#6 lore raw

Re: [patch 1/7 v2] Add function efi_remap_region for remapping to saved virt address

Quoted 22 lines · Dave Young
Quoted 10 lines · Toshi Kani
Quoted 6 lines · On Tue, 2013-11-05 at 16:20 +0800, [email protected]…

Kexec kernel will use saved runtime virtual mapping, so add a new function efi_remap_region to remapping it directly without calculate the virt addr from efi_va.

The md is passed in from 1st kernel, the virtual addr is saved in md->virt_addr.

:

Quoted 10 lines

arch/x86/platform/efi/efi_64.c void __init efi_map_region(efi_memory_de · line 211

Quoted 6 lines
arch/x86/platform/efi/efi_64.c +6 -0
+/*
+ * kexec kernel will use efi_map_region_fixed to map efi
+ * runtime memory ranges. md->virt_addr is the original virtual
+ * address which had been mapped in kexec 1st kernel.
+ */
+void __init efi_map_region_fixed(efi_memory_desc_t *md)

Can you simply use __map_region() instead of creating this function? Both functions seem to do the same thing. (In __map_region(), size and end are not used.)

Quoted 1 line

Matt also suggest to reuse __map_region in another apply, will do.

Will remove the unused variables in another patch.

--
Thanks
Dave

#7 lore raw

PATCH v2 2/7 x86 efi: reserve boot service fix

In reply to [email protected]

Current code check boot service region with kernel text region by:
start+size >= __pa_symbol(_text)
The end of the above region should be start + size - 1 instead.

I see this problem in ovmf + Fedora 19 grub boot:
text start: 1000000 md start: 800000 md size: 800000

---
 arch/x86/platform/efi/efi.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/platform/efi/efi.c +1 -1
@@ -438,7 +438,7 @@ void __init efi_reserve_boot_services(vo
 		 * - Not within any part of the kernel
 		 * - Not the bios reserved area
 		*/
-		if ((start+size >= __pa_symbol(_text)
+		if ((start + size > __pa_symbol(_text)
 				&& start <= __pa_symbol(_end)) ||
 			!e820_all_mapped(start, start+size, E820_RAM) ||
 			memblock_is_region_reserved(start, size)) {
Acked-by on v2 2/7
#8 lore raw

Re: [patch 2/7 v2] x86 efi: reserve boot service fix

Quoted 9 lines · On Tue, 2013-11-05 at 16:20 +0800, [email protected]…

Current code check boot service region with kernel text region by:
start+size >= __pa_symbol(_text)
The end of the above region should be start + size - 1 instead.

I see this problem in ovmf + Fedora 19 grub boot:
text start: 1000000 md start: 800000 md size: 800000

Thanks,
-Toshi

#9 lore raw

PATCH v2 3/7 Cleanup efi_enter_virtual_mode function

In reply to [email protected]

Add two small functions:
efi_merge_regions and efi_map_regions, efi_enter_virtual_mode calls them instead of embedding two long for loop.

v1->v2:
refresh; coding style fixes.

---
 arch/x86/platform/efi/efi.c |  107 +++++++++++++++++++++++++-------------------
 1 file changed, 63 insertions(+), 44 deletions(-)
arch/x86/platform/efi/efi.c +63 -44
@@ -773,44 +773,12 @@ void __init old_map_region(efi_memory_de
 		       (unsigned long long)md->phys_addr);
 }
 
-/*
- * This function will switch the EFI runtime services to virtual mode.
- * Essentially, we look through the EFI memmap and map every region that
- * has the runtime attribute bit set in its memory descriptor into the
- * ->trampoline_pgd page table using a top-down VA allocation scheme.
- *
- * The old method which used to update that memory descriptor with the
- * virtual address obtained from ioremap() is still supported when the
- * kernel is booted with efi=old_map on its command line. Same old
- * method enabled the runtime services to be called without having to
- * thunk back into physical mode for every invocation.
- *
- * The new method does a pagetable switch in a preemption-safe manner
- * so that we're in a different address space when calling a runtime
- * function. For function arguments passing we do copy the PGDs of the
- * kernel page table into ->trampoline_pgd prior to each call.
- */
-void __init efi_enter_virtual_mode(void)
+/* Merge contiguous regions of the same type and attribute */
+static void efi_merge_regions(void)
 {
+	void *p;
 	efi_memory_desc_t *md, *prev_md = NULL;
-	void *p, *new_memmap = NULL;
-	unsigned long size;
-	efi_status_t status;
-	u64 end, systab;
-	int count = 0;
-
-	efi.systab = NULL;
-
-	/*
-	 * We don't do virtual mode, since we don't do runtime services, on
-	 * non-native EFI
-	 */
-	if (!efi_is_native()) {
-		efi_unmap_memmap();
-		return;
-	}
 
-	/* Merge contiguous regions of the same type and attribute */
 	for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
 		u64 prev_size;
 		md = p;
@@ -837,6 +805,18 @@ void __init efi_enter_virtual_mode(void)
 		prev_md = md;
 
 	}
+}
+
+/*
+ * Map efi memory ranges for runtime serivce
+ * Return the new memmap with updated virtual addrresses.
+ */
+static void efi_map_regions(void **new_memmap, int *count)
+{
+	efi_memory_desc_t *md;
+	void *p;
+	unsigned long size;
+	u64 end, systab;
 
 	for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
 		md = p;
@@ -860,17 +840,59 @@ void __init efi_enter_virtual_mode(void)
 			efi.systab = (efi_system_table_t *) (unsigned long) systab;
 		}
 
-		new_memmap = krealloc(new_memmap,
-				      (count + 1) * memmap.desc_size,
-				      GFP_KERNEL);
-		if (!new_memmap)
+		*new_memmap = krealloc(*new_memmap,
+					(*count + 1) * memmap.desc_size,
+					GFP_KERNEL);
+		if (!*new_memmap)
 			goto err_out;
 
-		memcpy(new_memmap + (count * memmap.desc_size), md,
+		memcpy(*new_memmap + (*count * memmap.desc_size), md,
 		       memmap.desc_size);
-		count++;
+		(*count)++;
 	}
 
+err_out:
+	pr_err("Error reallocating memory, EFI runtime non-functional!\n");
+}
+
+/*
+ * This function will switch the EFI runtime services to virtual mode.
+ * Essentially, we look through the EFI memmap and map every region that
+ * has the runtime attribute bit set in its memory descriptor into the
+ * ->trampoline_pgd page table using a top-down VA allocation scheme.
+ *
+ * The old method which used to update that memory descriptor with the
+ * virtual address obtained from ioremap() is still supported when the
+ * kernel is booted with efi=old_map on its command line. Same old
+ * method enabled the runtime services to be called without having to
+ * thunk back into physical mode for every invocation.
+ *
+ * The new method does a pagetable switch in a preemption-safe manner
+ * so that we're in a different address space when calling a runtime
+ * function. For function arguments passing we do copy the PGDs of the
+ * kernel page table into ->trampoline_pgd prior to each call.
+ */
+void __init efi_enter_virtual_mode(void)
+{
+	efi_status_t status;
+	void *p, *new_memmap = NULL;
+	int count = 0;
+
+	efi.systab = NULL;
+
+	/*
+	 * We don't do virtual mode, since we don't do runtime services, on
+	 * non-native EFI
+	 */
+	if (!efi_is_native()) {
+		efi_unmap_memmap();
+		return;
+	}
+
+	efi_merge_regions();
+
+	efi_map_regions(&new_memmap, &count);
+
 	BUG_ON(!efi.systab);
 
 	efi_setup_page_tables();
@@ -922,9 +944,6 @@ void __init efi_enter_virtual_mode(void)
 			 0, NULL);
 
 	return;
-
- err_out:
-	pr_err("Error reallocating memory, EFI runtime non-functional!\n");
 }
 
 /*
#10 lore raw

Re: [patch 3/7 v2] Cleanup efi_enter_virtual_mode function

Quoted 11 lines · On Tue, 05 Nov, at 04:20:10PM, [email protected]…

Add two small functions:
efi_merge_regions and efi_map_regions, efi_enter_virtual_mode calls them instead of embedding two long for loop.

v1->v2:
refresh; coding style fixes.

---
 arch/x86/platform/efi/efi.c |  107 +++++++++++++++++++++++++-------------------
 1 file changed, 63 insertions(+), 44 deletions(-)

[...]

Quoted 14 lines
arch/x86/platform/efi/efi.c +4 -4
@@ -860,17 +840,59 @@ void __init efi_enter_virtual_mode(void)
 			efi.systab = (efi_system_table_t *) (unsigned long) systab;
 		}
 
-		new_memmap = krealloc(new_memmap,
-				      (count + 1) * memmap.desc_size,
-				      GFP_KERNEL);
-		if (!new_memmap)
+		*new_memmap = krealloc(*new_memmap,
+					(*count + 1) * memmap.desc_size,
+					GFP_KERNEL);
+		if (!*new_memmap)
 			goto err_out;
 

arch/x86/platform/efi/efi.c void __init efi_enter_virtual_mode(void) · line 856

Quoted 10 lines
arch/x86/platform/efi/efi.c +5 -2
-		memcpy(new_memmap + (count * memmap.desc_size), md,
+		memcpy(*new_memmap + (*count * memmap.desc_size), md,
 		       memmap.desc_size);
-		count++;
+		(*count)++;
 	}
 
+err_out:
+	pr_err("Error reallocating memory, EFI runtime non-functional!\n");
+}

You should really return an error value here so that we don't dereference 'new_memmap' below if it's NULL. In fact, just return the memmap...

arch/x86/platform/efi/efi.c void __init efi_enter_virtual_mode(void) · line 895

Quoted 5 lines
arch/x86/platform/efi/efi.c +5 -0
+
+	efi_merge_regions();
+
+	efi_map_regions(&new_memmap, &count);
+

and make sure to check the return value here.

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
author
#11 lore raw

Re: [patch 3/7 v2] Cleanup efi_enter_virtual_mode function

Quoted 36 lines · Matt Fleming
Quoted 11 lines · On Tue, 05 Nov, at 04:20:10PM, [email protected]…

Add two small functions:
efi_merge_regions and efi_map_regions, efi_enter_virtual_mode calls them instead of embedding two long for loop.

v1->v2:
refresh; coding style fixes.

---
 arch/x86/platform/efi/efi.c |  107 +++++++++++++++++++++++++-------------------
 1 file changed, 63 insertions(+), 44 deletions(-)

[...]

Quoted 21 lines
arch/x86/platform/efi/efi.c +6 -6
@@ -860,17 +840,59 @@ void __init efi_enter_virtual_mode(void)
 			efi.systab = (efi_system_table_t *) (unsigned long) systab;
 		}
 
-		new_memmap = krealloc(new_memmap,
-				      (count + 1) * memmap.desc_size,
-				      GFP_KERNEL);
-		if (!new_memmap)
+		*new_memmap = krealloc(*new_memmap,
+					(*count + 1) * memmap.desc_size,
+					GFP_KERNEL);
+		if (!*new_memmap)
 			goto err_out;
 
-		memcpy(new_memmap + (count * memmap.desc_size), md,
+		memcpy(*new_memmap + (*count * memmap.desc_size), md,
 		       memmap.desc_size);
-		count++;
+		(*count)++;
 	}
 
Quoted 7 lines

arch/x86/platform/efi/efi.c void __init efi_enter_virtual_mode(void) · line 856

Quoted 3 lines
arch/x86/platform/efi/efi.c +3 -0
+err_out:
+	pr_err("Error reallocating memory, EFI runtime non-functional!\n");
+}

You should really return an error value here so that we don't dereference 'new_memmap' below if it's NULL. In fact, just return the memmap...

Good catch, will do

Quoted 8 lines

arch/x86/platform/efi/efi.c void __init efi_enter_virtual_mode(void) · line 895

Quoted 6 lines
arch/x86/platform/efi/efi.c +5 -0
+
+	efi_merge_regions();
+
+	efi_map_regions(&new_memmap, &count);
+

and make sure to check the return value here.

Ok.

Quoted 2 lines
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
#12 lore raw

Re: [patch 3/7 v2] Cleanup efi_enter_virtual_mode function

In reply to [email protected]
Quoted 3 lines · On Tue, 2013-11-05 at 16:20 +0800, [email protected]…

Add two small functions:
efi_merge_regions and efi_map_regions, efi_enter_virtual_mode calls them instead of embedding two long for loop.

:

arch/x86/platform/efi/efi.c void __init efi_enter_virtual_mode(void) · line 878

Quoted 4 lines
arch/x86/platform/efi/efi.c +4 -0
+void __init efi_enter_virtual_mode(void)
+{
+	efi_status_t status;
+	void *p, *new_memmap = NULL;

*p is unused.

Thanks,
-Toshi

author
#13 lore raw

Re: [patch 3/7 v2] Cleanup efi_enter_virtual_mode function

Quoted 5 lines · Toshi Kani
Quoted 3 lines · On Tue, 2013-11-05 at 16:20 +0800, [email protected]…

Add two small functions:
efi_merge_regions and efi_map_regions, efi_enter_virtual_mode calls them instead of embedding two long for loop.

Quoted 8 lines

:

arch/x86/platform/efi/efi.c void __init efi_enter_virtual_mode(void) · line 878

Quoted 4 lines
arch/x86/platform/efi/efi.c +4 -0
+void __init efi_enter_virtual_mode(void)
+{
+	efi_status_t status;
+	void *p, *new_memmap = NULL;

*p is unused.

The *p was removed in later patch, will remove it in this patch.

Thanks for review.
Dave

#14 lore raw

PATCH v2 4/7 export more efi table variable to sysfs

In reply to [email protected]

Export fw_vendor, runtime and config tables physical addresses to /sys/firmware/efi/systab becaue kexec kernel will need them.

Quoted 1 line

From EFI spec these 3 variables will be updated to

virtual address after entering virtual mode. But kernel startup code will need the physical address.

---
 arch/x86/platform/efi/efi.c |    4 ++++
 drivers/firmware/efi/efi.c  |    9 +++++++++
 include/linux/efi.h         |    3 +++
 3 files changed, 16 insertions(+)
drivers/firmware/efi/efi.c +9 -0
@@ -32,6 +32,9 @@ struct efi __read_mostly efi = {
 	.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_tables  = EFI_INVALID_TABLE_ADDR,
 };
 EXPORT_SYMBOL(efi);
 
@@ -64,6 +67,12 @@ static ssize_t systab_show(struct kobjec
 		str += sprintf(str, "BOOTINFO=0x%lx\n", efi.boot_info);
 	if (efi.uga != EFI_INVALID_TABLE_ADDR)
 		str += sprintf(str, "UGA=0x%lx\n", efi.uga);
+	if (efi.fw_vendor != EFI_INVALID_TABLE_ADDR)
+		str += sprintf(str, "fw_vendor=0x%lx\n", efi.fw_vendor);
+	if (efi.runtime != EFI_INVALID_TABLE_ADDR)
+		str += sprintf(str, "runtime=0x%lx\n", efi.runtime);
+	if (efi.config_tables != EFI_INVALID_TABLE_ADDR)
+		str += sprintf(str, "config_tables=0x%lx\n", efi.config_tables);
 
 	return str - buf;
 }
include/linux/efi.h +3 -0
@@ -556,6 +556,9 @@ extern struct efi {
 	unsigned long hcdp;		/* HCDP table */
 	unsigned long uga;		/* UGA table */
 	unsigned long uv_systab;	/* UV system table */
+	unsigned long fw_vendor;
+	unsigned long runtime;
+	unsigned long config_tables;
 	efi_get_time_t *get_time;
 	efi_set_time_t *set_time;
 	efi_get_wakeup_time_t *get_wakeup_time;
arch/x86/platform/efi/efi.c +4 -0
@@ -653,6 +653,10 @@ void __init efi_init(void)
 
 	set_bit(EFI_SYSTEM_TABLES, &x86_efi_facility);
 
+	efi.fw_vendor = (unsigned long)efi.systab->fw_vendor;
+	efi.runtime = (unsigned long)efi.systab->runtime;
+	efi.config_tables = (unsigned long)efi.systab->tables;
+
 	/*
 	 * Show what we know for posterity
 	 */
#15 lore raw

Re: [patch 4/7 v2] export more efi table variable to sysfs

Quoted 3 lines · On Tue, Nov 05, 2013 at 04:20:11PM +0800…

Export fw_vendor, runtime and config tables physical addresses to /sys/firmware/efi/systab becaue kexec kernel will need them.

sysfs files are one-value-per-file.

Please don't abuse this and add more values to this single file, in fact, it should be broken up into individual sysfs files as it is, because this isn't ok now.

Sorry, you don't get to abuse this anymore :(

greg k-h

author
#16 lore raw

Re: [patch 4/7 v2] export more efi table variable to sysfs

Quoted 5 lines · Greg KH
Quoted 3 lines · On Tue, Nov 05, 2013 at 04:20:11PM +0800…

Export fw_vendor, runtime and config tables physical addresses to /sys/firmware/efi/systab becaue kexec kernel will need them.

Quoted 7 lines

sysfs files are one-value-per-file.

Please don't abuse this and add more values to this single file, in fact, it should be broken up into individual sysfs files as it is, because this isn't ok now.

Sorry, you don't get to abuse this anymore :(

Ok, I know this, just creating this without thinking about carefully. Will redo the patch, thanks for catching.

Thanks
Dave

author
#17 lore raw

Re: [patch 4/7 v2] export more efi table variable to sysfs

Quoted 8 lines · Dave Young
Quoted 7 lines · Greg KH
Quoted 3 lines · On Tue, Nov 05, 2013 at 04:20:11PM +0800…

Export fw_vendor, runtime and config tables physical addresses to /sys/firmware/efi/systab becaue kexec kernel will need them.

sysfs files are one-value-per-file.

Quoted 8 lines
Quoted 5 lines

Please don't abuse this and add more values to this single file, in fact, it should be broken up into individual sysfs files as it is, because this isn't ok now.

Sorry, you don't get to abuse this anymore :(

Ok, I know this, just creating this without thinking about carefully. Will redo the patch, thanks for catching.

I would like to add new files for the values used in this patchset. And will split the original systab later in another patchset.

Quoted 3 lines

Thanks
Dave

#18 lore raw

Re: [patch 4/7 v2] export more efi table variable to sysfs

Quoted 13 lines · Dave Young
Quoted 12 lines · Dave Young
Quoted 11 lines · Greg KH
Quoted 3 lines · On Tue, Nov 05, 2013 at 04:20:11PM +0800…

Export fw_vendor, runtime and config tables physical addresses to /sys/firmware/efi/systab becaue kexec kernel will need them.

sysfs files are one-value-per-file.

Please don't abuse this and add more values to this single file, in fact, it should be broken up into individual sysfs files as it is, because this isn't ok now.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Sorry, you don't get to abuse this anymore :(

Ok, I know this, just creating this without thinking about carefully. Will redo the patch, thanks for catching.

I would like to add new files for the values used in this patchset. And will split the original systab later in another patchset.

That's fine with me, thanks.

greg k-h

#19 lore raw

PATCH v2 5/7 export efi runtime memory mapping to sysfs

In reply to [email protected]

kexec kernel will need exactly same mapping for
efi runtime memory ranges. Thus here export the
runtime ranges mapping to sysfs, kexec-tools
will assemble them and pass to 2nd kernel via
setup_data.

Introducing a new directly /sys/firmware/efi/efi-runtime-map Just like /sys/firmware/memmap. Containing below attribute in each file of that directory:
attribute num_pages phys_addr type virt_addr

It will not work for efi 32bit. Only x86_64 currently.

---
 Documentation/ABI/testing/sysfs-efi-runtime-map |   45 ++++++
 arch/x86/include/asm/efi.h                      |    3 
 arch/x86/platform/efi/efi.c                     |   11 +
 drivers/firmware/efi/Kconfig                    |   10 +
 drivers/firmware/efi/Makefile                   |    1 
 drivers/firmware/efi/efi-runtime-map.c          |  164 ++++++++++++++++++++++++
 drivers/firmware/efi/efi.c                      |    3 
 include/linux/efi.h                             |    6 
 8 files changed, 242 insertions(+), 1 deletion(-)
arch/x86/platform/efi/efi.c +11 -0
@@ -76,6 +76,9 @@ static __initdata efi_config_table_type_
 	{NULL_GUID, NULL, NULL},
 };
 
+efi_memory_desc_t *efi_runtime_map;
+int nr_efi_runtime_map;
+
 /*
  * Returns 1 if 'facility' is enabled, 0 otherwise.
  */
@@ -852,6 +855,14 @@ static void efi_map_regions(void **new_m
 
 		memcpy(*new_memmap + (*count * memmap.desc_size), md,
 		       memmap.desc_size);
+		if (md->type != EFI_BOOT_SERVICES_CODE &&
+			md->type != EFI_BOOT_SERVICES_DATA) {
+			efi_runtime_map = krealloc(efi_runtime_map,
+					(nr_efi_runtime_map + 1) *
+					sizeof(efi_memory_desc_t), GFP_KERNEL);
+			*(efi_runtime_map + nr_efi_runtime_map) = *md;
+			nr_efi_runtime_map++;
+		}
 		(*count)++;
 	}
 
drivers/firmware/efi/Kconfig +10 -0
@@ -36,4 +36,14 @@ config EFI_VARS_PSTORE_DEFAULT_DISABLE
 	  backend for pstore by default. This setting can be overridden
 	  using the efivars module's pstore_disable parameter.
 
+config EFI_RUNTIME_MAP
+	bool "Add efi runtime map to sysfs" if EXPERT
+	default X86 && EFI
+	help
+	  Add the efi runtime memory map to /sys/firmware/efi/runtime-map.
+	  That memory map is used for example by kexec to set up efi virtual
+	  mapping the 2nd kernel, but can also be used for debugging purposes.
+
+	  See also Documentation/ABI/testing/sysfs-efi-runtime-map.
+
 endmenu
drivers/firmware/efi/Makefile +1 -0
@@ -4,3 +4,4 @@
 obj-y					+= efi.o vars.o
 obj-$(CONFIG_EFI_VARS)			+= efivars.o
 obj-$(CONFIG_EFI_VARS_PSTORE)		+= efi-pstore.o
+obj-$(CONFIG_EFI_RUNTIME_MAP)		+= efi-runtime-map.o
drivers/firmware/efi/efi-runtime-map.c new file +164 -0

164 lines not on this page · raw message

drivers/firmware/efi/efi.c +2 -1
@@ -38,7 +38,8 @@ struct efi __read_mostly efi = {
 };
 EXPORT_SYMBOL(efi);
 
-static struct kobject *efi_kobj;
+struct kobject *efi_kobj;
+EXPORT_SYMBOL_GPL(efi_kobj);
 static struct kobject *efivars_kobj;
 
 /*
arch/x86/include/asm/efi.h +3 -0
@@ -133,6 +133,9 @@ extern void efi_sync_low_kernel_mappings
 extern void efi_setup_page_tables(void);
 extern void __init old_map_region(efi_memory_desc_t *md);
 
+extern efi_memory_desc_t *efi_runtime_map;
+extern int nr_efi_runtime_map;
+
 #ifdef CONFIG_EFI
 
 static inline bool efi_is_native(void)
Documentation/ABI/testing/sysfs-efi-runtime-map new file +45 -0

45 lines not on this page · raw message

include/linux/efi.h +6 -0
@@ -872,4 +872,10 @@ int efivars_sysfs_init(void);
 
 #endif /* CONFIG_EFI_VARS */
 
+#ifdef CONFIG_EFI_RUNTIME_MAP
+extern efi_memory_desc_t *efi_runtime_map;
+extern int nr_efi_runtime_map;
+extern struct kobject *efi_kobj;
+#endif
+
 #endif /* _LINUX_EFI_H */
#20 lore raw

Re: [patch 5/7 v2] export efi runtime memory mapping to sysfs

Quoted 24 lines · On Tue, 05 Nov, at 04:20:12PM, [email protected]…

kexec kernel will need exactly same mapping for
efi runtime memory ranges. Thus here export the
runtime ranges mapping to sysfs, kexec-tools
will assemble them and pass to 2nd kernel via
setup_data.

Introducing a new directly /sys/firmware/efi/efi-runtime-map Just like /sys/firmware/memmap. Containing below attribute in each file of that directory:
attribute num_pages phys_addr type virt_addr

It will not work for efi 32bit. Only x86_64 currently.

---
 Documentation/ABI/testing/sysfs-efi-runtime-map |   45 ++++++
 arch/x86/include/asm/efi.h                      |    3 
 arch/x86/platform/efi/efi.c                     |   11 +
 drivers/firmware/efi/Kconfig                    |   10 +
 drivers/firmware/efi/Makefile                   |    1 
 drivers/firmware/efi/efi-runtime-map.c          |  164 ++++++++++++++++++++++++
 drivers/firmware/efi/efi.c                      |    3 
 include/linux/efi.h                             |    6 
 8 files changed, 242 insertions(+), 1 deletion(-)

[...]

Quoted 4 lines
arch/x86/platform/efi/efi.c +0 -0
@@ -852,6 +855,14 @@ static void efi_map_regions(void **new_m
 
 		memcpy(*new_memmap + (*count * memmap.desc_size), md,
 		       memmap.desc_size);

arch/x86/platform/efi/efi.c static void efi_map_regions(void **new_m · line 867

Quoted 10 lines
arch/x86/platform/efi/efi.c +8 -0
+		if (md->type != EFI_BOOT_SERVICES_CODE &&
+			md->type != EFI_BOOT_SERVICES_DATA) {
+			efi_runtime_map = krealloc(efi_runtime_map,
+					(nr_efi_runtime_map + 1) *
+					sizeof(efi_memory_desc_t), GFP_KERNEL);
+			*(efi_runtime_map + nr_efi_runtime_map) = *md;
+			nr_efi_runtime_map++;
+		}
 		(*count)++;
 	}

You really need to be using 'memmap.desc_size' here and not sizeof(efi_memory_desc_t) as the two may differ. Also, you should be checking for failure of krealloc() and using memcpy() instead of directly dereferencing 'md'.

drivers/firmware/efi/efi-runtime-map.c

Quoted 9 lines
drivers/firmware/efi/Makefile +1 -0
@@ -4,3 +4,4 @@
 obj-y					+= efi.o vars.o
 obj-$(CONFIG_EFI_VARS)			+= efivars.o
 obj-$(CONFIG_EFI_VARS_PSTORE)		+= efi-pstore.o
+obj-$(CONFIG_EFI_RUNTIME_MAP)		+= efi-runtime-map.o
drivers/firmware/efi/efi-runtime-map.c new file +0 -0

Small nit but I wouldn't bother prefixing the filename with "efi-", since you can't build this file as a module.

drivers/firmware/efi/efi-runtime-map.c line 59

Quoted 11 lines
drivers/firmware/efi/efi-runtime-map.c new file +11 -0
+/*
+ * These are default attributes that are added for every memmap entry.
+ */
+static struct attribute *def_attrs[] = {
+	&map_type_attr.attr,
+	&map_phys_addr_attr.attr,
+	&map_virt_addr_attr.attr,
+	&map_num_pages_attr.attr,
+	&map_attribute_attr.attr,
+	NULL
+};

If the UEFI spec ever releases an update for the memory descriptor structure, and bumps 'memmap.desc_version', how are we going to signal the incompatibility to legacy versions of kexec tools?

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
author
#21 lore raw

Re: [patch 5/7 v2] export efi runtime memory mapping to sysfs

Quoted 39 lines · Matt Fleming
Quoted 24 lines · On Tue, 05 Nov, at 04:20:12PM, [email protected]…

kexec kernel will need exactly same mapping for
efi runtime memory ranges. Thus here export the
runtime ranges mapping to sysfs, kexec-tools
will assemble them and pass to 2nd kernel via
setup_data.

Introducing a new directly /sys/firmware/efi/efi-runtime-map Just like /sys/firmware/memmap. Containing below attribute in each file of that directory:
attribute num_pages phys_addr type virt_addr

It will not work for efi 32bit. Only x86_64 currently.

---
 Documentation/ABI/testing/sysfs-efi-runtime-map |   45 ++++++
 arch/x86/include/asm/efi.h                      |    3 
 arch/x86/platform/efi/efi.c                     |   11 +
 drivers/firmware/efi/Kconfig                    |   10 +
 drivers/firmware/efi/Makefile                   |    1 
 drivers/firmware/efi/efi-runtime-map.c          |  164 ++++++++++++++++++++++++
 drivers/firmware/efi/efi.c                      |    3 
 include/linux/efi.h                             |    6 
 8 files changed, 242 insertions(+), 1 deletion(-)

[...]

Quoted 11 lines
arch/x86/platform/efi/efi.c +7 -0
@@ -852,6 +855,14 @@ static void efi_map_regions(void **new_m
 
 		memcpy(*new_memmap + (*count * memmap.desc_size), md,
 		       memmap.desc_size);
+		if (md->type != EFI_BOOT_SERVICES_CODE &&
+			md->type != EFI_BOOT_SERVICES_DATA) {
+			efi_runtime_map = krealloc(efi_runtime_map,
+					(nr_efi_runtime_map + 1) *
+					sizeof(efi_memory_desc_t), GFP_KERNEL);
+			*(efi_runtime_map + nr_efi_runtime_map) = *md;
+			nr_efi_runtime_map++;
Quoted 8 lines

arch/x86/platform/efi/efi.c static void efi_map_regions(void **new_m · line 867

Quoted 3 lines
arch/x86/platform/efi/efi.c +1 -0
+		}
 		(*count)++;
 	}

You really need to be using 'memmap.desc_size' here and not sizeof(efi_memory_desc_t) as the two may differ. Also, you should be checking for failure of krealloc() and using memcpy() instead of directly dereferencing 'md'.

I'm a bit confused with the desc_size and sizeof(efi_memory_desc_t), Because I intended to same struct efi_memory_desc_t in userspace to pass the setup_data, so I worry about if desc_size will cause problems.

Will double check it.

Quoted 13 lines

drivers/firmware/efi/efi-runtime-map.c

Quoted 10 lines
drivers/firmware/efi/Makefile +1 -0
@@ -4,3 +4,4 @@
 obj-y					+= efi.o vars.o
 obj-$(CONFIG_EFI_VARS)			+= efivars.o
 obj-$(CONFIG_EFI_VARS_PSTORE)		+= efi-pstore.o
+obj-$(CONFIG_EFI_RUNTIME_MAP)		+= efi-runtime-map.o
drivers/firmware/efi/efi-runtime-map.c new file +0 -0

Small nit but I wouldn't bother prefixing the filename with "efi-", since you can't build this file as a module.

Ok, will do

Quoted 16 lines

drivers/firmware/efi/efi-runtime-map.c line 59

Quoted 12 lines
drivers/firmware/efi/efi-runtime-map.c new file +11 -0
+/*
+ * These are default attributes that are added for every memmap entry.
+ */
+static struct attribute *def_attrs[] = {
+	&map_type_attr.attr,
+	&map_phys_addr_attr.attr,
+	&map_virt_addr_attr.attr,
+	&map_num_pages_attr.attr,
+	&map_attribute_attr.attr,
+	NULL
+};

If the UEFI spec ever releases an update for the memory descriptor structure, and bumps 'memmap.desc_version', how are we going to signal the incompatibility to legacy versions of kexec tools?

Hmm, that is a problem. I will consider to export memmap according to what firmware provided with extra desc_version instead of using attrs from kernel data structure efi_memory_desc_t

Now it's clear for previous question about desc_size and sizeof(efi_memory_desc_t) Will switch to use desc_size.

Quoted 3 lines
Signature · 2 lines
-- 
Matt Fleming, Intel Open Source Technology Center
author
#22 lore raw

Re: [patch 5/7 v2] export efi runtime memory mapping to sysfs

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
drivers/firmware/efi/efi-runtime-map.c new file +7 -0
+/*
+ * These are default attributes that are added for every memmap entry.
+ */
+static struct attribute *def_attrs[] = {
+	&map_type_attr.attr,
+	&map_phys_addr_attr.attr,
+	&map_virt_addr_attr.attr,
Quoted 8 lines

drivers/firmware/efi/efi-runtime-map.c line 59

Quoted 4 lines
drivers/firmware/efi/efi-runtime-map.c new file +4 -0
+	&map_num_pages_attr.attr,
+	&map_attribute_attr.attr,
+	NULL
+};

If the UEFI spec ever releases an update for the memory descriptor structure, and bumps 'memmap.desc_version', how are we going to signal the incompatibility to legacy versions of kexec tools?

Quoted 4 lines

Hmm, that is a problem. I will consider to export memmap according to what firmware provided with extra desc_version instead of using attrs from kernel data structure efi_memory_desc_t

Matt, desc_version is already in boot_params.efi_info, so kexec-tools can get the version from there. I do not need to export it as another file.

I think for now we do not need worry much about the compatibility issue, do you think I need add version checking in kexec-tools currently? like below?

if (desc_version != 1) /* current version is 1? */
error out it is not supported

--
Thanks
Dave

#23 lore raw

Re: [patch 5/7 v2] export efi runtime memory mapping to sysfs

Quoted 3 lines · Dave Young

Matt, desc_version is already in boot_params.efi_info, so kexec-tools can get the version from there. I do not need to export it as another file.

OK, cool.

Quoted 6 lines

I think for now we do not need worry much about the compatibility issue, do you think I need add version checking in kexec-tools currently? like below?

if (desc_version != 1) /* current version is 1? */
error out it is not supported

Yes, something like that. If you already have kexec-specific ways of checking a version number then that's fine. Just make sure that, if the EFI memory descriptor structure is extended in the future and more files are exported for each descriptor, kexec-tools say "I don't know how to build a data structure for from these files".

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
#24 lore raw

PATCH v2 6/7 passing kexec necessary efi data via setup_data

In reply to [email protected]

Add a new setup_data type SETUP_EFI for kexec use. Passing the saved fw_vendor, runtime, config tables and efi runtime mappings.

When entering virtual mode, directly mapping the efi runtime ragions which we passed in previously. And skip the step to call SetVirtualAddressMap.

Specially for HP z420 workstation it need another variable saving, it's the smbios physical address, the HP bios also update the SMBIOS address after entering virtual mode besides of the standard fw_vendor,runtime and config table.

Tested on ovmf+qemu, lenovo thinkpad, a dell laptop and an HP z420 workstation.

---
 arch/x86/include/asm/efi.h            |   12 ++
 arch/x86/include/uapi/asm/bootparam.h |    1 
 arch/x86/kernel/setup.c               |    3 
 arch/x86/platform/efi/efi.c           |  151 ++++++++++++++++++++++++++++++----
 4 files changed, 152 insertions(+), 15 deletions(-)
arch/x86/kernel/setup.c +3 -0
@@ -447,6 +447,9 @@ static void __init parse_setup_data(void
 		case SETUP_DTB:
 			add_dtb(pa_data);
 			break;
+		case SETUP_EFI:
+			parse_efi_setup(pa_data, data_len);
+			break;
 		default:
 			break;
 		}
arch/x86/platform/efi/efi.c +136 -15

224 lines not on this page · raw message

arch/x86/include/uapi/asm/bootparam.h +1 -0
@@ -6,6 +6,7 @@
 #define SETUP_E820_EXT			1
 #define SETUP_DTB			2
 #define SETUP_PCI			3
+#define SETUP_EFI			4
 
 /* ram_size flags */
 #define RAMDISK_IMAGE_START_MASK	0x07FF
arch/x86/include/asm/efi.h +12 -0
@@ -136,6 +136,18 @@ extern void __init old_map_region(efi_me
 extern efi_memory_desc_t *efi_runtime_map;
 extern int nr_efi_runtime_map;
 
+struct efi_setup_data {
+	u64 fw_vendor;
+	u64 runtime;
+	u64 tables;
+	u64 smbios;
+	u64 reserved[8];
+	efi_memory_desc_t map[0];
+};
+
+extern void parse_efi_setup(u64 phys_addr, u32 data_len);
+extern struct efi_setup_data *esdata;
+
 #ifdef CONFIG_EFI
 
 static inline bool efi_is_native(void)
#25 lore raw

Re: [patch 6/7 v2] passing kexec necessary efi data via setup_data

Quoted 4 lines · On Tue, 05 Nov, at 04:20:13PM, [email protected]…

Add a new setup_data type SETUP_EFI for kexec use. Passing the saved fw_vendor, runtime, config tables and efi runtime mappings.

Quoted 8 lines

When entering virtual mode, directly mapping the efi runtime ragions which we passed in previously. And skip the step to call SetVirtualAddressMap.

Specially for HP z420 workstation it need another variable saving, it's the smbios physical address, the HP bios also update the SMBIOS address after entering virtual mode besides of the standard fw_vendor,runtime and config table.

Does that mean that on some of the platforms you tested the SMBIOS address isn't updated?

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
author
#26 lore raw

Re: [patch 6/7 v2] passing kexec necessary efi data via setup_data

Quoted 9 lines · Matt Fleming
Quoted 8 lines · On Tue, 05 Nov, at 04:20:13PM, [email protected]…

Add a new setup_data type SETUP_EFI for kexec use. Passing the saved fw_vendor, runtime, config tables and efi runtime mappings.

When entering virtual mode, directly mapping the efi runtime ragions which we passed in previously. And skip the step to call SetVirtualAddressMap.

Quoted 7 lines
Quoted 4 lines

Specially for HP z420 workstation it need another variable saving, it's the smbios physical address, the HP bios also update the SMBIOS address after entering virtual mode besides of the standard fw_vendor,runtime and config table.

Does that mean that on some of the platforms you tested the SMBIOS address isn't updated?

Yes, on my three test machines, lenovo, dell and HP, only the HP machine need this that means the lenovo and dell machine does not update the SMBIOS address to virt addr.

Quoted 3 lines
Signature · 2 lines
-- 
Matt Fleming, Intel Open Source Technology Center
#27 lore raw

PATCH v2 7/7 x86: add xloadflags bit for efi runtime support on kexec

In reply to [email protected]

Old kexec-tools can not load new kernel. The reason is previously kexec-tools do not fill efi_info in x86 setup header thus efi init fail and switch to noefi boot. In new kexec-tools it will by default fill efi_info and pass other efi required infomation to 2nd kernel so kexec kernel efi initialization will success finally.

To prevent from breaking userspace, add a new xloadflags bit so kexec-tools will check the flag and switch to old logic.

---
 arch/x86/boot/header.S                |    9 ++++++++-
 arch/x86/include/uapi/asm/bootparam.h |    1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
arch/x86/boot/header.S +8 -1
@@ -391,7 +391,14 @@ xloadflags:
 #else
 # define XLF23 0
 #endif
-			.word XLF0 | XLF1 | XLF23
+
+#if defined(CONFIG_X86_64) && defined(CONFIG_EFI)
+# define XLF4 XLF_EFI_KEXEC
+#else
+# define XLF4 0
+#endif
+
+			.word XLF0 | XLF1 | XLF23 | XLF4
 
 cmdline_size:   .long   COMMAND_LINE_SIZE-1     #length of the command line,
                                                 #added with boot protocol
arch/x86/include/uapi/asm/bootparam.h +1 -0
@@ -24,6 +24,7 @@
 #define XLF_CAN_BE_LOADED_ABOVE_4G	(1<<1)
 #define XLF_EFI_HANDOVER_32		(1<<2)
 #define XLF_EFI_HANDOVER_64		(1<<3)
+#define XLF_EFI_KEXEC			(1<<4)
 
 #ifndef __ASSEMBLY__
#28 lore raw

Re: [patch 7/7 v2] x86: add xloadflags bit for efi runtime support on kexec

Quoted 18 lines · On Tue, 05 Nov, at 04:20:14PM, [email protected]…

Old kexec-tools can not load new kernel. The reason is previously kexec-tools do not fill efi_info in x86 setup header thus efi init fail and switch to noefi boot. In new kexec-tools it will by default fill efi_info and pass other efi required infomation to 2nd kernel so kexec kernel efi initialization will success finally.

To prevent from breaking userspace, add a new xloadflags bit so kexec-tools will check the flag and switch to old logic.

---
 arch/x86/boot/header.S                |    9 ++++++++-
 arch/x86/include/uapi/asm/bootparam.h |    1 +
 2 files changed, 9 insertions(+), 1 deletion(-)

arch/x86/boot/header.S xloadflags: · line 395

Quoted 6 lines
arch/x86/boot/header.S +2 -1
@@ -391,7 +391,14 @@ xloadflags:
 #else
 # define XLF23 0
 #endif
-			.word XLF0 | XLF1 | XLF23
+
+#if defined(CONFIG_X86_64) && defined(CONFIG_EFI)

&& defined(CONFIG_KEXEC) ?

Quoted 5 lines
arch/x86/boot/header.S +5 -0
+# define XLF4 XLF_EFI_KEXEC
+#else
+# define XLF4 0
+#endif
+
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
author
#29 lore raw

Re: [patch 7/7 v2] x86: add xloadflags bit for efi runtime support on kexec

Quoted 16 lines · Matt Fleming
Quoted 15 lines · On Tue, 05 Nov, at 04:20:14PM, [email protected]…

Old kexec-tools can not load new kernel. The reason is previously kexec-tools do not fill efi_info in x86 setup header thus efi init fail and switch to noefi boot. In new kexec-tools it will by default fill efi_info and pass other efi required infomation to 2nd kernel so kexec kernel efi initialization will success finally.

To prevent from breaking userspace, add a new xloadflags bit so kexec-tools will check the flag and switch to old logic.

---
 arch/x86/boot/header.S                |    9 ++++++++-
 arch/x86/include/uapi/asm/bootparam.h |    1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
Quoted 11 lines

arch/x86/boot/header.S xloadflags: · line 395

Quoted 9 lines
arch/x86/boot/header.S +2 -1
@@ -391,7 +391,14 @@ xloadflags:
 #else
 # define XLF23 0
 #endif
-			.word XLF0 | XLF1 | XLF23
+
+#if defined(CONFIG_X86_64) && defined(CONFIG_EFI)

&& defined(CONFIG_KEXEC) ?

Will add above.

Quoted 9 lines
Quoted 6 lines
arch/x86/boot/header.S +5 -0
+# define XLF4 XLF_EFI_KEXEC
+#else
+# define XLF4 0
+#endif
+
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
#30 lore raw

Re: [patch 7/7 v2] x86: add xloadflags bit for efi runtime support on kexec

In reply to [email protected]
Quoted 37 lines · On 11/05/2013 12:20 AM, [email protected] wrote:

Old kexec-tools can not load new kernel. The reason is previously kexec-tools do not fill efi_info in x86 setup header thus efi init fail and switch to noefi boot. In new kexec-tools it will by default fill efi_info and pass other efi required infomation to 2nd kernel so kexec kernel efi initialization will success finally.

To prevent from breaking userspace, add a new xloadflags bit so kexec-tools will check the flag and switch to old logic.

---
 arch/x86/boot/header.S                |    9 ++++++++-
 arch/x86/include/uapi/asm/bootparam.h |    1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
arch/x86/boot/header.S +8 -1
@@ -391,7 +391,14 @@ xloadflags:
 #else
 # define XLF23 0
 #endif
-			.word XLF0 | XLF1 | XLF23
+
+#if defined(CONFIG_X86_64) && defined(CONFIG_EFI)
+# define XLF4 XLF_EFI_KEXEC
+#else
+# define XLF4 0
+#endif
+
+			.word XLF0 | XLF1 | XLF23 | XLF4
 
 cmdline_size:   .long   COMMAND_LINE_SIZE-1     #length of the command line,
                                                 #added with boot protocol

arch/x86/include/uapi/asm/bootparam.h line 30

Quoted 7 lines
arch/x86/include/uapi/asm/bootparam.h +1 -0
@@ -24,6 +24,7 @@
 #define XLF_CAN_BE_LOADED_ABOVE_4G	(1<<1)
 #define XLF_EFI_HANDOVER_32		(1<<2)
 #define XLF_EFI_HANDOVER_64		(1<<3)
+#define XLF_EFI_KEXEC			(1<<4)
 
 #ifndef __ASSEMBLY__
 

Also needs to be added to Documentation/x86/boot.txt with the exact semantics being exposed.

-hpa

author
#31 lore raw

Re: [patch 7/7 v2] x86: add xloadflags bit for efi runtime support on kexec

Quoted 42 lines · H. Peter Anvin
Quoted 41 lines · On 11/05/2013 12:20 AM, [email protected] wrote:

Old kexec-tools can not load new kernel. The reason is previously kexec-tools do not fill efi_info in x86 setup header thus efi init fail and switch to noefi boot. In new kexec-tools it will by default fill efi_info and pass other efi required infomation to 2nd kernel so kexec kernel efi initialization will success finally.

To prevent from breaking userspace, add a new xloadflags bit so kexec-tools will check the flag and switch to old logic.

---
 arch/x86/boot/header.S                |    9 ++++++++-
 arch/x86/include/uapi/asm/bootparam.h |    1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
arch/x86/boot/header.S +8 -1
@@ -391,7 +391,14 @@ xloadflags:
 #else
 # define XLF23 0
 #endif
-			.word XLF0 | XLF1 | XLF23
+
+#if defined(CONFIG_X86_64) && defined(CONFIG_EFI)
+# define XLF4 XLF_EFI_KEXEC
+#else
+# define XLF4 0
+#endif
+
+			.word XLF0 | XLF1 | XLF23 | XLF4
 
 cmdline_size:   .long   COMMAND_LINE_SIZE-1     #length of the command line,
                                                 #added with boot protocol
arch/x86/include/uapi/asm/bootparam.h +1 -0
@@ -24,6 +24,7 @@
 #define XLF_CAN_BE_LOADED_ABOVE_4G	(1<<1)
 #define XLF_EFI_HANDOVER_32		(1<<2)
 #define XLF_EFI_HANDOVER_64		(1<<3)
+#define XLF_EFI_KEXEC			(1<<4)
 
Quoted 6 lines

arch/x86/include/uapi/asm/bootparam.h line 30

Quoted 3 lines
arch/x86/include/uapi/asm/bootparam.h +0 -0
 #ifndef __ASSEMBLY__
 

Also needs to be added to Documentation/x86/boot.txt with the exact semantics being exposed.

Will do

Quoted 3 lines

-hpa

#33 lore raw
In reply to [email protected]
Quoted 12 lines · On Tue, 05 Nov, at 04:20:07PM, [email protected]…

Hi,

Here is the V2 for supporting kexec kernel efi runtime. Per pervious discussion I pass the 1st kernel efi runtime mapping via setup_data to 2nd kernel. Besides of the runtime mapping info I also pass the fw_vendor, runtime, config table, smbios physical address in setup_data. EFI spec mentioned fw_vendor, runtime, config table addresses will be converted to virt address after entering virtual mode, but we will use it as physical address in efi_init. For smbios EFI spec did not mention about the address updating, but during my test on a HP workstation, the bios will convert it to Virt addr, thus pass it in setup_data as well.

I see this in the dmesg,

[    0.000000] efi: skipping setup_data on EFI 32BIT!

despite the fact that this is on an x86-64 box. Turns out it's because CONFIG_DEBUG_BOOT_PARAMS isn't set in my config. You may want to turn that on automatically. After doing that things work on my ASUS box (good work!) but the SATA controller craps out on my Tunnelmountain machine, but that's probably unrelated and I'll debug that separately.

I see a bunch of section mismatch warnings,

WARNING: arch/x86/platform/efi/built-in.o(.text+0xd1e): Section mismatch in reference from the function efi_map_regions_fixed() to the function .init.text:efi_map_region_fixed() The function efi_map_regions_fixed() references
the function __init efi_map_region_fixed().
This is often because efi_map_regions_fixed lacks a __init
annotation or the annotation of efi_map_region_fixed is wrong.

WARNING: arch/x86/platform/efi/built-in.o(.text+0xd2a): Section mismatch in reference from the function efi_map_regions_fixed() to the variable .init.data:efi_phys The function efi_map_regions_fixed() references
the variable __initdata efi_phys.
This is often because efi_map_regions_fixed lacks a __initdata
annotation or the annotation of efi_phys is wrong.

WARNING: arch/x86/platform/built-in.o(.text+0xd1e): Section mismatch in reference from the function efi_map_regions_fixed() to the function .init.text:efi_map_region_fixed() The function efi_map_regions_fixed() references
the function __init efi_map_region_fixed().
This is often because efi_map_regions_fixed lacks a __init
annotation or the annotation of efi_map_region_fixed is wrong.

WARNING: arch/x86/platform/built-in.o(.text+0xd2a): Section mismatch in reference from the function efi_map_regions_fixed() to the variable .init.data:efi_phys The function efi_map_regions_fixed() references
the variable __initdata efi_phys.
This is often because efi_map_regions_fixed lacks a __initdata
annotation or the annotation of efi_phys is wrong.

WARNING: arch/x86/built-in.o(.text+0x7c357): Section mismatch in reference from the function parse_efi_setup() to the function .init.text:early_memremap() The function parse_efi_setup() references
the function __init early_memremap().
This is often because parse_efi_setup lacks a __init
annotation or the annotation of early_memremap is wrong.

WARNING: arch/x86/built-in.o(.text+0x7c390): Section mismatch in reference from the function parse_efi_setup() to the function .init.text:early_iounmap() The function parse_efi_setup() references
the function __init early_iounmap().
This is often because parse_efi_setup lacks a __init
annotation or the annotation of early_iounmap is wrong.

WARNING: arch/x86/built-in.o(.text+0x7c5ce): Section mismatch in reference from the function efi_map_regions_fixed() to the function .init.text:efi_map_region_fixed() The function efi_map_regions_fixed() references
the function __init efi_map_region_fixed().
This is often because efi_map_regions_fixed lacks a __init
annotation or the annotation of efi_map_region_fixed is wrong.

WARNING: arch/x86/built-in.o(.text+0x7c5da): Section mismatch in reference from the function efi_map_regions_fixed() to the variable .init.data:vdso32_sysenter_end The function efi_map_regions_fixed() references
the variable __initdata vdso32_sysenter_end.
This is often because efi_map_regions_fixed lacks a __initdata
annotation or the annotation of vdso32_sysenter_end is wrong.

Also, many of your patch descriptions are missing subsystem tags. Please fix this in your next submission.

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
author
#34 lore raw

Hi, Matt

Quoted 16 lines · Matt Fleming
Quoted 12 lines · On Tue, 05 Nov, at 04:20:07PM, [email protected]…

Hi,

Here is the V2 for supporting kexec kernel efi runtime. Per pervious discussion I pass the 1st kernel efi runtime mapping via setup_data to 2nd kernel. Besides of the runtime mapping info I also pass the fw_vendor, runtime, config table, smbios physical address in setup_data. EFI spec mentioned fw_vendor, runtime, config table addresses will be converted to virt address after entering virtual mode, but we will use it as physical address in efi_init. For smbios EFI spec did not mention about the address updating, but during my test on a HP workstation, the bios will convert it to Virt addr, thus pass it in setup_data as well.

I see this in the dmesg,

Quoted 7 lines
[    0.000000] efi: skipping setup_data on EFI 32BIT!

despite the fact that this is on an x86-64 box. Turns out it's because CONFIG_DEBUG_BOOT_PARAMS isn't set in my config. You may want to turn that on automatically. After doing that things work on my ASUS box (good work!) but the SATA controller craps out on my Tunnelmountain machine, but that's probably unrelated and I'll debug that separately.

Hmm, if CONFIG_DEBUG_BOOT_PARAMS is not set, then kexec-tools should fail getting efi_info, so I will fix kexec-tools patch about this.

Also CONFIG_EFI_RUNTIME_MAP should select CONFIG_DEBUG_BOOT_PARAMS. In future will try to move the boot params data out of debugfs.

Quoted 45 lines

I see a bunch of section mismatch warnings,

WARNING: arch/x86/platform/efi/built-in.o(.text+0xd1e): Section mismatch in reference from the function efi_map_regions_fixed() to the function .init.text:efi_map_region_fixed() The function efi_map_regions_fixed() references
the function __init efi_map_region_fixed().
This is often because efi_map_regions_fixed lacks a __init
annotation or the annotation of efi_map_region_fixed is wrong.

WARNING: arch/x86/platform/efi/built-in.o(.text+0xd2a): Section mismatch in reference from the function efi_map_regions_fixed() to the variable .init.data:efi_phys The function efi_map_regions_fixed() references
the variable __initdata efi_phys.
This is often because efi_map_regions_fixed lacks a __initdata
annotation or the annotation of efi_phys is wrong.

WARNING: arch/x86/platform/built-in.o(.text+0xd1e): Section mismatch in reference from the function efi_map_regions_fixed() to the function .init.text:efi_map_region_fixed() The function efi_map_regions_fixed() references
the function __init efi_map_region_fixed().
This is often because efi_map_regions_fixed lacks a __init
annotation or the annotation of efi_map_region_fixed is wrong.

WARNING: arch/x86/platform/built-in.o(.text+0xd2a): Section mismatch in reference from the function efi_map_regions_fixed() to the variable .init.data:efi_phys The function efi_map_regions_fixed() references
the variable __initdata efi_phys.
This is often because efi_map_regions_fixed lacks a __initdata
annotation or the annotation of efi_phys is wrong.

WARNING: arch/x86/built-in.o(.text+0x7c357): Section mismatch in reference from the function parse_efi_setup() to the function .init.text:early_memremap() The function parse_efi_setup() references
the function __init early_memremap().
This is often because parse_efi_setup lacks a __init
annotation or the annotation of early_memremap is wrong.

WARNING: arch/x86/built-in.o(.text+0x7c390): Section mismatch in reference from the function parse_efi_setup() to the function .init.text:early_iounmap() The function parse_efi_setup() references
the function __init early_iounmap().
This is often because parse_efi_setup lacks a __init
annotation or the annotation of early_iounmap is wrong.

WARNING: arch/x86/built-in.o(.text+0x7c5ce): Section mismatch in reference from the function efi_map_regions_fixed() to the function .init.text:efi_map_region_fixed() The function efi_map_regions_fixed() references
the function __init efi_map_region_fixed().
This is often because efi_map_regions_fixed lacks a __init
annotation or the annotation of efi_map_region_fixed is wrong.

Quoted 5 lines

WARNING: arch/x86/built-in.o(.text+0x7c5da): Section mismatch in reference from the function efi_map_regions_fixed() to the variable .init.data:vdso32_sysenter_end The function efi_map_regions_fixed() references
the variable __initdata vdso32_sysenter_end.
This is often because efi_map_regions_fixed lacks a __initdata
annotation or the annotation of vdso32_sysenter_end is wrong.

Will fix, thanks for testing.

Quoted 3 lines

Also, many of your patch descriptions are missing subsystem tags. Please fix this in your next submission.

Do you means to add "efi:" in subject?

Thanks
Dave

#35 lore raw
Quoted 7 lines · Dave Young

Hmm, if CONFIG_DEBUG_BOOT_PARAMS is not set, then kexec-tools should fail getting efi_info, so I will fix kexec-tools patch about this.

Also CONFIG_EFI_RUNTIME_MAP should select CONFIG_DEBUG_BOOT_PARAMS. In future will try to move the boot params data out of debugfs.

Honestly, if we need debugfs to get actual functionality, it shouldn't be in sploit^Wdebugfs...

-hpa

author
#36 lore raw
Quoted 5 lines · H. Peter Anvin
Quoted 4 lines · Dave Young

Hmm, if CONFIG_DEBUG_BOOT_PARAMS is not set, then kexec-tools should fail getting efi_info, so I will fix kexec-tools patch about this.

Quoted 7 lines
Quoted 3 lines

Also CONFIG_EFI_RUNTIME_MAP should select CONFIG_DEBUG_BOOT_PARAMS. In future will try to move the boot params data out of debugfs.

Honestly, if we need debugfs to get actual functionality, it shouldn't be in sploit^Wdebugfs...

Huang Ying <[email protected]> created the debugfs file for boot_params. His first version patch tried sysfs, but sysfs is not designed for such
binary blobs so finally it go to debugfs.

Any idea for this is welcome, till now I have no better idea for such kind of data. We should have another *fs instead of using debugfs.

Thanks
Dave

#37 lore raw
Quoted 5 lines · Dave Young

Huang Ying <[email protected]> created the debugfs file for boot_params. His first version patch tried sysfs, but sysfs is not designed for such
binary blobs so finally it go to debugfs.

That is a misunderstanding. Binary blobs can exist in sysfs as long as the blob is something that is inherently a blob. This is admittedly a corner case, but it is without any doubt a protocol-defined binary structure.

The reason it was put in debugfs is that there was no non-debug user for it at the time.

Quoted 2 lines

Any idea for this is welcome, till now I have no better idea for such kind of data. We should have another *fs instead of using debugfs.

The problem with debugfs is that things go into debugfs with largely no auditing. As a result, mounting debugfs is very likely to mean that your system is exploitable one way or another.

-hpa

author
#38 lore raw
Quoted 11 lines · H. Peter Anvin
Quoted 5 lines · Dave Young

Huang Ying <[email protected]> created the debugfs file for boot_params. His first version patch tried sysfs, but sysfs is not designed for such
binary blobs so finally it go to debugfs.

That is a misunderstanding. Binary blobs can exist in sysfs as long as the blob is something that is inherently a blob. This is admittedly a corner case, but it is without any doubt a protocol-defined binary structure.

You are right. Greg objected that the whole structure being exported directly.

Quoted 3 lines

The reason it was put in debugfs is that there was no non-debug user for it at the time.

Ok, I did not know this background.

Quoted 7 lines
Quoted 3 lines

Any idea for this is welcome, till now I have no better idea for such kind of data. We should have another *fs instead of using debugfs.

The problem with debugfs is that things go into debugfs with largely no auditing. As a result, mounting debugfs is very likely to mean that your system is exploitable one way or another.

Hmm, agree. Thanks for explaining about it.

Thanks
Dave