Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9166795rwp; Thu, 20 Jul 2023 00:05:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlEyZhFP/WJGym/EqrRg2QRUAyHU1qtX6RN2HH0V1FIYYz0TWOshKaubhgVTZ6Wsl2ejS5ph X-Received: by 2002:a17:906:2c1:b0:98b:dc6c:b304 with SMTP id 1-20020a17090602c100b0098bdc6cb304mr1720400ejk.38.1689836730407; Thu, 20 Jul 2023 00:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689836730; cv=none; d=google.com; s=arc-20160816; b=VJFZNZdnHJD/4UvncAl04/o2kXlPm+SnmAigzA1tQuOwZxRXzJbBCkXgjaDbt+Kyvy M5qiLrfSm2V0JtGKSi9R2+B3Lc/oFVIZw6c6q/dU8noPdykdCE6kg/1SWp0H57znqOuw YogPTAb9JHvcg8sNPwah8tiT90cwbBx1OJEMC+lUJsTSen+eVqr14yUAo369DEjqK3Hc b0Kqg8eAyMILSGxGI//qBpr6lVd4Nt+53cHB+U9/ogf2YI+2OWW/uSW/8xqaqVtUkVUg Agt49gT9o15fFGRp/98NZj9IGPR5uCZBP1p4ePOgjZqePB6zJ+qUFbBYQDjiYFtWQPyM DBhQ== 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=kOy0dT2G76OH8M2j5J4qR41U115vk/oTR9mRcZ+8+M5w1PcQLIrFg3Q2L8MZefOOXX 9D2VofGw1TUz+7DFEryUF6pEqtZf/vzqt5LzMDGT3/vKWhkL+ynH8XBGfjdRXbEnnxAH 1rejo7oZ5M0u2dlSB2pkbOeHbZct+L19w7j4YUGQd/+/nPBvtL6o63c8GwbgSTebVtAa 5Qv9CvwQTINYOJjEwxz155GLMII3HsiHeLJKF6m8hXb838BwpTzPFQL4fpZ0n2oAT3xT 6WB15SidcOCGw605UVcy3TRq9XK8DTMxBivwUfdJlGP6DYBZlyEFIZq99DslDqS8MPDO Varw== 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 w22-20020a17090652d600b00997bf681534si257743ejn.230.2023.07.20.00.05.05; Thu, 20 Jul 2023 00:05:30 -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 S231169AbjGTGcS (ORCPT + 99 others); Thu, 20 Jul 2023 02:32:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230292AbjGTGb5 (ORCPT ); Thu, 20 Jul 2023 02:31:57 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AE01D2D72; Wed, 19 Jul 2023 23:30:25 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Cxc_AG1Lhk8o0HAA--.19217S3; Thu, 20 Jul 2023 14:28:22 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxvM7907hkHU81AA--.16059S27; Thu, 20 Jul 2023 14:28:22 +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 v17 25/30] LoongArch: KVM: Implement handle fpu exception Date: Thu, 20 Jul 2023 14:28:08 +0800 Message-Id: <20230720062813.4126751-26-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230720062813.4126751-1-zhaotianrui@loongson.cn> References: <20230720062813.4126751-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8CxvM7907hkHU81AA--.16059S27 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,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