diff options
author | Marc Zyngier <marc.zyngier@arm.com> | 2016-02-01 14:56:31 -0500 |
---|---|---|
committer | Marc Zyngier <marc.zyngier@arm.com> | 2016-02-29 13:34:14 -0500 |
commit | d4c7688c51e57be20ca5f3dffa4c8771888a42fc (patch) | |
tree | ef37556f1e5e57e9d9e5a582bf25f3daf1dfc636 | |
parent | b98e2e728eed3091edbce64cfcc447a482b7726c (diff) |
ARM: KVM: Switch to C-based stage2 init
As we now have hooks to setup VTCR from C code, let's drop the
original VTCR setup and reimplement it as part of the HYP code.
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
-rw-r--r-- | arch/arm/include/asm/kvm_asm.h | 2 | ||||
-rw-r--r-- | arch/arm/include/asm/kvm_host.h | 1 | ||||
-rw-r--r-- | arch/arm/kvm/hyp/Makefile | 1 | ||||
-rw-r--r-- | arch/arm/kvm/hyp/hyp.h | 2 | ||||
-rw-r--r-- | arch/arm/kvm/hyp/s2-setup.c | 34 | ||||
-rw-r--r-- | arch/arm/kvm/init.S | 8 |
6 files changed, 40 insertions, 8 deletions
diff --git a/arch/arm/include/asm/kvm_asm.h b/arch/arm/include/asm/kvm_asm.h index 4841225d10ea..3283a2f63254 100644 --- a/arch/arm/include/asm/kvm_asm.h +++ b/arch/arm/include/asm/kvm_asm.h | |||
@@ -98,6 +98,8 @@ extern void __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa); | |||
98 | extern void __kvm_tlb_flush_vmid(struct kvm *kvm); | 98 | extern void __kvm_tlb_flush_vmid(struct kvm *kvm); |
99 | 99 | ||
100 | extern int __kvm_vcpu_run(struct kvm_vcpu *vcpu); | 100 | extern int __kvm_vcpu_run(struct kvm_vcpu *vcpu); |
101 | |||
102 | extern void __init_stage2_translation(void); | ||
101 | #endif | 103 | #endif |
102 | 104 | ||
103 | #endif /* __ARM_KVM_ASM_H__ */ | 105 | #endif /* __ARM_KVM_ASM_H__ */ |
diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index c62d71751f7a..0fe41aaf2171 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h | |||
@@ -224,6 +224,7 @@ static inline void __cpu_init_hyp_mode(phys_addr_t boot_pgd_ptr, | |||
224 | 224 | ||
225 | static inline void __cpu_init_stage2(void) | 225 | static inline void __cpu_init_stage2(void) |
226 | { | 226 | { |
227 | kvm_call_hyp(__init_stage2_translation); | ||
227 | } | 228 | } |
228 | 229 | ||
229 | static inline int kvm_arch_dev_ioctl_check_extension(long ext) | 230 | static inline int kvm_arch_dev_ioctl_check_extension(long ext) |
diff --git a/arch/arm/kvm/hyp/Makefile b/arch/arm/kvm/hyp/Makefile index a7d3a7e0b702..7152369504a6 100644 --- a/arch/arm/kvm/hyp/Makefile +++ b/arch/arm/kvm/hyp/Makefile | |||
@@ -11,3 +11,4 @@ obj-$(CONFIG_KVM_ARM_HOST) += banked-sr.o | |||
11 | obj-$(CONFIG_KVM_ARM_HOST) += entry.o | 11 | obj-$(CONFIG_KVM_ARM_HOST) += entry.o |
12 | obj-$(CONFIG_KVM_ARM_HOST) += hyp-entry.o | 12 | obj-$(CONFIG_KVM_ARM_HOST) += hyp-entry.o |
13 | obj-$(CONFIG_KVM_ARM_HOST) += switch.o | 13 | obj-$(CONFIG_KVM_ARM_HOST) += switch.o |
14 | obj-$(CONFIG_KVM_ARM_HOST) += s2-setup.o | ||
diff --git a/arch/arm/kvm/hyp/hyp.h b/arch/arm/kvm/hyp/hyp.h index 8b9c2eb5a9dc..ff6de6a3af2d 100644 --- a/arch/arm/kvm/hyp/hyp.h +++ b/arch/arm/kvm/hyp/hyp.h | |||
@@ -71,6 +71,8 @@ | |||
71 | #define HCPTR __ACCESS_CP15(c1, 4, c1, 2) | 71 | #define HCPTR __ACCESS_CP15(c1, 4, c1, 2) |
72 | #define HSTR __ACCESS_CP15(c1, 4, c1, 3) | 72 | #define HSTR __ACCESS_CP15(c1, 4, c1, 3) |
73 | #define TTBCR __ACCESS_CP15(c2, 0, c0, 2) | 73 | #define TTBCR __ACCESS_CP15(c2, 0, c0, 2) |
74 | #define HTCR __ACCESS_CP15(c2, 4, c0, 2) | ||
75 | #define VTCR __ACCESS_CP15(c2, 4, c1, 2) | ||
74 | #define DACR __ACCESS_CP15(c3, 0, c0, 0) | 76 | #define DACR __ACCESS_CP15(c3, 0, c0, 0) |
75 | #define DFSR __ACCESS_CP15(c5, 0, c0, 0) | 77 | #define DFSR __ACCESS_CP15(c5, 0, c0, 0) |
76 | #define IFSR __ACCESS_CP15(c5, 0, c0, 1) | 78 | #define IFSR __ACCESS_CP15(c5, 0, c0, 1) |
diff --git a/arch/arm/kvm/hyp/s2-setup.c b/arch/arm/kvm/hyp/s2-setup.c new file mode 100644 index 000000000000..f5f49c53be28 --- /dev/null +++ b/arch/arm/kvm/hyp/s2-setup.c | |||
@@ -0,0 +1,34 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 - ARM Ltd | ||
3 | * Author: Marc Zyngier <marc.zyngier@arm.com> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include <linux/types.h> | ||
19 | #include <asm/kvm_arm.h> | ||
20 | #include <asm/kvm_asm.h> | ||
21 | |||
22 | #include "hyp.h" | ||
23 | |||
24 | void __hyp_text __init_stage2_translation(void) | ||
25 | { | ||
26 | u64 val; | ||
27 | |||
28 | val = read_sysreg(VTCR) & ~VTCR_MASK; | ||
29 | |||
30 | val |= read_sysreg(HTCR) & VTCR_HTCR_SH; | ||
31 | val |= KVM_VTCR_SL0 | KVM_VTCR_T0SZ | KVM_VTCR_S; | ||
32 | |||
33 | write_sysreg(val, VTCR); | ||
34 | } | ||
diff --git a/arch/arm/kvm/init.S b/arch/arm/kvm/init.S index 3988e72d16ff..1f9ae17476f9 100644 --- a/arch/arm/kvm/init.S +++ b/arch/arm/kvm/init.S | |||
@@ -84,14 +84,6 @@ __do_hyp_init: | |||
84 | orr r0, r0, r1 | 84 | orr r0, r0, r1 |
85 | mcr p15, 4, r0, c2, c0, 2 @ HTCR | 85 | mcr p15, 4, r0, c2, c0, 2 @ HTCR |
86 | 86 | ||
87 | mrc p15, 4, r1, c2, c1, 2 @ VTCR | ||
88 | ldr r2, =VTCR_MASK | ||
89 | bic r1, r1, r2 | ||
90 | bic r0, r0, #(~VTCR_HTCR_SH) @ clear non-reusable HTCR bits | ||
91 | orr r1, r0, r1 | ||
92 | orr r1, r1, #(KVM_VTCR_SL0 | KVM_VTCR_T0SZ | KVM_VTCR_S) | ||
93 | mcr p15, 4, r1, c2, c1, 2 @ VTCR | ||
94 | |||
95 | @ Use the same memory attributes for hyp. accesses as the kernel | 87 | @ Use the same memory attributes for hyp. accesses as the kernel |
96 | @ (copy MAIRx ro HMAIRx). | 88 | @ (copy MAIRx ro HMAIRx). |
97 | mrc p15, 0, r0, c10, c2, 0 | 89 | mrc p15, 0, r0, c10, c2, 0 |