]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/powerpc/kvm/book3s_hv_rm_mmu.c
KVM: PPC: Book3S HV: Provide mode where all vCPUs on a core must be the same VM
[mirror_ubuntu-bionic-kernel.git] / arch / powerpc / kvm / book3s_hv_rm_mmu.c
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2, as
4 * published by the Free Software Foundation.
5 *
6 * Copyright 2010-2011 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
7 */
8
9 #include <linux/types.h>
10 #include <linux/string.h>
11 #include <linux/kvm.h>
12 #include <linux/kvm_host.h>
13 #include <linux/hugetlb.h>
14 #include <linux/module.h>
15 #include <linux/log2.h>
16
17 #include <asm/tlbflush.h>
18 #include <asm/trace.h>
19 #include <asm/kvm_ppc.h>
20 #include <asm/kvm_book3s.h>
21 #include <asm/book3s/64/mmu-hash.h>
22 #include <asm/hvcall.h>
23 #include <asm/synch.h>
24 #include <asm/ppc-opcode.h>
25 #include <asm/pte-walk.h>
26
27 /* Translate address of a vmalloc'd thing to a linear map address */
28 static void *real_vmalloc_addr(void *x)
29 {
30 unsigned long addr = (unsigned long) x;
31 pte_t *p;
32 /*
33 * assume we don't have huge pages in vmalloc space...
34 * So don't worry about THP collapse/split. Called
35 * Only in realmode with MSR_EE = 0, hence won't need irq_save/restore.
36 */
37 p = find_init_mm_pte(addr, NULL);
38 if (!p || !pte_present(*p))
39 return NULL;
40 addr = (pte_pfn(*p) << PAGE_SHIFT) | (addr & ~PAGE_MASK);
41 return __va(addr);
42 }
43
44 /* Return 1 if we need to do a global tlbie, 0 if we can use tlbiel */
45 static int global_invalidates(struct kvm *kvm, unsigned long flags)
46 {
47 int global;
48 int cpu;
49
50 /*
51 * If there is only one vcore, and it's currently running,
52 * as indicated by local_paca->kvm_hstate.kvm_vcpu being set,
53 * we can use tlbiel as long as we mark all other physical
54 * cores as potentially having stale TLB entries for this lpid.
55 * Otherwise, don't use tlbiel.
56 */
57 if (kvm->arch.online_vcores == 1 && local_paca->kvm_hstate.kvm_vcpu)
58 global = 0;
59 else
60 global = 1;
61
62 if (!global) {
63 /* any other core might now have stale TLB entries... */
64 smp_wmb();
65 cpumask_setall(&kvm->arch.need_tlb_flush);
66 cpu = local_paca->kvm_hstate.kvm_vcore->pcpu;
67 /*
68 * On POWER9, threads are independent but the TLB is shared,
69 * so use the bit for the first thread to represent the core.
70 */
71 if (cpu_has_feature(CPU_FTR_ARCH_300))
72 cpu = cpu_first_thread_sibling(cpu);
73 cpumask_clear_cpu(cpu, &kvm->arch.need_tlb_flush);
74 }
75
76 return global;
77 }
78
79 /*
80 * Add this HPTE into the chain for the real page.
81 * Must be called with the chain locked; it unlocks the chain.
82 */
83 void kvmppc_add_revmap_chain(struct kvm *kvm, struct revmap_entry *rev,
84 unsigned long *rmap, long pte_index, int realmode)
85 {
86 struct revmap_entry *head, *tail;
87 unsigned long i;
88
89 if (*rmap & KVMPPC_RMAP_PRESENT) {
90 i = *rmap & KVMPPC_RMAP_INDEX;
91 head = &kvm->arch.hpt.rev[i];
92 if (realmode)
93 head = real_vmalloc_addr(head);
94 tail = &kvm->arch.hpt.rev[head->back];
95 if (realmode)
96 tail = real_vmalloc_addr(tail);
97 rev->forw = i;
98 rev->back = head->back;
99 tail->forw = pte_index;
100 head->back = pte_index;
101 } else {
102 rev->forw = rev->back = pte_index;
103 *rmap = (*rmap & ~KVMPPC_RMAP_INDEX) |
104 pte_index | KVMPPC_RMAP_PRESENT;
105 }
106 unlock_rmap(rmap);
107 }
108 EXPORT_SYMBOL_GPL(kvmppc_add_revmap_chain);
109
110 /* Update the dirty bitmap of a memslot */
111 void kvmppc_update_dirty_map(struct kvm_memory_slot *memslot,
112 unsigned long gfn, unsigned long psize)
113 {
114 unsigned long npages;
115
116 if (!psize || !memslot->dirty_bitmap)
117 return;
118 npages = (psize + PAGE_SIZE - 1) / PAGE_SIZE;
119 gfn -= memslot->base_gfn;
120 set_dirty_bits_atomic(memslot->dirty_bitmap, gfn, npages);
121 }
122 EXPORT_SYMBOL_GPL(kvmppc_update_dirty_map);
123
124 static void kvmppc_set_dirty_from_hpte(struct kvm *kvm,
125 unsigned long hpte_v, unsigned long hpte_gr)
126 {
127 struct kvm_memory_slot *memslot;
128 unsigned long gfn;
129 unsigned long psize;
130
131 psize = kvmppc_actual_pgsz(hpte_v, hpte_gr);
132 gfn = hpte_rpn(hpte_gr, psize);
133 memslot = __gfn_to_memslot(kvm_memslots_raw(kvm), gfn);
134 if (memslot && memslot->dirty_bitmap)
135 kvmppc_update_dirty_map(memslot, gfn, psize);
136 }
137
138 /* Returns a pointer to the revmap entry for the page mapped by a HPTE */
139 static unsigned long *revmap_for_hpte(struct kvm *kvm, unsigned long hpte_v,
140 unsigned long hpte_gr,
141 struct kvm_memory_slot **memslotp,
142 unsigned long *gfnp)
143 {
144 struct kvm_memory_slot *memslot;
145 unsigned long *rmap;
146 unsigned long gfn;
147
148 gfn = hpte_rpn(hpte_gr, kvmppc_actual_pgsz(hpte_v, hpte_gr));
149 memslot = __gfn_to_memslot(kvm_memslots_raw(kvm), gfn);
150 if (memslotp)
151 *memslotp = memslot;
152 if (gfnp)
153 *gfnp = gfn;
154 if (!memslot)
155 return NULL;
156
157 rmap = real_vmalloc_addr(&memslot->arch.rmap[gfn - memslot->base_gfn]);
158 return rmap;
159 }
160
161 /* Remove this HPTE from the chain for a real page */
162 static void remove_revmap_chain(struct kvm *kvm, long pte_index,
163 struct revmap_entry *rev,
164 unsigned long hpte_v, unsigned long hpte_r)
165 {
166 struct revmap_entry *next, *prev;
167 unsigned long ptel, head;
168 unsigned long *rmap;
169 unsigned long rcbits;
170 struct kvm_memory_slot *memslot;
171 unsigned long gfn;
172
173 rcbits = hpte_r & (HPTE_R_R | HPTE_R_C);
174 ptel = rev->guest_rpte |= rcbits;
175 rmap = revmap_for_hpte(kvm, hpte_v, ptel, &memslot, &gfn);
176 if (!rmap)
177 return;
178 lock_rmap(rmap);
179
180 head = *rmap & KVMPPC_RMAP_INDEX;
181 next = real_vmalloc_addr(&kvm->arch.hpt.rev[rev->forw]);
182 prev = real_vmalloc_addr(&kvm->arch.hpt.rev[rev->back]);
183 next->back = rev->back;
184 prev->forw = rev->forw;
185 if (head == pte_index) {
186 head = rev->forw;
187 if (head == pte_index)
188 *rmap &= ~(KVMPPC_RMAP_PRESENT | KVMPPC_RMAP_INDEX);
189 else
190 *rmap = (*rmap & ~KVMPPC_RMAP_INDEX) | head;
191 }
192 *rmap |= rcbits << KVMPPC_RMAP_RC_SHIFT;
193 if (rcbits & HPTE_R_C)
194 kvmppc_update_dirty_map(memslot, gfn,
195 kvmppc_actual_pgsz(hpte_v, hpte_r));
196 unlock_rmap(rmap);
197 }
198
199 long kvmppc_do_h_enter(struct kvm *kvm, unsigned long flags,
200 long pte_index, unsigned long pteh, unsigned long ptel,
201 pgd_t *pgdir, bool realmode, unsigned long *pte_idx_ret)
202 {
203 unsigned long i, pa, gpa, gfn, psize;
204 unsigned long slot_fn, hva;
205 __be64 *hpte;
206 struct revmap_entry *rev;
207 unsigned long g_ptel;
208 struct kvm_memory_slot *memslot;
209 unsigned hpage_shift;
210 bool is_ci;
211 unsigned long *rmap;
212 pte_t *ptep;
213 unsigned int writing;
214 unsigned long mmu_seq;
215 unsigned long rcbits, irq_flags = 0;
216
217 if (kvm_is_radix(kvm))
218 return H_FUNCTION;
219 psize = kvmppc_actual_pgsz(pteh, ptel);
220 if (!psize)
221 return H_PARAMETER;
222 writing = hpte_is_writable(ptel);
223 pteh &= ~(HPTE_V_HVLOCK | HPTE_V_ABSENT | HPTE_V_VALID);
224 ptel &= ~HPTE_GR_RESERVED;
225 g_ptel = ptel;
226
227 /* used later to detect if we might have been invalidated */
228 mmu_seq = kvm->mmu_notifier_seq;
229 smp_rmb();
230
231 /* Find the memslot (if any) for this address */
232 gpa = (ptel & HPTE_R_RPN) & ~(psize - 1);
233 gfn = gpa >> PAGE_SHIFT;
234 memslot = __gfn_to_memslot(kvm_memslots_raw(kvm), gfn);
235 pa = 0;
236 is_ci = false;
237 rmap = NULL;
238 if (!(memslot && !(memslot->flags & KVM_MEMSLOT_INVALID))) {
239 /* Emulated MMIO - mark this with key=31 */
240 pteh |= HPTE_V_ABSENT;
241 ptel |= HPTE_R_KEY_HI | HPTE_R_KEY_LO;
242 goto do_insert;
243 }
244
245 /* Check if the requested page fits entirely in the memslot. */
246 if (!slot_is_aligned(memslot, psize))
247 return H_PARAMETER;
248 slot_fn = gfn - memslot->base_gfn;
249 rmap = &memslot->arch.rmap[slot_fn];
250
251 /* Translate to host virtual address */
252 hva = __gfn_to_hva_memslot(memslot, gfn);
253 /*
254 * If we had a page table table change after lookup, we would
255 * retry via mmu_notifier_retry.
256 */
257 if (!realmode)
258 local_irq_save(irq_flags);
259 /*
260 * If called in real mode we have MSR_EE = 0. Otherwise
261 * we disable irq above.
262 */
263 ptep = __find_linux_pte(pgdir, hva, NULL, &hpage_shift);
264 if (ptep) {
265 pte_t pte;
266 unsigned int host_pte_size;
267
268 if (hpage_shift)
269 host_pte_size = 1ul << hpage_shift;
270 else
271 host_pte_size = PAGE_SIZE;
272 /*
273 * We should always find the guest page size
274 * to <= host page size, if host is using hugepage
275 */
276 if (host_pte_size < psize) {
277 if (!realmode)
278 local_irq_restore(flags);
279 return H_PARAMETER;
280 }
281 pte = kvmppc_read_update_linux_pte(ptep, writing);
282 if (pte_present(pte) && !pte_protnone(pte)) {
283 if (writing && !__pte_write(pte))
284 /* make the actual HPTE be read-only */
285 ptel = hpte_make_readonly(ptel);
286 is_ci = pte_ci(pte);
287 pa = pte_pfn(pte) << PAGE_SHIFT;
288 pa |= hva & (host_pte_size - 1);
289 pa |= gpa & ~PAGE_MASK;
290 }
291 }
292 if (!realmode)
293 local_irq_restore(irq_flags);
294
295 ptel &= HPTE_R_KEY | HPTE_R_PP0 | (psize-1);
296 ptel |= pa;
297
298 if (pa)
299 pteh |= HPTE_V_VALID;
300 else {
301 pteh |= HPTE_V_ABSENT;
302 ptel &= ~(HPTE_R_KEY_HI | HPTE_R_KEY_LO);
303 }
304
305 /*If we had host pte mapping then Check WIMG */
306 if (ptep && !hpte_cache_flags_ok(ptel, is_ci)) {
307 if (is_ci)
308 return H_PARAMETER;
309 /*
310 * Allow guest to map emulated device memory as
311 * uncacheable, but actually make it cacheable.
312 */
313 ptel &= ~(HPTE_R_W|HPTE_R_I|HPTE_R_G);
314 ptel |= HPTE_R_M;
315 }
316
317 /* Find and lock the HPTEG slot to use */
318 do_insert:
319 if (pte_index >= kvmppc_hpt_npte(&kvm->arch.hpt))
320 return H_PARAMETER;
321 if (likely((flags & H_EXACT) == 0)) {
322 pte_index &= ~7UL;
323 hpte = (__be64 *)(kvm->arch.hpt.virt + (pte_index << 4));
324 for (i = 0; i < 8; ++i) {
325 if ((be64_to_cpu(*hpte) & HPTE_V_VALID) == 0 &&
326 try_lock_hpte(hpte, HPTE_V_HVLOCK | HPTE_V_VALID |
327 HPTE_V_ABSENT))
328 break;
329 hpte += 2;
330 }
331 if (i == 8) {
332 /*
333 * Since try_lock_hpte doesn't retry (not even stdcx.
334 * failures), it could be that there is a free slot
335 * but we transiently failed to lock it. Try again,
336 * actually locking each slot and checking it.
337 */
338 hpte -= 16;
339 for (i = 0; i < 8; ++i) {
340 u64 pte;
341 while (!try_lock_hpte(hpte, HPTE_V_HVLOCK))
342 cpu_relax();
343 pte = be64_to_cpu(hpte[0]);
344 if (!(pte & (HPTE_V_VALID | HPTE_V_ABSENT)))
345 break;
346 __unlock_hpte(hpte, pte);
347 hpte += 2;
348 }
349 if (i == 8)
350 return H_PTEG_FULL;
351 }
352 pte_index += i;
353 } else {
354 hpte = (__be64 *)(kvm->arch.hpt.virt + (pte_index << 4));
355 if (!try_lock_hpte(hpte, HPTE_V_HVLOCK | HPTE_V_VALID |
356 HPTE_V_ABSENT)) {
357 /* Lock the slot and check again */
358 u64 pte;
359
360 while (!try_lock_hpte(hpte, HPTE_V_HVLOCK))
361 cpu_relax();
362 pte = be64_to_cpu(hpte[0]);
363 if (pte & (HPTE_V_VALID | HPTE_V_ABSENT)) {
364 __unlock_hpte(hpte, pte);
365 return H_PTEG_FULL;
366 }
367 }
368 }
369
370 /* Save away the guest's idea of the second HPTE dword */
371 rev = &kvm->arch.hpt.rev[pte_index];
372 if (realmode)
373 rev = real_vmalloc_addr(rev);
374 if (rev) {
375 rev->guest_rpte = g_ptel;
376 note_hpte_modification(kvm, rev);
377 }
378
379 /* Link HPTE into reverse-map chain */
380 if (pteh & HPTE_V_VALID) {
381 if (realmode)
382 rmap = real_vmalloc_addr(rmap);
383 lock_rmap(rmap);
384 /* Check for pending invalidations under the rmap chain lock */
385 if (mmu_notifier_retry(kvm, mmu_seq)) {
386 /* inval in progress, write a non-present HPTE */
387 pteh |= HPTE_V_ABSENT;
388 pteh &= ~HPTE_V_VALID;
389 ptel &= ~(HPTE_R_KEY_HI | HPTE_R_KEY_LO);
390 unlock_rmap(rmap);
391 } else {
392 kvmppc_add_revmap_chain(kvm, rev, rmap, pte_index,
393 realmode);
394 /* Only set R/C in real HPTE if already set in *rmap */
395 rcbits = *rmap >> KVMPPC_RMAP_RC_SHIFT;
396 ptel &= rcbits | ~(HPTE_R_R | HPTE_R_C);
397 }
398 }
399
400 /* Convert to new format on P9 */
401 if (cpu_has_feature(CPU_FTR_ARCH_300)) {
402 ptel = hpte_old_to_new_r(pteh, ptel);
403 pteh = hpte_old_to_new_v(pteh);
404 }
405 hpte[1] = cpu_to_be64(ptel);
406
407 /* Write the first HPTE dword, unlocking the HPTE and making it valid */
408 eieio();
409 __unlock_hpte(hpte, pteh);
410 asm volatile("ptesync" : : : "memory");
411
412 *pte_idx_ret = pte_index;
413 return H_SUCCESS;
414 }
415 EXPORT_SYMBOL_GPL(kvmppc_do_h_enter);
416
417 long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
418 long pte_index, unsigned long pteh, unsigned long ptel)
419 {
420 return kvmppc_do_h_enter(vcpu->kvm, flags, pte_index, pteh, ptel,
421 vcpu->arch.pgdir, true, &vcpu->arch.gpr[4]);
422 }
423
424 #ifdef __BIG_ENDIAN__
425 #define LOCK_TOKEN (*(u32 *)(&get_paca()->lock_token))
426 #else
427 #define LOCK_TOKEN (*(u32 *)(&get_paca()->paca_index))
428 #endif
429
430 static inline int is_mmio_hpte(unsigned long v, unsigned long r)
431 {
432 return ((v & HPTE_V_ABSENT) &&
433 (r & (HPTE_R_KEY_HI | HPTE_R_KEY_LO)) ==
434 (HPTE_R_KEY_HI | HPTE_R_KEY_LO));
435 }
436
437 static inline int try_lock_tlbie(unsigned int *lock)
438 {
439 unsigned int tmp, old;
440 unsigned int token = LOCK_TOKEN;
441
442 asm volatile("1:lwarx %1,0,%2\n"
443 " cmpwi cr0,%1,0\n"
444 " bne 2f\n"
445 " stwcx. %3,0,%2\n"
446 " bne- 1b\n"
447 " isync\n"
448 "2:"
449 : "=&r" (tmp), "=&r" (old)
450 : "r" (lock), "r" (token)
451 : "cc", "memory");
452 return old == 0;
453 }
454
455 static void do_tlbies(struct kvm *kvm, unsigned long *rbvalues,
456 long npages, int global, bool need_sync)
457 {
458 long i;
459
460 /*
461 * We use the POWER9 5-operand versions of tlbie and tlbiel here.
462 * Since we are using RIC=0 PRS=0 R=0, and P7/P8 tlbiel ignores
463 * the RS field, this is backwards-compatible with P7 and P8.
464 */
465 if (global) {
466 while (!try_lock_tlbie(&kvm->arch.tlbie_lock))
467 cpu_relax();
468 if (need_sync)
469 asm volatile("ptesync" : : : "memory");
470 for (i = 0; i < npages; ++i) {
471 asm volatile(PPC_TLBIE_5(%0,%1,0,0,0) : :
472 "r" (rbvalues[i]), "r" (kvm->arch.lpid));
473 }
474
475 if (cpu_has_feature(CPU_FTR_P9_TLBIE_BUG)) {
476 /*
477 * Need the extra ptesync to make sure we don't
478 * re-order the tlbie
479 */
480 asm volatile("ptesync": : :"memory");
481 asm volatile(PPC_TLBIE_5(%0,%1,0,0,0) : :
482 "r" (rbvalues[0]), "r" (kvm->arch.lpid));
483 }
484
485 asm volatile("eieio; tlbsync; ptesync" : : : "memory");
486 kvm->arch.tlbie_lock = 0;
487 } else {
488 if (need_sync)
489 asm volatile("ptesync" : : : "memory");
490 for (i = 0; i < npages; ++i) {
491 asm volatile(PPC_TLBIEL(%0,%1,0,0,0) : :
492 "r" (rbvalues[i]), "r" (0));
493 }
494 asm volatile("ptesync" : : : "memory");
495 }
496 }
497
498 long kvmppc_do_h_remove(struct kvm *kvm, unsigned long flags,
499 unsigned long pte_index, unsigned long avpn,
500 unsigned long *hpret)
501 {
502 __be64 *hpte;
503 unsigned long v, r, rb;
504 struct revmap_entry *rev;
505 u64 pte, orig_pte, pte_r;
506
507 if (kvm_is_radix(kvm))
508 return H_FUNCTION;
509 if (pte_index >= kvmppc_hpt_npte(&kvm->arch.hpt))
510 return H_PARAMETER;
511 hpte = (__be64 *)(kvm->arch.hpt.virt + (pte_index << 4));
512 while (!try_lock_hpte(hpte, HPTE_V_HVLOCK))
513 cpu_relax();
514 pte = orig_pte = be64_to_cpu(hpte[0]);
515 pte_r = be64_to_cpu(hpte[1]);
516 if (cpu_has_feature(CPU_FTR_ARCH_300)) {
517 pte = hpte_new_to_old_v(pte, pte_r);
518 pte_r = hpte_new_to_old_r(pte_r);
519 }
520 if ((pte & (HPTE_V_ABSENT | HPTE_V_VALID)) == 0 ||
521 ((flags & H_AVPN) && (pte & ~0x7fUL) != avpn) ||
522 ((flags & H_ANDCOND) && (pte & avpn) != 0)) {
523 __unlock_hpte(hpte, orig_pte);
524 return H_NOT_FOUND;
525 }
526
527 rev = real_vmalloc_addr(&kvm->arch.hpt.rev[pte_index]);
528 v = pte & ~HPTE_V_HVLOCK;
529 if (v & HPTE_V_VALID) {
530 hpte[0] &= ~cpu_to_be64(HPTE_V_VALID);
531 rb = compute_tlbie_rb(v, pte_r, pte_index);
532 do_tlbies(kvm, &rb, 1, global_invalidates(kvm, flags), true);
533 /*
534 * The reference (R) and change (C) bits in a HPT
535 * entry can be set by hardware at any time up until
536 * the HPTE is invalidated and the TLB invalidation
537 * sequence has completed. This means that when
538 * removing a HPTE, we need to re-read the HPTE after
539 * the invalidation sequence has completed in order to
540 * obtain reliable values of R and C.
541 */
542 remove_revmap_chain(kvm, pte_index, rev, v,
543 be64_to_cpu(hpte[1]));
544 }
545 r = rev->guest_rpte & ~HPTE_GR_RESERVED;
546 note_hpte_modification(kvm, rev);
547 unlock_hpte(hpte, 0);
548
549 if (is_mmio_hpte(v, pte_r))
550 atomic64_inc(&kvm->arch.mmio_update);
551
552 if (v & HPTE_V_ABSENT)
553 v = (v & ~HPTE_V_ABSENT) | HPTE_V_VALID;
554 hpret[0] = v;
555 hpret[1] = r;
556 return H_SUCCESS;
557 }
558 EXPORT_SYMBOL_GPL(kvmppc_do_h_remove);
559
560 long kvmppc_h_remove(struct kvm_vcpu *vcpu, unsigned long flags,
561 unsigned long pte_index, unsigned long avpn)
562 {
563 return kvmppc_do_h_remove(vcpu->kvm, flags, pte_index, avpn,
564 &vcpu->arch.gpr[4]);
565 }
566
567 long kvmppc_h_bulk_remove(struct kvm_vcpu *vcpu)
568 {
569 struct kvm *kvm = vcpu->kvm;
570 unsigned long *args = &vcpu->arch.gpr[4];
571 __be64 *hp, *hptes[4];
572 unsigned long tlbrb[4];
573 long int i, j, k, n, found, indexes[4];
574 unsigned long flags, req, pte_index, rcbits;
575 int global;
576 long int ret = H_SUCCESS;
577 struct revmap_entry *rev, *revs[4];
578 u64 hp0, hp1;
579
580 if (kvm_is_radix(kvm))
581 return H_FUNCTION;
582 global = global_invalidates(kvm, 0);
583 for (i = 0; i < 4 && ret == H_SUCCESS; ) {
584 n = 0;
585 for (; i < 4; ++i) {
586 j = i * 2;
587 pte_index = args[j];
588 flags = pte_index >> 56;
589 pte_index &= ((1ul << 56) - 1);
590 req = flags >> 6;
591 flags &= 3;
592 if (req == 3) { /* no more requests */
593 i = 4;
594 break;
595 }
596 if (req != 1 || flags == 3 ||
597 pte_index >= kvmppc_hpt_npte(&kvm->arch.hpt)) {
598 /* parameter error */
599 args[j] = ((0xa0 | flags) << 56) + pte_index;
600 ret = H_PARAMETER;
601 break;
602 }
603 hp = (__be64 *) (kvm->arch.hpt.virt + (pte_index << 4));
604 /* to avoid deadlock, don't spin except for first */
605 if (!try_lock_hpte(hp, HPTE_V_HVLOCK)) {
606 if (n)
607 break;
608 while (!try_lock_hpte(hp, HPTE_V_HVLOCK))
609 cpu_relax();
610 }
611 found = 0;
612 hp0 = be64_to_cpu(hp[0]);
613 hp1 = be64_to_cpu(hp[1]);
614 if (cpu_has_feature(CPU_FTR_ARCH_300)) {
615 hp0 = hpte_new_to_old_v(hp0, hp1);
616 hp1 = hpte_new_to_old_r(hp1);
617 }
618 if (hp0 & (HPTE_V_ABSENT | HPTE_V_VALID)) {
619 switch (flags & 3) {
620 case 0: /* absolute */
621 found = 1;
622 break;
623 case 1: /* andcond */
624 if (!(hp0 & args[j + 1]))
625 found = 1;
626 break;
627 case 2: /* AVPN */
628 if ((hp0 & ~0x7fUL) == args[j + 1])
629 found = 1;
630 break;
631 }
632 }
633 if (!found) {
634 hp[0] &= ~cpu_to_be64(HPTE_V_HVLOCK);
635 args[j] = ((0x90 | flags) << 56) + pte_index;
636 continue;
637 }
638
639 args[j] = ((0x80 | flags) << 56) + pte_index;
640 rev = real_vmalloc_addr(&kvm->arch.hpt.rev[pte_index]);
641 note_hpte_modification(kvm, rev);
642
643 if (!(hp0 & HPTE_V_VALID)) {
644 /* insert R and C bits from PTE */
645 rcbits = rev->guest_rpte & (HPTE_R_R|HPTE_R_C);
646 args[j] |= rcbits << (56 - 5);
647 hp[0] = 0;
648 if (is_mmio_hpte(hp0, hp1))
649 atomic64_inc(&kvm->arch.mmio_update);
650 continue;
651 }
652
653 /* leave it locked */
654 hp[0] &= ~cpu_to_be64(HPTE_V_VALID);
655 tlbrb[n] = compute_tlbie_rb(hp0, hp1, pte_index);
656 indexes[n] = j;
657 hptes[n] = hp;
658 revs[n] = rev;
659 ++n;
660 }
661
662 if (!n)
663 break;
664
665 /* Now that we've collected a batch, do the tlbies */
666 do_tlbies(kvm, tlbrb, n, global, true);
667
668 /* Read PTE low words after tlbie to get final R/C values */
669 for (k = 0; k < n; ++k) {
670 j = indexes[k];
671 pte_index = args[j] & ((1ul << 56) - 1);
672 hp = hptes[k];
673 rev = revs[k];
674 remove_revmap_chain(kvm, pte_index, rev,
675 be64_to_cpu(hp[0]), be64_to_cpu(hp[1]));
676 rcbits = rev->guest_rpte & (HPTE_R_R|HPTE_R_C);
677 args[j] |= rcbits << (56 - 5);
678 __unlock_hpte(hp, 0);
679 }
680 }
681
682 return ret;
683 }
684
685 long kvmppc_h_protect(struct kvm_vcpu *vcpu, unsigned long flags,
686 unsigned long pte_index, unsigned long avpn,
687 unsigned long va)
688 {
689 struct kvm *kvm = vcpu->kvm;
690 __be64 *hpte;
691 struct revmap_entry *rev;
692 unsigned long v, r, rb, mask, bits;
693 u64 pte_v, pte_r;
694
695 if (kvm_is_radix(kvm))
696 return H_FUNCTION;
697 if (pte_index >= kvmppc_hpt_npte(&kvm->arch.hpt))
698 return H_PARAMETER;
699
700 hpte = (__be64 *)(kvm->arch.hpt.virt + (pte_index << 4));
701 while (!try_lock_hpte(hpte, HPTE_V_HVLOCK))
702 cpu_relax();
703 v = pte_v = be64_to_cpu(hpte[0]);
704 if (cpu_has_feature(CPU_FTR_ARCH_300))
705 v = hpte_new_to_old_v(v, be64_to_cpu(hpte[1]));
706 if ((v & (HPTE_V_ABSENT | HPTE_V_VALID)) == 0 ||
707 ((flags & H_AVPN) && (v & ~0x7fUL) != avpn)) {
708 __unlock_hpte(hpte, pte_v);
709 return H_NOT_FOUND;
710 }
711
712 pte_r = be64_to_cpu(hpte[1]);
713 bits = (flags << 55) & HPTE_R_PP0;
714 bits |= (flags << 48) & HPTE_R_KEY_HI;
715 bits |= flags & (HPTE_R_PP | HPTE_R_N | HPTE_R_KEY_LO);
716
717 /* Update guest view of 2nd HPTE dword */
718 mask = HPTE_R_PP0 | HPTE_R_PP | HPTE_R_N |
719 HPTE_R_KEY_HI | HPTE_R_KEY_LO;
720 rev = real_vmalloc_addr(&kvm->arch.hpt.rev[pte_index]);
721 if (rev) {
722 r = (rev->guest_rpte & ~mask) | bits;
723 rev->guest_rpte = r;
724 note_hpte_modification(kvm, rev);
725 }
726
727 /* Update HPTE */
728 if (v & HPTE_V_VALID) {
729 /*
730 * If the page is valid, don't let it transition from
731 * readonly to writable. If it should be writable, we'll
732 * take a trap and let the page fault code sort it out.
733 */
734 r = (pte_r & ~mask) | bits;
735 if (hpte_is_writable(r) && !hpte_is_writable(pte_r))
736 r = hpte_make_readonly(r);
737 /* If the PTE is changing, invalidate it first */
738 if (r != pte_r) {
739 rb = compute_tlbie_rb(v, r, pte_index);
740 hpte[0] = cpu_to_be64((pte_v & ~HPTE_V_VALID) |
741 HPTE_V_ABSENT);
742 do_tlbies(kvm, &rb, 1, global_invalidates(kvm, flags),
743 true);
744 /* Don't lose R/C bit updates done by hardware */
745 r |= be64_to_cpu(hpte[1]) & (HPTE_R_R | HPTE_R_C);
746 hpte[1] = cpu_to_be64(r);
747 }
748 }
749 unlock_hpte(hpte, pte_v & ~HPTE_V_HVLOCK);
750 asm volatile("ptesync" : : : "memory");
751 if (is_mmio_hpte(v, pte_r))
752 atomic64_inc(&kvm->arch.mmio_update);
753
754 return H_SUCCESS;
755 }
756
757 long kvmppc_h_read(struct kvm_vcpu *vcpu, unsigned long flags,
758 unsigned long pte_index)
759 {
760 struct kvm *kvm = vcpu->kvm;
761 __be64 *hpte;
762 unsigned long v, r;
763 int i, n = 1;
764 struct revmap_entry *rev = NULL;
765
766 if (kvm_is_radix(kvm))
767 return H_FUNCTION;
768 if (pte_index >= kvmppc_hpt_npte(&kvm->arch.hpt))
769 return H_PARAMETER;
770 if (flags & H_READ_4) {
771 pte_index &= ~3;
772 n = 4;
773 }
774 rev = real_vmalloc_addr(&kvm->arch.hpt.rev[pte_index]);
775 for (i = 0; i < n; ++i, ++pte_index) {
776 hpte = (__be64 *)(kvm->arch.hpt.virt + (pte_index << 4));
777 v = be64_to_cpu(hpte[0]) & ~HPTE_V_HVLOCK;
778 r = be64_to_cpu(hpte[1]);
779 if (cpu_has_feature(CPU_FTR_ARCH_300)) {
780 v = hpte_new_to_old_v(v, r);
781 r = hpte_new_to_old_r(r);
782 }
783 if (v & HPTE_V_ABSENT) {
784 v &= ~HPTE_V_ABSENT;
785 v |= HPTE_V_VALID;
786 }
787 if (v & HPTE_V_VALID) {
788 r = rev[i].guest_rpte | (r & (HPTE_R_R | HPTE_R_C));
789 r &= ~HPTE_GR_RESERVED;
790 }
791 vcpu->arch.gpr[4 + i * 2] = v;
792 vcpu->arch.gpr[5 + i * 2] = r;
793 }
794 return H_SUCCESS;
795 }
796
797 long kvmppc_h_clear_ref(struct kvm_vcpu *vcpu, unsigned long flags,
798 unsigned long pte_index)
799 {
800 struct kvm *kvm = vcpu->kvm;
801 __be64 *hpte;
802 unsigned long v, r, gr;
803 struct revmap_entry *rev;
804 unsigned long *rmap;
805 long ret = H_NOT_FOUND;
806
807 if (kvm_is_radix(kvm))
808 return H_FUNCTION;
809 if (pte_index >= kvmppc_hpt_npte(&kvm->arch.hpt))
810 return H_PARAMETER;
811
812 rev = real_vmalloc_addr(&kvm->arch.hpt.rev[pte_index]);
813 hpte = (__be64 *)(kvm->arch.hpt.virt + (pte_index << 4));
814 while (!try_lock_hpte(hpte, HPTE_V_HVLOCK))
815 cpu_relax();
816 v = be64_to_cpu(hpte[0]);
817 r = be64_to_cpu(hpte[1]);
818 if (!(v & (HPTE_V_VALID | HPTE_V_ABSENT)))
819 goto out;
820
821 gr = rev->guest_rpte;
822 if (rev->guest_rpte & HPTE_R_R) {
823 rev->guest_rpte &= ~HPTE_R_R;
824 note_hpte_modification(kvm, rev);
825 }
826 if (v & HPTE_V_VALID) {
827 gr |= r & (HPTE_R_R | HPTE_R_C);
828 if (r & HPTE_R_R) {
829 kvmppc_clear_ref_hpte(kvm, hpte, pte_index);
830 rmap = revmap_for_hpte(kvm, v, gr, NULL, NULL);
831 if (rmap) {
832 lock_rmap(rmap);
833 *rmap |= KVMPPC_RMAP_REFERENCED;
834 unlock_rmap(rmap);
835 }
836 }
837 }
838 vcpu->arch.gpr[4] = gr;
839 ret = H_SUCCESS;
840 out:
841 unlock_hpte(hpte, v & ~HPTE_V_HVLOCK);
842 return ret;
843 }
844
845 long kvmppc_h_clear_mod(struct kvm_vcpu *vcpu, unsigned long flags,
846 unsigned long pte_index)
847 {
848 struct kvm *kvm = vcpu->kvm;
849 __be64 *hpte;
850 unsigned long v, r, gr;
851 struct revmap_entry *rev;
852 long ret = H_NOT_FOUND;
853
854 if (kvm_is_radix(kvm))
855 return H_FUNCTION;
856 if (pte_index >= kvmppc_hpt_npte(&kvm->arch.hpt))
857 return H_PARAMETER;
858
859 rev = real_vmalloc_addr(&kvm->arch.hpt.rev[pte_index]);
860 hpte = (__be64 *)(kvm->arch.hpt.virt + (pte_index << 4));
861 while (!try_lock_hpte(hpte, HPTE_V_HVLOCK))
862 cpu_relax();
863 v = be64_to_cpu(hpte[0]);
864 r = be64_to_cpu(hpte[1]);
865 if (!(v & (HPTE_V_VALID | HPTE_V_ABSENT)))
866 goto out;
867
868 gr = rev->guest_rpte;
869 if (gr & HPTE_R_C) {
870 rev->guest_rpte &= ~HPTE_R_C;
871 note_hpte_modification(kvm, rev);
872 }
873 if (v & HPTE_V_VALID) {
874 /* need to make it temporarily absent so C is stable */
875 hpte[0] |= cpu_to_be64(HPTE_V_ABSENT);
876 kvmppc_invalidate_hpte(kvm, hpte, pte_index);
877 r = be64_to_cpu(hpte[1]);
878 gr |= r & (HPTE_R_R | HPTE_R_C);
879 if (r & HPTE_R_C) {
880 hpte[1] = cpu_to_be64(r & ~HPTE_R_C);
881 eieio();
882 kvmppc_set_dirty_from_hpte(kvm, v, gr);
883 }
884 }
885 vcpu->arch.gpr[4] = gr;
886 ret = H_SUCCESS;
887 out:
888 unlock_hpte(hpte, v & ~HPTE_V_HVLOCK);
889 return ret;
890 }
891
892 void kvmppc_invalidate_hpte(struct kvm *kvm, __be64 *hptep,
893 unsigned long pte_index)
894 {
895 unsigned long rb;
896 u64 hp0, hp1;
897
898 hptep[0] &= ~cpu_to_be64(HPTE_V_VALID);
899 hp0 = be64_to_cpu(hptep[0]);
900 hp1 = be64_to_cpu(hptep[1]);
901 if (cpu_has_feature(CPU_FTR_ARCH_300)) {
902 hp0 = hpte_new_to_old_v(hp0, hp1);
903 hp1 = hpte_new_to_old_r(hp1);
904 }
905 rb = compute_tlbie_rb(hp0, hp1, pte_index);
906 do_tlbies(kvm, &rb, 1, 1, true);
907 }
908 EXPORT_SYMBOL_GPL(kvmppc_invalidate_hpte);
909
910 void kvmppc_clear_ref_hpte(struct kvm *kvm, __be64 *hptep,
911 unsigned long pte_index)
912 {
913 unsigned long rb;
914 unsigned char rbyte;
915 u64 hp0, hp1;
916
917 hp0 = be64_to_cpu(hptep[0]);
918 hp1 = be64_to_cpu(hptep[1]);
919 if (cpu_has_feature(CPU_FTR_ARCH_300)) {
920 hp0 = hpte_new_to_old_v(hp0, hp1);
921 hp1 = hpte_new_to_old_r(hp1);
922 }
923 rb = compute_tlbie_rb(hp0, hp1, pte_index);
924 rbyte = (be64_to_cpu(hptep[1]) & ~HPTE_R_R) >> 8;
925 /* modify only the second-last byte, which contains the ref bit */
926 *((char *)hptep + 14) = rbyte;
927 do_tlbies(kvm, &rb, 1, 1, false);
928 }
929 EXPORT_SYMBOL_GPL(kvmppc_clear_ref_hpte);
930
931 static int slb_base_page_shift[4] = {
932 24, /* 16M */
933 16, /* 64k */
934 34, /* 16G */
935 20, /* 1M, unsupported */
936 };
937
938 static struct mmio_hpte_cache_entry *mmio_cache_search(struct kvm_vcpu *vcpu,
939 unsigned long eaddr, unsigned long slb_v, long mmio_update)
940 {
941 struct mmio_hpte_cache_entry *entry = NULL;
942 unsigned int pshift;
943 unsigned int i;
944
945 for (i = 0; i < MMIO_HPTE_CACHE_SIZE; i++) {
946 entry = &vcpu->arch.mmio_cache.entry[i];
947 if (entry->mmio_update == mmio_update) {
948 pshift = entry->slb_base_pshift;
949 if ((entry->eaddr >> pshift) == (eaddr >> pshift) &&
950 entry->slb_v == slb_v)
951 return entry;
952 }
953 }
954 return NULL;
955 }
956
957 static struct mmio_hpte_cache_entry *
958 next_mmio_cache_entry(struct kvm_vcpu *vcpu)
959 {
960 unsigned int index = vcpu->arch.mmio_cache.index;
961
962 vcpu->arch.mmio_cache.index++;
963 if (vcpu->arch.mmio_cache.index == MMIO_HPTE_CACHE_SIZE)
964 vcpu->arch.mmio_cache.index = 0;
965
966 return &vcpu->arch.mmio_cache.entry[index];
967 }
968
969 /* When called from virtmode, this func should be protected by
970 * preempt_disable(), otherwise, the holding of HPTE_V_HVLOCK
971 * can trigger deadlock issue.
972 */
973 long kvmppc_hv_find_lock_hpte(struct kvm *kvm, gva_t eaddr, unsigned long slb_v,
974 unsigned long valid)
975 {
976 unsigned int i;
977 unsigned int pshift;
978 unsigned long somask;
979 unsigned long vsid, hash;
980 unsigned long avpn;
981 __be64 *hpte;
982 unsigned long mask, val;
983 unsigned long v, r, orig_v;
984
985 /* Get page shift, work out hash and AVPN etc. */
986 mask = SLB_VSID_B | HPTE_V_AVPN | HPTE_V_SECONDARY;
987 val = 0;
988 pshift = 12;
989 if (slb_v & SLB_VSID_L) {
990 mask |= HPTE_V_LARGE;
991 val |= HPTE_V_LARGE;
992 pshift = slb_base_page_shift[(slb_v & SLB_VSID_LP) >> 4];
993 }
994 if (slb_v & SLB_VSID_B_1T) {
995 somask = (1UL << 40) - 1;
996 vsid = (slb_v & ~SLB_VSID_B) >> SLB_VSID_SHIFT_1T;
997 vsid ^= vsid << 25;
998 } else {
999 somask = (1UL << 28) - 1;
1000 vsid = (slb_v & ~SLB_VSID_B) >> SLB_VSID_SHIFT;
1001 }
1002 hash = (vsid ^ ((eaddr & somask) >> pshift)) & kvmppc_hpt_mask(&kvm->arch.hpt);
1003 avpn = slb_v & ~(somask >> 16); /* also includes B */
1004 avpn |= (eaddr & somask) >> 16;
1005
1006 if (pshift >= 24)
1007 avpn &= ~((1UL << (pshift - 16)) - 1);
1008 else
1009 avpn &= ~0x7fUL;
1010 val |= avpn;
1011
1012 for (;;) {
1013 hpte = (__be64 *)(kvm->arch.hpt.virt + (hash << 7));
1014
1015 for (i = 0; i < 16; i += 2) {
1016 /* Read the PTE racily */
1017 v = be64_to_cpu(hpte[i]) & ~HPTE_V_HVLOCK;
1018 if (cpu_has_feature(CPU_FTR_ARCH_300))
1019 v = hpte_new_to_old_v(v, be64_to_cpu(hpte[i+1]));
1020
1021 /* Check valid/absent, hash, segment size and AVPN */
1022 if (!(v & valid) || (v & mask) != val)
1023 continue;
1024
1025 /* Lock the PTE and read it under the lock */
1026 while (!try_lock_hpte(&hpte[i], HPTE_V_HVLOCK))
1027 cpu_relax();
1028 v = orig_v = be64_to_cpu(hpte[i]) & ~HPTE_V_HVLOCK;
1029 r = be64_to_cpu(hpte[i+1]);
1030 if (cpu_has_feature(CPU_FTR_ARCH_300)) {
1031 v = hpte_new_to_old_v(v, r);
1032 r = hpte_new_to_old_r(r);
1033 }
1034
1035 /*
1036 * Check the HPTE again, including base page size
1037 */
1038 if ((v & valid) && (v & mask) == val &&
1039 kvmppc_hpte_base_page_shift(v, r) == pshift)
1040 /* Return with the HPTE still locked */
1041 return (hash << 3) + (i >> 1);
1042
1043 __unlock_hpte(&hpte[i], orig_v);
1044 }
1045
1046 if (val & HPTE_V_SECONDARY)
1047 break;
1048 val |= HPTE_V_SECONDARY;
1049 hash = hash ^ kvmppc_hpt_mask(&kvm->arch.hpt);
1050 }
1051 return -1;
1052 }
1053 EXPORT_SYMBOL(kvmppc_hv_find_lock_hpte);
1054
1055 /*
1056 * Called in real mode to check whether an HPTE not found fault
1057 * is due to accessing a paged-out page or an emulated MMIO page,
1058 * or if a protection fault is due to accessing a page that the
1059 * guest wanted read/write access to but which we made read-only.
1060 * Returns a possibly modified status (DSISR) value if not
1061 * (i.e. pass the interrupt to the guest),
1062 * -1 to pass the fault up to host kernel mode code, -2 to do that
1063 * and also load the instruction word (for MMIO emulation),
1064 * or 0 if we should make the guest retry the access.
1065 */
1066 long kvmppc_hpte_hv_fault(struct kvm_vcpu *vcpu, unsigned long addr,
1067 unsigned long slb_v, unsigned int status, bool data)
1068 {
1069 struct kvm *kvm = vcpu->kvm;
1070 long int index;
1071 unsigned long v, r, gr, orig_v;
1072 __be64 *hpte;
1073 unsigned long valid;
1074 struct revmap_entry *rev;
1075 unsigned long pp, key;
1076 struct mmio_hpte_cache_entry *cache_entry = NULL;
1077 long mmio_update = 0;
1078
1079 /* For protection fault, expect to find a valid HPTE */
1080 valid = HPTE_V_VALID;
1081 if (status & DSISR_NOHPTE) {
1082 valid |= HPTE_V_ABSENT;
1083 mmio_update = atomic64_read(&kvm->arch.mmio_update);
1084 cache_entry = mmio_cache_search(vcpu, addr, slb_v, mmio_update);
1085 }
1086 if (cache_entry) {
1087 index = cache_entry->pte_index;
1088 v = cache_entry->hpte_v;
1089 r = cache_entry->hpte_r;
1090 gr = cache_entry->rpte;
1091 } else {
1092 index = kvmppc_hv_find_lock_hpte(kvm, addr, slb_v, valid);
1093 if (index < 0) {
1094 if (status & DSISR_NOHPTE)
1095 return status; /* there really was no HPTE */
1096 return 0; /* for prot fault, HPTE disappeared */
1097 }
1098 hpte = (__be64 *)(kvm->arch.hpt.virt + (index << 4));
1099 v = orig_v = be64_to_cpu(hpte[0]) & ~HPTE_V_HVLOCK;
1100 r = be64_to_cpu(hpte[1]);
1101 if (cpu_has_feature(CPU_FTR_ARCH_300)) {
1102 v = hpte_new_to_old_v(v, r);
1103 r = hpte_new_to_old_r(r);
1104 }
1105 rev = real_vmalloc_addr(&kvm->arch.hpt.rev[index]);
1106 gr = rev->guest_rpte;
1107
1108 unlock_hpte(hpte, orig_v);
1109 }
1110
1111 /* For not found, if the HPTE is valid by now, retry the instruction */
1112 if ((status & DSISR_NOHPTE) && (v & HPTE_V_VALID))
1113 return 0;
1114
1115 /* Check access permissions to the page */
1116 pp = gr & (HPTE_R_PP0 | HPTE_R_PP);
1117 key = (vcpu->arch.shregs.msr & MSR_PR) ? SLB_VSID_KP : SLB_VSID_KS;
1118 status &= ~DSISR_NOHPTE; /* DSISR_NOHPTE == SRR1_ISI_NOPT */
1119 if (!data) {
1120 if (gr & (HPTE_R_N | HPTE_R_G))
1121 return status | SRR1_ISI_N_OR_G;
1122 if (!hpte_read_permission(pp, slb_v & key))
1123 return status | SRR1_ISI_PROT;
1124 } else if (status & DSISR_ISSTORE) {
1125 /* check write permission */
1126 if (!hpte_write_permission(pp, slb_v & key))
1127 return status | DSISR_PROTFAULT;
1128 } else {
1129 if (!hpte_read_permission(pp, slb_v & key))
1130 return status | DSISR_PROTFAULT;
1131 }
1132
1133 /* Check storage key, if applicable */
1134 if (data && (vcpu->arch.shregs.msr & MSR_DR)) {
1135 unsigned int perm = hpte_get_skey_perm(gr, vcpu->arch.amr);
1136 if (status & DSISR_ISSTORE)
1137 perm >>= 1;
1138 if (perm & 1)
1139 return status | DSISR_KEYFAULT;
1140 }
1141
1142 /* Save HPTE info for virtual-mode handler */
1143 vcpu->arch.pgfault_addr = addr;
1144 vcpu->arch.pgfault_index = index;
1145 vcpu->arch.pgfault_hpte[0] = v;
1146 vcpu->arch.pgfault_hpte[1] = r;
1147 vcpu->arch.pgfault_cache = cache_entry;
1148
1149 /* Check the storage key to see if it is possibly emulated MMIO */
1150 if ((r & (HPTE_R_KEY_HI | HPTE_R_KEY_LO)) ==
1151 (HPTE_R_KEY_HI | HPTE_R_KEY_LO)) {
1152 if (!cache_entry) {
1153 unsigned int pshift = 12;
1154 unsigned int pshift_index;
1155
1156 if (slb_v & SLB_VSID_L) {
1157 pshift_index = ((slb_v & SLB_VSID_LP) >> 4);
1158 pshift = slb_base_page_shift[pshift_index];
1159 }
1160 cache_entry = next_mmio_cache_entry(vcpu);
1161 cache_entry->eaddr = addr;
1162 cache_entry->slb_base_pshift = pshift;
1163 cache_entry->pte_index = index;
1164 cache_entry->hpte_v = v;
1165 cache_entry->hpte_r = r;
1166 cache_entry->rpte = gr;
1167 cache_entry->slb_v = slb_v;
1168 cache_entry->mmio_update = mmio_update;
1169 }
1170 if (data && (vcpu->arch.shregs.msr & MSR_IR))
1171 return -2; /* MMIO emulation - load instr word */
1172 }
1173
1174 return -1; /* send fault up to host kernel mode */
1175 }