lkml.org 
[lkml]   [2023]   [Aug]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v18 08/30] LoongArch: KVM: Implement vcpu handle exit interface
    Date
    Implement vcpu handle exit interface, getting the exit code by ESTAT
    register and using kvm exception vector to handle it.

    Reviewed-by: Bibo Mao <maobibo@loongson.cn>
    Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
    ---
    arch/loongarch/kvm/vcpu.c | 45 +++++++++++++++++++++++++++++++++++++++
    1 file changed, 45 insertions(+)

    diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
    index 485998d20322..a862b5ac15a0 100644
    --- a/arch/loongarch/kvm/vcpu.c
    +++ b/arch/loongarch/kvm/vcpu.c
    @@ -52,6 +52,51 @@ static void kvm_pre_enter_guest(struct kvm_vcpu *vcpu)
    vcpu->arch.aux_inuse &= ~KVM_LARCH_CSR;
    }

    +/*
    + * Return 1 for resume guest and "<= 0" for resume host.
    + */
    +static int _kvm_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
    +{
    + unsigned long exst = vcpu->arch.host_estat;
    + u32 intr = exst & 0x1fff; /* ignore NMI */
    + u32 exccode = (exst & CSR_ESTAT_EXC) >> CSR_ESTAT_EXC_SHIFT;
    + int ret = RESUME_GUEST;
    +
    + vcpu->mode = OUTSIDE_GUEST_MODE;
    +
    + /* Set a default exit reason */
    + run->exit_reason = KVM_EXIT_UNKNOWN;
    +
    + local_irq_enable();
    + guest_state_exit_irqoff();
    +
    + trace_kvm_exit(vcpu, exccode);
    + if (exccode) {
    + ret = _kvm_handle_fault(vcpu, exccode);
    + } else {
    + WARN(!intr, "vm exiting with suspicious irq\n");
    + ++vcpu->stat.int_exits;
    + }
    +
    + cond_resched();
    + local_irq_disable();
    +
    + if (ret == RESUME_HOST)
    + return ret;
    +
    + /* Only check for signals if not already exiting to userspace */
    + if (signal_pending(current)) {
    + vcpu->run->exit_reason = KVM_EXIT_INTR;
    + ++vcpu->stat.signal_exits;
    + return -EINTR;
    + }
    +
    + kvm_pre_enter_guest(vcpu);
    + trace_kvm_reenter(vcpu);
    + guest_state_enter_irqoff();
    + return RESUME_GUEST;
    +}
    +
    int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
    {
    unsigned long timer_hz;
    --
    2.39.1
    \
     
     \ /
      Last update: 2023-08-03 04:24    [W:4.536 / U:0.004 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site