Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2306092rdh; Tue, 26 Sep 2023 20:58:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPwXyzezyC7u8vcTicu7/7w+wrjSdVXXLuhdUYMym6gSGAZ5taFNS+KRX6rJQGNt7QDHD8 X-Received: by 2002:aa7:88cf:0:b0:68a:4d66:caf with SMTP id k15-20020aa788cf000000b0068a4d660cafmr1017781pff.34.1695787132142; Tue, 26 Sep 2023 20:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695787132; cv=none; d=google.com; s=arc-20160816; b=CjAQWsZ1J6BuARisUZG4RDQ/msPiN4nQzNVTGQCUmKtvkTEeQBHpzy3Cy6xXEz90N+ h6LsNOjdgPmHW3e8UocECKb+JAO4klQpOdWNsxmQC7u4TwVj49dpenQXB3AyyyWT88yB 9OQD3FuMfCpES+codgG/ZGN/lZuc4FVkM7ElcebYKMpkMwyNi7VONpdcZ/7eXHIQFvTK JjQYsHIPzJbh4a2w6oLsnt0tR6qCLOIullXLnkHHoAmsygtuszksBpwQsnD1vhS8I6vS bAxntuNYPkmRFULK5etOcFETUU8uNdgrtfzZUFF9U07hF3YwSyjPaGgxEWk7GbTfeYn6 SZaA== 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 Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id ds10-20020a056a004aca00b00690da053918si14030602pfb.4.2023.09.26.20.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 20:58:52 -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 845DF80C5A26; Tue, 26 Sep 2023 20:57:40 -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 S229702AbjI0D5X (ORCPT + 99 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 Content-Transfer-Encoding: 8bit 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:40 -0700 (PDT) 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; +} -- 2.39.3