Skip to content

Commit f9076ec

Browse files
glevandctmarinas
authored andcommitted
arm64: Add back cpu reset routines
Commit 68234df ("arm64: kill flush_cache_all()") removed the global arm64 routines cpu_reset() and cpu_soft_restart() needed by the arm64 kexec and kdump support. Add back a simplified version of cpu_soft_restart() with some changes needed for kexec in the new files cpu_reset.S, and cpu_reset.h. When a CPU is reset it needs to be put into the exception level it had when it entered the kernel. Update cpu_soft_restart() to accept an argument which signals if the reset address should be entered at EL1 or EL2, and add a new hypercall HVC_SOFT_RESTART which is used for the EL2 switch. Signed-off-by: Geoff Levand <geoff@infradead.org> Reviewed-by: James Morse <james.morse@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent b69e0dc commit f9076ec

File tree

4 files changed

+102
-1
lines changed

4 files changed

+102
-1
lines changed

arch/arm64/include/asm/virt.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
*/
3535
#define HVC_SET_VECTORS 1
3636

37+
/*
38+
* HVC_SOFT_RESTART - CPU soft reset, used by the cpu_soft_restart routine.
39+
*/
40+
#define HVC_SOFT_RESTART 2
41+
3742
#define BOOT_CPU_MODE_EL1 (0xe11)
3843
#define BOOT_CPU_MODE_EL2 (0xe12)
3944

arch/arm64/kernel/cpu-reset.S

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* CPU reset routines
3+
*
4+
* Copyright (C) 2001 Deep Blue Solutions Ltd.
5+
* Copyright (C) 2012 ARM Ltd.
6+
* Copyright (C) 2015 Huawei Futurewei Technologies.
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*/
12+
13+
#include <linux/linkage.h>
14+
#include <asm/assembler.h>
15+
#include <asm/sysreg.h>
16+
#include <asm/virt.h>
17+
18+
.text
19+
.pushsection .idmap.text, "ax"
20+
21+
/*
22+
* __cpu_soft_restart(el2_switch, entry, arg0, arg1, arg2) - Helper for
23+
* cpu_soft_restart.
24+
*
25+
* @el2_switch: Flag to indicate a swich to EL2 is needed.
26+
* @entry: Location to jump to for soft reset.
27+
* arg0: First argument passed to @entry.
28+
* arg1: Second argument passed to @entry.
29+
* arg2: Third argument passed to @entry.
30+
*
31+
* Put the CPU into the same state as it would be if it had been reset, and
32+
* branch to what would be the reset vector. It must be executed with the
33+
* flat identity mapping.
34+
*/
35+
ENTRY(__cpu_soft_restart)
36+
/* Clear sctlr_el1 flags. */
37+
mrs x12, sctlr_el1
38+
ldr x13, =SCTLR_ELx_FLAGS
39+
bic x12, x12, x13
40+
msr sctlr_el1, x12
41+
isb
42+
43+
cbz x0, 1f // el2_switch?
44+
mov x0, #HVC_SOFT_RESTART
45+
hvc #0 // no return
46+
47+
1: mov x18, x1 // entry
48+
mov x0, x2 // arg0
49+
mov x1, x3 // arg1
50+
mov x2, x4 // arg2
51+
br x18
52+
ENDPROC(__cpu_soft_restart)
53+
54+
.popsection

arch/arm64/kernel/cpu-reset.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* CPU reset routines
3+
*
4+
* Copyright (C) 2015 Huawei Futurewei Technologies.
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 as
8+
* published by the Free Software Foundation.
9+
*/
10+
11+
#ifndef _ARM64_CPU_RESET_H
12+
#define _ARM64_CPU_RESET_H
13+
14+
#include <asm/virt.h>
15+
16+
void __cpu_soft_restart(unsigned long el2_switch, unsigned long entry,
17+
unsigned long arg0, unsigned long arg1, unsigned long arg2);
18+
19+
static inline void __noreturn cpu_soft_restart(unsigned long el2_switch,
20+
unsigned long entry, unsigned long arg0, unsigned long arg1,
21+
unsigned long arg2)
22+
{
23+
typeof(__cpu_soft_restart) *restart;
24+
25+
el2_switch = el2_switch && !is_kernel_in_hyp_mode() &&
26+
is_hyp_mode_available();
27+
restart = (void *)virt_to_phys(__cpu_soft_restart);
28+
29+
cpu_install_idmap();
30+
restart(el2_switch, entry, arg0, arg1, arg2);
31+
unreachable();
32+
}
33+
34+
#endif

arch/arm64/kernel/hyp-stub.S

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,16 @@ el1_sync:
7171
msr vbar_el2, x1
7272
b 9f
7373

74+
2: cmp x0, #HVC_SOFT_RESTART
75+
b.ne 3f
76+
mov x0, x2
77+
mov x2, x4
78+
mov x4, x1
79+
mov x1, x3
80+
br x4 // no return
81+
7482
/* Someone called kvm_call_hyp() against the hyp-stub... */
75-
2: mov x0, #ARM_EXCEPTION_HYP_GONE
83+
3: mov x0, #ARM_EXCEPTION_HYP_GONE
7684

7785
9: eret
7886
ENDPROC(el1_sync)

0 commit comments

Comments
 (0)