xref: /linux/arch/loongarch/kvm/tlb.c (revision 257ca10c7317d4a424e48bb95d14ca53a1f1dd6f)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2020-2023 Loongson Technology Corporation Limited
4  */
5 
6 #include <linux/kvm_host.h>
7 #include <asm/tlb.h>
8 #include <asm/kvm_csr.h>
9 
10 /*
11  * kvm_flush_tlb_all() - Flush all root TLB entries for guests.
12  *
13  * Invalidate all entries including GVA-->GPA and GPA-->HPA mappings.
14  */
15 void kvm_flush_tlb_all(void)
16 {
17 	unsigned long flags;
18 
19 	local_irq_save(flags);
20 	invtlb_all(INVTLB_ALLGID, 0, 0);
21 	local_irq_restore(flags);
22 }
23 
24 void kvm_flush_tlb_gpa(struct kvm_vcpu *vcpu, unsigned long gpa)
25 {
26 	unsigned long flags;
27 
28 	local_irq_save(flags);
29 	gpa &= (PAGE_MASK << 1);
30 	invtlb(INVTLB_GID_ADDR, read_csr_gstat() & CSR_GSTAT_GID, gpa);
31 	local_irq_restore(flags);
32 }
33