Skip to contentSkip to conversation

kexec kernel efi runtime support

PATCH In review Dave Young 3 participants 33 messages Dec 20, 2013 – Jan 3, 2014

Subsystems (6)
Documentation x86 x86 MM EFI +2 more subsystems
lore
Share & tools
lore

Dave Young

author
#0 lore raw

v7 cover kexec kernel efi runtime support

Here is the V7 patchset 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/, smbios is already in /sys/firmware/efi/systab.

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

|__ 0
|   |__ attribute
|   |__ num_pages
|   |__ phys_addr
|   |__ type
|   |__ virt_addr
|__ 1

[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

The patches are based on linus tree + tip master + 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

Changes from v2:
- 01/09: a new patch to remove unused variables in __map_region function catched by Toshi Kani
- 09/09: a new patch to export x86 boot_params to sysfs instead of use debugfs files
- Matt: reuse __map_region instead do same thing in another function. add a wrapper function efi_map_region_fixed [02/09]
check return value of krealloc
sysfs dir name s/efi-runtime-map/runtime-map [06/09]
use desc_size in efi_runtime_map
for the xloadflags defination: +&& defined(CONFIG_KEXEC)
- Greg: sysfs : one file one value for fw_vendor, runtime, tables. [05/09] Document them in ABI testing
- HPA: Document the new xloadflag
- Also there's other function cleanup and improvement for error handling.

Changes from v3:
- Greg: sysfs code move to use __ATTR_RO and attr_group
- Boris: comments and code alignment

- Added 3 new patches below 10-print-efi-runtime-memmap.patch
- 10/12: print only runtime ranges in case EFI_DEBUG printing
11-reserve-setup-data-late.patch
- fix a bug of kdump kernel, move function for reserving setup data ranges late after parsing memmap= cmdline params because kdump kernel will pass exact memmap late.
12-x86-kdebugfs-use-ioremap.patch
- fix a bug of x86/kernel/kdebugfs.c, use ioremap instead of __va for low mem because __va does not work for exact memmap=

Changes from V4:
- variable efi_setup in 09/14 is changed to the physical address instead of the virtual address because it will be not iounmapped until entering virtual mode, it's too long and could cause leak.
- sparse warnings fixes (Matt):
Added 2 new patches to addressing sparse warnings:
01/14: x86-mm-sparse-warning-fix-for-early_memremap.patch 02/14: efi-use-early_memremap-and-early_memunmap.patch
- krealloc fixes (Boris)
- rebase on top of Linus tree + Matt's efi master tree (Boris)
- a lot of documention/spelling fixes (Boris)
- share function save_runtime_map in 1st/2nd kernel code (Matt)
- style and other fixes detail see the patch changelog themselves.

Changes from V5:
- add efi_runtime_map_setup() and remove the extern variables thus other arches can reuse the runtime_map exporting code. (Matt)
- check efi_reuse_config return value. (Matt)
- move parse_efi_setup to efi_$(BITS).c (Boris)
- call efi_runtime_map_init in efisubsys_init (Boris)
- save_runtime_map cleanup. (Boris)

Changes from V6:
- update memmap in userspace to the saved runtime map, thus kernel code become cleaner.
- patch 08: simplify save_runtime_map.
- patch 09: simplify efi_map_regions and efi_map_regions_fixed.
- remove the patch to handle print_efi_memmap for kexec kernel
- remove the last patch for fixing __va usage in kdebugfs since I can not reproduce it in kdump kernel, it should be addressed seperately.
- patch 06 (efi: cleanup efi_enter_virtual_mode function):
add a share function get_systab_virt_addr()
- rebase to latest mainline tree

The patches stay in kexec-efi-testing branch of below repo for testing:
https://github.com/daveyoung/linux.git

Dave Young (12):
x86/mm: sparse warning fix for early_memremap
efi: Use early_memremap and early_memunmap to fix sparse warnings
efi: remove unused variables in __map_region
efi: add a wrapper function efi_map_region_fixed
efi: reserve boot service fix
efi: cleanup efi_enter_virtual_mode function
efi: export more efi table variable to sysfs
efi: export efi runtime memory mapping to sysfs
efi: passing kexec necessary efi data via setup_data
x86: add xloadflags bit for efi runtime support on kexec
x86: export x86 boot_params to sysfs
x86: reserve setup_data ranges late after parsing memmap cmdline

 Documentation/ABI/testing/sysfs-firmware-efi       |  20 ++
 .../ABI/testing/sysfs-firmware-efi-runtime-map     |  34 ++
 Documentation/ABI/testing/sysfs-kernel-boot_params |  38 +++
 Documentation/x86/boot.txt                         |   3 +
 arch/x86/boot/header.S                             |   9 +-
 arch/x86/include/asm/efi.h                         |  14 +
 arch/x86/include/asm/io.h                          |   3 +-
 arch/x86/include/uapi/asm/bootparam.h              |   2 +
 arch/x86/kernel/Makefile                           |   1 +
 arch/x86/kernel/ksysfs.c                           | 339 ++++++++++++++++++++
 arch/x86/kernel/setup.c                            |   7 +-
 arch/x86/mm/ioremap.c                              |  10 +-
 arch/x86/platform/efi/efi.c                        | 345 ++++++++++++++++-----
 arch/x86/platform/efi/efi_32.c                     |   3 +
 arch/x86/platform/efi/efi_64.c                     |  22 +-
 drivers/firmware/efi/Kconfig                       |  11 +
 drivers/firmware/efi/Makefile                      |   1 +
 drivers/firmware/efi/efi.c                         |  49 ++-
 drivers/firmware/efi/runtime-map.c                 | 181 +++++++++++
 include/linux/efi.h                                |  16 +
 20 files changed, 1010 insertions(+), 98 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-firmware-efi
 create mode 100644 Documentation/ABI/testing/sysfs-firmware-efi-runtime-map
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-boot_params
 create mode 100644 arch/x86/kernel/ksysfs.c
 create mode 100644 drivers/firmware/efi/runtime-map.c
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH v7 1/12 x86/mm: sparse warning fix for early_memremap

There's a lot of sparse warnings for code like below:
void *a = early_memremap(phys_addr, size);

early_memremap intend to map kernel memory with ioremap facility, the return pointer should be a kernel ram pointer instead of iomem one.

For making the function clearer and supressing sparse warnings this patch do below two things:
1. cast to (__force void *) for the return value of early_memremap
2. add early_memunmap function and pass (__force void __iomem *) to iounmap

Quoted 4 lines

From Boris:
Ingo told me yesterday, it makes sense too. I'd guess we can try it. FWIW, all callers of early_memremap use the memory they get remapped as normal memory so we should be safe.

---
 arch/x86/include/asm/io.h |  3 ++-
 arch/x86/mm/ioremap.c     | 10 +++++++---
 2 files changed, 9 insertions(+), 4 deletions(-)
arch/x86/include/asm/io.h +2 -1
index 34f69cb..1db414f 100644
@@ -325,9 +325,10 @@ extern void early_ioremap_init(void);
 extern void early_ioremap_reset(void);
 extern void __iomem *early_ioremap(resource_size_t phys_addr,
 				   unsigned long size);
-extern void __iomem *early_memremap(resource_size_t phys_addr,
+extern void *early_memremap(resource_size_t phys_addr,
 				    unsigned long size);
 extern void early_iounmap(void __iomem *addr, unsigned long size);
+extern void early_memunmap(void *addr, unsigned long size);
 extern void fixup_early_ioremap(void);
 extern bool is_early_ioremap_ptep(pte_t *ptep);
 
arch/x86/mm/ioremap.c +7 -3
index 799580c..bbb4504 100644
@@ -562,10 +562,9 @@ early_ioremap(resource_size_t phys_addr, unsigned long size)
 }
 
 /* Remap memory */
-void __init __iomem *
-early_memremap(resource_size_t phys_addr, unsigned long size)
+void __init *early_memremap(resource_size_t phys_addr, unsigned long size)
 {
-	return __early_ioremap(phys_addr, size, PAGE_KERNEL);
+	return (__force void *)__early_ioremap(phys_addr, size, PAGE_KERNEL);
 }
 
 void __init early_iounmap(void __iomem *addr, unsigned long size)
@@ -620,3 +619,8 @@ void __init early_iounmap(void __iomem *addr, unsigned long size)
 	}
 	prev_map[slot] = NULL;
 }
