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()
230 unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu) in kvm_arch_vcpu_get_ip() argument
232 return vcpu->arch.guest_context.sepc; in kvm_arch_vcpu_get_ip()
236 vm_fault_t kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf) in kvm_arch_vcpu_fault() argument
244 struct kvm_vcpu *vcpu = filp->private_data; in kvm_arch_vcpu_async_ioctl() local
254 return kvm_riscv_vcpu_set_interrupt(vcpu, IRQ_VS_EXT); in kvm_arch_vcpu_async_ioctl()
256 return kvm_riscv_vcpu_unset_interrupt(vcpu, IRQ_VS_EXT); in kvm_arch_vcpu_async_ioctl()
265 struct kvm_vcpu *vcpu = filp->private_data; in kvm_arch_vcpu_ioctl() local
279 r = kvm_riscv_vcpu_set_reg(vcpu, &reg); in kvm_arch_vcpu_ioctl()
281 r = kvm_riscv_vcpu_get_reg(vcpu, &reg); in kvm_arch_vcpu_ioctl()
293 reg_list.n = kvm_riscv_vcpu_num_regs(vcpu); in kvm_arch_vcpu_ioctl()
299 r = kvm_riscv_vcpu_copy_reg_indices(vcpu, user_list->reg); in kvm_arch_vcpu_ioctl()
309 int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, in kvm_arch_vcpu_ioctl_get_sregs() argument
315 int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, in kvm_arch_vcpu_ioctl_set_sregs() argument
321 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) in kvm_arch_vcpu_ioctl_get_fpu() argument
326 int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) in kvm_arch_vcpu_ioctl_set_fpu() argument
331 int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, in kvm_arch_vcpu_ioctl_translate() argument
337 int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) in kvm_arch_vcpu_ioctl_get_regs() argument
342 int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) in kvm_arch_vcpu_ioctl_set_regs() argument
347 void kvm_riscv_vcpu_flush_interrupts(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_flush_interrupts() argument
349 struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; in kvm_riscv_vcpu_flush_interrupts()
352 if (READ_ONCE(vcpu->arch.irqs_pending_mask[0])) { in kvm_riscv_vcpu_flush_interrupts()
353 mask = xchg_acquire(&vcpu->arch.irqs_pending_mask[0], 0); in kvm_riscv_vcpu_flush_interrupts()
354 val = READ_ONCE(vcpu->arch.irqs_pending[0]) & mask; in kvm_riscv_vcpu_flush_interrupts()
361 kvm_riscv_vcpu_aia_flush_interrupts(vcpu); in kvm_riscv_vcpu_flush_interrupts()
364 void kvm_riscv_vcpu_sync_interrupts(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_sync_interrupts() argument
367 struct kvm_vcpu_arch *v = &vcpu->arch; in kvm_riscv_vcpu_sync_interrupts()
368 struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; in kvm_riscv_vcpu_sync_interrupts()
395 kvm_riscv_vcpu_aia_sync_interrupts(vcpu); in kvm_riscv_vcpu_sync_interrupts()
398 kvm_riscv_vcpu_timer_sync(vcpu); in kvm_riscv_vcpu_sync_interrupts()
401 int kvm_riscv_vcpu_set_interrupt(struct kvm_vcpu *vcpu, unsigned int irq) in kvm_riscv_vcpu_set_interrupt() argument
415 set_bit(irq, vcpu->arch.irqs_pending); in kvm_riscv_vcpu_set_interrupt()
417 set_bit(irq, vcpu->arch.irqs_pending_mask); in kvm_riscv_vcpu_set_interrupt()
419 kvm_vcpu_kick(vcpu); in kvm_riscv_vcpu_set_interrupt()
424 int kvm_riscv_vcpu_unset_interrupt(struct kvm_vcpu *vcpu, unsigned int irq) in kvm_riscv_vcpu_unset_interrupt() argument
438 clear_bit(irq, vcpu->arch.irqs_pending); in kvm_riscv_vcpu_unset_interrupt()
440 set_bit(irq, vcpu->arch.irqs_pending_mask); in kvm_riscv_vcpu_unset_interrupt()
445 bool kvm_riscv_vcpu_has_interrupts(struct kvm_vcpu *vcpu, u64 mask) in kvm_riscv_vcpu_has_interrupts() argument
449 ie = ((vcpu->arch.guest_csr.vsie & VSIP_VALID_MASK) in kvm_riscv_vcpu_has_interrupts()
451 ie |= vcpu->arch.guest_csr.vsie & ~IRQ_LOCAL_MASK & in kvm_riscv_vcpu_has_interrupts()
453 if (READ_ONCE(vcpu->arch.irqs_pending[0]) & ie) in kvm_riscv_vcpu_has_interrupts()
457 return kvm_riscv_vcpu_aia_has_interrupts(vcpu, mask); in kvm_riscv_vcpu_has_interrupts()
460 void __kvm_riscv_vcpu_power_off(struct kvm_vcpu *vcpu) in __kvm_riscv_vcpu_power_off() argument
462 WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_STOPPED); in __kvm_riscv_vcpu_power_off()
463 kvm_make_request(KVM_REQ_SLEEP, vcpu); in __kvm_riscv_vcpu_power_off()
464 kvm_vcpu_kick(vcpu); in __kvm_riscv_vcpu_power_off()
467 void kvm_riscv_vcpu_power_off(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_power_off() argument
469 spin_lock(&vcpu->arch.mp_state_lock); in kvm_riscv_vcpu_power_off()
470 __kvm_riscv_vcpu_power_off(vcpu); in kvm_riscv_vcpu_power_off()
471 spin_unlock(&vcpu->arch.mp_state_lock); in kvm_riscv_vcpu_power_off()
474 void __kvm_riscv_vcpu_power_on(struct kvm_vcpu *vcpu) in __kvm_riscv_vcpu_power_on() argument
476 WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_RUNNABLE); in __kvm_riscv_vcpu_power_on()
477 kvm_vcpu_wake_up(vcpu); in __kvm_riscv_vcpu_power_on()
480 void kvm_riscv_vcpu_power_on(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_power_on() argument
482 spin_lock(&vcpu->arch.mp_state_lock); in kvm_riscv_vcpu_power_on()
483 __kvm_riscv_vcpu_power_on(vcpu); in kvm_riscv_vcpu_power_on()
484 spin_unlock(&vcpu->arch.mp_state_lock); in kvm_riscv_vcpu_power_on()
487 bool kvm_riscv_vcpu_stopped(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_stopped() argument
489 return READ_ONCE(vcpu->arch.mp_state.mp_state) == KVM_MP_STATE_STOPPED; in kvm_riscv_vcpu_stopped()
492 int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, in kvm_arch_vcpu_ioctl_get_mpstate() argument
495 *mp_state = READ_ONCE(vcpu->arch.mp_state); in kvm_arch_vcpu_ioctl_get_mpstate()
500 int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, in kvm_arch_vcpu_ioctl_set_mpstate() argument
505 spin_lock(&vcpu->arch.mp_state_lock); in kvm_arch_vcpu_ioctl_set_mpstate()
509 WRITE_ONCE(vcpu->arch.mp_state, *mp_state); in kvm_arch_vcpu_ioctl_set_mpstate()
512 __kvm_riscv_vcpu_power_off(vcpu); in kvm_arch_vcpu_ioctl_set_mpstate()
518 spin_unlock(&vcpu->arch.mp_state_lock); in kvm_arch_vcpu_ioctl_set_mpstate()
523 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, in kvm_arch_vcpu_ioctl_set_guest_debug() argument
527 vcpu->guest_debug = dbg->control; in kvm_arch_vcpu_ioctl_set_guest_debug()
528 vcpu->arch.cfg.hedeleg &= ~BIT(EXC_BREAKPOINT); in kvm_arch_vcpu_ioctl_set_guest_debug()
530 vcpu->guest_debug = 0; in kvm_arch_vcpu_ioctl_set_guest_debug()
531 vcpu->arch.cfg.hedeleg |= BIT(EXC_BREAKPOINT); in kvm_arch_vcpu_ioctl_set_guest_debug()
537 static void kvm_riscv_vcpu_setup_config(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_setup_config() argument
539 const unsigned long *isa = vcpu->arch.isa; in kvm_riscv_vcpu_setup_config()
540 struct kvm_vcpu_config *cfg = &vcpu->arch.cfg; in kvm_riscv_vcpu_setup_config()
569 if (vcpu->guest_debug) in kvm_riscv_vcpu_setup_config()
573 void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) in kvm_arch_vcpu_load() argument
576 struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; in kvm_arch_vcpu_load()
577 struct kvm_vcpu_config *cfg = &vcpu->arch.cfg; in kvm_arch_vcpu_load()
620 kvm_riscv_gstage_update_hgatp(vcpu); in kvm_arch_vcpu_load()
622 kvm_riscv_vcpu_timer_restore(vcpu); in kvm_arch_vcpu_load()
624 kvm_riscv_vcpu_host_fp_save(&vcpu->arch.host_context); in kvm_arch_vcpu_load()
625 kvm_riscv_vcpu_guest_fp_restore(&vcpu->arch.guest_context, in kvm_arch_vcpu_load()
626 vcpu->arch.isa); in kvm_arch_vcpu_load()
627 kvm_riscv_vcpu_host_vector_save(&vcpu->arch.host_context); in kvm_arch_vcpu_load()
628 kvm_riscv_vcpu_guest_vector_restore(&vcpu->arch.guest_context, in kvm_arch_vcpu_load()
629 vcpu->arch.isa); in kvm_arch_vcpu_load()
631 kvm_riscv_vcpu_aia_load(vcpu, cpu); in kvm_arch_vcpu_load()
633 kvm_make_request(KVM_REQ_STEAL_UPDATE, vcpu); in kvm_arch_vcpu_load()
635 vcpu->cpu = cpu; in kvm_arch_vcpu_load()
638 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) in kvm_arch_vcpu_put() argument
641 struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; in kvm_arch_vcpu_put()
643 vcpu->cpu = -1; in kvm_arch_vcpu_put()
645 kvm_riscv_vcpu_aia_put(vcpu); in kvm_arch_vcpu_put()
647 kvm_riscv_vcpu_guest_fp_save(&vcpu->arch.guest_context, in kvm_arch_vcpu_put()
648 vcpu->arch.isa); in kvm_arch_vcpu_put()
649 kvm_riscv_vcpu_host_fp_restore(&vcpu->arch.host_context); in kvm_arch_vcpu_put()
651 kvm_riscv_vcpu_timer_save(vcpu); in kvm_arch_vcpu_put()
652 kvm_riscv_vcpu_guest_vector_save(&vcpu->arch.guest_context, in kvm_arch_vcpu_put()
653 vcpu->arch.isa); in kvm_arch_vcpu_put()
654 kvm_riscv_vcpu_host_vector_restore(&vcpu->arch.host_context); in kvm_arch_vcpu_put()
680 static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu) in kvm_riscv_check_vcpu_requests() argument
682 struct rcuwait *wait = kvm_arch_vcpu_get_wait(vcpu); in kvm_riscv_check_vcpu_requests()
684 if (kvm_request_pending(vcpu)) { in kvm_riscv_check_vcpu_requests()
685 if (kvm_check_request(KVM_REQ_SLEEP, vcpu)) { in kvm_riscv_check_vcpu_requests()
686 kvm_vcpu_srcu_read_unlock(vcpu); in kvm_riscv_check_vcpu_requests()
688 (!kvm_riscv_vcpu_stopped(vcpu)) && (!vcpu->arch.pause), in kvm_riscv_check_vcpu_requests()
690 kvm_vcpu_srcu_read_lock(vcpu); in kvm_riscv_check_vcpu_requests()
692 if (kvm_riscv_vcpu_stopped(vcpu) || vcpu->arch.pause) { in kvm_riscv_check_vcpu_requests()
697 kvm_make_request(KVM_REQ_SLEEP, vcpu); in kvm_riscv_check_vcpu_requests()
701 if (kvm_check_request(KVM_REQ_VCPU_RESET, vcpu)) in kvm_riscv_check_vcpu_requests()
702 kvm_riscv_reset_vcpu(vcpu); in kvm_riscv_check_vcpu_requests()
704 if (kvm_check_request(KVM_REQ_UPDATE_HGATP, vcpu)) in kvm_riscv_check_vcpu_requests()
705 kvm_riscv_gstage_update_hgatp(vcpu); in kvm_riscv_check_vcpu_requests()
707 if (kvm_check_request(KVM_REQ_FENCE_I, vcpu)) in kvm_riscv_check_vcpu_requests()
708 kvm_riscv_fence_i_process(vcpu); in kvm_riscv_check_vcpu_requests()
714 if (kvm_check_request(KVM_REQ_HFENCE_GVMA_VMID_ALL, vcpu)) in kvm_riscv_check_vcpu_requests()
715 kvm_riscv_hfence_gvma_vmid_all_process(vcpu); in kvm_riscv_check_vcpu_requests()
717 if (kvm_check_request(KVM_REQ_HFENCE_VVMA_ALL, vcpu)) in kvm_riscv_check_vcpu_requests()
718 kvm_riscv_hfence_vvma_all_process(vcpu); in kvm_riscv_check_vcpu_requests()
720 if (kvm_check_request(KVM_REQ_HFENCE, vcpu)) in kvm_riscv_check_vcpu_requests()
721 kvm_riscv_hfence_process(vcpu); in kvm_riscv_check_vcpu_requests()
723 if (kvm_check_request(KVM_REQ_STEAL_UPDATE, vcpu)) in kvm_riscv_check_vcpu_requests()
724 kvm_riscv_vcpu_record_steal_time(vcpu); in kvm_riscv_check_vcpu_requests()
728 static void kvm_riscv_update_hvip(struct kvm_vcpu *vcpu) in kvm_riscv_update_hvip() argument
730 struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; in kvm_riscv_update_hvip()
733 kvm_riscv_vcpu_aia_update_hvip(vcpu); in kvm_riscv_update_hvip()
736 static __always_inline void kvm_riscv_vcpu_swap_in_guest_state(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_swap_in_guest_state() argument
738 struct kvm_vcpu_smstateen_csr *smcsr = &vcpu->arch.smstateen_csr; in kvm_riscv_vcpu_swap_in_guest_state()
739 struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; in kvm_riscv_vcpu_swap_in_guest_state()
740 struct kvm_vcpu_config *cfg = &vcpu->arch.cfg; in kvm_riscv_vcpu_swap_in_guest_state()
742 vcpu->arch.host_scounteren = csr_swap(CSR_SCOUNTEREN, csr->scounteren); in kvm_riscv_vcpu_swap_in_guest_state()
743 vcpu->arch.host_senvcfg = csr_swap(CSR_SENVCFG, csr->senvcfg); in kvm_riscv_vcpu_swap_in_guest_state()
746 vcpu->arch.host_sstateen0 = csr_swap(CSR_SSTATEEN0, in kvm_riscv_vcpu_swap_in_guest_state()
750 static __always_inline void kvm_riscv_vcpu_swap_in_host_state(struct kvm_vcpu *vcpu) in kvm_riscv_vcpu_swap_in_host_state() argument
752 struct kvm_vcpu_smstateen_csr *smcsr = &vcpu->arch.smstateen_csr; in kvm_riscv_vcpu_swap_in_host_state()
753 struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; in kvm_riscv_vcpu_swap_in_host_state()
754 struct kvm_vcpu_config *cfg = &vcpu->arch.cfg; in kvm_riscv_vcpu_swap_in_host_state()
756 csr->scounteren = csr_swap(CSR_SCOUNTEREN, vcpu->arch.host_scounteren); in kvm_riscv_vcpu_swap_in_host_state()
757 csr->senvcfg = csr_swap(CSR_SENVCFG, vcpu->arch.host_senvcfg); in kvm_riscv_vcpu_swap_in_host_state()
761 vcpu->arch.host_sstateen0); in kvm_riscv_vcpu_swap_in_host_state()
765 * Actually run the vCPU, entering an RCU extended quiescent state (EQS) while
766 * the vCPU is running.
771 static void noinstr kvm_riscv_vcpu_enter_exit(struct kvm_vcpu *vcpu, in kvm_riscv_vcpu_enter_exit() argument
775 struct kvm_cpu_context *gcntx = &vcpu->arch.guest_context; in kvm_riscv_vcpu_enter_exit()
776 struct kvm_cpu_context *hcntx = &vcpu->arch.host_context; in kvm_riscv_vcpu_enter_exit()
786 kvm_riscv_vcpu_swap_in_guest_state(vcpu); in kvm_riscv_vcpu_enter_exit()
815 __kvm_riscv_nacl_switch_to(&vcpu->arch, SBI_EXT_NACL, in kvm_riscv_vcpu_enter_exit()
834 __kvm_riscv_switch_to(&vcpu->arch); in kvm_riscv_vcpu_enter_exit()
846 vcpu->arch.last_exit_cpu = vcpu->cpu; in kvm_riscv_vcpu_enter_exit()
848 kvm_riscv_vcpu_swap_in_host_state(vcpu); in kvm_riscv_vcpu_enter_exit()
851 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) in kvm_arch_vcpu_ioctl_run() argument
855 struct kvm_run *run = vcpu->run; in kvm_arch_vcpu_ioctl_run()
857 if (!vcpu->arch.ran_atleast_once) in kvm_arch_vcpu_ioctl_run()
858 kvm_riscv_vcpu_setup_config(vcpu); in kvm_arch_vcpu_ioctl_run()
860 /* Mark this VCPU ran at least once */ in kvm_arch_vcpu_ioctl_run()
861 vcpu->arch.ran_atleast_once = true; in kvm_arch_vcpu_ioctl_run()
863 kvm_vcpu_srcu_read_lock(vcpu); in kvm_arch_vcpu_ioctl_run()
868 ret = kvm_riscv_vcpu_mmio_return(vcpu, vcpu->run); in kvm_arch_vcpu_ioctl_run()
872 ret = kvm_riscv_vcpu_sbi_return(vcpu, vcpu->run); in kvm_arch_vcpu_ioctl_run()
876 ret = kvm_riscv_vcpu_csr_return(vcpu, vcpu->run); in kvm_arch_vcpu_ioctl_run()
883 kvm_vcpu_srcu_read_unlock(vcpu); in kvm_arch_vcpu_ioctl_run()
887 if (!vcpu->wants_to_run) { in kvm_arch_vcpu_ioctl_run()
888 kvm_vcpu_srcu_read_unlock(vcpu); in kvm_arch_vcpu_ioctl_run()
892 vcpu_load(vcpu); in kvm_arch_vcpu_ioctl_run()
894 kvm_sigset_activate(vcpu); in kvm_arch_vcpu_ioctl_run()
900 ret = xfer_to_guest_mode_handle_work(vcpu); in kvm_arch_vcpu_ioctl_run()
905 kvm_riscv_gstage_vmid_update(vcpu); in kvm_arch_vcpu_ioctl_run()
907 kvm_riscv_check_vcpu_requests(vcpu); in kvm_arch_vcpu_ioctl_run()
912 ret = kvm_riscv_vcpu_aia_update(vcpu); in kvm_arch_vcpu_ioctl_run()
922 * interrupts and before the final VCPU requests check. in kvm_arch_vcpu_ioctl_run()
924 * Documentation/virt/kvm/vcpu-requests.rst in kvm_arch_vcpu_ioctl_run()
926 vcpu->mode = IN_GUEST_MODE; in kvm_arch_vcpu_ioctl_run()
928 kvm_vcpu_srcu_read_unlock(vcpu); in kvm_arch_vcpu_ioctl_run()
932 * We might have got VCPU interrupts updated asynchronously in kvm_arch_vcpu_ioctl_run()
935 kvm_riscv_vcpu_flush_interrupts(vcpu); in kvm_arch_vcpu_ioctl_run()
938 kvm_riscv_update_hvip(vcpu); in kvm_arch_vcpu_ioctl_run()
940 if (kvm_riscv_gstage_vmid_ver_changed(&vcpu->kvm->arch.vmid) || in kvm_arch_vcpu_ioctl_run()
941 kvm_request_pending(vcpu) || in kvm_arch_vcpu_ioctl_run()
943 vcpu->mode = OUTSIDE_GUEST_MODE; in kvm_arch_vcpu_ioctl_run()
946 kvm_vcpu_srcu_read_lock(vcpu); in kvm_arch_vcpu_ioctl_run()
956 kvm_riscv_local_tlb_sanitize(vcpu); in kvm_arch_vcpu_ioctl_run()
958 trace_kvm_entry(vcpu); in kvm_arch_vcpu_ioctl_run()
962 kvm_riscv_vcpu_enter_exit(vcpu, &trap); in kvm_arch_vcpu_ioctl_run()
964 vcpu->mode = OUTSIDE_GUEST_MODE; in kvm_arch_vcpu_ioctl_run()
965 vcpu->stat.exits++; in kvm_arch_vcpu_ioctl_run()
968 kvm_riscv_vcpu_sync_interrupts(vcpu); in kvm_arch_vcpu_ioctl_run()
991 kvm_vcpu_srcu_read_lock(vcpu); in kvm_arch_vcpu_ioctl_run()
993 ret = kvm_riscv_vcpu_exit(vcpu, run, &trap); in kvm_arch_vcpu_ioctl_run()
996 kvm_sigset_deactivate(vcpu); in kvm_arch_vcpu_ioctl_run()
998 vcpu_put(vcpu); in kvm_arch_vcpu_ioctl_run()
1000 kvm_vcpu_srcu_read_unlock(vcpu); in kvm_arch_vcpu_ioctl_run()