Skip to content

Commit 9b731bc

Browse files
James Hoganrkrcmar
authored andcommitted
MIPS: KVM: Propagate kseg0/mapped tlb fault errors
Propagate errors from kvm_mips_handle_kseg0_tlb_fault() and kvm_mips_handle_mapped_seg_tlb_fault(), usually triggering an internal error since they normally indicate the guest accessed bad physical memory or the commpage in an unexpected way. Fixes: 858dd5d ("KVM/MIPS32: MMU/TLB operations for the Guest.") Fixes: e685c68 ("KVM/MIPS32: Privileged instruction/target branch emulation.") Signed-off-by: James Hogan <james.hogan@imgtec.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: "Radim Krčmář" <rkrcmar@redhat.com> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: linux-mips@linux-mips.org Cc: kvm@vger.kernel.org Cc: <stable@vger.kernel.org> # 3.10.x- Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
1 parent 0741f52 commit 9b731bc

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

arch/mips/kvm/emulate.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,8 +1642,14 @@ enum emulation_result kvm_mips_emulate_cache(union mips_instruction inst,
16421642

16431643
preempt_disable();
16441644
if (KVM_GUEST_KSEGX(va) == KVM_GUEST_KSEG0) {
1645-
if (kvm_mips_host_tlb_lookup(vcpu, va) < 0)
1646-
kvm_mips_handle_kseg0_tlb_fault(va, vcpu);
1645+
if (kvm_mips_host_tlb_lookup(vcpu, va) < 0 &&
1646+
kvm_mips_handle_kseg0_tlb_fault(va, vcpu)) {
1647+
kvm_err("%s: handling mapped kseg0 tlb fault for %lx, vcpu: %p, ASID: %#lx\n",
1648+
__func__, va, vcpu, read_c0_entryhi());
1649+
er = EMULATE_FAIL;
1650+
preempt_enable();
1651+
goto done;
1652+
}
16471653
} else if ((KVM_GUEST_KSEGX(va) < KVM_GUEST_KSEG0) ||
16481654
KVM_GUEST_KSEGX(va) == KVM_GUEST_KSEG23) {
16491655
int index;
@@ -1680,12 +1686,18 @@ enum emulation_result kvm_mips_emulate_cache(union mips_instruction inst,
16801686
run, vcpu);
16811687
preempt_enable();
16821688
goto dont_update_pc;
1683-
} else {
1684-
/*
1685-
* We fault an entry from the guest tlb to the
1686-
* shadow host TLB
1687-
*/
1688-
kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb);
1689+
}
1690+
/*
1691+
* We fault an entry from the guest tlb to the
1692+
* shadow host TLB
1693+
*/
1694+
if (kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb)) {
1695+
kvm_err("%s: handling mapped seg tlb fault for %lx, index: %u, vcpu: %p, ASID: %#lx\n",
1696+
__func__, va, index, vcpu,
1697+
read_c0_entryhi());
1698+
er = EMULATE_FAIL;
1699+
preempt_enable();
1700+
goto done;
16891701
}
16901702
}
16911703
} else {
@@ -2659,7 +2671,12 @@ enum emulation_result kvm_mips_handle_tlbmiss(u32 cause,
26592671
* OK we have a Guest TLB entry, now inject it into the
26602672
* shadow host TLB
26612673
*/
2662-
kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb);
2674+
if (kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb)) {
2675+
kvm_err("%s: handling mapped seg tlb fault for %lx, index: %u, vcpu: %p, ASID: %#lx\n",
2676+
__func__, va, index, vcpu,
2677+
read_c0_entryhi());
2678+
er = EMULATE_FAIL;
2679+
}
26632680
}
26642681
}
26652682

arch/mips/kvm/mmu.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,15 @@ u32 kvm_get_inst(u32 *opc, struct kvm_vcpu *vcpu)
368368
local_irq_restore(flags);
369369
return KVM_INVALID_INST;
370370
}
371-
kvm_mips_handle_mapped_seg_tlb_fault(vcpu,
372-
&vcpu->arch.
373-
guest_tlb[index]);
371+
if (kvm_mips_handle_mapped_seg_tlb_fault(vcpu,
372+
&vcpu->arch.guest_tlb[index])) {
373+
kvm_err("%s: handling mapped seg tlb fault failed for %p, index: %u, vcpu: %p, ASID: %#lx\n",
374+
__func__, opc, index, vcpu,
375+
read_c0_entryhi());
376+
kvm_mips_dump_guest_tlbs(vcpu);
377+
local_irq_restore(flags);
378+
return KVM_INVALID_INST;
379+
}
374380
inst = *(opc);
375381
}
376382
local_irq_restore(flags);

0 commit comments

Comments
 (0)