+
+void __init early_memunmap(void *addr, unsigned long size)
+{
+	early_iounmap((__force void __iomem *)addr, size);
+}
Signature · 1 line
1.8.3.1
author
#2 lore raw

PATCH v7 2/12 efi: Use early_memremap and early_memunmap to fix sparse warnings

In reply to Dave Young

There are a lot of sparse warnings for early_memremap and early_ioummap in arch/x86/platform/efi/efi.c and drivers/firmware/efi/efi.c.

early_memremap is for mapping kernel memory instead of io memory, but the early_memremap returns void __iomem pointer and early_iounmap accepts __iomem pointer as argument. Sparse checking is not happy with the mismatch.

Also there's several early_ioremap callbacks which need to be changed to early_memremap because they are actually mapping kernel memory.

Previous patch fixed the early_memremap function to return a normal pointer instead of __iomem pointer. Also introduced a new function early_memunmap which accept normal pointer as the argument.

This patch is fixing the sparse warnings as below:
1. use early_memremap instead of early_ioremap
2. use early_memunmap instead of early_iounmap

---
 arch/x86/platform/efi/efi.c | 20 ++++++++++----------
 drivers/firmware/efi/efi.c  |  4 ++--
 2 files changed, 12 insertions(+), 12 deletions(-)
arch/x86/platform/efi/efi.c +10 -10
index 7d8cacc..b1e07a4 100644
@@ -456,7 +456,7 @@ void __init efi_unmap_memmap(void)
 {
 	clear_bit(EFI_MEMMAP, &x86_efi_facility);
 	if (memmap.map) {
-		early_iounmap(memmap.map, memmap.nr_map * memmap.desc_size);
+		early_memunmap(memmap.map, memmap.nr_map * memmap.desc_size);
 		memmap.map = NULL;
 	}
 }
@@ -493,7 +493,7 @@ static int __init efi_systab_init(void *phys)
 		efi_system_table_64_t *systab64;
 		u64 tmp = 0;
 
