This source file includes following definitions.
- __tlb_switch_to_guest_vhe
- __tlb_switch_to_guest_nvhe
- __tlb_switch_to_guest
- __tlb_switch_to_host_vhe
- __tlb_switch_to_host_nvhe
- __tlb_switch_to_host
- __kvm_tlb_flush_vmid_ipa
- __kvm_tlb_flush_vmid
- __kvm_tlb_flush_local_vmid
- __kvm_flush_vm_context
1
2
3
4
5
6
7 #include <linux/irqflags.h>
8
9 #include <asm/kvm_hyp.h>
10 #include <asm/kvm_mmu.h>
11 #include <asm/tlbflush.h>
12
13 struct tlb_inv_context {
14 unsigned long flags;
15 u64 tcr;
16 u64 sctlr;
17 };
18
19 static void __hyp_text __tlb_switch_to_guest_vhe(struct kvm *kvm,
20 struct tlb_inv_context *cxt)
21 {
22 u64 val;
23
24 local_irq_save(cxt->flags);
25
26 if (cpus_have_const_cap(ARM64_WORKAROUND_1165522)) {
27
28
29
30
31
32
33
34
35
36 val = cxt->tcr = read_sysreg_el1(SYS_TCR);
37 val |= TCR_EPD1_MASK | TCR_EPD0_MASK;
38 write_sysreg_el1(val, SYS_TCR);
39 val = cxt->sctlr = read_sysreg_el1(SYS_SCTLR);
40 val |= SCTLR_ELx_M;
41 write_sysreg_el1(val, SYS_SCTLR);
42 }
43
44
45
46
47
48
49
50
51
52
53
54
55
56 __load_guest_stage2(kvm);
57 val = read_sysreg(hcr_el2);
58 val &= ~HCR_TGE;
59 write_sysreg(val, hcr_el2);
60 isb();
61 }
62
63 static void __hyp_text __tlb_switch_to_guest_nvhe(struct kvm *kvm,
64 struct tlb_inv_context *cxt)
65 {
66 __load_guest_stage2(kvm);
67 isb();
68 }
69
70 static void __hyp_text __tlb_switch_to_guest(struct kvm *kvm,
71 struct tlb_inv_context *cxt)
72 {
73 if (has_vhe())
74 __tlb_switch_to_guest_vhe(kvm, cxt);
75 else
76 __tlb_switch_to_guest_nvhe(kvm, cxt);
77 }
78
79 static void __hyp_text __tlb_switch_to_host_vhe(struct kvm *kvm,
80 struct tlb_inv_context *cxt)
81 {
82
83
84
85
86 write_sysreg(0, vttbr_el2);
87 write_sysreg(HCR_HOST_VHE_FLAGS, hcr_el2);
88 isb();
89
90 if (cpus_have_const_cap(ARM64_WORKAROUND_1165522)) {
91
92 write_sysreg_el1(cxt->tcr, SYS_TCR);
93 write_sysreg_el1(cxt->sctlr, SYS_SCTLR);
94 }
95
96 local_irq_restore(cxt->flags);
97 }
98
99 static void __hyp_text __tlb_switch_to_host_nvhe(struct kvm *kvm,
100 struct tlb_inv_context *cxt)
101 {
102 write_sysreg(0, vttbr_el2);
103 }
104
105 static void __hyp_text __tlb_switch_to_host(struct kvm *kvm,
106 struct tlb_inv_context *cxt)
107 {
108 if (has_vhe())
109 __tlb_switch_to_host_vhe(kvm, cxt);
110 else
111 __tlb_switch_to_host_nvhe(kvm, cxt);
112 }
113
114 void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
115 {
116 struct tlb_inv_context cxt;
117
118 dsb(ishst);
119
120
121 kvm = kern_hyp_va(kvm);
122 __tlb_switch_to_guest(kvm, &cxt);
123
124
125
126
127
128
129 ipa >>= 12;
130 __tlbi(ipas2e1is, ipa);
131
132
133
134
135
136
137
138 dsb(ish);
139 __tlbi(vmalle1is);
140 dsb(ish);
141 isb();
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162 if (!has_vhe() && icache_is_vpipt())
163 __flush_icache_all();
164
165 __tlb_switch_to_host(kvm, &cxt);
166 }
167
168 void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm)
169 {
170 struct tlb_inv_context cxt;
171
172 dsb(ishst);
173
174
175 kvm = kern_hyp_va(kvm);
176 __tlb_switch_to_guest(kvm, &cxt);
177
178 __tlbi(vmalls12e1is);
179 dsb(ish);
180 isb();
181
182 __tlb_switch_to_host(kvm, &cxt);
183 }
184
185 void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu)
186 {
187 struct kvm *kvm = kern_hyp_va(kern_hyp_va(vcpu)->kvm);
188 struct tlb_inv_context cxt;
189
190
191 __tlb_switch_to_guest(kvm, &cxt);
192
193 __tlbi(vmalle1);
194 dsb(nsh);
195 isb();
196
197 __tlb_switch_to_host(kvm, &cxt);
198 }
199
200 void __hyp_text __kvm_flush_vm_context(void)
201 {
202 dsb(ishst);
203 __tlbi(alle1is);
204
205
206
207
208
209
210
211
212
213
214 if (icache_is_vpipt())
215 asm volatile("ic ialluis");
216
217 dsb(ish);
218 }