]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.20.4/arm64-kvm-consistently-handle-host-hcr_el2-flags.patch
Linux 4.4.177
[thirdparty/kernel/stable-queue.git] / releases / 4.20.4 / arm64-kvm-consistently-handle-host-hcr_el2-flags.patch
1 From cfc22a22ef038242b76b463a279801a96b544244 Mon Sep 17 00:00:00 2001
2 From: Mark Rutland <mark.rutland@arm.com>
3 Date: Fri, 7 Dec 2018 18:39:21 +0000
4 Subject: arm64/kvm: consistently handle host HCR_EL2 flags
5
6 [ Upstream commit 4eaed6aa2c628101246bcabc91b203bfac1193f8 ]
7
8 In KVM we define the configuration of HCR_EL2 for a VHE HOST in
9 HCR_HOST_VHE_FLAGS, but we don't have a similar definition for the
10 non-VHE host flags, and open-code HCR_RW. Further, in head.S we
11 open-code the flags for VHE and non-VHE configurations.
12
13 In future, we're going to want to configure more flags for the host, so
14 lets add a HCR_HOST_NVHE_FLAGS defintion, and consistently use both
15 HCR_HOST_VHE_FLAGS and HCR_HOST_NVHE_FLAGS in the kvm code and head.S.
16
17 We now use mov_q to generate the HCR_EL2 value, as we use when
18 configuring other registers in head.S.
19
20 Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
21 Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
22 Signed-off-by: Mark Rutland <mark.rutland@arm.com>
23 Signed-off-by: Kristina Martsenko <kristina.martsenko@arm.com>
24 Reviewed-by: Christoffer Dall <christoffer.dall@arm.com>
25 Cc: Catalin Marinas <catalin.marinas@arm.com>
26 Cc: Marc Zyngier <marc.zyngier@arm.com>
27 Cc: Will Deacon <will.deacon@arm.com>
28 Cc: kvmarm@lists.cs.columbia.edu
29 Signed-off-by: Will Deacon <will.deacon@arm.com>
30 Signed-off-by: Sasha Levin <sashal@kernel.org>
31 ---
32 arch/arm64/include/asm/kvm_arm.h | 1 +
33 arch/arm64/kernel/head.S | 5 ++---
34 arch/arm64/kvm/hyp/switch.c | 2 +-
35 3 files changed, 4 insertions(+), 4 deletions(-)
36
37 diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
38 index 2dafd936d84d..7b914c6fb855 100644
39 --- a/arch/arm64/include/asm/kvm_arm.h
40 +++ b/arch/arm64/include/asm/kvm_arm.h
41 @@ -87,6 +87,7 @@
42 HCR_AMO | HCR_SWIO | HCR_TIDCP | HCR_RW | HCR_TLOR | \
43 HCR_FMO | HCR_IMO)
44 #define HCR_VIRT_EXCP_MASK (HCR_VSE | HCR_VI | HCR_VF)
45 +#define HCR_HOST_NVHE_FLAGS (HCR_RW)
46 #define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H)
47
48 /* TCR_EL2 Registers bits */
49 diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
50 index 4471f570a295..b207a2ce4bc6 100644
51 --- a/arch/arm64/kernel/head.S
52 +++ b/arch/arm64/kernel/head.S
53 @@ -496,10 +496,9 @@ ENTRY(el2_setup)
54 #endif
55
56 /* Hyp configuration. */
57 - mov x0, #HCR_RW // 64-bit EL1
58 + mov_q x0, HCR_HOST_NVHE_FLAGS
59 cbz x2, set_hcr
60 - orr x0, x0, #HCR_TGE // Enable Host Extensions
61 - orr x0, x0, #HCR_E2H
62 + mov_q x0, HCR_HOST_VHE_FLAGS
63 set_hcr:
64 msr hcr_el2, x0
65 isb
66 diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
67 index 7cc175c88a37..f6e02cc4d856 100644
68 --- a/arch/arm64/kvm/hyp/switch.c
69 +++ b/arch/arm64/kvm/hyp/switch.c
70 @@ -157,7 +157,7 @@ static void __hyp_text __deactivate_traps_nvhe(void)
71 mdcr_el2 |= MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT;
72
73 write_sysreg(mdcr_el2, mdcr_el2);
74 - write_sysreg(HCR_RW, hcr_el2);
75 + write_sysreg(HCR_HOST_NVHE_FLAGS, hcr_el2);
76 write_sysreg(CPTR_EL2_DEFAULT, cptr_el2);
77 }
78
79 --
80 2.19.1
81