Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6072644rwd; Mon, 19 Jun 2023 01:43:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6JZSo7RtFsrCBU8ANEFVBGUgcxNRJrJRYKrJkMk/2Hkfy+qV4iChDaank7ohdmUbOfKBXN X-Received: by 2002:a05:6a21:32a7:b0:121:5be9:b4f2 with SMTP id yt39-20020a056a2132a700b001215be9b4f2mr1657066pzb.5.1687164237691; Mon, 19 Jun 2023 01:43:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687164237; cv=none; d=google.com; s=arc-20160816; b=OrvQiJzTJZmXv3ZgT+Zkdpev1QXMvnpjMje1Nj3s7dNn7xXa53ZM6Y+U2cVG9s+/1R 2o0ZVaxWqwONJYwAt0Yiqj34L3BND3J3IOn2fnBhhXiqj6Gk0m4e7GoC6nwFmj6/Yt8U +/svgTNuqTqv7G8hNKGxLC18TnTZTX1ppVKsuH723AQo3pplMNp2jWUB+Th3sZe2rp2q ghcmtm1lfflbixS/U7/+qlvTECy1LSmMCPy350gxtzTC+88lH4uc557Qyok4hHTIZGEM 30XZH1kki3sdHJBSTyyTwSHdbXhymxQWk5smjEm93dlaf746RVYPtiRfy/P+qrrJvIWF CT9g== 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=Oi1kwRffeA95yRnB5eJTr9VC8FTUO5MydfvkcggDLjk=; b=twOTOsx43yCKusdhHZNIqyvS8lH+ndxhVJzY2N/PEeTjs2QUAxQ1Ve2flKNGSgxiil 2pZ4UgeQHlGDieqrerPSwtsp5EEmP35UfP3YyCDmSayz70rIhd03pI02HPkfB0mVDB7+ 0UnCXW7j0HctlatJkh6UqFbx75jldrNLNoX4/L8R0n9kHCOOb61c92k2J/s0/4+hwGxI siZQyCxDMX+suIKoQREUk2i1G6FcIA8VbKKllGL6b1fTd3KsLPwKs1kkIwbwmxpd2ZDv Nikff80DC5xSo4MflGdTiR2Yj4wtUpcPQp0qdIZNU4tg5ofPT92Z425Ck3BP4il01c6K oWrw== 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 m14-20020a170902db0e00b001aaf607910fsi20908931plx.376.2023.06.19.01.43.45; Mon, 19 Jun 2023 01:43:57 -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 S230000AbjFSIfP (ORCPT + 99 others); Mon, 19 Jun 2023 04:35:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230361AbjFSIdY (ORCPT ); Mon, 19 Jun 2023 04:33:24 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 16A6E106; Mon, 19 Jun 2023 01:33:22 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Bxa+rHEpBkP8wGAA--.13978S3; Mon, 19 Jun 2023 16:33:12 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxC8q3EpBkAgsgAA--.15169S27; Mon, 19 Jun 2023 16:33:11 +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 25/30] LoongArch: KVM: Implement handle fpu exception Date: Mon, 19 Jun 2023 16:32:50 +0800 Message-Id: <20230619083255.3841777-26-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--.15169S27 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 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 36a838607218..17e94ecec140 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -631,3 +631,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