-		systab64 = early_ioremap((unsigned long)phys,
+		systab64 = early_memremap((unsigned long)phys,
 					 sizeof(*systab64));
 		if (systab64 == NULL) {
 			pr_err("Couldn't map the system table!\n");
@@ -524,7 +524,7 @@ static int __init efi_systab_init(void *phys)
 		efi_systab.tables = systab64->tables;
 		tmp |= systab64->tables;
 
-		early_iounmap(systab64, sizeof(*systab64));
+		early_memunmap(systab64, sizeof(*systab64));
 #ifdef CONFIG_X86_32
 		if (tmp >> 32) {
 			pr_err("EFI data located above 4GB, disabling EFI.\n");
@@ -534,7 +534,7 @@ static int __init efi_systab_init(void *phys)
 	} else {
 		efi_system_table_32_t *systab32;
 
-		systab32 = early_ioremap((unsigned long)phys,
+		systab32 = early_memremap((unsigned long)phys,
 					 sizeof(*systab32));
 		if (systab32 == NULL) {
 			pr_err("Couldn't map the system table!\n");
@@ -555,7 +555,7 @@ static int __init efi_systab_init(void *phys)
 		efi_systab.nr_tables = systab32->nr_tables;
 		efi_systab.tables = systab32->tables;
 
-		early_iounmap(systab32, sizeof(*systab32));
+		early_memunmap(systab32, sizeof(*systab32));
 	}
 
 	efi.systab = &efi_systab;
@@ -586,7 +586,7 @@ static int __init efi_runtime_init(void)
 	 * address of several of the EFI runtime functions, needed to
 	 * set the firmware into virtual mode.
 	 */
-	runtime = early_ioremap((unsigned long)efi.systab->runtime,
+	runtime = early_memremap((unsigned long)efi.systab->runtime,
 				sizeof(efi_runtime_services_t));
 	if (!runtime) {
 		pr_err("Could not map the runtime service table!\n");
@@ -606,7 +606,7 @@ static int __init efi_runtime_init(void)
 	 * virtual mode.
 	 */
 	efi.get_time = phys_efi_get_time;
-	early_iounmap(runtime, sizeof(efi_runtime_services_t));
+	early_memunmap(runtime, sizeof(efi_runtime_services_t));
 
 	return 0;
 }
@@ -614,7 +614,7 @@ static int __init efi_runtime_init(void)
 static int __init efi_memmap_init(void)
 {
 	/* Map the EFI memory map */
-	memmap.map = early_ioremap((unsigned long)memmap.phys_map,
+	memmap.map = early_memremap((unsigned long)memmap.phys_map,
 				   memmap.nr_map * memmap.desc_size);
 	if (memmap.map == NULL) {
 		pr_err("Could not map the memory map!\n");
@@ -656,14 +656,14 @@ void __init efi_init(void)
 	/*
 	 * Show what we know for posterity
 	 */
-	c16 = tmp = early_ioremap(efi.systab->fw_vendor, 2);
+	c16 = tmp = early_memremap(efi.systab->fw_vendor, 2);
 	if (c16) {
 		for (i = 0; i < sizeof(vendor) - 1 && *c16; ++i)
 			vendor[i] = *c16++;
 		vendor[i] = '\0';
 	} else
 		pr_err("Could not map the firmware vendor!\n");
-	early_iounmap(tmp, 2);
+	early_memunmap(tmp, 2);
 
 	pr_info("EFI v%u.%.02u by %s\n",
 		efi.systab->hdr.revision >> 16,
drivers/firmware/efi/efi.c +2 -2
index 2e2fbde..b716a66 100644
@@ -253,7 +253,7 @@ int __init efi_config_init(efi_config_table_type_t *arch_tables)
 			if (table64 >> 32) {
 				pr_cont("\n");
 				pr_err("Table located above 4GB, disabling EFI.\n");
-				early_iounmap(config_tables,
+				early_memunmap(config_tables,
 					       efi.systab->nr_tables * sz);
 				return -EINVAL;
 			}
@@ -269,6 +269,6 @@ int __init efi_config_init(efi_config_table_type_t *arch_tables)
 		tablep += sz;
 	}
 	pr_cont("\n");
-	early_iounmap(config_tables, efi.systab->nr_tables * sz);
+	early_memunmap(config_tables, efi.systab->nr_tables * sz);
 	return 0;
 }
Signature · 1 line
1.8.3.1
author
#3 lore raw

PATCH v7 3/12 efi: remove unused variables in __map_region

In reply to Dave Young

variables size and end is useless in this function, thus remove them.

---
 arch/x86/platform/efi/efi_64.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
arch/x86/platform/efi/efi_64.c +1 -5
index bf286c3..c5a6491 100644
@@ -148,15 +148,11 @@ void efi_setup_page_tables(void)
 static void __init __map_region(efi_memory_desc_t *md, u64 va)
 {
 	pgd_t *pgd = (pgd_t *)__va(real_mode_header->trampoline_pgd);
-	unsigned long pf = 0, size;
-	u64 end;
+	unsigned long pf = 0;
 
 	if (!(md->attribute & EFI_MEMORY_WB))
 		pf |= _PAGE_PCD;
 
-	size = md->num_pages << PAGE_SHIFT;
-	end  = va + size;
-
 	if (kernel_map_pages_in_pgd(pgd, md->phys_addr, va, md->num_pages, pf))
 		pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
 			   md->phys_addr, va);
Signature · 1 line
1.8.3.1
author
#4 lore raw

PATCH v7 4/12 efi: add a wrapper function efi_map_region_fixed

In reply to Dave Young

Kexec kernel will use saved runtime virtual mapping, so add a new function efi_map_region_fixed for directly mapping a md to md->virt.

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

Matt: coding style
reuse __map_region
Boris: Strenthen comment lines to 80 cols.

---
 arch/x86/include/asm/efi.h     |  1 +
 arch/x86/platform/efi/efi_32.c |  2 ++
 arch/x86/platform/efi/efi_64.c | 10 ++++++++++
 3 files changed, 13 insertions(+)
arch/x86/include/asm/efi.h +1 -0
index 89a05b0..9fbaeb2 100644
@@ -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_32.c +2 -0
index e94557c..7b3ec6e 100644
@@ -47,6 +47,8 @@ void __init efi_map_region(efi_memory_desc_t *md)
 	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;
arch/x86/platform/efi/efi_64.c +10 -0
index c5a6491..ff08cb1 100644
@@ -199,6 +199,16 @@ void __init efi_map_region(efi_memory_desc_t *md)
 	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)
+{
+	__map_region(md, md->virt_addr);
+}
+
 void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size,
 				 u32 type, u64 attribute)
 {
Signature · 1 line
1.8.3.1
author
#5 lore raw

PATCH v7 5/12 efi: reserve boot service fix

In reply to Dave Young

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
index b1e07a4..f022294 100644
@@ -438,7 +438,7 @@ void __init efi_reserve_boot_services(void)
 		 * - 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)) {
Signature · 1 line
1.8.3.1
author
#6 lore raw

PATCH v7 6/12 efi: cleanup efi_enter_virtual_mode function

In reply to Dave Young

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.

v2->v3:
Toshi Kani:
remove unused variable
Matt: check return value of krealloc.
v3->v4:
Boris: Stretch comment to 80 cols
fix krealloc bug.
v4->v5:
Add a new share function get_systab_virt_addr() since later efi_map_regions_fixed will call it.

---
 arch/x86/platform/efi/efi.c | 132 ++++++++++++++++++++++++++------------------
 1 file changed, 79 insertions(+), 53 deletions(-)
arch/x86/platform/efi/efi.c +79 -53
index f022294..fd49100 100644
@@ -766,44 +766,12 @@ void __init old_map_region(efi_memory_desc_t *md)
 		       (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 __init 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;
@@ -828,8 +796,31 @@ void __init efi_enter_virtual_mode(void)
 			continue;
 		}
 		prev_md = md;
+	}
+}
+
+static void __init get_systab_virt_addr(efi_memory_desc_t *md)
+{
+	unsigned long size;
+	u64 end, systab;
 
+	size = md->num_pages << EFI_PAGE_SHIFT;
+	end = md->phys_addr + size;
+	systab = (u64)(unsigned long)efi_phys.systab;
+	if (md->phys_addr <= systab && systab < end) {
+		systab += md->virt_addr - md->phys_addr;
+		efi.systab = (efi_system_table_t *)(unsigned long)systab;
 	}
+}
+
+/*
+ * Map efi memory ranges for runtime serivce and update new_memmap with virtual
+ * addresses.
+ */
+static void * __init efi_map_regions(int *count)
+{
+	efi_memory_desc_t *md;
+	void *p, *tmp, *new_memmap = NULL;
 
 	for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
 		md = p;
@@ -842,26 +833,64 @@ void __init efi_enter_virtual_mode(void)
 		}
 
 		efi_map_region(md);
+		get_systab_virt_addr(md);
+
+		tmp = krealloc(new_memmap, (*count + 1) * memmap.desc_size,
+			       GFP_KERNEL);
+		if (!tmp)
+			goto out_krealloc;
+		new_memmap = tmp;
+		memcpy(new_memmap + (*count * memmap.desc_size), md,
+		       memmap.desc_size);
+		(*count)++;
+	}
 
-		size = md->num_pages << EFI_PAGE_SHIFT;
-		end = md->phys_addr + size;
+	return new_memmap;
+out_krealloc:
+	kfree(new_memmap);
+	return NULL;
+}
+
+/*
+ * 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 *new_memmap = NULL;
+	int count = 0;
 
-		systab = (u64) (unsigned long) efi_phys.systab;
-		if (md->phys_addr <= systab && systab < end) {
-			systab += md->virt_addr - md->phys_addr;
+	efi.systab = NULL;
 
-			efi.systab = (efi_system_table_t *) (unsigned long) systab;
-		}
+	/*
+	 * 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;
+	}
 
-		new_memmap = krealloc(new_memmap,
-				      (count + 1) * memmap.desc_size,
-				      GFP_KERNEL);
-		if (!new_memmap)
-			goto err_out;
+	efi_merge_regions();
 
-		memcpy(new_memmap + (count * memmap.desc_size), md,
-		       memmap.desc_size);
-		count++;
+	new_memmap = efi_map_regions(&count);
+	if (!new_memmap) {
+		pr_err("Error reallocating memory, EFI runtime non-functional!\n");
+		return;
 	}
 
 	BUG_ON(!efi.systab);
@@ -915,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");
 }
 
 /*
Signature · 1 line
1.8.3.1
author
#7 lore raw

PATCH v7 7/12 efi: export more efi table variable to sysfs

In reply to Dave Young

Export fw_vendor, runtime and config table physical addresses to /sys/firmware/efi/{fw_vendor,runtime,config_table} because kexec kernel 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.

changelog:
Greg: add standalone sysfs files instead of add lines to systab Document them as testing ABI
Greg: use group attrs and is_visible
Boris: align comments lines
Boris: add macros for _show functions, documentation fixes.
Matt: Documentation fixes.

---
 Documentation/ABI/testing/sysfs-firmware-efi | 20 ++++++++++++++
 arch/x86/platform/efi/efi.c                  |  4 +++
 drivers/firmware/efi/efi.c                   | 41 +++++++++++++++++++++++++++-
 include/linux/efi.h                          |  3 ++
 4 files changed, 67 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-firmware-efi
Documentation/ABI/testing/sysfs-firmware-efi new file +20 -0
new file mode 100644
index 0000000..05874da
@@ -0,0 +1,20 @@
+What:		/sys/firmware/efi/fw_vendor
+Date:		December 2013
+Contact:	Dave Young <[email protected]>
+Description:	It shows the physical address of firmware vendor field in the
+		EFI system table.
+Users:		Kexec
+
+What:		/sys/firmware/efi/runtime
+Date:		December 2013
+Contact:	Dave Young <[email protected]>
+Description:	It shows the physical address of runtime service table entry in
+		the EFI system table.
+Users:		Kexec
+
+What:		/sys/firmware/efi/config_table
+Date:		December 2013
+Contact:	Dave Young <[email protected]>
+Description:	It shows the physical address of config table entry in the EFI
+		system table.
+Users:		Kexec
arch/x86/platform/efi/efi.c +4 -0
index fd49100..d12d145 100644
@@ -653,6 +653,10 @@ void __init efi_init(void)
 
 	set_bit(EFI_SYSTEM_TABLES, &x86_efi_facility);
 
+	efi.config_table = (unsigned long)efi.systab->tables;
+	efi.fw_vendor	 = (unsigned long)efi.systab->fw_vendor;
+	efi.runtime	 = (unsigned long)efi.systab->runtime;
+
 	/*
 	 * Show what we know for posterity
 	 */
drivers/firmware/efi/efi.c +40 -1

59 lines not on this page · raw message

include/linux/efi.h +3 -0
index 49ece2c..988af61 100644
@@ -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;	/* fw_vendor */
+	unsigned long runtime;		/* runtime table */
+	unsigned long config_table;	/* config tables */
 	efi_get_time_t *get_time;
 	efi_set_time_t *set_time;
 	efi_get_wakeup_time_t *get_wakeup_time;
Signature · 1 line
1.8.3.1
author
#8 lore raw

PATCH v7 8/12 efi: export efi runtime memory mapping to sysfs

In reply to Dave Young

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 directory /sys/firmware/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

Changelog:
- Cleaup code, add function efi_save_runtime_map
- Improve err handling
- Add macros for sysfs _show functions
- Remove forward declarations.
Matt:
- s/efi-runtime-map.c/runtime-map.c
- Change dir name to runtime-map
- Changelog and documentation fixes.
- Documentation fixes.
- Update to use desc_size in efi_runtime_map
- Kconfig EFI_RUNTIME_MAP depends on X86 && KEXEC && EFI Boris:
- Documentation grammar/spelling fix
- krealloc fix.
- Move efi_runtime_map_init to efisubsys_initcall.
- Remove 'if EXPERT' for EFI_RUNTIME_MAP Kconfig option
- save_runtime_map: move error handling code into the function itself.
- other code improvement.
Me:
- userspace prepares valid memmap in boot_params thus in this version cleanup and improve save_runtime_map as a standalone function which iterate the memmap again. In this way code looks better also it is easier for later efi_kexec splitting.

---
 .../ABI/testing/sysfs-firmware-efi-runtime-map     |  34 ++++
 arch/x86/platform/efi/efi.c                        |  46 +++++-
 drivers/firmware/efi/Kconfig                       |  11 ++
 drivers/firmware/efi/Makefile                      |   1 +
 drivers/firmware/efi/efi.c                         |   4 +
 drivers/firmware/efi/runtime-map.c                 | 181 +++++++++++++++++++++
 include/linux/efi.h                                |  13 ++
 7 files changed, 287 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-firmware-efi-runtime-map
 create mode 100644 drivers/firmware/efi/runtime-map.c
Documentation/ABI/testing/sysfs-firmware-efi-runtime-map new file +34 -0
new file mode 100644
index 0000000..c61b9b3
@@ -0,0 +1,34 @@
+What:		/sys/firmware/efi/runtime-map/
+Date:		December 2013
+Contact:	Dave Young <[email protected]>
+Description:	Switching efi runtime services to virtual mode requires
+		that all efi memory ranges which have the runtime attribute
+		bit set to be mapped to virtual addresses.
+
+		The efi runtime services can only be switched to virtual
+		mode once without rebooting. The kexec kernel must maintain
+		the same physical to virtual address mappings as the first
+		kernel. The mappings are exported to sysfs so userspace tools
+		can reassemble them and pass them into the kexec kernel.
+
+		/sys/firmware/efi/runtime-map/ is the directory the kernel
+		exports that information in.
+
+		subdirectories are named with the number of the memory range:
+
+			/sys/firmware/efi/runtime-map/0
+			/sys/firmware/efi/runtime-map/1
+			/sys/firmware/efi/runtime-map/2
+			/sys/firmware/efi/runtime-map/3
+			...
+
+		Each subdirectory contains five files:
+
+		attribute : The attributes of the memory range.
+		num_pages : The size of the memory range in pages.
+		phys_addr : The physical address of the memory range.
+		type      : The type of the memory range.
+		virt_addr : The virtual address of the memory range.
+
+		Above values are all hexadecimal numbers with the '0x' prefix.
+Users:		Kexec
arch/x86/platform/efi/efi.c +43 -3

82 lines not on this page · raw message

drivers/firmware/efi/Kconfig +11 -0
index 6aecbc8..1e75f48 100644
@@ -36,6 +36,17 @@ 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 "Export efi runtime maps to sysfs"
+	depends on X86 && EFI && KEXEC
+	default y
+	help
+	  Export efi runtime memory maps 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-firmware-efi-runtime-map.
+
 endmenu
 
 config UEFI_CPER
drivers/firmware/efi/Makefile +1 -0
index 6c2a41e..9553496 100644
@@ -5,3 +5,4 @@ obj-$(CONFIG_EFI)			+= efi.o vars.o
 obj-$(CONFIG_EFI_VARS)			+= efivars.o
 obj-$(CONFIG_EFI_VARS_PSTORE)		+= efi-pstore.o
 obj-$(CONFIG_UEFI_CPER)			+= cper.o
+obj-$(CONFIG_EFI_RUNTIME_MAP)		+= runtime-map.o
drivers/firmware/efi/efi.c +4 -0
index 6d0bc52..7910cd5 100644
@@ -167,6 +167,10 @@ static int __init efisubsys_init(void)
 		goto err_unregister;
 	}
 
+	error = efi_runtime_map_init(efi_kobj);
+	if (error)
+		goto err_remove_group;
+
 	/* and the standard mountpoint for efivarfs */
 	efivars_kobj = kobject_create_and_add("efivars", efi_kobj);
 	if (!efivars_kobj) {
drivers/firmware/efi/runtime-map.c new file +181 -0

181 lines not on this page · raw message

include/linux/efi.h +13 -0
index 988af61..0a819e7 100644
@@ -876,4 +876,17 @@ int efivars_sysfs_init(void);
 
 #endif /* CONFIG_EFI_VARS */
 
+#ifdef CONFIG_EFI_RUNTIME_MAP
+int efi_runtime_map_init(struct kobject *);
+void efi_runtime_map_setup(void *, int, u32);
+#else
+static inline int efi_runtime_map_init(struct kobject *kobj)
+{
+	return 0;
+}
+
+static inline void
+efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
+#endif
+
 #endif /* _LINUX_EFI_H */
Signature · 1 line
1.8.3.1
author
#9 lore raw

PATCH v7 9/12 efi: passing kexec necessary efi data via setup_data

In reply to Dave Young

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 we need save the smbios physical address. The kernel boot sequence proceeds in the following order. Step 2 requires efi.smbios to be the physical address. However, I found that on HP z420 EFI system table has a virtual address of SMBIOS in step 1. Hence, we need set it back to the physical address with the smbios in efi_setup_data. (When it is still the physical address, it simply sets the same value.)

1. efi_init() - Set efi.smbios from EFI system table
2. dmi_scan_machine() - Temporary map efi.smbios to access SMBIOS table
3. efi_enter_virtual_mode() - Map EFI ranges

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

v2: refresh based on previous patch changes, code cleanup.
v3: use ioremap instead of phys_to_virt for efi_setup
v5: improve some code structure per comments from Matt
Boris: improve code structure, spell fix, etc.
Improve changelog from Toshi.
change the variable efi_setup to the physical address of efi setup_data instead of the ioremapped virt address
v6: Boris: Documentation fixes
move parse_efi_setup to efi_$(BITS).c
simplify parse_efi_setup logic
Matt: check return value of efi_reuse_config
v7: cleanup efi_map_regions and efi_map_regions_fixed
remove useless return at the end of efi_enter_virtual_mode

---
 arch/x86/include/asm/efi.h            |  13 +++
 arch/x86/include/uapi/asm/bootparam.h |   1 +
 arch/x86/kernel/setup.c               |   3 +
 arch/x86/platform/efi/efi.c           | 159 ++++++++++++++++++++++++++++------
 arch/x86/platform/efi/efi_32.c        |   1 +
 arch/x86/platform/efi/efi_64.c        |   6 ++
 6 files changed, 158 insertions(+), 25 deletions(-)
arch/x86/include/asm/efi.h +13 -0
index 9fbaeb2..cfcf438 100644
@@ -133,6 +133,19 @@ 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);
 
+struct efi_setup_data {
+	u64 fw_vendor;
+	u64 runtime;
+	u64 tables;
+	u64 smbios;
+	u64 reserved[8];
+	efi_memory_desc_t map[0];
+};
+
+extern u64 efi_setup;
+extern u32 efi_data_len;
+extern void parse_efi_setup(u64 phys_addr, u32 data_len);
+
 #ifdef CONFIG_EFI
 
 static inline bool efi_is_native(void)
arch/x86/include/uapi/asm/bootparam.h +1 -0
index 9c3733c..64fe421 100644
@@ -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/kernel/setup.c +3 -0
index f97cf4d..8032615 100644
@@ -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 +134 -25

246 lines not on this page · raw message

arch/x86/platform/efi/efi_32.c +1 -0
index 7b3ec6e..249b183 100644
@@ -48,6 +48,7 @@ void __init efi_map_region(efi_memory_desc_t *md)
 }
 
 void __init efi_map_region_fixed(efi_memory_desc_t *md) {}
