Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2398322rwd; Sun, 21 May 2023 20:28:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4I1IMwryNr8WB0APnn7XAEJng7jSB3cZx/MJCnjZ6yIMJHI0Y/xsAHKzC56qnKGjAW1wyB X-Received: by 2002:a17:90a:7f82:b0:250:40f5:6838 with SMTP id m2-20020a17090a7f8200b0025040f56838mr8814658pjl.30.1684726118752; Sun, 21 May 2023 20:28:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684726118; cv=none; d=google.com; s=arc-20160816; b=XoXmXxOGSqX1+NyVMjzq2Y3HTn4TkH1xdoL4Zim4jULUYqcY32N+DRLDz88Dx5IgFm JmlvyDE+C4gw9EQ1uapJP3UmNu/bU61kxLBSn54i7NWBKydWfOAhlc6hoInuLZhBSZM4 RutUmSo8+ChtkLyelBhrfhlBB6I+IJ+nuNk7/DZfPO6lnCRjJnJZG2f6RmI/Su2oMAq4 FnSMt8cawPUqafHw1UtvjecgJSRDf5iXpmBfA/hlIYGjXvXJCj0im2M59BAX3HC91dQc y/pc2Xc6U/ylE/MdltFhihQjv/BA+GNGHAIFRZnDZdJnJqo1TyNvD0aSSduNAAuK3ZcL hpFw== 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=YQNuVF2HiKZ1pLRNRGyJJzdCrMxp85EZEiiTfYVovgc=; b=Tx3FraMdlOdB84v0oafXsRHOMydo7sPw3mf62qhP3yiHTPmMc/dXAFMxDJ9bl7Vqux bpNXD5do5wlXsMC4nyuVhDhyGE1YBXU+RDjXr873eYpWZfqeMJDV57po+r/Q3+ADxZsG 4WHJJUQaWj3SnkEf6qylN8zIPMohQ2+oBc5C7wIXLvCOghcgA31GjZFyu9hFC1J+SQCf CbtYe9y9GNBxn31zu23N9p+DwKoUiignD35iOhoMtiKBxLSw2LBbrO+no5AL/o5nQw3I QCWgydsJ90pwHhP8VZlu4VUJdvGOJm2NUTTmOioHY0rhS6/Bw+FCYWq77xc3FTNfUle+ 4cdg== 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 mm16-20020a17090b359000b0024e1138cd9dsi3794929pjb.157.2023.05.21.20.28.26; Sun, 21 May 2023 20:28:38 -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 S231691AbjEVDOK (ORCPT + 99 others); Sun, 21 May 2023 23:14:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231572AbjEVDMa (ORCPT ); Sun, 21 May 2023 23:12:30 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7609DE0; Sun, 21 May 2023 20:12:27 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Dxi+qa3Wpk08sKAA--.18598S3; Mon, 22 May 2023 11:12:26 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxMMiR3WpkJIFuAA--.54000S27; Mon, 22 May 2023 11:12:25 +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 v11 25/31] LoongArch: KVM: Implement handle fpu exception Date: Mon, 22 May 2023 11:12:11 +0800 Message-Id: <20230522031217.956464-26-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230522031217.956464-1-zhaotianrui@loongson.cn> References: <20230522031217.956464-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8DxMMiR3WpkJIFuAA--.54000S27 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7trWDZrW7uw1UtrW8JFWDArb_yoW8JFW8pF WfAwnYkr48Wry7ta9Iy3ZFqrsxArWkKry7Wr9Fk345Zw4Ut3s5XF48KrWvgFy5Kr1rXa1S qr13KF98uF1UJ3DanT9S1TB71UUUUbUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bxxFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4 AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF 7I0E14v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aV CY1x0267AKxVW8Jr0_Cr1UM2kKe7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY62kv0487 Mc804VCY07AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VCjz48v1s IEY20_WwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_ Jw0_GFyl42xK82IYc2Ij64vIr41l42xK82IY6x8ErcxFaVAv8VWrMxC20s026xCaFVCjc4 AY6r1j6r4UMxCIbckI1I0E14v26r126r1DMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCj r7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6x IIjxv20xvE14v26w1j6s0DMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8Jr0_Cr1UMIIF0xvEx4A2js IEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvj4RuFApUUUUU X-Spam-Status: No, score=1.4 required=5.0 tests=BAYES_00,RCVD_IN_SBL_CSS, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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 1237ceb06d0c..10f9922a7e76 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