arm64 kexec kernel patches V8
Subsystems (5)
cover arm64 kexec kernel patches V8
Hi All,
This series adds the core support for kexec re-boots on arm64. This v8 of the series is mainly just a rebase to Linux-4.0-rc3, and a few very minor changes requested for v7.
To load a second stage kernel and execute a kexec re-boot on arm64 my patches to kexec-tools [2], which have not yet been merged upstream, are needed.
I have tested with the ARM VE fast model, the ARM Base model and the ARM Foundation model with various kernel config options for both the first and second stage kernels. Kexec on EFI systems works correctly. With the ACPI kernel patches from [3] applied, kexec on ACPI systems seeems to work correctly. More ACPI + kexec testing is needed.
Patch 1 here moves the macros from proc-macros.S to asm/assembler.h so that the dcache_line_size macro it defines can be uesd by kexec's relocate kernel routine.
Patches 2-4 rework the arm64 hcall mechanism to give the arm64 soft_restart() routine the ability to switch exception levels from EL1 to EL2 for kernels that were entered in EL2.
Patches 5-6 add the actual kexec support.
Please consider all patches for inclusion.
[1] https://git.kernel.org/cgit/linux/kernel/git/geoff/linux-kexec.git [2] https://git.kernel.org/cgit/linux/kernel/git/geoff/kexec-tools.git [3] http://git.linaro.org/leg/acpi/acpi.git #acpi-topic-juno-fvp
Several things are known to have problems on kexec re-boot:
spin-table
----------
PROBLEM: The spin-table enable method does not implement all the methods needed for CPU hot-plug, so the first stage kernel cannot be shutdown properly.
WORK-AROUND: Upgrade to system firmware that provides PSCI enable method support, OR build the first stage kernel with CONFIG_SMP=n, OR pass 'maxcpus=1' on the first stage kernel command line.
FIX: Upgrade system firmware to provide PSCI enable method support or add missing spin-table support to the kernel.
KVM
---
PROBLEM: KVM acquires hypervisor resources on startup, but does not free those resources on shutdown, so the first stage kernel cannot be shutdown properly when using kexec.
WORK-AROUND: Build the first stage kernel with CONFIG_KVM=n, or apply KVM bug fix patches from [1].
FIX: Takahiro Akashi has preliminary patches to fix the KVM shutdown problem. I have those in my master branch at [1]. KVM + kexec works properly with that branch. Patches neeeded:
arm64: kvm: add a cpu tear-down function
arm64: kexec: fix kvm issue
arm64/kvm: Remove !KEXEC Kconfig dependency
arm64/kexec: Enable kexec in the arm64 defconfig
/memreserve/
----------
PROBLEM: Device tree /memreserve/ entries are not available in /proc/device-tree. For systems that have /memreserve/ entries and use /proc/device-tree during kexec, the second stage kernel will use the reserved regions and the system will become unstable.
WORK-AROUND: Enable the kernel config option CONFIG_SYSFS=y to expose a binary device tree to user space at /sys/firmware/fdt that includes /memreserve/ entries OR pass a user specified DTB using the kexec --dtb option.
FIX: This is expected behavior. To maximize user support, rework device tree definitions to not use /memreserve/ entries.
-Geoff
The following changes since commit 06e5801b8cb3fc057d88cb4dc03c0b64b2744cda:
Linux 4.0-rc4 (2015-03-15 17:38:20 -0700)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/geoff/linux-kexec.git kexec-v8
for you to fetch changes up to 9d94104463ae6e3472526fb69e8111201c4a1fa7:
arm64/kexec: Add pr_devel output (2015-03-19 12:21:43 -0700)
----------------------------------------------------------------
Geoff Levand (6):
arm64: Fold proc-macros.S into assembler.h
arm64: Convert hcalls to use HVC immediate value
arm64: Add new hcall HVC_CALL_FUNC
arm64: Add EL2 switch to soft_restart arm64/kexec: Add core kexec support arm64/kexec: Add pr_devel output
arch/arm64/Kconfig | 9 ++ arch/arm64/include/asm/assembler.h | 37 ++++++- arch/arm64/include/asm/kexec.h | 48 +++++++++ arch/arm64/include/asm/proc-fns.h | 4 +- arch/arm64/include/asm/virt.h | 40 ++++++++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/hyp-stub.S | 43 +++++--- arch/arm64/kernel/machine_kexec.c | 189 ++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/process.c | 6 +- arch/arm64/kernel/relocate_kernel.S | 149 ++++++++++++++++++++++++++++ arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/hyp.S | 16 +-- arch/arm64/mm/cache.S | 2 - arch/arm64/mm/proc-macros.S | 54 ----------- arch/arm64/mm/proc.S | 49 +++++++--- include/uapi/linux/kexec.h | 1 + 16 files changed, 557 insertions(+), 92 deletions(-) create mode 100644 arch/arm64/include/asm/kexec.h create mode 100644 arch/arm64/kernel/machine_kexec.c create mode 100644 arch/arm64/kernel/relocate_kernel.S delete mode 100644 arch/arm64/mm/proc-macros.S
Signature · 7 lines
2.1.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 1/6 arm64: Fold proc-macros.S into assembler.h
To allow the assembler macros defined in arch/arm64/mm/proc-macros.S to be used outside the mm code move the contents of proc-macros.S to asm/assembler.h. Also, delete proc-macros.S, and fix up all references to proc-macros.S.
--- arch/arm64/include/asm/assembler.h | 37 +++++++++++++++++++++++++- arch/arm64/mm/cache.S | 2 -- arch/arm64/mm/proc-macros.S | 54 -------------------------------------- arch/arm64/mm/proc.S | 2 -- 4 files changed, 36 insertions(+), 59 deletions(-) delete mode 100644 arch/arm64/mm/proc-macros.S
arch/arm64/include/asm/assembler.h +36 -1
@@ -1,5 +1,5 @@/* -* Based on arch/arm/include/asm/assembler.h +* Based on arch/arm/include/asm/assembler.h, arch/arm/mm/proc-macros.S * * Copyright (C) 1996-2000 Russell King * Copyright (C) 2012 ARM Ltd.
@@ -23,6 +23,7 @@#ifndef __ASM_ASSEMBLER_H#define __ASM_ASSEMBLER_H +#include <asm/asm-offsets.h> #include <asm/ptrace.h> #include <asm/thread_info.h>
@@ -159,4 +160,38 @@ lr .req x30 // link register orr \rd, \lbits, \hbits, lsl #32 .endm +/* + * vma_vm_mm - get mm pointer from vma pointer (vma->vm_mm) + */ + .macro vma_vm_mm, rd, rn + ldr \rd, [\rn, #VMA_VM_MM] + .endm + +/* + * mmid - get context id from mm pointer (mm->context.id) + */ + .macro mmid, rd, rn + ldr \rd, [\rn, #MM_CONTEXT_ID] + .endm + +/* + * dcache_line_size - get the minimum D-cache line size from the CTR register. + */ + .macro dcache_line_size, reg, tmp + mrs \tmp, ctr_el0 // read CTR + ubfm \tmp, \tmp, #16, #19 // cache line size encoding + mov \reg, #4 // bytes per word + lsl \reg, \reg, \tmp // actual cache line size + .endm + +/* + * icache_line_size - get the minimum I-cache line size from the CTR register. + */ + .macro icache_line_size, reg, tmp + mrs \tmp, ctr_el0 // read CTR + and \tmp, \tmp, #0xf // cache line size encoding + mov \reg, #4 // bytes per word + lsl \reg, \reg, \tmp // actual cache line size + .endm + #endif /* __ASM_ASSEMBLER_H */
arch/arm64/mm/cache.S +0 -2
@@ -24,8 +24,6 @@ #include <asm/cpufeature.h> #include <asm/alternative-asm.h> -#include "proc-macros.S" - /* * __flush_dcache_all() *
arch/arm64/mm/proc-macros.S deleted +0 -54
54 lines not on this page · raw message
arch/arm64/mm/proc.S +0 -2
@@ -26,8 +26,6 @@ #include <asm/pgtable-hwdef.h> #include <asm/pgtable.h> -#include "proc-macros.S" - #ifdef CONFIG_ARM64_64K_PAGES #define TCR_TG_FLAGS TCR_TG0_64K | TCR_TG1_64K #else
Signature · 8 lines
2.1.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 2/6 arm64: Convert hcalls to use HVC immediate value
In reply to Geoff LevandThe existing arm64 hcall implementations are limited in that they only allow for two distinct hcalls; with the x0 register either zero or not zero. Also, the API of the hyp-stub exception vector routines and the KVM exception vector routines differ; hyp-stub uses a non-zero value in x0 to implement __hyp_set_vectors, whereas KVM uses it to implement kvm_call_hyp.
To allow for additional hcalls to be defined and to make the arm64 hcall API more consistent across exception vector routines, change the hcall implementations to use the 16 bit immediate value of the HVC instruction to specify the hcall type.
Define three new preprocessor macros HVC_CALL_HYP, HVC_GET_VECTORS, and HVC_SET_VECTORS to be used as hcall type specifiers and convert the existing __hyp_get_vectors(), __hyp_set_vectors() and kvm_call_hyp() routines to use these new macros when executing an HVC call. Also, change the corresponding hyp-stub and KVM el1_sync exception vector routines to use these new macros.
--- arch/arm64/include/asm/virt.h | 27 +++++++++++++++++++++++++++ arch/arm64/kernel/hyp-stub.S | 32 +++++++++++++++++++++----------- arch/arm64/kvm/hyp.S | 16 +++++++++------- 3 files changed, 57 insertions(+), 18 deletions(-)
arch/arm64/include/asm/virt.h +27 -0
@@ -18,6 +18,33 @@#ifndef __ASM__VIRT_H#define __ASM__VIRT_H +/* +* The arm64 hcall implementation uses the ISS field of the ESR_EL2 register to +* specify the hcall type. The exception handlers are allowed to use registers +* x17 and x18 in their implementation. Any routine issuing an hcall must not +* expect these registers to be preserved. +*/ + +/* +* HVC_CALL_HYP - Execute a hyp routine. +*/ + +#define HVC_CALL_HYP 0 + +/* +* HVC_GET_VECTORS - Return the value of the vbar_el2 register. +*/ + +#define HVC_GET_VECTORS 1 + +/* +* HVC_SET_VECTORS - Set the value of the vbar_el2 register. +* +* @x0: Physical address of the new vector table. +*/ + +#define HVC_SET_VECTORS 2 +#define BOOT_CPU_MODE_EL1 (0xe11)#define BOOT_CPU_MODE_EL2 (0xe12)
arch/arm64/kernel/hyp-stub.S +21 -11
@@ -22,6 +22,7 @@ #include <linux/irqchip/arm-gic-v3.h> #include <asm/assembler.h> +#include <asm/kvm_arm.h> #include <asm/ptrace.h> #include <asm/virt.h>
@@ -53,14 +54,22 @@ ENDPROC(__hyp_stub_vectors) .align 11 el1_sync: - mrs x1, esr_el2 - lsr x1, x1, #26 - cmp x1, #0x16 + mrs x18, esr_el2 + lsr x17, x18, #ESR_ELx_EC_SHIFT + and x18, x18, #ESR_ELx_ISS_MASK + + cmp x17, #ESR_ELx_EC_HVC64 b.ne 2f // Not an HVC trap - cbz x0, 1f - msr vbar_el2, x0 // Set vbar_el2 + + cmp x18, #HVC_GET_VECTORS + b.ne 1f + mrs x0, vbar_el2 b 2f -1: mrs x0, vbar_el2 // Return vbar_el2 + +1: cmp x18, #HVC_SET_VECTORS + b.ne 2f + msr vbar_el2, x0 + 2: eret ENDPROC(el1_sync)
@@ -100,11 +109,12 @@ ENDPROC(\label) * initialisation entry point. */ -ENTRY(__hyp_get_vectors) - mov x0, xzr - // fall through ENTRY(__hyp_set_vectors) - hvc #0 + hvc #HVC_SET_VECTORS ret -ENDPROC(__hyp_get_vectors) ENDPROC(__hyp_set_vectors) + +ENTRY(__hyp_get_vectors) + hvc #HVC_GET_VECTORS + ret +ENDPROC(__hyp_get_vectors)
arch/arm64/kvm/hyp.S +9 -7
@@ -27,6 +27,7 @@ #include <asm/kvm_asm.h> #include <asm/kvm_mmu.h> #include <asm/memory.h> +#include <asm/virt.h> #define CPU_GP_REG_OFFSET(x) (CPU_GP_REGS + x) #define CPU_XREG_OFFSET(x) CPU_GP_REG_OFFSET(CPU_USER_PT_REGS + 8*x)
@@ -1129,12 +1130,9 @@ __hyp_panic_str: * in Hyp mode (see init_hyp_mode in arch/arm/kvm/arm.c). Return values are * passed in r0 and r1. * - * A function pointer with a value of 0 has a special meaning, and is - * used to implement __hyp_get_vectors in the same way as in - * arch/arm64/kernel/hyp_stub.S. */ ENTRY(kvm_call_hyp) - hvc #0 + hvc #HVC_CALL_HYP ret ENDPROC(kvm_call_hyp)
@@ -1165,6 +1163,7 @@ el1_sync: // Guest trapped into EL2 mrs x1, esr_el2 lsr x2, x1, #ESR_ELx_EC_SHIFT + and x0, x1, #ESR_ELx_ISS_MASK cmp x2, #ESR_ELx_EC_HVC64 b.ne el1_trap
@@ -1173,15 +1172,18 @@ el1_sync: // Guest trapped into EL2 cbnz x3, el1_trap // called HVC /* Here, we're pretty sure the host called HVC. */ + mov x18, x0 pop x2, x3 pop x0, x1 - /* Check for __hyp_get_vectors */ - cbnz x0, 1f + cmp x18, #HVC_GET_VECTORS + b.ne 1f mrs x0, vbar_el2 b 2f -1: push lr, xzr +1: /* Default to HVC_CALL_HYP. */ + + push lr, xzr /* * Compute the function address in EL2, and shuffle the parameters.
Signature · 8 lines
2.1.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 2/6] arm64: Convert hcalls to use HVC immediate value
Quoted 11 lines · Geoff Levand
The existing arm64 hcall implementations are limited in that they only allow for two distinct hcalls; with the x0 register either zero or not zero. Also, the API of the hyp-stub exception vector routines and the KVM exception vector routines differ; hyp-stub uses a non-zero value in x0 to implement
__hyp_set_vectors, whereas KVM uses it to implementkvm_call_hyp.To allow for additional hcalls to be defined and to make the arm64 hcall API more consistent across exception vector routines, change the hcall implementations to use the 16 bit immediate value of the HVC instruction to specify the hcall type.
Quoted 8 lines
Define three new preprocessor macros
HVC_CALL_HYP,HVC_GET_VECTORS, andHVC_SET_VECTORSto be used as hcall type specifiers and convert the existing__hyp_get_vectors(),__hyp_set_vectors()andkvm_call_hyp()routines to use these new macros when executing an HVC call. Also, change the corresponding hyp-stub and KVMel1_syncexception vector routines to use these new macros.Signed-off-by Geoff Levand <[email protected]>
What is the status of this patch? I see it's not in 4.2. I ask because this patch might be breaking our 4.2-based kernel, and I'm just wondering if it's still applicable.
Signature · 8 lines
Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 2/6] arm64: Convert hcalls to use HVC immediate value
Quoted 3 lines · Timur Tabi
What is the status of this patch? I see it's not in 4.2. I ask because this patch might be breaking our 4.2-based kernel, and I'm just wondering if it's still applicable.
I have it in my linux-kexec repo, which currently based on 4.3-rc2. I plan to submit it again in the next week or so after testing.
-Geoff
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH 3/6 arm64: Add new hcall HVC_CALL_FUNC
In reply to Geoff LevandAdd the new hcall HVC_CALL_FUNC that allows execution of a function at EL2. During CPU reset the CPU must be brought to the exception level it had on entry to the kernel. The HVC_CALL_FUNC hcall will provide the mechanism needed for this exception level switch.
To allow the HVC_CALL_FUNC exception vector to work without a stack, which is needed to support an hcall at CPU reset, this implementation uses register x18 to store the link register across the caller provided function. This dictates that the caller provided function must preserve the contents of register x18.
--- arch/arm64/include/asm/virt.h | 13 +++++++++++++ arch/arm64/kernel/hyp-stub.S | 13 ++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-)
arch/arm64/include/asm/virt.h +13 -0
@@ -45,6 +45,19 @@#define HVC_SET_VECTORS 2 +/* +* HVC_CALL_FUNC - Execute a function at EL2. +* +* @x0: Physical address of the function to be executed. +* @x1: Passed as the first argument to the function. +* @x2: Passed as the second argument to the function. +* @x3: Passed as the third argument to the function. +* +* The called function must preserve the contents of register x18. +*/ + +#define HVC_CALL_FUNC 3 +#define BOOT_CPU_MODE_EL1 (0xe11)#define BOOT_CPU_MODE_EL2 (0xe12)
arch/arm64/kernel/hyp-stub.S +12 -1
@@ -67,8 +67,19 @@ el1_sync: b 2f 1: cmp x18, #HVC_SET_VECTORS - b.ne 2f + b.ne 1f msr vbar_el2, x0 + b 2f + +1: cmp x18, #HVC_CALL_FUNC + b.ne 2f + mov x18, lr + mov lr, x0 + mov x0, x1 + mov x1, x2 + mov x2, x3 + blr lr + mov lr, x18 2: eret ENDPROC(el1_sync)
Signature · 8 lines
2.1.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 4/6 arm64: Add EL2 switch to soft_restart
In reply to Geoff LevandWhen a CPU is reset it needs to be put into the exception level it had when it entered the kernel. Update cpu_reset() to accept an argument which signals if the soft reset address needs to be entered at EL1 or EL2.
This implementation updates cpu_soft_restart() and soft_restart() to pass the return value of is_hyp_mode_available() as the switch argument to cpu_reset(). Also, update the comments of cpu_reset(), cpu_soft_restart() and soft_restart() to reflect this change.
--- arch/arm64/include/asm/proc-fns.h | 4 ++-- arch/arm64/kernel/process.c | 6 ++++- arch/arm64/mm/proc.S | 47 +++++++++++++++++++++++++++++---------- 3 files changed, 42 insertions(+), 15 deletions(-)
arch/arm64/include/asm/proc-fns.h +2 -2
@@ -32,8 +32,8 @@ extern void cpu_cache_off(void);extern void cpu_do_idle (void );extern void cpu_do_switch_mm (unsigned long pgd_phys,struct mm_struct *mm);extern void cpu_reset (unsigned long addr) __attribute__((noreturn)); -void cpu_soft_restart (phys_addr_t cpu_reset, -unsigned long addr) __attribute__((noreturn)); +void cpu_soft_restart (phys_addr_t cpu_reset,unsigned long el2_switch, +unsigned long addr) __attribute__((noreturn));extern void cpu_do_suspend (struct cpu_suspend_ctx *ptr);extern u64 cpu_do_resume (phys_addr_t ptr,u64 idmap_ttbr);
arch/arm64/kernel/process.c +5 -1
@@ -51,6 +51,7 @@#include <asm/mmu_context.h> #include <asm/processor.h> #include <asm/stacktrace.h> +#include <asm/virt.h> #ifdef CONFIG_CC_STACKPROTECTOR #include <linux/stackprotector.h>
@@ -61,7 +62,10 @@ EXPORT_SYMBOL(__stack_chk_guard);void soft_restart (unsigned long addr) {setup_mm_for_reboot (); -cpu_soft_restart (virt_to_phys (cpu_reset), addr); + +cpu_soft_restart (virt_to_phys (cpu_reset), +is_hyp_mode_available (), addr); +/* Should never get here */ BUG (); }
arch/arm64/mm/proc.S +35 -12
74 lines not on this page · raw message
Signature · 8 lines
2.1.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 5/6 arm64/kexec: Add core kexec support
In reply to Geoff LevandAdd three new files, kexec.h, machine_kexec.c and relocate_kernel.S to the arm64 architecture that add support for the kexec re-boot mechanism (CONFIG_KEXEC) on arm64 platforms.
With the addition of arm64 kexec support shutdown code paths through the kernel are executed that previously were not. To avoid system instability do to problems in the current arm64 KVM kernel implementation add a Kconfig dependency on !KEXEC to the arm64 KVM menu item.
--- arch/arm64/Kconfig | 9 +++ arch/arm64/include/asm/kexec.h | 48 ++++++++++++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/machine_kexec.c | 125 ++++++++++++++++++++++++++++++ arch/arm64/kernel/relocate_kernel.S | 149 ++++++++++++++++++++++++++++++++++++ arch/arm64/kvm/Kconfig | 1 + include/uapi/linux/kexec.h | 1 + 7 files changed, 334 insertions(+) create mode 100644 arch/arm64/include/asm/kexec.h create mode 100644 arch/arm64/kernel/machine_kexec.c create mode 100644 arch/arm64/kernel/relocate_kernel.S
arch/arm64/Kconfig +9 -0
@@ -528,6 +528,15 @@ config SECCOMP and the task is only allowed to execute a few safe syscalls defined by each seccomp mode. +config KEXEC + depends on (!SMP || PM_SLEEP_SMP) + bool "kexec system call" + ---help--- + kexec is a system call that implements the ability to shutdown your + current kernel, and to start another kernel. It is like a reboot + but it is independent of the system firmware. And like a reboot + you can start any kernel with it, not just Linux. + config XEN_DOM0 def_bool y depends on XEN
arch/arm64/include/asm/kexec.h new file +48 -0
48 lines not on this page · raw message
arch/arm64/kernel/Makefile +1 -0
@@ -35,6 +35,7 @@ arm64-obj-$(CONFIG_KGDB) += kgdb.o arm64-obj-$(CONFIG_EFI) += efi.o efi-stub.o efi-entry.o arm64-obj-$(CONFIG_PCI) += pci.o arm64-obj-$(CONFIG_ARMV8_DEPRECATED) += armv8_deprecated.o +arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o obj-y += $(arm64-obj-y) vdso/ obj-m += $(arm64-obj-m)
arch/arm64/kernel/machine_kexec.c new file +125 -0
125 lines not on this page · raw message
arch/arm64/kernel/relocate_kernel.S new file +149 -0
149 lines not on this page · raw message
arch/arm64/kvm/Kconfig +1 -0
@@ -18,6 +18,7 @@ if VIRTUALIZATION config KVM bool "Kernel-based Virtual Machine (KVM) support" + depends on !KEXEC select MMU_NOTIFIER select PREEMPT_NOTIFIERS select ANON_INODES
include/uapi/linux/kexec.h +1 -0
@@ -39,6 +39,7 @@#define KEXEC_ARCH_SH (42 << 16)#define KEXEC_ARCH_MIPS_LE (10 << 16)#define KEXEC_ARCH_MIPS ( 8 << 16) +#define KEXEC_ARCH_ARM64 (183 << 16)/* The artificial cap on the number of segments passed to kexec_load. */ #define KEXEC_SEGMENT_MAX 16
Signature · 8 lines
2.1.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Suzuki K. Poulose
reviewerRe: [PATCH 5/6] arm64/kexec: Add core kexec support
Quoted 153 lines · Geoff Levand
Add three new files,
kexec.h,machine_kexec.candrelocate_kernel.Sto the arm64 architecture that add support for the kexec re-boot mechanism (CONFIG_KEXEC) on arm64 platforms.With the addition of arm64 kexec support shutdown code paths through the kernel are executed that previously were not. To avoid system instability do to problems in the current arm64 KVM kernel implementation add a
Kconfigdependency on !KEXEC to the arm64 KVM menu item.Signed-off-by Geoff Levand <[email protected]>--- arch/arm64/Kconfig | 9 +++ arch/arm64/include/asm/kexec.h | 48 ++++++++++++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/machine_kexec.c | 125 ++++++++++++++++++++++++++++++ arch/arm64/kernel/relocate_kernel.S | 149 ++++++++++++++++++++++++++++++++++++ arch/arm64/kvm/Kconfig | 1 + include/uapi/linux/kexec.h | 1 + 7 files changed, 334 insertions(+)create mode 100644
arch/arm64/include/asm/kexec.hcreate mode 100644arch/arm64/kernel/machine_kexec.ccreate mode 100644arch/arm64/kernel/relocate_kernel.Sarch/arm64/Kconfig +9
-0@@ -528,6 +528,15 @@ config SECCOMP and the task is only allowed to execute a few safe syscalls defined by each seccomp mode. +config KEXEC + depends on (!SMP || PM_SLEEP_SMP) + bool "kexec system call" + ---help--- + kexec is a system call that implements the ability to shutdown your + current kernel, and to start another kernel. It is like a reboot + but it is independent of the system firmware. And like a reboot + you can start any kernel with it, not just Linux. + config XEN_DOM0 def_bool y depends on XENarch/arm64/include/asm/kexec.h new file +48
-0@@ -0,0 +1,48 @@ +/* +* kexec for arm64 +* +* Copyright (C) Linaro. +* Copyright (C) Futurewei Technologies. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#if !defined(_ARM64_KEXEC_H) +#define _ARM64_KEXEC_H + +/* Maximum physical address we can use pages from */ + +#define KEXEC_SOURCE_MEMORY_LIMIT (-1UL) + +/* Maximum address we can reach in physical address mode */ + +#define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL) + +/* Maximum address we can use for the control code buffer */ + +#define KEXEC_CONTROL_MEMORY_LIMIT (-1UL) + +#define KEXEC_CONTROL_PAGE_SIZE 4096 + +#define KEXEC_ARCH KEXEC_ARCH_ARM64 + +#if !defined(__ASSEMBLY__) + +/** +* crash_setup_regs() - save registers for the panic kernel +* +* @newregs: registers are saved here +* @oldregs: registers to be saved (may be %NULL) +*/ + +static inline void crash_setup_regs (struct pt_regs *newregs, +struct pt_regs *oldregs) +{ +/* Empty routine needed to avoid build errors. */ +} + +#endif /* !defined(__ASSEMBLY__) */ + +#endif arch/arm64/kernel/Makefile +1
-0@@ -35,6 +35,7 @@ arm64-obj-$(CONFIG_KGDB) += kgdb.o arm64-obj-$(CONFIG_EFI) += efi.o efi-stub.o efi-entry.o arm64-obj-$(CONFIG_PCI) += pci.o arm64-obj-$(CONFIG_ARMV8_DEPRECATED) += armv8_deprecated.o +arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o obj-y += $(arm64-obj-y) vdso/ obj-m += $(arm64-obj-m)arch/arm64/kernel/machine_kexec.c new file +38
-0@@ -0,0 +1,125 @@ +/* +* kexec for arm64 +* +* Copyright (C) Linaro. +* Copyright (C) Futurewei Technologies. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/kexec.h> +#include <linux/of_fdt.h> +#include <linux/slab.h> +#include <linux/uaccess.h> + +#include <asm/cacheflush.h> +#include <asm/system_misc.h> + +/* Global variables for the relocate_kernel routine. */ +extern const unsigned char relocate_new_kernel[]; +extern const unsigned long relocate_new_kernel_size; +extern unsigned long arm64_kexec_dtb_addr; +extern unsigned long arm64_kexec_kimage_head; +extern unsigned long arm64_kexec_kimage_start; + +void machine_kexec_cleanup (struct kimage *image) +{ +/* Empty routine needed to avoid build errors. */ +} + +/** +* machine_kexec_prepare - Prepare for a kexec reboot. +* +* Called from the core kexec code when a kernel image is loaded. +*/ +int machine_kexec_prepare (struct kimage *image) +{
arch/arm64/kernel/machine_kexec.c line 48
Quoted 10 lines
arch/arm64/kernel/machine_kexec.c new file +10
-0+ arm64_kexec_kimage_start = image->start; +return 0 ; +} + +/** +* kexec_list_flush - Helper to flush the kimage list to PoC. +*/ +static void kexec_list_flush (unsigned long kimage_head) +{ +void *dest;
What is the use of dest ?
arch/arm64/kernel/machine_kexec.c line 54
Quoted 6 lines
arch/arm64/kernel/machine_kexec.c new file +6
-0+unsigned long *entry; + +for (entry = &kimage_head, dest =NULL ; ; entry++) { +unsigned int flag = *entry & + (IND_DESTINATION |IND_INDIRECTION |IND_DONE | +IND_SOURCE );
You could instead do :
flag = *entry & IND_FLAGS;
Quoted 11 lines
arch/arm64/kernel/machine_kexec.c new file +11
-0+void *addr =phys_to_virt (*entry &PAGE_MASK ); + +switch (flag) { +case IND_INDIRECTION : + entry = (unsigned long *)addr -1 ; +__flush_dcache_area (addr,PAGE_SIZE ); +break ; +case IND_DESTINATION : + dest = addr; +break ; +case IND_SOURCE :
arch/arm64/kernel/machine_kexec.c line 75
Quoted 10 lines
arch/arm64/kernel/machine_kexec.c new file +10
-0+__flush_dcache_area (addr,PAGE_SIZE ); + dest +=PAGE_SIZE ; +break ; +case IND_DONE : +return ; +default : +BUG (); + } + } +}
Thanks
Suzuki
Re: [PATCH 5/6] arm64/kexec: Add core kexec support
Hi Suzuki,
Quoted 6 lines · Suzuki K. Poulose
arch/arm64/kernel/machine_kexec.c line 48
Quoted 3 lines · Geoff Levand
arch/arm64/kernel/machine_kexec.c new file +3
-0+static void kexec_list_flush (unsigned long kimage_head) +{ +void *dest;What is the use of dest ?
dest is left over from when I had a generic list walk routine. I'll remove it.
Quoted 9 lines
arch/arm64/kernel/machine_kexec.c line 54
Quoted 6 lines
arch/arm64/kernel/machine_kexec.c new file +6
-0+unsigned long *entry; + +for (entry = &kimage_head, dest =NULL ; ; entry++) { +unsigned int flag = *entry & + (IND_DESTINATION |IND_INDIRECTION |IND_DONE | +IND_SOURCE );You could instead do :
flag = *entry & IND_FLAGS;
Yes, now that the patch to define IND_FLAGS has been merged.
-Geoff
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH v2 5/6 arm64/kexec: Add core kexec support
In reply to Geoff LevandAdd three new files, kexec.h, machine_kexec.c and relocate_kernel.S to the arm64 architecture that add support for the kexec re-boot mechanism (CONFIG_KEXEC) on arm64 platforms.
With the addition of arm64 kexec support shutdown code paths through the kernel are executed that previously were not. To avoid system instability do to problems in the current arm64 KVM kernel implementation add a Kconfig dependency on !KEXEC to the arm64 KVM menu item.
---
I pushed this V2 out to my kexec-v9 branch:
git://git.kernel.org/pub/scm/linux/kernel/git/geoff/linux-kexec.git kexec-v9
-Geoff
arch/arm64/Kconfig | 9 +++ arch/arm64/include/asm/kexec.h | 48 ++++++++++++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/machine_kexec.c | 120 +++++++++++++++++++++++++++++ arch/arm64/kernel/relocate_kernel.S | 149 ++++++++++++++++++++++++++++++++++++ arch/arm64/kvm/Kconfig | 1 + include/uapi/linux/kexec.h | 1 + 7 files changed, 329 insertions(+) create mode 100644 arch/arm64/include/asm/kexec.h create mode 100644 arch/arm64/kernel/machine_kexec.c create mode 100644 arch/arm64/kernel/relocate_kernel.S
arch/arm64/Kconfig +9 -0
@@ -553,6 +553,15 @@ config SECCOMP and the task is only allowed to execute a few safe syscalls defined by each seccomp mode. +config KEXEC + depends on (!SMP || PM_SLEEP_SMP) + bool "kexec system call" + ---help--- + kexec is a system call that implements the ability to shutdown your + current kernel, and to start another kernel. It is like a reboot + but it is independent of the system firmware. And like a reboot + you can start any kernel with it, not just Linux. + config XEN_DOM0 def_bool y depends on XEN
arch/arm64/include/asm/kexec.h new file +48 -0
48 lines not on this page · raw message
arch/arm64/kernel/Makefile +1 -0
@@ -35,6 +35,7 @@ arm64-obj-$(CONFIG_KGDB) += kgdb.o arm64-obj-$(CONFIG_EFI) += efi.o efi-stub.o efi-entry.o arm64-obj-$(CONFIG_PCI) += pci.o arm64-obj-$(CONFIG_ARMV8_DEPRECATED) += armv8_deprecated.o +arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o obj-y += $(arm64-obj-y) vdso/ obj-m += $(arm64-obj-m)
arch/arm64/kernel/machine_kexec.c new file +120 -0
120 lines not on this page · raw message
arch/arm64/kernel/relocate_kernel.S new file +149 -0
149 lines not on this page · raw message
arch/arm64/kvm/Kconfig +1 -0
@@ -18,6 +18,7 @@ if VIRTUALIZATION config KVM bool "Kernel-based Virtual Machine (KVM) support" + depends on !KEXEC select MMU_NOTIFIER select PREEMPT_NOTIFIERS select ANON_INODES
include/uapi/linux/kexec.h +1 -0
@@ -39,6 +39,7 @@#define KEXEC_ARCH_SH (42 << 16)#define KEXEC_ARCH_MIPS_LE (10 << 16)#define KEXEC_ARCH_MIPS ( 8 << 16) +#define KEXEC_ARCH_ARM64 (183 << 16)/* The artificial cap on the number of segments passed to kexec_load. */ #define KEXEC_SEGMENT_MAX 16
Signature · 9 lines
2.1.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 6/6 arm64/kexec: Add pr_devel output
In reply to Geoff LevandTo aid in debugging kexec problems or when adding new functionality to kexec add a new routine kexec_image_info() and several inline pr_devel statements.
--- arch/arm64/kernel/machine_kexec.c | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
arch/arm64/kernel/machine_kexec.c +64 -0
@@ -24,6 +24,48 @@ extern unsigned long arm64_kexec_dtb_addr;extern unsigned long arm64_kexec_kimage_head;extern unsigned long arm64_kexec_kimage_start; +/** +* kexec_is_dtb - Helper routine to check the device tree header signature. +*/ +static bool kexec_is_dtb (const void *dtb) +{ +__be32 magic; + +return get_user (magic, (__be32 *)dtb) ? false : + (be32_to_cpu (magic) ==OF_DT_HEADER ); +} + +/** +* kexec_image_info - For debugging output. +*/ +#define kexec_image_info (_i) _kexec_image_info(__func__, __LINE__, _i) +static void _kexec_image_info (const char *func,int line, +const struct kimage *image) +{ +unsigned long i; + +#if !defined(DEBUG ) +return ; +#endif +pr_devel ("%s:%d:\n" , func, line); +pr_devel (" kexec image info:\n" ); +pr_devel (" type: %d\n" , image->type); +pr_devel (" start: %lx\n" , image->start); +pr_devel (" head: %lx\n" , image->head); +pr_devel (" nr_segments: %lu\n" , image->nr_segments); + +for (i =0 ; i < image->nr_segments; i++) { +pr_devel (" segment[%lu]: %016lx - %016lx, %lx bytes, %lu pages%s\n" , + i, + image->segment[i].mem, + image->segment[i].mem + image->segment[i].memsz, + image->segment[i].memsz, + image->segment[i].memsz /PAGE_SIZE , + (kexec_is_dtb (image->segment[i].buf) ? +", dtb segment" :"" )); + } +} +void machine_kexec_cleanup (struct kimage *image) {/* Empty routine needed to avoid build errors. */
@@ -37,6 +79,7 @@ void machine_kexec_cleanup(struct kimage *image)int machine_kexec_prepare (struct kimage *image) { arm64_kexec_kimage_start = image->start; +kexec_image_info (image);return 0 ; }
@@ -91,6 +134,27 @@ void machine_kexec(struct kimage *image) reboot_code_buffer_phys =page_to_phys (image->control_code_page); reboot_code_buffer =phys_to_virt (reboot_code_buffer_phys); +kexec_image_info (image); + +pr_devel ("%s:%d: control_code_page: %p\n" , __func__, __LINE__, + image->control_code_page); +pr_devel ("%s:%d: reboot_code_buffer_phys: %pa\n" , __func__, __LINE__, + &reboot_code_buffer_phys); +pr_devel ("%s:%d: reboot_code_buffer: %p\n" , __func__, __LINE__, + reboot_code_buffer); +pr_devel ("%s:%d: relocate_new_kernel: %p\n" , __func__, __LINE__, + relocate_new_kernel); +pr_devel ("%s:%d: relocate_new_kernel_size: 0x%lx(%lu) bytes\n" , + __func__, __LINE__, relocate_new_kernel_size, + relocate_new_kernel_size); + +pr_devel ("%s:%d: kexec_dtb_addr: %lx\n" , __func__, __LINE__, + arm64_kexec_dtb_addr); +pr_devel ("%s:%d: kexec_kimage_head: %lx\n" , __func__, __LINE__, + arm64_kexec_kimage_head); +pr_devel ("%s:%d: kexec_kimage_start: %lx\n" , __func__, __LINE__, + arm64_kexec_kimage_start); +/* * Copy relocate_new_kernel to the reboot_code_buffer for use * after the kernel is shut down.
Signature · 7 lines
2.1.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Mark Rutland
reviewerQuoted 1 line · Geoff Levand
Hi All,
Hi Geoff,
As a heads-up, I'm not going to have the chanec to review this until after the FW summit next week.
[...]
Quoted 10 lines
KVM
---PROBLEM: KVM acquires hypervisor resources on startup, but does not free those resources on shutdown, so the first stage kernel cannot be shutdown properly when using kexec.
WORK-AROUND: Build the first stage kernel with
CONFIG_KVM=n, or apply KVM bug fix patches from [1].
Quoted 8 lines
FIX: Takahiro Akashi has preliminary patches to fix the KVM shutdown problem. I have those in my master branch at [1]. KVM + kexec works properly with that branch. Patches neeeded:
arm64: kvm: add a cpu tear-down function
arm64: kexec: fix kvm issue
arm64/kvm: Remove !KEXECKconfigdependency
arm64/kexec: Enable kexec in the arm64 defconfig
These (or some descendents thereof) are going to be a prerequisite for kexec.
Quoted 8 lines
/memreserve/
----------PROBLEM: Device tree /memreserve/ entries are not available in
/proc/device-tree. For systems that have /memreserve/ entries and use/proc/device-treeduring kexec, the second stage kernel will use the reserved regions and the system will become unstable.
Quoted 6 lines
WORK-AROUND: Enable the kernel config option
CONFIG_SYSFS=yto expose a binary device tree to user space at/sys/firmware/fdtthat includes /memreserve/ entries OR pass a user specified DTB using the kexec --dtb option.FIX: This is expected behavior. To maximize user support, rework device tree definitions to not use /memreserve/ entries.
I'd say that requiring CONFIG_SYSFS is the real fix here. That's a kernel change that maximises compatibility with DTBs (which we don't really have control over).
I hope that the tools warn somehow if they cannot see the fdt.
Mark.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hi,
I rebased my series to the latest arm64 for-next/core (v4.0-rc4) and pushed it out to:
git://git.kernel.org/pub/scm/linux/kernel/git/geoff/linux-kexec.git kexec-v9
-Geoff
Quoted 73 lines · Geoff Levand
Hi All,
This series adds the core support for kexec re-boots on arm64. This v8 of the series is mainly just a rebase to Linux-4.0-rc3, and a few very minor changes requested for v7.
To load a second stage kernel and execute a kexec re-boot on arm64 my patches to kexec-tools [2], which have not yet been merged upstream, are needed.
I have tested with the ARM VE fast model, the ARM Base model and the ARM Foundation model with various kernel config options for both the first and second stage kernels. Kexec on EFI systems works correctly. With the ACPI kernel patches from [3] applied, kexec on ACPI systems seeems to work correctly. More ACPI + kexec testing is needed.
Patch 1 here moves the macros from
proc-macros.Stoasm/assembler.hso that thedcache_line_sizemacro it defines can be uesd by kexec's relocate kernel routine.Patches 2-4 rework the arm64 hcall mechanism to give the arm64
soft_restart()routine the ability to switch exception levels from EL1 to EL2 for kernels that were entered in EL2.Patches 5-6 add the actual kexec support.
Please consider all patches for inclusion.
[1] https://git.kernel.org/cgit/linux/kernel/git/geoff/linux-kexec.git [2] https://git.kernel.org/cgit/linux/kernel/git/geoff/kexec-tools.git [3] http://git.linaro.org/leg/acpi/acpi.git #acpi-topic-juno-fvpSeveral things are known to have problems on kexec re-boot:
spin-table
----------PROBLEM: The spin-table enable method does not implement all the methods needed for CPU hot-plug, so the first stage kernel cannot be shutdown properly.
WORK-AROUND: Upgrade to system firmware that provides PSCI enable method support, OR build the first stage kernel with
CONFIG_SMP=n, OR pass 'maxcpus=1' on the first stage kernel command line.FIX: Upgrade system firmware to provide PSCI enable method support or add missing spin-table support to the kernel.
KVM
---PROBLEM: KVM acquires hypervisor resources on startup, but does not free those resources on shutdown, so the first stage kernel cannot be shutdown properly when using kexec.
WORK-AROUND: Build the first stage kernel with
CONFIG_KVM=n, or apply KVM bug fix patches from [1].FIX: Takahiro Akashi has preliminary patches to fix the KVM shutdown problem. I have those in my master branch at [1]. KVM + kexec works properly with that branch. Patches neeeded:
arm64: kvm: add a cpu tear-down function
arm64: kexec: fix kvm issue
arm64/kvm: Remove !KEXECKconfigdependency
arm64/kexec: Enable kexec in the arm64 defconfig/memreserve/
----------PROBLEM: Device tree /memreserve/ entries are not available in
/proc/device-tree. For systems that have /memreserve/ entries and use/proc/device-treeduring kexec, the second stage kernel will use the reserved regions and the system will become unstable.
Quoted 8 lines
WORK-AROUND: Enable the kernel config option
CONFIG_SYSFS=yto expose a binary device tree to user space at/sys/firmware/fdtthat includes /memreserve/ entries OR pass a user specified DTB using the kexec --dtb option.FIX: This is expected behavior. To maximize user support, rework device tree definitions to not use /memreserve/ entries.
-Geoff
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Suzuki K. Poulose
reviewerQuoted 23 lines · Geoff Levand
Hi All,
This series adds the core support for kexec re-boots on arm64. This v8 of the series is mainly just a rebase to Linux-4.0-rc3, and a few very minor changes requested for v7.
To load a second stage kernel and execute a kexec re-boot on arm64 my patches to kexec-tools [2], which have not yet been merged upstream, are needed.
I have tested with the ARM VE fast model, the ARM Base model and the ARM Foundation model with various kernel config options for both the first and second stage kernels. Kexec on EFI systems works correctly. With the ACPI kernel patches from [3] applied, kexec on ACPI systems seeems to work correctly. More ACPI + kexec testing is needed.
Patch 1 here moves the macros from
proc-macros.Stoasm/assembler.hso that thedcache_line_sizemacro it defines can be uesd by kexec's relocate kernel routine.Patches 2-4 rework the arm64 hcall mechanism to give the arm64
soft_restart()routine the ability to switch exception levels from EL1 to EL2 for kernels that were entered in EL2.
Quoted 6 lines
Patches 5-6 add the actual kexec support.
Please consider all patches for inclusion.
[1] https://git.kernel.org/cgit/linux/kernel/git/geoff/linux-kexec.git
[2] https://git.kernel.org/cgit/linux/kernel/git/geoff/kexec-tools.git
Btw, I get the following build failure for kexec-tools master branch, with Linaro tool chain (crosstool-NG linaro-1.13.1-4.9-2014.09 - Linaro GCC 4.9-2014.09 )
$ ./configure --host=aarch64-linux-gnu
[...]
$ make -j4
kexec/arch/arm64/kexec-arm64.c: In function ?machine_verify_elf_rel?:
kexec/arch/arm64/kexec-arm64.c:970:29: error: ?EM_AARCH64? undeclared
(first use in this function)
return (ehdr->e_machine == EM_AARCH64);
^
kexec/arch/arm64/kexec-arm64.c:970:29: note: each undeclared identifier
is reported only once for each function it appears in
kexec/arch/arm64/kexec-arm64.c:971:1: warning: control reaches end of
non-void function [-Wreturn-type]
}
^
make: *** [kexec/arch/arm64/kexec-arm64.o] Error 1
make: *** Waiting for unfinished jobs....
----You may need to add the definition of EM_AARCH64 to include/elf.h and include that instead of linux/elf.h, like the other archs.
Cheers
Suzuki
Hi,
Quoted 9 lines · Suzuki K. Poulose
Btw, I get the following build failure for kexec-tools master branch, with Linaro tool chain (crosstool-NG linaro-1.13.1-4.9-2014.09 - Linaro GCC 4.9-2014.09 )
$ ./configure --host=aarch64-linux-gnu [...] $ make -j4 kexec/arch/arm64/kexec-arm64.c: In function ‘machine_verify_elf_rel’: kexec/arch/arm64/kexec-arm64.c:970:29: error: ‘EM_AARCH64’ undeclared
I guess that toolchain is using some ancient headers. As a workaround you can use configure CPPFLAGS='-DEM_AARCH64=183'.
-Geoff
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hi Geoff,
I suppose there would be a next revision of kexec patches. When is the that expected?
Thanks a lot for working on this.
~Pratyush
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hi Pratyush,
Quoted 2 lines · Pratyush Anand
I suppose there would be a next revision of kexec patches. When is the that expected?
As I just replied to Marc's mail, I'll work on preparing a rebased kexec patch set the next chance I get. I'm hoping I can start on it his week.
-Geoff
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec