blob: 4b4e927c4822c3cac691a8d84dadf843a1b5efba [file] [log] [blame]
Alexander Graf0d8dc682009-10-30 05:47:11 +00001/*
2 * Copyright (C) 2009 SUSE Linux Products GmbH. All rights reserved.
3 *
4 * Authors:
5 * Alexander Graf <agraf@suse.de>
6 * Kevin Wolf <mail@kevin-wolf.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License, version 2, as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22#include <linux/kvm_host.h>
23
24#include <asm/kvm_ppc.h>
25#include <asm/kvm_book3s.h>
Aneesh Kumar K.Vf64e8082016-03-01 12:59:20 +053026#include <asm/book3s/64/mmu-hash.h>
Alexander Graf0d8dc682009-10-30 05:47:11 +000027#include <asm/machdep.h>
28#include <asm/mmu_context.h>
29#include <asm/hw_irq.h>
Aneesh Kumar K.V72c12532013-10-07 22:17:57 +053030#include "trace_pr.h"
Thomas Huth5358a962015-05-22 09:25:02 +020031#include "book3s.h"
Alexander Graf0d8dc682009-10-30 05:47:11 +000032
33#define PTE_SIZE 12
Alexander Graf0d8dc682009-10-30 05:47:11 +000034
Alexander Graffef093be2010-06-30 15:18:46 +020035void kvmppc_mmu_invalidate_pte(struct kvm_vcpu *vcpu, struct hpte_cache *pte)
Alexander Graf0d8dc682009-10-30 05:47:11 +000036{
Benjamin Herrenschmidt70257762016-07-05 15:03:58 +100037 mmu_hash_ops.hpte_invalidate(pte->slot, pte->host_vpn,
38 pte->pagesize, pte->pagesize,
39 MMU_SEGSIZE_256M, false);
Alexander Graf0d8dc682009-10-30 05:47:11 +000040}
41
42/* We keep 512 gvsid->hvsid entries, mapping the guest ones to the array using
43 * a hash, so we don't waste cycles on looping */
44static u16 kvmppc_sid_hash(struct kvm_vcpu *vcpu, u64 gvsid)
45{
Alexander Grafb9877ce2010-08-02 21:48:53 +020046 return (u16)(((gvsid >> (SID_MAP_BITS * 7)) & SID_MAP_MASK) ^
47 ((gvsid >> (SID_MAP_BITS * 6)) & SID_MAP_MASK) ^
48 ((gvsid >> (SID_MAP_BITS * 5)) & SID_MAP_MASK) ^
49 ((gvsid >> (SID_MAP_BITS * 4)) & SID_MAP_MASK) ^
50 ((gvsid >> (SID_MAP_BITS * 3)) & SID_MAP_MASK) ^
51 ((gvsid >> (SID_MAP_BITS * 2)) & SID_MAP_MASK) ^
52 ((gvsid >> (SID_MAP_BITS * 1)) & SID_MAP_MASK) ^
53 ((gvsid >> (SID_MAP_BITS * 0)) & SID_MAP_MASK));
Alexander Graf0d8dc682009-10-30 05:47:11 +000054}
55
Alexander Grafb9877ce2010-08-02 21:48:53 +020056
Alexander Graf0d8dc682009-10-30 05:47:11 +000057static struct kvmppc_sid_map *find_sid_vsid(struct kvm_vcpu *vcpu, u64 gvsid)
58{
59 struct kvmppc_sid_map *map;
60 u16 sid_map_mask;
61
Alexander Graf5deb8e72014-04-24 13:46:24 +020062 if (kvmppc_get_msr(vcpu) & MSR_PR)
Alexander Graf0d8dc682009-10-30 05:47:11 +000063 gvsid |= VSID_PR;
64
65 sid_map_mask = kvmppc_sid_hash(vcpu, gvsid);
66 map = &to_book3s(vcpu)->sid_map[sid_map_mask];
Alexander Grafc22c3192010-08-02 13:38:18 +020067 if (map->valid && (map->guest_vsid == gvsid)) {
Alexander Graf928d78b2010-08-02 21:25:33 +020068 trace_kvm_book3s_slb_found(gvsid, map->host_vsid);
Alexander Graf0d8dc682009-10-30 05:47:11 +000069 return map;
70 }
71
72 map = &to_book3s(vcpu)->sid_map[SID_MAP_MASK - sid_map_mask];
Alexander Grafc22c3192010-08-02 13:38:18 +020073 if (map->valid && (map->guest_vsid == gvsid)) {
Alexander Graf928d78b2010-08-02 21:25:33 +020074 trace_kvm_book3s_slb_found(gvsid, map->host_vsid);
Alexander Graf0d8dc682009-10-30 05:47:11 +000075 return map;
76 }
77
Alexander Graf928d78b2010-08-02 21:25:33 +020078 trace_kvm_book3s_slb_fail(sid_map_mask, gvsid);
Alexander Graf0d8dc682009-10-30 05:47:11 +000079 return NULL;
80}
81
Paul Mackerras93b159b2013-09-20 14:52:51 +100082int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte,
83 bool iswrite)
Alexander Graf0d8dc682009-10-30 05:47:11 +000084{
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +000085 unsigned long vpn;
Dan Williamsba049e92016-01-15 16:56:11 -080086 kvm_pfn_t hpaddr;
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +000087 ulong hash, hpteg;
Alexander Graf0d8dc682009-10-30 05:47:11 +000088 u64 vsid;
89 int ret;
90 int rflags = 0x192;
91 int vflags = 0;
92 int attempt = 0;
93 struct kvmppc_sid_map *map;
Alexander Graf468a12c2011-12-09 14:44:13 +010094 int r = 0;
Paul Mackerrasc9029c32013-09-20 14:52:45 +100095 int hpsize = MMU_PAGE_4K;
Paul Mackerras93b159b2013-09-20 14:52:51 +100096 bool writable;
Paul Mackerrasd78bca72013-09-20 14:52:52 +100097 unsigned long mmu_seq;
98 struct kvm *kvm = vcpu->kvm;
99 struct hpte_cache *cpte;
Paul Mackerrasadc0baf2013-09-20 14:52:53 +1000100 unsigned long gfn = orig_pte->raddr >> PAGE_SHIFT;
101 unsigned long pfn;
Paul Mackerrasd78bca72013-09-20 14:52:52 +1000102
103 /* used to check for invalidations in progress */
104 mmu_seq = kvm->mmu_notifier_seq;
105 smp_rmb();
Alexander Graf0d8dc682009-10-30 05:47:11 +0000106
107 /* Get host physical address for gpa */
Alexander Graf89b68c92014-07-13 16:37:12 +0200108 pfn = kvmppc_gpa_to_pfn(vcpu, orig_pte->raddr, iswrite, &writable);
Paul Mackerrasadc0baf2013-09-20 14:52:53 +1000109 if (is_error_noslot_pfn(pfn)) {
Alexander Graf89b68c92014-07-13 16:37:12 +0200110 printk(KERN_INFO "Couldn't get guest page for gpa %lx!\n",
111 orig_pte->raddr);
Alexander Graf468a12c2011-12-09 14:44:13 +0100112 r = -EINVAL;
113 goto out;
Alexander Graf0d8dc682009-10-30 05:47:11 +0000114 }
Paul Mackerrasadc0baf2013-09-20 14:52:53 +1000115 hpaddr = pfn << PAGE_SHIFT;
Alexander Graf0d8dc682009-10-30 05:47:11 +0000116
117 /* and write the mapping ea -> hpa into the pt */
118 vcpu->arch.mmu.esid_to_vsid(vcpu, orig_pte->eaddr >> SID_SHIFT, &vsid);
119 map = find_sid_vsid(vcpu, vsid);
120 if (!map) {
Alexander Grafac214672010-04-20 02:49:50 +0200121 ret = kvmppc_mmu_map_segment(vcpu, orig_pte->eaddr);
122 WARN_ON(ret < 0);
Alexander Graf0d8dc682009-10-30 05:47:11 +0000123 map = find_sid_vsid(vcpu, vsid);
124 }
Alexander Grafac214672010-04-20 02:49:50 +0200125 if (!map) {
126 printk(KERN_ERR "KVM: Segment map for 0x%llx (0x%lx) failed\n",
127 vsid, orig_pte->eaddr);
128 WARN_ON(true);
Alexander Graf468a12c2011-12-09 14:44:13 +0100129 r = -EINVAL;
130 goto out;
Alexander Grafac214672010-04-20 02:49:50 +0200131 }
Alexander Graf0d8dc682009-10-30 05:47:11 +0000132
Paul Mackerrasc9029c32013-09-20 14:52:45 +1000133 vpn = hpt_vpn(orig_pte->eaddr, map->host_vsid, MMU_SEGSIZE_256M);
Alexander Graf0d8dc682009-10-30 05:47:11 +0000134
Paul Mackerrasadc0baf2013-09-20 14:52:53 +1000135 kvm_set_pfn_accessed(pfn);
Paul Mackerras93b159b2013-09-20 14:52:51 +1000136 if (!orig_pte->may_write || !writable)
Paul Mackerrasadc0baf2013-09-20 14:52:53 +1000137 rflags |= PP_RXRX;
138 else {
139 mark_page_dirty(vcpu->kvm, gfn);
140 kvm_set_pfn_dirty(pfn);
141 }
Alexander Graf0d8dc682009-10-30 05:47:11 +0000142
143 if (!orig_pte->may_execute)
144 rflags |= HPTE_R_N;
Alexander Graf249ba1e2012-08-03 13:56:33 +0200145 else
Paul Mackerrasadc0baf2013-09-20 14:52:53 +1000146 kvmppc_mmu_flush_icache(pfn);
Alexander Graf0d8dc682009-10-30 05:47:11 +0000147
Paul Mackerrasc9029c32013-09-20 14:52:45 +1000148 /*
149 * Use 64K pages if possible; otherwise, on 64K page kernels,
150 * we need to transfer 4 more bits from guest real to host real addr.
151 */
152 if (vsid & VSID_64K)
153 hpsize = MMU_PAGE_64K;
154 else
155 hpaddr |= orig_pte->raddr & (~0xfffULL & ~PAGE_MASK);
156
157 hash = hpt_hash(vpn, mmu_psize_defs[hpsize].shift, MMU_SEGSIZE_256M);
Alexander Graf0d8dc682009-10-30 05:47:11 +0000158
Paul Mackerrasd78bca72013-09-20 14:52:52 +1000159 cpte = kvmppc_mmu_hpte_cache_next(vcpu);
160
161 spin_lock(&kvm->mmu_lock);
162 if (!cpte || mmu_notifier_retry(kvm, mmu_seq)) {
163 r = -EAGAIN;
164 goto out_unlock;
165 }
166
Alexander Graf0d8dc682009-10-30 05:47:11 +0000167map_again:
168 hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP);
169
170 /* In case we tried normal mapping already, let's nuke old entries */
171 if (attempt > 1)
Benjamin Herrenschmidt70257762016-07-05 15:03:58 +1000172 if (mmu_hash_ops.hpte_remove(hpteg) < 0) {
Alexander Graf468a12c2011-12-09 14:44:13 +0100173 r = -1;
Paul Mackerrasd78bca72013-09-20 14:52:52 +1000174 goto out_unlock;
Alexander Graf468a12c2011-12-09 14:44:13 +0100175 }
Alexander Graf0d8dc682009-10-30 05:47:11 +0000176
Benjamin Herrenschmidt70257762016-07-05 15:03:58 +1000177 ret = mmu_hash_ops.hpte_insert(hpteg, vpn, hpaddr, rflags, vflags,
178 hpsize, hpsize, MMU_SEGSIZE_256M);
Alexander Graf0d8dc682009-10-30 05:47:11 +0000179
Alexey Kardashevskiy90089932017-03-24 17:48:10 +1100180 if (ret == -1) {
Alexander Graf0d8dc682009-10-30 05:47:11 +0000181 /* If we couldn't map a primary PTE, try a secondary */
Alexander Graf0d8dc682009-10-30 05:47:11 +0000182 hash = ~hash;
Alexander Graf20a340a2010-02-19 11:00:46 +0100183 vflags ^= HPTE_V_SECONDARY;
Alexander Graf0d8dc682009-10-30 05:47:11 +0000184 attempt++;
Alexander Graf0d8dc682009-10-30 05:47:11 +0000185 goto map_again;
Alexey Kardashevskiy90089932017-03-24 17:48:10 +1100186 } else if (ret < 0) {
187 r = -EIO;
188 goto out_unlock;
Alexander Graf0d8dc682009-10-30 05:47:11 +0000189 } else {
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000190 trace_kvm_book3s_64_mmu_map(rflags, hpteg,
191 vpn, hpaddr, orig_pte);
Alexander Graf0d8dc682009-10-30 05:47:11 +0000192
Benjamin Herrenschmidt70257762016-07-05 15:03:58 +1000193 /*
194 * The mmu_hash_ops code may give us a secondary entry even
195 * though we asked for a primary. Fix up.
196 */
Alexander Grafa1eda282010-03-24 21:48:34 +0100197 if ((ret & _PTEIDX_SECONDARY) && !(vflags & HPTE_V_SECONDARY)) {
198 hash = ~hash;
199 hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP);
200 }
201
Paul Mackerrasd78bca72013-09-20 14:52:52 +1000202 cpte->slot = hpteg + (ret & 7);
203 cpte->host_vpn = vpn;
204 cpte->pte = *orig_pte;
Paul Mackerrasadc0baf2013-09-20 14:52:53 +1000205 cpte->pfn = pfn;
Paul Mackerrasd78bca72013-09-20 14:52:52 +1000206 cpte->pagesize = hpsize;
Alexander Graffef093be2010-06-30 15:18:46 +0200207
Paul Mackerrasd78bca72013-09-20 14:52:52 +1000208 kvmppc_mmu_hpte_cache_map(vcpu, cpte);
209 cpte = NULL;
Alexander Graf0d8dc682009-10-30 05:47:11 +0000210 }
Paul Mackerrasd78bca72013-09-20 14:52:52 +1000211
212out_unlock:
213 spin_unlock(&kvm->mmu_lock);
Paul Mackerrasadc0baf2013-09-20 14:52:53 +1000214 kvm_release_pfn_clean(pfn);
Paul Mackerrasd78bca72013-09-20 14:52:52 +1000215 if (cpte)
216 kvmppc_mmu_hpte_cache_free(cpte);
Alexander Graf0d8dc682009-10-30 05:47:11 +0000217
Alexander Graf468a12c2011-12-09 14:44:13 +0100218out:
219 return r;
Alexander Graf0d8dc682009-10-30 05:47:11 +0000220}
221
Paul Mackerras93b159b2013-09-20 14:52:51 +1000222void kvmppc_mmu_unmap_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte)
223{
224 u64 mask = 0xfffffffffULL;
225 u64 vsid;
226
227 vcpu->arch.mmu.esid_to_vsid(vcpu, pte->eaddr >> SID_SHIFT, &vsid);
228 if (vsid & VSID_64K)
229 mask = 0xffffffff0ULL;
230 kvmppc_mmu_pte_vflush(vcpu, pte->vpage, mask);
231}
232
Alexander Graf0d8dc682009-10-30 05:47:11 +0000233static struct kvmppc_sid_map *create_sid_map(struct kvm_vcpu *vcpu, u64 gvsid)
234{
235 struct kvmppc_sid_map *map;
236 struct kvmppc_vcpu_book3s *vcpu_book3s = to_book3s(vcpu);
237 u16 sid_map_mask;
238 static int backwards_map = 0;
239
Alexander Graf5deb8e72014-04-24 13:46:24 +0200240 if (kvmppc_get_msr(vcpu) & MSR_PR)
Alexander Graf0d8dc682009-10-30 05:47:11 +0000241 gvsid |= VSID_PR;
242
243 /* We might get collisions that trap in preceding order, so let's
244 map them differently */
245
246 sid_map_mask = kvmppc_sid_hash(vcpu, gvsid);
247 if (backwards_map)
248 sid_map_mask = SID_MAP_MASK - sid_map_mask;
249
250 map = &to_book3s(vcpu)->sid_map[sid_map_mask];
251
252 /* Make sure we're taking the other map next time */
253 backwards_map = !backwards_map;
254
255 /* Uh-oh ... out of mappings. Let's flush! */
Benjamin Herrenschmidtffe36492012-03-23 11:21:14 +1100256 if (vcpu_book3s->proto_vsid_next == vcpu_book3s->proto_vsid_max) {
257 vcpu_book3s->proto_vsid_next = vcpu_book3s->proto_vsid_first;
Alexander Graf0d8dc682009-10-30 05:47:11 +0000258 memset(vcpu_book3s->sid_map, 0,
259 sizeof(struct kvmppc_sid_map) * SID_MAP_NUM);
260 kvmppc_mmu_pte_flush(vcpu, 0, 0);
261 kvmppc_mmu_flush_segments(vcpu);
262 }
Benjamin Herrenschmidtffe36492012-03-23 11:21:14 +1100263 map->host_vsid = vsid_scramble(vcpu_book3s->proto_vsid_next++, 256M);
Alexander Graf0d8dc682009-10-30 05:47:11 +0000264
265 map->guest_vsid = gvsid;
266 map->valid = true;
267
Alexander Graf928d78b2010-08-02 21:25:33 +0200268 trace_kvm_book3s_slb_map(sid_map_mask, gvsid, map->host_vsid);
Alexander Graf5156f272010-04-20 02:49:52 +0200269
Alexander Graf0d8dc682009-10-30 05:47:11 +0000270 return map;
271}
272
273static int kvmppc_mmu_next_segment(struct kvm_vcpu *vcpu, ulong esid)
274{
Alexander Graf468a12c2011-12-09 14:44:13 +0100275 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
Alexander Graf0d8dc682009-10-30 05:47:11 +0000276 int i;
277 int max_slb_size = 64;
278 int found_inval = -1;
279 int r;
280
Alexander Graf0d8dc682009-10-30 05:47:11 +0000281 /* Are we overwriting? */
Alexander Graf207438d2014-05-15 14:36:05 +0200282 for (i = 0; i < svcpu->slb_max; i++) {
Alexander Graf468a12c2011-12-09 14:44:13 +0100283 if (!(svcpu->slb[i].esid & SLB_ESID_V))
Alexander Graf0d8dc682009-10-30 05:47:11 +0000284 found_inval = i;
Alexander Graf468a12c2011-12-09 14:44:13 +0100285 else if ((svcpu->slb[i].esid & ESID_MASK) == esid) {
286 r = i;
287 goto out;
288 }
Alexander Graf0d8dc682009-10-30 05:47:11 +0000289 }
290
291 /* Found a spare entry that was invalidated before */
Alexander Graf207438d2014-05-15 14:36:05 +0200292 if (found_inval >= 0) {
Alexander Graf468a12c2011-12-09 14:44:13 +0100293 r = found_inval;
294 goto out;
295 }
Alexander Graf0d8dc682009-10-30 05:47:11 +0000296
297 /* No spare invalid entry, so create one */
298
299 if (mmu_slb_size < 64)
300 max_slb_size = mmu_slb_size;
301
302 /* Overflowing -> purge */
Alexander Graf468a12c2011-12-09 14:44:13 +0100303 if ((svcpu->slb_max) == max_slb_size)
Alexander Graf0d8dc682009-10-30 05:47:11 +0000304 kvmppc_mmu_flush_segments(vcpu);
305
Alexander Graf468a12c2011-12-09 14:44:13 +0100306 r = svcpu->slb_max;
307 svcpu->slb_max++;
Alexander Graf0d8dc682009-10-30 05:47:11 +0000308
Alexander Graf468a12c2011-12-09 14:44:13 +0100309out:
310 svcpu_put(svcpu);
Alexander Graf0d8dc682009-10-30 05:47:11 +0000311 return r;
312}
313
314int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr)
315{
Alexander Graf468a12c2011-12-09 14:44:13 +0100316 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
Alexander Graf0d8dc682009-10-30 05:47:11 +0000317 u64 esid = eaddr >> SID_SHIFT;
318 u64 slb_esid = (eaddr & ESID_MASK) | SLB_ESID_V;
319 u64 slb_vsid = SLB_VSID_USER;
320 u64 gvsid;
321 int slb_index;
322 struct kvmppc_sid_map *map;
Alexander Graf468a12c2011-12-09 14:44:13 +0100323 int r = 0;
Alexander Graf0d8dc682009-10-30 05:47:11 +0000324
325 slb_index = kvmppc_mmu_next_segment(vcpu, eaddr & ESID_MASK);
326
327 if (vcpu->arch.mmu.esid_to_vsid(vcpu, esid, &gvsid)) {
328 /* Invalidate an entry */
Alexander Graf468a12c2011-12-09 14:44:13 +0100329 svcpu->slb[slb_index].esid = 0;
330 r = -ENOENT;
331 goto out;
Alexander Graf0d8dc682009-10-30 05:47:11 +0000332 }
333
334 map = find_sid_vsid(vcpu, gvsid);
335 if (!map)
336 map = create_sid_map(vcpu, gvsid);
337
338 map->guest_esid = esid;
339
340 slb_vsid |= (map->host_vsid << 12);
341 slb_vsid &= ~SLB_VSID_KP;
342 slb_esid |= slb_index;
343
Paul Mackerrasc9029c32013-09-20 14:52:45 +1000344#ifdef CONFIG_PPC_64K_PAGES
345 /* Set host segment base page size to 64K if possible */
346 if (gvsid & VSID_64K)
347 slb_vsid |= mmu_psize_defs[MMU_PAGE_64K].sllp;
348#endif
349
Alexander Graf468a12c2011-12-09 14:44:13 +0100350 svcpu->slb[slb_index].esid = slb_esid;
351 svcpu->slb[slb_index].vsid = slb_vsid;
Alexander Graf0d8dc682009-10-30 05:47:11 +0000352
Alexander Graf928d78b2010-08-02 21:25:33 +0200353 trace_kvm_book3s_slbmte(slb_vsid, slb_esid);
Alexander Graf0d8dc682009-10-30 05:47:11 +0000354
Alexander Graf468a12c2011-12-09 14:44:13 +0100355out:
356 svcpu_put(svcpu);
357 return r;
Alexander Graf0d8dc682009-10-30 05:47:11 +0000358}
359
Paul Mackerras0f296822013-06-22 17:16:32 +1000360void kvmppc_mmu_flush_segment(struct kvm_vcpu *vcpu, ulong ea, ulong seg_size)
361{
362 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
363 ulong seg_mask = -seg_size;
364 int i;
365
Alexander Graf207438d2014-05-15 14:36:05 +0200366 for (i = 0; i < svcpu->slb_max; i++) {
Paul Mackerras0f296822013-06-22 17:16:32 +1000367 if ((svcpu->slb[i].esid & SLB_ESID_V) &&
368 (svcpu->slb[i].esid & seg_mask) == ea) {
369 /* Invalidate this entry */
370 svcpu->slb[i].esid = 0;
371 }
372 }
373
374 svcpu_put(svcpu);
375}
376
Alexander Graf0d8dc682009-10-30 05:47:11 +0000377void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu)
378{
Alexander Graf468a12c2011-12-09 14:44:13 +0100379 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
Alexander Graf207438d2014-05-15 14:36:05 +0200380 svcpu->slb_max = 0;
Alexander Graf468a12c2011-12-09 14:44:13 +0100381 svcpu->slb[0].esid = 0;
382 svcpu_put(svcpu);
Alexander Graf0d8dc682009-10-30 05:47:11 +0000383}
384
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530385void kvmppc_mmu_destroy_pr(struct kvm_vcpu *vcpu)
Alexander Graf0d8dc682009-10-30 05:47:11 +0000386{
Alexander Graffef093be2010-06-30 15:18:46 +0200387 kvmppc_mmu_hpte_destroy(vcpu);
Alexander Graf8b6db3b2010-08-15 08:04:24 +0200388 __destroy_context(to_book3s(vcpu)->context_id[0]);
Alexander Graf9cc5e952010-04-16 00:11:45 +0200389}
390
391int kvmppc_mmu_init(struct kvm_vcpu *vcpu)
392{
393 struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
394 int err;
395
396 err = __init_new_context();
397 if (err < 0)
398 return -1;
Alexander Graf8b6db3b2010-08-15 08:04:24 +0200399 vcpu3s->context_id[0] = err;
Alexander Graf9cc5e952010-04-16 00:11:45 +0200400
Paul Mackerras8ed7b7e2013-06-22 17:13:32 +1000401 vcpu3s->proto_vsid_max = ((u64)(vcpu3s->context_id[0] + 1)
Aneesh Kumar K.Vaf81d782013-03-13 03:34:55 +0000402 << ESID_BITS) - 1;
Paul Mackerras8ed7b7e2013-06-22 17:13:32 +1000403 vcpu3s->proto_vsid_first = (u64)vcpu3s->context_id[0] << ESID_BITS;
Benjamin Herrenschmidtffe36492012-03-23 11:21:14 +1100404 vcpu3s->proto_vsid_next = vcpu3s->proto_vsid_first;
Alexander Graf9cc5e952010-04-16 00:11:45 +0200405
Alexander Graffef093be2010-06-30 15:18:46 +0200406 kvmppc_mmu_hpte_init(vcpu);
407
Alexander Graf9cc5e952010-04-16 00:11:45 +0200408 return 0;
Alexander Graf0d8dc682009-10-30 05:47:11 +0000409}