aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Hogan <james.hogan@imgtec.com>2016-06-09 05:50:43 -0400
committerPaolo Bonzini <pbonzini@redhat.com>2016-06-14 04:59:44 -0400
commit797179bc4fe06c89e47a9f36f886f68640b423f8 (patch)
tree61fd1880fe1814697700baf92795c23b7b858f84
parent4340fa55298d17049e71c7a34e04647379c269f3 (diff)
MIPS: KVM: Fix modular KVM under QEMU
Copy __kvm_mips_vcpu_run() into unmapped memory, so that we can never get a TLB refill exception in it when KVM is built as a module. This was observed to happen with the host MIPS kernel running under QEMU, due to a not entirely transparent optimisation in the QEMU TLB handling where TLB entries replaced with TLBWR are copied to a separate part of the TLB array. Code in those pages continue to be executable, but those mappings persist only until the next ASID switch, even if they are marked global. An ASID switch happens in __kvm_mips_vcpu_run() at exception level after switching to the guest exception base. Subsequent TLB mapped kernel instructions just prior to switching to the guest trigger a TLB refill exception, which enters the guest exception handlers without updating EPC. This appears as a guest triggered TLB refill on a host kernel mapped (host KSeg2) address, which is not handled correctly as user (guest) mode accesses to kernel (host) segments always generate address error exceptions. 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: kvm@vger.kernel.org Cc: linux-mips@linux-mips.org Cc: <stable@vger.kernel.org> # 3.10.x- Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--arch/mips/include/asm/kvm_host.h1
-rw-r--r--arch/mips/kvm/interrupt.h1
-rw-r--r--arch/mips/kvm/locore.S1
-rw-r--r--arch/mips/kvm/mips.c11
4 files changed, 13 insertions, 1 deletions
diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h
index 6733ac575da4..2d5bb133d11a 100644
--- a/arch/mips/include/asm/kvm_host.h
+++ b/arch/mips/include/asm/kvm_host.h
@@ -338,6 +338,7 @@ struct kvm_mips_tlb {
338#define KVM_MIPS_GUEST_TLB_SIZE 64 338#define KVM_MIPS_GUEST_TLB_SIZE 64
339struct kvm_vcpu_arch { 339struct kvm_vcpu_arch {
340 void *host_ebase, *guest_ebase; 340 void *host_ebase, *guest_ebase;
341 int (*vcpu_run)(struct kvm_run *run, struct kvm_vcpu *vcpu);
341 unsigned long host_stack; 342 unsigned long host_stack;
342 unsigned long host_gp; 343 unsigned long host_gp;
343 344
diff --git a/arch/mips/kvm/interrupt.h b/arch/mips/kvm/interrupt.h
index 4ab4bdfad703..2143884709e4 100644
--- a/arch/mips/kvm/interrupt.h
+++ b/arch/mips/kvm/interrupt.h
@@ -28,6 +28,7 @@
28#define MIPS_EXC_MAX 12 28#define MIPS_EXC_MAX 12
29/* XXXSL More to follow */ 29/* XXXSL More to follow */
30 30
31extern char __kvm_mips_vcpu_run_end[];
31extern char mips32_exception[], mips32_exceptionEnd[]; 32extern char mips32_exception[], mips32_exceptionEnd[];
32extern char mips32_GuestException[], mips32_GuestExceptionEnd[]; 33extern char mips32_GuestException[], mips32_GuestExceptionEnd[];
33 34
diff --git a/arch/mips/kvm/locore.S b/arch/mips/kvm/locore.S
index 3ef03009de5f..828fcfc1cd7f 100644
--- a/arch/mips/kvm/locore.S
+++ b/arch/mips/kvm/locore.S
@@ -202,6 +202,7 @@ FEXPORT(__kvm_mips_load_k0k1)
202 202
203 /* Jump to guest */ 203 /* Jump to guest */
204 eret 204 eret
205EXPORT(__kvm_mips_vcpu_run_end)
205 206
206VECTOR(MIPSX(exception), unknown) 207VECTOR(MIPSX(exception), unknown)
207/* Find out what mode we came from and jump to the proper handler. */ 208/* Find out what mode we came from and jump to the proper handler. */
diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index dc052fb5c7a2..44da5259f390 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -315,6 +315,15 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
315 memcpy(gebase + offset, mips32_GuestException, 315 memcpy(gebase + offset, mips32_GuestException,
316 mips32_GuestExceptionEnd - mips32_GuestException); 316 mips32_GuestExceptionEnd - mips32_GuestException);
317 317
318#ifdef MODULE
319 offset += mips32_GuestExceptionEnd - mips32_GuestException;
320 memcpy(gebase + offset, (char *)__kvm_mips_vcpu_run,
321 __kvm_mips_vcpu_run_end - (char *)__kvm_mips_vcpu_run);
322 vcpu->arch.vcpu_run = gebase + offset;
323#else
324 vcpu->arch.vcpu_run = __kvm_mips_vcpu_run;
325#endif
326
318 /* Invalidate the icache for these ranges */ 327 /* Invalidate the icache for these ranges */
319 local_flush_icache_range((unsigned long)gebase, 328 local_flush_icache_range((unsigned long)gebase,
320 (unsigned long)gebase + ALIGN(size, PAGE_SIZE)); 329 (unsigned long)gebase + ALIGN(size, PAGE_SIZE));
@@ -404,7 +413,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
404 /* Disable hardware page table walking while in guest */ 413 /* Disable hardware page table walking while in guest */
405 htw_stop(); 414 htw_stop();
406 415
407 r = __kvm_mips_vcpu_run(run, vcpu); 416 r = vcpu->arch.vcpu_run(run, vcpu);
408 417
409 /* Re-enable HTW before enabling interrupts */ 418 /* Re-enable HTW before enabling interrupts */
410 htw_start(); 419 htw_start();