lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250303091114.1511496-1-maobibo@loongson.cn>
Date: Mon,  3 Mar 2025 17:11:14 +0800
From: Bibo Mao <maobibo@...ngson.cn>
To: Tianrui Zhao <zhaotianrui@...ngson.cn>,
	Huacai Chen <chenhuacai@...nel.org>
Cc: WANG Xuerui <kernel@...0n.name>,
	kvm@...r.kernel.org,
	loongarch@...ts.linux.dev,
	linux-kernel@...r.kernel.org,
	Xianglai Li <lixianglai@...ngson.cn>
Subject: [PATCH] LoongArch: KVM: Reload guest CSR registers after S4

On host HW guest CSR registers are lost after suspend and resume
operation. Since last_vcpu of boot CPU still records latest vCPU pointer
so that guest CSR register skips to reload when boot CPU resumes and
vCPU is scheduled.

Here last_vcpu is cleared so that guest CSR register will reload from
scheduled vCPU context after suspend and resume.

Also there is another small fix for Loongson AVEC support, bit 14 is added
in CSR ESTAT register. Macro CSR_ESTAT_IS is replaced with hardcoded value
0x1fff and AVEC interrupt status bit 14 is supported with macro
CSR_ESTAT_IS.

Signed-off-by: Bibo Mao <maobibo@...ngson.cn>
---
 arch/loongarch/kvm/main.c | 8 ++++++++
 arch/loongarch/kvm/vcpu.c | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/loongarch/kvm/main.c b/arch/loongarch/kvm/main.c
index f6d3242b9234..b177773f38f6 100644
--- a/arch/loongarch/kvm/main.c
+++ b/arch/loongarch/kvm/main.c
@@ -284,6 +284,7 @@ long kvm_arch_dev_ioctl(struct file *filp,
 int kvm_arch_enable_virtualization_cpu(void)
 {
 	unsigned long env, gcfg = 0;
+	struct kvm_context *context;
 
 	env = read_csr_gcfg();
 
@@ -317,6 +318,13 @@ int kvm_arch_enable_virtualization_cpu(void)
 	kvm_debug("GCFG:%lx GSTAT:%lx GINTC:%lx GTLBC:%lx",
 		  read_csr_gcfg(), read_csr_gstat(), read_csr_gintc(), read_csr_gtlbc());
 
+	/*
+	 * HW Guest CSR registers are lost after CPU suspend and resume
+	 * Clear last_vcpu so that Guest CSR register forced to reload
+	 * from vCPU SW state
+	 */
+	context = this_cpu_ptr(vmcs);
+	context->last_vcpu = NULL;
 	return 0;
 }
 
diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
index 20f941af3e9e..9e1a9b4aa4c6 100644
--- a/arch/loongarch/kvm/vcpu.c
+++ b/arch/loongarch/kvm/vcpu.c
@@ -311,7 +311,7 @@ static int kvm_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)
 {
 	int ret = RESUME_GUEST;
 	unsigned long estat = vcpu->arch.host_estat;
-	u32 intr = estat & 0x1fff; /* Ignore NMI */
+	u32 intr = estat & CSR_ESTAT_IS;
 	u32 ecode = (estat & CSR_ESTAT_EXC) >> CSR_ESTAT_EXC_SHIFT;
 
 	vcpu->mode = OUTSIDE_GUEST_MODE;

base-commit: 1e15510b71c99c6e49134d756df91069f7d18141
-- 
2.39.3



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