* [PATCH 0/4] MIPS: KVM: Module + non dynamic translating fixes @ 2016-06-09 9:50 James Hogan 2016-06-09 9:50 ` [PATCH 1/4] MIPS: KVM: Fix modular KVM under QEMU James Hogan 2016-06-12 18:45 ` [PATCH 0/4] MIPS: KVM: Module + non dynamic translating fixes Paolo Bonzini 0 siblings, 2 replies; 4+ messages in thread From: James Hogan @ 2016-06-09 9:50 UTC (permalink / raw) To: Paolo Bonzini Cc: James Hogan, Radim Krčmář, Ralf Baechle, kvm, linux-mips, stable These patches fix a couple of issues I recently spotted when running KVM under QEMU (i.e. the host MIPS kernel is running under QEMU on a PC). Patches 1-2: Fix modular KVM broken by QEMU TLB optimisation (Patch 1 marked for stable). Patches 3-4: Fix cache instruction emulation, exposed by having dynamic translation of emulated instructions accidentally turned off. James Hogan (4): MIPS: KVM: Fix modular KVM under QEMU MIPS: KVM: Include bit 31 in segment matches MIPS: KVM: Don't unwind PC when emulating CACHE MIPS: KVM: Fix CACHE triggered exception emulation arch/mips/include/asm/kvm_host.h | 3 ++- arch/mips/kvm/emulate.c | 21 ++++++++++++++------- arch/mips/kvm/interrupt.h | 1 + arch/mips/kvm/locore.S | 1 + arch/mips/kvm/mips.c | 11 ++++++++++- 5 files changed, 28 insertions(+), 9 deletions(-) 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 -- 2.4.10 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/4] MIPS: KVM: Fix modular KVM under QEMU 2016-06-09 9:50 [PATCH 0/4] MIPS: KVM: Module + non dynamic translating fixes James Hogan @ 2016-06-09 9:50 ` James Hogan 2016-06-12 18:45 ` [PATCH 0/4] MIPS: KVM: Module + non dynamic translating fixes Paolo Bonzini 1 sibling, 0 replies; 4+ messages in thread From: James Hogan @ 2016-06-09 9:50 UTC (permalink / raw) To: Paolo Bonzini Cc: James Hogan, Radim Krčmář, Ralf Baechle, kvm, linux-mips, stable 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- --- arch/mips/include/asm/kvm_host.h | 1 + arch/mips/kvm/interrupt.h | 1 + arch/mips/kvm/locore.S | 1 + arch/mips/kvm/mips.c | 11 ++++++++++- 4 files changed, 13 insertions(+), 1 deletion(-) 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 { #define KVM_MIPS_GUEST_TLB_SIZE 64 struct kvm_vcpu_arch { void *host_ebase, *guest_ebase; + int (*vcpu_run)(struct kvm_run *run, struct kvm_vcpu *vcpu); unsigned long host_stack; unsigned long host_gp; 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 @@ #define MIPS_EXC_MAX 12 /* XXXSL More to follow */ +extern char __kvm_mips_vcpu_run_end[]; extern char mips32_exception[], mips32_exceptionEnd[]; extern char mips32_GuestException[], mips32_GuestExceptionEnd[]; 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) /* Jump to guest */ eret +EXPORT(__kvm_mips_vcpu_run_end) VECTOR(MIPSX(exception), unknown) /* 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) memcpy(gebase + offset, mips32_GuestException, mips32_GuestExceptionEnd - mips32_GuestException); +#ifdef MODULE + offset += mips32_GuestExceptionEnd - mips32_GuestException; + memcpy(gebase + offset, (char *)__kvm_mips_vcpu_run, + __kvm_mips_vcpu_run_end - (char *)__kvm_mips_vcpu_run); + vcpu->arch.vcpu_run = gebase + offset; +#else + vcpu->arch.vcpu_run = __kvm_mips_vcpu_run; +#endif + /* Invalidate the icache for these ranges */ local_flush_icache_range((unsigned long)gebase, (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) /* Disable hardware page table walking while in guest */ htw_stop(); - r = __kvm_mips_vcpu_run(run, vcpu); + r = vcpu->arch.vcpu_run(run, vcpu); /* Re-enable HTW before enabling interrupts */ htw_start(); -- 2.4.10 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/4] MIPS: KVM: Module + non dynamic translating fixes 2016-06-09 9:50 [PATCH 0/4] MIPS: KVM: Module + non dynamic translating fixes James Hogan 2016-06-09 9:50 ` [PATCH 1/4] MIPS: KVM: Fix modular KVM under QEMU James Hogan @ 2016-06-12 18:45 ` Paolo Bonzini 2016-06-14 9:03 ` Paolo Bonzini 1 sibling, 1 reply; 4+ messages in thread From: Paolo Bonzini @ 2016-06-12 18:45 UTC (permalink / raw) To: James Hogan Cc: Radim Krčmář, Ralf Baechle, kvm, linux-mips, stable On 09/06/2016 11:50, James Hogan wrote: > These patches fix a couple of issues I recently spotted when running KVM > under QEMU (i.e. the host MIPS kernel is running under QEMU on a PC). > > Patches 1-2: Fix modular KVM broken by QEMU TLB optimisation (Patch 1 > marked for stable). > > Patches 3-4: Fix cache instruction emulation, exposed by having dynamic > translation of emulated instructions accidentally turned off. > > James Hogan (4): > MIPS: KVM: Fix modular KVM under QEMU > MIPS: KVM: Include bit 31 in segment matches > MIPS: KVM: Don't unwind PC when emulating CACHE > MIPS: KVM: Fix CACHE triggered exception emulation > > arch/mips/include/asm/kvm_host.h | 3 ++- > arch/mips/kvm/emulate.c | 21 ++++++++++++++------- > arch/mips/kvm/interrupt.h | 1 + > arch/mips/kvm/locore.S | 1 + > arch/mips/kvm/mips.c | 11 ++++++++++- > 5 files changed, 28 insertions(+), 9 deletions(-) > > 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 > Queued for kvm/master. Paolo ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 0/4] MIPS: KVM: Module + non dynamic translating fixes 2016-06-12 18:45 ` [PATCH 0/4] MIPS: KVM: Module + non dynamic translating fixes Paolo Bonzini @ 2016-06-14 9:03 ` Paolo Bonzini 0 siblings, 0 replies; 4+ messages in thread From: Paolo Bonzini @ 2016-06-14 9:03 UTC (permalink / raw) To: James Hogan Cc: Radim Krčmář, Ralf Baechle, kvm, linux-mips, stable On 12/06/2016 20:45, Paolo Bonzini wrote: > > > On 09/06/2016 11:50, James Hogan wrote: >> These patches fix a couple of issues I recently spotted when running KVM >> under QEMU (i.e. the host MIPS kernel is running under QEMU on a PC). >> >> Patches 1-2: Fix modular KVM broken by QEMU TLB optimisation (Patch 1 >> marked for stable). >> >> Patches 3-4: Fix cache instruction emulation, exposed by having dynamic >> translation of emulated instructions accidentally turned off. >> >> James Hogan (4): >> MIPS: KVM: Fix modular KVM under QEMU >> MIPS: KVM: Include bit 31 in segment matches >> MIPS: KVM: Don't unwind PC when emulating CACHE >> MIPS: KVM: Fix CACHE triggered exception emulation >> >> arch/mips/include/asm/kvm_host.h | 3 ++- >> arch/mips/kvm/emulate.c | 21 ++++++++++++++------- >> arch/mips/kvm/interrupt.h | 1 + >> arch/mips/kvm/locore.S | 1 + >> arch/mips/kvm/mips.c | 11 ++++++++++- >> 5 files changed, 28 insertions(+), 9 deletions(-) >> >> 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 >> > > Queued for kvm/master. ... and kvm/next too, since your patches conflict with this one. Paolo ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-06-14 9:03 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-06-09 9:50 [PATCH 0/4] MIPS: KVM: Module + non dynamic translating fixes James Hogan 2016-06-09 9:50 ` [PATCH 1/4] MIPS: KVM: Fix modular KVM under QEMU James Hogan 2016-06-12 18:45 ` [PATCH 0/4] MIPS: KVM: Module + non dynamic translating fixes Paolo Bonzini 2016-06-14 9:03 ` Paolo Bonzini
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox