Re: [PATCH] LoongArch: KVM: return full old CSR value from kvm_emu_xchg_csr()
From: Bibo Mao
Date: Fri Jun 05 2026 - 03:22:42 EST
On 2026/6/4 下午8:34, Qiang Ma wrote:
The LoongArch CSRXCHG instruction returns the full old CSR value in rdReviewed-by: Bibo Mao <maobibo@xxxxxxxxxxx>
after applying the masked update. kvm_emu_xchg_csr() currently masks
the saved value before returning it to the guest, so rd receives only
the bits selected by the write mask.
That breaks the architectural behavior and makes a zero mask return 0
instead of the previous CSR value. Keep the masked CSR update, but
return the unmodified old CSR value.
Fixes: da50f5a693ff ("LoongArch: KVM: Implement handle csr exception")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Qiang Ma <maqianga@xxxxxxxxxxxxx>
---
arch/loongarch/kvm/exit.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c
index 3b95cd0f989b..264813d45cbe 100644
--- a/arch/loongarch/kvm/exit.c
+++ b/arch/loongarch/kvm/exit.c
@@ -103,7 +103,6 @@ static unsigned long kvm_emu_xchg_csr(struct kvm_vcpu *vcpu, int csrid,
old = kvm_read_sw_gcsr(csr, csrid);
val = (old & ~csr_mask) | (val & csr_mask);
kvm_write_sw_gcsr(csr, csrid, val);
- old = old & csr_mask;
} else
pr_warn_once("Unsupported csrxchg 0x%x with pc %lx\n", csrid, vcpu->arch.pc);