Skip to content

Commit 05d70eb

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Do not flush tlb if HW PTW supported
With HW PTW supported, invalid TLB is not added when page fault happens. But for EXCCODE_TLBM exception, stale TLB may exist because of the last read access. Thus TLB flush operation is necessary for the EXCCODE_TLBM exception, but not necessary for other tyeps of page fault exceptions. With SW PTW supported, invalid TLB is added in the TLB refill exception. TLB flush operation is necessary for all types of page fault exceptions. Here remove unnecessary TLB flush opereation with HW PTW supported. Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent fecd903 commit 05d70eb

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

arch/loongarch/include/asm/kvm_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ int kvm_arch_vcpu_dump_regs(struct kvm_vcpu *vcpu);
301301
/* MMU handling */
302302
void kvm_flush_tlb_all(void);
303303
void kvm_flush_tlb_gpa(struct kvm_vcpu *vcpu, unsigned long gpa);
304-
int kvm_handle_mm_fault(struct kvm_vcpu *vcpu, unsigned long badv, bool write);
304+
int kvm_handle_mm_fault(struct kvm_vcpu *vcpu, unsigned long badv, bool write, int ecode);
305305

306306
int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end, bool blockable);
307307
int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end);

arch/loongarch/kvm/exit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ int kvm_emu_mmio_write(struct kvm_vcpu *vcpu, larch_inst inst)
661661
return ret;
662662
}
663663

664-
static int kvm_handle_rdwr_fault(struct kvm_vcpu *vcpu, bool write)
664+
static int kvm_handle_rdwr_fault(struct kvm_vcpu *vcpu, bool write, int ecode)
665665
{
666666
int ret;
667667
larch_inst inst;
@@ -675,7 +675,7 @@ static int kvm_handle_rdwr_fault(struct kvm_vcpu *vcpu, bool write)
675675
return RESUME_GUEST;
676676
}
677677

678-
ret = kvm_handle_mm_fault(vcpu, badv, write);
678+
ret = kvm_handle_mm_fault(vcpu, badv, write, ecode);
679679
if (ret) {
680680
/* Treat as MMIO */
681681
inst.word = vcpu->arch.badi;
@@ -707,12 +707,12 @@ static int kvm_handle_rdwr_fault(struct kvm_vcpu *vcpu, bool write)
707707

708708
static int kvm_handle_read_fault(struct kvm_vcpu *vcpu, int ecode)
709709
{
710-
return kvm_handle_rdwr_fault(vcpu, false);
710+
return kvm_handle_rdwr_fault(vcpu, false, ecode);
711711
}
712712

713713
static int kvm_handle_write_fault(struct kvm_vcpu *vcpu, int ecode)
714714
{
715-
return kvm_handle_rdwr_fault(vcpu, true);
715+
return kvm_handle_rdwr_fault(vcpu, true, ecode);
716716
}
717717

718718
int kvm_complete_user_service(struct kvm_vcpu *vcpu, struct kvm_run *run)

arch/loongarch/kvm/mmu.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ static int kvm_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, bool write)
912912
return err;
913913
}
914914

915-
int kvm_handle_mm_fault(struct kvm_vcpu *vcpu, unsigned long gpa, bool write)
915+
int kvm_handle_mm_fault(struct kvm_vcpu *vcpu, unsigned long gpa, bool write, int ecode)
916916
{
917917
int ret;
918918

@@ -921,8 +921,17 @@ int kvm_handle_mm_fault(struct kvm_vcpu *vcpu, unsigned long gpa, bool write)
921921
return ret;
922922

923923
/* Invalidate this entry in the TLB */
924-
vcpu->arch.flush_gpa = gpa;
925-
kvm_make_request(KVM_REQ_TLB_FLUSH_GPA, vcpu);
924+
if (!cpu_has_ptw || (ecode == EXCCODE_TLBM)) {
925+
/*
926+
* With HW PTW, invalid TLB is not added when page fault. But
927+
* for EXCCODE_TLBM exception, stale TLB may exist because of
928+
* the last read access.
929+
*
930+
* With SW PTW, invalid TLB is added in TLB refill exception.
931+
*/
932+
vcpu->arch.flush_gpa = gpa;
933+
kvm_make_request(KVM_REQ_TLB_FLUSH_GPA, vcpu);
934+
}
926935

927936
return 0;
928937
}

0 commit comments

Comments
 (0)