diff options
author | Marc Zyngier <marc.zyngier@arm.com> | 2012-10-19 12:46:27 -0400 |
---|---|---|
committer | Catalin Marinas <catalin.marinas@arm.com> | 2012-12-05 06:26:49 -0500 |
commit | 712c6ff4dba4917a440be601dc312506322bffe8 (patch) | |
tree | 70890fcc3d289c04126fea2474f8a31fd79e3fcc /arch/arm64 | |
parent | f35a92053b45cf8154db5558ede3ba5245c9dc7e (diff) |
arm64: add hypervisor stub
If booted in EL2, install an dummy hypervisor whose only purpose
is to be replaced by a full fledged one.
A minimal API allows to:
- obtain the current HYP vectors (__hyp_get_vectors)
- set new HYP vectors (__hyp_set_vectors)
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Diffstat (limited to 'arch/arm64')
-rw-r--r-- | arch/arm64/include/asm/virt.h | 3 | ||||
-rw-r--r-- | arch/arm64/kernel/Makefile | 3 | ||||
-rw-r--r-- | arch/arm64/kernel/head.S | 4 | ||||
-rw-r--r-- | arch/arm64/kernel/hyp-stub.S | 109 |
4 files changed, 118 insertions, 1 deletions
diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h index f28547d9edfa..439827271e3d 100644 --- a/arch/arm64/include/asm/virt.h +++ b/arch/arm64/include/asm/virt.h | |||
@@ -33,6 +33,9 @@ | |||
33 | */ | 33 | */ |
34 | extern u32 __boot_cpu_mode[2]; | 34 | extern u32 __boot_cpu_mode[2]; |
35 | 35 | ||
36 | void __hyp_set_vectors(phys_addr_t phys_vector_base); | ||
37 | phys_addr_t __hyp_get_vectors(void); | ||
38 | |||
36 | /* Reports the availability of HYP mode */ | 39 | /* Reports the availability of HYP mode */ |
37 | static inline bool is_hyp_mode_available(void) | 40 | static inline bool is_hyp_mode_available(void) |
38 | { | 41 | { |
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index e2caff1b812a..74239c31e25a 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile | |||
@@ -8,7 +8,8 @@ AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) | |||
8 | # Object file lists. | 8 | # Object file lists. |
9 | arm64-obj-y := cputable.o debug-monitors.o entry.o irq.o fpsimd.o \ | 9 | arm64-obj-y := cputable.o debug-monitors.o entry.o irq.o fpsimd.o \ |
10 | entry-fpsimd.o process.o ptrace.o setup.o signal.o \ | 10 | entry-fpsimd.o process.o ptrace.o setup.o signal.o \ |
11 | sys.o stacktrace.o time.o traps.o io.o vdso.o | 11 | sys.o stacktrace.o time.o traps.o io.o vdso.o \ |
12 | hyp-stub.o | ||
12 | 13 | ||
13 | arm64-obj-$(CONFIG_COMPAT) += sys32.o kuser32.o signal32.o \ | 14 | arm64-obj-$(CONFIG_COMPAT) += sys32.o kuser32.o signal32.o \ |
14 | sys_compat.o | 15 | sys_compat.o |
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index bc6d991f8c59..5792749e34c4 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S | |||
@@ -185,6 +185,10 @@ ENTRY(el2_setup) | |||
185 | msr hstr_el2, xzr // Disable CP15 traps to EL2 | 185 | msr hstr_el2, xzr // Disable CP15 traps to EL2 |
186 | #endif | 186 | #endif |
187 | 187 | ||
188 | /* Hypervisor stub */ | ||
189 | adr x0, __hyp_stub_vectors | ||
190 | msr vbar_el2, x0 | ||
191 | |||
188 | /* spsr */ | 192 | /* spsr */ |
189 | mov x0, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\ | 193 | mov x0, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\ |
190 | PSR_MODE_EL1h) | 194 | PSR_MODE_EL1h) |
diff --git a/arch/arm64/kernel/hyp-stub.S b/arch/arm64/kernel/hyp-stub.S new file mode 100644 index 000000000000..0959611d9ff1 --- /dev/null +++ b/arch/arm64/kernel/hyp-stub.S | |||
@@ -0,0 +1,109 @@ | |||
1 | /* | ||
2 | * Hypervisor stub | ||
3 | * | ||
4 | * Copyright (C) 2012 ARM Ltd. | ||
5 | * Author: Marc Zyngier <marc.zyngier@arm.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | #include <linux/init.h> | ||
21 | #include <linux/linkage.h> | ||
22 | |||
23 | #include <asm/assembler.h> | ||
24 | #include <asm/ptrace.h> | ||
25 | #include <asm/virt.h> | ||
26 | |||
27 | .text | ||
28 | .align 11 | ||
29 | |||
30 | ENTRY(__hyp_stub_vectors) | ||
31 | ventry el2_sync_invalid // Synchronous EL2t | ||
32 | ventry el2_irq_invalid // IRQ EL2t | ||
33 | ventry el2_fiq_invalid // FIQ EL2t | ||
34 | ventry el2_error_invalid // Error EL2t | ||
35 | |||
36 | ventry el2_sync_invalid // Synchronous EL2h | ||
37 | ventry el2_irq_invalid // IRQ EL2h | ||
38 | ventry el2_fiq_invalid // FIQ EL2h | ||
39 | ventry el2_error_invalid // Error EL2h | ||
40 | |||
41 | ventry el1_sync // Synchronous 64-bit EL1 | ||
42 | ventry el1_irq_invalid // IRQ 64-bit EL1 | ||
43 | ventry el1_fiq_invalid // FIQ 64-bit EL1 | ||
44 | ventry el1_error_invalid // Error 64-bit EL1 | ||
45 | |||
46 | ventry el1_sync_invalid // Synchronous 32-bit EL1 | ||
47 | ventry el1_irq_invalid // IRQ 32-bit EL1 | ||
48 | ventry el1_fiq_invalid // FIQ 32-bit EL1 | ||
49 | ventry el1_error_invalid // Error 32-bit EL1 | ||
50 | ENDPROC(__hyp_stub_vectors) | ||
51 | |||
52 | .align 11 | ||
53 | |||
54 | el1_sync: | ||
55 | mrs x1, esr_el2 | ||
56 | lsr x1, x1, #26 | ||
57 | cmp x1, #0x16 | ||
58 | b.ne 2f // Not an HVC trap | ||
59 | cbz x0, 1f | ||
60 | msr vbar_el2, x0 // Set vbar_el2 | ||
61 | b 2f | ||
62 | 1: mrs x0, vbar_el2 // Return vbar_el2 | ||
63 | 2: eret | ||
64 | ENDPROC(el1_sync) | ||
65 | |||
66 | .macro invalid_vector label | ||
67 | \label: | ||
68 | b \label | ||
69 | ENDPROC(\label) | ||
70 | .endm | ||
71 | |||
72 | invalid_vector el2_sync_invalid | ||
73 | invalid_vector el2_irq_invalid | ||
74 | invalid_vector el2_fiq_invalid | ||
75 | invalid_vector el2_error_invalid | ||
76 | invalid_vector el1_sync_invalid | ||
77 | invalid_vector el1_irq_invalid | ||
78 | invalid_vector el1_fiq_invalid | ||
79 | invalid_vector el1_error_invalid | ||
80 | |||
81 | /* | ||
82 | * __hyp_set_vectors: Call this after boot to set the initial hypervisor | ||
83 | * vectors as part of hypervisor installation. On an SMP system, this should | ||
84 | * be called on each CPU. | ||
85 | * | ||
86 | * x0 must be the physical address of the new vector table, and must be | ||
87 | * 2KB aligned. | ||
88 | * | ||
89 | * Before calling this, you must check that the stub hypervisor is installed | ||
90 | * everywhere, by waiting for any secondary CPUs to be brought up and then | ||
91 | * checking that is_hyp_mode_available() is true. | ||
92 | * | ||
93 | * If not, there is a pre-existing hypervisor, some CPUs failed to boot, or | ||
94 | * something else went wrong... in such cases, trying to install a new | ||
95 | * hypervisor is unlikely to work as desired. | ||
96 | * | ||
97 | * When you call into your shiny new hypervisor, sp_el2 will contain junk, | ||
98 | * so you will need to set that to something sensible at the new hypervisor's | ||
99 | * initialisation entry point. | ||
100 | */ | ||
101 | |||
102 | ENTRY(__hyp_get_vectors) | ||
103 | mov x0, xzr | ||
104 | // fall through | ||
105 | ENTRY(__hyp_set_vectors) | ||
106 | hvc #0 | ||
107 | ret | ||
108 | ENDPROC(__hyp_get_vectors) | ||
109 | ENDPROC(__hyp_set_vectors) | ||