From patchwork Fri Jun 9 09:04:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 105461 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp815893vqr; Fri, 9 Jun 2023 02:21:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6D5dztRC5eaeqtZJnRYy4DbpCfLniLU+H+aWlrJxKg0uXBrlbM+Nb/nS+1iUHORwBAsWmi X-Received: by 2002:a05:6a00:21d2:b0:63b:54e4:871b with SMTP id t18-20020a056a0021d200b0063b54e4871bmr1454428pfj.8.1686302480198; Fri, 09 Jun 2023 02:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686302480; cv=none; d=google.com; s=arc-20160816; b=FtQVYUW5w77h1mmNoKOy3fKJbPtI1QmzAH1qsHMLrcNmLTSWDDYhUvW+KSID8VuvQA jeCDV7kJ/aHagk+kKO3EtC70R0owvOa5SA0AGL+DH65WfBewHVxgRNAN5DdfVT59AvNb eiyPToWFDmbUhvZ1Rgml/seoGBtlbqCtRpKMnJMvQcv5ByZaxmnEiweIT5JA6L9OaPSI cA1IRJIMoNOTxJoAGGh+CCQDSqiuFG20LIXNp7ke3YHCl0pENscfH2GW+qMnlimCvnMN kaX6KmZjUYNwLIKnQdyn12E84P534hrJWAmyNWn1WfDcDOHi4zgBzcLhz31ApiDqtX+k 4AOQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b4-20020a62cf04000000b006615f2c803asi2205056pfg.128.2023.06.09.02.21.05; Fri, 09 Jun 2023 02:21:20 -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 S241310AbjFIJHM (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768216309357454988?= X-GMAIL-MSGID: =?utf-8?q?1768216309357454988?= 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;