Received: by 2002:a05:7412:3210:b0:e2:908c:2ebd with SMTP id eu16csp38181rdb; Thu, 31 Aug 2023 02:11:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSURPuEokGGGEAeD7G/k+GejCm8xscrQaVPu/8PGfYJpadgZWNkd6AsnaIMCSI6kD72/Jh X-Received: by 2002:a05:6512:2002:b0:500:8257:4b34 with SMTP id a2-20020a056512200200b0050082574b34mr2689893lfb.68.1693473112029; Thu, 31 Aug 2023 02:11:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693473111; cv=none; d=google.com; s=arc-20160816; b=Bykozy9U1ytI+5kf/5cILWHlyHE7JHYameo+BX6D65l7huEaNQE2qst9lefORB+FY7 eatygFUIVOb/DJgvIUzpE+ID4PVgwH9HDqevqSJKyGvajTuujWO1fYAe4Ixy5uhri70p +YbztHUrlp+UgLGF7knYCRMDlyPUvW2o8SH+qYtSN5KaNhd8ywZyADhVDGzdoXTSMSO/ trS2K+GqDRYLr0T6TZhKe7LHjJ3H4XIlZLBVOm29tyFv7WeBWgXUgwDbgIAqfO11r8Br rFuW0ucRVMB48t8kKnsXT1seTpIuYKo/VfwT+is6/SaedBSU8b0Vvleq7jEra7zXqzm9 lo4w== 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=pgNYAJVTc0HQBq74T1mvWteJYsvANvKwh1hTnuVTBbY=; fh=ejoaVAUUbBXsA/6jM/beuI9xCYtV2osdR9SpI7hjY84=; b=ajiBrI7wdH89VqnjnpCcE/QX223ONkIih6fB1vYFXSkAufu56rgFKNzrEZZkZLnKgR 4PvPM8kzW8XtDPeVBRhRpdOpYW62JAhl+IdBW7rR0uyiAkiwU1J0V8qaij4mztGHxcnp qEwGY4Brt/CE3kZQ1pmr9ktf4Bt3goKwgK0CiP9/5zOGmCsVIFlKm8tySvQi0dnYz/MH a6uZZUURoyjtfPa20V/UUaIQvhSyJ2e3QucPRnxe7f+7VIi3TsGGu3w5n+jilRXpiJOp HHsNDNdOybkT6YEtkxgD1zBGJU0BKD6sfHPq74gqzqsWnWEtL2qN8a5btno7uQmHrr2l i/CQ== 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 qc12-20020a170906d8ac00b0098dd7716952si723258ejb.527.2023.08.31.02.11.23; Thu, 31 Aug 2023 02:11: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 S244770AbjHaIcK (ORCPT + 99 others); Thu, 31 Aug 2023 04:32:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229981AbjHaIb1 (ORCPT ); Thu, 31 Aug 2023 04:31:27 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5D3DC10D9; Thu, 31 Aug 2023 01:30:45 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxJuiuT_Bk1l4dAA--.1007S3; Thu, 31 Aug 2023 16:30:38 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Ax3c6gT_BkOPVnAA--.55892S27; Thu, 31 Aug 2023 16:30:37 +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 v20 25/30] LoongArch: KVM: Implement handle fpu exception Date: Thu, 31 Aug 2023 16:30:15 +0800 Message-Id: <20230831083020.2187109-26-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230831083020.2187109-1-zhaotianrui@loongson.cn> References: <20230831083020.2187109-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Ax3c6gT_BkOPVnAA--.55892S27 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, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,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 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 491d1c39a9..f9c7951261 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -628,3 +628,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.27.0