Lines Matching full:vcpu

29 	STATS_DESC_COUNTER(VCPU, ecall_exit_stat),
30 STATS_DESC_COUNTER(VCPU, wfi_exit_stat),
31 STATS_DESC_COUNTER(VCPU, wrs_exit_stat),
32 STATS_DESC_COUNTER(VCPU, mmio_exit_user),
33 STATS_DESC_COUNTER(VCPU, mmio_exit_kernel),
34 STATS_DESC_COUNTER(VCPU, csr_exit_user),
35 STATS_DESC_COUNTER(VCPU, csr_exit_kernel),
36 STATS_DESC_COUNTER(VCPU, signal_exits),
37 STATS_DESC_COUNTER(VCPU, exits)
49 static void kvm_riscv_reset_vcpu(struct kvm_vcpu *vcpu) in kvm_riscv_reset_vcpu() argument
51 struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; in kvm_riscv_reset_vcpu()
52 struct kvm_vcpu_csr *reset_csr = &vcpu->arch.guest_reset_csr; in kvm_riscv_reset_vcpu()
53 struct kvm_cpu_context *cntx = &vcpu->arch.guest_context; in kvm_riscv_reset_vcpu()
54 struct kvm_cpu_context *reset_cntx = &vcpu->arch.guest_reset_context; in kvm_riscv_reset_vcpu()
63 loaded = (vcpu->cpu != -1); in kvm_riscv_reset_vcpu()
65 kvm_arch_vcpu_put(vcpu); in kvm_riscv_reset_vcpu()
67 vcpu->arch.last_exit_cpu = -1; in kvm_riscv_reset_vcpu()
71 spin_lock(&vcpu->arch.reset_cntx_lock); in kvm_riscv_reset_vcpu()
73 spin_unlock(&vcpu->arch.reset_cntx_lock); in kvm_riscv_reset_vcpu()
75 kvm_riscv_vcpu_fp_reset(vcpu); in kvm_riscv_reset_vcpu()
77 kvm_riscv_vcpu_vector_reset(vcpu); in kvm_riscv_reset_vcpu()
79 kvm_riscv_vcpu_timer_reset(vcpu); in kvm_riscv_reset_vcpu()
81 kvm_riscv_vcpu_aia_reset(vcpu); in kvm_riscv_reset_vcpu()
83 bitmap_zero(vcpu->arch.irqs_pending, KVM_RISCV_VCPU_NR_IRQS); in kvm_riscv_reset_vcpu()
84 bitmap_zero(vcpu->arch.irqs_pending_mask, KVM_RISCV_VCPU_NR_IRQS); in kvm_riscv_reset_vcpu()
86 kvm_riscv_vcpu_pmu_reset(vcpu); in kvm_riscv_reset_vcpu()
88 vcpu->arch.hfence_head = 0; in kvm_riscv_reset_vcpu()
89 vcpu->arch.hfence_tail = 0; in kvm_riscv_reset_vcpu()
90 memset(vcpu->arch.hfence_queue, 0, sizeof(vcpu->arch.hfence_queue)); in kvm_riscv_reset_vcpu()
92 kvm_riscv_vcpu_sbi_sta_reset(vcpu); in kvm_riscv_reset_vcpu()
96 kvm_arch_vcpu_load(vcpu, smp_processor_id()); in kvm_riscv_reset_vcpu()
105 int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) in kvm_arch_vcpu_create() argument
109 struct kvm_vcpu_csr *reset_csr = &vcpu->arch.guest_reset_csr; in kvm_arch_vcpu_create()
111 spin_lock_init(&vcpu->arch.mp_state_lock); in kvm_arch_vcpu_create()
113 /* Mark this VCPU never ran */ in kvm_arch_vcpu_create()
114 vcpu->arch.ran_atleast_once = false; in kvm_arch_vcpu_create()
115 vcpu->arch.mmu_page_cache.gfp_zero = __GFP_ZERO; in kvm_arch_vcpu_create()
116 bitmap_zero(vcpu->arch.isa, RISCV_ISA_EXT_MAX); in kvm_arch_vcpu_create()
118 /* Setup ISA features available to VCPU */ in kvm_arch_vcpu_create()
119 kvm_riscv_vcpu_setup_isa(vcpu); in kvm_arch_vcpu_create()
122 vcpu->arch.mvendorid = sbi_get_mvendorid(); in kvm_arch_vcpu_create()
123 vcpu->arch.marchid = sbi_get_marchid(); in kvm_arch_vcpu_create()
124 vcpu->arch.mimpid = sbi_get_mimpid(); in kvm_arch_vcpu_create()
126 /* Setup VCPU hfence queue */ in kvm_arch_vcpu_create()
127 spin_lock_init(&vcpu->arch.hfence_lock); in kvm_arch_vcpu_create()
130 spin_lock_init(&vcpu->arch.reset_cntx_lock); in kvm_arch_vcpu_create()
132 spin_lock(&vcpu->arch.reset_cntx_lock); in kvm_arch_vcpu_create()
133 cntx = &vcpu->arch.guest_reset_context; in kvm_arch_vcpu_create()
139 spin_unlock(&vcpu->arch.reset_cntx_lock); in kvm_arch_vcpu_create()
141 if (kvm_riscv_vcpu_alloc_vector_context(vcpu, cntx)) in kvm_arch_vcpu_create()
147 /* Setup VCPU timer */ in kvm_arch_vcpu_create()
148 kvm_riscv_vcpu_timer_init(vcpu); in kvm_arch_vcpu_create()
151 kvm_riscv_vcpu_pmu_init(vcpu); in kvm_arch_vcpu_create()
153 /* Setup VCPU AIA */ in kvm_arch_vcpu_create()
154 rc = kvm_riscv_vcpu_aia_init(vcpu); in kvm_arch_vcpu_create()
162 kvm_riscv_vcpu_sbi_init(vcpu); in kvm_arch_vcpu_create()
164 /* Reset VCPU */ in kvm_arch_vcpu_create()
165 kvm_riscv_reset_vcpu(vcpu); in kvm_arch_vcpu_create()
170 void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu) in kvm_arch_vcpu_postcreate() argument
173 * vcpu with id 0 is the designated boot cpu. in kvm_arch_vcpu_postcreate()
177 if (vcpu->vcpu_idx != 0) in kvm_arch_vcpu_postcreate()
178 kvm_riscv_vcpu_power_off(vcpu); in kvm_arch_vcpu_postcreate()
181 void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) in kvm_arch_vcpu_destroy() argument
183 /* Cleanup VCPU AIA context */ in kvm_arch_vcpu_destroy()
184 kvm_riscv_vcpu_aia_deinit(vcpu); in kvm_arch_vcpu_destroy()
186 /* Cleanup VCPU timer */ in kvm_arch_vcpu_destroy()
187 kvm_riscv_vcpu_timer_deinit(vcpu); in kvm_arch_vcpu_destroy()
189 kvm_riscv_vcpu_pmu_deinit(vcpu); in kvm_arch_vcpu_destroy()
192 kvm_mmu_free_memory_cache(&vcpu->arch.mmu_page_cache); in kvm_arch_vcpu_destroy()
195 kvm_riscv_vcpu_free_vector_context(vcpu); in kvm_arch_vcpu_destroy()
198 int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) in kvm_cpu_has_pending_timer() argument
200 return kvm_riscv_vcpu_timer_pending(vcpu); in kvm_cpu_has_pending_timer()
203 void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) in kvm_arch_vcpu_blocking() argument
205 kvm_riscv_aia_wakeon_hgei(vcpu, true); in kvm_arch_vcpu_blocking()
208 void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) in kvm_arch_vcpu_unblocking() argument
210 kvm_riscv_aia_wakeon_hgei(vcpu, false); in kvm_arch_vcpu_unblocking()
213 int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu) in kvm_arch_vcpu_runnable() argument
215 return (kvm_riscv_vcpu_has_interrupts(vcpu, -1UL) && in kvm_arch_vcpu_runnable()
216 !kvm_riscv_vcpu_stopped(vcpu) && !vcpu->arch.pause); in kvm_arch_vcpu_runnable()
219 int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu) in kvm_arch_vcpu_should_kick() argument
221 return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE; in kvm_arch_vcpu_should_kick()
224 bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu) in kvm_arch_vcpu_in_kernel() argument
226 return (vcpu->arch.guest_context.sstatus & SR_SPP) ? true : false; in kvm_arch_vcpu_in_kernel()
229 vm_fault_t kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf) in kvm_arch_vcpu_fault() argument
237 struct kvm_vcpu *vcpu = filp->private_data; in kvm_arch_vcpu_async_ioctl() local
247 return kvm_riscv_vcpu_set_interrupt(vcpu, IRQ_VS_EXT); in kvm_arch_vcpu_async_ioctl()
249 return kvm_riscv_vcpu_unset_interrupt(vcpu, IRQ_VS_EXT); in kvm_arch_vcpu_async_ioctl()
258 struct kvm_vcpu *vcpu = filp->private_data; in kvm_arch_vcpu_ioctl() local
272 r = kvm_riscv_vcpu_set_reg(vcpu, &reg); in kvm_arch_vcpu_ioctl()
274 r = kvm_riscv_vcpu_get_reg(vcpu, &reg); in kvm_arch_vcpu_ioctl()
286 reg_list.n = kvm_riscv_vcpu_num_regs(vcpu); in kvm_arch_vcpu_ioctl()
292 r = kvm_riscv_vcpu_copy_reg_indices(vcpu, user_list->reg); in kvm_arch_vcpu_ioctl()
302 int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, in kvm_arch_vcpu_ioctl_get_sregs() argument
308 int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, in kvm_arch_vcpu_ioctl_set_sregs() argument
314 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) in kvm_arch_vcpu_ioctl_get_fpu() argument
319 int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) in kvm_arch_vcpu_ioctl_set_fpu() argument
324 int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, in kvm_arch_vcpu_ioctl_translate() argument
330 int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) in kvm_arch_vcpu_ioctl_get_regs() argument
335 int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) in kvm_arch_vcpu_ioctl_set_regs() argument
340 void kvm_riscv_vcpu_flush_interrupts(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_flush_interrupts() argument
342 struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; in kvm_riscv_vcpu_flush_interrupts()
345 if (READ_ONCE(vcpu->arch.irqs_pending_mask[0])) { in kvm_riscv_vcpu_flush_interrupts()
346 mask = xchg_acquire(&vcpu->arch.irqs_pending_mask[0], 0); in kvm_riscv_vcpu_flush_interrupts()
347 val = READ_ONCE(vcpu->arch.irqs_pending[0]) & mask; in kvm_riscv_vcpu_flush_interrupts()
354 kvm_riscv_vcpu_aia_flush_interrupts(vcpu); in kvm_riscv_vcpu_flush_interrupts()
357 void kvm_riscv_vcpu_sync_interrupts(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_sync_interrupts() argument
360 struct kvm_vcpu_arch *v = &vcpu->arch; in kvm_riscv_vcpu_sync_interrupts()
361 struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; in kvm_riscv_vcpu_sync_interrupts()
388 kvm_riscv_vcpu_aia_sync_interrupts(vcpu); in kvm_riscv_vcpu_sync_interrupts()
391 kvm_riscv_vcpu_timer_sync(vcpu); in kvm_riscv_vcpu_sync_interrupts()
394 int kvm_riscv_vcpu_set_interrupt(struct kvm_vcpu *vcpu, unsigned int irq) in kvm_riscv_vcpu_set_interrupt() argument
408 set_bit(irq, vcpu->arch.irqs_pending); in kvm_riscv_vcpu_set_interrupt()
410 set_bit(irq, vcpu->arch.irqs_pending_mask); in kvm_riscv_vcpu_set_interrupt()
412 kvm_vcpu_kick(vcpu); in kvm_riscv_vcpu_set_interrupt()
417 int kvm_riscv_vcpu_unset_interrupt(struct kvm_vcpu *vcpu, unsigned int irq) in kvm_riscv_vcpu_unset_interrupt() argument
431 clear_bit(irq, vcpu->arch.irqs_pending); in kvm_riscv_vcpu_unset_interrupt()
433 set_bit(irq, vcpu->arch.irqs_pending_mask); in kvm_riscv_vcpu_unset_interrupt()
438 bool kvm_riscv_vcpu_has_interrupts(struct kvm_vcpu *vcpu, u64 mask) in kvm_riscv_vcpu_has_interrupts() argument
442 ie = ((vcpu->arch.guest_csr.vsie & VSIP_VALID_MASK) in kvm_riscv_vcpu_has_interrupts()
444 ie |= vcpu->arch.guest_csr.vsie & ~IRQ_LOCAL_MASK & in kvm_riscv_vcpu_has_interrupts()
446 if (READ_ONCE(vcpu->arch.irqs_pending[0]) & ie) in kvm_riscv_vcpu_has_interrupts()
450 return kvm_riscv_vcpu_aia_has_interrupts(vcpu, mask); in kvm_riscv_vcpu_has_interrupts()
453 void __kvm_riscv_vcpu_power_off(struct kvm_vcpu *vcpu) in __kvm_riscv_vcpu_power_off() argument
455 WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_STOPPED); in __kvm_riscv_vcpu_power_off()
456 kvm_make_request(KVM_REQ_SLEEP, vcpu); in __kvm_riscv_vcpu_power_off()
457 kvm_vcpu_kick(vcpu); in __kvm_riscv_vcpu_power_off()
460 void kvm_riscv_vcpu_power_off(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_power_off() argument
462 spin_lock(&vcpu->arch.mp_state_lock); in kvm_riscv_vcpu_power_off()
463 __kvm_riscv_vcpu_power_off(vcpu); in kvm_riscv_vcpu_power_off()
464 spin_unlock(&vcpu->arch.mp_state_lock); in kvm_riscv_vcpu_power_off()
467 void __kvm_riscv_vcpu_power_on(struct kvm_vcpu *vcpu) in __kvm_riscv_vcpu_power_on() argument
469 WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_RUNNABLE); in __kvm_riscv_vcpu_power_on()
470 kvm_vcpu_wake_up(vcpu); in __kvm_riscv_vcpu_power_on()
473 void kvm_riscv_vcpu_power_on(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_power_on() argument
475 spin_lock(&vcpu->arch.mp_state_lock); in kvm_riscv_vcpu_power_on()
476 __kvm_riscv_vcpu_power_on(vcpu); in kvm_riscv_vcpu_power_on()
477 spin_unlock(&vcpu->arch.mp_state_lock); in kvm_riscv_vcpu_power_on()
480 bool kvm_riscv_vcpu_stopped(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_stopped() argument
482 return READ_ONCE(vcpu->arch.mp_state.mp_state) == KVM_MP_STATE_STOPPED; in kvm_riscv_vcpu_stopped()
485 int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, in kvm_arch_vcpu_ioctl_get_mpstate() argument
488 *mp_state = READ_ONCE(vcpu->arch.mp_state); in kvm_arch_vcpu_ioctl_get_mpstate()
493 int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, in kvm_arch_vcpu_ioctl_set_mpstate() argument
498 spin_lock(&vcpu->arch.mp_state_lock); in kvm_arch_vcpu_ioctl_set_mpstate()
502 WRITE_ONCE(vcpu->arch.mp_state, *mp_state); in kvm_arch_vcpu_ioctl_set_mpstate()
505 __kvm_riscv_vcpu_power_off(vcpu); in kvm_arch_vcpu_ioctl_set_mpstate()
511 spin_unlock(&vcpu->arch.mp_state_lock); in kvm_arch_vcpu_ioctl_set_mpstate()
516 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, in kvm_arch_vcpu_ioctl_set_guest_debug() argument
520 vcpu->guest_debug = dbg->control; in kvm_arch_vcpu_ioctl_set_guest_debug()
521 vcpu->arch.cfg.hedeleg &= ~BIT(EXC_BREAKPOINT); in kvm_arch_vcpu_ioctl_set_guest_debug()
523 vcpu->guest_debug = 0; in kvm_arch_vcpu_ioctl_set_guest_debug()
524 vcpu->arch.cfg.hedeleg |= BIT(EXC_BREAKPOINT); in kvm_arch_vcpu_ioctl_set_guest_debug()
530 static void kvm_riscv_vcpu_setup_config(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_setup_config() argument
532 const unsigned long *isa = vcpu->arch.isa; in kvm_riscv_vcpu_setup_config()
533 struct kvm_vcpu_config *cfg = &vcpu->arch.cfg; in kvm_riscv_vcpu_setup_config()
558 if (vcpu->guest_debug) in kvm_riscv_vcpu_setup_config()
562 void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) in kvm_arch_vcpu_load() argument
564 struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; in kvm_arch_vcpu_load()
565 struct kvm_vcpu_config *cfg = &vcpu->arch.cfg; in kvm_arch_vcpu_load()
586 kvm_riscv_gstage_update_hgatp(vcpu); in kvm_arch_vcpu_load()
588 kvm_riscv_vcpu_timer_restore(vcpu); in kvm_arch_vcpu_load()
590 kvm_riscv_vcpu_host_fp_save(&vcpu->arch.host_context); in kvm_arch_vcpu_load()
591 kvm_riscv_vcpu_guest_fp_restore(&vcpu->arch.guest_context, in kvm_arch_vcpu_load()
592 vcpu->arch.isa); in kvm_arch_vcpu_load()
593 kvm_riscv_vcpu_host_vector_save(&vcpu->arch.host_context); in kvm_arch_vcpu_load()
594 kvm_riscv_vcpu_guest_vector_restore(&vcpu->arch.guest_context, in kvm_arch_vcpu_load()
595 vcpu->arch.isa); in kvm_arch_vcpu_load()
597 kvm_riscv_vcpu_aia_load(vcpu, cpu); in kvm_arch_vcpu_load()
599 kvm_make_request(KVM_REQ_STEAL_UPDATE, vcpu); in kvm_arch_vcpu_load()
601 vcpu->cpu = cpu; in kvm_arch_vcpu_load()
604 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) in kvm_arch_vcpu_put() argument
606 struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; in kvm_arch_vcpu_put()
608 vcpu->cpu = -1; in kvm_arch_vcpu_put()
610 kvm_riscv_vcpu_aia_put(vcpu); in kvm_arch_vcpu_put()
612 kvm_riscv_vcpu_guest_fp_save(&vcpu->arch.guest_context, in kvm_arch_vcpu_put()
613 vcpu->arch.isa); in kvm_arch_vcpu_put()
614 kvm_riscv_vcpu_host_fp_restore(&vcpu->arch.host_context); in kvm_arch_vcpu_put()
616 kvm_riscv_vcpu_timer_save(vcpu); in kvm_arch_vcpu_put()
617 kvm_riscv_vcpu_guest_vector_save(&vcpu->arch.guest_context, in kvm_arch_vcpu_put()
618 vcpu->arch.isa); in kvm_arch_vcpu_put()
619 kvm_riscv_vcpu_host_vector_restore(&vcpu->arch.host_context); in kvm_arch_vcpu_put()
632 static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu) in kvm_riscv_check_vcpu_requests() argument
634 struct rcuwait *wait = kvm_arch_vcpu_get_wait(vcpu); in kvm_riscv_check_vcpu_requests()
636 if (kvm_request_pending(vcpu)) { in kvm_riscv_check_vcpu_requests()
637 if (kvm_check_request(KVM_REQ_SLEEP, vcpu)) { in kvm_riscv_check_vcpu_requests()
638 kvm_vcpu_srcu_read_unlock(vcpu); in kvm_riscv_check_vcpu_requests()
640 (!kvm_riscv_vcpu_stopped(vcpu)) && (!vcpu->arch.pause), in kvm_riscv_check_vcpu_requests()
642 kvm_vcpu_srcu_read_lock(vcpu); in kvm_riscv_check_vcpu_requests()
644 if (kvm_riscv_vcpu_stopped(vcpu) || vcpu->arch.pause) { in kvm_riscv_check_vcpu_requests()
649 kvm_make_request(KVM_REQ_SLEEP, vcpu); in kvm_riscv_check_vcpu_requests()
653 if (kvm_check_request(KVM_REQ_VCPU_RESET, vcpu)) in kvm_riscv_check_vcpu_requests()
654 kvm_riscv_reset_vcpu(vcpu); in kvm_riscv_check_vcpu_requests()
656 if (kvm_check_request(KVM_REQ_UPDATE_HGATP, vcpu)) in kvm_riscv_check_vcpu_requests()
657 kvm_riscv_gstage_update_hgatp(vcpu); in kvm_riscv_check_vcpu_requests()
659 if (kvm_check_request(KVM_REQ_FENCE_I, vcpu)) in kvm_riscv_check_vcpu_requests()
660 kvm_riscv_fence_i_process(vcpu); in kvm_riscv_check_vcpu_requests()
666 if (kvm_check_request(KVM_REQ_HFENCE_GVMA_VMID_ALL, vcpu)) in kvm_riscv_check_vcpu_requests()
667 kvm_riscv_hfence_gvma_vmid_all_process(vcpu); in kvm_riscv_check_vcpu_requests()
669 if (kvm_check_request(KVM_REQ_HFENCE_VVMA_ALL, vcpu)) in kvm_riscv_check_vcpu_requests()
670 kvm_riscv_hfence_vvma_all_process(vcpu); in kvm_riscv_check_vcpu_requests()
672 if (kvm_check_request(KVM_REQ_HFENCE, vcpu)) in kvm_riscv_check_vcpu_requests()
673 kvm_riscv_hfence_process(vcpu); in kvm_riscv_check_vcpu_requests()
675 if (kvm_check_request(KVM_REQ_STEAL_UPDATE, vcpu)) in kvm_riscv_check_vcpu_requests()
676 kvm_riscv_vcpu_record_steal_time(vcpu); in kvm_riscv_check_vcpu_requests()
680 static void kvm_riscv_update_hvip(struct kvm_vcpu *vcpu) in kvm_riscv_update_hvip() argument
682 struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; in kvm_riscv_update_hvip()
685 kvm_riscv_vcpu_aia_update_hvip(vcpu); in kvm_riscv_update_hvip()
688 static __always_inline void kvm_riscv_vcpu_swap_in_guest_state(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_swap_in_guest_state() argument
690 struct kvm_vcpu_smstateen_csr *smcsr = &vcpu->arch.smstateen_csr; in kvm_riscv_vcpu_swap_in_guest_state()
691 struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; in kvm_riscv_vcpu_swap_in_guest_state()
692 struct kvm_vcpu_config *cfg = &vcpu->arch.cfg; in kvm_riscv_vcpu_swap_in_guest_state()
694 vcpu->arch.host_senvcfg = csr_swap(CSR_SENVCFG, csr->senvcfg); in kvm_riscv_vcpu_swap_in_guest_state()
697 vcpu->arch.host_sstateen0 = csr_swap(CSR_SSTATEEN0, in kvm_riscv_vcpu_swap_in_guest_state()
701 static __always_inline void kvm_riscv_vcpu_swap_in_host_state(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_swap_in_host_state() argument
703 struct kvm_vcpu_smstateen_csr *smcsr = &vcpu->arch.smstateen_csr; in kvm_riscv_vcpu_swap_in_host_state()
704 struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; in kvm_riscv_vcpu_swap_in_host_state()
705 struct kvm_vcpu_config *cfg = &vcpu->arch.cfg; in kvm_riscv_vcpu_swap_in_host_state()
707 csr->senvcfg = csr_swap(CSR_SENVCFG, vcpu->arch.host_senvcfg); in kvm_riscv_vcpu_swap_in_host_state()
711 vcpu->arch.host_sstateen0); in kvm_riscv_vcpu_swap_in_host_state()
715 * Actually run the vCPU, entering an RCU extended quiescent state (EQS) while
716 * the vCPU is running.
721 static void noinstr kvm_riscv_vcpu_enter_exit(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_enter_exit() argument
723 kvm_riscv_vcpu_swap_in_guest_state(vcpu); in kvm_riscv_vcpu_enter_exit()
725 __kvm_riscv_switch_to(&vcpu->arch); in kvm_riscv_vcpu_enter_exit()
726 vcpu->arch.last_exit_cpu = vcpu->cpu; in kvm_riscv_vcpu_enter_exit()
728 kvm_riscv_vcpu_swap_in_host_state(vcpu); in kvm_riscv_vcpu_enter_exit()
731 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) in kvm_arch_vcpu_ioctl_run() argument
735 struct kvm_run *run = vcpu->run; in kvm_arch_vcpu_ioctl_run()
737 if (!vcpu->arch.ran_atleast_once) in kvm_arch_vcpu_ioctl_run()
738 kvm_riscv_vcpu_setup_config(vcpu); in kvm_arch_vcpu_ioctl_run()
740 /* Mark this VCPU ran at least once */ in kvm_arch_vcpu_ioctl_run()
741 vcpu->arch.ran_atleast_once = true; in kvm_arch_vcpu_ioctl_run()
743 kvm_vcpu_srcu_read_lock(vcpu); in kvm_arch_vcpu_ioctl_run()
748 ret = kvm_riscv_vcpu_mmio_return(vcpu, vcpu->run); in kvm_arch_vcpu_ioctl_run()
752 ret = kvm_riscv_vcpu_sbi_return(vcpu, vcpu->run); in kvm_arch_vcpu_ioctl_run()
756 ret = kvm_riscv_vcpu_csr_return(vcpu, vcpu->run); in kvm_arch_vcpu_ioctl_run()
763 kvm_vcpu_srcu_read_unlock(vcpu); in kvm_arch_vcpu_ioctl_run()
767 if (!vcpu->wants_to_run) { in kvm_arch_vcpu_ioctl_run()
768 kvm_vcpu_srcu_read_unlock(vcpu); in kvm_arch_vcpu_ioctl_run()
772 vcpu_load(vcpu); in kvm_arch_vcpu_ioctl_run()
774 kvm_sigset_activate(vcpu); in kvm_arch_vcpu_ioctl_run()
780 ret = xfer_to_guest_mode_handle_work(vcpu); in kvm_arch_vcpu_ioctl_run()
785 kvm_riscv_gstage_vmid_update(vcpu); in kvm_arch_vcpu_ioctl_run()
787 kvm_riscv_check_vcpu_requests(vcpu); in kvm_arch_vcpu_ioctl_run()
792 ret = kvm_riscv_vcpu_aia_update(vcpu); in kvm_arch_vcpu_ioctl_run()
802 * interrupts and before the final VCPU requests check. in kvm_arch_vcpu_ioctl_run()
804 * Documentation/virt/kvm/vcpu-requests.rst in kvm_arch_vcpu_ioctl_run()
806 vcpu->mode = IN_GUEST_MODE; in kvm_arch_vcpu_ioctl_run()
808 kvm_vcpu_srcu_read_unlock(vcpu); in kvm_arch_vcpu_ioctl_run()
812 * We might have got VCPU interrupts updated asynchronously in kvm_arch_vcpu_ioctl_run()
815 kvm_riscv_vcpu_flush_interrupts(vcpu); in kvm_arch_vcpu_ioctl_run()
818 kvm_riscv_update_hvip(vcpu); in kvm_arch_vcpu_ioctl_run()
820 if (kvm_riscv_gstage_vmid_ver_changed(&vcpu->kvm->arch.vmid) || in kvm_arch_vcpu_ioctl_run()
821 kvm_request_pending(vcpu) || in kvm_arch_vcpu_ioctl_run()
823 vcpu->mode = OUTSIDE_GUEST_MODE; in kvm_arch_vcpu_ioctl_run()
826 kvm_vcpu_srcu_read_lock(vcpu); in kvm_arch_vcpu_ioctl_run()
836 kvm_riscv_local_tlb_sanitize(vcpu); in kvm_arch_vcpu_ioctl_run()
838 trace_kvm_entry(vcpu); in kvm_arch_vcpu_ioctl_run()
842 kvm_riscv_vcpu_enter_exit(vcpu); in kvm_arch_vcpu_ioctl_run()
844 vcpu->mode = OUTSIDE_GUEST_MODE; in kvm_arch_vcpu_ioctl_run()
845 vcpu->stat.exits++; in kvm_arch_vcpu_ioctl_run()
852 trap.sepc = vcpu->arch.guest_context.sepc; in kvm_arch_vcpu_ioctl_run()
859 kvm_riscv_vcpu_sync_interrupts(vcpu); in kvm_arch_vcpu_ioctl_run()
882 kvm_vcpu_srcu_read_lock(vcpu); in kvm_arch_vcpu_ioctl_run()
884 ret = kvm_riscv_vcpu_exit(vcpu, run, &trap); in kvm_arch_vcpu_ioctl_run()
887 kvm_sigset_deactivate(vcpu); in kvm_arch_vcpu_ioctl_run()
889 vcpu_put(vcpu); in kvm_arch_vcpu_ioctl_run()
891 kvm_vcpu_srcu_read_unlock(vcpu); in kvm_arch_vcpu_ioctl_run()