+void __init parse_efi_setup(u64 phys_addr, u32 data_len) {}
 
 void efi_call_phys_prelog(void)
 {
arch/x86/platform/efi/efi_64.c +6 -0
index ff08cb1..324b651 100644
@@ -228,3 +228,9 @@ void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size,
 
 	return (void __iomem *)__va(phys_addr);
 }
+
+void __init parse_efi_setup(u64 phys_addr, u32 data_len)
+{
+	efi_setup = phys_addr + sizeof(struct setup_data);
+	efi_data_len = data_len - sizeof(struct setup_data);
+}
Signature · 1 line
1.8.3.1
#10 lore raw

Re: [PATCH v7 09/12] efi: passing kexec necessary efi data via setup_data

Quoted 44 lines · Dave Young

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 we need save the smbios physical address. The kernel boot sequence proceeds in the following order. Step 2 requires efi.smbios to be the physical address. However, I found that on HP z420 EFI system table has a virtual address of SMBIOS in step 1. Hence, we need set it back to the physical address with the smbios in efi_setup_data. (When it is still the physical address, it simply sets the same value.)

1. efi_init() - Set efi.smbios from EFI system table
2. dmi_scan_machine() - Temporary map efi.smbios to access SMBIOS table
3. efi_enter_virtual_mode() - Map EFI ranges

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

v2: refresh based on previous patch changes, code cleanup.
v3: use ioremap instead of phys_to_virt for efi_setup
v5: improve some code structure per comments from Matt
Boris: improve code structure, spell fix, etc.
Improve changelog from Toshi.
change the variable efi_setup to the physical address of efi setup_data instead of the ioremapped virt address
v6: Boris: Documentation fixes
move parse_efi_setup to efi_$(BITS).c
simplify parse_efi_setup logic
Matt: check return value of efi_reuse_config
v7: cleanup efi_map_regions and efi_map_regions_fixed
remove useless return at the end of efi_enter_virtual_mode

