]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
LoongArch: KVM: Return full old CSR value from kvm_emu_xchg_csr()
authorQiang Ma <maqianga@uniontech.com>
Thu, 11 Jun 2026 12:46:43 +0000 (20:46 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Thu, 11 Jun 2026 12:46:43 +0000 (20:46 +0800)
The LoongArch CSRXCHG instruction returns the full old CSR value in rd
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. So, keep the masked CSR update, but
return the unmodified old CSR value.

Cc: stable@vger.kernel.org
Fixes: da50f5a693ff ("LoongArch: KVM: Implement handle csr exception")
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Qiang Ma <maqianga@uniontech.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/kvm/exit.c

index c8492670f169ed324b23a8b058db306e75deeb22..8572b63478bb98abcc23fd6cc54db8417b6210c8 100644 (file)
@@ -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);