Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1698142rwo; Wed, 2 Aug 2023 20:14:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlHEA47bEbM7HdEW4SaZM0odcI/puybBRrU2RL7MYq0AlB2zZGQznP5E6Q7snWI42PbC0qeE X-Received: by 2002:a05:6a21:3e05:b0:135:38b5:7e4e with SMTP id bk5-20020a056a213e0500b0013538b57e4emr15602857pzc.59.1691032451166; Wed, 02 Aug 2023 20:14:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691032451; cv=none; d=google.com; s=arc-20160816; b=SpQm26+6bierXrPcSGEltQrJfGNOLKHL6FSCOHFakugALzvfHJrGo0SDor+tQhiDBC spHcnVfYfiI8JnaCJmE72+sQKjVNUq5PUJDKMputB1eQyoTMH0peB5BiyBfWf7iFQ7VX QUSK6wPGt4Lxo9jaaDkmwHTlQqREmaBUZZCR1zfk/rR9wrgYBS1+PnhVLZ+D6pKg2YlX 3MV4buasTFJkSdrSfTsoHzXbZxqyAeIMmLMejYJ9xAg+vIrKiK9Ee1gXk8AYmRqJpDGX UUFgVMHpvRA9aAtKUS+CnUW6URfW+Fm2w3/+R38v7JNF28UF3RhAV2kSTE8vFt1wwKA5 gRPQ== 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=; fh=vBXozhnPXwSB3DJhjnKWz3f6luaN/KxHDpM6/QeZg4o=; b=Ow47AcwOO+vKd+6LB1VB7AQiOuFKIgp3bLl8G7Auedsoawml4yTvmKPLUdGLYO61vo bh4PzIDdeYe+MP5rpBiGf6UnBmNrYjJ+goiKt+rJ1nYj6RuYSc/Bw2Monk4LGBLN8CFr LJ0cPjEbPhjMH35vl+PDqXlcnx2XT97MQ0sVjDWn/srucGdLSL4pX9GQSEaCIJ57GBZd gRee1xYghXMRkq9CsfSLXNkkyw5R3sOEwenor5D8KpXsPfhUuKRHGwLynqy5M/+HeOTI Zs2UrGlXAJDRQqg0csYyGyl3KdYVczdFdJVLjfiRE0A76QfhV6xBGfFo/6w0rTgW1hv8 3ouA== 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 li8-20020a170903294800b001b000b3f132si6628125plb.298.2023.08.02.20.13.59; Wed, 02 Aug 2023 20:14:11 -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 S232331AbjHCC0E (ORCPT + 99 others); Wed, 2 Aug 2023 22:26:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233551AbjHCCZE (ORCPT ); Wed, 2 Aug 2023 22:25:04 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F2EB644B9; Wed, 2 Aug 2023 19:22:46 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Dx_+tbD8tk6mkPAA--.35046S3; Thu, 03 Aug 2023 10:22:19 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cx_c4yD8tk8oNGAA--.51268S27; Thu, 03 Aug 2023 10:22:16 +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 v18 25/30] LoongArch: KVM: Implement handle fpu exception Date: Thu, 3 Aug 2023 10:21:33 +0800 Message-Id: <20230803022138.2736430-26-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230803022138.2736430-1-zhaotianrui@loongson.cn> References: <20230803022138.2736430-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Cx_c4yD8tk8oNGAA--.51268S27 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