Skip to content

Commit 2a06dab

Browse files
James Hoganbonzini
authored andcommitted
MIPS: KVM: Fail if ebase doesn't fit in CP0_EBase
Fail if the address of the allocated exception base doesn't fit into the CP0_EBase register. This can happen on MIPS64 if CP0_EBase.WG isn't implemented but RAM is available outside of the range of KSeg0. 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 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 0d17aea commit 2a06dab

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

arch/mips/kvm/mips.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,18 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
300300
kvm_debug("Allocated %d bytes for KVM Exception Handlers @ %p\n",
301301
ALIGN(size, PAGE_SIZE), gebase);
302302

303+
/*
304+
* Check new ebase actually fits in CP0_EBase. The lack of a write gate
305+
* limits us to the low 512MB of physical address space. If the memory
306+
* we allocate is out of range, just give up now.
307+
*/
308+
if (!cpu_has_ebase_wg && virt_to_phys(gebase) >= 0x20000000) {
309+
kvm_err("CP0_EBase.WG required for guest exception base %pK\n",
310+
gebase);
311+
err = -ENOMEM;
312+
goto out_free_gebase;
313+
}
314+
303315
/* Save new ebase */
304316
vcpu->arch.guest_ebase = gebase;
305317

0 commit comments

Comments
 (0)