From patchwork Thu Jun 29 07:55:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 114229 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9482578vqr; Thu, 29 Jun 2023 01:31:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Ok4vPZbj/X97ACda7yY6DpgvSd/TnSduz6x4CG9rKGqr563+w7Uugq5FeVJTP8+XBdkW4 X-Received: by 2002:a17:902:f691:b0:1af:adc2:ab5b with SMTP id l17-20020a170902f69100b001afadc2ab5bmr44923921plg.0.1688027463878; Thu, 29 Jun 2023 01:31:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688027463; cv=none; d=google.com; s=arc-20160816; b=iSitCP5SvVeNkJVe96hfTrMO4w5j/i+7TFkj0pWd27bxpZpk2VHkRbdfipD1DIhIYk AQM+FT67tJMUElSuqWepzGfwpojmczyJgTXrMmDNHtGsDGP71hZEB7RnInH038oCTcQ8 Qr6tFFmmHAIDBCTWhagJlk8Ann2B0lhhs2iiZN449jIFgavY0SXpg4OQO5ZIlvjDAdrf +3obYeR8vRLS0GlAKX9zXUt6uxAgsFNrXI996QItVEIB6737e1K1v+GwH5glDk/Utm2O N659gR3p/OnfSTpYv+Twrc6new2bQnVhWLUiQO2PBukAFXUEQm+g7M6ig3Q3JsLc/kr4 Lr4w== 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=KIvr3S6NVxouALk/OQfcqJOzxjsWUF61gNJlfnnLiIc=; fh=5MymQ7GIBp7zNXW64cKeokietRhKQkEhpOBaNYPDGGU=; b=sV5p9YDJdZPXv5WpSU8L5vA5os+lmqO87eykjPGo7TH8jy6Qudd99+KE1DFx2uB1ep Nf8ImQhCH7laxzx1wMcqxYWwhVaDddvzp5tZGuugCrbBq0a9RkZ+Z1hCawtpW6f0GxYN cHOa/ge53UW+mz0+dO5AdntzzkPeWHtq2u29B7vSGDG5dXHVOuQNSNHoPjg/mxlxAMrJ mfv8RZsLnywlTu6GlQPSuZvXKZS4Wr1jD+zVsUMkYt6DtJUd8p2h3nlbOUjfaQ2RURAP kZ8P7JTsoqikJB0ZGKa2hd4o6WuMPlIZ151MvCG+RCH9r3nLRNQMcB60KEt75qN8YMlM D+TQ== 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 c9-20020a170902d48900b001b04bc1f28csi10788913plg.517.2023.06.29.01.30.49; Thu, 29 Jun 2023 01:31:03 -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 S232579AbjF2IC6 (ORCPT + 99 others); Thu, 29 Jun 2023 04:02:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232487AbjF2H4W (ORCPT ); Thu, 29 Jun 2023 03:56:22 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 83DEE3A91; Thu, 29 Jun 2023 00:55:49 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Bx2cUAOZ1k8sQDAA--.6016S3; Thu, 29 Jun 2023 15:55:44 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxzyP6OJ1kYGYQAA--.18424S10; Thu, 29 Jun 2023 15:55:44 +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, hejinyang@loongson.cn Subject: [PATCH v16 08/30] LoongArch: KVM: Implement vcpu handle exit interface Date: Thu, 29 Jun 2023 15:55:16 +0800 Message-Id: <20230629075538.4063701-9-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230629075538.4063701-1-zhaotianrui@loongson.cn> References: <20230629075538.4063701-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxzyP6OJ1kYGYQAA--.18424S10 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?1770025085854810486?= X-GMAIL-MSGID: =?utf-8?q?1770025085854810486?= Implement vcpu handle exit interface, getting the exit code by ESTAT register and using kvm exception vector to handle it. Reviewed-by: Bibo Mao 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;