Lines Matching +full:intc +full:- +full:nr +full:- +full:irqs
1 // SPDX-License-Identifier: GPL-2.0-only
9 * Kevin Wolf <mail@kevin-wolf.de>
32 #include <linux/page-flags.h>
50 #include <asm/ppc-opcode.h>
51 #include <asm/asm-prototypes.h>
73 #include <asm/pnv-pci.h>
108 MODULE_PARM_DESC(dynamic_mt_modes, "Set of allowed dynamic micro-threading modes: 0 (= none), 2, 4,…
170 vcpu = READ_ONCE(vc->runnable_threads[i]); in next_runnable_thread()
181 for (i = -1; (vcpu = next_runnable_thread(vc, &i)); )
215 if (paca_ptrs[cpu]->kvm_hstate.xics_phys) { in kvmppc_ipi_thread()
241 ++vcpu->stat.generic.halt_wakeup; in kvmppc_fast_vcpu_kick_hv()
243 cpu = READ_ONCE(vcpu->arch.thread_cpu); in kvmppc_fast_vcpu_kick_hv()
248 cpu = vcpu->cpu; in kvmppc_fast_vcpu_kick_hv()
267 * a vcore using vc->stolen_tb, and the stolen time when the vcpu
281 * updates to vc->stolen_tb are protected by the vcore->stoltb_lock
299 spin_lock_irqsave(&vc->stoltb_lock, flags); in kvmppc_core_start_stolen()
300 vc->preempt_tb = tb; in kvmppc_core_start_stolen()
301 spin_unlock_irqrestore(&vc->stoltb_lock, flags); in kvmppc_core_start_stolen()
310 spin_lock_irqsave(&vc->stoltb_lock, flags); in kvmppc_core_end_stolen()
311 if (vc->preempt_tb != TB_NIL) { in kvmppc_core_end_stolen()
312 vc->stolen_tb += tb - vc->preempt_tb; in kvmppc_core_end_stolen()
313 vc->preempt_tb = TB_NIL; in kvmppc_core_end_stolen()
315 spin_unlock_irqrestore(&vc->stoltb_lock, flags); in kvmppc_core_end_stolen()
320 struct kvmppc_vcore *vc = vcpu->arch.vcore; in kvmppc_core_vcpu_load_hv()
325 if (vcpu->arch.busy_preempt != TB_NIL) { in kvmppc_core_vcpu_load_hv()
326 WARN_ON_ONCE(vcpu->arch.state != KVMPPC_VCPU_BUSY_IN_HOST); in kvmppc_core_vcpu_load_hv()
327 vc->stolen_tb += mftb() - vcpu->arch.busy_preempt; in kvmppc_core_vcpu_load_hv()
328 vcpu->arch.busy_preempt = TB_NIL; in kvmppc_core_vcpu_load_hv()
336 * We can test vc->runner without taking the vcore lock, in kvmppc_core_vcpu_load_hv()
337 * because only this task ever sets vc->runner to this in kvmppc_core_vcpu_load_hv()
341 if (vc->runner == vcpu && vc->vcore_state >= VCORE_SLEEPING) in kvmppc_core_vcpu_load_hv()
344 spin_lock_irqsave(&vcpu->arch.tbacct_lock, flags); in kvmppc_core_vcpu_load_hv()
345 if (vcpu->arch.state == KVMPPC_VCPU_BUSY_IN_HOST && in kvmppc_core_vcpu_load_hv()
346 vcpu->arch.busy_preempt != TB_NIL) { in kvmppc_core_vcpu_load_hv()
347 vcpu->arch.busy_stolen += now - vcpu->arch.busy_preempt; in kvmppc_core_vcpu_load_hv()
348 vcpu->arch.busy_preempt = TB_NIL; in kvmppc_core_vcpu_load_hv()
350 spin_unlock_irqrestore(&vcpu->arch.tbacct_lock, flags); in kvmppc_core_vcpu_load_hv()
355 struct kvmppc_vcore *vc = vcpu->arch.vcore; in kvmppc_core_vcpu_put_hv()
364 WARN_ON_ONCE(vcpu->arch.state == KVMPPC_VCPU_RUNNABLE); in kvmppc_core_vcpu_put_hv()
370 vcpu->arch.state == KVMPPC_VCPU_BUSY_IN_HOST) in kvmppc_core_vcpu_put_hv()
371 vcpu->arch.busy_preempt = mftb(); in kvmppc_core_vcpu_put_hv()
377 if (vc->runner == vcpu && vc->vcore_state >= VCORE_SLEEPING) in kvmppc_core_vcpu_put_hv()
380 spin_lock_irqsave(&vcpu->arch.tbacct_lock, flags); in kvmppc_core_vcpu_put_hv()
381 if (vcpu->arch.state == KVMPPC_VCPU_BUSY_IN_HOST) in kvmppc_core_vcpu_put_hv()
382 vcpu->arch.busy_preempt = now; in kvmppc_core_vcpu_put_hv()
383 spin_unlock_irqrestore(&vcpu->arch.tbacct_lock, flags); in kvmppc_core_vcpu_put_hv()
388 vcpu->arch.pvr = pvr; in kvmppc_set_pvr_hv()
397 struct kvmppc_vcore *vc = vcpu->arch.vcore; in kvmppc_set_arch_compat()
432 return -EINVAL; in kvmppc_set_arch_compat()
438 return -EINVAL; in kvmppc_set_arch_compat()
440 spin_lock(&vc->lock); in kvmppc_set_arch_compat()
441 vc->arch_compat = arch_compat; in kvmppc_set_arch_compat()
446 vc->pcr = (host_pcr_bit - guest_pcr_bit) | PCR_MASK; in kvmppc_set_arch_compat()
447 spin_unlock(&vc->lock); in kvmppc_set_arch_compat()
456 pr_err("vcpu %p (%d):\n", vcpu, vcpu->vcpu_id); in kvmppc_dump_regs()
458 vcpu->arch.regs.nip, vcpu->arch.shregs.msr, vcpu->arch.trap); in kvmppc_dump_regs()
464 vcpu->arch.regs.ctr, vcpu->arch.regs.link); in kvmppc_dump_regs()
466 vcpu->arch.shregs.srr0, vcpu->arch.shregs.srr1); in kvmppc_dump_regs()
468 vcpu->arch.shregs.sprg0, vcpu->arch.shregs.sprg1); in kvmppc_dump_regs()
470 vcpu->arch.shregs.sprg2, vcpu->arch.shregs.sprg3); in kvmppc_dump_regs()
472 vcpu->arch.regs.ccr, vcpu->arch.regs.xer, vcpu->arch.shregs.dsisr); in kvmppc_dump_regs()
473 pr_err("dar = %.16llx\n", vcpu->arch.shregs.dar); in kvmppc_dump_regs()
475 vcpu->arch.fault_dar, vcpu->arch.fault_dsisr); in kvmppc_dump_regs()
476 pr_err("SLB (%d entries):\n", vcpu->arch.slb_max); in kvmppc_dump_regs()
477 for (r = 0; r < vcpu->arch.slb_max; ++r) in kvmppc_dump_regs()
479 vcpu->arch.slb[r].orige, vcpu->arch.slb[r].origv); in kvmppc_dump_regs()
481 vcpu->arch.vcore->lpcr, vcpu->kvm->arch.sdr1, in kvmppc_dump_regs()
482 vcpu->arch.last_inst); in kvmppc_dump_regs()
492 vpa->__old_status |= LPPACA_OLD_SHARED_PROC; in init_vpa()
493 vpa->yield_count = cpu_to_be32(1); in init_vpa()
500 if (addr & (L1_CACHE_BYTES - 1)) in set_vpa()
501 return -EINVAL; in set_vpa()
502 spin_lock(&vcpu->arch.vpa_update_lock); in set_vpa()
503 if (v->next_gpa != addr || v->len != len) { in set_vpa()
504 v->next_gpa = addr; in set_vpa()
505 v->len = addr ? len : 0; in set_vpa()
506 v->update_pending = 1; in set_vpa()
508 spin_unlock(&vcpu->arch.vpa_update_lock); in set_vpa()
512 /* Length for a per-processor buffer is passed in at offset 4 in the buffer */
523 if (vpap->update_pending) in vpa_is_registered()
524 return vpap->next_gpa != 0; in vpa_is_registered()
525 return vpap->pinned_addr != NULL; in vpa_is_registered()
532 struct kvm *kvm = vcpu->kvm; in do_h_register_vpa()
547 /* Registering new area - address must be cache-line aligned */ in do_h_register_vpa()
548 if ((vpa & (L1_CACHE_BYTES - 1)) || !vpa) in do_h_register_vpa()
556 len = be16_to_cpu(((struct reg_vpa *)va)->length.hword); in do_h_register_vpa()
558 len = be32_to_cpu(((struct reg_vpa *)va)->length.word); in do_h_register_vpa()
571 spin_lock(&tvcpu->arch.vpa_update_lock); in do_h_register_vpa()
584 vpap = &tvcpu->arch.vpa; in do_h_register_vpa()
591 len -= len % sizeof(struct dtl_entry); in do_h_register_vpa()
595 if (!vpa_is_registered(&tvcpu->arch.vpa)) in do_h_register_vpa()
598 vpap = &tvcpu->arch.dtl; in do_h_register_vpa()
605 if (!vpa_is_registered(&tvcpu->arch.vpa)) in do_h_register_vpa()
608 vpap = &tvcpu->arch.slb_shadow; in do_h_register_vpa()
615 if (vpa_is_registered(&tvcpu->arch.dtl) || in do_h_register_vpa()
616 vpa_is_registered(&tvcpu->arch.slb_shadow)) in do_h_register_vpa()
619 vpap = &tvcpu->arch.vpa; in do_h_register_vpa()
624 vpap = &tvcpu->arch.dtl; in do_h_register_vpa()
629 vpap = &tvcpu->arch.slb_shadow; in do_h_register_vpa()
635 vpap->next_gpa = vpa; in do_h_register_vpa()
636 vpap->len = len; in do_h_register_vpa()
637 vpap->update_pending = 1; in do_h_register_vpa()
640 spin_unlock(&tvcpu->arch.vpa_update_lock); in do_h_register_vpa()
647 struct kvm *kvm = vcpu->kvm; in kvmppc_update_vpa()
653 * We need to pin the page pointed to by vpap->next_gpa, in kvmppc_update_vpa()
661 gpa = vpap->next_gpa; in kvmppc_update_vpa()
662 spin_unlock(&vcpu->arch.vpa_update_lock); in kvmppc_update_vpa()
667 spin_lock(&vcpu->arch.vpa_update_lock); in kvmppc_update_vpa()
668 if (gpa == vpap->next_gpa) in kvmppc_update_vpa()
675 vpap->update_pending = 0; in kvmppc_update_vpa()
676 if (va && nb < vpap->len) { in kvmppc_update_vpa()
685 if (vpap->pinned_addr) in kvmppc_update_vpa()
686 kvmppc_unpin_guest_page(kvm, vpap->pinned_addr, vpap->gpa, in kvmppc_update_vpa()
687 vpap->dirty); in kvmppc_update_vpa()
688 vpap->gpa = gpa; in kvmppc_update_vpa()
689 vpap->pinned_addr = va; in kvmppc_update_vpa()
690 vpap->dirty = false; in kvmppc_update_vpa()
692 vpap->pinned_end = va + vpap->len; in kvmppc_update_vpa()
697 if (!(vcpu->arch.vpa.update_pending || in kvmppc_update_vpas()
698 vcpu->arch.slb_shadow.update_pending || in kvmppc_update_vpas()
699 vcpu->arch.dtl.update_pending)) in kvmppc_update_vpas()
702 spin_lock(&vcpu->arch.vpa_update_lock); in kvmppc_update_vpas()
703 if (vcpu->arch.vpa.update_pending) { in kvmppc_update_vpas()
704 kvmppc_update_vpa(vcpu, &vcpu->arch.vpa); in kvmppc_update_vpas()
705 if (vcpu->arch.vpa.pinned_addr) in kvmppc_update_vpas()
706 init_vpa(vcpu, vcpu->arch.vpa.pinned_addr); in kvmppc_update_vpas()
708 if (vcpu->arch.dtl.update_pending) { in kvmppc_update_vpas()
709 kvmppc_update_vpa(vcpu, &vcpu->arch.dtl); in kvmppc_update_vpas()
710 vcpu->arch.dtl_ptr = vcpu->arch.dtl.pinned_addr; in kvmppc_update_vpas()
711 vcpu->arch.dtl_index = 0; in kvmppc_update_vpas()
713 if (vcpu->arch.slb_shadow.update_pending) in kvmppc_update_vpas()
714 kvmppc_update_vpa(vcpu, &vcpu->arch.slb_shadow); in kvmppc_update_vpas()
715 spin_unlock(&vcpu->arch.vpa_update_lock); in kvmppc_update_vpas()
729 spin_lock_irqsave(&vc->stoltb_lock, flags); in vcore_stolen_time()
730 p = vc->stolen_tb; in vcore_stolen_time()
731 if (vc->vcore_state != VCORE_INACTIVE && in vcore_stolen_time()
732 vc->preempt_tb != TB_NIL) in vcore_stolen_time()
733 p += now - vc->preempt_tb; in vcore_stolen_time()
734 spin_unlock_irqrestore(&vc->stoltb_lock, flags); in vcore_stolen_time()
745 dt = vcpu->arch.dtl_ptr; in __kvmppc_create_dtl_entry()
750 dt->dispatch_reason = 7; in __kvmppc_create_dtl_entry()
751 dt->preempt_reason = 0; in __kvmppc_create_dtl_entry()
752 dt->processor_id = cpu_to_be16(pcpu + vcpu->arch.ptid); in __kvmppc_create_dtl_entry()
753 dt->enqueue_to_dispatch_time = cpu_to_be32(stolen); in __kvmppc_create_dtl_entry()
754 dt->ready_to_enqueue_time = 0; in __kvmppc_create_dtl_entry()
755 dt->waiting_to_ready_time = 0; in __kvmppc_create_dtl_entry()
756 dt->timebase = cpu_to_be64(now); in __kvmppc_create_dtl_entry()
757 dt->fault_addr = 0; in __kvmppc_create_dtl_entry()
758 dt->srr0 = cpu_to_be64(kvmppc_get_pc(vcpu)); in __kvmppc_create_dtl_entry()
759 dt->srr1 = cpu_to_be64(vcpu->arch.shregs.msr); in __kvmppc_create_dtl_entry()
762 if (dt == vcpu->arch.dtl.pinned_end) in __kvmppc_create_dtl_entry()
763 dt = vcpu->arch.dtl.pinned_addr; in __kvmppc_create_dtl_entry()
764 vcpu->arch.dtl_ptr = dt; in __kvmppc_create_dtl_entry()
765 /* order writing *dt vs. writing vpa->dtl_idx */ in __kvmppc_create_dtl_entry()
767 vpa->dtl_idx = cpu_to_be64(++vcpu->arch.dtl_index); in __kvmppc_create_dtl_entry()
769 /* vcpu->arch.dtl.dirty is set by the caller */ in __kvmppc_create_dtl_entry()
781 vpa = vcpu->arch.vpa.pinned_addr; in kvmppc_update_vpa_dispatch()
788 stolen = core_stolen - vcpu->arch.stolen_logged; in kvmppc_update_vpa_dispatch()
789 vcpu->arch.stolen_logged = core_stolen; in kvmppc_update_vpa_dispatch()
790 spin_lock_irqsave(&vcpu->arch.tbacct_lock, flags); in kvmppc_update_vpa_dispatch()
791 stolen += vcpu->arch.busy_stolen; in kvmppc_update_vpa_dispatch()
792 vcpu->arch.busy_stolen = 0; in kvmppc_update_vpa_dispatch()
793 spin_unlock_irqrestore(&vcpu->arch.tbacct_lock, flags); in kvmppc_update_vpa_dispatch()
795 vpa->enqueue_dispatch_tb = cpu_to_be64(be64_to_cpu(vpa->enqueue_dispatch_tb) + stolen); in kvmppc_update_vpa_dispatch()
797 __kvmppc_create_dtl_entry(vcpu, vpa, vc->pcpu, now + vc->tb_offset, stolen); in kvmppc_update_vpa_dispatch()
799 vcpu->arch.vpa.dirty = true; in kvmppc_update_vpa_dispatch()
810 vpa = vcpu->arch.vpa.pinned_addr; in kvmppc_update_vpa_dispatch_p9()
814 stolen = vc->stolen_tb; in kvmppc_update_vpa_dispatch_p9()
815 stolen_delta = stolen - vcpu->arch.stolen_logged; in kvmppc_update_vpa_dispatch_p9()
816 vcpu->arch.stolen_logged = stolen; in kvmppc_update_vpa_dispatch_p9()
818 vpa->enqueue_dispatch_tb = cpu_to_be64(stolen); in kvmppc_update_vpa_dispatch_p9()
820 __kvmppc_create_dtl_entry(vcpu, vpa, vc->pcpu, now, stolen_delta); in kvmppc_update_vpa_dispatch_p9()
822 vcpu->arch.vpa.dirty = true; in kvmppc_update_vpa_dispatch_p9()
831 if (vcpu->arch.doorbell_request) in kvmppc_doorbell_pending()
836 * Ensure that the read of vcore->dpdes comes after the read in kvmppc_doorbell_pending()
837 * of vcpu->doorbell_request. This barrier matches the in kvmppc_doorbell_pending()
841 vc = vcpu->arch.vcore; in kvmppc_doorbell_pending()
842 thr = vcpu->vcpu_id - vc->first_vcpuid; in kvmppc_doorbell_pending()
843 return !!(vc->dpdes & (1 << thr)); in kvmppc_doorbell_pending()
848 if (vcpu->arch.vcore->arch_compat >= PVR_ARCH_207) in kvmppc_power8_compatible()
850 if ((!vcpu->arch.vcore->arch_compat) && in kvmppc_power8_compatible()
892 if (!vcpu->kvm->arch.dawr1_enabled) in kvmppc_h_set_mode()
915 /* Copy guest memory in place - must reside within a single memslot */
927 return -EFAULT; in kvmppc_copy_guest()
928 if ((from + len) >= ((from_memslot->base_gfn + from_memslot->npages) in kvmppc_copy_guest()
930 return -EINVAL; in kvmppc_copy_guest()
933 return -EFAULT; in kvmppc_copy_guest()
934 from_addr |= (from & (PAGE_SIZE - 1)); in kvmppc_copy_guest()
939 return -EFAULT; in kvmppc_copy_guest()
940 if ((to + len) >= ((to_memslot->base_gfn + to_memslot->npages) in kvmppc_copy_guest()
942 return -EINVAL; in kvmppc_copy_guest()
945 return -EFAULT; in kvmppc_copy_guest()
946 to_addr |= (to & (PAGE_SIZE - 1)); in kvmppc_copy_guest()
952 return -EFAULT; in kvmppc_copy_guest()
961 u64 pg_mask = SZ_4K - 1; in kvmppc_h_page_init()
975 ret = kvmppc_copy_guest(vcpu->kvm, dest, src, pg_sz); in kvmppc_h_page_init()
979 ret = kvm_clear_guest(vcpu->kvm, dest, pg_sz); in kvmppc_h_page_init()
991 struct kvmppc_vcore *vcore = target->arch.vcore; in kvm_arch_vcpu_yield_to()
1005 spin_lock(&vcore->lock); in kvm_arch_vcpu_yield_to()
1006 if (target->arch.state == KVMPPC_VCPU_RUNNABLE && in kvm_arch_vcpu_yield_to()
1007 vcore->vcore_state != VCORE_INACTIVE && in kvm_arch_vcpu_yield_to()
1008 vcore->runner) in kvm_arch_vcpu_yield_to()
1009 target = vcore->runner; in kvm_arch_vcpu_yield_to()
1010 spin_unlock(&vcore->lock); in kvm_arch_vcpu_yield_to()
1021 spin_lock(&vcpu->arch.vpa_update_lock); in kvmppc_get_yield_count()
1022 lppaca = (struct lppaca *)vcpu->arch.vpa.pinned_addr; in kvmppc_get_yield_count()
1024 yield_count = be32_to_cpu(lppaca->yield_count); in kvmppc_get_yield_count()
1025 spin_unlock(&vcpu->arch.vpa_update_lock); in kvmppc_get_yield_count()
1032 * Handles only nested process-scoped invalidation requests in L0.
1040 * The partition-scoped invalidations aren't handled here in L0. in kvmppc_nested_h_rpt_invalidate()
1050 do_h_rpt_invalidate_prt(pid, vcpu->arch.nested->shadow_lpid, in kvmppc_nested_h_rpt_invalidate()
1062 if (!kvm_is_radix(vcpu->kvm)) in kvmppc_h_rpt_invalidate()
1069 * Partition-scoped invalidation for nested guests. in kvmppc_h_rpt_invalidate()
1072 if (!nesting_enabled(vcpu->kvm)) in kvmppc_h_rpt_invalidate()
1084 * Process-scoped invalidation for L1 guests. in kvmppc_h_rpt_invalidate()
1086 do_h_rpt_invalidate_prt(id, vcpu->kvm->arch.lpid, in kvmppc_h_rpt_invalidate()
1093 struct kvm *kvm = vcpu->kvm; in kvmppc_pseries_do_hcall()
1101 !test_bit(req/4, vcpu->kvm->arch.enabled_hcalls)) in kvmppc_pseries_do_hcall()
1160 tvcpu->arch.prodded = 1; in kvmppc_pseries_do_hcall()
1162 if (tvcpu->arch.ceded) in kvmppc_pseries_do_hcall()
1167 if (target == -1) in kvmppc_pseries_do_hcall()
1185 if (list_empty(&kvm->arch.rtas_tokens)) in kvmppc_pseries_do_hcall()
1188 idx = srcu_read_lock(&kvm->srcu); in kvmppc_pseries_do_hcall()
1190 srcu_read_unlock(&kvm->srcu, idx); in kvmppc_pseries_do_hcall()
1192 if (rc == -ENOENT) in kvmppc_pseries_do_hcall()
1271 if (!arch_get_random_seed_longs(&vcpu->arch.regs.gpr[4], 1)) in kvmppc_pseries_do_hcall()
1295 vcpu->arch.hcall_needed = 0; in kvmppc_pseries_do_hcall()
1296 return -EINTR; in kvmppc_pseries_do_hcall()
1299 vcpu->arch.hcall_needed = 0; in kvmppc_pseries_do_hcall()
1349 * Instead the kvm->arch.secure_guest flag is checked inside in kvmppc_pseries_do_hcall()
1360 vcpu->arch.hcall_needed = 0; in kvmppc_pseries_do_hcall()
1365 * Handle H_CEDE in the P9 path where we don't call the real-mode hcall
1374 vcpu->arch.ceded = 1; in kvmppc_cede()
1376 if (vcpu->arch.prodded) { in kvmppc_cede()
1377 vcpu->arch.prodded = 0; in kvmppc_cede()
1379 vcpu->arch.ceded = 0; in kvmppc_cede()
1412 /* See if it's in the real-mode table */ in kvmppc_hcall_impl_hv()
1430 vcpu->run->exit_reason = KVM_EXIT_DEBUG; in kvmppc_emulate_debug_inst()
1431 vcpu->run->debug.arch.address = kvmppc_get_pc(vcpu); in kvmppc_emulate_debug_inst()
1450 nthreads = vcpu->kvm->arch.emul_smt_mode; in kvmppc_read_dpdes()
1452 cpu = vcpu->vcpu_id & ~(nthreads - 1); in kvmppc_read_dpdes()
1454 v = kvmppc_find_vcpu(vcpu->kvm, cpu); in kvmppc_read_dpdes()
1460 * which will update its vcore->dpdes value. in kvmppc_read_dpdes()
1462 pcpu = READ_ONCE(v->cpu); in kvmppc_read_dpdes()
1472 * On POWER9, emulate doorbell-related instructions in order to
1473 * give the guest the illusion of running on a multi-threaded core.
1481 struct kvm *kvm = vcpu->kvm; in kvmppc_emulate_doorbell_instr()
1491 thr = vcpu->vcpu_id & (kvm->arch.emul_smt_mode - 1); in kvmppc_emulate_doorbell_instr()
1498 if (arg >= kvm->arch.emul_smt_mode) in kvmppc_emulate_doorbell_instr()
1500 tvcpu = kvmppc_find_vcpu(kvm, vcpu->vcpu_id - thr + arg); in kvmppc_emulate_doorbell_instr()
1503 if (!tvcpu->arch.doorbell_request) { in kvmppc_emulate_doorbell_instr()
1504 tvcpu->arch.doorbell_request = 1; in kvmppc_emulate_doorbell_instr()
1512 vcpu->arch.vcore->dpdes = 0; in kvmppc_emulate_doorbell_instr()
1513 vcpu->arch.doorbell_request = 0; in kvmppc_emulate_doorbell_instr()
1544 if (!(vcpu->arch.hfscr_permitted & HFSCR_PM)) in kvmppc_pmu_unavailable()
1554 if (!(vcpu->arch.hfscr_permitted & HFSCR_EBB)) in kvmppc_ebb_unavailable()
1564 if (!(vcpu->arch.hfscr_permitted & HFSCR_TM)) in kvmppc_tm_unavailable()
1575 struct kvm_run *run = vcpu->run; in kvmppc_handle_exit_hv()
1578 vcpu->stat.sum_exits++; in kvmppc_handle_exit_hv()
1583 * setting paca->kvm_hstate.in_guest to KVM_GUEST_MODE_GUEST_HV in kvmppc_handle_exit_hv()
1591 vcpu->arch.trap, kvmppc_get_pc(vcpu), in kvmppc_handle_exit_hv()
1592 vcpu->arch.shregs.msr); in kvmppc_handle_exit_hv()
1594 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; in kvmppc_handle_exit_hv()
1595 run->hw.hardware_exit_reason = vcpu->arch.trap; in kvmppc_handle_exit_hv()
1598 run->exit_reason = KVM_EXIT_UNKNOWN; in kvmppc_handle_exit_hv()
1599 run->ready_for_interrupt_injection = 1; in kvmppc_handle_exit_hv()
1600 switch (vcpu->arch.trap) { in kvmppc_handle_exit_hv()
1601 /* We're good on these - the host merely wanted to get our attention */ in kvmppc_handle_exit_hv()
1604 vcpu->arch.trap = BOOK3S_INTERRUPT_HV_DECREMENTER; in kvmppc_handle_exit_hv()
1607 vcpu->stat.dec_exits++; in kvmppc_handle_exit_hv()
1613 vcpu->stat.ext_intr_exits++; in kvmppc_handle_exit_hv()
1630 machine_check_print_event_info(&vcpu->arch.mce_evt,false, true); in kvmppc_handle_exit_hv()
1638 if (!vcpu->kvm->arch.fwnmi_enabled) { in kvmppc_handle_exit_hv()
1647 run->exit_reason = KVM_EXIT_NMI; in kvmppc_handle_exit_hv()
1648 run->hw.hardware_exit_reason = vcpu->arch.trap; in kvmppc_handle_exit_hv()
1649 /* Clear out the old NMI status from run->flags */ in kvmppc_handle_exit_hv()
1650 run->flags &= ~KVM_RUN_PPC_NMI_DISP_MASK; in kvmppc_handle_exit_hv()
1652 if (vcpu->arch.mce_evt.disposition == MCE_DISPOSITION_RECOVERED) in kvmppc_handle_exit_hv()
1653 run->flags |= KVM_RUN_PPC_NMI_DISP_FULLY_RECOV; in kvmppc_handle_exit_hv()
1655 run->flags |= KVM_RUN_PPC_NMI_DISP_NOT_RECOV; in kvmppc_handle_exit_hv()
1706 * hcall - gather args and set exit_reason. This will next be in kvmppc_handle_exit_hv()
1710 run->papr_hcall.nr = kvmppc_get_gpr(vcpu, 3); in kvmppc_handle_exit_hv()
1712 run->papr_hcall.args[i] = kvmppc_get_gpr(vcpu, 4 + i); in kvmppc_handle_exit_hv()
1713 run->exit_reason = KVM_EXIT_PAPR_HCALL; in kvmppc_handle_exit_hv()
1714 vcpu->arch.hcall_needed = 1; in kvmppc_handle_exit_hv()
1733 unlikely(vcpu->arch.fault_dsisr == HDSISR_CANARY)) { in kvmppc_handle_exit_hv()
1738 if (kvm_is_radix(vcpu->kvm) || !cpu_has_feature(CPU_FTR_ARCH_300)) { in kvmppc_handle_exit_hv()
1740 * Radix doesn't require anything, and pre-ISAv3.0 hash in kvmppc_handle_exit_hv()
1749 if (!(vcpu->arch.fault_dsisr & (DSISR_NOHPTE | DSISR_PROTFAULT))) { in kvmppc_handle_exit_hv()
1752 vcpu->arch.fault_dar, vcpu->arch.fault_dsisr); in kvmppc_handle_exit_hv()
1758 vsid = vcpu->kvm->arch.vrma_slb_v; in kvmppc_handle_exit_hv()
1760 vsid = vcpu->arch.fault_gpa; in kvmppc_handle_exit_hv()
1762 err = kvmppc_hpte_hv_fault(vcpu, vcpu->arch.fault_dar, in kvmppc_handle_exit_hv()
1763 vsid, vcpu->arch.fault_dsisr, true); in kvmppc_handle_exit_hv()
1766 } else if (err == -1 || err == -2) { in kvmppc_handle_exit_hv()
1771 vcpu->arch.fault_dar, err); in kvmppc_handle_exit_hv()
1780 vcpu->arch.fault_dar = kvmppc_get_pc(vcpu); in kvmppc_handle_exit_hv()
1781 vcpu->arch.fault_dsisr = __kvmppc_get_msr_hv(vcpu) & in kvmppc_handle_exit_hv()
1783 if (kvm_is_radix(vcpu->kvm) || !cpu_has_feature(CPU_FTR_ARCH_300)) { in kvmppc_handle_exit_hv()
1785 * Radix doesn't require anything, and pre-ISAv3.0 hash in kvmppc_handle_exit_hv()
1791 vcpu->arch.fault_dsisr |= DSISR_ISSTORE; in kvmppc_handle_exit_hv()
1796 if (!(vcpu->arch.fault_dsisr & SRR1_ISI_NOPT)) { in kvmppc_handle_exit_hv()
1798 vcpu->arch.fault_dsisr | in kvmppc_handle_exit_hv()
1805 vsid = vcpu->kvm->arch.vrma_slb_v; in kvmppc_handle_exit_hv()
1807 vsid = vcpu->arch.fault_gpa; in kvmppc_handle_exit_hv()
1809 err = kvmppc_hpte_hv_fault(vcpu, vcpu->arch.fault_dar, in kvmppc_handle_exit_hv()
1810 vsid, vcpu->arch.fault_dsisr, false); in kvmppc_handle_exit_hv()
1813 } else if (err == -1) { in kvmppc_handle_exit_hv()
1831 if (vcpu->arch.emul_inst != KVM_INST_FETCH_FAILED) in kvmppc_handle_exit_hv()
1832 vcpu->arch.last_inst = kvmppc_need_byteswap(vcpu) ? in kvmppc_handle_exit_hv()
1833 swab32(vcpu->arch.emul_inst) : in kvmppc_handle_exit_hv()
1834 vcpu->arch.emul_inst; in kvmppc_handle_exit_hv()
1835 if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) { in kvmppc_handle_exit_hv()
1847 * This occurs for various TM-related instructions that in kvmppc_handle_exit_hv()
1849 * handled the cases where the guest was in real-suspend in kvmppc_handle_exit_hv()
1853 if (r != -1) in kvmppc_handle_exit_hv()
1893 vcpu->arch.trap, kvmppc_get_pc(vcpu), in kvmppc_handle_exit_hv()
1895 run->hw.hardware_exit_reason = vcpu->arch.trap; in kvmppc_handle_exit_hv()
1908 vcpu->stat.sum_exits++; in kvmppc_handle_nested_exit()
1913 * setting paca->kvm_hstate.in_guest to KVM_GUEST_MODE_GUEST_HV in kvmppc_handle_nested_exit()
1921 vcpu->arch.trap, kvmppc_get_pc(vcpu), in kvmppc_handle_nested_exit()
1926 switch (vcpu->arch.trap) { in kvmppc_handle_nested_exit()
1927 /* We're good on these - the host merely wanted to get our attention */ in kvmppc_handle_nested_exit()
1929 vcpu->stat.dec_exits++; in kvmppc_handle_nested_exit()
1933 vcpu->stat.ext_intr_exits++; in kvmppc_handle_nested_exit()
1938 vcpu->stat.ext_intr_exits++; in kvmppc_handle_nested_exit()
1943 vcpu->arch.trap = BOOK3S_INTERRUPT_HV_DECREMENTER; in kvmppc_handle_nested_exit()
1944 vcpu->stat.dec_exits++; in kvmppc_handle_nested_exit()
1961 machine_check_print_event_info(&vcpu->arch.mce_evt, false, true); in kvmppc_handle_nested_exit()
1971 srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); in kvmppc_handle_nested_exit()
1973 srcu_read_unlock(&vcpu->kvm->srcu, srcu_idx); in kvmppc_handle_nested_exit()
1976 vcpu->arch.fault_dar = kvmppc_get_pc(vcpu); in kvmppc_handle_nested_exit()
1977 vcpu->arch.fault_dsisr = kvmppc_get_msr(vcpu) & in kvmppc_handle_nested_exit()
1980 vcpu->arch.fault_dsisr |= DSISR_ISSTORE; in kvmppc_handle_nested_exit()
1981 srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); in kvmppc_handle_nested_exit()
1983 srcu_read_unlock(&vcpu->kvm->srcu, srcu_idx); in kvmppc_handle_nested_exit()
1989 * This occurs for various TM-related instructions that in kvmppc_handle_nested_exit()
1991 * handled the cases where the guest was in real-suspend in kvmppc_handle_nested_exit()
1995 if (r != -1) in kvmppc_handle_nested_exit()
2001 u64 cause = vcpu->arch.hfscr >> 56; in kvmppc_handle_nested_exit()
2009 if (!(vcpu->arch.hfscr_permitted & (1UL << cause)) || in kvmppc_handle_nested_exit()
2010 (vcpu->arch.nested_hfscr & (1UL << cause))) { in kvmppc_handle_nested_exit()
2012 vcpu->arch.trap = BOOK3S_INTERRUPT_H_EMUL_ASSIST; in kvmppc_handle_nested_exit()
2019 vcpu->arch.emul_inst = ppc_inst_val(pinst); in kvmppc_handle_nested_exit()
2032 vcpu->arch.trap = 0; in kvmppc_handle_nested_exit()
2043 * guests for process-scoped invalidations when in kvmppc_handle_nested_exit()
2068 sregs->pvr = vcpu->arch.pvr; in kvm_arch_vcpu_ioctl_get_sregs_hv()
2069 for (i = 0; i < vcpu->arch.slb_max; i++) { in kvm_arch_vcpu_ioctl_get_sregs_hv()
2070 sregs->u.s.ppc64.slb[i].slbe = vcpu->arch.slb[i].orige; in kvm_arch_vcpu_ioctl_get_sregs_hv()
2071 sregs->u.s.ppc64.slb[i].slbv = vcpu->arch.slb[i].origv; in kvm_arch_vcpu_ioctl_get_sregs_hv()
2083 if (sregs->pvr != vcpu->arch.pvr) in kvm_arch_vcpu_ioctl_set_sregs_hv()
2084 return -EINVAL; in kvm_arch_vcpu_ioctl_set_sregs_hv()
2087 for (i = 0; i < vcpu->arch.slb_nr; i++) { in kvm_arch_vcpu_ioctl_set_sregs_hv()
2088 if (sregs->u.s.ppc64.slb[i].slbe & SLB_ESID_V) { in kvm_arch_vcpu_ioctl_set_sregs_hv()
2089 vcpu->arch.slb[j].orige = sregs->u.s.ppc64.slb[i].slbe; in kvm_arch_vcpu_ioctl_set_sregs_hv()
2090 vcpu->arch.slb[j].origv = sregs->u.s.ppc64.slb[i].slbv; in kvm_arch_vcpu_ioctl_set_sregs_hv()
2094 vcpu->arch.slb_max = j; in kvm_arch_vcpu_ioctl_set_sregs_hv()
2145 struct kvm *kvm = vcpu->kvm; in kvmppc_set_lpcr()
2146 struct kvmppc_vcore *vc = vcpu->arch.vcore; in kvmppc_set_lpcr()
2149 spin_lock(&vc->lock); in kvmppc_set_lpcr()
2153 * DPFD (default prefetch depth), ILE (interrupt little-endian), in kvmppc_set_lpcr()
2160 /* Broken 32-bit version of LPCR must not clear top bits */ in kvmppc_set_lpcr()
2165 (vc->lpcr & ~mask) | (new_lpcr & mask)); in kvmppc_set_lpcr()
2168 * If ILE (interrupt little-endian) has changed, update the in kvmppc_set_lpcr()
2171 if ((new_lpcr & LPCR_ILE) != (vc->lpcr & LPCR_ILE)) { in kvmppc_set_lpcr()
2176 if (vcpu->arch.vcore != vc) in kvmppc_set_lpcr()
2179 vcpu->arch.intr_msr |= MSR_LE; in kvmppc_set_lpcr()
2181 vcpu->arch.intr_msr &= ~MSR_LE; in kvmppc_set_lpcr()
2185 vc->lpcr = new_lpcr; in kvmppc_set_lpcr()
2187 spin_unlock(&vc->lock); in kvmppc_set_lpcr()
2204 *val = get_reg_val(id, vcpu->arch.dabr); in kvmppc_get_one_reg_hv()
2207 *val = get_reg_val(id, vcpu->arch.dabrx); in kvmppc_get_one_reg_hv()
2225 i = id - KVM_REG_PPC_MMCR0; in kvmppc_get_one_reg_hv()
2235 *val = get_reg_val(id, vcpu->arch.mmcrs); in kvmppc_get_one_reg_hv()
2241 i = id - KVM_REG_PPC_PMC1; in kvmppc_get_one_reg_hv()
2245 i = id - KVM_REG_PPC_SPMC1; in kvmppc_get_one_reg_hv()
2246 *val = get_reg_val(id, vcpu->arch.spmc[i]); in kvmppc_get_one_reg_hv()
2273 * either vcore->dpdes or doorbell_request. in kvmppc_get_one_reg_hv()
2277 *val = get_reg_val(id, vcpu->arch.doorbell_request); in kvmppc_get_one_reg_hv()
2279 *val = get_reg_val(id, vcpu->arch.vcore->dpdes); in kvmppc_get_one_reg_hv()
2282 *val = get_reg_val(id, vcpu->arch.vcore->vtb); in kvmppc_get_one_reg_hv()
2300 *val = get_reg_val(id, vcpu->arch.csigr); in kvmppc_get_one_reg_hv()
2303 *val = get_reg_val(id, vcpu->arch.tacr); in kvmppc_get_one_reg_hv()
2306 *val = get_reg_val(id, vcpu->arch.tcscr); in kvmppc_get_one_reg_hv()
2309 *val = get_reg_val(id, vcpu->arch.pid); in kvmppc_get_one_reg_hv()
2312 *val = get_reg_val(id, vcpu->arch.acop); in kvmppc_get_one_reg_hv()
2318 *val = get_reg_val(id, vcpu->arch.tid); in kvmppc_get_one_reg_hv()
2321 *val = get_reg_val(id, vcpu->arch.psscr); in kvmppc_get_one_reg_hv()
2324 spin_lock(&vcpu->arch.vpa_update_lock); in kvmppc_get_one_reg_hv()
2325 *val = get_reg_val(id, vcpu->arch.vpa.next_gpa); in kvmppc_get_one_reg_hv()
2326 spin_unlock(&vcpu->arch.vpa_update_lock); in kvmppc_get_one_reg_hv()
2329 spin_lock(&vcpu->arch.vpa_update_lock); in kvmppc_get_one_reg_hv()
2330 val->vpaval.addr = vcpu->arch.slb_shadow.next_gpa; in kvmppc_get_one_reg_hv()
2331 val->vpaval.length = vcpu->arch.slb_shadow.len; in kvmppc_get_one_reg_hv()
2332 spin_unlock(&vcpu->arch.vpa_update_lock); in kvmppc_get_one_reg_hv()
2335 spin_lock(&vcpu->arch.vpa_update_lock); in kvmppc_get_one_reg_hv()
2336 val->vpaval.addr = vcpu->arch.dtl.next_gpa; in kvmppc_get_one_reg_hv()
2337 val->vpaval.length = vcpu->arch.dtl.len; in kvmppc_get_one_reg_hv()
2338 spin_unlock(&vcpu->arch.vpa_update_lock); in kvmppc_get_one_reg_hv()
2341 *val = get_reg_val(id, vcpu->arch.vcore->tb_offset); in kvmppc_get_one_reg_hv()
2345 *val = get_reg_val(id, vcpu->arch.vcore->lpcr); in kvmppc_get_one_reg_hv()
2352 *val = get_reg_val(id, vcpu->arch.tfhar); in kvmppc_get_one_reg_hv()
2355 *val = get_reg_val(id, vcpu->arch.tfiar); in kvmppc_get_one_reg_hv()
2358 *val = get_reg_val(id, vcpu->arch.texasr); in kvmppc_get_one_reg_hv()
2361 i = id - KVM_REG_PPC_TM_GPR0; in kvmppc_get_one_reg_hv()
2362 *val = get_reg_val(id, vcpu->arch.gpr_tm[i]); in kvmppc_get_one_reg_hv()
2367 i = id - KVM_REG_PPC_TM_VSR0; in kvmppc_get_one_reg_hv()
2370 val->vsxval[j] = vcpu->arch.fp_tm.fpr[i][j]; in kvmppc_get_one_reg_hv()
2373 val->vval = vcpu->arch.vr_tm.vr[i-32]; in kvmppc_get_one_reg_hv()
2375 r = -ENXIO; in kvmppc_get_one_reg_hv()
2380 *val = get_reg_val(id, vcpu->arch.cr_tm); in kvmppc_get_one_reg_hv()
2383 *val = get_reg_val(id, vcpu->arch.xer_tm); in kvmppc_get_one_reg_hv()
2386 *val = get_reg_val(id, vcpu->arch.lr_tm); in kvmppc_get_one_reg_hv()
2389 *val = get_reg_val(id, vcpu->arch.ctr_tm); in kvmppc_get_one_reg_hv()
2392 *val = get_reg_val(id, vcpu->arch.fp_tm.fpscr); in kvmppc_get_one_reg_hv()
2395 *val = get_reg_val(id, vcpu->arch.amr_tm); in kvmppc_get_one_reg_hv()
2398 *val = get_reg_val(id, vcpu->arch.ppr_tm); in kvmppc_get_one_reg_hv()
2401 *val = get_reg_val(id, vcpu->arch.vrsave_tm); in kvmppc_get_one_reg_hv()
2405 *val = get_reg_val(id, vcpu->arch.vr_tm.vscr.u[3]); in kvmppc_get_one_reg_hv()
2407 r = -ENXIO; in kvmppc_get_one_reg_hv()
2410 *val = get_reg_val(id, vcpu->arch.dscr_tm); in kvmppc_get_one_reg_hv()
2413 *val = get_reg_val(id, vcpu->arch.tar_tm); in kvmppc_get_one_reg_hv()
2417 *val = get_reg_val(id, vcpu->arch.vcore->arch_compat); in kvmppc_get_one_reg_hv()
2420 *val = get_reg_val(id, vcpu->arch.dec_expires); in kvmppc_get_one_reg_hv()
2423 *val = get_reg_val(id, vcpu->arch.online); in kvmppc_get_one_reg_hv()
2426 *val = get_reg_val(id, vcpu->kvm->arch.l1_ptcr); in kvmppc_get_one_reg_hv()
2432 r = -EINVAL; in kvmppc_get_one_reg_hv()
2450 r = -EINVAL; in kvmppc_set_one_reg_hv()
2453 vcpu->arch.dabr = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2456 vcpu->arch.dabrx = set_reg_val(id, *val) & ~DABRX_HYP; in kvmppc_set_one_reg_hv()
2474 i = id - KVM_REG_PPC_MMCR0; in kvmppc_set_one_reg_hv()
2484 vcpu->arch.mmcrs = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2490 i = id - KVM_REG_PPC_PMC1; in kvmppc_set_one_reg_hv()
2494 i = id - KVM_REG_PPC_SPMC1; in kvmppc_set_one_reg_hv()
2495 vcpu->arch.spmc[i] = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2520 vcpu->arch.doorbell_request = set_reg_val(id, *val) & 1; in kvmppc_set_one_reg_hv()
2522 vcpu->arch.vcore->dpdes = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2525 vcpu->arch.vcore->vtb = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2546 vcpu->arch.csigr = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2549 vcpu->arch.tacr = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2552 vcpu->arch.tcscr = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2555 vcpu->arch.pid = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2558 vcpu->arch.acop = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2564 vcpu->arch.tid = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2567 vcpu->arch.psscr = set_reg_val(id, *val) & PSSCR_GUEST_VIS; in kvmppc_set_one_reg_hv()
2571 r = -EINVAL; in kvmppc_set_one_reg_hv()
2572 if (!addr && (vcpu->arch.slb_shadow.next_gpa || in kvmppc_set_one_reg_hv()
2573 vcpu->arch.dtl.next_gpa)) in kvmppc_set_one_reg_hv()
2575 r = set_vpa(vcpu, &vcpu->arch.vpa, addr, sizeof(struct lppaca)); in kvmppc_set_one_reg_hv()
2578 addr = val->vpaval.addr; in kvmppc_set_one_reg_hv()
2579 len = val->vpaval.length; in kvmppc_set_one_reg_hv()
2580 r = -EINVAL; in kvmppc_set_one_reg_hv()
2581 if (addr && !vcpu->arch.vpa.next_gpa) in kvmppc_set_one_reg_hv()
2583 r = set_vpa(vcpu, &vcpu->arch.slb_shadow, addr, len); in kvmppc_set_one_reg_hv()
2586 addr = val->vpaval.addr; in kvmppc_set_one_reg_hv()
2587 len = val->vpaval.length; in kvmppc_set_one_reg_hv()
2588 r = -EINVAL; in kvmppc_set_one_reg_hv()
2590 !vcpu->arch.vpa.next_gpa)) in kvmppc_set_one_reg_hv()
2592 len -= len % sizeof(struct dtl_entry); in kvmppc_set_one_reg_hv()
2593 r = set_vpa(vcpu, &vcpu->arch.dtl, addr, len); in kvmppc_set_one_reg_hv()
2608 if (!vcpu->arch.dec_expires && tb_offset) in kvmppc_set_one_reg_hv()
2609 vcpu->arch.dec_expires = get_tb() + tb_offset; in kvmppc_set_one_reg_hv()
2611 vcpu->arch.vcore->tb_offset = tb_offset; in kvmppc_set_one_reg_hv()
2625 vcpu->arch.tfhar = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2628 vcpu->arch.tfiar = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2631 vcpu->arch.texasr = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2634 i = id - KVM_REG_PPC_TM_GPR0; in kvmppc_set_one_reg_hv()
2635 vcpu->arch.gpr_tm[i] = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2640 i = id - KVM_REG_PPC_TM_VSR0; in kvmppc_set_one_reg_hv()
2643 vcpu->arch.fp_tm.fpr[i][j] = val->vsxval[j]; in kvmppc_set_one_reg_hv()
2646 vcpu->arch.vr_tm.vr[i-32] = val->vval; in kvmppc_set_one_reg_hv()
2648 r = -ENXIO; in kvmppc_set_one_reg_hv()
2652 vcpu->arch.cr_tm = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2655 vcpu->arch.xer_tm = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2658 vcpu->arch.lr_tm = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2661 vcpu->arch.ctr_tm = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2664 vcpu->arch.fp_tm.fpscr = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2667 vcpu->arch.amr_tm = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2670 vcpu->arch.ppr_tm = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2673 vcpu->arch.vrsave_tm = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2677 vcpu->arch.vr.vscr.u[3] = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2679 r = - ENXIO; in kvmppc_set_one_reg_hv()
2682 vcpu->arch.dscr_tm = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2685 vcpu->arch.tar_tm = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2692 vcpu->arch.dec_expires = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2696 if (i && !vcpu->arch.online) in kvmppc_set_one_reg_hv()
2697 atomic_inc(&vcpu->arch.vcore->online_count); in kvmppc_set_one_reg_hv()
2698 else if (!i && vcpu->arch.online) in kvmppc_set_one_reg_hv()
2699 atomic_dec(&vcpu->arch.vcore->online_count); in kvmppc_set_one_reg_hv()
2700 vcpu->arch.online = i; in kvmppc_set_one_reg_hv()
2703 vcpu->kvm->arch.l1_ptcr = set_reg_val(id, *val); in kvmppc_set_one_reg_hv()
2709 r = -EINVAL; in kvmppc_set_one_reg_hv()
2739 spin_lock_init(&vcore->lock); in kvmppc_vcore_create()
2740 spin_lock_init(&vcore->stoltb_lock); in kvmppc_vcore_create()
2741 rcuwait_init(&vcore->wait); in kvmppc_vcore_create()
2742 vcore->preempt_tb = TB_NIL; in kvmppc_vcore_create()
2743 vcore->lpcr = kvm->arch.lpcr; in kvmppc_vcore_create()
2744 vcore->first_vcpuid = id; in kvmppc_vcore_create()
2745 vcore->kvm = kvm; in kvmppc_vcore_create()
2746 INIT_LIST_HEAD(&vcore->preempt_list); in kvmppc_vcore_create()
2783 struct kvm_vcpu *vcpu = inode->i_private; in debugfs_timings_open()
2788 return -ENOMEM; in debugfs_timings_open()
2790 kvm_get_kvm(vcpu->kvm); in debugfs_timings_open()
2791 p->vcpu = vcpu; in debugfs_timings_open()
2792 file->private_data = p; in debugfs_timings_open()
2799 struct debugfs_timings_state *p = file->private_data; in debugfs_timings_release()
2801 kvm_put_kvm(p->vcpu->kvm); in debugfs_timings_release()
2809 struct debugfs_timings_state *p = file->private_data; in debugfs_timings_read()
2810 struct kvm_vcpu *vcpu = p->vcpu; in debugfs_timings_read()
2819 if (!p->buflen) { in debugfs_timings_read()
2820 s = p->buf; in debugfs_timings_read()
2821 buf_end = s + sizeof(p->buf); in debugfs_timings_read()
2829 count = acc->seqcount; in debugfs_timings_read()
2834 if (count == acc->seqcount) { in debugfs_timings_read()
2842 snprintf(s, buf_end - s, "%s: stuck\n", in debugfs_timings_read()
2845 snprintf(s, buf_end - s, in debugfs_timings_read()
2853 p->buflen = s - p->buf; in debugfs_timings_read()
2857 if (pos >= p->buflen) in debugfs_timings_read()
2859 if (len > p->buflen - pos) in debugfs_timings_read()
2860 len = p->buflen - pos; in debugfs_timings_read()
2861 n = copy_to_user(buf, p->buf + pos, len); in debugfs_timings_read()
2864 return -EFAULT; in debugfs_timings_read()
2865 len -= n; in debugfs_timings_read()
2874 return -EACCES; in debugfs_timings_write()
2910 kvm = vcpu->kvm; in kvmppc_core_vcpu_create_hv()
2911 id = vcpu->vcpu_id; in kvmppc_core_vcpu_create_hv()
2913 vcpu->arch.shared = &vcpu->arch.shregs; in kvmppc_core_vcpu_create_hv()
2920 vcpu->arch.shared_big_endian = true; in kvmppc_core_vcpu_create_hv()
2922 vcpu->arch.shared_big_endian = false; in kvmppc_core_vcpu_create_hv()
2935 spin_lock_init(&vcpu->arch.vpa_update_lock); in kvmppc_core_vcpu_create_hv()
2936 spin_lock_init(&vcpu->arch.tbacct_lock); in kvmppc_core_vcpu_create_hv()
2937 vcpu->arch.busy_preempt = TB_NIL; in kvmppc_core_vcpu_create_hv()
2939 vcpu->arch.intr_msr = MSR_SF | MSR_ME; in kvmppc_core_vcpu_create_hv()
2964 vcpu->arch.hfscr |= HFSCR_TM; in kvmppc_core_vcpu_create_hv()
2966 vcpu->arch.hfscr_permitted = kvmppc_get_hfscr_hv(vcpu); in kvmppc_core_vcpu_create_hv()
2969 * PM, EBB, TM are demand-faulted so start with it clear. in kvmppc_core_vcpu_create_hv()
2975 vcpu->arch.state = KVMPPC_VCPU_NOTREADY; in kvmppc_core_vcpu_create_hv()
2977 init_waitqueue_head(&vcpu->arch.cpu_run); in kvmppc_core_vcpu_create_hv()
2979 mutex_lock(&kvm->lock); in kvmppc_core_vcpu_create_hv()
2981 err = -EINVAL; in kvmppc_core_vcpu_create_hv()
2983 if (id >= (KVM_MAX_VCPUS * kvm->arch.emul_smt_mode)) { in kvmppc_core_vcpu_create_hv()
2987 BUG_ON(kvm->arch.smt_mode != 1); in kvmppc_core_vcpu_create_hv()
2991 core = id / kvm->arch.smt_mode; in kvmppc_core_vcpu_create_hv()
2994 vcore = kvm->arch.vcores[core]; in kvmppc_core_vcpu_create_hv()
3003 err = -ENOMEM; in kvmppc_core_vcpu_create_hv()
3005 id & ~(kvm->arch.smt_mode - 1)); in kvmppc_core_vcpu_create_hv()
3006 mutex_lock(&kvm->arch.mmu_setup_lock); in kvmppc_core_vcpu_create_hv()
3007 kvm->arch.vcores[core] = vcore; in kvmppc_core_vcpu_create_hv()
3008 kvm->arch.online_vcores++; in kvmppc_core_vcpu_create_hv()
3009 mutex_unlock(&kvm->arch.mmu_setup_lock); in kvmppc_core_vcpu_create_hv()
3012 mutex_unlock(&kvm->lock); in kvmppc_core_vcpu_create_hv()
3017 spin_lock(&vcore->lock); in kvmppc_core_vcpu_create_hv()
3018 ++vcore->num_threads; in kvmppc_core_vcpu_create_hv()
3019 spin_unlock(&vcore->lock); in kvmppc_core_vcpu_create_hv()
3020 vcpu->arch.vcore = vcore; in kvmppc_core_vcpu_create_hv()
3021 vcpu->arch.ptid = vcpu->vcpu_id - vcore->first_vcpuid; in kvmppc_core_vcpu_create_hv()
3022 vcpu->arch.thread_cpu = -1; in kvmppc_core_vcpu_create_hv()
3023 vcpu->arch.prev_cpu = -1; in kvmppc_core_vcpu_create_hv()
3025 vcpu->arch.cpu_type = KVM_CPU_3S_64; in kvmppc_core_vcpu_create_hv()
3038 return -EINVAL; in kvmhv_set_smt_mode()
3040 return -EINVAL; in kvmhv_set_smt_mode()
3047 return -EINVAL; in kvmhv_set_smt_mode()
3056 mutex_lock(&kvm->lock); in kvmhv_set_smt_mode()
3057 err = -EBUSY; in kvmhv_set_smt_mode()
3058 if (!kvm->arch.online_vcores) { in kvmhv_set_smt_mode()
3059 kvm->arch.smt_mode = smt_mode; in kvmhv_set_smt_mode()
3060 kvm->arch.emul_smt_mode = esmt; in kvmhv_set_smt_mode()
3063 mutex_unlock(&kvm->lock); in kvmhv_set_smt_mode()
3070 if (vpa->pinned_addr) in unpin_vpa()
3071 kvmppc_unpin_guest_page(kvm, vpa->pinned_addr, vpa->gpa, in unpin_vpa()
3072 vpa->dirty); in unpin_vpa()
3077 spin_lock(&vcpu->arch.vpa_update_lock); in kvmppc_core_vcpu_free_hv()
3078 unpin_vpa(vcpu->kvm, &vcpu->arch.dtl); in kvmppc_core_vcpu_free_hv()
3079 unpin_vpa(vcpu->kvm, &vcpu->arch.slb_shadow); in kvmppc_core_vcpu_free_hv()
3080 unpin_vpa(vcpu->kvm, &vcpu->arch.vpa); in kvmppc_core_vcpu_free_hv()
3081 spin_unlock(&vcpu->arch.vpa_update_lock); in kvmppc_core_vcpu_free_hv()
3101 dec_nsec = tb_to_ns(kvmppc_dec_expires_host_tb(vcpu) - now); in kvmppc_set_timer()
3102 hrtimer_start(&vcpu->arch.dec_timer, dec_nsec, HRTIMER_MODE_REL); in kvmppc_set_timer()
3103 vcpu->arch.timer_running = 1; in kvmppc_set_timer()
3113 if (vcpu->arch.state != KVMPPC_VCPU_RUNNABLE) in kvmppc_remove_runnable()
3115 spin_lock_irq(&vcpu->arch.tbacct_lock); in kvmppc_remove_runnable()
3117 vcpu->arch.busy_stolen += vcore_stolen_time(vc, now) - in kvmppc_remove_runnable()
3118 vcpu->arch.stolen_logged; in kvmppc_remove_runnable()
3119 vcpu->arch.busy_preempt = now; in kvmppc_remove_runnable()
3120 vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST; in kvmppc_remove_runnable()
3121 spin_unlock_irq(&vcpu->arch.tbacct_lock); in kvmppc_remove_runnable()
3122 --vc->n_runnable; in kvmppc_remove_runnable()
3123 WRITE_ONCE(vc->runnable_threads[vcpu->arch.ptid], NULL); in kvmppc_remove_runnable()
3134 tpaca->kvm_hstate.kvm_vcpu = NULL; in kvmppc_grab_hwthread()
3135 tpaca->kvm_hstate.kvm_vcore = NULL; in kvmppc_grab_hwthread()
3136 tpaca->kvm_hstate.napping = 0; in kvmppc_grab_hwthread()
3138 tpaca->kvm_hstate.hwthread_req = 1; in kvmppc_grab_hwthread()
3150 while (tpaca->kvm_hstate.hwthread_state == KVM_HWTHREAD_IN_KERNEL) { in kvmppc_grab_hwthread()
3151 if (--timeout <= 0) { in kvmppc_grab_hwthread()
3153 return -EBUSY; in kvmppc_grab_hwthread()
3165 tpaca->kvm_hstate.hwthread_req = 0; in kvmppc_release_hwthread()
3166 tpaca->kvm_hstate.kvm_vcpu = NULL; in kvmppc_release_hwthread()
3167 tpaca->kvm_hstate.kvm_vcore = NULL; in kvmppc_release_hwthread()
3168 tpaca->kvm_hstate.kvm_split_mode = NULL; in kvmppc_release_hwthread()
3175 struct kvm_nested_guest *nested = vcpu->arch.nested; in radix_flush_cpu()
3180 need_tlb_flush = &nested->need_tlb_flush; in radix_flush_cpu()
3182 need_tlb_flush = &kvm->arch.need_tlb_flush; in radix_flush_cpu()
3210 struct kvm *kvm = vcpu->kvm; in do_migrate_away_vcpu()
3220 if (kvm->arch.lpcr & LPCR_GTSE) in do_migrate_away_vcpu()
3228 struct kvm_nested_guest *nested = vcpu->arch.nested; in kvmppc_prepare_radix_vcpu()
3229 struct kvm *kvm = vcpu->kvm; in kvmppc_prepare_radix_vcpu()
3236 prev_cpu = nested->prev_cpu[vcpu->arch.nested_vcpu_id]; in kvmppc_prepare_radix_vcpu()
3238 prev_cpu = vcpu->arch.prev_cpu; in kvmppc_prepare_radix_vcpu()
3261 nested->prev_cpu[vcpu->arch.nested_vcpu_id] = pcpu; in kvmppc_prepare_radix_vcpu()
3263 vcpu->arch.prev_cpu = pcpu; in kvmppc_prepare_radix_vcpu()
3272 cpu = vc->pcpu; in kvmppc_start_thread()
3274 if (vcpu->arch.timer_running) { in kvmppc_start_thread()
3275 hrtimer_try_to_cancel(&vcpu->arch.dec_timer); in kvmppc_start_thread()
3276 vcpu->arch.timer_running = 0; in kvmppc_start_thread()
3278 cpu += vcpu->arch.ptid; in kvmppc_start_thread()
3279 vcpu->cpu = vc->pcpu; in kvmppc_start_thread()
3280 vcpu->arch.thread_cpu = cpu; in kvmppc_start_thread()
3283 tpaca->kvm_hstate.kvm_vcpu = vcpu; in kvmppc_start_thread()
3284 tpaca->kvm_hstate.ptid = cpu - vc->pcpu; in kvmppc_start_thread()
3285 tpaca->kvm_hstate.fake_suspend = 0; in kvmppc_start_thread()
3288 tpaca->kvm_hstate.kvm_vcore = vc; in kvmppc_start_thread()
3305 * for any threads that still have a non-NULL vcore ptr. in kvmppc_wait_for_nap()
3308 if (paca_ptrs[cpu + i]->kvm_hstate.kvm_vcore) in kvmppc_wait_for_nap()
3318 if (paca_ptrs[cpu + i]->kvm_hstate.kvm_vcore) in kvmppc_wait_for_nap()
3324 * this core are off-line. Then grab the threads so they can't
3347 } while (--thr > 0); in on_primary_thread()
3372 spin_lock_init(&lp->lock); in init_vcore_lists()
3373 INIT_LIST_HEAD(&lp->list); in init_vcore_lists()
3383 vc->vcore_state = VCORE_PREEMPT; in kvmppc_vcore_preempt()
3384 vc->pcpu = smp_processor_id(); in kvmppc_vcore_preempt()
3385 if (vc->num_threads < threads_per_vcore(vc->kvm)) { in kvmppc_vcore_preempt()
3386 spin_lock(&lp->lock); in kvmppc_vcore_preempt()
3387 list_add_tail(&vc->preempt_list, &lp->list); in kvmppc_vcore_preempt()
3388 spin_unlock(&lp->lock); in kvmppc_vcore_preempt()
3402 if (!list_empty(&vc->preempt_list)) { in kvmppc_vcore_end_preempt()
3403 lp = &per_cpu(preempted_vcores, vc->pcpu); in kvmppc_vcore_end_preempt()
3404 spin_lock(&lp->lock); in kvmppc_vcore_end_preempt()
3405 list_del_init(&vc->preempt_list); in kvmppc_vcore_end_preempt()
3406 spin_unlock(&lp->lock); in kvmppc_vcore_end_preempt()
3408 vc->vcore_state = VCORE_INACTIVE; in kvmppc_vcore_end_preempt()
3424 * This mapping means subcores 0 and 1 can use threads 0-3 and 4-7
3425 * respectively in 2-way micro-threading (split-core) mode on POWER8.
3432 cip->n_subcores = 1; in init_core_info()
3433 cip->max_subcore_threads = vc->num_threads; in init_core_info()
3434 cip->total_threads = vc->num_threads; in init_core_info()
3435 cip->subcore_threads[0] = vc->num_threads; in init_core_info()
3436 cip->vc[0] = vc; in init_core_info()
3442 * POWER9 "SMT4" cores are permanently in what is effectively a 4-way in subcore_config_ok()
3443 * split-core mode, with one thread per subcore. in subcore_config_ok()
3465 vc->entry_exit_map = 0; in init_vcore_to_run()
3466 vc->in_guest = 0; in init_vcore_to_run()
3467 vc->napping_threads = 0; in init_vcore_to_run()
3468 vc->conferring_threads = 0; in init_vcore_to_run()
3469 vc->tb_offset_applied = 0; in init_vcore_to_run()
3474 int n_threads = vc->num_threads; in can_dynamic_split()
3481 if (one_vm_per_core && vc->kvm != cip->vc[0]->kvm) in can_dynamic_split()
3484 if (n_threads < cip->max_subcore_threads) in can_dynamic_split()
3485 n_threads = cip->max_subcore_threads; in can_dynamic_split()
3486 if (!subcore_config_ok(cip->n_subcores + 1, n_threads)) in can_dynamic_split()
3488 cip->max_subcore_threads = n_threads; in can_dynamic_split()
3490 sub = cip->n_subcores; in can_dynamic_split()
3491 ++cip->n_subcores; in can_dynamic_split()
3492 cip->total_threads += vc->num_threads; in can_dynamic_split()
3493 cip->subcore_threads[sub] = vc->num_threads; in can_dynamic_split()
3494 cip->vc[sub] = vc; in can_dynamic_split()
3496 list_del_init(&vc->preempt_list); in can_dynamic_split()
3508 if (cip->total_threads + pvc->num_threads > target_threads) in can_piggyback()
3520 if (signal_pending(vcpu->arch.run_task)) in prepare_threads()
3521 vcpu->arch.ret = -EINTR; in prepare_threads()
3522 else if (vcpu->arch.vpa.update_pending || in prepare_threads()
3523 vcpu->arch.slb_shadow.update_pending || in prepare_threads()
3524 vcpu->arch.dtl.update_pending) in prepare_threads()
3525 vcpu->arch.ret = RESUME_GUEST; in prepare_threads()
3529 wake_up(&vcpu->arch.cpu_run); in prepare_threads()
3538 spin_lock(&lp->lock); in collect_piggybacks()
3539 list_for_each_entry_safe(pvc, vcnext, &lp->list, preempt_list) { in collect_piggybacks()
3540 if (!spin_trylock(&pvc->lock)) in collect_piggybacks()
3543 if (!pvc->n_runnable || !pvc->kvm->arch.mmu_ready) { in collect_piggybacks()
3544 list_del_init(&pvc->preempt_list); in collect_piggybacks()
3545 if (pvc->runner == NULL) { in collect_piggybacks()
3546 pvc->vcore_state = VCORE_INACTIVE; in collect_piggybacks()
3549 spin_unlock(&pvc->lock); in collect_piggybacks()
3553 spin_unlock(&pvc->lock); in collect_piggybacks()
3557 pvc->vcore_state = VCORE_PIGGYBACK; in collect_piggybacks()
3558 if (cip->total_threads >= target_threads) in collect_piggybacks()
3561 spin_unlock(&lp->lock); in collect_piggybacks()
3570 for (sub = 0; sub < cip->n_subcores; ++sub) { in recheck_signals_and_mmu()
3571 vc = cip->vc[sub]; in recheck_signals_and_mmu()
3572 if (!vc->kvm->arch.mmu_ready) in recheck_signals_and_mmu()
3575 if (signal_pending(vcpu->arch.run_task)) in recheck_signals_and_mmu()
3588 spin_lock(&vc->lock); in post_guest_process()
3598 spin_unlock(&vc->lock); in post_guest_process()
3607 if (vcpu->arch.trap) in post_guest_process()
3609 vcpu->arch.run_task); in post_guest_process()
3611 vcpu->arch.ret = ret; in post_guest_process()
3612 vcpu->arch.trap = 0; in post_guest_process()
3614 spin_lock(&vc->lock); in post_guest_process()
3615 if (is_kvmppc_resume_guest(vcpu->arch.ret)) { in post_guest_process()
3616 if (vcpu->arch.pending_exceptions) in post_guest_process()
3618 if (vcpu->arch.ceded) in post_guest_process()
3624 wake_up(&vcpu->arch.cpu_run); in post_guest_process()
3630 } else if (vc->runner) { in post_guest_process()
3631 vc->vcore_state = VCORE_PREEMPT; in post_guest_process()
3634 vc->vcore_state = VCORE_INACTIVE; in post_guest_process()
3636 if (vc->n_runnable > 0 && vc->runner == NULL) { in post_guest_process()
3638 i = -1; in post_guest_process()
3640 wake_up(&vcpu->arch.cpu_run); in post_guest_process()
3643 spin_unlock(&vc->lock); in post_guest_process()
3663 kvmppc_host_rm_ops_hv->rm_core[core].rm_state.in_host = 0; in kvmppc_clear_host_core()
3684 kvmppc_host_rm_ops_hv->rm_core[core].rm_state.in_host = 1; in kvmppc_set_host_core()
3692 local_paca->irq_happened |= PACA_IRQ_EE; in set_irq_happened()
3695 local_paca->irq_happened |= PACA_IRQ_DBELL; in set_irq_happened()
3698 local_paca->irq_happened |= PACA_IRQ_HMI; in set_irq_happened()
3708 * Called with vc->lock held.
3738 if (vc->runner->arch.state != KVMPPC_VCPU_RUNNABLE) in kvmppc_run_core()
3745 vc->preempt_tb = TB_NIL; in kvmppc_run_core()
3752 controlled_threads = threads_per_vcore(vc->kvm); in kvmppc_run_core()
3760 ((vc->num_threads > threads_per_subcore) || !on_primary_thread())) { in kvmppc_run_core()
3762 vcpu->arch.ret = -EBUSY; in kvmppc_run_core()
3764 wake_up(&vcpu->arch.cpu_run); in kvmppc_run_core()
3778 if (vc->num_threads < target_threads) in kvmppc_run_core()
3782 * Hard-disable interrupts, and check resched flag and signals. in kvmppc_run_core()
3793 vc->vcore_state = VCORE_INACTIVE; in kvmppc_run_core()
3799 spin_unlock(&pvc->lock); in kvmppc_run_core()
3808 /* Decide on micro-threading (split-core) mode */ in kvmppc_run_core()
3846 paca->kvm_hstate.napping = 0; in kvmppc_run_core()
3847 paca->kvm_hstate.kvm_split_mode = sip; in kvmppc_run_core()
3850 /* Initiate micro-threading (split-core) on POWER8 if required */ in kvmppc_run_core()
3873 int n_online = atomic_read(&vc->online_count); in kvmppc_run_core()
3876 * Use the 8-thread value if we're doing split-core in kvmppc_run_core()
3892 pvc->pcpu = pcpu + thr; in kvmppc_run_core()
3896 * It updates vcpu->cpu and vcpu->arch.thread_cpu in kvmppc_run_core()
3905 if (!vcpu->arch.ptid) in kvmppc_run_core()
3907 active |= 1 << (thr + vcpu->arch.ptid); in kvmppc_run_core()
3924 * When doing micro-threading, poke the inactive threads as well. in kvmppc_run_core()
3935 vc->vcore_state = VCORE_RUNNING; in kvmppc_run_core()
3941 spin_unlock(&core_info.vc[sub]->lock); in kvmppc_run_core()
3945 srcu_idx = srcu_read_lock(&vc->kvm->srcu); in kvmppc_run_core()
3955 srcu_read_unlock(&vc->kvm->srcu, srcu_idx); in kvmppc_run_core()
3959 spin_lock(&vc->lock); in kvmppc_run_core()
3961 vc->vcore_state = VCORE_EXITING; in kvmppc_run_core()
3966 /* Return to whole-core mode if we split the core earlier */ in kvmppc_run_core()
3991 * Service IRQs here before guest_timing_exit_irqoff() so any in kvmppc_run_core()
4007 if (sip && sip->napped[i]) in kvmppc_run_core()
4011 spin_unlock(&vc->lock); in kvmppc_run_core()
4023 spin_lock(&vc->lock); in kvmppc_run_core()
4026 vc->vcore_state = VCORE_INACTIVE; in kvmppc_run_core()
4038 struct lppaca *lp = vcpu->arch.vpa.pinned_addr; in vcpu_vpa_increment_dispatch()
4040 u32 yield_count = be32_to_cpu(lp->yield_count) + 1; in vcpu_vpa_increment_dispatch()
4041 lp->yield_count = cpu_to_be32(yield_count); in vcpu_vpa_increment_dispatch()
4042 vcpu->arch.vpa.dirty = 1; in vcpu_vpa_increment_dispatch()
4049 struct kvmppc_vcore *vc = vcpu->arch.vcore; in kvmhv_vcpu_entry_p9_nested()
4076 if (vcpu->arch.psscr != host_psscr) in kvmhv_vcpu_entry_p9_nested()
4077 mtspr(SPRN_PSSCR_PR, vcpu->arch.psscr); in kvmhv_vcpu_entry_p9_nested()
4082 vcpu->arch.regs.msr = vcpu->arch.shregs.msr; in kvmhv_vcpu_entry_p9_nested()
4084 if (vcpu->arch.nested) { in kvmhv_vcpu_entry_p9_nested()
4085 hvregs.lpid = vcpu->arch.nested->shadow_lpid; in kvmhv_vcpu_entry_p9_nested()
4086 hvregs.vcpu_token = vcpu->arch.nested_vcpu_id; in kvmhv_vcpu_entry_p9_nested()
4088 hvregs.lpid = vcpu->kvm->arch.lpid; in kvmhv_vcpu_entry_p9_nested()
4089 hvregs.vcpu_token = vcpu->vcpu_id; in kvmhv_vcpu_entry_p9_nested()
4099 if (vcpu->arch.doorbell_request) in kvmhv_vcpu_entry_p9_nested()
4100 vcpu->arch.doorbell_request = 0; in kvmhv_vcpu_entry_p9_nested()
4116 mtspr(SPRN_DEC, kvmppc_dec_expires_host_tb(vcpu) - *tb); in kvmhv_vcpu_entry_p9_nested()
4118 mtspr(SPRN_DAR, vcpu->arch.shregs.dar); in kvmhv_vcpu_entry_p9_nested()
4119 mtspr(SPRN_DSISR, vcpu->arch.shregs.dsisr); in kvmhv_vcpu_entry_p9_nested()
4121 accumulate_time(vcpu, &vcpu->arch.in_guest); in kvmhv_vcpu_entry_p9_nested()
4123 __pa(&vcpu->arch.regs)); in kvmhv_vcpu_entry_p9_nested()
4124 accumulate_time(vcpu, &vcpu->arch.guest_exit); in kvmhv_vcpu_entry_p9_nested()
4127 vcpu->arch.shregs.msr = vcpu->arch.regs.msr; in kvmhv_vcpu_entry_p9_nested()
4128 vcpu->arch.shregs.dar = mfspr(SPRN_DAR); in kvmhv_vcpu_entry_p9_nested()
4129 vcpu->arch.shregs.dsisr = mfspr(SPRN_DSISR); in kvmhv_vcpu_entry_p9_nested()
4130 vcpu->arch.psscr = mfspr(SPRN_PSSCR_PR); in kvmhv_vcpu_entry_p9_nested()
4138 vcpu->arch.dec_expires = dec + (*tb + vc->tb_offset); in kvmhv_vcpu_entry_p9_nested()
4143 if (vcpu->arch.psscr != host_psscr) in kvmhv_vcpu_entry_p9_nested()
4155 struct kvm *kvm = vcpu->kvm; in kvmhv_p9_guest_entry()
4156 struct kvm_nested_guest *nested = vcpu->arch.nested; in kvmhv_p9_guest_entry()
4168 vcpu->arch.ceded = 0; in kvmhv_p9_guest_entry()
4212 vcpu->arch.ceded = 0; in kvmhv_p9_guest_entry()
4244 vcpu->arch.slb_max = 0; in kvmhv_p9_guest_entry()
4261 prepare_to_wait(&vcpu->arch.cpu_run, &wait, wait_state); in kvmppc_wait_for_exec()
4262 if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) { in kvmppc_wait_for_exec()
4263 spin_unlock(&vc->lock); in kvmppc_wait_for_exec()
4265 spin_lock(&vc->lock); in kvmppc_wait_for_exec()
4267 finish_wait(&vcpu->arch.cpu_run, &wait); in kvmppc_wait_for_exec()
4275 vc->halt_poll_ns *= halt_poll_ns_grow; in grow_halt_poll_ns()
4276 if (vc->halt_poll_ns < halt_poll_ns_grow_start) in grow_halt_poll_ns()
4277 vc->halt_poll_ns = halt_poll_ns_grow_start; in grow_halt_poll_ns()
4283 vc->halt_poll_ns = 0; in shrink_halt_poll_ns()
4285 vc->halt_poll_ns /= halt_poll_ns_shrink; in shrink_halt_poll_ns()
4293 return vcpu->arch.irq_pending || vcpu->arch.xive_saved_state.pipr < in xive_interrupt_pending()
4294 vcpu->arch.xive_saved_state.cppr; in xive_interrupt_pending()
4305 if (vcpu->arch.pending_exceptions || vcpu->arch.prodded || in kvmppc_vcpu_woken()
4314 if (!vcpu->arch.ceded || kvmppc_vcpu_woken(vcpu)) in kvmppc_vcpu_check_block()
4338 * or external interrupt to one of the vcpus. vc->lock is held.
4350 if (vc->halt_poll_ns) { in kvmppc_vcore_blocked()
4351 ktime_t stop = ktime_add_ns(start_poll, vc->halt_poll_ns); in kvmppc_vcore_blocked()
4352 ++vc->runner->stat.generic.halt_attempted_poll; in kvmppc_vcore_blocked()
4354 vc->vcore_state = VCORE_POLLING; in kvmppc_vcore_blocked()
4355 spin_unlock(&vc->lock); in kvmppc_vcore_blocked()
4365 spin_lock(&vc->lock); in kvmppc_vcore_blocked()
4366 vc->vcore_state = VCORE_INACTIVE; in kvmppc_vcore_blocked()
4369 ++vc->runner->stat.generic.halt_successful_poll; in kvmppc_vcore_blocked()
4374 prepare_to_rcuwait(&vc->wait); in kvmppc_vcore_blocked()
4377 finish_rcuwait(&vc->wait); in kvmppc_vcore_blocked()
4380 if (vc->halt_poll_ns) in kvmppc_vcore_blocked()
4381 ++vc->runner->stat.generic.halt_successful_poll; in kvmppc_vcore_blocked()
4387 vc->vcore_state = VCORE_SLEEPING; in kvmppc_vcore_blocked()
4388 trace_kvmppc_vcore_blocked(vc->runner, 0); in kvmppc_vcore_blocked()
4389 spin_unlock(&vc->lock); in kvmppc_vcore_blocked()
4391 finish_rcuwait(&vc->wait); in kvmppc_vcore_blocked()
4392 spin_lock(&vc->lock); in kvmppc_vcore_blocked()
4393 vc->vcore_state = VCORE_INACTIVE; in kvmppc_vcore_blocked()
4394 trace_kvmppc_vcore_blocked(vc->runner, 1); in kvmppc_vcore_blocked()
4395 ++vc->runner->stat.halt_successful_wait; in kvmppc_vcore_blocked()
4400 block_ns = ktime_to_ns(cur) - ktime_to_ns(start_poll); in kvmppc_vcore_blocked()
4404 vc->runner->stat.generic.halt_wait_ns += in kvmppc_vcore_blocked()
4405 ktime_to_ns(cur) - ktime_to_ns(start_wait); in kvmppc_vcore_blocked()
4407 vc->runner->stat.generic.halt_wait_hist, in kvmppc_vcore_blocked()
4408 ktime_to_ns(cur) - ktime_to_ns(start_wait)); in kvmppc_vcore_blocked()
4410 if (vc->halt_poll_ns) { in kvmppc_vcore_blocked()
4411 vc->runner->stat.generic.halt_poll_fail_ns += in kvmppc_vcore_blocked()
4412 ktime_to_ns(start_wait) - in kvmppc_vcore_blocked()
4415 vc->runner->stat.generic.halt_poll_fail_hist, in kvmppc_vcore_blocked()
4416 ktime_to_ns(start_wait) - in kvmppc_vcore_blocked()
4421 if (vc->halt_poll_ns) { in kvmppc_vcore_blocked()
4422 vc->runner->stat.generic.halt_poll_success_ns += in kvmppc_vcore_blocked()
4423 ktime_to_ns(cur) - in kvmppc_vcore_blocked()
4426 vc->runner->stat.generic.halt_poll_success_hist, in kvmppc_vcore_blocked()
4427 ktime_to_ns(cur) - ktime_to_ns(start_poll)); in kvmppc_vcore_blocked()
4433 if (block_ns <= vc->halt_poll_ns) in kvmppc_vcore_blocked()
4436 else if (vc->halt_poll_ns && block_ns > halt_poll_ns) in kvmppc_vcore_blocked()
4439 else if (vc->halt_poll_ns < halt_poll_ns && in kvmppc_vcore_blocked()
4442 if (vc->halt_poll_ns > halt_poll_ns) in kvmppc_vcore_blocked()
4443 vc->halt_poll_ns = halt_poll_ns; in kvmppc_vcore_blocked()
4445 vc->halt_poll_ns = 0; in kvmppc_vcore_blocked()
4457 struct kvm *kvm = vcpu->kvm; in kvmhv_setup_mmu()
4459 mutex_lock(&kvm->arch.mmu_setup_lock); in kvmhv_setup_mmu()
4460 if (!kvm->arch.mmu_ready) { in kvmhv_setup_mmu()
4466 kvm->arch.mmu_ready = 1; in kvmhv_setup_mmu()
4469 mutex_unlock(&kvm->arch.mmu_setup_lock); in kvmhv_setup_mmu()
4475 struct kvm_run *run = vcpu->run; in kvmppc_run_vcpu()
4482 run->exit_reason = 0; in kvmppc_run_vcpu()
4483 vcpu->arch.ret = RESUME_GUEST; in kvmppc_run_vcpu()
4484 vcpu->arch.trap = 0; in kvmppc_run_vcpu()
4490 vc = vcpu->arch.vcore; in kvmppc_run_vcpu()
4491 spin_lock(&vc->lock); in kvmppc_run_vcpu()
4492 vcpu->arch.ceded = 0; in kvmppc_run_vcpu()
4493 vcpu->arch.run_task = current; in kvmppc_run_vcpu()
4494 vcpu->arch.stolen_logged = vcore_stolen_time(vc, mftb()); in kvmppc_run_vcpu()
4495 vcpu->arch.state = KVMPPC_VCPU_RUNNABLE; in kvmppc_run_vcpu()
4496 vcpu->arch.busy_preempt = TB_NIL; in kvmppc_run_vcpu()
4497 WRITE_ONCE(vc->runnable_threads[vcpu->arch.ptid], vcpu); in kvmppc_run_vcpu()
4498 ++vc->n_runnable; in kvmppc_run_vcpu()
4506 if ((vc->vcore_state == VCORE_PIGGYBACK || in kvmppc_run_vcpu()
4507 vc->vcore_state == VCORE_RUNNING) && in kvmppc_run_vcpu()
4512 } else if (vc->vcore_state == VCORE_SLEEPING) { in kvmppc_run_vcpu()
4513 rcuwait_wake_up(&vc->wait); in kvmppc_run_vcpu()
4518 while (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE && in kvmppc_run_vcpu()
4521 if (!vcpu->kvm->arch.mmu_ready) { in kvmppc_run_vcpu()
4522 spin_unlock(&vc->lock); in kvmppc_run_vcpu()
4524 spin_lock(&vc->lock); in kvmppc_run_vcpu()
4526 run->exit_reason = KVM_EXIT_FAIL_ENTRY; in kvmppc_run_vcpu()
4527 run->fail_entry. in kvmppc_run_vcpu()
4529 vcpu->arch.ret = r; in kvmppc_run_vcpu()
4534 if (vc->vcore_state == VCORE_PREEMPT && vc->runner == NULL) in kvmppc_run_vcpu()
4537 if (vc->vcore_state != VCORE_INACTIVE) { in kvmppc_run_vcpu()
4543 if (signal_pending(v->arch.run_task)) { in kvmppc_run_vcpu()
4545 v->stat.signal_exits++; in kvmppc_run_vcpu()
4546 v->run->exit_reason = KVM_EXIT_INTR; in kvmppc_run_vcpu()
4547 v->arch.ret = -EINTR; in kvmppc_run_vcpu()
4548 wake_up(&v->arch.cpu_run); in kvmppc_run_vcpu()
4551 if (!vc->n_runnable || vcpu->arch.state != KVMPPC_VCPU_RUNNABLE) in kvmppc_run_vcpu()
4556 n_ceded += v->arch.ceded; in kvmppc_run_vcpu()
4558 v->arch.ceded = 0; in kvmppc_run_vcpu()
4560 vc->runner = vcpu; in kvmppc_run_vcpu()
4561 if (n_ceded == vc->n_runnable) { in kvmppc_run_vcpu()
4566 cond_resched_lock(&vc->lock); in kvmppc_run_vcpu()
4567 if (vc->vcore_state == VCORE_PREEMPT) in kvmppc_run_vcpu()
4572 vc->runner = NULL; in kvmppc_run_vcpu()
4575 while (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE && in kvmppc_run_vcpu()
4576 (vc->vcore_state == VCORE_RUNNING || in kvmppc_run_vcpu()
4577 vc->vcore_state == VCORE_EXITING || in kvmppc_run_vcpu()
4578 vc->vcore_state == VCORE_PIGGYBACK)) in kvmppc_run_vcpu()
4581 if (vc->vcore_state == VCORE_PREEMPT && vc->runner == NULL) in kvmppc_run_vcpu()
4584 if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) { in kvmppc_run_vcpu()
4586 vcpu->stat.signal_exits++; in kvmppc_run_vcpu()
4587 run->exit_reason = KVM_EXIT_INTR; in kvmppc_run_vcpu()
4588 vcpu->arch.ret = -EINTR; in kvmppc_run_vcpu()
4591 if (vc->n_runnable && vc->vcore_state == VCORE_INACTIVE) { in kvmppc_run_vcpu()
4593 i = -1; in kvmppc_run_vcpu()
4595 wake_up(&v->arch.cpu_run); in kvmppc_run_vcpu()
4599 spin_unlock(&vc->lock); in kvmppc_run_vcpu()
4600 return vcpu->arch.ret; in kvmppc_run_vcpu()
4607 struct kvm_run *run = vcpu->run; in kvmhv_run_single_vcpu()
4611 struct kvm *kvm = vcpu->kvm; in kvmhv_run_single_vcpu()
4612 struct kvm_nested_guest *nested = vcpu->arch.nested; in kvmhv_run_single_vcpu()
4618 run->exit_reason = 0; in kvmhv_run_single_vcpu()
4619 vcpu->arch.ret = RESUME_GUEST; in kvmhv_run_single_vcpu()
4620 vcpu->arch.trap = 0; in kvmhv_run_single_vcpu()
4622 vc = vcpu->arch.vcore; in kvmhv_run_single_vcpu()
4623 vcpu->arch.ceded = 0; in kvmhv_run_single_vcpu()
4624 vcpu->arch.run_task = current; in kvmhv_run_single_vcpu()
4625 vcpu->arch.last_inst = KVM_INST_FETCH_FAILED; in kvmhv_run_single_vcpu()
4628 if (unlikely(!kvm->arch.mmu_ready)) { in kvmhv_run_single_vcpu()
4631 run->exit_reason = KVM_EXIT_FAIL_ENTRY; in kvmhv_run_single_vcpu()
4632 run->fail_entry.hardware_entry_failure_reason = 0; in kvmhv_run_single_vcpu()
4633 vcpu->arch.ret = r; in kvmhv_run_single_vcpu()
4651 vcpu->arch.state = KVMPPC_VCPU_RUNNABLE; in kvmhv_run_single_vcpu()
4655 if (need_resched() || !kvm->arch.mmu_ready) in kvmhv_run_single_vcpu()
4658 vcpu->cpu = pcpu; in kvmhv_run_single_vcpu()
4659 vcpu->arch.thread_cpu = pcpu; in kvmhv_run_single_vcpu()
4660 vc->pcpu = pcpu; in kvmhv_run_single_vcpu()
4661 local_paca->kvm_hstate.kvm_vcpu = vcpu; in kvmhv_run_single_vcpu()
4662 local_paca->kvm_hstate.ptid = 0; in kvmhv_run_single_vcpu()
4663 local_paca->kvm_hstate.fake_suspend = 0; in kvmhv_run_single_vcpu()
4676 &vcpu->arch.pending_exceptions) || in kvmhv_run_single_vcpu()
4689 } else if (vcpu->arch.pending_exceptions || in kvmhv_run_single_vcpu()
4691 vcpu->arch.ret = RESUME_HOST; in kvmhv_run_single_vcpu()
4695 if (vcpu->arch.timer_running) { in kvmhv_run_single_vcpu()
4696 hrtimer_try_to_cancel(&vcpu->arch.dec_timer); in kvmhv_run_single_vcpu()
4697 vcpu->arch.timer_running = 0; in kvmhv_run_single_vcpu()
4702 kvmppc_update_vpa_dispatch_p9(vcpu, vc, tb + vc->tb_offset); in kvmhv_run_single_vcpu()
4708 srcu_idx = srcu_read_lock(&kvm->srcu); in kvmhv_run_single_vcpu()
4714 vcpu->arch.trap = trap; in kvmhv_run_single_vcpu()
4719 srcu_read_unlock(&kvm->srcu, srcu_idx); in kvmhv_run_single_vcpu()
4723 vcpu->cpu = -1; in kvmhv_run_single_vcpu()
4724 vcpu->arch.thread_cpu = -1; in kvmhv_run_single_vcpu()
4725 vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST; in kvmhv_run_single_vcpu()
4730 * Service IRQs here before guest_timing_exit_irqoff() so any in kvmhv_run_single_vcpu()
4764 vcpu->arch.ret = r; in kvmhv_run_single_vcpu()
4773 vcpu->stat.signal_exits++; in kvmhv_run_single_vcpu()
4774 run->exit_reason = KVM_EXIT_INTR; in kvmhv_run_single_vcpu()
4775 vcpu->arch.ret = -EINTR; in kvmhv_run_single_vcpu()
4788 vcpu->arch.ceded = 0; in kvmhv_run_single_vcpu()
4793 return vcpu->arch.ret; in kvmhv_run_single_vcpu()
4796 vcpu->stat.signal_exits++; in kvmhv_run_single_vcpu()
4797 run->exit_reason = KVM_EXIT_INTR; in kvmhv_run_single_vcpu()
4798 vcpu->arch.ret = -EINTR; in kvmhv_run_single_vcpu()
4800 vcpu->cpu = -1; in kvmhv_run_single_vcpu()
4801 vcpu->arch.thread_cpu = -1; in kvmhv_run_single_vcpu()
4802 vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST; in kvmhv_run_single_vcpu()
4810 struct kvm_run *run = vcpu->run; in kvmppc_vcpu_run_hv()
4816 start_timing(vcpu, &vcpu->arch.vcpu_entry); in kvmppc_vcpu_run_hv()
4818 if (!vcpu->arch.sane) { in kvmppc_vcpu_run_hv()
4819 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; in kvmppc_vcpu_run_hv()
4820 return -EINVAL; in kvmppc_vcpu_run_hv()
4825 run->exit_reason = KVM_EXIT_INTR; in kvmppc_vcpu_run_hv()
4826 return -EINTR; in kvmppc_vcpu_run_hv()
4834 if (cpu_has_feature(CPU_FTR_TM) && current->thread.regs && in kvmppc_vcpu_run_hv()
4835 (current->thread.regs->msr & MSR_TM)) { in kvmppc_vcpu_run_hv()
4836 if (MSR_TM_ACTIVE(current->thread.regs->msr)) { in kvmppc_vcpu_run_hv()
4837 run->exit_reason = KVM_EXIT_FAIL_ENTRY; in kvmppc_vcpu_run_hv()
4838 run->fail_entry.hardware_entry_failure_reason = 0; in kvmppc_vcpu_run_hv()
4839 return -EINVAL; in kvmppc_vcpu_run_hv()
4848 if (!vcpu->arch.online) { in kvmppc_vcpu_run_hv()
4849 atomic_inc(&vcpu->arch.vcore->online_count); in kvmppc_vcpu_run_hv()
4850 vcpu->arch.online = 1; in kvmppc_vcpu_run_hv()
4855 kvm = vcpu->kvm; in kvmppc_vcpu_run_hv()
4856 atomic_inc(&kvm->arch.vcpus_running); in kvmppc_vcpu_run_hv()
4878 vcpu->arch.waitp = &vcpu->arch.vcore->wait; in kvmppc_vcpu_run_hv()
4879 vcpu->arch.pgdir = kvm->mm->pgd; in kvmppc_vcpu_run_hv()
4880 vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST; in kvmppc_vcpu_run_hv()
4883 accumulate_time(vcpu, &vcpu->arch.guest_entry); in kvmppc_vcpu_run_hv()
4886 vcpu->arch.vcore->lpcr); in kvmppc_vcpu_run_hv()
4890 if (run->exit_reason == KVM_EXIT_PAPR_HCALL) { in kvmppc_vcpu_run_hv()
4891 accumulate_time(vcpu, &vcpu->arch.hcall); in kvmppc_vcpu_run_hv()
4908 accumulate_time(vcpu, &vcpu->arch.pg_fault); in kvmppc_vcpu_run_hv()
4909 srcu_idx = srcu_read_lock(&kvm->srcu); in kvmppc_vcpu_run_hv()
4911 vcpu->arch.fault_dar, vcpu->arch.fault_dsisr); in kvmppc_vcpu_run_hv()
4912 srcu_read_unlock(&kvm->srcu, srcu_idx); in kvmppc_vcpu_run_hv()
4920 accumulate_time(vcpu, &vcpu->arch.vcpu_exit); in kvmppc_vcpu_run_hv()
4922 vcpu->arch.state = KVMPPC_VCPU_NOTREADY; in kvmppc_vcpu_run_hv()
4923 atomic_dec(&kvm->arch.vcpus_running); in kvmppc_vcpu_run_hv()
4935 (*sps)->page_shift = shift; in kvmppc_add_seg_page_size()
4936 (*sps)->slb_enc = sllp; in kvmppc_add_seg_page_size()
4937 (*sps)->enc[0].page_shift = shift; in kvmppc_add_seg_page_size()
4938 (*sps)->enc[0].pte_enc = kvmppc_pgsize_lp_encoding(shift, shift); in kvmppc_add_seg_page_size()
4944 if (penc != -1) { in kvmppc_add_seg_page_size()
4945 (*sps)->enc[1].page_shift = 24; in kvmppc_add_seg_page_size()
4946 (*sps)->enc[1].pte_enc = penc; in kvmppc_add_seg_page_size()
4962 info->data_keys = 32; in kvm_vm_ioctl_get_smmu_info_hv()
4963 info->instr_keys = cpu_has_feature(CPU_FTR_ARCH_207S) ? 32 : 0; in kvm_vm_ioctl_get_smmu_info_hv()
4965 /* POWER7, 8 and 9 all have 1T segments and 32-entry SLB */ in kvm_vm_ioctl_get_smmu_info_hv()
4966 info->flags = KVM_PPC_PAGE_SIZES_REAL | KVM_PPC_1T_SEGMENTS; in kvm_vm_ioctl_get_smmu_info_hv()
4967 info->slb_size = 32; in kvm_vm_ioctl_get_smmu_info_hv()
4969 /* We only support these sizes for now, and no muti-size segments */ in kvm_vm_ioctl_get_smmu_info_hv()
4970 sps = &info->sps[0]; in kvm_vm_ioctl_get_smmu_info_hv()
4977 info->flags |= KVM_PPC_NO_HASH; in kvm_vm_ioctl_get_smmu_info_hv()
4995 mutex_lock(&kvm->slots_lock); in kvm_vm_ioctl_get_dirty_log_hv()
4997 r = -EINVAL; in kvm_vm_ioctl_get_dirty_log_hv()
4998 if (log->slot >= KVM_USER_MEM_SLOTS) in kvm_vm_ioctl_get_dirty_log_hv()
5002 memslot = id_to_memslot(slots, log->slot); in kvm_vm_ioctl_get_dirty_log_hv()
5003 r = -ENOENT; in kvm_vm_ioctl_get_dirty_log_hv()
5004 if (!memslot || !memslot->dirty_bitmap) in kvm_vm_ioctl_get_dirty_log_hv()
5012 buf = memslot->dirty_bitmap + n / sizeof(long); in kvm_vm_ioctl_get_dirty_log_hv()
5028 p = memslot->dirty_bitmap; in kvm_vm_ioctl_get_dirty_log_hv()
5035 spin_lock(&vcpu->arch.vpa_update_lock); in kvm_vm_ioctl_get_dirty_log_hv()
5036 kvmppc_harvest_vpa_dirty(&vcpu->arch.vpa, memslot, buf); in kvm_vm_ioctl_get_dirty_log_hv()
5037 kvmppc_harvest_vpa_dirty(&vcpu->arch.dtl, memslot, buf); in kvm_vm_ioctl_get_dirty_log_hv()
5038 spin_unlock(&vcpu->arch.vpa_update_lock); in kvm_vm_ioctl_get_dirty_log_hv()
5041 r = -EFAULT; in kvm_vm_ioctl_get_dirty_log_hv()
5042 if (copy_to_user(log->dirty_bitmap, buf, n)) in kvm_vm_ioctl_get_dirty_log_hv()
5047 mutex_unlock(&kvm->slots_lock); in kvm_vm_ioctl_get_dirty_log_hv()
5053 vfree(slot->arch.rmap); in kvmppc_core_free_memslot_hv()
5054 slot->arch.rmap = NULL; in kvmppc_core_free_memslot_hv()
5063 unsigned long size = array_size(new->npages, sizeof(*new->arch.rmap)); in kvmppc_core_prepare_memory_region_hv()
5066 return -ENOMEM; in kvmppc_core_prepare_memory_region_hv()
5068 new->arch.rmap = vzalloc(size); in kvmppc_core_prepare_memory_region_hv()
5069 if (!new->arch.rmap) in kvmppc_core_prepare_memory_region_hv()
5070 return -ENOMEM; in kvmppc_core_prepare_memory_region_hv()
5072 new->arch.rmap = old->arch.rmap; in kvmppc_core_prepare_memory_region_hv()
5090 atomic64_inc(&kvm->arch.mmio_update); in kvmppc_core_commit_memory_region_hv()
5100 * to get rid of any THP PTEs in the partition-scoped page tables in kvmppc_core_commit_memory_region_hv()
5106 ((new->flags ^ old->flags) & KVM_MEM_LOG_DIRTY_PAGES)) in kvmppc_core_commit_memory_region_hv()
5111 if (!kvm->arch.secure_guest) in kvmppc_core_commit_memory_region_hv()
5132 * Update LPCR values in kvm->arch and in vcores.
5133 * Caller must hold kvm->arch.mmu_setup_lock (for mutual exclusion
5134 * of kvm->arch.lpcr update).
5141 if ((kvm->arch.lpcr & mask) == lpcr) in kvmppc_update_lpcr()
5144 kvm->arch.lpcr = (kvm->arch.lpcr & ~mask) | lpcr; in kvmppc_update_lpcr()
5147 struct kvmppc_vcore *vc = kvm->arch.vcores[i]; in kvmppc_update_lpcr()
5151 spin_lock(&vc->lock); in kvmppc_update_lpcr()
5152 vc->lpcr = (vc->lpcr & ~mask) | lpcr; in kvmppc_update_lpcr()
5153 verify_lpcr(kvm, vc->lpcr); in kvmppc_update_lpcr()
5154 spin_unlock(&vc->lock); in kvmppc_update_lpcr()
5155 if (++cores_done >= kvm->arch.online_vcores) in kvmppc_update_lpcr()
5165 /* PS field - page size for VRMA */ in kvmppc_setup_partition_table()
5166 dw0 = ((kvm->arch.vrma_slb_v & SLB_VSID_L) >> 1) | in kvmppc_setup_partition_table()
5167 ((kvm->arch.vrma_slb_v & SLB_VSID_LP) << 1); in kvmppc_setup_partition_table()
5169 dw0 |= kvm->arch.sdr1; in kvmppc_setup_partition_table()
5172 dw1 = kvm->arch.process_table; in kvmppc_setup_partition_table()
5175 __pa(kvm->arch.pgtable) | RADIX_PGD_INDEX_SIZE; in kvmppc_setup_partition_table()
5176 dw1 = PATB_GR | kvm->arch.process_table; in kvmppc_setup_partition_table()
5178 kvmhv_set_ptbl_entry(kvm->arch.lpid, dw0, dw1); in kvmppc_setup_partition_table()
5182 * Set up HPT (hashed page table) and RMA (real-mode area).
5183 * Must be called with kvm->arch.mmu_setup_lock held.
5188 struct kvm *kvm = vcpu->kvm; in kvmppc_hv_setup_htab_rma()
5197 if (!kvm->arch.hpt.virt) { in kvmppc_hv_setup_htab_rma()
5205 while ((err == -ENOMEM) && --order >= PPC_MIN_HPT_ORDER) in kvmppc_hv_setup_htab_rma()
5217 srcu_idx = srcu_read_lock(&kvm->srcu); in kvmppc_hv_setup_htab_rma()
5221 err = -EINVAL; in kvmppc_hv_setup_htab_rma()
5222 if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID)) in kvmppc_hv_setup_htab_rma()
5226 hva = memslot->userspace_addr; in kvmppc_hv_setup_htab_rma()
5227 mmap_read_lock(kvm->mm); in kvmppc_hv_setup_htab_rma()
5228 vma = vma_lookup(kvm->mm, hva); in kvmppc_hv_setup_htab_rma()
5229 if (!vma || (vma->vm_flags & VM_IO)) in kvmppc_hv_setup_htab_rma()
5234 mmap_read_unlock(kvm->mm); in kvmppc_hv_setup_htab_rma()
5246 kvm->arch.vrma_slb_v = senc | SLB_VSID_B_1T | in kvmppc_hv_setup_htab_rma()
5253 /* the -4 is to account for senc values starting at 0x10 */ in kvmppc_hv_setup_htab_rma()
5254 lpcr = senc << (LPCR_VRMASD_SH - 4); in kvmppc_hv_setup_htab_rma()
5258 /* Order updates to kvm->arch.lpcr etc. vs. mmu_ready */ in kvmppc_hv_setup_htab_rma()
5262 srcu_read_unlock(&kvm->srcu, srcu_idx); in kvmppc_hv_setup_htab_rma()
5267 mmap_read_unlock(kvm->mm); in kvmppc_hv_setup_htab_rma()
5272 * Must be called with kvm->arch.mmu_setup_lock held and
5282 kvm->arch.process_table = 0; in kvmppc_switch_mmu_to_hpt()
5284 spin_lock(&kvm->mmu_lock); in kvmppc_switch_mmu_to_hpt()
5285 kvm->arch.radix = 0; in kvmppc_switch_mmu_to_hpt()
5286 spin_unlock(&kvm->mmu_lock); in kvmppc_switch_mmu_to_hpt()
5299 * Must be called with kvm->arch.mmu_setup_lock held and
5312 spin_lock(&kvm->mmu_lock); in kvmppc_switch_mmu_to_radix()
5313 kvm->arch.radix = 1; in kvmppc_switch_mmu_to_radix()
5314 spin_unlock(&kvm->mmu_lock); in kvmppc_switch_mmu_to_radix()
5315 kvmppc_free_hpt(&kvm->arch.hpt); in kvmppc_switch_mmu_to_radix()
5322 (kvm->arch.host_lpcr & LPCR_HAIL)) in kvmppc_switch_mmu_to_radix()
5332 * Allocate a per-core structure for managing state about which cores are
5337 * It is only freed when the kvm-hv module is unloaded.
5360 ops->rm_core = kzalloc(size, GFP_KERNEL); in kvmppc_alloc_host_rm_ops()
5362 if (!ops->rm_core) { in kvmppc_alloc_host_rm_ops()
5374 ops->rm_core[core].rm_state.in_host = 1; in kvmppc_alloc_host_rm_ops()
5377 ops->vcpu_kick = kvmppc_fast_vcpu_kick_hv; in kvmppc_alloc_host_rm_ops()
5390 kfree(ops->rm_core); in kvmppc_alloc_host_rm_ops()
5406 kfree(kvmppc_host_rm_ops_hv->rm_core); in kvmppc_free_host_rm_ops()
5418 mutex_init(&kvm->arch.uvmem_lock); in kvmppc_core_init_vm_hv()
5419 INIT_LIST_HEAD(&kvm->arch.uvmem_pfns); in kvmppc_core_init_vm_hv()
5420 mutex_init(&kvm->arch.mmu_setup_lock); in kvmppc_core_init_vm_hv()
5426 return -ENOMEM; in kvmppc_core_init_vm_hv()
5427 kvm->arch.lpid = lpid; in kvmppc_core_init_vm_hv()
5441 cpumask_setall(&kvm->arch.need_tlb_flush); in kvmppc_core_init_vm_hv()
5444 memcpy(kvm->arch.enabled_hcalls, default_enabled_hcalls, in kvmppc_core_init_vm_hv()
5445 sizeof(kvm->arch.enabled_hcalls)); in kvmppc_core_init_vm_hv()
5448 kvm->arch.host_sdr1 = mfspr(SPRN_SDR1); in kvmppc_core_init_vm_hv()
5452 kvm->arch.host_lpid = mfspr(SPRN_LPID); in kvmppc_core_init_vm_hv()
5453 kvm->arch.host_lpcr = lpcr = mfspr(SPRN_LPCR); in kvmppc_core_init_vm_hv()
5464 kvm->arch.vrma_slb_v = SLB_VSID_B_1T | in kvmppc_core_init_vm_hv()
5473 * be unnecessary but better safe than sorry in case we re-enable in kvmppc_core_init_vm_hv()
5492 kvm->arch.radix = 1; in kvmppc_core_init_vm_hv()
5493 kvm->arch.mmu_ready = 1; in kvmppc_core_init_vm_hv()
5498 (kvm->arch.host_lpcr & LPCR_HAIL)) in kvmppc_core_init_vm_hv()
5502 kvmppc_free_lpid(kvm->arch.lpid); in kvmppc_core_init_vm_hv()
5509 kvm->arch.lpcr = lpcr; in kvmppc_core_init_vm_hv()
5512 kvm->arch.resize_hpt = NULL; in kvmppc_core_init_vm_hv()
5522 kvm->arch.tlb_sets = 1; in kvmppc_core_init_vm_hv()
5524 kvm->arch.tlb_sets = POWER9_TLB_SETS_RADIX; /* 128 */ in kvmppc_core_init_vm_hv()
5526 kvm->arch.tlb_sets = POWER9_TLB_SETS_HASH; /* 256 */ in kvmppc_core_init_vm_hv()
5528 kvm->arch.tlb_sets = POWER8_TLB_SETS; /* 512 */ in kvmppc_core_init_vm_hv()
5530 kvm->arch.tlb_sets = POWER7_TLB_SETS; /* 128 */ in kvmppc_core_init_vm_hv()
5547 kvm->arch.smt_mode = threads_per_subcore; in kvmppc_core_init_vm_hv()
5549 kvm->arch.smt_mode = 1; in kvmppc_core_init_vm_hv()
5550 kvm->arch.emul_smt_mode = 1; in kvmppc_core_init_vm_hv()
5568 kfree(kvm->arch.vcores[i]); in kvmppc_free_vcores()
5569 kvm->arch.online_vcores = 0; in kvmppc_free_vcores()
5583 kvmppc_free_hpt(&kvm->arch.hpt); in kvmppc_core_destroy_vm_hv()
5589 kvm->arch.process_table = 0; in kvmppc_core_destroy_vm_hv()
5590 if (kvm->arch.secure_guest) in kvmppc_core_destroy_vm_hv()
5591 uv_svm_terminate(kvm->arch.lpid); in kvmppc_core_destroy_vm_hv()
5592 kvmhv_set_ptbl_entry(kvm->arch.lpid, 0, 0); in kvmppc_core_destroy_vm_hv()
5595 kvmppc_free_lpid(kvm->arch.lpid); in kvmppc_core_destroy_vm_hv()
5629 return -EIO; in kvmppc_core_check_processor_compat_hv()
5636 kfree(kvm->arch.pimap); in kvmppc_free_pimap()
5658 return -EIO; in kvmppc_set_passthru_irq()
5660 mutex_lock(&kvm->lock); in kvmppc_set_passthru_irq()
5662 pimap = kvm->arch.pimap; in kvmppc_set_passthru_irq()
5667 mutex_unlock(&kvm->lock); in kvmppc_set_passthru_irq()
5668 return -ENOMEM; in kvmppc_set_passthru_irq()
5670 kvm->arch.pimap = pimap; in kvmppc_set_passthru_irq()
5676 * what our real-mode EOI code does, or a XIVE interrupt in kvmppc_set_passthru_irq()
5678 chip = irq_data_get_irq_chip(&desc->irq_data); in kvmppc_set_passthru_irq()
5682 mutex_unlock(&kvm->lock); in kvmppc_set_passthru_irq()
5683 return -ENOENT; in kvmppc_set_passthru_irq()
5689 * otherwise re-use this entry. in kvmppc_set_passthru_irq()
5691 for (i = 0; i < pimap->n_mapped; i++) { in kvmppc_set_passthru_irq()
5692 if (guest_gsi == pimap->mapped[i].v_hwirq) { in kvmppc_set_passthru_irq()
5693 if (pimap->mapped[i].r_hwirq) { in kvmppc_set_passthru_irq()
5694 mutex_unlock(&kvm->lock); in kvmppc_set_passthru_irq()
5695 return -EINVAL; in kvmppc_set_passthru_irq()
5702 mutex_unlock(&kvm->lock); in kvmppc_set_passthru_irq()
5703 return -EAGAIN; /* table is full */ in kvmppc_set_passthru_irq()
5706 irq_map = &pimap->mapped[i]; in kvmppc_set_passthru_irq()
5708 irq_map->v_hwirq = guest_gsi; in kvmppc_set_passthru_irq()
5709 irq_map->desc = desc; in kvmppc_set_passthru_irq()
5718 * The 'host_irq' number is mapped in the PCI-MSI domain but in kvmppc_set_passthru_irq()
5723 irq_map->r_hwirq = (unsigned int)irqd_to_hwirq(host_data); in kvmppc_set_passthru_irq()
5725 if (i == pimap->n_mapped) in kvmppc_set_passthru_irq()
5726 pimap->n_mapped++; in kvmppc_set_passthru_irq()
5731 kvmppc_xics_set_mapped(kvm, guest_gsi, irq_map->r_hwirq); in kvmppc_set_passthru_irq()
5733 irq_map->r_hwirq = 0; in kvmppc_set_passthru_irq()
5735 mutex_unlock(&kvm->lock); in kvmppc_set_passthru_irq()
5751 return -EIO; in kvmppc_clr_passthru_irq()
5753 mutex_lock(&kvm->lock); in kvmppc_clr_passthru_irq()
5754 if (!kvm->arch.pimap) in kvmppc_clr_passthru_irq()
5757 pimap = kvm->arch.pimap; in kvmppc_clr_passthru_irq()
5759 for (i = 0; i < pimap->n_mapped; i++) { in kvmppc_clr_passthru_irq()
5760 if (guest_gsi == pimap->mapped[i].v_hwirq) in kvmppc_clr_passthru_irq()
5764 if (i == pimap->n_mapped) { in kvmppc_clr_passthru_irq()
5765 mutex_unlock(&kvm->lock); in kvmppc_clr_passthru_irq()
5766 return -ENODEV; in kvmppc_clr_passthru_irq()
5772 kvmppc_xics_clr_mapped(kvm, guest_gsi, pimap->mapped[i].r_hwirq); in kvmppc_clr_passthru_irq()
5775 pimap->mapped[i].r_hwirq = 0; in kvmppc_clr_passthru_irq()
5782 mutex_unlock(&kvm->lock); in kvmppc_clr_passthru_irq()
5793 irqfd->producer = prod; in kvmppc_irq_bypass_add_producer_hv()
5795 ret = kvmppc_set_passthru_irq(irqfd->kvm, prod->irq, irqfd->gsi); in kvmppc_irq_bypass_add_producer_hv()
5798 prod->irq, irqfd->gsi, ret); in kvmppc_irq_bypass_add_producer_hv()
5810 irqfd->producer = NULL; in kvmppc_irq_bypass_del_producer_hv()
5814 * default external interrupt handling mode - KVM real mode in kvmppc_irq_bypass_del_producer_hv()
5817 ret = kvmppc_clr_passthru_irq(irqfd->kvm, prod->irq, irqfd->gsi); in kvmppc_irq_bypass_del_producer_hv()
5820 prod->irq, irqfd->gsi, ret); in kvmppc_irq_bypass_del_producer_hv()
5827 struct kvm *kvm __maybe_unused = filp->private_data; in kvm_arch_vm_ioctl_hv()
5838 r = -EOPNOTSUPP; in kvm_arch_vm_ioctl_hv()
5842 r = -EFAULT; in kvm_arch_vm_ioctl_hv()
5855 r = -EFAULT; in kvm_arch_vm_ioctl_hv()
5865 r = -EFAULT; in kvm_arch_vm_ioctl_hv()
5876 r = -EFAULT; in kvm_arch_vm_ioctl_hv()
5885 r = -ENOTTY; in kvm_arch_vm_ioctl_hv()
5894 * all hcalls that were implemented before the hcall-enabling
5944 return -ENODEV; in kvmhv_configure_mmu()
5947 if (cfg->flags & ~(KVM_PPC_MMUV3_RADIX | KVM_PPC_MMUV3_GTSE)) in kvmhv_configure_mmu()
5948 return -EINVAL; in kvmhv_configure_mmu()
5951 radix = !!(cfg->flags & KVM_PPC_MMUV3_RADIX); in kvmhv_configure_mmu()
5952 if (!!(cfg->process_table & PATB_GR) != radix) in kvmhv_configure_mmu()
5953 return -EINVAL; in kvmhv_configure_mmu()
5956 if ((cfg->process_table & PRTS_MASK) > 24) in kvmhv_configure_mmu()
5957 return -EINVAL; in kvmhv_configure_mmu()
5961 return -EINVAL; in kvmhv_configure_mmu()
5965 return -EINVAL; in kvmhv_configure_mmu()
5967 mutex_lock(&kvm->arch.mmu_setup_lock); in kvmhv_configure_mmu()
5969 if (kvm->arch.mmu_ready) { in kvmhv_configure_mmu()
5970 kvm->arch.mmu_ready = 0; in kvmhv_configure_mmu()
5973 if (atomic_read(&kvm->arch.vcpus_running)) { in kvmhv_configure_mmu()
5974 kvm->arch.mmu_ready = 1; in kvmhv_configure_mmu()
5975 err = -EBUSY; in kvmhv_configure_mmu()
5987 kvm->arch.process_table = cfg->process_table; in kvmhv_configure_mmu()
5990 lpcr = (cfg->flags & KVM_PPC_MMUV3_GTSE) ? LPCR_GTSE : 0; in kvmhv_configure_mmu()
5995 mutex_unlock(&kvm->arch.mmu_setup_lock); in kvmhv_configure_mmu()
6002 return -EPERM; in kvmhv_enable_nested()
6004 return -ENODEV; in kvmhv_enable_nested()
6006 return -ENODEV; in kvmhv_enable_nested()
6010 kvm->arch.nested_enable = true; in kvmhv_enable_nested()
6017 int rc = -EINVAL; in kvmhv_load_from_eaddr()
6023 rc = -EINVAL; in kvmhv_load_from_eaddr()
6027 if (rc && vcpu->arch.nested) in kvmhv_load_from_eaddr()
6028 rc = -EAGAIN; in kvmhv_load_from_eaddr()
6036 int rc = -EINVAL; in kvmhv_store_to_eaddr()
6042 rc = -EINVAL; in kvmhv_store_to_eaddr()
6046 if (rc && vcpu->arch.nested) in kvmhv_store_to_eaddr()
6047 rc = -EAGAIN; in kvmhv_store_to_eaddr()
6055 vpa->gpa = 0; in unpin_vpa_reset()
6056 vpa->pinned_addr = NULL; in unpin_vpa_reset()
6057 vpa->dirty = false; in unpin_vpa_reset()
6058 vpa->update_pending = 0; in unpin_vpa_reset()
6070 return -EINVAL; in kvmhv_enable_svm()
6072 kvm->arch.svm_enabled = 1; in kvmhv_enable_svm()
6079 * - Release all device pages
6080 * - Issue ucall to terminate the guest on the UV side
6081 * - Unpin the VPA pages.
6082 * - Reinit the partition scoped page tables
6092 if (!(kvm->arch.secure_guest & KVMPPC_SECURE_INIT_START)) in kvmhv_svm_off()
6095 mutex_lock(&kvm->arch.mmu_setup_lock); in kvmhv_svm_off()
6096 mmu_was_ready = kvm->arch.mmu_ready; in kvmhv_svm_off()
6097 if (kvm->arch.mmu_ready) { in kvmhv_svm_off()
6098 kvm->arch.mmu_ready = 0; in kvmhv_svm_off()
6101 if (atomic_read(&kvm->arch.vcpus_running)) { in kvmhv_svm_off()
6102 kvm->arch.mmu_ready = 1; in kvmhv_svm_off()
6103 ret = -EBUSY; in kvmhv_svm_off()
6108 srcu_idx = srcu_read_lock(&kvm->srcu); in kvmhv_svm_off()
6119 uv_unregister_mem_slot(kvm->arch.lpid, memslot->id); in kvmhv_svm_off()
6122 srcu_read_unlock(&kvm->srcu, srcu_idx); in kvmhv_svm_off()
6124 ret = uv_svm_terminate(kvm->arch.lpid); in kvmhv_svm_off()
6126 ret = -EINVAL; in kvmhv_svm_off()
6132 * to UV via UV_PAGE_IN before the non-boot vcpus get a in kvmhv_svm_off()
6141 spin_lock(&vcpu->arch.vpa_update_lock); in kvmhv_svm_off()
6142 unpin_vpa_reset(kvm, &vcpu->arch.dtl); in kvmhv_svm_off()
6143 unpin_vpa_reset(kvm, &vcpu->arch.slb_shadow); in kvmhv_svm_off()
6144 unpin_vpa_reset(kvm, &vcpu->arch.vpa); in kvmhv_svm_off()
6145 spin_unlock(&vcpu->arch.vpa_update_lock); in kvmhv_svm_off()
6149 kvm->arch.secure_guest = 0; in kvmhv_svm_off()
6150 kvm->arch.mmu_ready = mmu_was_ready; in kvmhv_svm_off()
6152 mutex_unlock(&kvm->arch.mmu_setup_lock); in kvmhv_svm_off()
6159 return -ENODEV; in kvmhv_enable_dawr1()
6163 kvm->arch.dawr1_enabled = true; in kvmhv_enable_dawr1()
6250 if (paca_ptrs[first_cpu]->sibling_subcore_state) in kvm_init_subcore_bitmap()
6257 return -ENOMEM; in kvm_init_subcore_bitmap()
6263 paca_ptrs[cpu]->sibling_subcore_state = in kvm_init_subcore_bitmap()
6280 pr_err("KVM-HV: Host does not support TLBIE\n"); in kvmppc_book3s_init_hv()
6281 return -ENODEV; in kvmppc_book3s_init_hv()
6289 return -ENODEV; in kvmppc_book3s_init_hv()
6303 * either directly, via paca_ptrs[cpu]->kvm_hstate.xics_phys, or in kvmppc_book3s_init_hv()
6308 !local_paca->kvm_hstate.xics_phys) { in kvmppc_book3s_init_hv()
6311 np = of_find_compatible_node(NULL, NULL, "ibm,opal-intc"); in kvmppc_book3s_init_hv()
6313 pr_err("KVM-HV: Cannot determine method for accessing XICS\n"); in kvmppc_book3s_init_hv()
6314 r = -ENODEV; in kvmppc_book3s_init_hv()
6317 /* presence of intc confirmed - node can be dropped again */ in kvmppc_book3s_init_hv()
6338 pr_err("KVM-HV: kvmppc_uvmem_init failed %d\n", r); in kvmppc_book3s_init_hv()