]>
Commit | Line | Data |
---|---|---|
5eec0a91 MZ |
1 | /* |
2 | * Copyright (C) 2015 - 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 | ||
13720a56 | 18 | #include <asm/kvm_hyp.h> |
fa715319 | 19 | #include <asm/tlbflush.h> |
5eec0a91 | 20 | |
68925176 MZ |
21 | static void __hyp_text __tlb_switch_to_guest_vhe(struct kvm *kvm) |
22 | { | |
23 | u64 val; | |
24 | ||
25 | /* | |
26 | * With VHE enabled, we have HCR_EL2.{E2H,TGE} = {1,1}, and | |
27 | * most TLB operations target EL2/EL0. In order to affect the | |
28 | * guest TLBs (EL1/EL0), we need to change one of these two | |
29 | * bits. Changing E2H is impossible (goodbye TTBR1_EL2), so | |
30 | * let's flip TGE before executing the TLB operation. | |
31 | */ | |
32 | write_sysreg(kvm->arch.vttbr, vttbr_el2); | |
33 | val = read_sysreg(hcr_el2); | |
34 | val &= ~HCR_TGE; | |
35 | write_sysreg(val, hcr_el2); | |
36 | isb(); | |
37 | } | |
38 | ||
39 | static void __hyp_text __tlb_switch_to_guest_nvhe(struct kvm *kvm) | |
40 | { | |
41 | write_sysreg(kvm->arch.vttbr, vttbr_el2); | |
42 | isb(); | |
43 | } | |
44 | ||
45 | static hyp_alternate_select(__tlb_switch_to_guest, | |
46 | __tlb_switch_to_guest_nvhe, | |
47 | __tlb_switch_to_guest_vhe, | |
48 | ARM64_HAS_VIRT_HOST_EXTN); | |
49 | ||
50 | static void __hyp_text __tlb_switch_to_host_vhe(struct kvm *kvm) | |
51 | { | |
52 | /* | |
53 | * We're done with the TLB operation, let's restore the host's | |
54 | * view of HCR_EL2. | |
55 | */ | |
56 | write_sysreg(0, vttbr_el2); | |
57 | write_sysreg(HCR_HOST_VHE_FLAGS, hcr_el2); | |
58 | } | |
59 | ||
60 | static void __hyp_text __tlb_switch_to_host_nvhe(struct kvm *kvm) | |
61 | { | |
62 | write_sysreg(0, vttbr_el2); | |
63 | } | |
64 | ||
65 | static hyp_alternate_select(__tlb_switch_to_host, | |
66 | __tlb_switch_to_host_nvhe, | |
67 | __tlb_switch_to_host_vhe, | |
68 | ARM64_HAS_VIRT_HOST_EXTN); | |
69 | ||
cf0ba18a | 70 | void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa) |
5eec0a91 MZ |
71 | { |
72 | dsb(ishst); | |
73 | ||
74 | /* Switch to requested VMID */ | |
75 | kvm = kern_hyp_va(kvm); | |
68925176 | 76 | __tlb_switch_to_guest()(kvm); |
5eec0a91 MZ |
77 | |
78 | /* | |
79 | * We could do so much better if we had the VA as well. | |
80 | * Instead, we invalidate Stage-2 for this IPA, and the | |
81 | * whole of Stage-1. Weep... | |
82 | */ | |
83 | ipa >>= 12; | |
fa715319 | 84 | __tlbi(ipas2e1is, ipa); |
5eec0a91 MZ |
85 | |
86 | /* | |
87 | * We have to ensure completion of the invalidation at Stage-2, | |
88 | * since a table walk on another CPU could refill a TLB with a | |
89 | * complete (S1 + S2) walk based on the old Stage-2 mapping if | |
90 | * the Stage-1 invalidation happened first. | |
91 | */ | |
92 | dsb(ish); | |
fa715319 | 93 | __tlbi(vmalle1is); |
5eec0a91 MZ |
94 | dsb(ish); |
95 | isb(); | |
96 | ||
68925176 | 97 | __tlb_switch_to_host()(kvm); |
5eec0a91 MZ |
98 | } |
99 | ||
cf0ba18a | 100 | void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm) |
5eec0a91 MZ |
101 | { |
102 | dsb(ishst); | |
103 | ||
104 | /* Switch to requested VMID */ | |
105 | kvm = kern_hyp_va(kvm); | |
68925176 | 106 | __tlb_switch_to_guest()(kvm); |
5eec0a91 | 107 | |
fa715319 | 108 | __tlbi(vmalls12e1is); |
5eec0a91 MZ |
109 | dsb(ish); |
110 | isb(); | |
111 | ||
68925176 | 112 | __tlb_switch_to_host()(kvm); |
5eec0a91 MZ |
113 | } |
114 | ||
94d0e598 MZ |
115 | void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu) |
116 | { | |
117 | struct kvm *kvm = kern_hyp_va(kern_hyp_va(vcpu)->kvm); | |
118 | ||
119 | /* Switch to requested VMID */ | |
68925176 | 120 | __tlb_switch_to_guest()(kvm); |
94d0e598 | 121 | |
fa715319 | 122 | __tlbi(vmalle1); |
94d0e598 MZ |
123 | dsb(nsh); |
124 | isb(); | |
125 | ||
68925176 | 126 | __tlb_switch_to_host()(kvm); |
94d0e598 MZ |
127 | } |
128 | ||
cf0ba18a | 129 | void __hyp_text __kvm_flush_vm_context(void) |
5eec0a91 MZ |
130 | { |
131 | dsb(ishst); | |
fa715319 CC |
132 | __tlbi(alle1is); |
133 | asm volatile("ic ialluis" : : ); | |
5eec0a91 MZ |
134 | dsb(ish); |
135 | } |