From patchwork Fri Apr 7 01:59:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 80622 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1430827vqo; Thu, 6 Apr 2023 19:05:52 -0700 (PDT) X-Google-Smtp-Source: AKy350bdYEmCL29ZTAVp3/OuqDIvB5An4Vj0eKTjFhJxDvEuYuTIff7Q3QrImacIlfESlFmduNoB X-Received: by 2002:aa7:d697:0:b0:500:29e3:ce with SMTP id d23-20020aa7d697000000b0050029e300cemr1340103edr.36.1680833151970; Thu, 06 Apr 2023 19:05:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680833151; cv=none; d=google.com; s=arc-20160816; b=PIRKL24ouRZYCnrJo4u36QAmCBwNlP/5K6eT4En1GBDF6w5BXMKM7asuYM3cQyfXSb GwPZPf4yx97NK30pK10N2HGshBVkYmY7vSm3bDNQ62OQfc3P5TENj74T4eCJSWk3Fe8g HZ93NdkOMDKl1AiY35UhUslh9ngWFk3Nrw1gyqWyTJsM2f1/z6w080jMTFcD8qRLSrS/ IFaK+JuF+CACgJneKZM8Ig3OH2YZjbobmd99bg6qjQDpjuc2wjTc7AP/8c8RQuc1pT1u dSGYwF0cJZM5juQFz22GsKimocmiGAgpTjXQDg14P2bZ3zhesrFy5EJzhfSpwj0b4FBG syVA== 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=O7XwvLzaJWnRBYM+bAUFn4KQnMDl5KShKxcuCo5i6LA=; b=0ET/sb+qbo28nT8I2ku66I7t+5So3vCmFCNyeu4EBKq+reNHenZsLHcAvS1PluAwhs WtuZ8QqHwaSR5tRcEYeaFNoTQIywdMOfOwDy/MB21DU2iFnqnmUs1c+ux0ht43d/5mse 0vGL5h4JypCN2apR0Zvd4b6O+fqVguQgbCjPH68f2gub8ZhXaCa+aV+CSUiQ806eNWqs wWJgkywb83i3Cs38E5EYKiRwpw3nOkM1u9tDeF/4ycmMV9Fwm49kEUV3DzmYIXePZsB1 K0HVl2giDgzx1FpCvFTTrYX7HN+PZm5LcPCmH7ORoVt8bDQCC9gLHBGk1fbiqXiOe/zC pKuQ== 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 k3-20020a05640212c300b00501d70c10bbsi2303132edx.72.2023.04.06.19.05.28; Thu, 06 Apr 2023 19:05:51 -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 S240023AbjDGCBe (ORCPT + 99 others); Thu, 6 Apr 2023 22:01:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239735AbjDGCAW (ORCPT ); Thu, 6 Apr 2023 22:00:22 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ED6E59ECC; Thu, 6 Apr 2023 19:00:20 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Axz_8zeS9kdKcXAA--.36721S3; Fri, 07 Apr 2023 10:00:19 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxLL4jeS9k17sXAA--.23369S27; Fri, 07 Apr 2023 10:00:18 +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 , zhaotianrui@loongson.cn Subject: [PATCH v5 25/30] LoongArch: KVM: Implement handle fpu exception Date: Fri, 7 Apr 2023 09:59:58 +0800 Message-Id: <20230407020003.3651096-26-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230407020003.3651096-1-zhaotianrui@loongson.cn> References: <20230407020003.3651096-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxLL4jeS9k17sXAA--.23369S27 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7trWDZrW7uw1UtrW8JFWDArb_yoW8JFyxpF WfAwnYkr48Wry7tanIy3WqqrsxArZ5Kry7Wr9Fk345Zw1Ut34rXF48KrWqgFy5Kr1rXa1S vr13KFn8uF1UJ3DanT9S1TB71UUUUjJqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj 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=-0.0 required=5.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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?1762481303180026498?= X-GMAIL-MSGID: =?utf-8?q?1762481303180026498?= 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 0daf18242..e218e7a43 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -633,3 +633,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; +}