Skip to content

Commit 4d38d04

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Clear LLBCTL if secondary mmu mapping is changed
LLBCTL is a separated guest CSR register from host, host exception ERET instruction will clear the host LLBCTL CSR register, and guest exception will clear the guest LLBCTL CSR register. VCPU0 atomic64_fetch_add_unless VCPU1 atomic64_fetch_add_unless ll.d %[p], %[c] beq %[p], %[u], 1f Here secondary mmu mapping is changed, host hpa page is replaced with a new page. And VCPU1 will execute atomic instruction on the new page. ll.d %[p], %[c] beq %[p], %[u], 1f add.d %[rc], %[p], %[a] sc.d %[rc], %[c] add.d %[rc], %[p], %[a] sc.d %[rc], %[c] LLBCTL is set on VCPU0 and it represents the memory is not modified by other VCPUs, sc.d will modify the memory directly. So clear WCLLB of the guest LLBCTL register when mapping is the changed. Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 5bc55a3 commit 4d38d04

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

arch/loongarch/kvm/main.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,24 @@ void kvm_check_vpid(struct kvm_vcpu *vcpu)
245245
trace_kvm_vpid_change(vcpu, vcpu->arch.vpid);
246246
vcpu->cpu = cpu;
247247
kvm_clear_request(KVM_REQ_TLB_FLUSH_GPA, vcpu);
248+
249+
/*
250+
* LLBCTL is a separated guest CSR register from host, a general
251+
* exception ERET instruction clears the host LLBCTL register in
252+
* host mode, and clears the guest LLBCTL register in guest mode.
253+
* ERET in tlb refill exception does not clear LLBCTL register.
254+
*
255+
* When secondary mmu mapping is changed, guest OS does not know
256+
* even if the content is changed after mapping is changed.
257+
*
258+
* Here clear WCLLB of the guest LLBCTL register when mapping is
259+
* changed. Otherwise, if mmu mapping is changed while guest is
260+
* executing LL/SC pair, LL loads with the old address and set
261+
* the LLBCTL flag, SC checks the LLBCTL flag and will store the
262+
* new address successfully since LLBCTL_WCLLB is on, even if
263+
* memory with new address is changed on other VCPUs.
264+
*/
265+
set_gcsr_llbctl(CSR_LLBCTL_WCLLB);
248266
}
249267

250268
/* Restore GSTAT(0x50).vpid */

0 commit comments

Comments
 (0)