Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp311168rdb; Sat, 19 Aug 2023 02:47:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGAZV1NKci07ED2nFPnpBYEdbqZeCGeb6AEgF3fglbnkijtJoXV0ABb4rvJmfAIsVS8d1pY X-Received: by 2002:a6b:c982:0:b0:783:6e76:6bc7 with SMTP id z124-20020a6bc982000000b007836e766bc7mr2640883iof.2.1692438447335; Sat, 19 Aug 2023 02:47:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692438447; cv=none; d=google.com; s=arc-20160816; b=0SeyQKr7DHHDScKvuEdTq2isRrQoLnOEy9VV5ljOonUFF761C9ZXYiGbj8cKZsw5m+ 98ctBn0fUhHp7N8iBcwM08z4F3ncmPCUZK9U1ZIp2ma/05dgE5SOEYQPrR2RnRULzonS uCEsANqVMUZc0j58X0XqNGfmBUtTPEfvVp9LTk1+bVgQKSfG2Pxsob2yhzVPzbeoGoaK KA99zkVz6LffZq+X1cFvBD8BubqVNorZfpYORgrJBejgjV45+zTpUAxSB1YW3525p+bD fCMuaIccSuERajOdskRc9yt+PAdQsZK4P+VM5Y3g6IUoPEGM+wEYUPfnQhfcXAGQi7dS vT1w== 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=nAoNRYgqBcaJxRkEQ9BcPNNvxkPhVQgjUNu5yXItDkM=; fh=vBXozhnPXwSB3DJhjnKWz3f6luaN/KxHDpM6/QeZg4o=; b=pHwRBVZNPyLptRdbQAIQmwyKz8PNiBppfM6c3PMpo+SFMn6X30SK6hn6ATho87GHko 725NOJL6zZpFdEebwTyMBzbTCEcivSPK9PrFQoLxP2b1eMr7Vu2hQ2saYSGi+w7TQ0J6 MoYGDsar6Hign3NQ+owscER/2NbWVFvuit8gt1IzcBUtTjiqukxj2vZHnTzx/JTS6NIm QyU0xZ6B+FHiOiW0lAJHgAv52o7F5QROFt8GCeFminFzACzxwNG5IaeYk9xrlEcisv3m ODYBIuiyuYyNGhaSFcZSI0LSWUnpaWpZEorGobDX3+Z6tmLSkng70AjP9iN+eaYUWlGH 7BhQ== 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:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w59-20020a17090a6bc100b00267668f8be7si3239855pjj.64.2023.08.19.02.47.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 02:47:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B69D630D51; Sat, 19 Aug 2023 01:28:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351142AbjHQNAy (ORCPT + 99 others); Thu, 17 Aug 2023 09:00:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351290AbjHQNAl (ORCPT ); Thu, 17 Aug 2023 09:00:41 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6759A30C7; Thu, 17 Aug 2023 06:00:38 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Dx6erQGd5kpYYZAA--.46685S3; Thu, 17 Aug 2023 21:00:00 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxniPIGd5kmchcAA--.55665S27; Thu, 17 Aug 2023 21:00:00 +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 v19 25/30] LoongArch: KVM: Implement handle fpu exception Date: Thu, 17 Aug 2023 20:59:46 +0800 Message-Id: <20230817125951.1126909-26-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230817125951.1126909-1-zhaotianrui@loongson.cn> References: <20230817125951.1126909-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8BxniPIGd5kmchcAA--.55665S27 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 491d1c39a945..f9c7951261e6 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.39.1