From patchwork Wed Sep 27 03:09:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 145124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2365161vqu; Tue, 26 Sep 2023 20:58:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFfncthLQv57UbPg4owyE0pyQ5c6RNt158XduGO2dd/VNlLI5RDVsSTaVIm52V4571j3P/W X-Received: by 2002:a05:6808:a98:b0:3ae:1e08:41fe with SMTP id q24-20020a0568080a9800b003ae1e0841femr887413oij.57.1695787133173; Tue, 26 Sep 2023 20:58:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695787133; cv=none; d=google.com; s=arc-20160816; b=pnDb7D6HaAF5vI/WaM2vqKaa574qweK+kwpPu086Ymck+tzJEyWRPBjOyi/6BxJP0P z5Fx07addsOyYN7K9uvAILik34t0ZCu1FmsGthavKGxvrHc6hFYP7SkvaCdSUc+sOqib +kLBX77JvGXOJyduANrYCrDG8E5nL17niyKBFVwrwyqRNyiodDY73fsQ4+AXaNxTs5IW 1u7Xty9Uxk3753R9znKrfmcE+3aRF6EdM/o3gbrnHFGBWmuB/sRB5nlDyymKsApXR148 R4IcpnWCYt8ICmaTLb9nMSgXEJUr7aRRzQzICypxhr9KHu2Yxtw6tY6gpOZHRvivI2ox W3lg== 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=benHCXokLb6W3XW9o7XxkG8BVrKTi8X9QUszostd+bU=; fh=DndB7O6DTG6Sgonrk2zkDJR5MPyE/Qek5uYuwsra5zw=; b=0cWBUjxf3mYWOlkMHtJd1nNQ7rhna4bl4fjGNDF/OkXVFE9F17aCVY//5ZOdO/sjsl uuyiD3S308X2sbqrL1XuLIy9dM2X1c2Gm6rbyFzFQQ8axUyA1a4eNNiJ920L84Lt+U3P levCJUdKl2e1EdBop4/c5qDYRGD2ch3llQmI7QpzGF7vqFmmO5pNla/mXrhQCvc0ebIT uCReia/b00HH5o7eXydJ3FANrBkOgIPpDY4+BlnWI7NePWPJ2BWjL83wXJo143TmvAAS Q1f8Hh24xg2Vl5sjNryas2CNWJELf10QuNP3brtQXbPUoLsbAZN+ZeDCx1kks7BCnowW p1Tw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id fa14-20020a17090af0ce00b00277624ffa82si6085332pjb.86.2023.09.26.20.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 20:58:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 6389E80C5A33; Tue, 26 Sep 2023 20:57:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229705AbjI0D5X (ORCPT + 26 others); Tue, 26 Sep 2023 23:57:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229617AbjI0D4L (ORCPT ); Tue, 26 Sep 2023 23:56:11 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 06210CDB; Tue, 26 Sep 2023 20:10:15 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Cxc_AQnRNlkRctAA--.20871S3; Wed, 27 Sep 2023 11:10:08 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxjd4InRNlhZETAA--.42466S22; Wed, 27 Sep 2023 11:10:08 +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, Huacai Chen Subject: [PATCH v22 20/25] LoongArch: KVM: Implement handle fpu exception Date: Wed, 27 Sep 2023 11:09:54 +0800 Message-Id: <20230927030959.3629941-21-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230927030959.3629941-1-zhaotianrui@loongson.cn> References: <20230927030959.3629941-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cxjd4InRNlhZETAA--.42466S22 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 26 Sep 2023 20:57:42 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778161688865122863 X-GMAIL-MSGID: 1778161688865122863 Implement handle fpu exception, using kvm_own_fpu() to enable fpu for guest. Reviewed-by: Bibo Mao Tested-by: Huacai Chen Signed-off-by: Tianrui Zhao --- arch/loongarch/kvm/exit.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c index c31894b75b..e855ab9099 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -631,3 +631,30 @@ static int kvm_handle_write_fault(struct kvm_vcpu *vcpu) { return kvm_handle_rdwr_fault(vcpu, true); } + +/** + * 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; +}