---
 arch/x86/include/asm/efi.h            |  13 +++
 arch/x86/include/uapi/asm/bootparam.h |   1 +
 arch/x86/kernel/setup.c               |   3 +
 arch/x86/platform/efi/efi.c           | 159 ++++++++++++++++++++++++++++------
 arch/x86/platform/efi/efi_32.c        |   1 +
 arch/x86/platform/efi/efi_64.c        |   6 ++
 6 files changed, 158 insertions(+), 25 deletions(-)

[...]

Quoted 7 lines
arch/x86/platform/efi/efi.c +4 -2
 		efi_systab.hdr = systab64->hdr;
-		efi_systab.fw_vendor = systab64->fw_vendor;
-		tmp |= systab64->fw_vendor;
+
+		efi_systab.fw_vendor = data ? (unsigned long)data->fw_vendor :
+					      systab64->fw_vendor;
+		tmp |= efi_systab.fw_vendor;

[... snip ...]

Quoted 15 lines
arch/x86/platform/efi/efi.c +4 -4
@@ -519,15 +530,20 @@ static int __init efi_systab_init(void *phys)
 		tmp |= systab64->stderr_handle;
 		efi_systab.stderr = systab64->stderr;
 		tmp |= systab64->stderr;
-		efi_systab.runtime = (void *)(unsigned long)systab64->runtime;
-		tmp |= systab64->runtime;
+		efi_systab.runtime = data ?
+				     (void *)(unsigned long)data->runtime :
+				     (void *)(unsigned long)systab64->runtime;
+		tmp |= (unsigned long)efi_systab.runtime;
 		efi_systab.boottime = (void *)(unsigned long)systab64->boottime;
 		tmp |= systab64->boottime;
 		efi_systab.nr_tables = systab64->nr_tables;
-		efi_systab.tables = systab64->tables;
-		tmp |= systab64->tables;

arch/x86/platform/efi/efi.c static int __init efi_systab_init(void *phys) · line 549

Quoted 10 lines
arch/x86/platform/efi/efi.c +5 -0
+		efi_systab.tables = data ? (unsigned long)data->tables :
+					   systab64->tables;
+		tmp |= efi_systab.tables;
 
 		early_memunmap(systab64, sizeof(*systab64));
+		if (data)
+			early_memunmap(data, sizeof(*data));
 #ifdef CONFIG_X86_32
 		if (tmp >> 32) {
 			pr_err("EFI data located above 4GB, disabling EFI.\n");

This isn't correct, and means we now won't trigger this pr_err() if booting a CONFIG_X86_32 kernel with EFI_64BIT and where the ->fw_vendor, ->runtime or ->tables pointer is above 4GB - you've mixed up systab and systab64. I've fixed this up like so when applying this patch,

---

@@ -494,18 +495,27 @@ static int __init efi_systab_init(void *phys)
{
if (efi_enabled(EFI_64BIT)) {
efi_system_table_64_t *systab64;
+ struct efi_setup_data *data = NULL;
u64 tmp = 0;

+ if (efi_setup) {
+ data = early_memremap(efi_setup, sizeof(*data));
+ if (!data)
+ return -ENOMEM;
+ }
systab64 = early_ioremap((unsigned long)phys,
sizeof(*systab64));
if (systab64 == NULL) {
pr_err("Couldn't map the system table!\n");
+ if (data)
+ early_iounmap(data, sizeof(*data));
return -ENOMEM;
}

efi_systab.hdr = systab64->hdr;
- efi_systab.fw_vendor = systab64->fw_vendor;
- tmp |= systab64->fw_vendor;
+ efi_systab.fw_vendor = data ? (unsigned long)data->fw_vendor :
+ systab64->fw_vendor;
+ tmp |= data ? data->fw_vendor : systab64->fw_vendor;
efi_systab.fw_revision = systab64->fw_revision; efi_systab.con_in_handle = systab64->con_in_handle; tmp |= systab64->con_in_handle;
@@ -519,15 +529,20 @@ static int __init efi_systab_init(void *phys)
tmp |= systab64->stderr_handle;
efi_systab.stderr = systab64->stderr;
tmp |= systab64->stderr;
- efi_systab.runtime = (void *)(unsigned long)systab64->runtime;
- tmp |= systab64->runtime;
+ efi_systab.runtime = data ?
+ (void *)(unsigned long)data->runtime :
+ (void *)(unsigned long)systab64->runtime;
+ tmp |= data ? data->runtime : systab64->runtime;
efi_systab.boottime = (void *)(unsigned long)systab64->boottime; tmp |= systab64->boottime;
efi_systab.nr_tables = systab64->nr_tables;
- efi_systab.tables = systab64->tables;
- tmp |= systab64->tables;
+ efi_systab.tables = data ? (unsigned long)data->tables :
+ systab64->tables;
+ tmp |= data ? data->tables : systab64->tables;

early_iounmap(systab64, sizeof(*systab64));
+ if (data)
+ early_iounmap(data, sizeof(*data));
#ifdef CONFIG_X86_32
if (tmp >> 32) {
pr_err("EFI data located above 4GB, disabling EFI.\n");

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

Re: [PATCH v7 09/12] efi: passing kexec necessary efi data via setup_data

Quoted 10 lines

arch/x86/platform/efi/efi.c static int __init efi_systab_init(void *phys) · line 549

Quoted 5 lines
arch/x86/platform/efi/efi.c +2 -0
+		if (data)
+			early_memunmap(data, sizeof(*data));
 #ifdef CONFIG_X86_32
 		if (tmp >> 32) {
 			pr_err("EFI data located above 4GB, disabling EFI.\n");

This isn't correct, and means we now won't trigger this pr_err() if booting a CONFIG_X86_32 kernel with EFI_64BIT and where the ->fw_vendor, ->runtime or ->tables pointer is above 4GB - you've mixed up systab and systab64. I've fixed this up like so when applying this patch,

You are right, I missed this 32bit tmp value, thanks for taking care of this.

Thanks
Dave

#12 lore raw

Re: [PATCH v7 09/12] efi: passing kexec necessary efi data via setup_data

In reply to Dave Young
Quoted 12 lines · Dave Young
arch/x86/include/asm/efi.h +8 -0
@@ -133,6 +133,19 @@ 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);
 
+struct efi_setup_data {
+	u64 fw_vendor;
+	u64 runtime;
+	u64 tables;
+	u64 smbios;
+	u64 reserved[8];
+	efi_memory_desc_t map[0];
+};

[...]

arch/x86/platform/efi/efi.c static int __init efi_memmap_init(void) · line 713

Quoted 8 lines
arch/x86/platform/efi/efi.c +8 -0
+static void get_nr_runtime_map(void)
+{
+	if (!efi_setup)
+		return;
+
+	nr_efi_runtime_map = (efi_data_len - sizeof(struct efi_setup_data)) /
+			     sizeof(efi_memory_desc_t);
+}

Do we actually need the 'map' entry in efi_setup_data now that you're passing it via efi_info (which is much better approach!)? Also, we don't need the global nr_efi_runtime_map or efi_runtime_map variables now, right?

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

Re: [PATCH v7 09/12] efi: passing kexec necessary efi data via setup_data

Quoted 16 lines · Matt Fleming
Quoted 12 lines · Dave Young
arch/x86/include/asm/efi.h +8 -0
@@ -133,6 +133,19 @@ 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);
 
+struct efi_setup_data {
+	u64 fw_vendor;
+	u64 runtime;
+	u64 tables;
+	u64 smbios;
+	u64 reserved[8];
+	efi_memory_desc_t map[0];
+};

[...]

Quoted 13 lines

arch/x86/platform/efi/efi.c static int __init efi_memmap_init(void) · line 713

Quoted 8 lines
arch/x86/platform/efi/efi.c +8 -0
+static void get_nr_runtime_map(void)
+{
+	if (!efi_setup)
+		return;
+
+	nr_efi_runtime_map = (efi_data_len - sizeof(struct efi_setup_data)) /
+			     sizeof(efi_memory_desc_t);
+}

Do we actually need the 'map' entry in efi_setup_data now that you're passing it via efi_info (which is much better approach!)? Also, we don't need the global nr_efi_runtime_map or efi_runtime_map variables now, right?

The map is still necessary because we need store the map somewhere and pass the physicall address to kexec kernel. Passing them in setup_data is the only better way currently...

In efi_info there's only an entry for the map physical address, the original map area is not valid any more.

Thanks
Dave

author
#14 lore raw

Re: [PATCH v7 09/12] efi: passing kexec necessary efi data via setup_data

Quoted 11 lines
Quoted 4 lines

Do we actually need the 'map' entry in efi_setup_data now that you're passing it via efi_info (which is much better approach!)? Also, we don't need the global nr_efi_runtime_map or efi_runtime_map variables now, right?

The map is still necessary because we need store the map somewhere and pass the physicall address to kexec kernel. Passing them in setup_data is the only better way currently...

In efi_info there's only an entry for the map physical address, the original map area is not valid any more.

For kexec kernel it might be ok to use the old map area, but for kdump kernel we can only use the memory which is early reserved with crashkernel= cmdline.

Thanks
Dave

#15 lore raw

Re: [PATCH v7 09/12] efi: passing kexec necessary efi data via setup_data

In reply to Dave Young
Quoted 31 lines · Dave Young
Quoted 16 lines · Matt Fleming
Quoted 12 lines · Dave Young
arch/x86/include/asm/efi.h +8 -0
@@ -133,6 +133,19 @@ 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);
 
+struct efi_setup_data {
+	u64 fw_vendor;
+	u64 runtime;
+	u64 tables;
+	u64 smbios;
+	u64 reserved[8];
+	efi_memory_desc_t map[0];
+};

[...]

Quoted 13 lines

arch/x86/platform/efi/efi.c static int __init efi_memmap_init(void) · line 713

Quoted 8 lines
arch/x86/platform/efi/efi.c +8 -0
+static void get_nr_runtime_map(void)
+{
+	if (!efi_setup)
+		return;
+
+	nr_efi_runtime_map = (efi_data_len - sizeof(struct efi_setup_data)) /
+			     sizeof(efi_memory_desc_t);
+}

Do we actually need the 'map' entry in efi_setup_data now that you're passing it via efi_info (which is much better approach!)? Also, we don't need the global nr_efi_runtime_map or efi_runtime_map variables now, right?

Quoted 6 lines

The map is still necessary because we need store the map somewhere and pass the physicall address to kexec kernel. Passing them in setup_data is the only better way currently...

In efi_info there's only an entry for the map physical address, the original map area is not valid any more.

Where do you dereference efi_setup_data.map* in the kexec kernel?

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

Re: [PATCH v7 09/12] efi: passing kexec necessary efi data via setup_data

Quoted 32 lines · Matt Fleming
Quoted 31 lines · Dave Young
Quoted 29 lines · Matt Fleming
Quoted 12 lines · Dave Young
arch/x86/include/asm/efi.h +8 -0
@@ -133,6 +133,19 @@ 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);
 
+struct efi_setup_data {
+	u64 fw_vendor;
+	u64 runtime;
+	u64 tables;
+	u64 smbios;
+	u64 reserved[8];
+	efi_memory_desc_t map[0];
+};

[...]

arch/x86/platform/efi/efi.c static int __init efi_memmap_init(void) · line 713

Quoted 8 lines
arch/x86/platform/efi/efi.c +8 -0
+static void get_nr_runtime_map(void)
+{
+	if (!efi_setup)
+		return;
+
+	nr_efi_runtime_map = (efi_data_len - sizeof(struct efi_setup_data)) /
+			     sizeof(efi_memory_desc_t);
+}

Do we actually need the 'map' entry in efi_setup_data now that you're passing it via efi_info (which is much better approach!)? Also, we don't need the global nr_efi_runtime_map or efi_runtime_map variables now, right?

Quoted 8 lines
Quoted 6 lines

The map is still necessary because we need store the map somewhere and pass the physicall address to kexec kernel. Passing them in setup_data is the only better way currently...

In efi_info there's only an entry for the map physical address, the original map area is not valid any more.

Where do you dereference efi_setup_data.map* in the kexec kernel?

The field itself is not dereferenced in kernel but it's still used in userspace code for collecting and saving runtime maps. Since I still append the map at the end of efi_setup_data so I think keep the map[0] is ok. What's your opinion?

Thanks
Dave

author
#17 lore raw

Re: [PATCH v7 09/12] efi: passing kexec necessary efi data via setup_data

Quoted 37 lines · Dave Young
Quoted 36 lines · Matt Fleming
Quoted 35 lines · Dave Young
Quoted 16 lines · Matt Fleming
Quoted 12 lines · Dave Young
(quoted diff) +8 -0
@@ -133,6 +133,19 @@ 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);
 
