From: geoff@infradead.org (Geoff Levand)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v20 03/14] arm64: Add back cpu reset routines
Date: Thu, 23 Jun 2016 17:54:48 +0000 [thread overview]
Message-ID: <9e9cc6f355e353bba1ddcc1f98f9fba41f9dcbf2.1466702804.git.geoff@infradead.org> (raw)
In-Reply-To: <cover.1466702804.git.geoff@infradead.org>
Commit 68234df4ea79 ("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>
---
arch/arm64/include/asm/virt.h | 5 ++++
arch/arm64/kernel/cpu-reset.S | 54 +++++++++++++++++++++++++++++++++++++++++++
arch/arm64/kernel/cpu-reset.h | 34 +++++++++++++++++++++++++++
arch/arm64/kernel/hyp-stub.S | 10 +++++++-
4 files changed, 102 insertions(+), 1 deletion(-)
create mode 100644 arch/arm64/kernel/cpu-reset.S
create mode 100644 arch/arm64/kernel/cpu-reset.h
diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h
index dcbcf8d..bbc6a8c 100644
--- a/arch/arm64/include/asm/virt.h
+++ b/arch/arm64/include/asm/virt.h
@@ -34,6 +34,11 @@
*/
#define HVC_SET_VECTORS 1
+/*
+ * HVC_SOFT_RESTART - CPU soft reset, used by the cpu_soft_restart routine.
+ */
+#define HVC_SOFT_RESTART 2
+
#define BOOT_CPU_MODE_EL1 (0xe11)
#define BOOT_CPU_MODE_EL2 (0xe12)
diff --git a/arch/arm64/kernel/cpu-reset.S b/arch/arm64/kernel/cpu-reset.S
new file mode 100644
index 0000000..65f42d2
--- /dev/null
+++ b/arch/arm64/kernel/cpu-reset.S
@@ -0,0 +1,54 @@
+/*
+ * CPU reset routines
+ *
+ * Copyright (C) 2001 Deep Blue Solutions Ltd.
+ * Copyright (C) 2012 ARM Ltd.
+ * Copyright (C) 2015 Huawei 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/linkage.h>
+#include <asm/assembler.h>
+#include <asm/sysreg.h>
+#include <asm/virt.h>
+
+.text
+.pushsection .idmap.text, "ax"
+
+/*
+ * __cpu_soft_restart(el2_switch, entry, arg0, arg1, arg2) - Helper for
+ * cpu_soft_restart.
+ *
+ * @el2_switch: Flag to indicate a swich to EL2 is needed.
+ * @entry: Location to jump to for soft reset.
+ * arg0: First argument passed to @entry.
+ * arg1: Second argument passed to @entry.
+ * arg2: Third argument passed to @entry.
+ *
+ * Put the CPU into the same state as it would be if it had been reset, and
+ * branch to what would be the reset vector. It must be executed with the
+ * flat identity mapping.
+ */
+ENTRY(__cpu_soft_restart)
+ /* Clear sctlr_el1 flags. */
+ mrs x12, sctlr_el1
+ ldr x13, =SCTLR_ELx_FLAGS
+ bic x12, x12, x13
+ msr sctlr_el1, x12
+ isb
+
+ cbz x0, 1f // el2_switch?
+ mov x0, #HVC_SOFT_RESTART
+ hvc #0 // no return
+
+1: mov x18, x1 // entry
+ mov x0, x2 // arg0
+ mov x1, x3 // arg1
+ mov x2, x4 // arg2
+ br x18
+ENDPROC(__cpu_soft_restart)
+
+.popsection
diff --git a/arch/arm64/kernel/cpu-reset.h b/arch/arm64/kernel/cpu-reset.h
new file mode 100644
index 0000000..d4e9ecb
--- /dev/null
+++ b/arch/arm64/kernel/cpu-reset.h
@@ -0,0 +1,34 @@
+/*
+ * CPU reset routines
+ *
+ * Copyright (C) 2015 Huawei 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.
+ */
+
+#ifndef _ARM64_CPU_RESET_H
+#define _ARM64_CPU_RESET_H
+
+#include <asm/virt.h>
+
+void __cpu_soft_restart(unsigned long el2_switch, unsigned long entry,
+ unsigned long arg0, unsigned long arg1, unsigned long arg2);
+
+static inline void __noreturn cpu_soft_restart(unsigned long el2_switch,
+ unsigned long entry, unsigned long arg0, unsigned long arg1,
+ unsigned long arg2)
+{
+ typeof(__cpu_soft_restart) *restart;
+
+ el2_switch = el2_switch && !is_kernel_in_hyp_mode() &&
+ is_hyp_mode_available();
+ restart = (void *)virt_to_phys(__cpu_soft_restart);
+
+ cpu_install_idmap();
+ restart(el2_switch, entry, arg0, arg1, arg2);
+ unreachable();
+}
+
+#endif
diff --git a/arch/arm64/kernel/hyp-stub.S b/arch/arm64/kernel/hyp-stub.S
index 8727f44..d3b5f75 100644
--- a/arch/arm64/kernel/hyp-stub.S
+++ b/arch/arm64/kernel/hyp-stub.S
@@ -71,8 +71,16 @@ el1_sync:
msr vbar_el2, x1
b 9f
+2: cmp x0, #HVC_SOFT_RESTART
+ b.ne 3f
+ mov x0, x2
+ mov x2, x4
+ mov x4, x1
+ mov x1, x3
+ br x4 // no return
+
/* Someone called kvm_call_hyp() against the hyp-stub... */
-2: mov x0, #ARM_EXCEPTION_HYP_GONE
+3: mov x0, #ARM_EXCEPTION_HYP_GONE
9: eret
ENDPROC(el1_sync)
--
2.5.0
next prev parent reply other threads:[~2016-06-23 17:54 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-23 17:54 [PATCH v20 00/14] arm64 kexec kernel patches Geoff Levand
2016-06-23 17:54 ` [PATCH v20 06/14] arm64/kexec: Add pr_debug output Geoff Levand
2016-06-23 17:54 ` [PATCH v20 07/14] arm64: kdump: reserve memory for crash dump kernel Geoff Levand
2016-06-23 17:54 ` [PATCH v20 04/14] arm64/kexec: Add core kexec support Geoff Levand
2016-06-27 11:18 ` James Morse
2016-06-27 14:39 ` Catalin Marinas
2016-06-27 16:29 ` James Morse
2016-06-27 17:00 ` Geoff Levand
2016-06-23 17:54 ` [PATCH v20 02/14] arm64: smp: Add function to determine if cpus are stuck in the kernel Geoff Levand
2016-06-23 17:54 ` [PATCH v20 08/14] arm64: limit memory regions based on DT property, usable-memory Geoff Levand
2016-06-23 17:54 ` [PATCH v20 11/14] arm64: kdump: add VMCOREINFO's for user-space coredump tools Geoff Levand
2016-06-23 17:54 ` [PATCH v20 10/14] arm64: kdump: add kdump support Geoff Levand
2016-06-23 17:54 ` [PATCH v20 12/14] arm64: kdump: enable kdump in the arm64 defconfig Geoff Levand
2016-06-23 17:54 ` Geoff Levand [this message]
2016-06-23 17:54 ` [PATCH v20 01/14] arm64: hibernate: Don't hibernate on systems with stuck CPUs Geoff Levand
2016-06-27 11:04 ` James Morse
2016-06-27 16:44 ` Geoff Levand
2016-06-23 17:54 ` [PATCH v20 05/14] arm64/kexec: Enable kexec in the arm64 defconfig Geoff Levand
2016-06-23 17:54 ` [PATCH v20 09/14] arm64: kdump: implement machine_crash_shutdown() Geoff Levand
2016-06-23 17:54 ` [PATCH v20 14/14] Documentation: dt: usable-memory and elfcorehdr nodes for arm64 kexec Geoff Levand
2016-06-23 17:54 ` [PATCH v20 13/14] arm64: kdump: update a kernel doc Geoff Levand
2016-06-30 9:00 ` Baoquan He
2016-07-01 7:37 ` AKASHI Takahiro
2016-07-01 7:45 ` Baoquan He
2016-07-04 3:04 ` AKASHI Takahiro
2016-06-30 13:00 ` Dave Young
2016-06-27 17:00 ` [PATCH v20 00/14] arm64 kexec kernel patches Catalin Marinas
2016-06-27 17:07 ` Geoff Levand
2016-06-29 0:54 ` AKASHI Takahiro
2016-06-29 9:20 ` Catalin Marinas
2016-06-30 1:46 ` AKASHI Takahiro
2016-07-01 2:39 ` Pratyush Anand
2016-07-04 7:14 ` AKASHI Takahiro
2016-07-04 10:15 ` Pratyush Anand
2016-07-15 4:17 ` Simon Horman
2016-07-15 16:18 ` Geoff Levand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9e9cc6f355e353bba1ddcc1f98f9fba41f9dcbf2.1466702804.git.geoff@infradead.org \
--to=geoff@infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).