Lines Matching full:vcpu
24 static int kvm_emu_cpucfg(struct kvm_vcpu *vcpu, larch_inst inst) in kvm_emu_cpucfg() argument
34 ++vcpu->stat.cpucfg_exits; in kvm_emu_cpucfg()
35 index = vcpu->arch.gprs[rj]; in kvm_emu_cpucfg()
46 vcpu->arch.gprs[rd] = vcpu->arch.cpucfg[index]; in kvm_emu_cpucfg()
50 vcpu->arch.gprs[rd] = *(unsigned int *)KVM_SIGNATURE; in kvm_emu_cpucfg()
53 ret = vcpu->kvm->arch.pv_features & LOONGARCH_PV_FEAT_MASK; in kvm_emu_cpucfg()
54 vcpu->arch.gprs[rd] = ret; in kvm_emu_cpucfg()
57 vcpu->arch.gprs[rd] = 0; in kvm_emu_cpucfg()
65 static unsigned long kvm_emu_read_csr(struct kvm_vcpu *vcpu, int csrid) in kvm_emu_read_csr() argument
68 struct loongarch_csrs *csr = vcpu->arch.csr; in kvm_emu_read_csr()
77 pr_warn_once("Unsupported csrrd 0x%x with pc %lx\n", csrid, vcpu->arch.pc); in kvm_emu_read_csr()
82 static unsigned long kvm_emu_write_csr(struct kvm_vcpu *vcpu, int csrid, unsigned long val) in kvm_emu_write_csr() argument
85 struct loongarch_csrs *csr = vcpu->arch.csr; in kvm_emu_write_csr()
91 pr_warn_once("Unsupported csrwr 0x%x with pc %lx\n", csrid, vcpu->arch.pc); in kvm_emu_write_csr()
96 static unsigned long kvm_emu_xchg_csr(struct kvm_vcpu *vcpu, int csrid, in kvm_emu_xchg_csr() argument
100 struct loongarch_csrs *csr = vcpu->arch.csr; in kvm_emu_xchg_csr()
108 pr_warn_once("Unsupported csrxchg 0x%x with pc %lx\n", csrid, vcpu->arch.pc); in kvm_emu_xchg_csr()
113 static int kvm_handle_csr(struct kvm_vcpu *vcpu, larch_inst inst) in kvm_handle_csr() argument
128 if (csrid >= LOONGARCH_CSR_PERFCTRL0 && csrid <= vcpu->arch.max_pmu_csrid) { in kvm_handle_csr()
129 if (kvm_guest_has_pmu(&vcpu->arch)) { in kvm_handle_csr()
130 vcpu->arch.pc -= 4; in kvm_handle_csr()
131 kvm_make_request(KVM_REQ_PMU, vcpu); in kvm_handle_csr()
139 val = kvm_emu_read_csr(vcpu, csrid); in kvm_handle_csr()
140 vcpu->arch.gprs[rd] = val; in kvm_handle_csr()
143 val = vcpu->arch.gprs[rd]; in kvm_handle_csr()
144 val = kvm_emu_write_csr(vcpu, csrid, val); in kvm_handle_csr()
145 vcpu->arch.gprs[rd] = val; in kvm_handle_csr()
148 val = vcpu->arch.gprs[rd]; in kvm_handle_csr()
149 csr_mask = vcpu->arch.gprs[rj]; in kvm_handle_csr()
150 val = kvm_emu_xchg_csr(vcpu, csrid, csr_mask, val); in kvm_handle_csr()
151 vcpu->arch.gprs[rd] = val; in kvm_handle_csr()
157 int kvm_emu_iocsr(larch_inst inst, struct kvm_run *run, struct kvm_vcpu *vcpu) in kvm_emu_iocsr() argument
169 addr = vcpu->arch.gprs[rj]; in kvm_emu_iocsr()
172 val = &vcpu->arch.gprs[rd]; in kvm_emu_iocsr()
209 idx = srcu_read_lock(&vcpu->kvm->srcu); in kvm_emu_iocsr()
210 ret = kvm_io_bus_write(vcpu, KVM_IOCSR_BUS, addr, run->iocsr_io.len, val); in kvm_emu_iocsr()
211 srcu_read_unlock(&vcpu->kvm->srcu, idx); in kvm_emu_iocsr()
221 idx = srcu_read_lock(&vcpu->kvm->srcu); in kvm_emu_iocsr()
222 ret = kvm_io_bus_read(vcpu, KVM_IOCSR_BUS, addr, run->iocsr_io.len, val); in kvm_emu_iocsr()
223 srcu_read_unlock(&vcpu->kvm->srcu, idx); in kvm_emu_iocsr()
229 vcpu->arch.io_gpr = rd; in kvm_emu_iocsr()
237 int kvm_complete_iocsr_read(struct kvm_vcpu *vcpu, struct kvm_run *run) in kvm_complete_iocsr_read() argument
240 unsigned long *gpr = &vcpu->arch.gprs[vcpu->arch.io_gpr]; in kvm_complete_iocsr_read()
257 run->iocsr_io.len, vcpu->arch.badv); in kvm_complete_iocsr_read()
265 int kvm_emu_idle(struct kvm_vcpu *vcpu) in kvm_emu_idle() argument
267 ++vcpu->stat.idle_exits; in kvm_emu_idle()
268 trace_kvm_exit_idle(vcpu, KVM_TRACE_EXIT_IDLE); in kvm_emu_idle()
270 if (!kvm_arch_vcpu_runnable(vcpu)) in kvm_emu_idle()
271 kvm_vcpu_halt(vcpu); in kvm_emu_idle()
276 static int kvm_trap_handle_gspr(struct kvm_vcpu *vcpu) in kvm_trap_handle_gspr() argument
281 struct kvm_run *run = vcpu->run; in kvm_trap_handle_gspr()
284 inst.word = vcpu->arch.badi; in kvm_trap_handle_gspr()
285 curr_pc = vcpu->arch.pc; in kvm_trap_handle_gspr()
286 update_pc(&vcpu->arch); in kvm_trap_handle_gspr()
288 trace_kvm_exit_gspr(vcpu, inst.word); in kvm_trap_handle_gspr()
292 er = kvm_emu_cpucfg(vcpu, inst); in kvm_trap_handle_gspr()
295 er = kvm_handle_csr(vcpu, inst); in kvm_trap_handle_gspr()
301 trace_kvm_exit_cache(vcpu, KVM_TRACE_EXIT_CACHE); in kvm_trap_handle_gspr()
306 er = kvm_emu_iocsr(inst, run, vcpu); in kvm_trap_handle_gspr()
309 er = kvm_emu_idle(vcpu); in kvm_trap_handle_gspr()
331 kvm_arch_vcpu_dump_regs(vcpu); in kvm_trap_handle_gspr()
332 vcpu->arch.pc = curr_pc; in kvm_trap_handle_gspr()
344 static int kvm_handle_gspr(struct kvm_vcpu *vcpu) in kvm_handle_gspr() argument
349 er = kvm_trap_handle_gspr(vcpu); in kvm_handle_gspr()
354 vcpu->run->exit_reason = KVM_EXIT_MMIO; in kvm_handle_gspr()
357 vcpu->run->exit_reason = KVM_EXIT_LOONGARCH_IOCSR; in kvm_handle_gspr()
360 kvm_queue_exception(vcpu, EXCCODE_INE, 0); in kvm_handle_gspr()
367 int kvm_emu_mmio_read(struct kvm_vcpu *vcpu, larch_inst inst) in kvm_emu_mmio_read() argument
371 struct kvm_run *run = vcpu->run; in kvm_emu_mmio_read()
373 run->mmio.phys_addr = vcpu->arch.badv; in kvm_emu_mmio_read()
374 vcpu->mmio_needed = 2; /* signed */ in kvm_emu_mmio_read()
403 vcpu->mmio_needed = 1; /* unsigned */ in kvm_emu_mmio_read()
410 vcpu->mmio_needed = 1; /* unsigned */ in kvm_emu_mmio_read()
417 vcpu->mmio_needed = 1; /* unsigned */ in kvm_emu_mmio_read()
438 vcpu->mmio_needed = 1; /* unsigned */ in kvm_emu_mmio_read()
445 vcpu->mmio_needed = 1; /* unsigned */ in kvm_emu_mmio_read()
452 vcpu->mmio_needed = 1; /* unsigned */ in kvm_emu_mmio_read()
474 idx = srcu_read_lock(&vcpu->kvm->srcu); in kvm_emu_mmio_read()
475 ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, vcpu->arch.badv, in kvm_emu_mmio_read()
476 run->mmio.len, &vcpu->arch.gprs[rd]); in kvm_emu_mmio_read()
477 srcu_read_unlock(&vcpu->kvm->srcu, idx); in kvm_emu_mmio_read()
479 update_pc(&vcpu->arch); in kvm_emu_mmio_read()
480 vcpu->mmio_needed = 0; in kvm_emu_mmio_read()
485 vcpu->arch.io_gpr = rd; in kvm_emu_mmio_read()
487 vcpu->mmio_is_write = 0; in kvm_emu_mmio_read()
492 inst.word, vcpu->arch.pc, vcpu->arch.badv); in kvm_emu_mmio_read()
493 kvm_arch_vcpu_dump_regs(vcpu); in kvm_emu_mmio_read()
494 vcpu->mmio_needed = 0; in kvm_emu_mmio_read()
499 int kvm_complete_mmio_read(struct kvm_vcpu *vcpu, struct kvm_run *run) in kvm_complete_mmio_read() argument
502 unsigned long *gpr = &vcpu->arch.gprs[vcpu->arch.io_gpr]; in kvm_complete_mmio_read()
505 update_pc(&vcpu->arch); in kvm_complete_mmio_read()
508 if (vcpu->mmio_needed == 2) in kvm_complete_mmio_read()
514 if (vcpu->mmio_needed == 2) in kvm_complete_mmio_read()
520 if (vcpu->mmio_needed == 2) in kvm_complete_mmio_read()
530 run->mmio.len, vcpu->arch.badv); in kvm_complete_mmio_read()
541 int kvm_emu_mmio_write(struct kvm_vcpu *vcpu, larch_inst inst) in kvm_emu_mmio_write() argument
546 struct kvm_run *run = vcpu->run; in kvm_emu_mmio_write()
553 curr_pc = vcpu->arch.pc; in kvm_emu_mmio_write()
554 update_pc(&vcpu->arch); in kvm_emu_mmio_write()
557 run->mmio.phys_addr = vcpu->arch.badv; in kvm_emu_mmio_write()
567 *(unsigned int *)data = vcpu->arch.gprs[rd]; in kvm_emu_mmio_write()
571 *(unsigned long *)data = vcpu->arch.gprs[rd]; in kvm_emu_mmio_write()
581 rd_val = vcpu->arch.gprs[rd]; in kvm_emu_mmio_write()
612 *(unsigned char *)data = vcpu->arch.gprs[rd]; in kvm_emu_mmio_write()
616 *(unsigned short *)data = vcpu->arch.gprs[rd]; in kvm_emu_mmio_write()
620 *(unsigned int *)data = vcpu->arch.gprs[rd]; in kvm_emu_mmio_write()
624 *(unsigned long *)data = vcpu->arch.gprs[rd]; in kvm_emu_mmio_write()
643 idx = srcu_read_lock(&vcpu->kvm->srcu); in kvm_emu_mmio_write()
644 ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, vcpu->arch.badv, run->mmio.len, data); in kvm_emu_mmio_write()
645 srcu_read_unlock(&vcpu->kvm->srcu, idx); in kvm_emu_mmio_write()
650 vcpu->mmio_needed = 1; in kvm_emu_mmio_write()
651 vcpu->mmio_is_write = 1; in kvm_emu_mmio_write()
655 vcpu->arch.pc = curr_pc; in kvm_emu_mmio_write()
657 inst.word, vcpu->arch.pc, vcpu->arch.badv); in kvm_emu_mmio_write()
658 kvm_arch_vcpu_dump_regs(vcpu); in kvm_emu_mmio_write()
664 static int kvm_handle_rdwr_fault(struct kvm_vcpu *vcpu, bool write) in kvm_handle_rdwr_fault() argument
669 struct kvm_run *run = vcpu->run; in kvm_handle_rdwr_fault()
670 unsigned long badv = vcpu->arch.badv; in kvm_handle_rdwr_fault()
672 ret = kvm_handle_mm_fault(vcpu, badv, write); in kvm_handle_rdwr_fault()
675 inst.word = vcpu->arch.badi; in kvm_handle_rdwr_fault()
677 er = kvm_emu_mmio_write(vcpu, inst); in kvm_handle_rdwr_fault()
680 if (kvm_is_ifetch_fault(&vcpu->arch)) { in kvm_handle_rdwr_fault()
681 kvm_queue_exception(vcpu, EXCCODE_ADE, EXSUBCODE_ADEF); in kvm_handle_rdwr_fault()
685 er = kvm_emu_mmio_read(vcpu, inst); in kvm_handle_rdwr_fault()
695 kvm_queue_exception(vcpu, EXCCODE_ADE, EXSUBCODE_ADEM); in kvm_handle_rdwr_fault()
702 static int kvm_handle_read_fault(struct kvm_vcpu *vcpu) in kvm_handle_read_fault() argument
704 return kvm_handle_rdwr_fault(vcpu, false); in kvm_handle_read_fault()
707 static int kvm_handle_write_fault(struct kvm_vcpu *vcpu) in kvm_handle_write_fault() argument
709 return kvm_handle_rdwr_fault(vcpu, true); in kvm_handle_write_fault()
714 * @vcpu: Virtual CPU context.
719 static int kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu) in kvm_handle_fpu_disabled() argument
721 struct kvm_run *run = vcpu->run; in kvm_handle_fpu_disabled()
723 if (!kvm_guest_has_fpu(&vcpu->arch)) { in kvm_handle_fpu_disabled()
724 kvm_queue_exception(vcpu, EXCCODE_INE, 0); in kvm_handle_fpu_disabled()
733 if (WARN_ON(vcpu->arch.aux_inuse & KVM_LARCH_FPU)) { in kvm_handle_fpu_disabled()
739 kvm_own_fpu(vcpu); in kvm_handle_fpu_disabled()
744 static long kvm_save_notify(struct kvm_vcpu *vcpu) in kvm_save_notify() argument
748 id = kvm_read_reg(vcpu, LOONGARCH_GPR_A1); in kvm_save_notify()
749 data = kvm_read_reg(vcpu, LOONGARCH_GPR_A2); in kvm_save_notify()
755 vcpu->arch.st.guest_addr = data; in kvm_save_notify()
759 vcpu->arch.st.last_steal = current->sched_info.run_delay; in kvm_save_notify()
760 kvm_make_request(KVM_REQ_STEAL_UPDATE, vcpu); in kvm_save_notify()
771 * @vcpu: Virtual CPU context.
776 static int kvm_handle_lsx_disabled(struct kvm_vcpu *vcpu) in kvm_handle_lsx_disabled() argument
778 if (kvm_own_lsx(vcpu)) in kvm_handle_lsx_disabled()
779 kvm_queue_exception(vcpu, EXCCODE_INE, 0); in kvm_handle_lsx_disabled()
786 * @vcpu: Virtual CPU context.
791 static int kvm_handle_lasx_disabled(struct kvm_vcpu *vcpu) in kvm_handle_lasx_disabled() argument
793 if (kvm_own_lasx(vcpu)) in kvm_handle_lasx_disabled()
794 kvm_queue_exception(vcpu, EXCCODE_INE, 0); in kvm_handle_lasx_disabled()
799 static int kvm_handle_lbt_disabled(struct kvm_vcpu *vcpu) in kvm_handle_lbt_disabled() argument
801 if (kvm_own_lbt(vcpu)) in kvm_handle_lbt_disabled()
802 kvm_queue_exception(vcpu, EXCCODE_INE, 0); in kvm_handle_lbt_disabled()
807 static int kvm_send_pv_ipi(struct kvm_vcpu *vcpu) in kvm_send_pv_ipi() argument
813 min = kvm_read_reg(vcpu, LOONGARCH_GPR_A3); in kvm_send_pv_ipi()
815 ipi_bitmap = kvm_read_reg(vcpu, LOONGARCH_GPR_A1 + i); in kvm_send_pv_ipi()
821 dest = kvm_get_vcpu_by_cpuid(vcpu->kvm, cpu + min); in kvm_send_pv_ipi()
826 /* Send SWI0 to dest vcpu to emulate IPI interrupt */ in kvm_send_pv_ipi()
838 static void kvm_handle_service(struct kvm_vcpu *vcpu) in kvm_handle_service() argument
841 unsigned long func = kvm_read_reg(vcpu, LOONGARCH_GPR_A0); in kvm_handle_service()
845 if (kvm_guest_has_pv_feature(vcpu, KVM_FEATURE_IPI)) { in kvm_handle_service()
846 kvm_send_pv_ipi(vcpu); in kvm_handle_service()
851 if (kvm_guest_has_pv_feature(vcpu, KVM_FEATURE_STEAL_TIME)) in kvm_handle_service()
852 ret = kvm_save_notify(vcpu); in kvm_handle_service()
858 kvm_write_reg(vcpu, LOONGARCH_GPR_A0, ret); in kvm_handle_service()
861 static int kvm_handle_hypercall(struct kvm_vcpu *vcpu) in kvm_handle_hypercall() argument
867 inst.word = vcpu->arch.badi; in kvm_handle_hypercall()
873 vcpu->stat.hypercall_exits++; in kvm_handle_hypercall()
874 kvm_handle_service(vcpu); in kvm_handle_hypercall()
878 if (vcpu->guest_debug & KVM_GUESTDBG_SW_BP_MASK) { in kvm_handle_hypercall()
879 vcpu->run->exit_reason = KVM_EXIT_DEBUG; in kvm_handle_hypercall()
886 kvm_write_reg(vcpu, LOONGARCH_GPR_A0, KVM_HCALL_INVALID_CODE); in kvm_handle_hypercall()
891 update_pc(&vcpu->arch); in kvm_handle_hypercall()
899 static int kvm_fault_ni(struct kvm_vcpu *vcpu) in kvm_fault_ni() argument
905 inst = vcpu->arch.badi; in kvm_fault_ni()
906 badv = vcpu->arch.badv; in kvm_fault_ni()
907 estat = vcpu->arch.host_estat; in kvm_fault_ni()
910 ecode, vcpu->arch.pc, inst, badv, read_gcsr_estat()); in kvm_fault_ni()
911 kvm_arch_vcpu_dump_regs(vcpu); in kvm_fault_ni()
912 kvm_queue_exception(vcpu, EXCCODE_INE, 0); in kvm_fault_ni()
931 int kvm_handle_fault(struct kvm_vcpu *vcpu, int fault) in kvm_handle_fault() argument
933 return kvm_fault_tables[fault](vcpu); in kvm_handle_fault()