+struct efi_setup_data {
+	u64 fw_vendor;
+	u64 runtime;
+	u64 tables;
+	u64 smbios;
+	u64 reserved[8];
+	efi_memory_desc_t map[0];
+};

[...]

Quoted 13 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+static void get_nr_runtime_map(void)
+{
+	if (!efi_setup)
+		return;
+
+	nr_efi_runtime_map = (efi_data_len - sizeof(struct efi_setup_data)) /
+			     sizeof(efi_memory_desc_t);
+}

Do we actually need the 'map' entry in efi_setup_data now that you're passing it via efi_info (which is much better approach!)? Also, we don't need the global nr_efi_runtime_map or efi_runtime_map variables now, right?

The map is still necessary because we need store the map somewhere and pass the physicall address to kexec kernel. Passing them in setup_data is the only better way currently...

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

In efi_info there's only an entry for the map physical address, the original map area is not valid any more.

Where do you dereference efi_setup_data.map* in the kexec kernel?

The field itself is not dereferenced in kernel but it's still used in userspace code for collecting and saving runtime maps. Since I still append the map at the end of efi_setup_data so I think keep the map[0] is ok. What's your opinion?

Matt, if you want to remove the map[0] please fold below one line patch? I have no strong opinion.

arch/x86/include/asm/efi.h +0 -1
Index: linux/arch/x86/include/asm/efi.h
===================================================================
@@ -139,7 +139,6 @@ struct efi_setup_data {
 	u64 tables;
 	u64 smbios;
 	u64 reserved[8];
-	efi_memory_desc_t map[0];
 };
 
 extern u64 efi_setup;
#18 lore raw

Re: [PATCH v7 09/12] efi: passing kexec necessary efi data via setup_data

Quoted 9 lines · Dave Young

Matt, if you want to remove the map[0] please fold below one line patch? I have no strong opinion.

Index: linux/arch/x86/include/asm/efi.h
===================================================================

