Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1410952rwd; Sun, 14 May 2023 19:36:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5fNRKHwEWrbE60IRNDM0aDCTDliSWUNhALoMy3wzhk4jsgfo8qyUARrmXo6B7WPo3a4xAm X-Received: by 2002:a05:6a20:1048:b0:ff:1df3:51dd with SMTP id gt8-20020a056a20104800b000ff1df351ddmr34400918pzc.37.1684118210901; Sun, 14 May 2023 19:36:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684118210; cv=none; d=google.com; s=arc-20160816; b=sSIFE8Q7HT7etNti/YiT+rxIEiiN9Zuc0Pyd1bXnDBHfbbabjzPnINvCUYK3w7UPgJ 09onAdeIY1zcH6gHdxn2n7eFdxAxYY6lHZ7hQyL33R4wGXU188xzik7KvJ3EIcucPVEM kEymfNZpX9ods6M9aaXsRoVsuNAGfDPe/vfRpnXuV2beFDzBxZFykxCXNx6OhfgMQgjv hixMAlm73gb0xT52g02V1ihn1GPEtwAza1BovqzcVSJvOcZqot6IW2cqwsn0PtXVvBWO aD4GLS3PiEe6eCY/jCOitoQhJNOko7HDDCPGadv8SIP4dtzVp9DZG/obOyJNOGcN6tZ9 ivgA== 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=E61YsjzJllAwuQrJ113Q+IVbapmSOdQvAPupoxNLBVI=; b=AWVxcAYRLj9bXrlE4XJ1vcNXwYFDB/5y795+nHzbFvBucLZKbPKsmyfu0/6NGwckdM en6/C+0r0DWDhalPMNRdy8f9pyTgujLFCDxQk8aDrWTVBFW7e8nuS4K9I5EjN9Gr3vfD kNSWCrwtY/ZfXU/gIB4J9Z4b68MC0059CCBCJDFMobUDfCrZucEw6m/ce8uv2IFjn6B5 ZHutcRmBFWiBIJ7tsfIALNGfBp7/QCdyydA+8uvPgBOsWlPUV0sLtMd9SAUp8jc/ID6V dRJ2/DxyOYsnyccrnSxcuitOhFig65rWBoCl90WkYUeSERyWTE6FtTGa1cd7onATRgzG +KJw== 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 x24-20020a63db58000000b0050beb3fe627si15412191pgi.459.2023.05.14.19.36.39; Sun, 14 May 2023 19:36:50 -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 S238938AbjEOCR2 (ORCPT + 99 others); Sun, 14 May 2023 22:17:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237997AbjEOCPm (ORCPT ); Sun, 14 May 2023 22:15:42 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 423D2172B; Sun, 14 May 2023 19:15:39 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8DxyOnKlWFkL7AIAA--.15032S3; Mon, 15 May 2023 10:15:38 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dxn7O6lWFk0KJeAA--.33838S27; Mon, 15 May 2023 10:15:37 +0800 (CST) From: Tianrui Zhao To: Paolo Bonzini , Huacai Chen Cc: WANG Xuerui , Greg Kroah-Hartman , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Jens Axboe , Mark Brown , Alex Deucher , Oliver Upton , maobibo@loongson.cn, Xi Ruoyao , zhaotianrui@loongson.cn Subject: [PATCH v10 25/30] LoongArch: KVM: Implement handle fpu exception Date: Mon, 15 May 2023 10:15:17 +0800 Message-Id: <20230515021522.2445551-26-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230515021522.2445551-1-zhaotianrui@loongson.cn> References: <20230515021522.2445551-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Dxn7O6lWFk0KJeAA--.33838S27 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7trWDZrW7uw1UtrW8JFWDArb_yoW8JFW8pF WfAwnYkr48Wry7ta9Iy3ZFqrsxArWkKry7Wr9Fk345Zw4Ut3s5XF48KrWvgFy5Kr1rXa1S qr13KF98uF1UJ3DanT9S1TB71UUUUjJqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bx8Fc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4 AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF 7I0E14v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aV CY1x0267AKxVWxJr0_GcWln4kS14v26r126r1DM2AIxVAIcxkEcVAq07x20xvEncxIr21l 57IF6xkI12xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6x8ErcxFaV Av8VWrMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x0262kKe7AKxVWU AVWUtwCF04k20xvY0x0EwIxGrwCF04k20xvE74AGY7Cv6cx26rWl4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1l4IxYO2xFxVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4UJVWxJr1lIxAIcVC2z280aV CY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0zR9iSdUUUUU= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, 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. 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 1237ceb06d0c..10f9922a7e76 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.31.1