From patchwork Tue Feb 28 07:00:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 62310 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2866955wrd; Mon, 27 Feb 2023 23:26:24 -0800 (PST) X-Google-Smtp-Source: AK7set9DWFAgKbnk078GC/HxpaJUOTpF+r5W9z59hl7ndQ788edVlYz6oy5zSj5B74vs6N7nTCS4 X-Received: by 2002:a17:902:f70f:b0:19c:f8c9:4dff with SMTP id h15-20020a170902f70f00b0019cf8c94dffmr1796231plo.38.1677569183811; Mon, 27 Feb 2023 23:26:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677569183; cv=none; d=google.com; s=arc-20160816; b=Dvbr6odDO3OvPiQvPstvVRSvwJegD8xA3y+IztOsx1oLu3WJJ0g65v8UZZCitbzyWO xnOWgc1/QqlgYKe5LNmz/AvHMXiTPA7+3TLTY2R995hQrGMTYieWTSZtNSqjceZXamwr 7jiWsYgTflaW8iVgQN3wLiYZoN69ETyeXf2B7Vd1pJZ9/2f+/eSgoPlXwuYnwIj8a+fs Dh5WjbkJl95cLKkHK++dW/j+vR1s4F8clBywvUi3684FSwAU/KlB7NeRWKVowGMb7jGM NK+AhHam8RAOQqgkfVIPwRg4LBxCXCcQ/dgTrIw7cqYJcoCkV128UmtmPSIkiKyKjQ7D Zg0g== 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=4etmBbBgmABlgXSx/T6c1W/3Lm2FaZAm2jf9IZbviyk=; b=R8BgAWD81keDA5SI7t1R1NzvvXtQGkHtltoIh6cg0exSLOG2qU/1aG7X32MgJW2erT mbpOwSCLKQuO7+h6TmSyhNP7NhOhq1JjzaEGjcSQPpntpYoxB6QhJ6nqzbH8utn6UtSB jEZ1qBT47T6eDBtCMuq1X9kA0IYubgohlPrK+lCBLhCh47Ks9PWANkOmUw7tUm9QQqiu G9QyN8kewmHXoQXw4jaY12qdMHu0FnrId0aq9F5Tx5aNYDmKRfBzKOv/KpBdJ5Ww4CV3 xFOCya10LfOAj4Xyu4fU7zGoRig++lqA6abVrldwMpyiF4beVWq9ZWu/hKP7hw2zDVDU u4fQ== 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 kv5-20020a17090328c500b0019b7766afdcsi8504461plb.554.2023.02.27.23.26.08; Mon, 27 Feb 2023 23:26:23 -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 S231142AbjB1HCZ (ORCPT + 99 others); Tue, 28 Feb 2023 02:02:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229471AbjB1HBJ (ORCPT ); Tue, 28 Feb 2023 02:01:09 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 61F8483F9; Mon, 27 Feb 2023 23:01:07 -0800 (PST) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxJPyypv1jJmEGAA--.6330S3; Tue, 28 Feb 2023 15:01:06 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bxc+Wppv1jPG9AAA--.15462S27; Tue, 28 Feb 2023 15:01:06 +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 , Oliver Upton , maobibo@loongson.cn, Xi Ruoyao Subject: [PATCH v3 25/29] LoongArch: KVM: Implement handle fpu exception Date: Tue, 28 Feb 2023 15:00:52 +0800 Message-Id: <20230228070057.3687180-26-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230228070057.3687180-1-zhaotianrui@loongson.cn> References: <20230228070057.3687180-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Bxc+Wppv1jPG9AAA--.15462S27 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7trWDZrW7uw1UtrW8JFWDArb_yoW8JFW8pF WfAwnYkr48WFy7tanIy3WqqrsxC3ykKry7Wr9Fk345Zw4Uta4rXr48KrWqgFyrKr1rXa1S qr13KFn8uF1UJ3DanT9S1TB71UUUUjJqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b4AFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4 AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF 7I0E14v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I8E87Iv6x kF7I0E14v26F4UJVW0owAaw2AFwI0_JF0_Jw1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAq jxCEc2xF0cIa020Ex4CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E74AGY7Cv6c x26rWlOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF7I0En4kS14v26r12 6r1DMxAIw28IcxkI7VAKI48JMxAIw28IcVCjz48v1sIEY20_WwCFx2IqxVCFs4IE7xkEbV WUJVW8JwCFI7km07C267AKxVWUAVWUtwC20s026c02F40E14v26r1j6r18MI8I3I0E7480 Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7 IYx2IY67AKxVWDJVCq3wCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAI w20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr1j6F4UJwCI42IY6I8E87Iv6x kF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7xRiTKZJUUUUU== X-Spam-Status: No, score=1.4 required=5.0 tests=BAYES_00,RCVD_IN_SBL_CSS, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * 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?1759058784902491763?= X-GMAIL-MSGID: =?utf-8?q?1759058784902491763?= Implement handle fpu exception, using kvm_own_fpu to enable fpu for guest. 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 85e2523dad33..2f626063ede3 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -626,3 +626,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; +}