Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4284722rdb; Thu, 14 Sep 2023 18:54:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGk4vLMLlA42wMByFUlKBYUf8a0jVNnb23vSA4Edv7uxL8vCNmSI/+fwgQmBGJ7GtS6/2ki X-Received: by 2002:a05:6a00:179b:b0:68f:b7f6:f1df with SMTP id s27-20020a056a00179b00b0068fb7f6f1dfmr415980pfg.5.1694742844995; Thu, 14 Sep 2023 18:54:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694742844; cv=none; d=google.com; s=arc-20160816; b=zFwagZOw+gsk5v9HNiXoHu5+GPj99QbAu/z/KPR9WV3knBDyHzF1tZ4aygE2JZVGHt Rd8ZGlrdN+ygI6ECxzac02TmPwIkoFu2wSevZWNK0ICha0Z6ZxATaWmOk5aMZCSmabeD 7GvCBHX01oX34yrTfVraqnIoaRMGFJ8TitQMfdWuZ/1wMvqxjXZQaxzSweCWmU81xmuL pCfICWg4bFTFPvzkGBPIYhi2fU0yczMrkcnA4LEF+voaybSpebBhB3oddw7VUNhZMbmD L1Sp68ojOzJHltmh8BMBz4+vgWQ2Csm/nwJrh+YaOSvtDRftmdDuxXOaKXAx2WD3oe+b Nu9w== 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=Ta/k1hzNa7zlxNwF4kuOedIHoFXR1zhVqF0Bb+Q4AEI=; fh=ejoaVAUUbBXsA/6jM/beuI9xCYtV2osdR9SpI7hjY84=; b=digB5iefcSvl40AIYm0ZfeS/CbCF1mUDqgxwS2j1Nd5tm9WP70jgILd9tQh5QpfCV/ Owg82sIcKIU51m1WIYzgQTImd6KByM51Nf3hlAcehg1yK+1ZoGwBJiFyiSWxF9wq/wUa ZssKTN60FdM8c1UowsKJV22eNGhzlJya6Tjgsv43j4glkWEZzmDg3GrUHM/EAI6xZIf0 P0mTRnll88GEB8P3ag+/euuBv06UA/Xh1qY7JGGBA3p7ypyZ74lPoTrO2zeIl0zahBL/ XQSaK8jhDI/xFuZ6+ycQKer/hjXPRBa7N/cQma/FOG2hvrrLfiUraJ6P7fuV9k8XGWfk 4doA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id bq10-20020a056a000e0a00b00686b62a6dc4si2445054pfb.145.2023.09.14.18.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 18:54:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 8AFCD8377BBA; Thu, 14 Sep 2023 18:52:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231906AbjIOBvP (ORCPT + 99 others); Thu, 14 Sep 2023 21:51:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231268AbjIOBuw (ORCPT ); Thu, 14 Sep 2023 21:50:52 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7B2D135B5; Thu, 14 Sep 2023 18:50:15 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxJuhMuANlbf8nAA--.18113S3; Fri, 15 Sep 2023 09:50:04 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Axndw9uANl+ioGAA--.11927S26; Fri, 15 Sep 2023 09:50:03 +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 24/29] LoongArch: KVM: Implement handle fpu exception Date: Fri, 15 Sep 2023 09:49:44 +0800 Message-Id: <20230915014949.1222777-25-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--.11927S26 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 (groat.vger.email [0.0.0.0]); Thu, 14 Sep 2023 18:52:17 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Implement handle fpu exception, using kvm_own_fpu to enable fpu for guest. Reviewed-by: Bibo Mao Signed-off-by: Tianrui Zhao --- arch/loongarch/kvm/exit.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c index 004b91055a..a91811918d 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -638,3 +638,29 @@ static int kvm_handle_read_fault(struct kvm_vcpu *vcpu) { return kvm_handle_mmu_fault(vcpu, false); } + +/** + * kvm_handle_fpu_disabled() - Guest used fpu however it is disabled at host + * @vcpu: Virtual CPU context. + * + * Handle when the guest attempts to use fpu which hasn't been allowed + * by the root context. + */ +static int kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu) +{ + struct kvm_run *run = vcpu->run; + + /* + * If guest FPU not present, the FPU operation should have been + * treated as a reserved instruction! + * If FPU already in use, we shouldn't get this at all. + */ + if (WARN_ON(vcpu->arch.aux_inuse & KVM_LARCH_FPU)) { + kvm_err("%s internal error\n", __func__); + run->exit_reason = KVM_EXIT_INTERNAL_ERROR; + return RESUME_HOST; + } + + kvm_own_fpu(vcpu); + return RESUME_GUEST; +} -- 2.39.1