Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6065107rwd; Mon, 19 Jun 2023 01:35:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7O7oSuY7NdEApU0vENLq+zHh3PzaJZcidK1NR/pkoTI/ZrPn8SDFYnV4P4wpvq9fuQoJn6 X-Received: by 2002:a05:6a00:2d1f:b0:666:b0e7:10ea with SMTP id fa31-20020a056a002d1f00b00666b0e710eamr5513076pfb.31.1687163746616; Mon, 19 Jun 2023 01:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687163746; cv=none; d=google.com; s=arc-20160816; b=q3q8s5WoPS6DXSR4YNY8KRMLJ790pHVce1K1blIlQpo8Chvkc84w+oE5ZrGYmBx51W Ky56Rx1NLqjulGtU0ahLmVJn/BLBUBDRN+7NvgXULHWHljJY9sPiBEn5sOc7zYsTxlb1 tnxxhgdow+tyqXGhTIKcaZE99Ph/jnsHF8KWZMobFf+hnjR9jXK9dIyoE65wqq+t3Wgs mGZt7BPa1HZI0Dgj/CTJTXhMP7/TN9sY/B1oUNABTwc7r2VlIZgsI83Get5jGm0JKVNp VF2VVkuI1mI3k8W+Sdb+aHxmuiaZJB4xpt3VgQCbJWFt5bCY/1g9JH/NIzZ/mVZy2kdu aKUw== 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=; b=HEWe/M2khqmowQvbcW2qlKj7KD6WBajKt7l1/ovQl8drc/M5VqfvsGzUFyfmBS5VXb yUwwqkQ5rJudFBiUif5pmfnUWblZVFdv3+s/XRkXxk27/J1AWSCQOjglZHoSIwO1BpbY zDJ40XrzUIthu7KOW/GhMUxcptxELcXBLD6UtWVLq0GuydVab/jg4Ig+gJGEWBfthIg1 eqZa+4FubGkH3KXnIVFiAy4EGO9N8Ptdw0g3GDidqXMQDIxOo1TvdElOKQfdjDqTgJEF JKXvKWtfWIgkdioixhCUTMaSGBTgAqM2ADd4si6R9H5nt/nCrg4SDqXqkQrWULFaqhzM j1gA== 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 e128-20020a636986000000b00543d2b889e0si20639415pgc.469.2023.06.19.01.35.31; Mon, 19 Jun 2023 01:35:46 -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 S230495AbjFSId6 (ORCPT + 99 others); Mon, 19 Jun 2023 04:33:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbjFSIdJ (ORCPT ); Mon, 19 Jun 2023 04:33:09 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 317A8E77; Mon, 19 Jun 2023 01:33:06 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Dx_+u_EpBkZssGAA--.13962S3; Mon, 19 Jun 2023 16:33:03 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxC8q3EpBkAgsgAA--.15169S10; Mon, 19 Jun 2023 16:33:02 +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 v14 08/30] LoongArch: KVM: Implement vcpu handle exit interface Date: Mon, 19 Jun 2023 16:32:33 +0800 Message-Id: <20230619083255.3841777-9-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230619083255.3841777-1-zhaotianrui@loongson.cn> References: <20230619083255.3841777-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8BxC8q3EpBkAgsgAA--.15169S10 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