Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4366439rdb; Thu, 14 Sep 2023 22:56:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYussJfo39ELlqBKYmUUCY/yf7/4SyDXdheYHaNZ9T2XtNk9+VvKqmC3h7mNMOwsOgdML5 X-Received: by 2002:a17:90a:fb4a:b0:26d:4312:17e5 with SMTP id iq10-20020a17090afb4a00b0026d431217e5mr535035pjb.6.1694757399073; Thu, 14 Sep 2023 22:56:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694757399; cv=none; d=google.com; s=arc-20160816; b=CFOoOTlnZhLQ2Eq8bRsbqoN7u6ow2QDYKO1wJQ4WjCLvEw6oilK+EbWrcKKV9JGR4W tZjkubLDAaFw4nH6X34XB/NGQlpVRk88F4kTdpGTUqqGJ/W3z/VdgLBumaNNfi2I840f Ba3M9sR5vYPT7NVST37zqR0VP1sNBRwwBh1Yu/Xr7oFovtd9XIvHBhvi30BaWJv7FaJy J+4f9maHkaw5RKgMtOPq7uEg7hJ0O8uZlhVnvVKxPbQJS397MggZtsU2wP3ReJsQroV5 iXqMhE3ps8oE+n0b7lBLaVFaFRjEz4jPsSfIoRdgYK9vByQcCWUJTSFj6zs+0Cg643Ka gmJQ== 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=QYO9I/KOp0bwumT/EEpUnX7OMf0vNzf3Sn9cMg22k/g=; fh=ejoaVAUUbBXsA/6jM/beuI9xCYtV2osdR9SpI7hjY84=; b=UZpBd8fALvmrTeg4IsZbKMnnVyKlDujWq3fvHQfRRaIvfaoFLSh70Staw4RCyCaE8E AG8JQLeDuU8MKsHIS8+GVFRGNirBp+z5+2roNesKmNVXNzuf6mBVZYVJL9YI60feGUhL Zltaw6ycLam4nDu+5yp4ZXf0nrYTuAW24VmRlSar1EF1d0BFJSrfmiZWYc3xYFDf5eRt Is1FcqPIo/+Hc2CXqvY9owuIyb4URHSbxPtM2JhLbtRAiaaVgHPuh4i6ow39FaLgl/sP iifkjZD3GP2uEy+EWAzkVWbkMFaZxbICFNgIoSdzhJSazSn8PEAPi9iGdKbIHDhwl/QX rzGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id z18-20020a17090ad79200b00267f99d5b8csi2795465pju.20.2023.09.14.22.56.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 22:56:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 90CEE82F4091; Thu, 14 Sep 2023 18:50:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231458AbjIOBuP (ORCPT + 99 others); Thu, 14 Sep 2023 21:50:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231327AbjIOBuF (ORCPT ); Thu, 14 Sep 2023 21:50:05 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 50986271E; Thu, 14 Sep 2023 18:50:00 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8CxbetFuANluf4nAA--.9229S3; Fri, 15 Sep 2023 09:49:57 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Axndw9uANl+ioGAA--.11927S10; Fri, 15 Sep 2023 09:49:56 +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 Subject: [PATCH v21 08/29] LoongArch: KVM: Implement vcpu handle exit interface Date: Fri, 15 Sep 2023 09:49:28 +0800 Message-Id: <20230915014949.1222777-9-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230915014949.1222777-1-zhaotianrui@loongson.cn> References: <20230915014949.1222777-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Axndw9uANl+ioGAA--.11927S10 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 14 Sep 2023 18:50:18 -0700 (PDT) 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 | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index a510082e9b..bfc2ec1a88 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -104,6 +104,47 @@ static int kvm_pre_enter_guest(struct kvm_vcpu *vcpu) return ret; } +/* + * 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; + + guest_timing_exit_irqoff(); + guest_state_exit_irqoff(); + local_irq_enable(); + + 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; + } + + if (ret == RESUME_GUEST) + ret = kvm_pre_enter_guest(vcpu); + + if (ret != RESUME_GUEST) { + local_irq_disable(); + return ret; + } + + guest_timing_enter_irqoff(); + guest_state_enter_irqoff(); + trace_kvm_reenter(vcpu); + return RESUME_GUEST; +} + int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) { unsigned long timer_hz; -- 2.39.1