arch/x86/include/asm/efi.h struct efi_setup_data { · line 144

Quoted 7 lines
arch/x86/include/asm/efi.h +0 -1
@@ -139,7 +139,6 @@ struct efi_setup_data {
 	u64 tables;
 	u64 smbios;
 	u64 reserved[8];
-	efi_memory_desc_t map[0];
 };
 
 extern u64 efi_setup;

Thanks Dave, I will fold this in. I would suggest updating your kexec-tools patches so that the two structures are in sync.

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

Re: [PATCH v7 09/12] efi: passing kexec necessary efi data via setup_data

Quoted 16 lines · Matt Fleming
Quoted 15 lines · Dave Young

Matt, if you want to remove the map[0] please fold below one line patch? I have no strong opinion.

Index: linux/arch/x86/include/asm/efi.h
===================================================================

arch/x86/include/asm/efi.h +0 -1
@@ -139,7 +139,6 @@ struct efi_setup_data {
 	u64 tables;
 	u64 smbios;
 	u64 reserved[8];
-	efi_memory_desc_t map[0];
 };
 
Quoted 4 lines

arch/x86/include/asm/efi.h struct efi_setup_data { · line 144

Quoted 1 line
arch/x86/include/asm/efi.h +0 -0
 extern u64 efi_setup;

Thanks Dave, I will fold this in. I would suggest updating your kexec-tools patches so that the two structures are in sync.

Sure, since it is removed in kernel I will update kexec-tools.

Thanks
Dave

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

PATCH v7 10/12 x86: add xloadflags bit for efi runtime support on kexec

In reply to Dave Young

Old kexec-tools can not load new kernel. The reason is kexec-tools do not fill efi_info in x86 setup header previously, thus efi failed to initialize. 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 can succeed finally.

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

changelog:
Matt: +&& defined(CONFIG_KEXEC)
improve patch description.
HPA: document the flag.

---
 Documentation/x86/boot.txt            | 3 +++
 arch/x86/boot/header.S                | 9 ++++++++-
 arch/x86/include/uapi/asm/bootparam.h | 1 +
 3 files changed, 12 insertions(+), 1 deletion(-)
Documentation/x86/boot.txt +3 -0
index f4f268c..cb81741d 100644
@@ -608,6 +608,9 @@ Protocol:       2.12+
 	- If 1, the kernel supports the 64-bit EFI handoff entry point
           given at handover_offset + 0x200.
 
+  Bit 4 (read): XLF_EFI_KEXEC
+	- If 1, the kernel supports kexec EFI boot with EFI runtime support.
+
 Field name:	cmdline_size
 Type:		read
 Offset/size:	0x238/4
arch/x86/boot/header.S +8 -1
index 9ec06a1..ec3b8ba 100644
@@ -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)
+# 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
index 64fe421..225b098 100644
@@ -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__
 
Signature · 1 line
1.8.3.1
author
#21 lore raw

PATCH v7 11/12 x86: export x86 boot_params to sysfs

In reply to Dave Young

kexec-tools use boot_params for getting the 1st kernel hardware_subarch, the kexec kernel efi runtime support also need read the old efi_info from boot_params. Currently it exists in debugfs which is not a good place for such infomation. Per HPA, we should avoid of "sploit debugfs".

In this patch /sys/kernel/boot_params are exported, also the setup_data is exported as a subdirectory. kexec-tools is using debugfs for hardware_subarch for a long time now so we're not removing it yet.

Structure is like below:

/sys/kernel/boot_params

|__ data                /* boot_params in binary*/
|__ setup_data
|   |__ 0               /* the first setup_data node */
|   |   |__ data        /* setup_data node 0 in binary*/
|   |   |__ type        /* setup_data type of setup_data node 0, hex string */

[snip]
|__ version /* boot protocal version (in hex, "0x" prefixed)*/

Changelog:
Greg: use __ATTR_RO() and group attr.
Matt and Boris: Documentation improvement, code indentation. Documentation fix.

---
 Documentation/ABI/testing/sysfs-kernel-boot_params |  38 +++
 arch/x86/kernel/Makefile                           |   1 +
 arch/x86/kernel/ksysfs.c                           | 339 +++++++++++++++++++++
 3 files changed, 378 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-boot_params
 create mode 100644 arch/x86/kernel/ksysfs.c
Documentation/ABI/testing/sysfs-kernel-boot_params new file +38 -0
new file mode 100644
index 0000000..eca38ce
@@ -0,0 +1,38 @@
+What:		/sys/kernel/boot_params
+Date:		December 2013
+Contact:	Dave Young <[email protected]>
+Description:	The /sys/kernel/boot_params directory contains two
+		files: "data" and "version" and one subdirectory "setup_data".
+		It is used to export the kernel boot parameters of an x86
+		platform to userspace for kexec and debugging purpose.
+
+		If there's no setup_data in boot_params the subdirectory will
+		not be created.
+
+		"data" file is the binary representation of struct boot_params.
+
+		"version" file is the string representation of boot
+		protocol version.
+
+		"setup_data" subdirectory contains the setup_data data
+		structure in boot_params. setup_data is maintained in kernel
+		as a link list. In "setup_data" subdirectory there's one
+		subdirectory for each link list node named with the number
+		of the list nodes. The list node subdirectory contains two
+		files "type" and "data". "type" file is the string
+		representation of setup_data type. "data" file is the binary
+		representation of setup_data payload.
+
+		The whole boot_params directory structure is like below:
+		/sys/kernel/boot_params
+		|__ data
+		|__ setup_data
+		|   |__ 0
+		|   |   |__ data
+		|   |   |__ type
+		|   |__ 1
+		|       |__ data
+		|       |__ type
+		|__ version
+
+Users:		Kexec
arch/x86/kernel/Makefile +1 -0
index 9b0a34e..510cca5 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_X86_64)	+= sys_x86_64.o x8664_ksyms_64.o
 obj-y			+= syscall_$(BITS).o
 obj-$(CONFIG_X86_64)	+= vsyscall_64.o
 obj-$(CONFIG_X86_64)	+= vsyscall_emu_64.o
+obj-$(CONFIG_SYSFS)	+= ksysfs.o
 obj-y			+= bootflag.o e820.o
 obj-y			+= pci-dma.o quirks.o topology.o kdebugfs.o
 obj-y			+= alternative.o i8253.o pci-nommu.o hw_breakpoint.o
arch/x86/kernel/ksysfs.c new file +339 -0

339 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#22 lore raw

PATCH v7 12/12 x86: reserve setup_data ranges late after parsing memmap cmdline

In reply to Dave Young

Currently e820_reserve_setup_data is called before parsing early params, it works in normal case. But for memmap=exactmap, the final memory ranges are created after parsing memmap= cmdline params, so the previous e820_reserve_setup_data has no effect. For example, setup_data ranges will still be marked as normal system ram, thus when later sysfs driver ioremap them kernel will warn about mapping normal ram.

This patch fix it by moving the e820_reserve_setup_data callback after parsing early params so they can be set as reserved ranges and later ioremap will be fine with it.

changes:
Boris: improve patch description

---
 arch/x86/kernel/setup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/setup.c +2 -2
index 8032615..5a7b2a0 100644
@@ -941,8 +941,6 @@ void __init setup_arch(char **cmdline_p)
 	iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
 	setup_memory_map();
 	parse_setup_data();
-	/* update the e820_saved too */
-	e820_reserve_setup_data();
 
 	copy_edd();
 
@@ -1004,6 +1002,8 @@ void __init setup_arch(char **cmdline_p)
 		early_dump_pci_devices();
 #endif
 
+	/* update the e820_saved too */
+	e820_reserve_setup_data();
 	finish_e820_parsing();
 
 	if (efi_enabled(EFI_BOOT))
Signature · 1 line
1.8.3.1
Tested-by on the v7 series
#23 lore raw
In reply to Dave Young
Quoted 27 lines · Dave Young

Here is the V7 patchset 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/, smbios is already in /sys/firmware/efi/systab.

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

|__ 0
|   |__ attribute
|   |__ num_pages
|   |__ phys_addr
|   |__ type
|   |__ virt_addr
|__ 1

[snip]

Quoted 8 lines

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

Tested on an HP 60-way UEFI platform (proto). For the series:

Thanks,
-Toshi

#24 lore raw
In reply to Dave Young
Quoted 10 lines · Dave Young

Here is the V7 patchset 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.

OK Dave, I've pulled patches 3-12 into the 'kexec' branch at,

git://git.kernel.org/pub/scm/linux/kernel/git/mfleming/efi.git

I plan on sending this branch to the tip folks this week for further testing.

Please have a look and make sure I haven't messed anything up when dropping the first two patches (though they were very small and trival).

Toshi, if you could grab that branch and give it a test, that'd be excellent.

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
#25 lore raw
Quoted 16 lines · Matt Fleming
Quoted 10 lines · Dave Young

Here is the V7 patchset 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.

OK Dave, I've pulled patches 3-12 into the 'kexec' branch at,

git://git.kernel.org/pub/scm/linux/kernel/git/mfleming/efi.git

Quoted 8 lines

I plan on sending this branch to the tip folks this week for further testing.

Please have a look and make sure I haven't messed anything up when dropping the first two patches (though they were very small and trival).

Toshi, if you could grab that branch and give it a test, that'd be excellent.

The kexec branch is missing the following change, which is required for fast reboot with multi-cpus.

commit 279f1df915c3a6ed3075d98a849705bf53851f99
Author: Vivek Goyal <[email protected]>
Date: Tue Nov 26 10:25:28 2013 +0800

kexec: migrate to reboot cpu

With this change added, I confirmed that the branch kernel works fine.

Thanks,
-Toshi

#26 lore raw
Quoted 11 lines · Toshi Kani

The kexec branch is missing the following change, which is required for fast reboot with multi-cpus.

commit 279f1df915c3a6ed3075d98a849705bf53851f99
Author: Vivek Goyal <[email protected]>
Date: Tue Nov 26 10:25:28 2013 +0800

kexec: migrate to reboot cpu

With this change added, I confirmed that the branch kernel works fine.

I can't find that commit in Linus' tree. Where is it from?

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
#27 lore raw
Quoted 9 lines · Matt Fleming
Quoted 8 lines · Toshi Kani

The kexec branch is missing the following change, which is required for fast reboot with multi-cpus.

   commit 279f1df915c3a6ed3075d98a849705bf53851f99
   Author: Vivek Goyal <[email protected]>
   Date:   Tue Nov 26 10:25:28 2013 +0800
Quoted 5 lines
Quoted 3 lines

kexec: migrate to reboot cpu

