Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp15850356rwd; Mon, 26 Jun 2023 02:07:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6b12uucQZ6MJUjZUme95U8Akugf7kZkRmSfWy6ZqXajkURjn+BilDtrXLjtTs4k1O8goOp X-Received: by 2002:aa7:c1cc:0:b0:51b:ebea:18f9 with SMTP id d12-20020aa7c1cc000000b0051bebea18f9mr6608683edp.20.1687770440573; Mon, 26 Jun 2023 02:07:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687770440; cv=none; d=google.com; s=arc-20160816; b=aZIEAFHgfNXpGmZOQJXy7olMedrqJ9Dr7CKeoxMlmAOJjWFtiSA2h9T0DKFG2+YzFh PtJxJsSvTRC/jLCvlQyEHzHX+BueUbKCvLfOB1gkkEXZ6UFkn5Ja/2jmcH3vy8KR/UNU GbD0FpK7np/Ej4EgIUYDrtLqtkV7ChpRk9x4khHCbiVR9K61bZJOqa8dpPF2QHZAEwyG wLeBbrV4GLiEg2L7vOBsjM1dJ7akJsM/jyMlKZ1/cd8M9EtbNUbY5tVTAopn0i5LASVy OUN+bExaTo41N1s9/1SSvi+2qogRMc9ANEVbXieHA2cIADdw+vtAIvSmemkwnIr2L++P C1NA== 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=FJJE1KfQOXNgUCxk/Gxke8tBG9gBLo3aFI+sNzAMBeU=; b=NvADqNy2KsHhWaj16hFuLbUDAI2trJbfVOl2sjJbj6wtl6I5Esbsyb+aaRaHvhaQB2 0WXmtD4kgGgEzjsFK2ZaGG6HRNvEwzdHugpioUEJ/c2EUL+f2h3ZO1uhwj75XNwa/h9G tLozEvWbkRdZkNh+xgHeputoryKRlUHE+FjYeGHtx95b8QMH3li2y6No4BiDN/AMSWdG lJFkGH6Mrud38Hz2mYY0zuBY0xmQrL5FT9Hw1VLg+2cizk5nTqBMntH68dHoAl4BaGBZ MP+EOj+gPaR3zd/tLDsG5oKPEGia6cETjpUU/YjOvLQHTHNTVcenDSPSVwGF5eSWijyo Kzdg== 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 bf18-20020a0564021a5200b0051bf8e0c5d1si2557305edb.315.2023.06.26.02.06.56; Mon, 26 Jun 2023 02:07: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 S230376AbjFZIsW (ORCPT + 99 others); Mon, 26 Jun 2023 04:48:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230303AbjFZIsD (ORCPT ); Mon, 26 Jun 2023 04:48:03 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C63C693; Mon, 26 Jun 2023 01:48:00 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxCsa+UJlkdzQCAA--.3377S3; Mon, 26 Jun 2023 16:47:58 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bxxsy5UJlk4hQJAA--.19269S10; Mon, 26 Jun 2023 16:47:57 +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 v15 08/30] LoongArch: KVM: Implement vcpu handle exit interface Date: Mon, 26 Jun 2023 16:47:30 +0800 Message-Id: <20230626084752.1138621-9-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230626084752.1138621-1-zhaotianrui@loongson.cn> References: <20230626084752.1138621-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Bxxsy5UJlk4hQJAA--.19269S10 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. 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; -- 2.39.1