From nobody Mon Jun 8 04:26:43 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33D9A304BB2; Mon, 8 Jun 2026 01:32:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780882356; cv=none; b=Gh4b6KLpjnZshHnbKYMqSWnGQA/nfcBT7ftj8678601RoZKGsMrA6JCJjs6fFNRGMvyU3jq+KYB8PVOSJ4jmZc0XHOIrZFy7mNFELIL2ywOr3KQC8/pkYdOhFm6L7FlmoPXWRDlzJq+3agRRc5ZbNF1PTR5S9fjXr9S7d+n3L34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780882356; c=relaxed/simple; bh=jzVWtUayeOPCeFSiXCUSWlxb3xZ9FyPrfGI2r0tqKgE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=njK4QywWuZrHkW65PSkQUl5gVWg+/Gk0jWCRKqWOUUAV3GU4c+ohAl4SshV3c/2Eg1rFmYYayh0JWldofDPc/ohdibiOKTA9jW3WOHkShekzlkOqM3uj5kKgiv02h0ON6DdDzVoHUr7MtR/sxXmWaaXMdtxlTDjhTgydFhka040= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8Dx8eqqGyZqK5kRAA--.47440S3; Mon, 08 Jun 2026 09:32:26 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJAxHMKoGyZqNTafAA--.39164S3; Mon, 08 Jun 2026 09:32:26 +0800 (CST) From: Bibo Mao To: Huacai Chen Cc: kernel@xen0n.name, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/4] LoongArch: KVM: Add separate KVM_REQ_LBT_LOAD request bit Date: Mon, 8 Jun 2026 09:32:19 +0800 Message-Id: <20260608013222.375257-2-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20260608013222.375257-1-maobibo@loongson.cn> References: <20260608013222.375257-1-maobibo@loongson.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJAxHMKoGyZqNTafAA--.39164S3 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Content-Type: text/plain; charset="utf-8" There are different structures with LBT and FPU register restore, with LBT the structure is vcpu::arch::lbt, with FPU the structure is vcpu::arch::fpu. And FPU/LSX/LASX saving and restoring share the common structure vcpu::arch::fpu. New request bit KVM_REQ_LBT_LOAD is used for LBT register restore, and rename KVM_REQ_AUX_LOAD with KVM_REQ_FPU_LOAD for FPU register restore. Signed-off-by: Bibo Mao --- arch/loongarch/include/asm/kvm_host.h | 3 ++- arch/loongarch/kvm/exit.c | 12 +++++------- arch/loongarch/kvm/vcpu.c | 8 ++++---- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/arch/loongarch/include/asm/kvm_host.h b/arch/loongarch/include= /asm/kvm_host.h index 776bc487a705..e76a49d4233b 100644 --- a/arch/loongarch/include/asm/kvm_host.h +++ b/arch/loongarch/include/asm/kvm_host.h @@ -38,7 +38,8 @@ #define KVM_REQ_TLB_FLUSH_GPA KVM_ARCH_REQ(0) #define KVM_REQ_STEAL_UPDATE KVM_ARCH_REQ(1) #define KVM_REQ_PMU KVM_ARCH_REQ(2) -#define KVM_REQ_AUX_LOAD KVM_ARCH_REQ(3) +#define KVM_REQ_FPU_LOAD KVM_ARCH_REQ(3) +#define KVM_REQ_LBT_LOAD KVM_ARCH_REQ(4) =20 #define KVM_GUESTDBG_SW_BP_MASK \ (KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_SW_BP) diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c index 3b95cd0f989b..b839c989d3dc 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -756,7 +756,7 @@ static int kvm_handle_fpu_disabled(struct kvm_vcpu *vcp= u, int ecode) } =20 vcpu->arch.aux_ldtype =3D KVM_LARCH_FPU; - kvm_make_request(KVM_REQ_AUX_LOAD, vcpu); + kvm_make_request(KVM_REQ_FPU_LOAD, vcpu); =20 return RESUME_GUEST; } @@ -798,7 +798,7 @@ static int kvm_handle_lsx_disabled(struct kvm_vcpu *vcp= u, int ecode) kvm_queue_exception(vcpu, EXCCODE_INE, 0); else { vcpu->arch.aux_ldtype =3D KVM_LARCH_LSX; - kvm_make_request(KVM_REQ_AUX_LOAD, vcpu); + kvm_make_request(KVM_REQ_FPU_LOAD, vcpu); } =20 return RESUME_GUEST; @@ -818,7 +818,7 @@ static int kvm_handle_lasx_disabled(struct kvm_vcpu *vc= pu, int ecode) kvm_queue_exception(vcpu, EXCCODE_INE, 0); else { vcpu->arch.aux_ldtype =3D KVM_LARCH_LASX; - kvm_make_request(KVM_REQ_AUX_LOAD, vcpu); + kvm_make_request(KVM_REQ_FPU_LOAD, vcpu); } =20 return RESUME_GUEST; @@ -828,10 +828,8 @@ static int kvm_handle_lbt_disabled(struct kvm_vcpu *vc= pu, int ecode) { if (!kvm_guest_has_lbt(&vcpu->arch)) kvm_queue_exception(vcpu, EXCCODE_INE, 0); - else { - vcpu->arch.aux_ldtype =3D KVM_LARCH_LBT; - kvm_make_request(KVM_REQ_AUX_LOAD, vcpu); - } + else + kvm_make_request(KVM_REQ_LBT_LOAD, vcpu); =20 return RESUME_GUEST; } diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index e28084c49e68..c28aa37f37a9 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -239,7 +239,7 @@ static void kvm_late_check_requests(struct kvm_vcpu *vc= pu) vcpu->arch.flush_gpa =3D INVALID_GPA; } =20 - if (kvm_check_request(KVM_REQ_AUX_LOAD, vcpu)) { + if (kvm_check_request(KVM_REQ_FPU_LOAD, vcpu)) { switch (vcpu->arch.aux_ldtype) { case KVM_LARCH_FPU: kvm_own_fpu(vcpu); @@ -250,15 +250,15 @@ static void kvm_late_check_requests(struct kvm_vcpu *= vcpu) case KVM_LARCH_LASX: kvm_own_lasx(vcpu); break; - case KVM_LARCH_LBT: - kvm_own_lbt(vcpu); - break; default: break; } =20 vcpu->arch.aux_ldtype =3D 0; } + + if (kvm_check_request(KVM_REQ_LBT_LOAD, vcpu)) + kvm_own_lbt(vcpu); } =20 /* --=20 2.39.3 From nobody Mon Jun 8 04:26:43 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33A643009F6; Mon, 8 Jun 2026 01:32:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780882357; cv=none; b=LdMk7ZFWoONU1hXLaJuYFeg/aFOHIXfO91gtyKEn0j/VZU7vLGEULWLOJjSxPaLieZiMsIAZ/HxNdsagVwbv95PFzf3sc7tniSQUvTK3RiOLy7DQzxhaOwI2uPWEOWeaSz32xtDNjnoSbHalabj5q8FIUs3y7UHI+mD8AS23i8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780882357; c=relaxed/simple; bh=7X/o4G1fvfmnKd7iOOFpxC41mGun6DPSfaNnPfSQgbM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=d16nTgisg2++vZMhueZSqkLmjo0to8ArdlZ3AtHBY+jgruiwDKpfN5q2caBFJJkmoOpxb3sS5W8qltODelb8AwVYe9zpZCLpYosnHwT2PvFDEKFSMT67fH1OzBjFpM0GDKIj5ggbKmyEIk+0MRl32mKSpgeOerLKP8WaVXFFbLs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8Dx8eqrGyZqLpkRAA--.47443S3; Mon, 08 Jun 2026 09:32:27 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJAxHMKoGyZqNTafAA--.39164S4; Mon, 08 Jun 2026 09:32:26 +0800 (CST) From: Bibo Mao To: Huacai Chen Cc: kernel@xen0n.name, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/4] LoongArch: KVM: Enable FPU with max VM supported FPU type Date: Mon, 8 Jun 2026 09:32:20 +0800 Message-Id: <20260608013222.375257-3-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20260608013222.375257-1-maobibo@loongson.cn> References: <20260608013222.375257-1-maobibo@loongson.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJAxHMKoGyZqNTafAA--.39164S4 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Content-Type: text/plain; charset="utf-8" There are three FPU types FPU/LSX/LASX, which represents FPU64, FPU128 and FPU256, and now lazy FPU method is used with FPU enabling. There are three different HW FPU exception code with different FPU type. The exising method is to enable specified FPU type with responding FPU exeception. Supposing application uses FPU64 and FPU256, there will be FPU256 exception when FPU256 type is used. Here enable FPU with VM supported type directly, it can avoid unnecessary FPU exception in future if further FPU type is used. Signed-off-by: Bibo Mao --- arch/loongarch/include/asm/kvm_host.h | 1 - arch/loongarch/kvm/exit.c | 9 ++------- arch/loongarch/kvm/vcpu.c | 19 +++++-------------- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/arch/loongarch/include/asm/kvm_host.h b/arch/loongarch/include= /asm/kvm_host.h index e76a49d4233b..bad16c5f963c 100644 --- a/arch/loongarch/include/asm/kvm_host.h +++ b/arch/loongarch/include/asm/kvm_host.h @@ -204,7 +204,6 @@ struct kvm_vcpu_arch { =20 /* Which auxiliary state is loaded (KVM_LARCH_*) */ unsigned int aux_inuse; - unsigned int aux_ldtype; =20 /* FPU state */ struct loongarch_fpu fpu FPU_ALIGN; diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c index b839c989d3dc..c8492670f169 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -755,7 +755,6 @@ static int kvm_handle_fpu_disabled(struct kvm_vcpu *vcp= u, int ecode) return RESUME_HOST; } =20 - vcpu->arch.aux_ldtype =3D KVM_LARCH_FPU; kvm_make_request(KVM_REQ_FPU_LOAD, vcpu); =20 return RESUME_GUEST; @@ -796,10 +795,8 @@ static int kvm_handle_lsx_disabled(struct kvm_vcpu *vc= pu, int ecode) { if (!kvm_guest_has_lsx(&vcpu->arch)) kvm_queue_exception(vcpu, EXCCODE_INE, 0); - else { - vcpu->arch.aux_ldtype =3D KVM_LARCH_LSX; + else kvm_make_request(KVM_REQ_FPU_LOAD, vcpu); - } =20 return RESUME_GUEST; } @@ -816,10 +813,8 @@ static int kvm_handle_lasx_disabled(struct kvm_vcpu *v= cpu, int ecode) { if (!kvm_guest_has_lasx(&vcpu->arch)) kvm_queue_exception(vcpu, EXCCODE_INE, 0); - else { - vcpu->arch.aux_ldtype =3D KVM_LARCH_LASX; + else kvm_make_request(KVM_REQ_FPU_LOAD, vcpu); - } =20 return RESUME_GUEST; } diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index c28aa37f37a9..7f55875d8b3b 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -240,21 +240,12 @@ static void kvm_late_check_requests(struct kvm_vcpu *= vcpu) } =20 if (kvm_check_request(KVM_REQ_FPU_LOAD, vcpu)) { - switch (vcpu->arch.aux_ldtype) { - case KVM_LARCH_FPU: - kvm_own_fpu(vcpu); - break; - case KVM_LARCH_LSX: - kvm_own_lsx(vcpu); - break; - case KVM_LARCH_LASX: + if (kvm_guest_has_lasx(&vcpu->arch)) kvm_own_lasx(vcpu); - break; - default: - break; - } - - vcpu->arch.aux_ldtype =3D 0; + else if (kvm_guest_has_lsx(&vcpu->arch)) + kvm_own_lsx(vcpu); + else + kvm_own_fpu(vcpu); } =20 if (kvm_check_request(KVM_REQ_LBT_LOAD, vcpu)) --=20 2.39.3 From nobody Mon Jun 8 04:26:43 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33C5430274D; Mon, 8 Jun 2026 01:32:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780882357; cv=none; b=nImhhfqSTNplZxYl+xN5p9+//8IT/gGzKVbOpCjhDXqr2xnYp2kDLygwyo+XnKJ1T7+Nk8a7BB3dcijxEDKfKvk1bT7pNOwjxzHjM62tAvuK9aJleCH3wuc2AYQgD2fe5C7c5oleG4eJ5J7qJ3RP4ro8ygvbJ/LpHZwIFlbyQJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780882357; c=relaxed/simple; bh=8xk4jwJ3RGc19PQEwYu3FIfdG1523kR6HC2z/MVXCTE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QGM3ZTH2l7erQa0Z9sHuSNKfvPZGTu/K7WeJbtNW7V9Rr/AqcncKWgdNFqsG25cPKChHGGM3eSLLr5SuoRanRx14FzOaq43547BOEKhVUQwoZEJCxZfDqhnFkzXUQOZtX01iJKhblVShS6t4AjDal5VYvsg60Jrfwdwr7AVLbxY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8Cxf+urGyZqM5kRAA--.46837S3; Mon, 08 Jun 2026 09:32:27 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJAxHMKoGyZqNTafAA--.39164S5; Mon, 08 Jun 2026 09:32:27 +0800 (CST) From: Bibo Mao To: Huacai Chen Cc: kernel@xen0n.name, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/4] LoongArch: KVM: Remove some middle FPU states Date: Mon, 8 Jun 2026 09:32:21 +0800 Message-Id: <20260608013222.375257-4-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20260608013222.375257-1-maobibo@loongson.cn> References: <20260608013222.375257-1-maobibo@loongson.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJAxHMKoGyZqNTafAA--.39164S5 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Content-Type: text/plain; charset="utf-8" With max VM supported FPU type enabled, if VM supports LASX, there is FPU none --> LASX, no middle FPU state such as FPU --> LASX or LSX --> LASX. Here remove the middle FPU states in function kvm_own_lsx() and kvm_own_lasx(). And it becomes simpler than before. Signed-off-by: Bibo Mao --- arch/loongarch/kvm/vcpu.c | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index 7f55875d8b3b..53abf7aa61f8 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -1389,21 +1389,7 @@ int kvm_own_lsx(struct kvm_vcpu *vcpu) /* Enable LSX for guest */ kvm_check_fcsr(vcpu, vcpu->arch.fpu.fcsr); set_csr_euen(CSR_EUEN_LSXEN | CSR_EUEN_FPEN); - switch (vcpu->arch.aux_inuse & KVM_LARCH_FPU) { - case KVM_LARCH_FPU: - /* - * Guest FPU state already loaded, - * only restore upper LSX state - */ - _restore_lsx_upper(&vcpu->arch.fpu); - break; - default: - /* Neither FP or LSX already active, - * restore full LSX state - */ - kvm_restore_lsx(&vcpu->arch.fpu); - break; - } + kvm_restore_lsx(&vcpu->arch.fpu); =20 trace_kvm_aux(vcpu, KVM_TRACE_AUX_RESTORE, KVM_TRACE_AUX_LSX); vcpu->arch.aux_inuse |=3D KVM_LARCH_LSX | KVM_LARCH_FPU; @@ -1418,22 +1404,8 @@ int kvm_own_lasx(struct kvm_vcpu *vcpu) { kvm_check_fcsr(vcpu, vcpu->arch.fpu.fcsr); set_csr_euen(CSR_EUEN_FPEN | CSR_EUEN_LSXEN | CSR_EUEN_LASXEN); - switch (vcpu->arch.aux_inuse & (KVM_LARCH_FPU | KVM_LARCH_LSX)) { - case KVM_LARCH_LSX: - case KVM_LARCH_LSX | KVM_LARCH_FPU: - /* Guest LSX state already loaded, only restore upper LASX state */ - _restore_lasx_upper(&vcpu->arch.fpu); - break; - case KVM_LARCH_FPU: - /* Guest FP state already loaded, only restore upper LSX & LASX state */ - _restore_lsx_upper(&vcpu->arch.fpu); - _restore_lasx_upper(&vcpu->arch.fpu); - break; - default: - /* Neither FP or LSX already active, restore full LASX state */ - kvm_restore_lasx(&vcpu->arch.fpu); - break; - } + /* Neither FP or LSX already active, restore full LASX state */ + kvm_restore_lasx(&vcpu->arch.fpu); =20 trace_kvm_aux(vcpu, KVM_TRACE_AUX_RESTORE, KVM_TRACE_AUX_LASX); vcpu->arch.aux_inuse |=3D KVM_LARCH_LASX | KVM_LARCH_LSX | KVM_LARCH_FPU; --=20 2.39.3 From nobody Mon Jun 8 04:26:43 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B5CDE30C162; Mon, 8 Jun 2026 01:32:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780882358; cv=none; b=pAbBawrL7pUpG9ZaKnmmNmtnZxarD12ms9imxzKlI4JbbpRt2OCcMUNezZ6cKjxb2JFzjFC3wUJfFWRUFguOWvmeLOl+0CTTcvWSKAD5+rGvuStVbYCcub4ChIBV9P99L8Fl2gK/qDlOBOns8pdNbV72d5tVrmx6Hj2GzI8SIQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780882358; c=relaxed/simple; bh=oakNK6X8TU6thKHoIaSGzRPsPywe+hsjGOU8ofHTkN0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kLSJjGggtvPTw5wEjDsPThw/VFi3s/8DXzGKHYawjuVeyGLAVQDua6aqhPUzLsD5idqAxhstcsOZjj8wyAVmUxl2z0x0mItOuKbruCAVZHxH/BMlQKl35LdxqVHrp8x7ueM/iBL9UI0lW3/6lYuG7yE2YKiao3GrINvZ2ZygBO4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8CxnOmuGyZqOJkRAA--.45105S3; Mon, 08 Jun 2026 09:32:30 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJAx38KtGyZqODafAA--.38930S2; Mon, 08 Jun 2026 09:32:29 +0800 (CST) From: Bibo Mao To: Huacai Chen Cc: kernel@xen0n.name, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 4/4] LoongArch: KVM: Remove KVM_LARCH_LASX and KVM_LARCH_LSX Date: Mon, 8 Jun 2026 09:32:22 +0800 Message-Id: <20260608013222.375257-5-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20260608013222.375257-1-maobibo@loongson.cn> References: <20260608013222.375257-1-maobibo@loongson.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJAx38KtGyZqODafAA--.38930S2 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Content-Type: text/plain; charset="utf-8" In kvm_lose_fpu() FPU state will save in vcpu::arch::fpu, its FPU state comes from vcpu->arch.aux_inuse. Instead existing API vm_guest_has_xxx() can be used also, and bit KVM_LARCH_LASX and KVM_LARCH_LSX in arch.aux_inuse are removed. It makes the logic simpler than ever. Signed-off-by: Bibo Mao --- arch/loongarch/include/asm/kvm_host.h | 2 -- arch/loongarch/kvm/vcpu.c | 17 ++++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/arch/loongarch/include/asm/kvm_host.h b/arch/loongarch/include= /asm/kvm_host.h index bad16c5f963c..aa2000cfb58a 100644 --- a/arch/loongarch/include/asm/kvm_host.h +++ b/arch/loongarch/include/asm/kvm_host.h @@ -158,8 +158,6 @@ enum emulation_result { }; =20 #define KVM_LARCH_FPU (0x1 << 0) -#define KVM_LARCH_LSX (0x1 << 1) -#define KVM_LARCH_LASX (0x1 << 2) #define KVM_LARCH_LBT (0x1 << 3) #define KVM_LARCH_PMU (0x1 << 4) #define KVM_LARCH_SWCSR_LATEST (0x1 << 5) diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index 53abf7aa61f8..76414ce06330 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -1392,7 +1392,7 @@ int kvm_own_lsx(struct kvm_vcpu *vcpu) kvm_restore_lsx(&vcpu->arch.fpu); =20 trace_kvm_aux(vcpu, KVM_TRACE_AUX_RESTORE, KVM_TRACE_AUX_LSX); - vcpu->arch.aux_inuse |=3D KVM_LARCH_LSX | KVM_LARCH_FPU; + vcpu->arch.aux_inuse |=3D KVM_LARCH_FPU; =20 return 0; } @@ -1408,7 +1408,7 @@ int kvm_own_lasx(struct kvm_vcpu *vcpu) kvm_restore_lasx(&vcpu->arch.fpu); =20 trace_kvm_aux(vcpu, KVM_TRACE_AUX_RESTORE, KVM_TRACE_AUX_LASX); - vcpu->arch.aux_inuse |=3D KVM_LARCH_LASX | KVM_LARCH_LSX | KVM_LARCH_FPU; + vcpu->arch.aux_inuse |=3D KVM_LARCH_FPU; =20 return 0; } @@ -1419,29 +1419,32 @@ void kvm_lose_fpu(struct kvm_vcpu *vcpu) { preempt_disable(); =20 + if (!(vcpu->arch.aux_inuse & KVM_LARCH_FPU)) + goto done; + kvm_check_fcsr_alive(vcpu); - if (vcpu->arch.aux_inuse & KVM_LARCH_LASX) { + if (kvm_guest_has_lasx(&vcpu->arch)) { kvm_save_lasx(&vcpu->arch.fpu); - vcpu->arch.aux_inuse &=3D ~(KVM_LARCH_LSX | KVM_LARCH_FPU | KVM_LARCH_LA= SX); trace_kvm_aux(vcpu, KVM_TRACE_AUX_SAVE, KVM_TRACE_AUX_LASX); =20 /* Disable LASX & LSX & FPU */ clear_csr_euen(CSR_EUEN_FPEN | CSR_EUEN_LSXEN | CSR_EUEN_LASXEN); - } else if (vcpu->arch.aux_inuse & KVM_LARCH_LSX) { + } else if (kvm_guest_has_lsx(&vcpu->arch)) { kvm_save_lsx(&vcpu->arch.fpu); - vcpu->arch.aux_inuse &=3D ~(KVM_LARCH_LSX | KVM_LARCH_FPU); trace_kvm_aux(vcpu, KVM_TRACE_AUX_SAVE, KVM_TRACE_AUX_LSX); =20 /* Disable LSX & FPU */ clear_csr_euen(CSR_EUEN_FPEN | CSR_EUEN_LSXEN); } else if (vcpu->arch.aux_inuse & KVM_LARCH_FPU) { kvm_save_fpu(&vcpu->arch.fpu); - vcpu->arch.aux_inuse &=3D ~KVM_LARCH_FPU; trace_kvm_aux(vcpu, KVM_TRACE_AUX_SAVE, KVM_TRACE_AUX_FPU); =20 /* Disable FPU */ clear_csr_euen(CSR_EUEN_FPEN); } + vcpu->arch.aux_inuse &=3D ~KVM_LARCH_FPU; + +done: kvm_lose_lbt(vcpu); =20 preempt_enable(); --=20 2.39.3