With this change added, I confirmed that the branch kernel works fine.

I can't find that commit in Linus' tree. Where is it from?

Dave's git tree for the patchset has this change. This change was accepted by Vivek, so I think it is in his tree.

Thanks,
-Toshi

author Tested-by Baoquan He Tested-by WANG Chao Acked-by H. Peter Anvin
#28 lore raw
In reply to Matt Fleming
Quoted 9 lines · Matt Fleming
Quoted 8 lines · Toshi Kani

The kexec branch is missing the following change, which is required for fast reboot with multi-cpus.

   commit 279f1df915c3a6ed3075d98a849705bf53851f99
   Author: Vivek Goyal <[email protected]>
   Date:   Tue Nov 26 10:25:28 2013 +0800
Quoted 5 lines
Quoted 3 lines

kexec: migrate to reboot cpu

With this change added, I confirmed that the branch kernel works fine.

I can't find that commit in Linus' tree. Where is it from?

Previously it was in Andrew's mm tree, currently it's below commit in linus tree:

commit c97102ba96324da330078ad8619ba4dfe840dbe3

Author: Vivek Goyal <[email protected]>
Date:   Wed Dec 18 17:08:31 2013 -0800

kexec: migrate to reboot cpu

Commit 1b3a5d02ee07 ("reboot: move arch/x86 reboot= handling to generic kernel") moved reboot= handling to generic code. In the process it also removed the code in native_machine_shutdown() which are moving reboot process to reboot_cpu/cpu0.

I guess that thought must have been that all reboot paths are calling migrate_to_reboot_cpu(), so we don't need this special handling. But kexec reboot path (kernel_kexec()) is not calling migrate_to_reboot_cpu() so above change broke kexec. Now reboot can happen on non-boot cpu and when INIT is sent in second kerneo to bring up BP, it brings down the machine.

So start calling migrate_to_reboot_cpu() in kexec reboot path to avoid this problem.

Bisected by WANG Chao.

author
#29 lore raw
In reply to Matt Fleming
Quoted 14 lines · Matt Fleming
Quoted 10 lines · Dave Young

Here is the V7 patchset 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.

OK Dave, I've pulled patches 3-12 into the 'kexec' branch at,

Quoted 7 lines

git://git.kernel.org/pub/scm/linux/kernel/git/mfleming/efi.git

I plan on sending this branch to the tip folks this week for further testing.

Please have a look and make sure I haven't messed anything up when dropping the first two patches (though they were very small and trival).

Matt, I have reviewed them, it looks good to me. Thanks for removing the global variable in your last one.

Thanks
Dave

author
#30 lore raw
In reply to Matt Fleming
Quoted 12 lines · Matt Fleming
Quoted 10 lines · Dave Young

Here is the V7 patchset 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.

Quoted 7 lines

OK Dave, I've pulled patches 3-12 into the 'kexec' branch at,

git://git.kernel.org/pub/scm/linux/kernel/git/mfleming/efi.git

I plan on sending this branch to the tip folks this week for further testing.

Hi, Matt

randconfig build robot reports several problems:
1. sparse warnings which should be fixed by the early_memremap patches
2. ksysfs.c building fails because of lack include <asm/io.h>
3. parse_efi_setup is called in arch/x86/kernel/setup.c, but if it will faill in case withoug CONFIG_EFI.

Here is the fix for 2. and 3, please take a look. I'm not sure if I should resend the patches or leave them to you.

(Build tested with the configs mentioned in the failure report email. Tested kexec boot in OVMF/qemu virtual machine)

Thanks a lot~
-----------------

build fix: include asm/io.h for calling ioremap_cache

---
 arch/x86/kernel/ksysfs.c |    1 +
 1 file changed, 1 insertion(+)
arch/x86/kernel/ksysfs.c +1 -0
Index: linux/arch/x86/kernel/ksysfs.c
===================================================================
@@ -16,6 +16,7 @@
 #include <linux/stat.h>
 #include <linux/slab.h>
 #include <linux/mm.h>
+#include <asm/io.h>
 
 #include <asm/setup.h>
 

build fix: move parse_efi_setup to efi*.c, call it in efi_init instead in setup.c

---
 arch/x86/include/asm/efi.h     |    3 +--
 arch/x86/kernel/setup.c        |    3 ---
 arch/x86/platform/efi/efi.c    |    1 +
 arch/x86/platform/efi/efi_32.c |    2 +-
 arch/x86/platform/efi/efi_64.c |   18 ++++++++++++++++--
 5 files changed, 19 insertions(+), 8 deletions(-)
arch/x86/include/asm/efi.h +1 -2
Index: linux/arch/x86/include/asm/efi.h
===================================================================
@@ -143,8 +143,7 @@ struct efi_setup_data {
 };
 
 extern u64 efi_setup;
-extern u32 efi_data_len;
-extern void parse_efi_setup(u64 phys_addr, u32 data_len);
+extern void parse_efi_setup(void);
 
 #ifdef CONFIG_EFI
 
arch/x86/kernel/setup.c +0 -3
Index: linux/arch/x86/kernel/setup.c
===================================================================
@@ -447,9 +447,6 @@ 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 +1 -0
Index: linux/arch/x86/platform/efi/efi.c
===================================================================
@@ -719,6 +719,7 @@ void __init efi_init(void)
 			  ((__u64)boot_params.efi_info.efi_systab_hi<<32));
 #endif
 
+	parse_efi_setup();
 	if (efi_systab_init(efi_phys.systab))
 		return;
 
arch/x86/platform/efi/efi_32.c +1 -1
Index: linux/arch/x86/platform/efi/efi_32.c
===================================================================
@@ -48,7 +48,7 @@ void __init efi_map_region(efi_memory_de
 }
 
 void __init efi_map_region_fixed(efi_memory_desc_t *md) {}
-void __init parse_efi_setup(u64 phys_addr, u32 data_len) {}
+void __init parse_efi_setup(void) {}
 
 void efi_call_phys_prelog(void)
 {
arch/x86/platform/efi/efi_64.c +16 -2
Index: linux/arch/x86/platform/efi/efi_64.c
===================================================================
@@ -229,7 +229,21 @@ void __iomem *__init efi_ioremap(unsigne
 	return (void __iomem *)__va(phys_addr);
 }
 
-void __init parse_efi_setup(u64 phys_addr, u32 data_len)
+void __init parse_efi_setup(void)
 {
-	efi_setup = phys_addr + sizeof(struct setup_data);
+	struct setup_data *data;
+	u64 pa_data;
+
+	pa_data = boot_params.hdr.setup_data;
+	while (pa_data) {
+		u32 map_len;
+
+		map_len = max(PAGE_SIZE - (pa_data & ~PAGE_MASK),
+			      (u64)sizeof(struct setup_data));
+		data = early_memremap(pa_data, map_len);
+		if (data->type == SETUP_EFI)
+			efi_setup = pa_data + sizeof(struct setup_data);
+		pa_data = data->next;
+		early_iounmap(data, map_len);
+	}
 }
#31 lore raw
Quoted 5 lines · Dave Young

Hi, Matt

randconfig build robot reports several problems:
1. sparse warnings which should be fixed by the early_memremap patches

Yeah, this will be fixed up when Mark's memremap patch series gets merged.

Quoted 2 lines

Here is the fix for 2. and 3, please take a look. I'm not sure if I should resend the patches or leave them to you.

Please send these as separate patches and include the compiler errors in the commit message. I'll pick them up and send them to Peter.

Quoted 1 line

build fix: move parse_efi_setup to efi*.c, call it in efi_init instead in setup.c

Why have you moved the call site for parse_efi_setup()? What's the rationale? Parsing SETUP_* entries outside of parse_setup_data() seems to me to be a step backwards in terms of clarity.

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

Please send these as separate patches and include the compiler errors in the commit message. I'll pick them up and send them to Peter.

Sent.

Quoted 6 lines
Quoted 2 lines

build fix: move parse_efi_setup to efi*.c, call it in efi_init instead in setup.c

Why have you moved the call site for parse_efi_setup()? What's the rationale? Parsing SETUP_* entries outside of parse_setup_data() seems to me to be a step backwards in terms of clarity.

SETUP_PCI also duplicate the parsing logic out of setup.c.
I added static inline in ifdef else branch, but I got some warnings yestoday about "unused function", double checked it today there's no such warnings anymore, it might be caused by some mistake.

Changed to static inline {} in patches I just sent a moment ago.

Thanks
Dave