From patchwork Tue Feb 14 02:56:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 56620 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2723487wrn; Mon, 13 Feb 2023 18:58:46 -0800 (PST) X-Google-Smtp-Source: AK7set/JmoLjJV6gmLULvOdkYj9DNq8f8zHQk6x+RqfNrXmrqG85S6+AiAzf9je4xpGqqPDOG4AS X-Received: by 2002:a17:90b:4c8d:b0:230:acb2:e3f0 with SMTP id my13-20020a17090b4c8d00b00230acb2e3f0mr690742pjb.33.1676343526201; Mon, 13 Feb 2023 18:58:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676343526; cv=none; d=google.com; s=arc-20160816; b=LQNV63dXmK2p9UpZ5bWDU3h40ZkQ0KgqvRXmd9GYPGtL70oNo1aT67Ogk2SV2K/jmO gTTW1lF3ZRxL1rz0J4T054Jkm0mZL+fWjJBEoA8IGni1nnCwbyXv5BId9jb4zI62eRuz Bfmlx/gliqsmMJF3NwzfAo9XZXldMO6ljbmiaYKcLOcDSyiS4JLmO/fH6PhCZARR1Vc6 S+IfXNs/fxN6KimAIwUoTLv/WG18GZ5lkTNA9aWG2qXX+uXQghpErYcuT3HLR88CRleB T74Y1etcPt0n6D7sAMPqfRe0RR86WCQ1Q1wgOVCGChSARVz5mONXZunjMS8XLR/3PVMD B5HQ== 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=sBajucdtqV5fmmbTtcYinA1OuMxRL3FL1UAbFK06xXI=; b=PIVzQXd+rzNTHhFoEXSVnA3rtH2FMjolGnNxw8mR/eABGzbgQbYBeCZ1N0G1ZXHyu+ Uuw9fAdA5chGpiYMeu4LJWAVhF8wEmizvT/PnZtdxBWfuD2f27QPJ1MYJOzfX0gWgjm+ dkvd1Rq2hG/scGKwyuN2G3GFNVm5ZF0Uf+3dSJHSdenJGqMCGACYF8qWXuFpHsMiD9hH UmUPSArXl2ukM2Fyem1gzUjp5DumtrmTg9fYTlew9EiRB+VICh1/uEX4a6MFmprUHcRk MwzPaSNiqffCUG2SyIDoYctovBQ2TF/QluUDJceb/ZzUA7s9ij6Mn0DPtNiuPj3qmMle cs7g== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k10-20020a17090a9d8a00b002340e8e4d6csi3001044pjp.94.2023.02.13.18.58.33; Mon, 13 Feb 2023 18:58:46 -0800 (PST) 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 S231526AbjBNC5r (ORCPT + 99 others); Mon, 13 Feb 2023 21:57:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229781AbjBNC5B (ORCPT ); Mon, 13 Feb 2023 21:57:01 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3816C17CCC; Mon, 13 Feb 2023 18:56:59 -0800 (PST) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Dx3tp5+Opjw1cAAA--.1170S3; Tue, 14 Feb 2023 10:56:57 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Axeb1w+OpjmZwyAA--.28802S22; Tue, 14 Feb 2023 10:56:56 +0800 (CST) From: Tianrui Zhao To: Paolo Bonzini Cc: Huacai Chen , WANG Xuerui , Greg Kroah-Hartman , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Jens Axboe , Mark Brown , Alex Deucher Subject: [PATCH v1 20/24] LoongArch: KVM: Implement handle fpu exception Date: Tue, 14 Feb 2023 10:56:44 +0800 Message-Id: <20230214025648.1898508-21-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230214025648.1898508-1-zhaotianrui@loongson.cn> References: <20230214025648.1898508-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Axeb1w+OpjmZwyAA--.28802S22 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7tF45ur4xuFW7KFWUtF47Arb_yoW8Gr18pF WfZwnY9r48Wry7ta9Iy3Wqqr43CrZ5Kry7WrZFk345Zw4Uta4rXF48KrWvgFy5tr1rXa1S qr13KFn8uF1UA3DanT9S1TB71UUUUjJqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bxxFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4 AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF 7I0E14v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aV CY1x0267AKxVW8Jr0_Cr1UM2kKe7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY62kv0487 Mc804VCY07AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VCjz48v1s IEY20_WwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_ JF0_Jw1l42xK82IYc2Ij64vIr41l42xK82IY6x8ErcxFaVAv8VWrMxC20s026xCaFVCjc4 AY6r1j6r4UMxCIbckI1I0E14v26r126r1DMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCj r7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6x IIjxv20xvE14v26w1j6s0DMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8Jr0_Cr1UMIIF0xvEx4A2js IEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvj4RKpBTUUUUU X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757773589227150458?= X-GMAIL-MSGID: =?utf-8?q?1757773589227150458?= Implement handle fpu exception, using kvm_own_fpu to enable fpu for guest. Signed-off-by: Tianrui Zhao --- arch/loongarch/kvm/exit.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c index 30e64ba72..89c90faa1 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -625,3 +625,30 @@ 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(!_kvm_guest_has_fpu(&vcpu->arch) || + 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; +}