1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corporation, 2018
4 * Authors Suraj Jitindar Singh <sjitindarsingh@gmail.com>
5 * Paul Mackerras <paulus@ozlabs.org>
7 * Description: KVM functions specific to running nested KVM-HV guests
8 * on Book3S processors (specifically POWER9 and later).
11 #include <linux/kernel.h>
12 #include <linux/kvm_host.h>
13 #include <linux/llist.h>
15 #include <asm/kvm_ppc.h>
16 #include <asm/kvm_book3s.h>
18 #include <asm/pgtable.h>
19 #include <asm/pgalloc.h>
20 #include <asm/pte-walk.h>
23 static struct patb_entry *pseries_partition_tb;
25 static void kvmhv_update_ptbl_cache(struct kvm_nested_guest *gp);
26 static void kvmhv_free_memslot_nest_rmap(struct kvm_memory_slot *free);
28 void kvmhv_save_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state *hr)
30 struct kvmppc_vcore *vc = vcpu->arch.vcore;
32 hr->pcr = vc->pcr | PCR_MASK;
33 hr->dpdes = vc->dpdes;
34 hr->hfscr = vcpu->arch.hfscr;
35 hr->tb_offset = vc->tb_offset;
36 hr->dawr0 = vcpu->arch.dawr;
37 hr->dawrx0 = vcpu->arch.dawrx;
38 hr->ciabr = vcpu->arch.ciabr;
39 hr->purr = vcpu->arch.purr;
40 hr->spurr = vcpu->arch.spurr;
41 hr->ic = vcpu->arch.ic;
43 hr->srr0 = vcpu->arch.shregs.srr0;
44 hr->srr1 = vcpu->arch.shregs.srr1;
45 hr->sprg[0] = vcpu->arch.shregs.sprg0;
46 hr->sprg[1] = vcpu->arch.shregs.sprg1;
47 hr->sprg[2] = vcpu->arch.shregs.sprg2;
48 hr->sprg[3] = vcpu->arch.shregs.sprg3;
49 hr->pidr = vcpu->arch.pid;
50 hr->cfar = vcpu->arch.cfar;
51 hr->ppr = vcpu->arch.ppr;
54 /* Use noinline_for_stack due to https://bugs.llvm.org/show_bug.cgi?id=49610 */
55 static noinline_for_stack void byteswap_pt_regs(struct pt_regs *regs)
57 unsigned long *addr = (unsigned long *) regs;
59 for (; addr < ((unsigned long *) (regs + 1)); addr++)
60 *addr = swab64(*addr);
63 static void byteswap_hv_regs(struct hv_guest_state *hr)
65 hr->version = swab64(hr->version);
66 hr->lpid = swab32(hr->lpid);
67 hr->vcpu_token = swab32(hr->vcpu_token);
68 hr->lpcr = swab64(hr->lpcr);
69 hr->pcr = swab64(hr->pcr) | PCR_MASK;
70 hr->amor = swab64(hr->amor);
71 hr->dpdes = swab64(hr->dpdes);
72 hr->hfscr = swab64(hr->hfscr);
73 hr->tb_offset = swab64(hr->tb_offset);
74 hr->dawr0 = swab64(hr->dawr0);
75 hr->dawrx0 = swab64(hr->dawrx0);
76 hr->ciabr = swab64(hr->ciabr);
77 hr->hdec_expiry = swab64(hr->hdec_expiry);
78 hr->purr = swab64(hr->purr);
79 hr->spurr = swab64(hr->spurr);
80 hr->ic = swab64(hr->ic);
81 hr->vtb = swab64(hr->vtb);
82 hr->hdar = swab64(hr->hdar);
83 hr->hdsisr = swab64(hr->hdsisr);
84 hr->heir = swab64(hr->heir);
85 hr->asdr = swab64(hr->asdr);
86 hr->srr0 = swab64(hr->srr0);
87 hr->srr1 = swab64(hr->srr1);
88 hr->sprg[0] = swab64(hr->sprg[0]);
89 hr->sprg[1] = swab64(hr->sprg[1]);
90 hr->sprg[2] = swab64(hr->sprg[2]);
91 hr->sprg[3] = swab64(hr->sprg[3]);
92 hr->pidr = swab64(hr->pidr);
93 hr->cfar = swab64(hr->cfar);
94 hr->ppr = swab64(hr->ppr);
97 static void save_hv_return_state(struct kvm_vcpu *vcpu, int trap,
98 struct hv_guest_state *hr)
100 struct kvmppc_vcore *vc = vcpu->arch.vcore;
102 hr->dpdes = vc->dpdes;
103 hr->hfscr = vcpu->arch.hfscr;
104 hr->purr = vcpu->arch.purr;
105 hr->spurr = vcpu->arch.spurr;
106 hr->ic = vcpu->arch.ic;
108 hr->srr0 = vcpu->arch.shregs.srr0;
109 hr->srr1 = vcpu->arch.shregs.srr1;
110 hr->sprg[0] = vcpu->arch.shregs.sprg0;
111 hr->sprg[1] = vcpu->arch.shregs.sprg1;
112 hr->sprg[2] = vcpu->arch.shregs.sprg2;
113 hr->sprg[3] = vcpu->arch.shregs.sprg3;
114 hr->pidr = vcpu->arch.pid;
115 hr->cfar = vcpu->arch.cfar;
116 hr->ppr = vcpu->arch.ppr;
118 case BOOK3S_INTERRUPT_H_DATA_STORAGE:
119 hr->hdar = vcpu->arch.fault_dar;
120 hr->hdsisr = vcpu->arch.fault_dsisr;
121 hr->asdr = vcpu->arch.fault_gpa;
123 case BOOK3S_INTERRUPT_H_INST_STORAGE:
124 hr->asdr = vcpu->arch.fault_gpa;
126 case BOOK3S_INTERRUPT_H_EMUL_ASSIST:
127 hr->heir = vcpu->arch.emul_inst;
132 static void sanitise_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state *hr)
135 * Don't let L1 enable features for L2 which we've disabled for L1,
136 * but preserve the interrupt cause field.
138 hr->hfscr &= (HFSCR_INTR_CAUSE | vcpu->arch.hfscr);
140 /* Don't let data address watchpoint match in hypervisor state */
141 hr->dawrx0 &= ~DAWRX_HYP;
143 /* Don't let completed instruction address breakpt match in HV state */
144 if ((hr->ciabr & CIABR_PRIV) == CIABR_PRIV_HYPER)
145 hr->ciabr &= ~CIABR_PRIV;
148 static void restore_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state *hr)
150 struct kvmppc_vcore *vc = vcpu->arch.vcore;
152 vc->pcr = hr->pcr | PCR_MASK;
153 vc->dpdes = hr->dpdes;
154 vcpu->arch.hfscr = hr->hfscr;
155 vcpu->arch.dawr = hr->dawr0;
156 vcpu->arch.dawrx = hr->dawrx0;
157 vcpu->arch.ciabr = hr->ciabr;
158 vcpu->arch.purr = hr->purr;
159 vcpu->arch.spurr = hr->spurr;
160 vcpu->arch.ic = hr->ic;
162 vcpu->arch.shregs.srr0 = hr->srr0;
163 vcpu->arch.shregs.srr1 = hr->srr1;
164 vcpu->arch.shregs.sprg0 = hr->sprg[0];
165 vcpu->arch.shregs.sprg1 = hr->sprg[1];
166 vcpu->arch.shregs.sprg2 = hr->sprg[2];
167 vcpu->arch.shregs.sprg3 = hr->sprg[3];
168 vcpu->arch.pid = hr->pidr;
169 vcpu->arch.cfar = hr->cfar;
170 vcpu->arch.ppr = hr->ppr;
173 void kvmhv_restore_hv_return_state(struct kvm_vcpu *vcpu,
174 struct hv_guest_state *hr)
176 struct kvmppc_vcore *vc = vcpu->arch.vcore;
178 vc->dpdes = hr->dpdes;
179 vcpu->arch.hfscr = hr->hfscr;
180 vcpu->arch.purr = hr->purr;
181 vcpu->arch.spurr = hr->spurr;
182 vcpu->arch.ic = hr->ic;
184 vcpu->arch.fault_dar = hr->hdar;
185 vcpu->arch.fault_dsisr = hr->hdsisr;
186 vcpu->arch.fault_gpa = hr->asdr;
187 vcpu->arch.emul_inst = hr->heir;
188 vcpu->arch.shregs.srr0 = hr->srr0;
189 vcpu->arch.shregs.srr1 = hr->srr1;
190 vcpu->arch.shregs.sprg0 = hr->sprg[0];
191 vcpu->arch.shregs.sprg1 = hr->sprg[1];
192 vcpu->arch.shregs.sprg2 = hr->sprg[2];
193 vcpu->arch.shregs.sprg3 = hr->sprg[3];
194 vcpu->arch.pid = hr->pidr;
195 vcpu->arch.cfar = hr->cfar;
196 vcpu->arch.ppr = hr->ppr;
199 static void kvmhv_nested_mmio_needed(struct kvm_vcpu *vcpu, u64 regs_ptr)
201 /* No need to reflect the page fault to L1, we've handled it */
205 * Since the L2 gprs have already been written back into L1 memory when
206 * we complete the mmio, store the L1 memory location of the L2 gpr
207 * being loaded into by the mmio so that the loaded value can be
208 * written there in kvmppc_complete_mmio_load()
210 if (((vcpu->arch.io_gpr & KVM_MMIO_REG_EXT_MASK) == KVM_MMIO_REG_GPR)
211 && (vcpu->mmio_is_write == 0)) {
212 vcpu->arch.nested_io_gpr = (gpa_t) regs_ptr +
213 offsetof(struct pt_regs,
214 gpr[vcpu->arch.io_gpr]);
215 vcpu->arch.io_gpr = KVM_MMIO_REG_NESTED_GPR;
219 long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu)
222 struct kvm_nested_guest *l2;
223 struct pt_regs l2_regs, saved_l1_regs;
224 struct hv_guest_state l2_hv, saved_l1_hv;
225 struct kvmppc_vcore *vc = vcpu->arch.vcore;
226 u64 hv_ptr, regs_ptr;
228 s64 delta_purr, delta_spurr, delta_ic, delta_vtb;
232 if (vcpu->kvm->arch.l1_ptcr == 0)
233 return H_NOT_AVAILABLE;
235 if (MSR_TM_TRANSACTIONAL(vcpu->arch.shregs.msr))
238 /* copy parameters in */
239 hv_ptr = kvmppc_get_gpr(vcpu, 4);
240 err = kvm_vcpu_read_guest(vcpu, hv_ptr, &l2_hv,
241 sizeof(struct hv_guest_state));
244 if (kvmppc_need_byteswap(vcpu))
245 byteswap_hv_regs(&l2_hv);
246 if (l2_hv.version != HV_GUEST_STATE_VERSION)
249 regs_ptr = kvmppc_get_gpr(vcpu, 5);
250 err = kvm_vcpu_read_guest(vcpu, regs_ptr, &l2_regs,
251 sizeof(struct pt_regs));
254 if (kvmppc_need_byteswap(vcpu))
255 byteswap_pt_regs(&l2_regs);
256 if (l2_hv.vcpu_token >= NR_CPUS)
260 * L1 must have set up a suspended state to enter the L2 in a
261 * transactional state, and only in that case. These have to be
262 * filtered out here to prevent causing a TM Bad Thing in the
263 * host HRFID. We could synthesize a TM Bad Thing back to the L1
264 * here but there doesn't seem like much point.
266 if (MSR_TM_SUSPENDED(vcpu->arch.shregs.msr)) {
267 if (!MSR_TM_ACTIVE(l2_regs.msr))
270 if (l2_regs.msr & MSR_TS_MASK)
272 if (WARN_ON_ONCE(vcpu->arch.shregs.msr & MSR_TS_MASK))
277 l2 = kvmhv_get_nested(vcpu->kvm, l2_hv.lpid, true);
280 if (!l2->l1_gr_to_hr) {
281 mutex_lock(&l2->tlb_lock);
282 kvmhv_update_ptbl_cache(l2);
283 mutex_unlock(&l2->tlb_lock);
286 /* save l1 values of things */
287 vcpu->arch.regs.msr = vcpu->arch.shregs.msr;
288 saved_l1_regs = vcpu->arch.regs;
289 kvmhv_save_hv_regs(vcpu, &saved_l1_hv);
291 /* convert TB values/offsets to host (L0) values */
292 hdec_exp = l2_hv.hdec_expiry - vc->tb_offset;
293 vc->tb_offset += l2_hv.tb_offset;
295 /* set L1 state to L2 state */
296 vcpu->arch.nested = l2;
297 vcpu->arch.nested_vcpu_id = l2_hv.vcpu_token;
298 vcpu->arch.regs = l2_regs;
299 vcpu->arch.shregs.msr = vcpu->arch.regs.msr;
300 mask = LPCR_DPFD | LPCR_ILE | LPCR_TC | LPCR_AIL | LPCR_LD |
301 LPCR_LPES | LPCR_MER;
302 lpcr = (vc->lpcr & ~mask) | (l2_hv.lpcr & mask);
303 sanitise_hv_regs(vcpu, &l2_hv);
304 restore_hv_regs(vcpu, &l2_hv);
306 vcpu->arch.ret = RESUME_GUEST;
309 if (mftb() >= hdec_exp) {
310 vcpu->arch.trap = BOOK3S_INTERRUPT_HV_DECREMENTER;
314 r = kvmhv_run_single_vcpu(vcpu->arch.kvm_run, vcpu, hdec_exp,
316 } while (is_kvmppc_resume_guest(r));
318 /* save L2 state for return */
319 l2_regs = vcpu->arch.regs;
320 l2_regs.msr = vcpu->arch.shregs.msr;
321 delta_purr = vcpu->arch.purr - l2_hv.purr;
322 delta_spurr = vcpu->arch.spurr - l2_hv.spurr;
323 delta_ic = vcpu->arch.ic - l2_hv.ic;
324 delta_vtb = vc->vtb - l2_hv.vtb;
325 save_hv_return_state(vcpu, vcpu->arch.trap, &l2_hv);
327 /* restore L1 state */
328 vcpu->arch.nested = NULL;
329 vcpu->arch.regs = saved_l1_regs;
330 vcpu->arch.shregs.msr = saved_l1_regs.msr & ~MSR_TS_MASK;
331 /* set L1 MSR TS field according to L2 transaction state */
332 if (l2_regs.msr & MSR_TS_MASK)
333 vcpu->arch.shregs.msr |= MSR_TS_S;
334 vc->tb_offset = saved_l1_hv.tb_offset;
335 restore_hv_regs(vcpu, &saved_l1_hv);
336 vcpu->arch.purr += delta_purr;
337 vcpu->arch.spurr += delta_spurr;
338 vcpu->arch.ic += delta_ic;
339 vc->vtb += delta_vtb;
341 kvmhv_put_nested(l2);
343 /* copy l2_hv_state and regs back to guest */
344 if (kvmppc_need_byteswap(vcpu)) {
345 byteswap_hv_regs(&l2_hv);
346 byteswap_pt_regs(&l2_regs);
348 err = kvm_vcpu_write_guest(vcpu, hv_ptr, &l2_hv,
349 sizeof(struct hv_guest_state));
352 err = kvm_vcpu_write_guest(vcpu, regs_ptr, &l2_regs,
353 sizeof(struct pt_regs));
360 if (vcpu->mmio_needed) {
361 kvmhv_nested_mmio_needed(vcpu, regs_ptr);
365 return vcpu->arch.trap;
368 long kvmhv_nested_init(void)
374 if (!kvmhv_on_pseries())
376 if (!radix_enabled())
379 /* find log base 2 of KVMPPC_NR_LPIDS, rounding up */
380 ptb_order = __ilog2(KVMPPC_NR_LPIDS - 1) + 1;
383 pseries_partition_tb = kmalloc(sizeof(struct patb_entry) << ptb_order,
385 if (!pseries_partition_tb) {
386 pr_err("kvm-hv: failed to allocated nested partition table\n");
390 ptcr = __pa(pseries_partition_tb) | (ptb_order - 8);
391 rc = plpar_hcall_norets(H_SET_PARTITION_TABLE, ptcr);
392 if (rc != H_SUCCESS) {
393 pr_err("kvm-hv: Parent hypervisor does not support nesting (rc=%ld)\n",
395 kfree(pseries_partition_tb);
396 pseries_partition_tb = NULL;
403 void kvmhv_nested_exit(void)
406 * N.B. the kvmhv_on_pseries() test is there because it enables
407 * the compiler to remove the call to plpar_hcall_norets()
408 * when CONFIG_PPC_PSERIES=n.
410 if (kvmhv_on_pseries() && pseries_partition_tb) {
411 plpar_hcall_norets(H_SET_PARTITION_TABLE, 0);
412 kfree(pseries_partition_tb);
413 pseries_partition_tb = NULL;
417 static void kvmhv_flush_lpid(unsigned int lpid)
421 if (!kvmhv_on_pseries()) {
422 radix__flush_all_lpid(lpid);
426 rc = plpar_hcall_norets(H_TLB_INVALIDATE, H_TLBIE_P1_ENC(2, 0, 1),
427 lpid, TLBIEL_INVAL_SET_LPID);
429 pr_err("KVM: TLB LPID invalidation hcall failed, rc=%ld\n", rc);
432 void kvmhv_set_ptbl_entry(unsigned int lpid, u64 dw0, u64 dw1)
434 if (!kvmhv_on_pseries()) {
435 mmu_partition_table_set_entry(lpid, dw0, dw1, true);
439 pseries_partition_tb[lpid].patb0 = cpu_to_be64(dw0);
440 pseries_partition_tb[lpid].patb1 = cpu_to_be64(dw1);
441 /* L0 will do the necessary barriers */
442 kvmhv_flush_lpid(lpid);
445 static void kvmhv_set_nested_ptbl(struct kvm_nested_guest *gp)
449 dw0 = PATB_HR | radix__get_tree_size() |
450 __pa(gp->shadow_pgtable) | RADIX_PGD_INDEX_SIZE;
451 kvmhv_set_ptbl_entry(gp->shadow_lpid, dw0, gp->process_table);
454 void kvmhv_vm_nested_init(struct kvm *kvm)
456 kvm->arch.max_nested_lpid = -1;
460 * Handle the H_SET_PARTITION_TABLE hcall.
461 * r4 = guest real address of partition table + log_2(size) - 12
462 * (formatted as for the PTCR).
464 long kvmhv_set_partition_table(struct kvm_vcpu *vcpu)
466 struct kvm *kvm = vcpu->kvm;
467 unsigned long ptcr = kvmppc_get_gpr(vcpu, 4);
469 long ret = H_SUCCESS;
471 srcu_idx = srcu_read_lock(&kvm->srcu);
473 * Limit the partition table to 4096 entries (because that's what
474 * hardware supports), and check the base address.
476 if ((ptcr & PRTS_MASK) > 12 - 8 ||
477 !kvm_is_visible_gfn(vcpu->kvm, (ptcr & PRTB_MASK) >> PAGE_SHIFT))
479 srcu_read_unlock(&kvm->srcu, srcu_idx);
480 if (ret == H_SUCCESS)
481 kvm->arch.l1_ptcr = ptcr;
486 * Handle the H_COPY_TOFROM_GUEST hcall.
487 * r4 = L1 lpid of nested guest
489 * r6 = eaddr to access
490 * r7 = to buffer (L1 gpa)
491 * r8 = from buffer (L1 gpa)
492 * r9 = n bytes to copy
494 long kvmhv_copy_tofrom_guest_nested(struct kvm_vcpu *vcpu)
496 struct kvm_nested_guest *gp;
497 int l1_lpid = kvmppc_get_gpr(vcpu, 4);
498 int pid = kvmppc_get_gpr(vcpu, 5);
499 gva_t eaddr = kvmppc_get_gpr(vcpu, 6);
500 gpa_t gp_to = (gpa_t) kvmppc_get_gpr(vcpu, 7);
501 gpa_t gp_from = (gpa_t) kvmppc_get_gpr(vcpu, 8);
503 unsigned long n = kvmppc_get_gpr(vcpu, 9);
504 bool is_load = !!gp_to;
507 if (gp_to && gp_from) /* One must be NULL to determine the direction */
510 if (eaddr & (0xFFFUL << 52))
513 buf = kzalloc(n, GFP_KERNEL | __GFP_NOWARN);
517 gp = kvmhv_get_nested(vcpu->kvm, l1_lpid, false);
523 mutex_lock(&gp->tlb_lock);
526 /* Load from the nested guest into our buffer */
527 rc = __kvmhv_copy_tofrom_guest_radix(gp->shadow_lpid, pid,
528 eaddr, buf, NULL, n);
532 /* Write what was loaded into our buffer back to the L1 guest */
533 rc = kvm_vcpu_write_guest(vcpu, gp_to, buf, n);
537 /* Load the data to be stored from the L1 guest into our buf */
538 rc = kvm_vcpu_read_guest(vcpu, gp_from, buf, n);
542 /* Store from our buffer into the nested guest */
543 rc = __kvmhv_copy_tofrom_guest_radix(gp->shadow_lpid, pid,
544 eaddr, NULL, buf, n);
550 mutex_unlock(&gp->tlb_lock);
551 kvmhv_put_nested(gp);
561 * Reload the partition table entry for a guest.
562 * Caller must hold gp->tlb_lock.
564 static void kvmhv_update_ptbl_cache(struct kvm_nested_guest *gp)
567 struct patb_entry ptbl_entry;
568 unsigned long ptbl_addr;
569 struct kvm *kvm = gp->l1_host;
572 ptbl_addr = (kvm->arch.l1_ptcr & PRTB_MASK) + (gp->l1_lpid << 4);
573 if (gp->l1_lpid < (1ul << ((kvm->arch.l1_ptcr & PRTS_MASK) + 8)))
574 ret = kvm_read_guest(kvm, ptbl_addr,
575 &ptbl_entry, sizeof(ptbl_entry));
578 gp->process_table = 0;
580 gp->l1_gr_to_hr = be64_to_cpu(ptbl_entry.patb0);
581 gp->process_table = be64_to_cpu(ptbl_entry.patb1);
583 kvmhv_set_nested_ptbl(gp);
586 struct kvm_nested_guest *kvmhv_alloc_nested(struct kvm *kvm, unsigned int lpid)
588 struct kvm_nested_guest *gp;
591 gp = kzalloc(sizeof(*gp), GFP_KERNEL);
596 mutex_init(&gp->tlb_lock);
597 gp->shadow_pgtable = pgd_alloc(kvm->mm);
598 if (!gp->shadow_pgtable)
600 shadow_lpid = kvmppc_alloc_lpid();
603 gp->shadow_lpid = shadow_lpid;
606 memset(gp->prev_cpu, -1, sizeof(gp->prev_cpu));
611 pgd_free(kvm->mm, gp->shadow_pgtable);
618 * Free up any resources allocated for a nested guest.
620 static void kvmhv_release_nested(struct kvm_nested_guest *gp)
622 struct kvm *kvm = gp->l1_host;
624 if (gp->shadow_pgtable) {
626 * No vcpu is using this struct and no call to
627 * kvmhv_get_nested can find this struct,
628 * so we don't need to hold kvm->mmu_lock.
630 kvmppc_free_pgtable_radix(kvm, gp->shadow_pgtable,
632 pgd_free(kvm->mm, gp->shadow_pgtable);
634 kvmhv_set_ptbl_entry(gp->shadow_lpid, 0, 0);
635 kvmppc_free_lpid(gp->shadow_lpid);
639 static void kvmhv_remove_nested(struct kvm_nested_guest *gp)
641 struct kvm *kvm = gp->l1_host;
642 int lpid = gp->l1_lpid;
645 spin_lock(&kvm->mmu_lock);
646 if (gp == kvm->arch.nested_guests[lpid]) {
647 kvm->arch.nested_guests[lpid] = NULL;
648 if (lpid == kvm->arch.max_nested_lpid) {
649 while (--lpid >= 0 && !kvm->arch.nested_guests[lpid])
651 kvm->arch.max_nested_lpid = lpid;
656 spin_unlock(&kvm->mmu_lock);
658 kvmhv_release_nested(gp);
662 * Free up all nested resources allocated for this guest.
663 * This is called with no vcpus of the guest running, when
664 * switching the guest to HPT mode or when destroying the
667 void kvmhv_release_all_nested(struct kvm *kvm)
670 struct kvm_nested_guest *gp;
671 struct kvm_nested_guest *freelist = NULL;
672 struct kvm_memory_slot *memslot;
675 spin_lock(&kvm->mmu_lock);
676 for (i = 0; i <= kvm->arch.max_nested_lpid; i++) {
677 gp = kvm->arch.nested_guests[i];
680 kvm->arch.nested_guests[i] = NULL;
681 if (--gp->refcnt == 0) {
686 kvm->arch.max_nested_lpid = -1;
687 spin_unlock(&kvm->mmu_lock);
688 while ((gp = freelist) != NULL) {
690 kvmhv_release_nested(gp);
693 srcu_idx = srcu_read_lock(&kvm->srcu);
694 kvm_for_each_memslot(memslot, kvm_memslots(kvm))
695 kvmhv_free_memslot_nest_rmap(memslot);
696 srcu_read_unlock(&kvm->srcu, srcu_idx);
699 /* caller must hold gp->tlb_lock */
700 static void kvmhv_flush_nested(struct kvm_nested_guest *gp)
702 struct kvm *kvm = gp->l1_host;
704 spin_lock(&kvm->mmu_lock);
705 kvmppc_free_pgtable_radix(kvm, gp->shadow_pgtable, gp->shadow_lpid);
706 spin_unlock(&kvm->mmu_lock);
707 kvmhv_flush_lpid(gp->shadow_lpid);
708 kvmhv_update_ptbl_cache(gp);
709 if (gp->l1_gr_to_hr == 0)
710 kvmhv_remove_nested(gp);
713 struct kvm_nested_guest *kvmhv_get_nested(struct kvm *kvm, int l1_lpid,
716 struct kvm_nested_guest *gp, *newgp;
718 if (l1_lpid >= KVM_MAX_NESTED_GUESTS ||
719 l1_lpid >= (1ul << ((kvm->arch.l1_ptcr & PRTS_MASK) + 12 - 4)))
722 spin_lock(&kvm->mmu_lock);
723 gp = kvm->arch.nested_guests[l1_lpid];
726 spin_unlock(&kvm->mmu_lock);
731 newgp = kvmhv_alloc_nested(kvm, l1_lpid);
734 spin_lock(&kvm->mmu_lock);
735 if (kvm->arch.nested_guests[l1_lpid]) {
736 /* someone else beat us to it */
737 gp = kvm->arch.nested_guests[l1_lpid];
739 kvm->arch.nested_guests[l1_lpid] = newgp;
743 if (l1_lpid > kvm->arch.max_nested_lpid)
744 kvm->arch.max_nested_lpid = l1_lpid;
747 spin_unlock(&kvm->mmu_lock);
750 kvmhv_release_nested(newgp);
755 void kvmhv_put_nested(struct kvm_nested_guest *gp)
757 struct kvm *kvm = gp->l1_host;
760 spin_lock(&kvm->mmu_lock);
762 spin_unlock(&kvm->mmu_lock);
764 kvmhv_release_nested(gp);
767 static struct kvm_nested_guest *kvmhv_find_nested(struct kvm *kvm, int lpid)
769 if (lpid > kvm->arch.max_nested_lpid)
771 return kvm->arch.nested_guests[lpid];
774 static inline bool kvmhv_n_rmap_is_equal(u64 rmap_1, u64 rmap_2)
776 return !((rmap_1 ^ rmap_2) & (RMAP_NESTED_LPID_MASK |
777 RMAP_NESTED_GPA_MASK));
780 void kvmhv_insert_nest_rmap(struct kvm *kvm, unsigned long *rmapp,
781 struct rmap_nested **n_rmap)
783 struct llist_node *entry = ((struct llist_head *) rmapp)->first;
784 struct rmap_nested *cursor;
785 u64 rmap, new_rmap = (*n_rmap)->rmap;
787 /* Are there any existing entries? */
789 /* No -> use the rmap as a single entry */
790 *rmapp = new_rmap | RMAP_NESTED_IS_SINGLE_ENTRY;
794 /* Do any entries match what we're trying to insert? */
795 for_each_nest_rmap_safe(cursor, entry, &rmap) {
796 if (kvmhv_n_rmap_is_equal(rmap, new_rmap))
800 /* Do we need to create a list or just add the new entry? */
802 if (rmap & RMAP_NESTED_IS_SINGLE_ENTRY) /* Not previously a list */
804 llist_add(&((*n_rmap)->list), (struct llist_head *) rmapp);
805 if (rmap & RMAP_NESTED_IS_SINGLE_ENTRY) /* Not previously a list */
806 (*n_rmap)->list.next = (struct llist_node *) rmap;
808 /* Set NULL so not freed by caller */
812 static void kvmhv_update_nest_rmap_rc(struct kvm *kvm, u64 n_rmap,
813 unsigned long clr, unsigned long set,
814 unsigned long hpa, unsigned long mask)
816 struct kvm_nested_guest *gp;
818 unsigned int shift, lpid;
821 gpa = n_rmap & RMAP_NESTED_GPA_MASK;
822 lpid = (n_rmap & RMAP_NESTED_LPID_MASK) >> RMAP_NESTED_LPID_SHIFT;
823 gp = kvmhv_find_nested(kvm, lpid);
828 ptep = __find_linux_pte(gp->shadow_pgtable, gpa, NULL, &shift);
830 * If the pte is present and the pfn is still the same, update the pte.
831 * If the pfn has changed then this is a stale rmap entry, the nested
832 * gpa actually points somewhere else now, and there is nothing to do.
833 * XXX A future optimisation would be to remove the rmap entry here.
835 if (ptep && pte_present(*ptep) && ((pte_val(*ptep) & mask) == hpa)) {
836 __radix_pte_update(ptep, clr, set);
837 kvmppc_radix_tlbie_page(kvm, gpa, shift, lpid);
842 * For a given list of rmap entries, update the rc bits in all ptes in shadow
843 * page tables for nested guests which are referenced by the rmap list.
845 void kvmhv_update_nest_rmap_rc_list(struct kvm *kvm, unsigned long *rmapp,
846 unsigned long clr, unsigned long set,
847 unsigned long hpa, unsigned long nbytes)
849 struct llist_node *entry = ((struct llist_head *) rmapp)->first;
850 struct rmap_nested *cursor;
851 unsigned long rmap, mask;
853 if ((clr | set) & ~(_PAGE_DIRTY | _PAGE_ACCESSED))
856 mask = PTE_RPN_MASK & ~(nbytes - 1);
859 for_each_nest_rmap_safe(cursor, entry, &rmap)
860 kvmhv_update_nest_rmap_rc(kvm, rmap, clr, set, hpa, mask);
863 static void kvmhv_remove_nest_rmap(struct kvm *kvm, u64 n_rmap,
864 unsigned long hpa, unsigned long mask)
866 struct kvm_nested_guest *gp;
868 unsigned int shift, lpid;
871 gpa = n_rmap & RMAP_NESTED_GPA_MASK;
872 lpid = (n_rmap & RMAP_NESTED_LPID_MASK) >> RMAP_NESTED_LPID_SHIFT;
873 gp = kvmhv_find_nested(kvm, lpid);
877 /* Find and invalidate the pte */
878 ptep = __find_linux_pte(gp->shadow_pgtable, gpa, NULL, &shift);
879 /* Don't spuriously invalidate ptes if the pfn has changed */
880 if (ptep && pte_present(*ptep) && ((pte_val(*ptep) & mask) == hpa))
881 kvmppc_unmap_pte(kvm, ptep, gpa, shift, NULL, gp->shadow_lpid);
884 static void kvmhv_remove_nest_rmap_list(struct kvm *kvm, unsigned long *rmapp,
885 unsigned long hpa, unsigned long mask)
887 struct llist_node *entry = llist_del_all((struct llist_head *) rmapp);
888 struct rmap_nested *cursor;
891 for_each_nest_rmap_safe(cursor, entry, &rmap) {
892 kvmhv_remove_nest_rmap(kvm, rmap, hpa, mask);
897 /* called with kvm->mmu_lock held */
898 void kvmhv_remove_nest_rmap_range(struct kvm *kvm,
899 const struct kvm_memory_slot *memslot,
900 unsigned long gpa, unsigned long hpa,
901 unsigned long nbytes)
903 unsigned long gfn, end_gfn;
904 unsigned long addr_mask;
908 gfn = (gpa >> PAGE_SHIFT) - memslot->base_gfn;
909 end_gfn = gfn + (nbytes >> PAGE_SHIFT);
911 addr_mask = PTE_RPN_MASK & ~(nbytes - 1);
914 for (; gfn < end_gfn; gfn++) {
915 unsigned long *rmap = &memslot->arch.rmap[gfn];
916 kvmhv_remove_nest_rmap_list(kvm, rmap, hpa, addr_mask);
920 static void kvmhv_free_memslot_nest_rmap(struct kvm_memory_slot *free)
924 for (page = 0; page < free->npages; page++) {
925 unsigned long rmap, *rmapp = &free->arch.rmap[page];
926 struct rmap_nested *cursor;
927 struct llist_node *entry;
929 entry = llist_del_all((struct llist_head *) rmapp);
930 for_each_nest_rmap_safe(cursor, entry, &rmap)
935 static bool kvmhv_invalidate_shadow_pte(struct kvm_vcpu *vcpu,
936 struct kvm_nested_guest *gp,
937 long gpa, int *shift_ret)
939 struct kvm *kvm = vcpu->kvm;
944 spin_lock(&kvm->mmu_lock);
945 ptep = __find_linux_pte(gp->shadow_pgtable, gpa, NULL, &shift);
948 if (ptep && pte_present(*ptep)) {
949 kvmppc_unmap_pte(kvm, ptep, gpa, shift, NULL, gp->shadow_lpid);
952 spin_unlock(&kvm->mmu_lock);
959 static inline int get_ric(unsigned int instr)
961 return (instr >> 18) & 0x3;
964 static inline int get_prs(unsigned int instr)
966 return (instr >> 17) & 0x1;
969 static inline int get_r(unsigned int instr)
971 return (instr >> 16) & 0x1;
974 static inline int get_lpid(unsigned long r_val)
976 return r_val & 0xffffffff;
979 static inline int get_is(unsigned long r_val)
981 return (r_val >> 10) & 0x3;
984 static inline int get_ap(unsigned long r_val)
986 return (r_val >> 5) & 0x7;
989 static inline long get_epn(unsigned long r_val)
994 static int kvmhv_emulate_tlbie_tlb_addr(struct kvm_vcpu *vcpu, int lpid,
997 struct kvm *kvm = vcpu->kvm;
998 struct kvm_nested_guest *gp;
1000 int shift, shadow_shift;
1003 shift = ap_to_shift(ap);
1006 /* Invalid ap encoding */
1009 addr &= ~((1UL << shift) - 1);
1010 npages = 1UL << (shift - PAGE_SHIFT);
1012 gp = kvmhv_get_nested(kvm, lpid, false);
1013 if (!gp) /* No such guest -> nothing to do */
1015 mutex_lock(&gp->tlb_lock);
1017 /* There may be more than one host page backing this single guest pte */
1019 kvmhv_invalidate_shadow_pte(vcpu, gp, addr, &shadow_shift);
1021 npages -= 1UL << (shadow_shift - PAGE_SHIFT);
1022 addr += 1UL << shadow_shift;
1023 } while (npages > 0);
1025 mutex_unlock(&gp->tlb_lock);
1026 kvmhv_put_nested(gp);
1030 static void kvmhv_emulate_tlbie_lpid(struct kvm_vcpu *vcpu,
1031 struct kvm_nested_guest *gp, int ric)
1033 struct kvm *kvm = vcpu->kvm;
1035 mutex_lock(&gp->tlb_lock);
1038 /* Invalidate TLB */
1039 spin_lock(&kvm->mmu_lock);
1040 kvmppc_free_pgtable_radix(kvm, gp->shadow_pgtable,
1042 kvmhv_flush_lpid(gp->shadow_lpid);
1043 spin_unlock(&kvm->mmu_lock);
1048 * We don't cache this -> nothing to do
1052 /* Invalidate TLB, PWC and caching of partition table entries */
1053 kvmhv_flush_nested(gp);
1058 mutex_unlock(&gp->tlb_lock);
1061 static void kvmhv_emulate_tlbie_all_lpid(struct kvm_vcpu *vcpu, int ric)
1063 struct kvm *kvm = vcpu->kvm;
1064 struct kvm_nested_guest *gp;
1067 spin_lock(&kvm->mmu_lock);
1068 for (i = 0; i <= kvm->arch.max_nested_lpid; i++) {
1069 gp = kvm->arch.nested_guests[i];
1071 spin_unlock(&kvm->mmu_lock);
1072 kvmhv_emulate_tlbie_lpid(vcpu, gp, ric);
1073 spin_lock(&kvm->mmu_lock);
1076 spin_unlock(&kvm->mmu_lock);
1079 static int kvmhv_emulate_priv_tlbie(struct kvm_vcpu *vcpu, unsigned int instr,
1080 unsigned long rsval, unsigned long rbval)
1082 struct kvm *kvm = vcpu->kvm;
1083 struct kvm_nested_guest *gp;
1084 int r, ric, prs, is, ap;
1089 ric = get_ric(instr);
1090 prs = get_prs(instr);
1092 lpid = get_lpid(rsval);
1096 * These cases are invalid and are not handled:
1097 * r != 1 -> Only radix supported
1098 * prs == 1 -> Not HV privileged
1099 * ric == 3 -> No cluster bombs for radix
1100 * is == 1 -> Partition scoped translations not associated with pid
1101 * (!is) && (ric == 1 || ric == 2) -> Not supported by ISA
1103 if ((!r) || (prs) || (ric == 3) || (is == 1) ||
1104 ((!is) && (ric == 1 || ric == 2)))
1111 * Invalidate TLB for a given target address
1113 epn = get_epn(rbval);
1115 ret = kvmhv_emulate_tlbie_tlb_addr(vcpu, lpid, ap, epn);
1118 /* Invalidate matching LPID */
1119 gp = kvmhv_get_nested(kvm, lpid, false);
1121 kvmhv_emulate_tlbie_lpid(vcpu, gp, ric);
1122 kvmhv_put_nested(gp);
1126 /* Invalidate ALL LPIDs */
1127 kvmhv_emulate_tlbie_all_lpid(vcpu, ric);
1138 * This handles the H_TLB_INVALIDATE hcall.
1139 * Parameters are (r4) tlbie instruction code, (r5) rS contents,
1142 long kvmhv_do_nested_tlbie(struct kvm_vcpu *vcpu)
1146 ret = kvmhv_emulate_priv_tlbie(vcpu, kvmppc_get_gpr(vcpu, 4),
1147 kvmppc_get_gpr(vcpu, 5), kvmppc_get_gpr(vcpu, 6));
1153 /* Used to convert a nested guest real address to a L1 guest real address */
1154 static int kvmhv_translate_addr_nested(struct kvm_vcpu *vcpu,
1155 struct kvm_nested_guest *gp,
1156 unsigned long n_gpa, unsigned long dsisr,
1157 struct kvmppc_pte *gpte_p)
1159 u64 fault_addr, flags = dsisr & DSISR_ISSTORE;
1162 ret = kvmppc_mmu_walk_radix_tree(vcpu, n_gpa, gpte_p, gp->l1_gr_to_hr,
1166 /* We didn't find a pte */
1167 if (ret == -EINVAL) {
1168 /* Unsupported mmu config */
1169 flags |= DSISR_UNSUPP_MMU;
1170 } else if (ret == -ENOENT) {
1171 /* No translation found */
1172 flags |= DSISR_NOHPTE;
1173 } else if (ret == -EFAULT) {
1174 /* Couldn't access L1 real address */
1175 flags |= DSISR_PRTABLE_FAULT;
1176 vcpu->arch.fault_gpa = fault_addr;
1183 /* We found a pte -> check permissions */
1184 if (dsisr & DSISR_ISSTORE) {
1186 if (!gpte_p->may_write) {
1187 flags |= DSISR_PROTFAULT;
1190 } else if (vcpu->arch.trap == BOOK3S_INTERRUPT_H_INST_STORAGE) {
1191 /* Can we execute? */
1192 if (!gpte_p->may_execute) {
1193 flags |= SRR1_ISI_N_OR_G;
1198 if (!gpte_p->may_read && !gpte_p->may_write) {
1199 flags |= DSISR_PROTFAULT;
1208 vcpu->arch.fault_dsisr = flags;
1209 if (vcpu->arch.trap == BOOK3S_INTERRUPT_H_INST_STORAGE) {
1210 vcpu->arch.shregs.msr &= ~0x783f0000ul;
1211 vcpu->arch.shregs.msr |= flags;
1216 static long kvmhv_handle_nested_set_rc(struct kvm_vcpu *vcpu,
1217 struct kvm_nested_guest *gp,
1218 unsigned long n_gpa,
1219 struct kvmppc_pte gpte,
1220 unsigned long dsisr)
1222 struct kvm *kvm = vcpu->kvm;
1223 bool writing = !!(dsisr & DSISR_ISSTORE);
1227 /* Are the rc bits set in the L1 partition scoped pte? */
1228 pgflags = _PAGE_ACCESSED;
1230 pgflags |= _PAGE_DIRTY;
1231 if (pgflags & ~gpte.rc)
1234 spin_lock(&kvm->mmu_lock);
1235 /* Set the rc bit in the pte of our (L0) pgtable for the L1 guest */
1236 ret = kvmppc_hv_handle_set_rc(kvm, kvm->arch.pgtable, writing,
1237 gpte.raddr, kvm->arch.lpid);
1243 /* Set the rc bit in the pte of the shadow_pgtable for the nest guest */
1244 ret = kvmppc_hv_handle_set_rc(kvm, gp->shadow_pgtable, writing, n_gpa,
1252 spin_unlock(&kvm->mmu_lock);
1256 static inline int kvmppc_radix_level_to_shift(int level)
1268 static inline int kvmppc_radix_shift_to_level(int shift)
1270 if (shift == PUD_SHIFT)
1272 if (shift == PMD_SHIFT)
1274 if (shift == PAGE_SHIFT)
1280 /* called with gp->tlb_lock held */
1281 static long int __kvmhv_nested_page_fault(struct kvm_run *run,
1282 struct kvm_vcpu *vcpu,
1283 struct kvm_nested_guest *gp)
1285 struct kvm *kvm = vcpu->kvm;
1286 struct kvm_memory_slot *memslot;
1287 struct rmap_nested *n_rmap;
1288 struct kvmppc_pte gpte;
1290 unsigned long mmu_seq;
1291 unsigned long dsisr = vcpu->arch.fault_dsisr;
1292 unsigned long ea = vcpu->arch.fault_dar;
1293 unsigned long *rmapp;
1294 unsigned long n_gpa, gpa, gfn, perm = 0UL;
1295 unsigned int shift, l1_shift, level;
1296 bool writing = !!(dsisr & DSISR_ISSTORE);
1297 bool kvm_ro = false;
1300 if (!gp->l1_gr_to_hr) {
1301 kvmhv_update_ptbl_cache(gp);
1302 if (!gp->l1_gr_to_hr)
1306 /* Convert the nested guest real address into a L1 guest real address */
1308 n_gpa = vcpu->arch.fault_gpa & ~0xF000000000000FFFULL;
1309 if (!(dsisr & DSISR_PRTABLE_FAULT))
1310 n_gpa |= ea & 0xFFF;
1311 ret = kvmhv_translate_addr_nested(vcpu, gp, n_gpa, dsisr, &gpte);
1314 * If the hardware found a translation but we don't now have a usable
1315 * translation in the l1 partition-scoped tree, remove the shadow pte
1316 * and let the guest retry.
1318 if (ret == RESUME_HOST &&
1319 (dsisr & (DSISR_PROTFAULT | DSISR_BADACCESS | DSISR_NOEXEC_OR_G |
1320 DSISR_BAD_COPYPASTE)))
1325 /* Failed to set the reference/change bits */
1326 if (dsisr & DSISR_SET_RC) {
1327 ret = kvmhv_handle_nested_set_rc(vcpu, gp, n_gpa, gpte, dsisr);
1328 if (ret == RESUME_HOST)
1332 dsisr &= ~DSISR_SET_RC;
1333 if (!(dsisr & (DSISR_BAD_FAULT_64S | DSISR_NOHPTE |
1335 return RESUME_GUEST;
1339 * We took an HISI or HDSI while we were running a nested guest which
1340 * means we have no partition scoped translation for that. This means
1341 * we need to insert a pte for the mapping into our shadow_pgtable.
1344 l1_shift = gpte.page_shift;
1345 if (l1_shift < PAGE_SHIFT) {
1346 /* We don't support l1 using a page size smaller than our own */
1347 pr_err("KVM: L1 guest page shift (%d) less than our own (%d)\n",
1348 l1_shift, PAGE_SHIFT);
1352 gfn = gpa >> PAGE_SHIFT;
1354 /* 1. Get the corresponding host memslot */
1356 memslot = gfn_to_memslot(kvm, gfn);
1357 if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID)) {
1358 if (dsisr & (DSISR_PRTABLE_FAULT | DSISR_BADACCESS)) {
1359 /* unusual error -> reflect to the guest as a DSI */
1360 kvmppc_core_queue_data_storage(vcpu, ea, dsisr);
1361 return RESUME_GUEST;
1364 /* passthrough of emulated MMIO case */
1365 return kvmppc_hv_emulate_mmio(run, vcpu, gpa, ea, writing);
1367 if (memslot->flags & KVM_MEM_READONLY) {
1369 /* Give the guest a DSI */
1370 kvmppc_core_queue_data_storage(vcpu, ea,
1371 DSISR_ISSTORE | DSISR_PROTFAULT);
1372 return RESUME_GUEST;
1377 /* 2. Find the host pte for this L1 guest real address */
1379 /* Used to check for invalidations in progress */
1380 mmu_seq = kvm->mmu_notifier_seq;
1383 /* See if can find translation in our partition scoped tables for L1 */
1385 spin_lock(&kvm->mmu_lock);
1386 pte_p = __find_linux_pte(kvm->arch.pgtable, gpa, NULL, &shift);
1391 spin_unlock(&kvm->mmu_lock);
1393 if (!pte_present(pte) || (writing && !(pte_val(pte) & _PAGE_WRITE))) {
1394 /* No suitable pte found -> try to insert a mapping */
1395 ret = kvmppc_book3s_instantiate_page(vcpu, gpa, memslot,
1396 writing, kvm_ro, &pte, &level);
1398 return RESUME_GUEST;
1401 shift = kvmppc_radix_level_to_shift(level);
1403 /* Align gfn to the start of the page */
1404 gfn = (gpa & ~((1UL << shift) - 1)) >> PAGE_SHIFT;
1406 /* 3. Compute the pte we need to insert for nest_gpa -> host r_addr */
1408 /* The permissions is the combination of the host and l1 guest ptes */
1409 perm |= gpte.may_read ? 0UL : _PAGE_READ;
1410 perm |= gpte.may_write ? 0UL : _PAGE_WRITE;
1411 perm |= gpte.may_execute ? 0UL : _PAGE_EXEC;
1412 /* Only set accessed/dirty (rc) bits if set in host and l1 guest ptes */
1413 perm |= (gpte.rc & _PAGE_ACCESSED) ? 0UL : _PAGE_ACCESSED;
1414 perm |= ((gpte.rc & _PAGE_DIRTY) && writing) ? 0UL : _PAGE_DIRTY;
1415 pte = __pte(pte_val(pte) & ~perm);
1417 /* What size pte can we insert? */
1418 if (shift > l1_shift) {
1420 unsigned int actual_shift = PAGE_SHIFT;
1421 if (PMD_SHIFT < l1_shift)
1422 actual_shift = PMD_SHIFT;
1423 mask = (1UL << shift) - (1UL << actual_shift);
1424 pte = __pte(pte_val(pte) | (gpa & mask));
1425 shift = actual_shift;
1427 level = kvmppc_radix_shift_to_level(shift);
1428 n_gpa &= ~((1UL << shift) - 1);
1430 /* 4. Insert the pte into our shadow_pgtable */
1432 n_rmap = kzalloc(sizeof(*n_rmap), GFP_KERNEL);
1434 return RESUME_GUEST; /* Let the guest try again */
1435 n_rmap->rmap = (n_gpa & RMAP_NESTED_GPA_MASK) |
1436 (((unsigned long) gp->l1_lpid) << RMAP_NESTED_LPID_SHIFT);
1437 rmapp = &memslot->arch.rmap[gfn - memslot->base_gfn];
1438 ret = kvmppc_create_pte(kvm, gp->shadow_pgtable, pte, n_gpa, level,
1439 mmu_seq, gp->shadow_lpid, rmapp, &n_rmap);
1443 ret = RESUME_GUEST; /* Let the guest try again */
1448 kvmhv_invalidate_shadow_pte(vcpu, gp, n_gpa, NULL);
1449 return RESUME_GUEST;
1452 long int kvmhv_nested_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu)
1454 struct kvm_nested_guest *gp = vcpu->arch.nested;
1457 mutex_lock(&gp->tlb_lock);
1458 ret = __kvmhv_nested_page_fault(run, vcpu, gp);
1459 mutex_unlock(&gp->tlb_lock);
1463 int kvmhv_nested_next_lpid(struct kvm *kvm, int lpid)
1467 spin_lock(&kvm->mmu_lock);
1468 while (++lpid <= kvm->arch.max_nested_lpid) {
1469 if (kvm->arch.nested_guests[lpid]) {
1474 spin_unlock(&kvm->mmu_lock);