Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1803578rwd; Fri, 9 Jun 2023 02:19:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7p2tvBzRQa4+irctHMOizIzZI88W2S81qN4dIR74rbDXQSnEZOQQ03A2g2/Cm0tL0ikiLl X-Received: by 2002:a17:902:ec8a:b0:1a1:d54b:71df with SMTP id x10-20020a170902ec8a00b001a1d54b71dfmr1556405plg.0.1686302379204; Fri, 09 Jun 2023 02:19:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686302379; cv=none; d=google.com; s=arc-20160816; b=HRxvqUhhGYEi/v+Cj2iGOvUCKBKS7LJ5E/xwp1+vooQtQW5FGu4+xt/e+jS4bL4XAv lIbAc7Sd+d2UbywGU0QOO4JKZdZXQ4KyOcTNuBszATDVW7pWb74JTdr+c8+ntW6MRe1A Wsaku8oQLQdNgrsdUA0sdputTil7N0ZJRjA+g+p6jMNn942HTxUYX/K5DQipoA+N5DCz 6tIg60qKJ20Z0B5JCSOM1/bY/ZyXJ/YjP+L/TK7aLaX+g8HyFJH1mgpMZXIKEcEycscj Jh38v6nVRILgDMPkSGDwqYdtCLqj3tJh6XypcfxEbmFzMG35s8zdxQiynvkb5os7+s5Y CWQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=hITzPB2vkpZxFpBbJyN80noRiL3x23Jbtx1XNWyanHI=; b=t7St5gGYmb7G4Q3Vj1MMt0Lqm2UFJkoOMG+Agim8dEMbZpO24uJPjqk+bQsyy08ngk wW0MGlwKACUNu+RuNmyKh2cNPmdlRVE6YbcrAr6wUKTOy7eHpYOyqmfJZ7QhhgPtmWH8 0hVwZEbCFBVmSH0LYy3LaIMI6XF1Yqw6sTKPUQvUUf2uwuVC4+AaUImx6YazYYCGnD0o YjDlZXDjdVPh28AaFjNYU/B774fpMh8ygbXaCmnZM9P2S2sQlbuY1i0RnB0LF9YfoXVQ wmok4COeo3qqw/fSYm0OVJgn279dmuSvej6AIzCXYp8XwMnEPxdK9v4VtLXy/pjA62+z sxqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id im16-20020a170902bb1000b001b1a2c14a48si2449354plb.141.2023.06.09.02.19.27; Fri, 09 Jun 2023 02:19:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241308AbjFIJHM (ORCPT + 99 others); Fri, 9 Jun 2023 05:07:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241204AbjFIJGB (ORCPT ); Fri, 9 Jun 2023 05:06:01 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5F83A210E; Fri, 9 Jun 2023 02:05:50 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxEelt64JkzfsAAA--.1098S3; Fri, 09 Jun 2023 17:05:49 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxluRO64JkSXEKAA--.31854S6; Fri, 09 Jun 2023 17:05:48 +0800 (CST) From: Tianrui Zhao To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Huacai Chen , WANG Xuerui , Greg Kroah-Hartman , loongarch@lists.linux.dev, Jens Axboe , Mark Brown , Alex Deucher , Oliver Upton , maobibo@loongson.cn, Xi Ruoyao , zhaotianrui@loongson.cn, tangyouling@loongson.cn Subject: [PATCH v13 08/30] LoongArch: KVM: Implement vcpu handle exit interface Date: Fri, 9 Jun 2023 17:04:56 +0800 Message-Id: <20230609090518.2130926-9-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230609090518.2130926-1-zhaotianrui@loongson.cn> References: <20230609090518.2130926-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8DxluRO64JkSXEKAA--.31854S6 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement vcpu handle exit interface, getting the exit code by ESTAT register and using kvm exception vector to handle it. Signed-off-by: Tianrui Zhao --- 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 eba5c07b8be3..a45e9d9efe5b 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