KVM/MIPS: Implement hardware virtualization via the MIPS-VZ extensions.
Subsystems (4)
cover KVM/MIPS: Implement hardware virtualization via the MIPS-VZ extensions.
From: David Daney <[email protected]>
These patches take a somewhat different approach to MIPS virtualization via the MIPS-VZ extensions than the patches previously sent by Sanjay Lal.
Several facts about the code:
o Existing exception handlers are modified to hook in to KVM instead of intercepting all exceptions via the EBase register, and then chaining to real exception handlers.
o Able to boot 64-bit SMP guests that use the FPU (I have booted 4-way SMP 64-bit MIPS/Linux).
o Additional overhead on every exception even when *no* vCPU is running.
o Lower interrupt overhead, than the EBase interception method, when vCPU *is* running.
o This code is somewhat smaller than the existing trap/emulate implementation (about 2100 lines vs. about 5300 lines)
o Currently probably only usable on the OCTEON III CPU model, as some MIPS-VZ implementation-defined behaviors were assumed to have the OCTEON III behavior.
Note: I think Ralf already has the 17/31 (MIPS: Quit exposing Kconfig symbols in uapi headers.) queued, but I also include it here.
David Daney (31):
MIPS: Move allocate_kscratch to cpu-probe.c and make it public.
MIPS: Save and restore K0/K1 when CONFIG_KVM_MIPSVZ mips/kvm: Fix 32-bitisms in kvm_locore.S
mips/kvm: Add casts to avoid pointer width mismatch build failures. mips/kvm: Use generic cache flushing functions.
mips/kvm: Rename kvm_vcpu_arch.pc to kvm_vcpu_arch.epc mips/kvm: Rename VCPU_registername to KVM_VCPU_ARCH_registername mips/kvm: Fix code formatting in arch/mips/kvm/kvm_locore.S mips/kvm: Factor trap-and-emulate support into a pluggable
implementation.
mips/kvm: Implement ioctls to get and set FPU registers.
MIPS: Rearrange branch.c so it can be used by kvm code.
MIPS: Add instruction format information for WAIT, MTC0, MFC0, et al. mips/kvm: Add accessors for MIPS VZ registers.
mips/kvm: Add thread_info flag to indicate operation in MIPS VZ Guest
Mode.
mips/kvm: Exception handling to leave and reenter guest mode. mips/kvm: Add exception handler for MIPSVZ Guest exceptions.
MIPS: Quit exposing Kconfig symbols in uapi headers. mips/kvm: Add pt_regs slots for BadInstr and BadInstrP mips/kvm: Add host definitions for MIPS VZ based host. mips/kvm: Hook into TLB fault handlers.
mips/kvm: Allow set_except_vector() to be used from MIPSVZ code. mips/kvm: Split get_new_mmu_context into two parts. mips/kvm: Hook into CP unusable exception handler. mips/kvm: Add thread_struct fields used by MIPSVZ hosts. mips/kvm: Add some asm-offsets constants used by MIPSVZ. mips/kvm: Split up Kconfig and Makefile definitions in preperation
for MIPSVZ.
mips/kvm: Gate the use of kvm_local_flush_tlb_all() by KVM_MIPSTE mips/kvm: Only use KVM_COALESCED_MMIO_PAGE_OFFSET with KVM_MIPSTE mips/kvm: Add MIPSVZ support.
mips/kvm: Enable MIPSVZ in Kconfig/Makefile
mips/kvm: Allow for upto 8 KVM vcpus per vm.
arch/mips/Kconfig | 1 + arch/mips/include/asm/branch.h | 7 + arch/mips/include/asm/kvm_host.h | 622 +----------- arch/mips/include/asm/kvm_mips_te.h | 589 +++++++++++ arch/mips/include/asm/kvm_mips_vz.h | 29 + arch/mips/include/asm/mipsregs.h | 264 +++++ arch/mips/include/asm/mmu_context.h | 12 +- arch/mips/include/asm/processor.h | 6 + arch/mips/include/asm/ptrace.h | 36 + arch/mips/include/asm/stackframe.h | 150 ++- arch/mips/include/asm/thread_info.h | 2 + arch/mips/include/asm/uasm.h | 2 +- arch/mips/include/uapi/asm/inst.h | 23 +- arch/mips/include/uapi/asm/ptrace.h | 17 +- arch/mips/kernel/asm-offsets.c | 124 ++- arch/mips/kernel/branch.c | 63 +- arch/mips/kernel/cpu-probe.c | 34 + arch/mips/kernel/genex.S | 8 + arch/mips/kernel/scall64-64.S | 12 + arch/mips/kernel/scall64-n32.S | 12 + arch/mips/kernel/traps.c | 15 +- arch/mips/kvm/Kconfig | 23 +- arch/mips/kvm/Makefile | 15 +- arch/mips/kvm/kvm_locore.S | 980 +++++++++--------- arch/mips/kvm/kvm_mips.c | 768 ++------------ arch/mips/kvm/kvm_mips_comm.h | 1 + arch/mips/kvm/kvm_mips_commpage.c | 9 +- arch/mips/kvm/kvm_mips_dyntrans.c | 4 +- arch/mips/kvm/kvm_mips_emul.c | 312 +++--- arch/mips/kvm/kvm_mips_int.c | 53 +- arch/mips/kvm/kvm_mips_int.h | 2 - arch/mips/kvm/kvm_mips_stats.c | 6 +- arch/mips/kvm/kvm_mipsvz.c | 1894 +++++++++++++++++++++++++++++++++++ arch/mips/kvm/kvm_mipsvz_guest.S | 234 +++++ arch/mips/kvm/kvm_tlb.c | 140 +-- arch/mips/kvm/kvm_trap_emul.c | 932 +++++++++++++++-- arch/mips/mm/fault.c | 8 + arch/mips/mm/tlbex-fault.S | 6 + arch/mips/mm/tlbex.c | 45 +- 39 files changed, 5299 insertions(+), 2161 deletions(-) create mode 100644 arch/mips/include/asm/kvm_mips_te.h create mode 100644 arch/mips/include/asm/kvm_mips_vz.h create mode 100644 arch/mips/kvm/kvm_mipsvz.c create mode 100644 arch/mips/kvm/kvm_mipsvz_guest.S
Signature · 1 line
1.7.11.7
PATCH 2/31 MIPS: Save and restore K0/K1 when CONFIG_KVM_MIPSVZ
From: David Daney <[email protected]>
We cannot clobber any registers on exceptions as any guest will need them all.
--- arch/mips/include/asm/mipsregs.h | 2 ++ arch/mips/include/asm/stackframe.h | 15 +++++++++++++++ arch/mips/kernel/cpu-probe.c | 7 ++++++- arch/mips/kernel/genex.S | 5 +++++ arch/mips/kernel/scall64-64.S | 12 ++++++++++++ arch/mips/kernel/scall64-n32.S | 12 ++++++++++++ arch/mips/kernel/traps.c | 5 +++++ arch/mips/mm/tlbex.c | 25 +++++++++++++++++++++++++ 8 files changed, 82 insertions(+), 1 deletion(-)
arch/mips/include/asm/mipsregs.h +2 -0
@@ -73,6 +73,8 @@#define CP0_TAGHI $29#define CP0_ERROREPC $30#define CP0_DESAVE $31 +#define CP0_KSCRATCH1 $31, 2 +#define CP0_KSCRATCH2 $31, 3/* * R4640/R4650 cp0 register names. These registers are listed
arch/mips/include/asm/stackframe.h +15 -0
@@ -181,6 +181,16 @@#endif LONG_S k0, PT_R29(sp) LONG_S $3, PT_R3(sp) +#ifdef CONFIG_KVM_MIPSVZ +/* +* With KVM_MIPSVZ, we must not clobber k0/k1 +* they were saved before they were used +*/ +MFC0 k0,CP0_KSCRATCH1 + MFC0 $3, CP0_KSCRATCH2 + LONG_S k0, PT_R26(sp) + LONG_S $3, PT_R27(sp) +#endif /* * You might think that you don't need to save $0, * but the FPU emulator and gdb remote debug stub
@@ -447,6 +457,11 @@ .endm .macro RESTORE_SP_AND_RET + +#ifdef CONFIG_KVM_MIPSVZ + LONG_L k0, PT_R26(sp) + LONG_L k1, PT_R27(sp) +#endif LONG_L sp, PT_R29(sp) .set mips3 eret
arch/mips/kernel/cpu-probe.c +6 -1
@@ -1067,7 +1067,12 @@ __cpuinit void cpu_report(void)static DEFINE_SPINLOCK (kscratch_used_lock); -static unsigned int kscratch_used_mask; +static unsigned int kscratch_used_mask +#ifdef CONFIG_KVM_MIPSVZ +/* KVM_MIPSVZ implemtation uses these two statically. */ +=0xc +#endif +;int allocate_kscratch (void ) {
arch/mips/kernel/genex.S +5 -0
@@ -46,6 +46,11 @@ NESTED(except_vec3_generic, 0, sp) .set push .set noat +#ifdef CONFIG_KVM_MIPSVZ + /* With KVM_MIPSVZ, we must not clobber k0/k1 */ + MTC0 k0, CP0_KSCRATCH1 + MTC0 k1, CP0_KSCRATCH2 +#endif #if R5432_CP0_INTERRUPT_WAR mfc0 k0, CP0_INDEX #endif
arch/mips/kernel/scall64-64.S +12 -0
@@ -62,6 +62,9 @@ NESTED(handle_sys64, PT_SIZE, sp) jalr t2 # Do The Real Thing (TM) li t0, -EMAXERRNO - 1 # error? +#if defined(CONFIG_KVM_MIPSVZ) && defined(CONFIG_FAST_ACCESS_TO_THREAD_POINTER) + ld t2, TI_TP_VALUE($28) +#endif sltu t0, t0, v0 sd t0, PT_R7(sp) # set error flag beqz t0, 1f
@@ -70,6 +73,9 @@ NESTED(handle_sys64, PT_SIZE, sp) dnegu v0 # error sd t1, PT_R0(sp) # save it for syscall restarting 1: sd v0, PT_R2(sp) # result +#if defined(CONFIG_KVM_MIPSVZ) && defined(CONFIG_FAST_ACCESS_TO_THREAD_POINTER) + sd t2, PT_R26(sp) +#endif n64_syscall_exit: j syscall_exit_partial
@@ -93,6 +99,9 @@ syscall_trace_entry: jalr t0 li t0, -EMAXERRNO - 1 # error? +#if defined(CONFIG_KVM_MIPSVZ) && defined(CONFIG_FAST_ACCESS_TO_THREAD_POINTER) + ld t2, TI_TP_VALUE($28) +#endif sltu t0, t0, v0 sd t0, PT_R7(sp) # set error flag beqz t0, 1f
@@ -101,6 +110,9 @@ syscall_trace_entry: dnegu v0 # error sd t1, PT_R0(sp) # save it for syscall restarting 1: sd v0, PT_R2(sp) # result +#if defined(CONFIG_KVM_MIPSVZ) && defined(CONFIG_FAST_ACCESS_TO_THREAD_POINTER) + sd t2, PT_R26(sp) +#endif j syscall_exit
arch/mips/kernel/scall64-n32.S +12 -0
@@ -55,6 +55,9 @@ NESTED(handle_sysn32, PT_SIZE, sp) jalr t2 # Do The Real Thing (TM) li t0, -EMAXERRNO - 1 # error? +#if defined(CONFIG_KVM_MIPSVZ) && defined(CONFIG_FAST_ACCESS_TO_THREAD_POINTER) + ld t2, TI_TP_VALUE($28) +#endif sltu t0, t0, v0 sd t0, PT_R7(sp) # set error flag beqz t0, 1f
@@ -63,6 +66,9 @@ NESTED(handle_sysn32, PT_SIZE, sp) dnegu v0 # error sd t1, PT_R0(sp) # save it for syscall restarting 1: sd v0, PT_R2(sp) # result +#if defined(CONFIG_KVM_MIPSVZ) && defined(CONFIG_FAST_ACCESS_TO_THREAD_POINTER) + sd t2, PT_R26(sp) +#endif j syscall_exit_partial
@@ -85,6 +91,9 @@ n32_syscall_trace_entry: jalr t0 li t0, -EMAXERRNO - 1 # error? +#if defined(CONFIG_KVM_MIPSVZ) && defined(CONFIG_FAST_ACCESS_TO_THREAD_POINTER) + ld t2, TI_TP_VALUE($28) +#endif sltu t0, t0, v0 sd t0, PT_R7(sp) # set error flag beqz t0, 1f
@@ -93,6 +102,9 @@ n32_syscall_trace_entry: dnegu v0 # error sd t1, PT_R0(sp) # save it for syscall restarting 1: sd v0, PT_R2(sp) # result +#if defined(CONFIG_KVM_MIPSVZ) && defined(CONFIG_FAST_ACCESS_TO_THREAD_POINTER) + sd t2, PT_R26(sp) +#endif j syscall_exit
arch/mips/kernel/traps.c +5 -0
@@ -1483,6 +1483,11 @@ void __init *set_except_vector(int n, void *addr)#endif u32 *buf = (u32 *)(ebase +0x200 );unsigned int k0 =26 ; +#ifdef CONFIG_KVM_MIPSVZ +unsigned int k1 =27 ; +UASM_i_MTC0 (&buf, k0,31 ,2 ); +UASM_i_MTC0 (&buf, k1,31 ,3 ); +#endif if ((handler & jump_mask) == ((ebase +0x200 ) & jump_mask)) {uasm_i_j (&buf, handler & ~jump_mask);uasm_i_nop (&buf);
arch/mips/mm/tlbex.c +25 -0
@@ -372,11 +372,19 @@ static void __cpuinit build_restore_work_registers(u32 **p) {if (scratch_reg >0 ) {UASM_i_MFC0 (p,1 ,31 , scratch_reg); +#ifdef CONFIG_KVM_MIPSVZ +UASM_i_MFC0 (p,K0 ,31 ,2 ); +UASM_i_MFC0 (p,K1 ,31 ,3 ); +#endif return ; }/* K0 already points to save area, restore $1 and $2 */ UASM_i_LW (p,1 , offsetof(struct tlb_reg_save , a),K0 );UASM_i_LW (p,2 , offsetof(struct tlb_reg_save , b),K0 ); +#ifdef CONFIG_KVM_MIPSVZ +UASM_i_MFC0 (p,K0 ,31 ,2 ); +UASM_i_MFC0 (p,K1 ,31 ,3 ); +#endif }#ifndef CONFIG_MIPS_PGD_C0_CONTEXT
@@ -1089,6 +1097,11 @@ build_fast_tlb_refill_handler (u32 **p, struct uasm_label **l,int vmalloc_branch_delay_filled =0 ;const int scratch =1 ;/* Our extra working register */ +#ifdef CONFIG_KVM_MIPSVZ +UASM_i_MTC0 (p,K0 ,31 ,2 ); +UASM_i_MTC0 (p,K1 ,31 ,3 ); +#endif + rv.huge_pte = scratch; rv.restore_scratch =0 ;
@@ -1244,6 +1257,10 @@ build_fast_tlb_refill_handler (u32 **p, struct uasm_label **l, rv.restore_scratch =1 ; } +#ifdef CONFIG_KVM_MIPSVZ +UASM_i_MFC0 (p,K0 ,31 ,2 ); +UASM_i_MFC0 (p,K1 ,31 ,3 ); +#endif uasm_i_eret (p);/* return from trap */ return rv;
@@ -1277,6 +1294,10 @@ static void __cpuinit build_r4000_tlb_refill_handler(void) scratch_reg); vmalloc_mode = refill_scratch; }else { +#ifdef CONFIG_KVM_MIPSVZ +UASM_i_MTC0 (&p,K0 ,31 ,2 ); +UASM_i_MTC0 (&p,K1 ,31 ,3 ); +#endif htlb_info.huge_pte =K0 ; htlb_info.restore_scratch =0 ; vmalloc_mode = refill_noscratch;
@@ -1311,6 +1332,10 @@ static void __cpuinit build_r4000_tlb_refill_handler(void)build_update_entries (&p,K0 ,K1 );build_tlb_write_entry (&p, &l, &r, tlb_random);uasm_l_leave (&l, p); +#ifdef CONFIG_KVM_MIPSVZ +UASM_i_MFC0 (&p,K0 ,31 ,2 ); +UASM_i_MFC0 (&p,K1 ,31 ,3 ); +#endif uasm_i_eret (&p);/* return from trap */ }#ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT
Signature · 1 line
1.7.11.7
PATCH 3/31 mips/kvm: Fix 32-bitisms in kvm_locore.S
In reply to David DaneyFrom: David Daney <[email protected]>
For a warning free compile, we need to use the width aware PTR_LI and PTR_LA macros. Use LI variant for immediate data and LA variant for addresses.
--- arch/mips/kvm/kvm_locore.S | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/mips/kvm/kvm_locore.S +4 -4
@@ -310,7 +310,7 @@ NESTED (MIPSX(GuestException), CALLFRAME_SIZ, ra) LONG_S t0, VCPU_R26(k1) /* Get GUEST k1 and save it in VCPU */ - la t1, ~0x2ff + PTR_LI t1, ~0x2ff mfc0 t0, CP0_EBASE and t0, t0, t1 LONG_L t0, 0x3000(t0)
@@ -384,14 +384,14 @@ NESTED (MIPSX(GuestException), CALLFRAME_SIZ, ra) mtc0 k0, CP0_DDATA_LO /* Restore RDHWR access */ - la k0, 0x2000000F + PTR_LI k0, 0x2000000F mtc0 k0, CP0_HWRENA /* Jump to handler */ FEXPORT(__kvm_mips_jump_to_handler) /* XXXKYMA: not sure if this is safe, how large is the stack?? */ /* Now jump to the kvm_mips_handle_exit() to see if we can deal with this in the kernel */ - la t9,kvm_mips_handle_exit + PTR_LA t9, kvm_mips_handle_exit jalr.hb t9 addiu sp,sp, -CALLFRAME_SIZ /* BD Slot */
@@ -566,7 +566,7 @@ __kvm_mips_return_to_host: mtlo k0 /* Restore RDHWR access */ - la k0, 0x2000000F + PTR_LI k0, 0x2000000F mtc0 k0, CP0_HWRENA
Signature · 1 line
1.7.11.7
PATCH 4/31 mips/kvm: Add casts to avoid pointer width mismatch build failures.
In reply to David DaneyFrom: David Daney <[email protected]>
When building for 64-bits we need these cases to make it build.
--- arch/mips/kvm/kvm_mips.c | 4 ++-- arch/mips/kvm/kvm_mips_dyntrans.c | 4 ++-- arch/mips/kvm/kvm_mips_emul.c | 2 +- arch/mips/kvm/kvm_tlb.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-)
arch/mips/kvm/kvm_mips.c +2 -2
@@ -303,7 +303,7 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id) }/* Save Linux EBASE */ - vcpu->arch.host_ebase = (void *)read_c0_ebase (); + vcpu->arch.host_ebase = (void *)(long )(read_c0_ebase () &0x3ff ); gebase =kzalloc (ALIGN (size,PAGE_SIZE ),GFP_KERNEL );
@@ -339,7 +339,7 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id) offset =0x2000 ;kvm_info ("Installing KVM Exception handlers @ %p, %#x bytes\n" , gebase + offset, - mips32_GuestExceptionEnd - mips32_GuestException); + (unsigned )(mips32_GuestExceptionEnd - mips32_GuestException));memcpy (gebase + offset, mips32_GuestException, mips32_GuestExceptionEnd - mips32_GuestException);
arch/mips/kvm/kvm_mips_dyntrans.c +2 -2
@@ -94,7 +94,7 @@ kvm_mips_trans_mfc0(uint32_t inst, uint32_t *opc, struct kvm_vcpu *vcpu) cop0); } -if (KVM_GUEST_KSEGX (opc) ==KVM_GUEST_KSEG0 ) { +if (KVM_GUEST_KSEGX ((unsigned long )opc) ==KVM_GUEST_KSEG0 ) { kseg0_opc =CKSEG0ADDR (kvm_mips_translate_guest_kseg0_to_hpa (vcpu, (unsigned long ) opc));
@@ -129,7 +129,7 @@ kvm_mips_trans_mtc0(uint32_t inst, uint32_t *opc, struct kvm_vcpu *vcpu) offsetof(struct mips_coproc , reg[rd][sel]) + offsetof(struct kvm_mips_commpage, cop0); -if (KVM_GUEST_KSEGX (opc) ==KVM_GUEST_KSEG0 ) { +if (KVM_GUEST_KSEGX ((unsigned long )opc) ==KVM_GUEST_KSEG0 ) { kseg0_opc =CKSEG0ADDR (kvm_mips_translate_guest_kseg0_to_hpa (vcpu, (unsigned long ) opc));
arch/mips/kvm/kvm_mips_emul.c +1 -1
@@ -892,7 +892,7 @@ int kvm_mips_sync_icache(unsigned long va, struct kvm_vcpu *vcpu) pfn = kvm->arch.guest_pmap[gfn]; pa = (pfn <<PAGE_SHIFT ) | offset; -printk ("%s: va: %#lx, unmapped: %#x\n" , __func__, va,CKSEG0ADDR (pa)); +printk ("%s: va: %#lx, unmapped: %#lx\n" , __func__, va,CKSEG0ADDR (pa));mips32_SyncICache (CKSEG0ADDR (pa),32 );return 0 ;
arch/mips/kvm/kvm_tlb.c +2 -2
@@ -353,7 +353,7 @@ int kvm_mips_handle_commpage_tlb_fault(unsigned long badvaddr,unsigned long entrylo0 =0 , entrylo1 =0 ; - pfn0 =CPHYSADDR (vcpu->arch.kseg0_commpage) >>PAGE_SHIFT ; + pfn0 =CPHYSADDR ((unsigned long )vcpu->arch.kseg0_commpage) >>PAGE_SHIFT ; pfn1 =0 ; entrylo0 =mips3_paddr_to_tlbpfn (pfn0 <<PAGE_SHIFT ) | (0x3 <<3 ) | (1 <<2 ) | (0x1 <<1 );
@@ -916,7 +916,7 @@ uint32_t kvm_get_inst(uint32_t *opc, struct kvm_vcpu *vcpu) inst = *(opc); }local_irq_restore (flags); - }else if (KVM_GUEST_KSEGX (opc) ==KVM_GUEST_KSEG0 ) { + }else if (KVM_GUEST_KSEGX ((unsigned long )opc) ==KVM_GUEST_KSEG0 ) { paddr =kvm_mips_translate_guest_kseg0_to_hpa (vcpu, (unsigned long ) opc);
Signature · 1 line
1.7.11.7
PATCH 5/31 mips/kvm: Use generic cache flushing functions.
In reply to David DaneyFrom: David Daney <[email protected]>
We don't know if we have the r4k specific functions available, so use universally available __flush_cache_all() instead. This takes longer as it flushes both i-cache and d-cache, but is available for all CPUs.
--- arch/mips/kvm/kvm_mips_emul.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
arch/mips/kvm/kvm_mips_emul.c +2 -4
@@ -916,8 +916,6 @@ kvm_mips_emulate_cache(uint32_t inst, uint32_t *opc, uint32_t cause, struct kvm_run *run, struct kvm_vcpu *vcpu) { struct mips_coproc *cop0 = vcpu->arch.cop0; -extern void (*r4k_blast_dcache) (void ); -extern void (*r4k_blast_icache) (void );enum emulation_result er =EMULATE_DONE ;int32_t offset, cache, op_inst, op, base;struct kvm_vcpu_arch *arch = &vcpu->arch;
@@ -954,9 +952,9 @@ kvm_mips_emulate_cache(uint32_t inst, uint32_t *opc, uint32_t cause, arch->gprs[base], offset);if (cache ==MIPS_CACHE_DCACHE ) -r4k_blast_dcache (); +__flush_cache_all ();else if (cache ==MIPS_CACHE_ICACHE ) -r4k_blast_icache (); +__flush_cache_all ();else {printk ("%s: unsupported CACHE INDEX operation\n" , __func__);
Signature · 1 line
1.7.11.7
PATCH 6/31 mips/kvm: Rename kvm_vcpu_arch.pc to kvm_vcpu_arch.epc
In reply to David DaneyFrom: David Daney <[email protected]>
The proper MIPS name for this register is EPC, so use that.
Change the asm-offsets name to KVM_VCPU_ARCH_EPC, so that the symbol name prefix matches the structure name.
--- arch/mips/include/asm/kvm_host.h | 2 +- arch/mips/kernel/asm-offsets.c | 2 +- arch/mips/kvm/kvm_locore.S | 6 +- arch/mips/kvm/kvm_mips.c | 12 ++-- arch/mips/kvm/kvm_mips_emul.c | 140 +++++++++++++++++++-------------------- arch/mips/kvm/kvm_mips_int.c | 8 +-- arch/mips/kvm/kvm_trap_emul.c | 20 +++--- 7 files changed, 95 insertions(+), 95 deletions(-)
arch/mips/include/asm/kvm_host.h +1 -1
@@ -363,7 +363,7 @@ struct kvm_vcpu_arch {unsigned long gprs[32 ];unsigned long hi;unsigned long lo; -unsigned long pc; +unsigned long epc;/* FPU State */ struct mips_fpu_struct fpu;
arch/mips/kernel/asm-offsets.c +1 -1
@@ -385,7 +385,7 @@ void output_kvm_defines(void)OFFSET (VCPU_R31 , kvm_vcpu_arch, gprs[31 ]);OFFSET (VCPU_LO , kvm_vcpu_arch, lo);OFFSET (VCPU_HI , kvm_vcpu_arch, hi); -OFFSET (VCPU_PC , kvm_vcpu_arch, pc); +OFFSET (KVM_VCPU_ARCH_EPC , kvm_vcpu_arch, epc);OFFSET (VCPU_COP0 , kvm_vcpu_arch, cop0);OFFSET (VCPU_GUEST_KERNEL_ASID , kvm_vcpu_arch, guest_kernel_asid);OFFSET (VCPU_GUEST_USER_ASID , kvm_vcpu_arch, guest_user_asid);
arch/mips/kvm/kvm_locore.S +3 -3
@@ -151,7 +151,7 @@ FEXPORT(__kvm_mips_vcpu_run) /* Set Guest EPC */ - LONG_L t0, VCPU_PC(k1) + LONG_L t0, KVM_VCPU_ARCH_EPC(k1) mtc0 t0, CP0_EPC FEXPORT(__kvm_mips_load_asid)
@@ -330,7 +330,7 @@ NESTED (MIPSX(GuestException), CALLFRAME_SIZ, ra) /* Save Host level EPC, BadVaddr and Cause to VCPU, useful to process the exception */ mfc0 k0,CP0_EPC - LONG_S k0, VCPU_PC(k1) + LONG_S k0, KVM_VCPU_ARCH_EPC(k1) mfc0 k0, CP0_BADVADDR LONG_S k0, VCPU_HOST_CP0_BADVADDR(k1)
@@ -438,7 +438,7 @@ __kvm_mips_return_to_guest: /* Set Guest EPC */ - LONG_L t0, VCPU_PC(k1) + LONG_L t0, KVM_VCPU_ARCH_EPC(k1) mtc0 t0, CP0_EPC /* Set the ASID for the Guest Kernel */
arch/mips/kvm/kvm_mips.c +6 -6
@@ -583,7 +583,7 @@ static int kvm_mips_get_reg(struct kvm_vcpu *vcpu, v = (long )vcpu->arch.lo;break ;case KVM_REG_MIPS_PC : - v = (long )vcpu->arch.pc; + v = (long )vcpu->arch.epc;break ;case KVM_REG_MIPS_CP0_INDEX :
@@ -658,7 +658,7 @@ static int kvm_mips_set_reg(struct kvm_vcpu *vcpu, vcpu->arch.lo = v;break ;case KVM_REG_MIPS_PC : - vcpu->arch.pc = v; + vcpu->arch.epc = v;break ;case KVM_REG_MIPS_CP0_INDEX :
@@ -890,7 +890,7 @@ int kvm_arch_vcpu_dump_regs(struct kvm_vcpu *vcpu)return -1 ;printk ("VCPU Register Dump:\n" ); -printk ("\tpc = 0x%08lx\n" , vcpu->arch.pc);; +printk ("\tepc = 0x%08lx\n" , vcpu->arch.epc);;printk ("\texceptions: %08lx\n" , vcpu->arch.pending_exceptions);for (i =0 ; i <32 ; i +=4 ) {
@@ -920,7 +920,7 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) vcpu->arch.gprs[0 ] =0 ;/* zero is special, and cannot be set. */ vcpu->arch.hi = regs->hi; vcpu->arch.lo = regs->lo; - vcpu->arch.pc = regs->pc; + vcpu->arch.epc = regs->pc;return 0 ; }
@@ -934,7 +934,7 @@ int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) regs->hi = vcpu->arch.hi; regs->lo = vcpu->arch.lo; - regs->pc = vcpu->arch.pc; + regs->pc = vcpu->arch.epc;return 0 ; }
@@ -1014,7 +1014,7 @@ int kvm_mips_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu) {uint32_t cause = vcpu->arch.host_cp0_cause;uint32_t exccode = (cause >>CAUSEB_EXCCODE ) &0x1f ; -uint32_t __user *opc = (uint32_t __user *) vcpu->arch.pc; +uint32_t __user *opc = (uint32_t __user *) vcpu->arch.epc;unsigned long badvaddr = vcpu->arch.host_cp0_badvaddr;enum emulation_result er =EMULATE_DONE ;int ret =RESUME_GUEST ;
arch/mips/kvm/kvm_mips_emul.c +70 -70
457 lines not on this page · raw message
arch/mips/kvm/kvm_mips_int.c +4 -4
@@ -167,7 +167,7 @@ kvm_mips_irq_deliver_cb(struct kvm_vcpu *vcpu, unsigned int priority,if ((kvm_read_c0_guest_status (cop0) &ST0_EXL ) ==0 ) {/* save old pc */ -kvm_write_c0_guest_epc (cop0, arch->pc); +kvm_write_c0_guest_epc (cop0, arch->epc);kvm_set_c0_guest_status (cop0,ST0_EXL );if (cause &CAUSEF_BD )
@@ -175,7 +175,7 @@ kvm_mips_irq_deliver_cb(struct kvm_vcpu *vcpu, unsigned int priority,else kvm_clear_c0_guest_cause (cop0,CAUSEF_BD ); -kvm_debug ("Delivering INT @ pc %#lx\n" , arch->pc); +kvm_debug ("Delivering INT @ pc %#lx\n" , arch->epc); }else kvm_err ("Trying to deliver interrupt when EXL is already set\n" );
@@ -185,9 +185,9 @@ kvm_mips_irq_deliver_cb(struct kvm_vcpu *vcpu, unsigned int priority,/* XXXSL Set PC to the interrupt exception entry point */ if (kvm_read_c0_guest_cause (cop0) &CAUSEF_IV ) - arch->pc =KVM_GUEST_KSEG0 +0x200 ; + arch->epc =KVM_GUEST_KSEG0 +0x200 ;else - arch->pc =KVM_GUEST_KSEG0 +0x180 ; + arch->epc =KVM_GUEST_KSEG0 +0x180 ;clear_bit (priority, &vcpu->arch.pending_exceptions); }
arch/mips/kvm/kvm_trap_emul.c +10 -10
@@ -43,7 +43,7 @@ static gpa_t kvm_trap_emul_gva_to_gpa_cb(gva_t gva)static int kvm_trap_emul_handle_cop_unusable (struct kvm_vcpu *vcpu) {struct kvm_run *run = vcpu->run; -uint32_t __user *opc = (uint32_t __user *) vcpu->arch.pc; +uint32_t __user *opc = (uint32_t __user *) vcpu->arch.epc;unsigned long cause = vcpu->arch.host_cp0_cause;enum emulation_result er =EMULATE_DONE ;int ret =RESUME_GUEST ;
@@ -77,7 +77,7 @@ static int kvm_trap_emul_handle_cop_unusable(struct kvm_vcpu *vcpu)static int kvm_trap_emul_handle_tlb_mod (struct kvm_vcpu *vcpu) {struct kvm_run *run = vcpu->run; -uint32_t __user *opc = (uint32_t __user *) vcpu->arch.pc; +uint32_t __user *opc = (uint32_t __user *) vcpu->arch.epc;unsigned long badvaddr = vcpu->arch.host_cp0_badvaddr;unsigned long cause = vcpu->arch.host_cp0_cause;enum emulation_result er =EMULATE_DONE ;
@@ -124,7 +124,7 @@ static int kvm_trap_emul_handle_tlb_mod(struct kvm_vcpu *vcpu)static int kvm_trap_emul_handle_tlb_st_miss (struct kvm_vcpu *vcpu) {struct kvm_run *run = vcpu->run; -uint32_t __user *opc = (uint32_t __user *) vcpu->arch.pc; +uint32_t __user *opc = (uint32_t __user *) vcpu->arch.epc;unsigned long badvaddr = vcpu->arch.host_cp0_badvaddr;unsigned long cause = vcpu->arch.host_cp0_cause;enum emulation_result er =EMULATE_DONE ;
@@ -174,7 +174,7 @@ static int kvm_trap_emul_handle_tlb_st_miss(struct kvm_vcpu *vcpu)static int kvm_trap_emul_handle_tlb_ld_miss (struct kvm_vcpu *vcpu) {struct kvm_run *run = vcpu->run; -uint32_t __user *opc = (uint32_t __user *) vcpu->arch.pc; +uint32_t __user *opc = (uint32_t __user *) vcpu->arch.epc;unsigned long badvaddr = vcpu->arch.host_cp0_badvaddr;unsigned long cause = vcpu->arch.host_cp0_cause;enum emulation_result er =EMULATE_DONE ;
@@ -190,7 +190,7 @@ static int kvm_trap_emul_handle_tlb_ld_miss(struct kvm_vcpu *vcpu) || KVM_GUEST_KSEGX(badvaddr) == KVM_GUEST_KSEG23) {#ifdef DEBUG kvm_debug ("USER ADDR TLB ST fault: PC: %#lx, BadVaddr: %#lx\n" , - vcpu->arch.pc, badvaddr); + vcpu->arch.epc, badvaddr);#endif /* User Address (UA) fault, this could happen if
@@ -228,7 +228,7 @@ static int kvm_trap_emul_handle_tlb_ld_miss(struct kvm_vcpu *vcpu)static int kvm_trap_emul_handle_addr_err_st (struct kvm_vcpu *vcpu) {struct kvm_run *run = vcpu->run; -uint32_t __user *opc = (uint32_t __user *) vcpu->arch.pc; +uint32_t __user *opc = (uint32_t __user *) vcpu->arch.epc;unsigned long badvaddr = vcpu->arch.host_cp0_badvaddr;unsigned long cause = vcpu->arch.host_cp0_cause;enum emulation_result er =EMULATE_DONE ;
@@ -261,7 +261,7 @@ static int kvm_trap_emul_handle_addr_err_st(struct kvm_vcpu *vcpu)static int kvm_trap_emul_handle_addr_err_ld (struct kvm_vcpu *vcpu) {struct kvm_run *run = vcpu->run; -uint32_t __user *opc = (uint32_t __user *) vcpu->arch.pc; +uint32_t __user *opc = (uint32_t __user *) vcpu->arch.epc;unsigned long badvaddr = vcpu->arch.host_cp0_badvaddr;unsigned long cause = vcpu->arch.host_cp0_cause;enum emulation_result er =EMULATE_DONE ;
@@ -294,7 +294,7 @@ static int kvm_trap_emul_handle_addr_err_ld(struct kvm_vcpu *vcpu)static int kvm_trap_emul_handle_syscall (struct kvm_vcpu *vcpu) {struct kvm_run *run = vcpu->run; -uint32_t __user *opc = (uint32_t __user *) vcpu->arch.pc; +uint32_t __user *opc = (uint32_t __user *) vcpu->arch.epc;unsigned long cause = vcpu->arch.host_cp0_cause;enum emulation_result er =EMULATE_DONE ;int ret =RESUME_GUEST ;
@@ -312,7 +312,7 @@ static int kvm_trap_emul_handle_syscall(struct kvm_vcpu *vcpu)static int kvm_trap_emul_handle_res_inst (struct kvm_vcpu *vcpu) {struct kvm_run *run = vcpu->run; -uint32_t __user *opc = (uint32_t __user *) vcpu->arch.pc; +uint32_t __user *opc = (uint32_t __user *) vcpu->arch.epc;unsigned long cause = vcpu->arch.host_cp0_cause;enum emulation_result er =EMULATE_DONE ;int ret =RESUME_GUEST ;
@@ -330,7 +330,7 @@ static int kvm_trap_emul_handle_res_inst(struct kvm_vcpu *vcpu)static int kvm_trap_emul_handle_break (struct kvm_vcpu *vcpu) {struct kvm_run *run = vcpu->run; -uint32_t __user *opc = (uint32_t __user *) vcpu->arch.pc; +uint32_t __user *opc = (uint32_t __user *) vcpu->arch.epc;unsigned long cause = vcpu->arch.host_cp0_cause;enum emulation_result er =EMULATE_DONE ;int ret =RESUME_GUEST ;
Signature · 1 line
1.7.11.7
PATCH 7/31 mips/kvm: Rename VCPU_registername to KVM_VCPU_ARCH_registername
In reply to David DaneyFrom: David Daney <[email protected]>
This makes it follow the pattern where the structure name is the symbol name prefix.
--- arch/mips/kernel/asm-offsets.c | 68 +++++++------- arch/mips/kvm/kvm_locore.S | 206 ++++++++++++++++++++--------------------- 2 files changed, 137 insertions(+), 137 deletions(-)
arch/mips/kernel/asm-offsets.c +34 -34
@@ -351,40 +351,40 @@ void output_kvm_defines(void)OFFSET (VCPU_GUEST_INST , kvm_vcpu_arch, guest_inst); -OFFSET (VCPU_R0 , kvm_vcpu_arch, gprs[0 ]); -OFFSET (VCPU_R1 , kvm_vcpu_arch, gprs[1 ]); -OFFSET (VCPU_R2 , kvm_vcpu_arch, gprs[2 ]); -OFFSET (VCPU_R3 , kvm_vcpu_arch, gprs[3 ]); -OFFSET (VCPU_R4 , kvm_vcpu_arch, gprs[4 ]); -OFFSET (VCPU_R5 , kvm_vcpu_arch, gprs[5 ]); -OFFSET (VCPU_R6 , kvm_vcpu_arch, gprs[6 ]); -OFFSET (VCPU_R7 , kvm_vcpu_arch, gprs[7 ]); -OFFSET (VCPU_R8 , kvm_vcpu_arch, gprs[8 ]); -OFFSET (VCPU_R9 , kvm_vcpu_arch, gprs[9 ]); -OFFSET (VCPU_R10 , kvm_vcpu_arch, gprs[10 ]); -OFFSET (VCPU_R11 , kvm_vcpu_arch, gprs[11 ]); -OFFSET (VCPU_R12 , kvm_vcpu_arch, gprs[12 ]); -OFFSET (VCPU_R13 , kvm_vcpu_arch, gprs[13 ]); -OFFSET (VCPU_R14 , kvm_vcpu_arch, gprs[14 ]); -OFFSET (VCPU_R15 , kvm_vcpu_arch, gprs[15 ]); -OFFSET (VCPU_R16 , kvm_vcpu_arch, gprs[16 ]); -OFFSET (VCPU_R17 , kvm_vcpu_arch, gprs[17 ]); -OFFSET (VCPU_R18 , kvm_vcpu_arch, gprs[18 ]); -OFFSET (VCPU_R19 , kvm_vcpu_arch, gprs[19 ]); -OFFSET (VCPU_R20 , kvm_vcpu_arch, gprs[20 ]); -OFFSET (VCPU_R21 , kvm_vcpu_arch, gprs[21 ]); -OFFSET (VCPU_R22 , kvm_vcpu_arch, gprs[22 ]); -OFFSET (VCPU_R23 , kvm_vcpu_arch, gprs[23 ]); -OFFSET (VCPU_R24 , kvm_vcpu_arch, gprs[24 ]); -OFFSET (VCPU_R25 , kvm_vcpu_arch, gprs[25 ]); -OFFSET (VCPU_R26 , kvm_vcpu_arch, gprs[26 ]); -OFFSET (VCPU_R27 , kvm_vcpu_arch, gprs[27 ]); -OFFSET (VCPU_R28 , kvm_vcpu_arch, gprs[28 ]); -OFFSET (VCPU_R29 , kvm_vcpu_arch, gprs[29 ]); -OFFSET (VCPU_R30 , kvm_vcpu_arch, gprs[30 ]); -OFFSET (VCPU_R31 , kvm_vcpu_arch, gprs[31 ]); -OFFSET (VCPU_LO , kvm_vcpu_arch, lo); -OFFSET (VCPU_HI , kvm_vcpu_arch, hi); +OFFSET (KVM_VCPU_ARCH_R0 , kvm_vcpu_arch, gprs[0 ]); +OFFSET (KVM_VCPU_ARCH_R1 , kvm_vcpu_arch, gprs[1 ]); +OFFSET (KVM_VCPU_ARCH_R2 , kvm_vcpu_arch, gprs[2 ]); +OFFSET (KVM_VCPU_ARCH_R3 , kvm_vcpu_arch, gprs[3 ]); +OFFSET (KVM_VCPU_ARCH_R4 , kvm_vcpu_arch, gprs[4 ]); +OFFSET (KVM_VCPU_ARCH_R5 , kvm_vcpu_arch, gprs[5 ]); +OFFSET (KVM_VCPU_ARCH_R6 , kvm_vcpu_arch, gprs[6 ]); +OFFSET (KVM_VCPU_ARCH_R7 , kvm_vcpu_arch, gprs[7 ]); +OFFSET (KVM_VCPU_ARCH_R8 , kvm_vcpu_arch, gprs[8 ]); +OFFSET (KVM_VCPU_ARCH_R9 , kvm_vcpu_arch, gprs[9 ]); +OFFSET (KVM_VCPU_ARCH_R10 , kvm_vcpu_arch, gprs[10 ]); +OFFSET (KVM_VCPU_ARCH_R11 , kvm_vcpu_arch, gprs[11 ]); +OFFSET (KVM_VCPU_ARCH_R12 , kvm_vcpu_arch, gprs[12 ]); +OFFSET (KVM_VCPU_ARCH_R13 , kvm_vcpu_arch, gprs[13 ]); +OFFSET (KVM_VCPU_ARCH_R14 , kvm_vcpu_arch, gprs[14 ]); +OFFSET (KVM_VCPU_ARCH_R15 , kvm_vcpu_arch, gprs[15 ]); +OFFSET (KVM_VCPU_ARCH_R16 , kvm_vcpu_arch, gprs[16 ]); +OFFSET (KVM_VCPU_ARCH_R17 , kvm_vcpu_arch, gprs[17 ]); +OFFSET (KVM_VCPU_ARCH_R18 , kvm_vcpu_arch, gprs[18 ]); +OFFSET (KVM_VCPU_ARCH_R19 , kvm_vcpu_arch, gprs[19 ]); +OFFSET (KVM_VCPU_ARCH_R20 , kvm_vcpu_arch, gprs[20 ]); +OFFSET (KVM_VCPU_ARCH_R21 , kvm_vcpu_arch, gprs[21 ]); +OFFSET (KVM_VCPU_ARCH_R22 , kvm_vcpu_arch, gprs[22 ]); +OFFSET (KVM_VCPU_ARCH_R23 , kvm_vcpu_arch, gprs[23 ]); +OFFSET (KVM_VCPU_ARCH_R24 , kvm_vcpu_arch, gprs[24 ]); +OFFSET (KVM_VCPU_ARCH_R25 , kvm_vcpu_arch, gprs[25 ]); +OFFSET (KVM_VCPU_ARCH_R26 , kvm_vcpu_arch, gprs[26 ]); +OFFSET (KVM_VCPU_ARCH_R27 , kvm_vcpu_arch, gprs[27 ]); +OFFSET (KVM_VCPU_ARCH_R28 , kvm_vcpu_arch, gprs[28 ]); +OFFSET (KVM_VCPU_ARCH_R29 , kvm_vcpu_arch, gprs[29 ]); +OFFSET (KVM_VCPU_ARCH_R30 , kvm_vcpu_arch, gprs[30 ]); +OFFSET (KVM_VCPU_ARCH_R31 , kvm_vcpu_arch, gprs[31 ]); +OFFSET (KVM_VCPU_ARCH_LO , kvm_vcpu_arch, lo); +OFFSET (KVM_VCPU_ARCH_HI , kvm_vcpu_arch, hi);OFFSET (KVM_VCPU_ARCH_EPC , kvm_vcpu_arch, epc);OFFSET (VCPU_COP0 , kvm_vcpu_arch, cop0);OFFSET (VCPU_GUEST_KERNEL_ASID , kvm_vcpu_arch, guest_kernel_asid);
arch/mips/kvm/kvm_locore.S +103 -103
262 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 8/31 mips/kvm: Fix code formatting in arch/mips/kvm/kvm_locore.S
In reply to David DaneyFrom: David Daney <[email protected]>
It was a completely inconsistent mix of spaces and tabs.
--- arch/mips/kvm/kvm_locore.S | 921 +++++++++++++++++++++++---------------------- 1 file changed, 464 insertions(+), 457 deletions(-)
arch/mips/kvm/kvm_locore.S +464 -457
@@ -1,13 +1,13 @@ /* -* This file is subject to the terms and conditions of the GNU General Public -* License. See the file "COPYING" in the main directory of this archive -* for more details. -* -* Main entry point for the guest, exception handling. -* -* Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. -* Authors: Sanjay Lal <[email protected]> -*/ + * This file is subject to the terms and conditions of the GNU General Public + * License. See the file "COPYING" in the main directory of this archive + * for more details. + * + * Main entry point for the guest, exception handling. + * + * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. + * Authors: Sanjay Lal <[email protected]> + */ #include <asm/asm.h> #include <asm/asmmacro.h>
@@ -57,172 +57,177 @@ */ FEXPORT(__kvm_mips_vcpu_run) - .set push - .set noreorder - .set noat - - /* k0/k1 not being used in host kernel context */ - addiu k1,sp, -PT_SIZE - LONG_S $0, PT_R0(k1) - LONG_S $1, PT_R1(k1) - LONG_S $2, PT_R2(k1) - LONG_S $3, PT_R3(k1) - - LONG_S $4, PT_R4(k1) - LONG_S $5, PT_R5(k1) - LONG_S $6, PT_R6(k1) - LONG_S $7, PT_R7(k1) - - LONG_S $8, PT_R8(k1) - LONG_S $9, PT_R9(k1) - LONG_S $10, PT_R10(k1) - LONG_S $11, PT_R11(k1) - LONG_S $12, PT_R12(k1) - LONG_S $13, PT_R13(k1) - LONG_S $14, PT_R14(k1) - LONG_S $15, PT_R15(k1) - LONG_S $16, PT_R16(k1) - LONG_S $17, PT_R17(k1) - - LONG_S $18, PT_R18(k1) - LONG_S $19, PT_R19(k1) - LONG_S $20, PT_R20(k1) - LONG_S $21, PT_R21(k1) - LONG_S $22, PT_R22(k1) - LONG_S $23, PT_R23(k1) - LONG_S $24, PT_R24(k1) - LONG_S $25, PT_R25(k1) + .set push + .set noreorder + .set noat + + /* k0/k1 not being used in host kernel context */ + addiu k1, sp, -PT_SIZE + LONG_S $0, PT_R0(k1) + LONG_S $1, PT_R1(k1) + LONG_S $2, PT_R2(k1) + LONG_S $3, PT_R3(k1) + + LONG_S $4, PT_R4(k1) + LONG_S $5, PT_R5(k1) + LONG_S $6, PT_R6(k1) + LONG_S $7, PT_R7(k1) + + LONG_S $8, PT_R8(k1) + LONG_S $9, PT_R9(k1) + LONG_S $10, PT_R10(k1) + LONG_S $11, PT_R11(k1) + LONG_S $12, PT_R12(k1) + LONG_S $13, PT_R13(k1) + LONG_S $14, PT_R14(k1) + LONG_S $15, PT_R15(k1) + LONG_S $16, PT_R16(k1) + LONG_S $17, PT_R17(k1) + + LONG_S $18, PT_R18(k1) + LONG_S $19, PT_R19(k1) + LONG_S $20, PT_R20(k1) + LONG_S $21, PT_R21(k1) + LONG_S $22, PT_R22(k1) + LONG_S $23, PT_R23(k1) + LONG_S $24, PT_R24(k1) + LONG_S $25, PT_R25(k1) /* XXXKYMA k0/k1 not saved, not being used if we got here through an ioctl() */ - LONG_S $28, PT_R28(k1) - LONG_S $29, PT_R29(k1) - LONG_S $30, PT_R30(k1) - LONG_S $31, PT_R31(k1) + LONG_S $28, PT_R28(k1) + LONG_S $29, PT_R29(k1) + LONG_S $30, PT_R30(k1) + LONG_S $31, PT_R31(k1) - /* Save hi/lo */ - mflo v0 - LONG_S v0, PT_LO(k1) - mfhi v1 - LONG_S v1, PT_HI(k1) + /* Save hi/lo */ + mflo v0 + LONG_S v0, PT_LO(k1) + mfhi v1 + LONG_S v1, PT_HI(k1) /* Save host status */ - mfc0 v0, CP0_STATUS - LONG_S v0, PT_STATUS(k1) + mfc0 v0, CP0_STATUS + LONG_S v0, PT_STATUS(k1) /* Save host ASID, shove it into the BVADDR location */ - mfc0 v1,CP0_ENTRYHI - andi v1, 0xff - LONG_S v1, PT_HOST_ASID(k1) + mfc0 v1, CP0_ENTRYHI + andi v1, 0xff + LONG_S v1, PT_HOST_ASID(k1) - /* Save DDATA_LO, will be used to store pointer to vcpu */ - mfc0 v1, CP0_DDATA_LO - LONG_S v1, PT_HOST_USERLOCAL(k1) + /* Save DDATA_LO, will be used to store pointer to vcpu */ + mfc0 v1, CP0_DDATA_LO + LONG_S v1, PT_HOST_USERLOCAL(k1) - /* DDATA_LO has pointer to vcpu */ - mtc0 a1,CP0_DDATA_LO + /* DDATA_LO has pointer to vcpu */ + mtc0 a1, CP0_DDATA_LO - /* Offset into vcpu->arch */ - addiu k1, a1, VCPU_HOST_ARCH + /* Offset into vcpu->arch */ + addiu k1, a1, VCPU_HOST_ARCH - /* Save the host stack to VCPU, used for exception processing when we exit from the Guest */ - LONG_S sp, VCPU_HOST_STACK(k1) + /* + * Save the host stack to VCPU, used for exception processing + * when we exit from the Guest + */ + LONG_S sp, VCPU_HOST_STACK(k1) - /* Save the kernel gp as well */ - LONG_S gp, VCPU_HOST_GP(k1) + /* Save the kernel gp as well */ + LONG_S gp, VCPU_HOST_GP(k1) /* Setup status register for running the guest in UM, interrupts are disabled */ - li k0,(ST0_EXL | KSU_USER| ST0_BEV) - mtc0 k0,CP0_STATUS - ehb - - /* load up the new EBASE */ - LONG_L k0, VCPU_GUEST_EBASE(k1) - mtc0 k0,CP0_EBASE - - /* Now that the new EBASE has been loaded, unset BEV, set interrupt mask as it was - * but make sure that timer interrupts are enabled - */ - li k0,(ST0_EXL | KSU_USER | ST0_IE) - andi v0, v0, ST0_IM - or k0, k0, v0 - mtc0 k0,CP0_STATUS - ehb + li k0, (ST0_EXL | KSU_USER| ST0_BEV) + mtc0 k0, CP0_STATUS + ehb + + /* load up the new EBASE */ + LONG_L k0, VCPU_GUEST_EBASE(k1) + mtc0 k0, CP0_EBASE + + /* + * Now that the new EBASE has been loaded, unset BEV, set + * interrupt mask as it was but make sure that timer interrupts + * are enabled + */ + li k0, (ST0_EXL | KSU_USER | ST0_IE) + andi v0, v0, ST0_IM + or k0, k0, v0 + mtc0 k0, CP0_STATUS + ehb /* Set Guest EPC */ - LONG_L t0, KVM_VCPU_ARCH_EPC(k1) - mtc0 t0, CP0_EPC + LONG_L t0, KVM_VCPU_ARCH_EPC(k1) + mtc0 t0, CP0_EPC FEXPORT(__kvm_mips_load_asid) - /* Set the ASID for the Guest Kernel */ - sll t0, t0, 1 /* with kseg0 @ 0x40000000, kernel */ - /* addresses shift to 0x80000000 */ - bltz t0, 1f /* If kernel */ - addiu t1, k1, VCPU_GUEST_KERNEL_ASID /* (BD) */ - addiu t1, k1, VCPU_GUEST_USER_ASID /* else user */ + /* Set the ASID for the Guest Kernel */ + sll t0, t0, 1 /* with kseg0 @ 0x40000000, kernel */ + /* addresses shift to 0x80000000 */ + bltz t0, 1f /* If kernel */ + addiu t1, k1, VCPU_GUEST_KERNEL_ASID /* (BD) */ + addiu t1, k1, VCPU_GUEST_USER_ASID /* else user */ 1: - /* t1: contains the base of the ASID array, need to get the cpu id */ - LONG_L t2, TI_CPU($28) /* smp_processor_id */ - sll t2, t2, 2 /* x4 */ - addu t3, t1, t2 - LONG_L k0, (t3) - andi k0, k0, 0xff - mtc0 k0,CP0_ENTRYHI - ehb - - /* Disable RDHWR access */ - mtc0 zero, CP0_HWRENA - - /* Now load up the Guest Context from VCPU */ - LONG_L $1, KVM_VCPU_ARCH_R1(k1) - LONG_L $2, KVM_VCPU_ARCH_R2(k1) - LONG_L $3, KVM_VCPU_ARCH_R3(k1) - - LONG_L $4, KVM_VCPU_ARCH_R4(k1) - LONG_L $5, KVM_VCPU_ARCH_R5(k1) - LONG_L $6, KVM_VCPU_ARCH_R6(k1) - LONG_L $7, KVM_VCPU_ARCH_R7(k1) - - LONG_L $8, KVM_VCPU_ARCH_R8(k1) - LONG_L $9, KVM_VCPU_ARCH_R9(k1) - LONG_L $10, KVM_VCPU_ARCH_R10(k1) - LONG_L $11, KVM_VCPU_ARCH_R11(k1) - LONG_L $12, KVM_VCPU_ARCH_R12(k1) - LONG_L $13, KVM_VCPU_ARCH_R13(k1) - LONG_L $14, KVM_VCPU_ARCH_R14(k1) - LONG_L $15, KVM_VCPU_ARCH_R15(k1) - LONG_L $16, KVM_VCPU_ARCH_R16(k1) - LONG_L $17, KVM_VCPU_ARCH_R17(k1) - LONG_L $18, KVM_VCPU_ARCH_R18(k1) - LONG_L $19, KVM_VCPU_ARCH_R19(k1) - LONG_L $20, KVM_VCPU_ARCH_R20(k1) - LONG_L $21, KVM_VCPU_ARCH_R21(k1) - LONG_L $22, KVM_VCPU_ARCH_R22(k1) - LONG_L $23, KVM_VCPU_ARCH_R23(k1) - LONG_L $24, KVM_VCPU_ARCH_R24(k1) - LONG_L $25, KVM_VCPU_ARCH_R25(k1) - - /* k0/k1 loaded up later */ - - LONG_L $28, KVM_VCPU_ARCH_R28(k1) - LONG_L $29, KVM_VCPU_ARCH_R29(k1) - LONG_L $30, KVM_VCPU_ARCH_R30(k1) - LONG_L $31, KVM_VCPU_ARCH_R31(k1) - - /* Restore hi/lo */ - LONG_L k0, KVM_VCPU_ARCH_LO(k1) - mtlo k0 - - LONG_L k0, KVM_VCPU_ARCH_HI(k1) - mthi k0 + /* t1: contains the base of the ASID array, need to get the cpu id */ + LONG_L t2, TI_CPU($28) /* smp_processor_id */ + sll t2, t2, 2 /* x4 */ + addu t3, t1, t2 + LONG_L k0, (t3) + andi k0, k0, 0xff + mtc0 k0, CP0_ENTRYHI + ehb + + /* Disable RDHWR access */ + mtc0 zero, CP0_HWRENA + + /* Now load up the Guest Context from VCPU */ + LONG_L $1, KVM_VCPU_ARCH_R1(k1) + LONG_L $2, KVM_VCPU_ARCH_R2(k1) + LONG_L $3, KVM_VCPU_ARCH_R3(k1) + + LONG_L $4, KVM_VCPU_ARCH_R4(k1) + LONG_L $5, KVM_VCPU_ARCH_R5(k1) + LONG_L $6, KVM_VCPU_ARCH_R6(k1) + LONG_L $7, KVM_VCPU_ARCH_R7(k1) + + LONG_L $8, KVM_VCPU_ARCH_R8(k1) + LONG_L $9, KVM_VCPU_ARCH_R9(k1) + LONG_L $10, KVM_VCPU_ARCH_R10(k1) + LONG_L $11, KVM_VCPU_ARCH_R11(k1) + LONG_L $12, KVM_VCPU_ARCH_R12(k1) + LONG_L $13, KVM_VCPU_ARCH_R13(k1) + LONG_L $14, KVM_VCPU_ARCH_R14(k1) + LONG_L $15, KVM_VCPU_ARCH_R15(k1) + LONG_L $16, KVM_VCPU_ARCH_R16(k1) + LONG_L $17, KVM_VCPU_ARCH_R17(k1) + LONG_L $18, KVM_VCPU_ARCH_R18(k1) + LONG_L $19, KVM_VCPU_ARCH_R19(k1) + LONG_L $20, KVM_VCPU_ARCH_R20(k1) + LONG_L $21, KVM_VCPU_ARCH_R21(k1) + LONG_L $22, KVM_VCPU_ARCH_R22(k1) + LONG_L $23, KVM_VCPU_ARCH_R23(k1) + LONG_L $24, KVM_VCPU_ARCH_R24(k1) + LONG_L $25, KVM_VCPU_ARCH_R25(k1) + + /* k0/k1 loaded up later */ + + LONG_L $28, KVM_VCPU_ARCH_R28(k1) + LONG_L $29, KVM_VCPU_ARCH_R29(k1) + LONG_L $30, KVM_VCPU_ARCH_R30(k1) + LONG_L $31, KVM_VCPU_ARCH_R31(k1) + + /* Restore hi/lo */ + LONG_L k0, KVM_VCPU_ARCH_LO(k1) + mtlo k0 + + LONG_L k0, KVM_VCPU_ARCH_HI(k1) + mthi k0 FEXPORT(__kvm_mips_load_k0k1) /* Restore the guest's k0/k1 registers */ - LONG_L k0, KVM_VCPU_ARCH_R26(k1) - LONG_L k1, KVM_VCPU_ARCH_R27(k1) + LONG_L k0, KVM_VCPU_ARCH_R26(k1) + LONG_L k1, KVM_VCPU_ARCH_R27(k1) - /* Jump to guest */ + /* Jump to guest */ eret .set pop
@@ -230,19 +235,19 @@ VECTOR(MIPSX(exception), unknown) /* * Find out what mode we came from and jump to the proper handler. */ - .set push + .set push .set noat - .set noreorder - mtc0 k0, CP0_ERROREPC #01: Save guest k0 - ehb #02: - - mfc0 k0, CP0_EBASE #02: Get EBASE - srl k0, k0, 10 #03: Get rid of CPUNum - sll k0, k0, 10 #04 - LONG_S k1, 0x3000(k0) #05: Save k1 @ offset 0x3000 - addiu k0, k0, 0x2000 #06: Exception handler is installed @ offset 0x2000 - j k0 #07: jump to the function - nop #08: branch delay slot + .set noreorder + mtc0 k0, CP0_ERROREPC #01: Save guest k0 + ehb #02: + + mfc0 k0, CP0_EBASE #02: Get EBASE + srl k0, k0, 10 #03: Get rid of CPUNum + sll k0, k0, 10 #04 + LONG_S k1, 0x3000(k0) #05: Save k1 @ offset 0x3000 + addiu k0, k0, 0x2000 #06: Exception handler is installed @ offset 0x2000 + j k0 #07: jump to the function + nop #08: branch delay slot .set push VECTOR_END(MIPSX(exceptionEnd)) .end MIPSX(exception)
@@ -253,327 +258,330 @@ VECTOR_END(MIPSX(exceptionEnd)) * */ NESTED (MIPSX(GuestException), CALLFRAME_SIZ, ra) - .set push - .set noat - .set noreorder - - /* Get the VCPU pointer from DDTATA_LO */ - mfc0 k1, CP0_DDATA_LO - addiu k1, k1, VCPU_HOST_ARCH - - /* Start saving Guest context to VCPU */ - LONG_S $0, KVM_VCPU_ARCH_R0(k1) - LONG_S $1, KVM_VCPU_ARCH_R1(k1) - LONG_S $2, KVM_VCPU_ARCH_R2(k1) - LONG_S $3, KVM_VCPU_ARCH_R3(k1) - LONG_S $4, KVM_VCPU_ARCH_R4(k1) - LONG_S $5, KVM_VCPU_ARCH_R5(k1) - LONG_S $6, KVM_VCPU_ARCH_R6(k1) - LONG_S $7, KVM_VCPU_ARCH_R7(k1) - LONG_S $8, KVM_VCPU_ARCH_R8(k1) - LONG_S $9, KVM_VCPU_ARCH_R9(k1) - LONG_S $10, KVM_VCPU_ARCH_R10(k1) - LONG_S $11, KVM_VCPU_ARCH_R11(k1) - LONG_S $12, KVM_VCPU_ARCH_R12(k1) - LONG_S $13, KVM_VCPU_ARCH_R13(k1) - LONG_S $14, KVM_VCPU_ARCH_R14(k1) - LONG_S $15, KVM_VCPU_ARCH_R15(k1) - LONG_S $16, KVM_VCPU_ARCH_R16(k1) - LONG_S $17, KVM_VCPU_ARCH_R17(k1) - LONG_S $18, KVM_VCPU_ARCH_R18(k1) - LONG_S $19, KVM_VCPU_ARCH_R19(k1) - LONG_S $20, KVM_VCPU_ARCH_R20(k1) - LONG_S $21, KVM_VCPU_ARCH_R21(k1) - LONG_S $22, KVM_VCPU_ARCH_R22(k1) - LONG_S $23, KVM_VCPU_ARCH_R23(k1) - LONG_S $24, KVM_VCPU_ARCH_R24(k1) - LONG_S $25, KVM_VCPU_ARCH_R25(k1) - - /* Guest k0/k1 saved later */ - - LONG_S $28, KVM_VCPU_ARCH_R28(k1) - LONG_S $29, KVM_VCPU_ARCH_R29(k1) - LONG_S $30, KVM_VCPU_ARCH_R30(k1) - LONG_S $31, KVM_VCPU_ARCH_R31(k1) - - /* We need to save hi/lo and restore them on - * the way out - */ - mfhi t0 - LONG_S t0, KVM_VCPU_ARCH_HI(k1) - - mflo t0 - LONG_S t0, KVM_VCPU_ARCH_LO(k1) - - /* Finally save guest k0/k1 to VCPU */ - mfc0 t0, CP0_ERROREPC - LONG_S t0, KVM_VCPU_ARCH_R26(k1) - - /* Get GUEST k1 and save it in VCPU */ + .set push + .set noat + .set noreorder + + /* Get the VCPU pointer from DDTATA_LO */ + mfc0 k1, CP0_DDATA_LO + addiu k1, k1, VCPU_HOST_ARCH + + /* Start saving Guest context to VCPU */ + LONG_S $0, KVM_VCPU_ARCH_R0(k1) + LONG_S $1, KVM_VCPU_ARCH_R1(k1) + LONG_S $2, KVM_VCPU_ARCH_R2(k1) + LONG_S $3, KVM_VCPU_ARCH_R3(k1) + LONG_S $4, KVM_VCPU_ARCH_R4(k1) + LONG_S $5, KVM_VCPU_ARCH_R5(k1) + LONG_S $6, KVM_VCPU_ARCH_R6(k1) + LONG_S $7, KVM_VCPU_ARCH_R7(k1) + LONG_S $8, KVM_VCPU_ARCH_R8(k1) + LONG_S $9, KVM_VCPU_ARCH_R9(k1) + LONG_S $10, KVM_VCPU_ARCH_R10(k1) + LONG_S $11, KVM_VCPU_ARCH_R11(k1) + LONG_S $12, KVM_VCPU_ARCH_R12(k1) + LONG_S $13, KVM_VCPU_ARCH_R13(k1) + LONG_S $14, KVM_VCPU_ARCH_R14(k1) + LONG_S $15, KVM_VCPU_ARCH_R15(k1) + LONG_S $16, KVM_VCPU_ARCH_R16(k1) + LONG_S $17, KVM_VCPU_ARCH_R17(k1) + LONG_S $18, KVM_VCPU_ARCH_R18(k1) + LONG_S $19, KVM_VCPU_ARCH_R19(k1) + LONG_S $20, KVM_VCPU_ARCH_R20(k1) + LONG_S $21, KVM_VCPU_ARCH_R21(k1) + LONG_S $22, KVM_VCPU_ARCH_R22(k1) + LONG_S $23, KVM_VCPU_ARCH_R23(k1) + LONG_S $24, KVM_VCPU_ARCH_R24(k1) + LONG_S $25, KVM_VCPU_ARCH_R25(k1) + + /* Guest k0/k1 saved later */ + + LONG_S $28, KVM_VCPU_ARCH_R28(k1) + LONG_S $29, KVM_VCPU_ARCH_R29(k1) + LONG_S $30, KVM_VCPU_ARCH_R30(k1) + LONG_S $31, KVM_VCPU_ARCH_R31(k1) + + /* We need to save hi/lo and restore them on + * the way out + */ + mfhi t0 + LONG_S t0, KVM_VCPU_ARCH_HI(k1) + + mflo t0 + LONG_S t0, KVM_VCPU_ARCH_LO(k1) + + /* Finally save guest k0/k1 to VCPU */ + mfc0 t0, CP0_ERROREPC + LONG_S t0, KVM_VCPU_ARCH_R26(k1) + + /* Get GUEST k1 and save it in VCPU */ PTR_LI t1, ~0x2ff - mfc0 t0, CP0_EBASE - and t0, t0, t1 - LONG_L t0, 0x3000(t0) - LONG_S t0, KVM_VCPU_ARCH_R27(k1) - - /* Now that context has been saved, we can use other registers */ + mfc0 t0, CP0_EBASE + and t0, t0, t1 + LONG_L t0, 0x3000(t0) + LONG_S t0, KVM_VCPU_ARCH_R27(k1) - /* Restore vcpu */ - mfc0 a1, CP0_DDATA_LO - move s1, a1 + /* Now that context has been saved, we can use other registers */ - /* Restore run (vcpu->run) */ - LONG_L a0, VCPU_RUN(a1) - /* Save pointer to run in s0, will be saved by the compiler */ - move s0, a0 + /* Restore vcpu */ + mfc0 a1, CP0_DDATA_LO + move s1, a1 + /* Restore run (vcpu->run) */ + LONG_L a0, VCPU_RUN(a1) + /* Save pointer to run in s0, will be saved by the compiler */ + move s0, a0 - /* Save Host level EPC, BadVaddr and Cause to VCPU, useful to process the exception */ - mfc0 k0,CP0_EPC - LONG_S k0, KVM_VCPU_ARCH_EPC(k1) + /* Save Host level EPC, BadVaddr and Cause to VCPU, useful to + * process the exception */ + mfc0 k0,CP0_EPC + LONG_S k0, KVM_VCPU_ARCH_EPC(k1) - mfc0 k0, CP0_BADVADDR - LONG_S k0, VCPU_HOST_CP0_BADVADDR(k1) + mfc0 k0, CP0_BADVADDR + LONG_S k0, VCPU_HOST_CP0_BADVADDR(k1) - mfc0 k0, CP0_CAUSE - LONG_S k0, VCPU_HOST_CP0_CAUSE(k1) + mfc0 k0, CP0_CAUSE + LONG_S k0, VCPU_HOST_CP0_CAUSE(k1) - mfc0 k0, CP0_ENTRYHI - LONG_S k0, VCPU_HOST_ENTRYHI(k1) + mfc0 k0, CP0_ENTRYHI + LONG_S k0, VCPU_HOST_ENTRYHI(k1) - /* Now restore the host state just enough to run the handlers */ + /* Now restore the host state just enough to run the handlers */ - /* Swtich EBASE to the one used by Linux */ - /* load up the host EBASE */ - mfc0 v0, CP0_STATUS + /* Swtich EBASE to the one used by Linux */ + /* load up the host EBASE */ + mfc0 v0, CP0_STATUS - .set at - or k0, v0, ST0_BEV - .set noat + .set at + or k0, v0, ST0_BEV + .set noat - mtc0 k0, CP0_STATUS - ehb + mtc0 k0, CP0_STATUS + ehb - LONG_L k0, VCPU_HOST_EBASE(k1) - mtc0 k0,CP0_EBASE + LONG_L k0, VCPU_HOST_EBASE(k1) + mtc0 k0,CP0_EBASE - /* Now that the new EBASE has been loaded, unset BEV and KSU_USER */ - .set at - and v0, v0, ~(ST0_EXL | KSU_USER | ST0_IE) - or v0, v0, ST0_CU0 - .set noat - mtc0 v0, CP0_STATUS - ehb + /* Now that the new EBASE has been loaded, unset BEV and KSU_USER */ + .set at + and v0, v0, ~(ST0_EXL | KSU_USER | ST0_IE) + or v0, v0, ST0_CU0 + .set noat + mtc0 v0, CP0_STATUS + ehb - /* Load up host GP */ - LONG_L gp, VCPU_HOST_GP(k1) + /* Load up host GP */ + LONG_L gp, VCPU_HOST_GP(k1) - /* Need a stack before we can jump to "C" */ - LONG_L sp, VCPU_HOST_STACK(k1) + /* Need a stack before we can jump to "C" */ + LONG_L sp, VCPU_HOST_STACK(k1) - /* Saved host state */ - addiu sp,sp, -PT_SIZE + /* Saved host state */ + addiu sp,sp, -PT_SIZE - /* XXXKYMA do we need to load the host ASID, maybe not because the - * kernel entries are marked GLOBAL, need to verify - */ + /* XXXKYMA do we need to load the host ASID, maybe not because the + * kernel entries are marked GLOBAL, need to verify + */ - /* Restore host DDATA_LO */ - LONG_L k0, PT_HOST_USERLOCAL(sp) - mtc0 k0, CP0_DDATA_LO + /* Restore host DDATA_LO */ + LONG_L k0, PT_HOST_USERLOCAL(sp) + mtc0 k0, CP0_DDATA_LO - /* Restore RDHWR access */ + /* Restore RDHWR access */ PTR_LI k0, 0x2000000F - mtc0 k0, CP0_HWRENA + mtc0 k0, CP0_HWRENA - /* Jump to handler */ + /* Jump to handler */ FEXPORT(__kvm_mips_jump_to_handler) - /* XXXKYMA: not sure if this is safe, how large is the stack?? */ - /* Now jump to the kvm_mips_handle_exit() to see if we can deal with this in the kernel */ + /* XXXKYMA: not sure if this is safe, how large is the stack?? + * Now jump to the kvm_mips_handle_exit() to see if we can deal + * with this in the kernel */ PTR_LA t9, kvm_mips_handle_exit - jalr.hb t9 - addiu sp,sp, -CALLFRAME_SIZ /* BD Slot */ - - /* Return from handler Make sure interrupts are disabled */ - di - ehb - - /* XXXKYMA: k0/k1 could have been blown away if we processed an exception - * while we were handling the exception from the guest, reload k1 - */ - move k1, s1 - addiu k1, k1, VCPU_HOST_ARCH - - /* Check return value, should tell us if we are returning to the host (handle I/O etc) - * or resuming the guest - */ - andi t0, v0, RESUME_HOST - bnez t0, __kvm_mips_return_to_host - nop + jalr.hb t9 + addiu sp,sp, -CALLFRAME_SIZ /* BD Slot */ + + /* Return from handler Make sure interrupts are disabled */ + di + ehb + + /* XXXKYMA: k0/k1 could have been blown away if we processed + * an exception while we were handling the exception from the + * guest, reload k1 + */ + + move k1, s1 + addiu k1, k1, VCPU_HOST_ARCH + + /* Check return value, should tell us if we are returning to the + * host (handle I/O etc)or resuming the guest + */ + andi t0, v0, RESUME_HOST + bnez t0, __kvm_mips_return_to_host + nop __kvm_mips_return_to_guest: - /* Put the saved pointer to vcpu (s1) back into the DDATA_LO Register */ - mtc0 s1, CP0_DDATA_LO - - /* Load up the Guest EBASE to minimize the window where BEV is set */ - LONG_L t0, VCPU_GUEST_EBASE(k1) - - /* Switch EBASE back to the one used by KVM */ - mfc0 v1, CP0_STATUS - .set at - or k0, v1, ST0_BEV - .set noat - mtc0 k0, CP0_STATUS - ehb - mtc0 t0,CP0_EBASE - - /* Setup status register for running guest in UM */ - .set at - or v1, v1, (ST0_EXL | KSU_USER | ST0_IE) - and v1, v1, ~ST0_CU0 - .set noat - mtc0 v1, CP0_STATUS - ehb + /* Put the saved pointer to vcpu (s1) back into the DDATA_LO Register */ + mtc0 s1, CP0_DDATA_LO + + /* Load up the Guest EBASE to minimize the window where BEV is set */ + LONG_L t0, VCPU_GUEST_EBASE(k1) + /* Switch EBASE back to the one used by KVM */ + mfc0 v1, CP0_STATUS + .set at + or k0, v1, ST0_BEV + .set noat + mtc0 k0, CP0_STATUS + ehb + mtc0 t0, CP0_EBASE + + /* Setup status register for running guest in UM */ + .set at + or v1, v1, (ST0_EXL | KSU_USER | ST0_IE) + and v1, v1, ~ST0_CU0 + .set noat + mtc0 v1, CP0_STATUS + ehb /* Set Guest EPC */ - LONG_L t0, KVM_VCPU_ARCH_EPC(k1) - mtc0 t0, CP0_EPC - - /* Set the ASID for the Guest Kernel */ - sll t0, t0, 1 /* with kseg0 @ 0x40000000, kernel */ - /* addresses shift to 0x80000000 */ - bltz t0, 1f /* If kernel */ - addiu t1, k1, VCPU_GUEST_KERNEL_ASID /* (BD) */ - addiu t1, k1, VCPU_GUEST_USER_ASID /* else user */ + LONG_L t0, KVM_VCPU_ARCH_EPC(k1) + mtc0 t0, CP0_EPC + + /* Set the ASID for the Guest Kernel */ + sll t0, t0, 1 /* with kseg0 @ 0x40000000, kernel */ + /* addresses shift to 0x80000000 */ + bltz t0, 1f /* If kernel */ + addiu t1, k1, VCPU_GUEST_KERNEL_ASID /* (BD) */ + addiu t1, k1, VCPU_GUEST_USER_ASID /* else user */ 1: - /* t1: contains the base of the ASID array, need to get the cpu id */ - LONG_L t2, TI_CPU($28) /* smp_processor_id */ - sll t2, t2, 2 /* x4 */ - addu t3, t1, t2 - LONG_L k0, (t3) - andi k0, k0, 0xff - mtc0 k0,CP0_ENTRYHI - ehb - - /* Disable RDHWR access */ - mtc0 zero, CP0_HWRENA + /* t1: contains the base of the ASID array, need to get the cpu id */ + LONG_L t2, TI_CPU($28) /* smp_processor_id */ + sll t2, t2, 2 /* x4 */ + addu t3, t1, t2 + LONG_L k0, (t3) + andi k0, k0, 0xff + mtc0 k0,CP0_ENTRYHI + ehb + + /* Disable RDHWR access */ + mtc0 zero, CP0_HWRENA /* load the guest context from VCPU and return */ - LONG_L $0, KVM_VCPU_ARCH_R0(k1) - LONG_L $1, KVM_VCPU_ARCH_R1(k1) - LONG_L $2, KVM_VCPU_ARCH_R2(k1) - LONG_L $3, KVM_VCPU_ARCH_R3(k1) - LONG_L $4, KVM_VCPU_ARCH_R4(k1) - LONG_L $5, KVM_VCPU_ARCH_R5(k1) - LONG_L $6, KVM_VCPU_ARCH_R6(k1) - LONG_L $7, KVM_VCPU_ARCH_R7(k1) - LONG_L $8, KVM_VCPU_ARCH_R8(k1) - LONG_L $9, KVM_VCPU_ARCH_R9(k1) - LONG_L $10, KVM_VCPU_ARCH_R10(k1) - LONG_L $11, KVM_VCPU_ARCH_R11(k1) - LONG_L $12, KVM_VCPU_ARCH_R12(k1) - LONG_L $13, KVM_VCPU_ARCH_R13(k1) - LONG_L $14, KVM_VCPU_ARCH_R14(k1) - LONG_L $15, KVM_VCPU_ARCH_R15(k1) - LONG_L $16, KVM_VCPU_ARCH_R16(k1) - LONG_L $17, KVM_VCPU_ARCH_R17(k1) - LONG_L $18, KVM_VCPU_ARCH_R18(k1) - LONG_L $19, KVM_VCPU_ARCH_R19(k1) - LONG_L $20, KVM_VCPU_ARCH_R20(k1) - LONG_L $21, KVM_VCPU_ARCH_R21(k1) - LONG_L $22, KVM_VCPU_ARCH_R22(k1) - LONG_L $23, KVM_VCPU_ARCH_R23(k1) - LONG_L $24, KVM_VCPU_ARCH_R24(k1) - LONG_L $25, KVM_VCPU_ARCH_R25(k1) - - /* $/k1 loaded later */ - LONG_L $28, KVM_VCPU_ARCH_R28(k1) - LONG_L $29, KVM_VCPU_ARCH_R29(k1) - LONG_L $30, KVM_VCPU_ARCH_R30(k1) - LONG_L $31, KVM_VCPU_ARCH_R31(k1) + LONG_L $0, KVM_VCPU_ARCH_R0(k1) + LONG_L $1, KVM_VCPU_ARCH_R1(k1) + LONG_L $2, KVM_VCPU_ARCH_R2(k1) + LONG_L $3, KVM_VCPU_ARCH_R3(k1) + LONG_L $4, KVM_VCPU_ARCH_R4(k1) + LONG_L $5, KVM_VCPU_ARCH_R5(k1) + LONG_L $6, KVM_VCPU_ARCH_R6(k1) + LONG_L $7, KVM_VCPU_ARCH_R7(k1) + LONG_L $8, KVM_VCPU_ARCH_R8(k1) + LONG_L $9, KVM_VCPU_ARCH_R9(k1) + LONG_L $10, KVM_VCPU_ARCH_R10(k1) + LONG_L $11, KVM_VCPU_ARCH_R11(k1) + LONG_L $12, KVM_VCPU_ARCH_R12(k1) + LONG_L $13, KVM_VCPU_ARCH_R13(k1) + LONG_L $14, KVM_VCPU_ARCH_R14(k1) + LONG_L $15, KVM_VCPU_ARCH_R15(k1) + LONG_L $16, KVM_VCPU_ARCH_R16(k1) + LONG_L $17, KVM_VCPU_ARCH_R17(k1) + LONG_L $18, KVM_VCPU_ARCH_R18(k1) + LONG_L $19, KVM_VCPU_ARCH_R19(k1) + LONG_L $20, KVM_VCPU_ARCH_R20(k1) + LONG_L $21, KVM_VCPU_ARCH_R21(k1) + LONG_L $22, KVM_VCPU_ARCH_R22(k1) + LONG_L $23, KVM_VCPU_ARCH_R23(k1) + LONG_L $24, KVM_VCPU_ARCH_R24(k1) + LONG_L $25, KVM_VCPU_ARCH_R25(k1) + + /* $/k1 loaded later */ + LONG_L $28, KVM_VCPU_ARCH_R28(k1) + LONG_L $29, KVM_VCPU_ARCH_R29(k1) + LONG_L $30, KVM_VCPU_ARCH_R30(k1) + LONG_L $31, KVM_VCPU_ARCH_R31(k1) FEXPORT(__kvm_mips_skip_guest_restore) - LONG_L k0, KVM_VCPU_ARCH_HI(k1) - mthi k0 + LONG_L k0, KVM_VCPU_ARCH_HI(k1) + mthi k0 - LONG_L k0, KVM_VCPU_ARCH_LO(k1) - mtlo k0 + LONG_L k0, KVM_VCPU_ARCH_LO(k1) + mtlo k0 - LONG_L k0, KVM_VCPU_ARCH_R26(k1) - LONG_L k1, KVM_VCPU_ARCH_R27(k1) + LONG_L k0, KVM_VCPU_ARCH_R26(k1) + LONG_L k1, KVM_VCPU_ARCH_R27(k1) - eret + eret __kvm_mips_return_to_host: - /* EBASE is already pointing to Linux */ - LONG_L k1, VCPU_HOST_STACK(k1) - addiu k1,k1, -PT_SIZE - - /* Restore host DDATA_LO */ - LONG_L k0, PT_HOST_USERLOCAL(k1) - mtc0 k0, CP0_DDATA_LO - - /* Restore host ASID */ - LONG_L k0, PT_HOST_ASID(sp) - andi k0, 0xff - mtc0 k0,CP0_ENTRYHI - ehb - - /* Load context saved on the host stack */ - LONG_L $0, PT_R0(k1) - LONG_L $1, PT_R1(k1) - - /* r2/v0 is the return code, shift it down by 2 (arithmetic) to recover the err code */ - sra k0, v0, 2 - move $2, k0 - - LONG_L $3, PT_R3(k1) - LONG_L $4, PT_R4(k1) - LONG_L $5, PT_R5(k1) - LONG_L $6, PT_R6(k1) - LONG_L $7, PT_R7(k1) - LONG_L $8, PT_R8(k1) - LONG_L $9, PT_R9(k1) - LONG_L $10, PT_R10(k1) - LONG_L $11, PT_R11(k1) - LONG_L $12, PT_R12(k1) - LONG_L $13, PT_R13(k1) - LONG_L $14, PT_R14(k1) - LONG_L $15, PT_R15(k1) - LONG_L $16, PT_R16(k1) - LONG_L $17, PT_R17(k1) - LONG_L $18, PT_R18(k1) - LONG_L $19, PT_R19(k1) - LONG_L $20, PT_R20(k1) - LONG_L $21, PT_R21(k1) - LONG_L $22, PT_R22(k1) - LONG_L $23, PT_R23(k1) - LONG_L $24, PT_R24(k1) - LONG_L $25, PT_R25(k1) - - /* Host k0/k1 were not saved */ - - LONG_L $28, PT_R28(k1) - LONG_L $29, PT_R29(k1) - LONG_L $30, PT_R30(k1) - - LONG_L k0, PT_HI(k1) - mthi k0 - - LONG_L k0, PT_LO(k1) - mtlo k0 - - /* Restore RDHWR access */ + /* EBASE is already pointing to Linux */ + LONG_L k1, VCPU_HOST_STACK(k1) + addiu k1,k1, -PT_SIZE + + /* Restore host DDATA_LO */ + LONG_L k0, PT_HOST_USERLOCAL(k1) + mtc0 k0, CP0_DDATA_LO + + /* Restore host ASID */ + LONG_L k0, PT_HOST_ASID(sp) + andi k0, 0xff + mtc0 k0,CP0_ENTRYHI + ehb + + /* Load context saved on the host stack */ + LONG_L $0, PT_R0(k1) + LONG_L $1, PT_R1(k1) + + /* r2/v0 is the return code, shift it down by 2 (arithmetic) + * to recover the err code */ + sra k0, v0, 2 + move $2, k0 + + LONG_L $3, PT_R3(k1) + LONG_L $4, PT_R4(k1) + LONG_L $5, PT_R5(k1) + LONG_L $6, PT_R6(k1) + LONG_L $7, PT_R7(k1) + LONG_L $8, PT_R8(k1) + LONG_L $9, PT_R9(k1) + LONG_L $10, PT_R10(k1) + LONG_L $11, PT_R11(k1) + LONG_L $12, PT_R12(k1) + LONG_L $13, PT_R13(k1) + LONG_L $14, PT_R14(k1) + LONG_L $15, PT_R15(k1) + LONG_L $16, PT_R16(k1) + LONG_L $17, PT_R17(k1) + LONG_L $18, PT_R18(k1) + LONG_L $19, PT_R19(k1) + LONG_L $20, PT_R20(k1) + LONG_L $21, PT_R21(k1) + LONG_L $22, PT_R22(k1) + LONG_L $23, PT_R23(k1) + LONG_L $24, PT_R24(k1) + LONG_L $25, PT_R25(k1) + + /* Host k0/k1 were not saved */ + + LONG_L $28, PT_R28(k1) + LONG_L $29, PT_R29(k1) + LONG_L $30, PT_R30(k1) + + LONG_L k0, PT_HI(k1) + mthi k0 + + LONG_L k0, PT_LO(k1) + mtlo k0 + + /* Restore RDHWR access */ PTR_LI k0, 0x2000000F - mtc0 k0, CP0_HWRENA + mtc0 k0, CP0_HWRENA - /* Restore RA, which is the address we will return to */ - LONG_L ra, PT_R31(k1) - j ra - nop + /* Restore RA, which is the address we will return to */ + LONG_L ra, PT_R31(k1) + j ra + nop .set pop VECTOR_END(MIPSX(GuestExceptionEnd))
@@ -627,24 +635,23 @@ MIPSX(exceptions): #define HW_SYNCI_Step $1 LEAF(MIPSX(SyncICache)) - .set push + .set push .set mips32r2 - beq a1, zero, 20f - nop - addu a1, a0, a1 - rdhwr v0, HW_SYNCI_Step - beq v0, zero, 20f - nop - + beq a1, zero, 20f + nop + addu a1, a0, a1 + rdhwr v0, HW_SYNCI_Step + beq v0, zero, 20f + nop 10: - synci 0(a0) - addu a0, a0, v0 - sltu v1, a0, a1 - bne v1, zero, 10b - nop - sync + synci 0(a0) + addu a0, a0, v0 + sltu v1, a0, a1 + bne v1, zero, 10b + nop + sync 20: - jr.hb ra - nop - .set pop + jr.hb ra + nop + .set pop END(MIPSX(SyncICache))
Signature · 1 line
1.7.11.7
PATCH 9/31 mips/kvm: Factor trap-and-emulate support into a pluggable implementation.
In reply to David DaneyFrom: David Daney <[email protected]>
Many of the arch entry points now dispatch through an ops vector. This will allow alternate implementations based on the MIPSVZ hardware support to be added.
There is no substantive code change here, just moving things around. The biggest change is that the implementation specific data needed by the vcpu and kvm is held in separate structures, pointed to by vcpu->arch.impl and kvm->arch.impl, minor changes to the assembly code was made to traverse these pointers.
--- arch/mips/include/asm/kvm_host.h | 610 ++---------------------- arch/mips/include/asm/kvm_mips_te.h | 589 +++++++++++++++++++++++ arch/mips/kernel/asm-offsets.c | 100 ++-- arch/mips/kvm/kvm_locore.S | 47 +- arch/mips/kvm/kvm_mips.c | 709 ++-------------------------- arch/mips/kvm/kvm_mips_comm.h | 1 + arch/mips/kvm/kvm_mips_commpage.c | 9 +- arch/mips/kvm/kvm_mips_emul.c | 172 ++++--- arch/mips/kvm/kvm_mips_int.c | 45 +- arch/mips/kvm/kvm_mips_int.h | 2 - arch/mips/kvm/kvm_mips_stats.c | 6 +- arch/mips/kvm/kvm_tlb.c | 138 +++--- arch/mips/kvm/kvm_trap_emul.c | 912 ++++++++++++++++++++++++++++++++++-- 13 files changed, 1807 insertions(+), 1533 deletions(-) create mode 100644 arch/mips/include/asm/kvm_mips_te.h
arch/mips/include/asm/kvm_host.h +28 -582
@@ -35,51 +35,9 @@#define KVM_PAGES_PER_HPAGE (x) 1 - -/* Special address that contains the comm page, used for reducing # of traps */ -#define KVM_GUEST_COMMPAGE_ADDR 0x0 - -#define KVM_GUEST_KERNEL_MODE (vcpu) ((kvm_read_c0_guest_status(vcpu->arch.cop0) & (ST0_EXL | ST0_ERL)) || \ - ((kvm_read_c0_guest_status(vcpu->arch.cop0) & KSU_USER) == 0)) - -#define KVM_GUEST_KUSEG 0x00000000UL -#define KVM_GUEST_KSEG0 0x40000000UL -#define KVM_GUEST_KSEG23 0x60000000UL -#define KVM_GUEST_KSEGX (a) ((_ACAST32_(a)) & 0x60000000) -#define KVM_GUEST_CPHYSADDR (a) ((_ACAST32_(a)) & 0x1fffffff) - -#define KVM_GUEST_CKSEG0ADDR (a) (KVM_GUEST_CPHYSADDR(a) | KVM_GUEST_KSEG0) -#define KVM_GUEST_CKSEG1ADDR (a) (KVM_GUEST_CPHYSADDR(a) | KVM_GUEST_KSEG1) -#define KVM_GUEST_CKSEG23ADDR (a) (KVM_GUEST_CPHYSADDR(a) | KVM_GUEST_KSEG23) - -/* -* Map an address to a certain kernel segment -*/ -#define KVM_GUEST_KSEG0ADDR (a) (KVM_GUEST_CPHYSADDR(a) | KVM_GUEST_KSEG0) -#define KVM_GUEST_KSEG1ADDR (a) (KVM_GUEST_CPHYSADDR(a) | KVM_GUEST_KSEG1) -#define KVM_GUEST_KSEG23ADDR (a) (KVM_GUEST_CPHYSADDR(a) | KVM_GUEST_KSEG23) - -#define KVM_INVALID_PAGE 0xdeadbeef -#define KVM_INVALID_INST 0xdeadbeef -#define KVM_INVALID_ADDR 0xdeadbeef - -#define KVM_MALTA_GUEST_RTC_ADDR 0xb8000070UL - -#define GUEST_TICKS_PER_JIFFY (40000000/HZ) -#define MS_TO_NS (x) (x * 1E6L) - -#define CAUSEB_DC 27 -#define CAUSEF_DC (_ULCAST_(1) << 27) -struct kvm ; -struct kvm_run ;struct kvm_vcpu ; -struct kvm_interrupt ; - -extern atomic_t kvm_mips_instance; -extern pfn_t (*kvm_mips_gfn_to_pfn) (struct kvm *kvm,gfn_t gfn); -extern void (*kvm_mips_release_pfn_clean) (pfn_t pfn); -extern bool (*kvm_mips_is_error_pfn) (pfn_t pfn); +enum kvm_mr_change ;struct kvm_vm_stat {u32 remote_tlb_flush;
@@ -103,561 +61,49 @@ struct kvm_vcpu_stat {u32 halt_wakeup; }; -enum kvm_mips_exit_types { -WAIT_EXITS , -CACHE_EXITS , -SIGNAL_EXITS , -INT_EXITS , -COP_UNUSABLE_EXITS , -TLBMOD_EXITS , -TLBMISS_LD_EXITS , -TLBMISS_ST_EXITS , -ADDRERR_ST_EXITS , -ADDRERR_LD_EXITS , -SYSCALL_EXITS , -RESVD_INST_EXITS , -BREAK_INST_EXITS , -FLUSH_DCACHE_EXITS , -MAX_KVM_MIPS_EXIT_TYPES -}; -struct kvm_arch_memory_slot { }; -struct kvm_arch { -/* Guest GVA->HPA page table */ -unsigned long *guest_pmap; -unsigned long guest_pmap_npages; - -/* Wired host TLB used for the commpage */ -int commpage_tlb; -}; - -#define N_MIPS_COPROC_REGS 32 -#define N_MIPS_COPROC_SEL 8 - -struct mips_coproc { -unsigned long reg[N_MIPS_COPROC_REGS ][N_MIPS_COPROC_SEL ]; -#ifdef CONFIG_KVM_MIPS_DEBUG_COP0_COUNTERS -unsigned long stat[N_MIPS_COPROC_REGS ][N_MIPS_COPROC_SEL ]; -#endif +struct kvm_mips_ops { +int (*vcpu_runnable)(struct kvm_vcpu *vcpu); +void (*free_vcpus)(struct kvm *kvm); +void (*destroy_vm)(struct kvm *kvm); +void (*commit_memory_region)(struct kvm *kvm, +struct kvm_userspace_memory_region *mem, +const struct kvm_memory_slot *old, +enum kvm_mr_change change); +struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm,unsigned int id); +void (*vcpu_free)(struct kvm_vcpu *vcpu); +int (*vcpu_run)(struct kvm_vcpu *vcpu,struct kvm_run *run); +long (*vm_ioctl)(struct kvm *kvm,unsigned int ioctl, +unsigned long arg); +long (*vcpu_ioctl)(struct kvm_vcpu *vcpu,unsigned int ioctl, +unsigned long arg); +int (*get_reg)(struct kvm_vcpu *vcpu,const struct kvm_one_reg *reg); +int (*set_reg)(struct kvm_vcpu *vcpu,const struct kvm_one_reg *reg, +u64 v); +int (*cpu_has_pending_timer)(struct kvm_vcpu *vcpu); +int (*vcpu_init)(struct kvm_vcpu *vcpu); +int (*vcpu_setup)(struct kvm_vcpu *vcpu); +void (*vcpu_load)(struct kvm_vcpu *vcpu,int cpu); +void (*vcpu_put)(struct kvm_vcpu *vcpu); }; -/* -* Coprocessor 0 register names -*/ -#define MIPS_CP0_TLB_INDEX 0 -#define MIPS_CP0_TLB_RANDOM 1 -#define MIPS_CP0_TLB_LOW 2 -#define MIPS_CP0_TLB_LO0 2 -#define MIPS_CP0_TLB_LO1 3 -#define MIPS_CP0_TLB_CONTEXT 4 -#define MIPS_CP0_TLB_PG_MASK 5 -#define MIPS_CP0_TLB_WIRED 6 -#define MIPS_CP0_HWRENA 7 -#define MIPS_CP0_BAD_VADDR 8 -#define MIPS_CP0_COUNT 9 -#define MIPS_CP0_TLB_HI 10 -#define MIPS_CP0_COMPARE 11 -#define MIPS_CP0_STATUS 12 -#define MIPS_CP0_CAUSE 13 -#define MIPS_CP0_EXC_PC 14 -#define MIPS_CP0_PRID 15 -#define MIPS_CP0_CONFIG 16 -#define MIPS_CP0_LLADDR 17 -#define MIPS_CP0_WATCH_LO 18 -#define MIPS_CP0_WATCH_HI 19 -#define MIPS_CP0_TLB_XCONTEXT 20 -#define MIPS_CP0_ECC 26 -#define MIPS_CP0_CACHE_ERR 27 -#define MIPS_CP0_TAG_LO 28 -#define MIPS_CP0_TAG_HI 29 -#define MIPS_CP0_ERROR_PC 30 -#define MIPS_CP0_DEBUG 23 -#define MIPS_CP0_DEPC 24 -#define MIPS_CP0_PERFCNT 25 -#define MIPS_CP0_ERRCTL 26 -#define MIPS_CP0_DATA_LO 28 -#define MIPS_CP0_DATA_HI 29 -#define MIPS_CP0_DESAVE 31 - -#define MIPS_CP0_CONFIG_SEL 0 -#define MIPS_CP0_CONFIG1_SEL 1 -#define MIPS_CP0_CONFIG2_SEL 2 -#define MIPS_CP0_CONFIG3_SEL 3 - -/* Config0 register bits */ -#define CP0C0_M 31 -#define CP0C0_K23 28 -#define CP0C0_KU 25 -#define CP0C0_MDU 20 -#define CP0C0_MM 17 -#define CP0C0_BM 16 -#define CP0C0_BE 15 -#define CP0C0_AT 13 -#define CP0C0_AR 10 -#define CP0C0_MT 7 -#define CP0C0_VI 3 -#define CP0C0_K0 0 - -/* Config1 register bits */ -#define CP0C1_M 31 -#define CP0C1_MMU 25 -#define CP0C1_IS 22 -#define CP0C1_IL 19 -#define CP0C1_IA 16 -#define CP0C1_DS 13 -#define CP0C1_DL 10 -#define CP0C1_DA 7 -#define CP0C1_C2 6 -#define CP0C1_MD 5 -#define CP0C1_PC 4 -#define CP0C1_WR 3 -#define CP0C1_CA 2 -#define CP0C1_EP 1 -#define CP0C1_FP 0 - -/* Config2 Register bits */ -#define CP0C2_M 31 -#define CP0C2_TU 28 -#define CP0C2_TS 24 -#define CP0C2_TL 20 -#define CP0C2_TA 16 -#define CP0C2_SU 12 -#define CP0C2_SS 8 -#define CP0C2_SL 4 -#define CP0C2_SA 0 - -/* Config3 Register bits */ -#define CP0C3_M 31 -#define CP0C3_ISA_ON_EXC 16 -#define CP0C3_ULRI 13 -#define CP0C3_DSPP 10 -#define CP0C3_LPA 7 -#define CP0C3_VEIC 6 -#define CP0C3_VInt 5 -#define CP0C3_SP 4 -#define CP0C3_MT 2 -#define CP0C3_SM 1 -#define CP0C3_TL 0 - -/* Have config1, Cacheable, noncoherent, write-back, write allocate*/ -#define MIPS_CONFIG0 \ - ((1 << CP0C0_M) | (0x3 << CP0C0_K0)) - -/* Have config2, no coprocessor2 attached, no MDMX support attached, -no performance counters, watch registers present, -no code compression, EJTAG present, no FPU, no watch registers */ -#define MIPS_CONFIG1 \ -((1 << CP0C1_M) | \ - (0 << CP0C1_C2) | (0 << CP0C1_MD) | (0 << CP0C1_PC) | \ - (0 << CP0C1_WR) | (0 << CP0C1_CA) | (1 << CP0C1_EP) | \ - (0 << CP0C1_FP)) - -/* Have config3, no tertiary/secondary caches implemented */ -#define MIPS_CONFIG2 \ -((1 << CP0C2_M)) - -/* No config4, no DSP ASE, no large physaddr (PABITS), -no external interrupt controller, no vectored interrupts, -no 1kb pages, no SmartMIPS ASE, no trace logic */ -#define MIPS_CONFIG3 \ -((0 << CP0C3_M) | (0 << CP0C3_DSPP) | (0 << CP0C3_LPA) | \ - (0 << CP0C3_VEIC) | (0 << CP0C3_VInt) | (0 << CP0C3_SP) | \ - (0 << CP0C3_SM) | (0 << CP0C3_TL)) - -/* MMU types, the first four entries have the same layout as the -CP0C0_MT field. */ -enum mips_mmu_types { -MMU_TYPE_NONE , -MMU_TYPE_R4000 , -MMU_TYPE_RESERVED , -MMU_TYPE_FMT , -MMU_TYPE_R3000 , -MMU_TYPE_R6000 , -MMU_TYPE_R8000 -}; - -/* -* Trap codes -*/ -#define T_INT 0/* Interrupt pending */ -#define T_TLB_MOD 1/* TLB modified fault */ -#define T_TLB_LD_MISS 2/* TLB miss on load or ifetch */ -#define T_TLB_ST_MISS 3/* TLB miss on a store */ -#define T_ADDR_ERR_LD 4/* Address error on a load or ifetch */ -#define T_ADDR_ERR_ST 5/* Address error on a store */ -#define T_BUS_ERR_IFETCH 6/* Bus error on an ifetch */ -#define T_BUS_ERR_LD_ST 7/* Bus error on a load or store */ -#define T_SYSCALL 8/* System call */ -#define T_BREAK 9/* Breakpoint */ -#define T_RES_INST 10/* Reserved instruction exception */ -#define T_COP_UNUSABLE 11/* Coprocessor unusable */ -#define T_OVFLOW 12/* Arithmetic overflow */ - -/* -* Trap definitions added for r4000 port. -*/ -#define T_TRAP 13/* Trap instruction */ -#define T_VCEI 14/* Virtual coherency exception */ -#define T_FPE 15/* Floating point exception */ -#define T_WATCH 23/* Watch address reference */ -#define T_VCED 31/* Virtual coherency data */ - -/* Resume Flags */ -#define RESUME_FLAG_DR (1<<0)/* Reload guest nonvolatile state? */ -#define RESUME_FLAG_HOST (1<<1)/* Resume host? */ - -#define RESUME_GUEST 0 -#define RESUME_GUEST_DR RESUME_FLAG_DR -#define RESUME_HOST RESUME_FLAG_HOST - -enum emulation_result { -EMULATE_DONE ,/* no further processing */ -EMULATE_DO_MMIO ,/* kvm_run filled with MMIO request */ -EMULATE_FAIL ,/* can't emulate this instruction */ -EMULATE_WAIT ,/* WAIT instruction */ -EMULATE_PRIV_FAIL , +struct kvm_arch { +const struct kvm_mips_ops *ops; +void *impl; }; -#define MIPS3_PG_G 0x00000001/* Global; ignore ASID if in lo0 & lo1 */ -#define MIPS3_PG_V 0x00000002/* Valid */ -#define MIPS3_PG_NV 0x00000000 -#define MIPS3_PG_D 0x00000004/* Dirty */ - -#define mips3_paddr_to_tlbpfn (x) \ - (((unsigned long)(x) >> MIPS3_PG_SHIFT) & MIPS3_PG_FRAME) -#define mips3_tlbpfn_to_paddr (x) \ - ((unsigned long)((x) & MIPS3_PG_FRAME) << MIPS3_PG_SHIFT) - -#define MIPS3_PG_SHIFT 6 -#define MIPS3_PG_FRAME 0x3fffffc0 - -#define VPN2_MASK 0xffffe000 -#define TLB_IS_GLOBAL (x) (((x).tlb_lo0 & MIPS3_PG_G) && ((x).tlb_lo1 & MIPS3_PG_G)) -#define TLB_VPN2 (x) ((x).tlb_hi & VPN2_MASK) -#define TLB_ASID (x) ((x).tlb_hi & ASID_MASK) -#define TLB_IS_VALID (x, va) (((va) & (1 << PAGE_SHIFT)) ? ((x).tlb_lo1 & MIPS3_PG_V) : ((x).tlb_lo0 & MIPS3_PG_V)) - -struct kvm_mips_tlb { -long tlb_mask; -long tlb_hi; -long tlb_lo0; -long tlb_lo1; -}; -#define KVM_MIPS_GUEST_TLB_SIZE 64struct kvm_vcpu_arch { -void *host_ebase, *guest_ebase; -unsigned long host_stack; -unsigned long host_gp; - -/* Host CP0 registers used when handling exits from guest */ -unsigned long host_cp0_badvaddr; -unsigned long host_cp0_cause; -unsigned long host_cp0_epc; -unsigned long host_cp0_entryhi; -uint32_t guest_inst; -/* GPRS */ unsigned long gprs[32 ];unsigned long hi;unsigned long lo;unsigned long epc; -/* FPU State */ -struct mips_fpu_struct fpu; - -/* COP0 State */ -struct mips_coproc *cop0; - -/* Host KSEG0 address of the EI/DI offset */ -void *kseg0_commpage; - -u32 io_gpr;/* GPR used as IO source/target */ - -/* Used to calibrate the virutal count register for the guest */ -int32_t host_cp0_count; - -/* Bitmask of exceptions that are pending */ -unsigned long pending_exceptions; - -/* Bitmask of pending exceptions to be cleared */ -unsigned long pending_exceptions_clr; - -unsigned long pending_load_cause; - -/* Save/Restore the entryhi register when are are preempted/scheduled back in */ -unsigned long preempt_entryhi; - -/* S/W Based TLB for guest */ -struct kvm_mips_tlb guest_tlb[KVM_MIPS_GUEST_TLB_SIZE ]; - -/* Cached guest kernel/user ASIDs */ -uint32_t guest_user_asid[NR_CPUS ]; -uint32_t guest_kernel_asid[NR_CPUS ]; -struct mm_struct guest_kernel_mm, guest_user_mm; - -struct kvm_mips_tlb shadow_tlb[NR_CPUS ][KVM_MIPS_GUEST_TLB_SIZE ]; - - -struct hrtimer comparecount_timer; - -int last_sched_cpu; - -/* WAIT executed */ -int wait; +void *impl; }; -#define kvm_read_c0_guest_index (cop0) (cop0->reg[MIPS_CP0_TLB_INDEX][0]) -#define kvm_write_c0_guest_index (cop0, val) (cop0->reg[MIPS_CP0_TLB_INDEX][0] = val) -#define kvm_read_c0_guest_entrylo0 (cop0) (cop0->reg[MIPS_CP0_TLB_LO0][0]) -#define kvm_read_c0_guest_entrylo1 (cop0) (cop0->reg[MIPS_CP0_TLB_LO1][0]) -#define kvm_read_c0_guest_context (cop0) (cop0->reg[MIPS_CP0_TLB_CONTEXT][0]) -#define kvm_write_c0_guest_context (cop0, val) (cop0->reg[MIPS_CP0_TLB_CONTEXT][0] = (val)) -#define kvm_read_c0_guest_userlocal (cop0) (cop0->reg[MIPS_CP0_TLB_CONTEXT][2]) -#define kvm_read_c0_guest_pagemask (cop0) (cop0->reg[MIPS_CP0_TLB_PG_MASK][0]) -#define kvm_write_c0_guest_pagemask (cop0, val) (cop0->reg[MIPS_CP0_TLB_PG_MASK][0] = (val)) -#define kvm_read_c0_guest_wired (cop0) (cop0->reg[MIPS_CP0_TLB_WIRED][0]) -#define kvm_write_c0_guest_wired (cop0, val) (cop0->reg[MIPS_CP0_TLB_WIRED][0] = (val)) -#define kvm_read_c0_guest_badvaddr (cop0) (cop0->reg[MIPS_CP0_BAD_VADDR][0]) -#define kvm_write_c0_guest_badvaddr (cop0, val) (cop0->reg[MIPS_CP0_BAD_VADDR][0] = (val)) -#define kvm_read_c0_guest_count (cop0) (cop0->reg[MIPS_CP0_COUNT][0]) -#define kvm_write_c0_guest_count (cop0, val) (cop0->reg[MIPS_CP0_COUNT][0] = (val)) -#define kvm_read_c0_guest_entryhi (cop0) (cop0->reg[MIPS_CP0_TLB_HI][0]) -#define kvm_write_c0_guest_entryhi (cop0, val) (cop0->reg[MIPS_CP0_TLB_HI][0] = (val)) -#define kvm_read_c0_guest_compare (cop0) (cop0->reg[MIPS_CP0_COMPARE][0]) -#define kvm_write_c0_guest_compare (cop0, val) (cop0->reg[MIPS_CP0_COMPARE][0] = (val)) -#define kvm_read_c0_guest_status (cop0) (cop0->reg[MIPS_CP0_STATUS][0]) -#define kvm_write_c0_guest_status (cop0, val) (cop0->reg[MIPS_CP0_STATUS][0] = (val)) -#define kvm_read_c0_guest_intctl (cop0) (cop0->reg[MIPS_CP0_STATUS][1]) -#define kvm_write_c0_guest_intctl (cop0, val) (cop0->reg[MIPS_CP0_STATUS][1] = (val)) -#define kvm_read_c0_guest_cause (cop0) (cop0->reg[MIPS_CP0_CAUSE][0]) -#define kvm_write_c0_guest_cause (cop0, val) (cop0->reg[MIPS_CP0_CAUSE][0] = (val)) -#define kvm_read_c0_guest_epc (cop0) (cop0->reg[MIPS_CP0_EXC_PC][0]) -#define kvm_write_c0_guest_epc (cop0, val) (cop0->reg[MIPS_CP0_EXC_PC][0] = (val)) -#define kvm_read_c0_guest_prid (cop0) (cop0->reg[MIPS_CP0_PRID][0]) -#define kvm_write_c0_guest_prid (cop0, val) (cop0->reg[MIPS_CP0_PRID][0] = (val)) -#define kvm_read_c0_guest_ebase (cop0) (cop0->reg[MIPS_CP0_PRID][1]) -#define kvm_write_c0_guest_ebase (cop0, val) (cop0->reg[MIPS_CP0_PRID][1] = (val)) -#define kvm_read_c0_guest_config (cop0) (cop0->reg[MIPS_CP0_CONFIG][0]) -#define kvm_read_c0_guest_config1 (cop0) (cop0->reg[MIPS_CP0_CONFIG][1]) -#define kvm_read_c0_guest_config2 (cop0) (cop0->reg[MIPS_CP0_CONFIG][2]) -#define kvm_read_c0_guest_config3 (cop0) (cop0->reg[MIPS_CP0_CONFIG][3]) -#define kvm_read_c0_guest_config7 (cop0) (cop0->reg[MIPS_CP0_CONFIG][7]) -#define kvm_write_c0_guest_config (cop0, val) (cop0->reg[MIPS_CP0_CONFIG][0] = (val)) -#define kvm_write_c0_guest_config1 (cop0, val) (cop0->reg[MIPS_CP0_CONFIG][1] = (val)) -#define kvm_write_c0_guest_config2 (cop0, val) (cop0->reg[MIPS_CP0_CONFIG][2] = (val)) -#define kvm_write_c0_guest_config3 (cop0, val) (cop0->reg[MIPS_CP0_CONFIG][3] = (val)) -#define kvm_write_c0_guest_config7 (cop0, val) (cop0->reg[MIPS_CP0_CONFIG][7] = (val)) -#define kvm_read_c0_guest_errorepc (cop0) (cop0->reg[MIPS_CP0_ERROR_PC][0]) -#define kvm_write_c0_guest_errorepc (cop0, val) (cop0->reg[MIPS_CP0_ERROR_PC][0] = (val)) - -#define kvm_set_c0_guest_status (cop0, val) (cop0->reg[MIPS_CP0_STATUS][0] |= (val)) -#define kvm_clear_c0_guest_status (cop0, val) (cop0->reg[MIPS_CP0_STATUS][0] &= ~(val)) -#define kvm_set_c0_guest_cause (cop0, val) (cop0->reg[MIPS_CP0_CAUSE][0] |= (val)) -#define kvm_clear_c0_guest_cause (cop0, val) (cop0->reg[MIPS_CP0_CAUSE][0] &= ~(val)) -#define kvm_change_c0_guest_cause (cop0, change, val) \ -{ \ - kvm_clear_c0_guest_cause(cop0, change); \ - kvm_set_c0_guest_cause(cop0, ((val) & (change))); \ -} -#define kvm_set_c0_guest_ebase (cop0, val) (cop0->reg[MIPS_CP0_PRID][1] |= (val)) -#define kvm_clear_c0_guest_ebase (cop0, val) (cop0->reg[MIPS_CP0_PRID][1] &= ~(val)) -#define kvm_change_c0_guest_ebase (cop0, change, val) \ -{ \ - kvm_clear_c0_guest_ebase(cop0, change); \ - kvm_set_c0_guest_ebase(cop0, ((val) & (change))); \ -} - - -struct kvm_mips_callbacks { -int (*handle_cop_unusable) (struct kvm_vcpu *vcpu); -int (*handle_tlb_mod) (struct kvm_vcpu *vcpu); -int (*handle_tlb_ld_miss) (struct kvm_vcpu *vcpu); -int (*handle_tlb_st_miss) (struct kvm_vcpu *vcpu); -int (*handle_addr_err_st) (struct kvm_vcpu *vcpu); -int (*handle_addr_err_ld) (struct kvm_vcpu *vcpu); -int (*handle_syscall) (struct kvm_vcpu *vcpu); -int (*handle_res_inst) (struct kvm_vcpu *vcpu); -int (*handle_break) (struct kvm_vcpu *vcpu); -int (*vm_init) (struct kvm *kvm); -int (*vcpu_init) (struct kvm_vcpu *vcpu); -int (*vcpu_setup) (struct kvm_vcpu *vcpu); -gpa_t (*gva_to_gpa) (gva_t gva); -void (*queue_timer_int) (struct kvm_vcpu *vcpu); -void (*dequeue_timer_int) (struct kvm_vcpu *vcpu); -void (*queue_io_int) (struct kvm_vcpu *vcpu, -struct kvm_mips_interrupt *irq); -void (*dequeue_io_int) (struct kvm_vcpu *vcpu, -struct kvm_mips_interrupt *irq); -int (*irq_deliver) (struct kvm_vcpu *vcpu,unsigned int priority, -uint32_t cause); -int (*irq_clear) (struct kvm_vcpu *vcpu,unsigned int priority, -uint32_t cause); -}; -extern struct kvm_mips_callbacks *kvm_mips_callbacks; -int kvm_mips_emulation_init (struct kvm_mips_callbacks **install_callbacks); - -/* Debug: dump vcpu state */ -int kvm_arch_vcpu_dump_regs (struct kvm_vcpu *vcpu); - -/* Trampoline ASM routine to start running in "Guest" context */ -extern int __kvm_mips_vcpu_run (struct kvm_run *run,struct kvm_vcpu *vcpu); - -/* TLB handling */ -uint32_t kvm_get_kernel_asid (struct kvm_vcpu *vcpu); - -uint32_t kvm_get_user_asid (struct kvm_vcpu *vcpu); - -uint32_t kvm_get_commpage_asid (struct kvm_vcpu *vcpu); - -extern int kvm_mips_handle_kseg0_tlb_fault (unsigned long badbaddr, -struct kvm_vcpu *vcpu); - -extern int kvm_mips_handle_commpage_tlb_fault (unsigned long badvaddr, -struct kvm_vcpu *vcpu); - -extern int kvm_mips_handle_mapped_seg_tlb_fault (struct kvm_vcpu *vcpu, -struct kvm_mips_tlb *tlb, -unsigned long *hpa0, -unsigned long *hpa1); - -extern enum emulation_result kvm_mips_handle_tlbmiss (unsigned long cause, -uint32_t *opc, -struct kvm_run *run, -struct kvm_vcpu *vcpu); - -extern enum emulation_result kvm_mips_handle_tlbmod (unsigned long cause, -uint32_t *opc, -struct kvm_run *run, -struct kvm_vcpu *vcpu); - -extern void kvm_mips_dump_host_tlbs (void ); -extern void kvm_mips_dump_guest_tlbs (struct kvm_vcpu *vcpu); -extern void kvm_mips_dump_shadow_tlbs (struct kvm_vcpu *vcpu); -extern void kvm_mips_flush_host_tlb (int skip_kseg0); -extern int kvm_mips_host_tlb_inv (struct kvm_vcpu *vcpu,unsigned long entryhi); -extern int kvm_mips_host_tlb_inv_index (struct kvm_vcpu *vcpu,int index); - -extern int kvm_mips_guest_tlb_lookup (struct kvm_vcpu *vcpu, -unsigned long entryhi); -extern int kvm_mips_host_tlb_lookup (struct kvm_vcpu *vcpu,unsigned long vaddr); -extern unsigned long kvm_mips_translate_guest_kseg0_to_hpa (struct kvm_vcpu *vcpu, -unsigned long gva); -extern void kvm_get_new_mmu_context (struct mm_struct *mm,unsigned long cpu, -struct kvm_vcpu *vcpu); -extern void kvm_shadow_tlb_put (struct kvm_vcpu *vcpu); -extern void kvm_shadow_tlb_load (struct kvm_vcpu *vcpu); -extern void kvm_local_flush_tlb_all (void ); -extern void kvm_mips_init_shadow_tlb (struct kvm_vcpu *vcpu); -extern void kvm_mips_alloc_new_mmu_context (struct kvm_vcpu *vcpu); -extern void kvm_mips_vcpu_load (struct kvm_vcpu *vcpu,int cpu); -extern void kvm_mips_vcpu_put (struct kvm_vcpu *vcpu); - -/* Emulation */ -uint32_t kvm_get_inst (uint32_t *opc,struct kvm_vcpu *vcpu); -enum emulation_result update_pc (struct kvm_vcpu *vcpu,uint32_t cause); - -extern enum emulation_result kvm_mips_emulate_inst (unsigned long cause, -uint32_t *opc, -struct kvm_run *run, -struct kvm_vcpu *vcpu); - -extern enum emulation_result kvm_mips_emulate_syscall (unsigned long cause, -uint32_t *opc, -struct kvm_run *run, -struct kvm_vcpu *vcpu); - -extern enum emulation_result kvm_mips_emulate_tlbmiss_ld (unsigned long cause, -uint32_t *opc, -struct kvm_run *run, -struct kvm_vcpu *vcpu); - -extern enum emulation_result kvm_mips_emulate_tlbinv_ld (unsigned long cause, -uint32_t *opc, -struct kvm_run *run, -struct kvm_vcpu *vcpu); - -extern enum emulation_result kvm_mips_emulate_tlbmiss_st (unsigned long cause, -uint32_t *opc, -struct kvm_run *run, -struct kvm_vcpu *vcpu); - -extern enum emulation_result kvm_mips_emulate_tlbinv_st (unsigned long cause, -uint32_t *opc, -struct kvm_run *run, -struct kvm_vcpu *vcpu); - -extern enum emulation_result kvm_mips_emulate_tlbmod (unsigned long cause, -uint32_t *opc, -struct kvm_run *run, -struct kvm_vcpu *vcpu); - -extern enum emulation_result kvm_mips_emulate_fpu_exc (unsigned long cause, -uint32_t *opc, -struct kvm_run *run, -struct kvm_vcpu *vcpu); - -extern enum emulation_result kvm_mips_handle_ri (unsigned long cause, -uint32_t *opc, -struct kvm_run *run, -struct kvm_vcpu *vcpu); - -extern enum emulation_result kvm_mips_emulate_ri_exc (unsigned long cause, -uint32_t *opc, -struct kvm_run *run, -struct kvm_vcpu *vcpu); - -extern enum emulation_result kvm_mips_emulate_bp_exc (unsigned long cause, -uint32_t *opc, -struct kvm_run *run, -struct kvm_vcpu *vcpu); - -extern enum emulation_result kvm_mips_complete_mmio_load (struct kvm_vcpu *vcpu, -struct kvm_run *run); - -enum emulation_result kvm_mips_emulate_count (struct kvm_vcpu *vcpu); - -enum emulation_result kvm_mips_check_privilege (unsigned long cause, -uint32_t *opc, -struct kvm_run *run, -struct kvm_vcpu *vcpu); - -enum emulation_result kvm_mips_emulate_cache (uint32_t inst, -uint32_t *opc, -uint32_t cause, -struct kvm_run *run, -struct kvm_vcpu *vcpu); -enum emulation_result kvm_mips_emulate_CP0 (uint32_t inst, -uint32_t *opc, -uint32_t cause, -struct kvm_run *run, -struct kvm_vcpu *vcpu); -enum emulation_result kvm_mips_emulate_store (uint32_t inst, -uint32_t cause, -struct kvm_run *run, -struct kvm_vcpu *vcpu); -enum emulation_result kvm_mips_emulate_load (uint32_t inst, -uint32_t cause, -struct kvm_run *run, -struct kvm_vcpu *vcpu); - -/* Dynamic binary translation */ -extern int kvm_mips_trans_cache_index (uint32_t inst,uint32_t *opc, -struct kvm_vcpu *vcpu); -extern int kvm_mips_trans_cache_va (uint32_t inst,uint32_t *opc, -struct kvm_vcpu *vcpu); -extern int kvm_mips_trans_mfc0 (uint32_t inst,uint32_t *opc, -struct kvm_vcpu *vcpu); -extern int kvm_mips_trans_mtc0 (uint32_t inst,uint32_t *opc, -struct kvm_vcpu *vcpu); - -/* Misc */ -extern void mips32_SyncICache (unsigned long addr,unsigned long size); -extern int kvm_mips_dump_stats (struct kvm_vcpu *vcpu); -extern unsigned long kvm_mips_get_ramsize (struct kvm *kvm); - -#endif /* __MIPS_KVM_HOST_H__ */
arch/mips/include/asm/kvm_mips_te.h new file +589 -0
589 lines not on this page · raw message
arch/mips/kernel/asm-offsets.c +51 -49
122 lines not on this page · raw message
arch/mips/kvm/kvm_locore.S +23 -24
151 lines not on this page · raw message
arch/mips/kvm/kvm_mips.c +39 -670
853 lines not on this page · raw message
arch/mips/kvm/kvm_mips_comm.h +1 -0
@@ -11,6 +11,7 @@ #ifndef __KVM_MIPS_COMMPAGE_H__ #define __KVM_MIPS_COMMPAGE_H__ +#include <asm/kvm_mips_te.h> struct kvm_mips_commpage { struct mips_coproc cop0; /* COP0 state is mapped into Guest kernel via commpage */
arch/mips/kvm/kvm_mips_commpage.c +6 -3
@@ -22,16 +22,19 @@#include <linux/kvm_host.h> +#include <asm/kvm_mips_te.h> +#include "kvm_mips_comm.h" void kvm_mips_commpage_init (struct kvm_vcpu *vcpu) { -struct kvm_mips_commpage *page = vcpu->arch.kseg0_commpage; +struct kvm_mips_vcpu_te *vcpu_te = vcpu->arch.impl; +struct kvm_mips_commpage *page = vcpu_te->kseg0_commpage;memset (page,0 ,sizeof (struct kvm_mips_commpage ));/* Specific init values for fields */ - vcpu->arch.cop0 = &page->cop0; -memset (vcpu->arch.cop0,0 ,sizeof (struct mips_coproc )); + vcpu_te->cop0 = &page->cop0; +memset (vcpu_te->cop0,0 ,sizeof (struct mips_coproc ));return ; }
arch/mips/kvm/kvm_mips_emul.c +98 -74
528 lines not on this page · raw message
arch/mips/kvm/kvm_mips_int.c +28 -17
88 lines not on this page · raw message
arch/mips/kvm/kvm_tlb.c +74 -64
138 lines not on this page · raw message
arch/mips/kvm/kvm_trap_emul.c +866 -46
912 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.11.7
Part of the diff is not shown here. View the raw message.
PATCH 10/31 mips/kvm: Implement ioctls to get and set FPU registers.
In reply to David DaneyFrom: David Daney <[email protected]>
The current implementation does nothing with them, but future MIPSVZ work need them. Also add the asm-offsets accessors for the fields.
--- arch/mips/include/asm/kvm_host.h | 8 ++++++++ arch/mips/kernel/asm-offsets.c | 8 ++++++++ arch/mips/kvm/kvm_mips.c | 26 ++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-)
arch/mips/include/asm/kvm_host.h +8 -0
@@ -102,6 +102,14 @@ struct kvm_vcpu_arch {unsigned long lo;unsigned long epc; +/* FPU state */ +u64 fpr[32 ]; +u32 fir; +u32 fccr; +u32 fexr; +u32 fenr; +u32 fcsr; +void *impl; };
arch/mips/kernel/asm-offsets.c +8 -0
@@ -377,6 +377,14 @@ void output_kvm_defines(void)OFFSET (KVM_VCPU_ARCH_HI , kvm_vcpu, arch.hi);OFFSET (KVM_VCPU_ARCH_EPC , kvm_vcpu, arch.epc);OFFSET (KVM_VCPU_ARCH_IMPL , kvm_vcpu, arch.impl); +BLANK (); +OFFSET (KVM_VCPU_ARCH_FPR , kvm_vcpu, arch.fpr); +OFFSET (KVM_VCPU_ARCH_FIR , kvm_vcpu, arch.fir); +OFFSET (KVM_VCPU_ARCH_FCCR , kvm_vcpu, arch.fccr); +OFFSET (KVM_VCPU_ARCH_FEXR , kvm_vcpu, arch.fexr); +OFFSET (KVM_VCPU_ARCH_FENR , kvm_vcpu, arch.fenr); +OFFSET (KVM_VCPU_ARCH_FCSR , kvm_vcpu, arch.fcsr); +BLANK ();OFFSET (KVM_MIPS_VCPU_TE_HOST_EBASE , kvm_mips_vcpu_te, host_ebase);OFFSET (KVM_MIPS_VCPU_TE_GUEST_EBASE , kvm_mips_vcpu_te, guest_ebase);
arch/mips/kvm/kvm_mips.c +24 -2
@@ -465,12 +465,34 @@ int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)int kvm_arch_vcpu_ioctl_get_fpu (struct kvm_vcpu *vcpu,struct kvm_fpu *fpu) { -return -ENOIOCTLCMD ; +int i; + +for (i =0 ; i <ARRAY_SIZE (vcpu->arch.fpr); i++) + fpu->fpr[i] = vcpu->arch.fpr[i]; + + fpu->fir = vcpu->arch.fir; + fpu->fccr = vcpu->arch.fccr; + fpu->fexr = vcpu->arch.fexr; + fpu->fenr = vcpu->arch.fenr; + fpu->fcsr = vcpu->arch.fcsr; + +return 0 ; }int kvm_arch_vcpu_ioctl_set_fpu (struct kvm_vcpu *vcpu,struct kvm_fpu *fpu) { -return -ENOIOCTLCMD ; +int i; + +for (i =0 ; i <ARRAY_SIZE (vcpu->arch.fpr); i++) + vcpu->arch.fpr[i] = fpu->fpr[i]; + + vcpu->arch.fir = fpu->fir; + vcpu->arch.fccr = fpu->fccr; + vcpu->arch.fexr = fpu->fexr; + vcpu->arch.fenr = fpu->fenr; + vcpu->arch.fcsr = fpu->fcsr; + +return 0 ; }int kvm_arch_vcpu_fault (struct kvm_vcpu *vcpu,struct vm_fault *vmf)
Signature · 1 line
1.7.11.7
PATCH 11/31 MIPS: Rearrange branch.c so it can be used by kvm code.
In reply to David DaneyFrom: David Daney <[email protected]>
Introduce __compute_return_epc_for_insn0() entry point.
--- arch/mips/include/asm/branch.h | 7 +++++ arch/mips/kernel/branch.c | 63 +++++++++++++++++++++++++++++++----------- 2 files changed, 54 insertions(+), 16 deletions(-)
arch/mips/include/asm/branch.h +7 -0
@@ -37,6 +37,13 @@ static inline unsigned long exception_epc(struct pt_regs *regs)#define BRANCH_LIKELY_TAKEN 0x0001 +extern int __compute_return_epc (struct pt_regs *regs); +extern int __compute_return_epc_for_insn (struct pt_regs *regs, +union mips_instruction insn); +extern int __compute_return_epc_for_insn0 (struct pt_regs *regs, +union mips_instruction insn, +unsigned int (*get_fcr31)(void )); +static inline int compute_return_epc (struct pt_regs *regs) {if (get_isa16_mode (regs->cp0_epc)) {
arch/mips/kernel/branch.c +47 -16
95 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 12/31 MIPS: Add instruction format information for WAIT, MTC0, MFC0, et al.
In reply to David DaneyFrom: David Daney <[email protected]>
--- arch/mips/include/uapi/asm/inst.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
arch/mips/include/uapi/asm/inst.h +22 -1
@@ -117,7 +117,8 @@ enum bcop_op {enum cop0_coi_func { tlbr_op =0x01 , tlbwi_op =0x02 , tlbwr_op =0x06 , tlbp_op =0x08 , - rfe_op =0x10 , eret_op =0x18 + rfe_op =0x10 , eret_op =0x18 , + wait_op =0x20 };/*
@@ -567,6 +568,24 @@ struct b_format { /* BREAK and SYSCALL */ ;))) }; +struct c0_format { /* WAIT, TLB?? */ + BITFIELD_FIELD(unsigned int opcode : 6, + BITFIELD_FIELD(unsigned int co : 1, + BITFIELD_FIELD(unsigned int code : 19, + BITFIELD_FIELD(unsigned int func : 6, + ;)))) +}; + +struct c0m_format { /* MTC0, MFC0, ... */ + BITFIELD_FIELD(unsigned int opcode : 6, + BITFIELD_FIELD(unsigned int func : 5, + BITFIELD_FIELD(unsigned int rt : 5, + BITFIELD_FIELD(unsigned int rd : 5, + BITFIELD_FIELD(unsigned int code : 8, + BITFIELD_FIELD(unsigned int sel : 3, + ;)))))) +}; + struct ps_format { /* MIPS-3D / paired single format */ BITFIELD_FIELD(unsigned int opcode : 6, BITFIELD_FIELD(unsigned int rs : 5,
@@ -857,6 +876,8 @@ union mips_instruction {struct f_format f_format;struct ma_format ma_format;struct b_format b_format; +struct c0_format c0_format; +struct c0m_format c0m_format;struct ps_format ps_format;struct v_format v_format;struct fb_format fb_format;
Signature · 1 line
1.7.11.7
PATCH 13/31 mips/kvm: Add accessors for MIPS VZ registers.
In reply to David DaneyFrom: David Daney <[email protected]>
There are accessors for both the guest control registers as well as guest CP0 context.
--- arch/mips/include/asm/mipsregs.h | 260 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 260 insertions(+)
arch/mips/include/asm/mipsregs.h +260 -0
@@ -50,10 +50,13 @@#define CP0_WIRED $6#define CP0_INFO $7#define CP0_BADVADDR $8 +#define CP0_BADINSTR $8, 1 +#define CP0_BADINSTRP $8, 2#define CP0_COUNT $9#define CP0_ENTRYHI $10#define CP0_COMPARE $11#define CP0_STATUS $12 +#define CP0_GUESTCTL0 $12, 6#define CP0_CAUSE $13#define CP0_EPC $14#define CP0_PRID $15
@@ -623,6 +626,10 @@#define MIPS_FPIR_L (_ULCAST_(1) << 21)#define MIPS_FPIR_F64 (_ULCAST_(1) << 22) +/* Bits in the MIPS VZ GuestCtl0 Register */ +#define MIPS_GUESTCTL0B_GM 31 +#define MIPS_GUESTCTL0F_GM (_ULCAST_(1) << MIPS_GUESTCTL0B_GM) +#ifndef __ASSEMBLY__/*
@@ -851,6 +858,144 @@ do { \local_irq_restore (__flags); \ }while (0 ) +/* +* Macros to access the VZ Guest system control coprocessor + */ + +#define __read_32bit_gc0_register (source, sel) \ + ({ int __res; \ + __asm__ __volatile__( \ + ".set mips64r2\n\t" \ + ".set\tvirt\n\t" \ + ".ifeq 0-" #sel "\n\t" \ + "mfgc0\t%0, " #source ", 0\n\t" \ + ".endif\n\t" \ + ".ifeq 1-" #sel "\n\t" \ + "mfgc0\t%0, " #source ", 1\n\t" \ + ".endif\n\t" \ + ".ifeq 2-" #sel "\n\t" \ + "mfgc0\t%0, " #source ", 2\n\t" \ + ".endif\n\t" \ + ".ifeq 3-" #sel "\n\t" \ + "mfgc0\t%0, " #source ", 3\n\t" \ + ".endif\n\t" \ + ".ifeq 4-" #sel "\n\t" \ + "mfgc0\t%0, " #source ", 4\n\t" \ + ".endif\n\t" \ + ".ifeq 5-" #sel "\n\t" \ + "mfgc0\t%0, " #source ", 5\n\t" \ + ".endif\n\t" \ + ".ifeq 6-" #sel "\n\t" \ + "mfgc0\t%0, " #source ", 6\n\t" \ + ".endif\n\t" \ + ".ifeq 7-" #sel "\n\t" \ + "mfgc0\t%0, " #source ", 7\n\t" \ + ".endif\n\t" \ + ".set\tmips0" \ + : "=r" (__res)); \ + __res; \ +}) + +#define __read_64bit_gc0_register (source, sel) \ + ({ unsigned long long __res; \ + __asm__ __volatile__( \ + ".set mips64r2\n\t" \ + ".set\tvirt\n\t" \ + ".ifeq 0-" #sel "\n\t" \ + "dmfgc0\t%0, " #source ", 0\n\t" \ + ".endif\n\t" \ + ".ifeq 1-" #sel "\n\t" \ + "dmfgc0\t%0, " #source ", 1\n\t" \ + ".endif\n\t" \ + ".ifeq 2-" #sel "\n\t" \ + "dmfgc0\t%0, " #source ", 2\n\t" \ + ".endif\n\t" \ + ".ifeq 3-" #sel "\n\t" \ + "dmfgc0\t%0, " #source ", 3\n\t" \ + ".endif\n\t" \ + ".ifeq 4-" #sel "\n\t" \ + "dmfgc0\t%0, " #source ", 4\n\t" \ + ".endif\n\t" \ + ".ifeq 5-" #sel "\n\t" \ + "dmfgc0\t%0, " #source ", 5\n\t" \ + ".endif\n\t" \ + ".ifeq 6-" #sel "\n\t" \ + "dmfgc0\t%0, " #source ", 6\n\t" \ + ".endif\n\t" \ + ".ifeq 7-" #sel "\n\t" \ + "dmfgc0\t%0, " #source ", 7\n\t" \ + ".endif\n\t" \ + ".set\tmips0" \ + : "=r" (__res)); \ + __res; \ +}) + +#define __write_32bit_gc0_register (source, sel, value) \ +do { \ + __asm__ __volatile__( \ + ".set mips64r2\n\t" \ + ".set\tvirt\n\t" \ + ".ifeq 0-" #sel "\n\t" \ + "mtgc0\t%z0, " #source ", 0\n\t" \ + ".endif\n\t" \ + ".ifeq 1-" #sel "\n\t" \ + "mtgc0\t%z0, " #source ", 1\n\t" \ + ".endif\n\t" \ + ".ifeq 2-" #sel "\n\t" \ + "mtgc0\t%z0, " #source ", 2\n\t" \ + ".endif\n\t" \ + ".ifeq 3-" #sel "\n\t" \ + "mtgc0\t%z0, " #source ", 3\n\t" \ + ".endif\n\t" \ + ".ifeq 4-" #sel "\n\t" \ + "mtgc0\t%z0, " #source ", 4\n\t" \ + ".endif\n\t" \ + ".ifeq 5-" #sel "\n\t" \ + "mtgc0\t%z0, " #source ", 5\n\t" \ + ".endif\n\t" \ + ".ifeq 6-" #sel "\n\t" \ + "mtgc0\t%z0, " #source ", 6\n\t" \ + ".endif\n\t" \ + ".ifeq 7-" #sel "\n\t" \ + "mtgc0\t%z0, " #source ", 7\n\t" \ + ".endif\n\t" \ + ".set\tmips0" \ + : : "Jr" ((unsigned int)(value))); \ +} while (0) + +#define __write_64bit_gc0_register (source, sel, value) \ +do { \ + __asm__ __volatile__( \ + ".set mips64r2\n\t" \ + ".set\tvirt\n\t" \ + ".ifeq 0-" #sel "\n\t" \ + "dmtgc0\t%z0, " #source ", 0\n\t" \ + ".endif\n\t" \ + ".ifeq 1-" #sel "\n\t" \ + "dmtgc0\t%z0, " #source ", 1\n\t" \ + ".endif\n\t" \ + ".ifeq 2-" #sel "\n\t" \ + "dmtgc0\t%z0, " #source ", 2\n\t" \ + ".endif\n\t" \ + ".ifeq 3-" #sel "\n\t" \ + "dmtgc0\t%z0, " #source ", 3\n\t" \ + ".endif\n\t" \ + ".ifeq 4-" #sel "\n\t" \ + "dmtgc0\t%z0, " #source ", 4\n\t" \ + ".endif\n\t" \ + ".ifeq 5-" #sel "\n\t" \ + "dmtgc0\t%z0, " #source ", 5\n\t" \ + ".endif\n\t" \ + ".ifeq 6-" #sel "\n\t" \ + "dmtgc0\t%z0, " #source ", 6\n\t" \ + ".endif\n\t" \ + ".ifeq 7-" #sel "\n\t" \ + "dmtgc0\t%z0, " #source ", 7\n\t" \ + ".endif\n\t" \ + ".set\tmips0" \ + : : "Jr" (value)); \ +} while (0) +#define read_c0_index () __read_32bit_c0_register($0, 0)#define write_c0_index (val) __write_32bit_c0_register($0, 0, val)
@@ -889,6 +1034,12 @@ do { \#define read_c0_badvaddr () __read_ulong_c0_register($8, 0)#define write_c0_badvaddr (val) __write_ulong_c0_register($8, 0, val) +#define read_c0_badinstr () __read_32bit_c0_register($8, 1) +#define write_c0_badinstr (val) __write_32bit_c0_register($8, 1, val) + +#define read_c0_badinstrp () __read_32bit_c0_register($8, 2) +#define write_c0_badinstrp (val) __write_32bit_c0_register($8, 2, val) +#define read_c0_count () __read_32bit_c0_register($9, 0)#define write_c0_count (val) __write_32bit_c0_register($9, 0, val)
@@ -1162,6 +1313,93 @@ do { \#define read_c0_brcm_sleepcount () __read_32bit_c0_register($22, 7)#define write_c0_brcm_sleepcount (val) __write_32bit_c0_register($22, 7, val) +/* MIPS VZ */ +#define read_c0_guestctl0 () __read_32bit_c0_register($12, 6) +#define write_c0_guestctl0 (val) __write_32bit_c0_register($12, 6, val) + +#define read_c0_guestctl1 () __read_32bit_c0_register($10, 4) +#define write_c0_guestctl1 (val) __write_32bit_c0_register($10, 4, val) + +#define read_c0_guestctl2 () __read_32bit_c0_register($10, 5) +#define write_c0_guestctl2 (val) __write_32bit_c0_register($10, 5, val) + +#define read_c0_guestctl3 () __read_32bit_c0_register($10, 6) +#define write_c0_guestctl3 (val) __write_32bit_c0_register($10, 6, val) + +#define read_c0_gtoffset () __read_32bit_c0_register($12, 7) +#define write_c0_gtoffset (val) __write_32bit_c0_register($12, 7, val) + +#define read_gc0_index () __read_32bit_gc0_register($0, 0) +#define write_gc0_index (val) __write_32bit_gc0_register($0, 0, val) + +#define read_gc0_entrylo0 () __read_64bit_gc0_register($2, 0) +#define write_gc0_entrylo0 (val) __write_64bit_gc0_register($2, 0, val) + +#define read_gc0_entrylo1 () __read_64bit_gc0_register($3, 0) +#define write_gc0_entrylo1 (val) __write_64bit_gc0_register($3, 0, val) + +#define read_gc0_context () __read_64bit_gc0_register($4, 0) +#define write_gc0_context (val) __write_64bit_gc0_register($4, 0, val) + +#define read_gc0_userlocal () __read_64bit_gc0_register($4, 2) +#define write_gc0_userlocal (val) __write_64bit_gc0_register($4, 2, val) + +#define read_gc0_pagemask () __read_32bit_gc0_register($5, 0) +#define write_gc0_pagemask (val) __write_32bit_gc0_register($5, 0, val) + +#define read_gc0_pagegrain () __read_32bit_gc0_register($5, 1) +#define write_gc0_pagegrain (val) __write_32bit_gc0_register($5, 1, val) + +#define read_gc0_wired () __read_32bit_gc0_register($6, 0) +#define write_gc0_wired (val) __write_32bit_gc0_register($6, 0, val) + +#define read_gc0_hwrena () __read_32bit_gc0_register($7, 0) +#define write_gc0_hwrena (val) __write_32bit_gc0_register($7, 0, val) + +#define read_gc0_badvaddr () __read_64bit_gc0_register($8, 0) +#define write_gc0_badvaddr (val) __write_64bit_gc0_register($8, 0, val) + +#define read_gc0_count () __read_32bit_gc0_register($9, 0) +/* Not possible to write gc0_count. */ + +#define read_gc0_entryhi () __read_64bit_gc0_register($10, 0) +#define write_gc0_entryhi (val) __write_64bit_gc0_register($10, 0, val) + +#define read_gc0_compare () __read_32bit_gc0_register($11, 0) +#define write_gc0_compare (val) __write_32bit_gc0_register($11, 0, val) + +#define read_gc0_status () __read_32bit_gc0_register($12, 0) +#define write_gc0_status (val) __write_32bit_gc0_register($12, 0, val) + +#define read_gc0_cause () __read_32bit_gc0_register($13, 0) +#define write_gc0_cause (val) __write_32bit_gc0_register($13, 0, val) + +#define read_gc0_ebase () __read_64bit_gc0_register($15, 1) +#define write_gc0_ebase (val) __write_64bit_gc0_register($15, 1, val) + +#define read_gc0_config () __read_32bit_gc0_register($16, 0) +#define read_gc0_config1 () __read_32bit_gc0_register($16, 1) +#define read_gc0_config2 () __read_32bit_gc0_register($16, 2) +#define read_gc0_config3 () __read_32bit_gc0_register($16, 3) +#define read_gc0_config4 () __read_32bit_gc0_register($16, 4) +#define read_gc0_config5 () __read_32bit_gc0_register($16, 5) +#define read_gc0_config6 () __read_32bit_gc0_register($16, 6) +#define read_gc0_config7 () __read_32bit_gc0_register($16, 7) +#define write_gc0_config (val) __write_32bit_gc0_register($16, 0, val) +#define write_gc0_config1 (val) __write_32bit_gc0_register($16, 1, val) +#define write_gc0_config2 (val) __write_32bit_gc0_register($16, 2, val) +#define write_gc0_config3 (val) __write_32bit_gc0_register($16, 3, val) +#define write_gc0_config4 (val) __write_32bit_gc0_register($16, 4, val) +#define write_gc0_config5 (val) __write_32bit_gc0_register($16, 5, val) +#define write_gc0_config6 (val) __write_32bit_gc0_register($16, 6, val) +#define write_gc0_config7 (val) __write_32bit_gc0_register($16, 7, val) + +#define read_gc0_xcontext () __read_64bit_gc0_register($20, 0) +#define write_gc0_xcontext (val) __write_64bit_gc0_register($20, 0, val) + +#define read_gc0_kscratch (idx) __read_64bit_gc0_register($31, (idx)) +#define write_gc0_kscratch (idx, val) __write_64bit_gc0_register($31, (idx), val) +/* * Macros to access the floating point coprocessor control registers */
@@ -1633,6 +1871,28 @@ static inline void tlb_write_random(void) ".set reorder"); } +static inline void guest_tlb_write_indexed (void ) +{ + __asm__ __volatile__( +".set push\n\t" +".set mips64r2\n\t" +".set virt\n\t" +".set noreorder\n\t" +"tlbgwi\n\t" +".set pop" ); +} + +static inline void guest_tlb_read (void ) +{ + __asm__ __volatile__( +".set push\n\t" +".set mips64r2\n\t" +".set virt\n\t" +".set noreorder\n\t" +"tlbgr\n\t" +".set pop" ); +} +/* * Manipulate bits in a c0 register. */
Signature · 1 line
1.7.11.7
PATCH 14/31 mips/kvm: Add thread_info flag to indicate operation in MIPS VZ Guest Mode.
In reply to David DaneyFrom: David Daney <[email protected]>
--- arch/mips/include/asm/thread_info.h | 2 ++ 1 file changed, 2 insertions(+)
arch/mips/include/asm/thread_info.h +2 -0
@@ -109,6 +109,7 @@ static inline struct thread_info *current_thread_info(void)#define TIF_RESTORE_SIGMASK 9/* restore signal mask in do_signal() */ #define TIF_USEDFPU 16/* FPU was used by this task this quantum (SMP) */ #define TIF_MEMDIE 18/* is terminating due to OOM killer */ +#define TIF_GUESTMODE 19/* If set, running in VZ Guest mode. */ #define TIF_FIXADE 20/* Fix address errors in software */ #define TIF_LOGADE 21/* Log address errors to syslog */ #define TIF_32BIT_REGS 22/* also implies 16/32 fprs */
@@ -124,6 +125,7 @@ static inline struct thread_info *current_thread_info(void)#define _TIF_SECCOMP (1<<TIF_SECCOMP)#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)#define _TIF_USEDFPU (1<<TIF_USEDFPU) +#define _TIF_GUESTMODE (1<<TIF_GUESTMODE)#define _TIF_FIXADE (1<<TIF_FIXADE)#define _TIF_LOGADE (1<<TIF_LOGADE)#define _TIF_32BIT_REGS (1<<TIF_32BIT_REGS)
Signature · 1 line
1.7.11.7
PATCH 15/31 mips/kvm: Exception handling to leave and reenter guest mode.
In reply to David DaneyFrom: David Daney <[email protected]>
Currently this is a little complex, here are the facts about how it works:
o When running in Guest mode we set the high bit of CP0_XCONTEXT. If this bit is clear, we don't do anything special on an exception.
o If we are in guest mode, upon an exception we:
1) load the stack pointer from the mips_kvm_rootsp array instead of kernelsp.
2) Clear GuestCtl[GM] and high bit of CP0_XCONTEXT.
3) Restore host ASID and PGD pointer.
o Upon restarting from an exception we test the task TIF_GUESTMODE flag if it is clear, nothing special is done.
o If Guest mode is active for the thread we:
1) Compare the stack pointer to mips_kvm_rootsp, if it doesn't match we are not reentering guest mode, so no more special processing is done.
2) If reentering guest mode:
2a) Set high bit of CP0_XCONTEXT and GuestCtl[GM].
2b) Set Guest mode ASID and PGD pointer.
This allows a single set of exception handlers to be used for both host and guest mode operation.
--- arch/mips/include/asm/stackframe.h | 135 ++++++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 3 deletions(-)
arch/mips/include/asm/stackframe.h +132 -3
@@ -17,6 +17,7 @@#include <asm/asmmacro.h> #include <asm/mipsregs.h> #include <asm/asm-offsets.h> +#include <asm/thread_info.h> /* * For SMTC kernel, global IE should be left set, and interrupts
@@ -98,7 +99,9 @@#define CPU_ID_REG CP0_CONTEXT#define CPU_ID_MFC0 MFC0#endif - .macro get_saved_sp /* SMP variation */ +#define CPU_ID_MASK ((1 << 13) - 1) + + .macro get_saved_sp_for_save_some /* SMP variation */ CPU_ID_MFC0 k0, CPU_ID_REG#if defined(CONFIG_32BIT ) || defined(KBUILD_64BIT_SYM32 ) lui k1, %hi(kernelsp)
@@ -110,15 +113,49 @@ dsll k1, 16#endif LONG_SRL k0, PTEBASE_SHIFT +#ifdef CONFIG_KVM_MIPSVZ +andi k0,CPU_ID_MASK /* high bits indicate guest mode. */ +#endif LONG_ADDU k1, k0 LONG_L k1, %lo(kernelsp)(k1) .endm + .macro get_saved_sp + CPU_ID_MFC0 k0, CPU_ID_REG + get_saved_sp_for_save_some + .endm + + .macro get_mips_kvm_rootsp /* SMP variation */ +#if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32) + lui k1, %hi(mips_kvm_rootsp) +#else + lui k1, %highest(mips_kvm_rootsp) + daddiu k1, %higher(mips_kvm_rootsp) + dsll k1, 16 + daddiu k1, %hi(mips_kvm_rootsp) + dsll k1, 16 +#endif + LONG_SRL k0, PTEBASE_SHIFT + andi k0, CPU_ID_MASK /* high bits indicate guest mode. */ + LONG_ADDU k1, k0 + LONG_L k1, %lo(mips_kvm_rootsp)(k1) + .endm + .macro set_saved_sp stackp temp temp2 CPU_ID_MFC0 \temp, CPU_ID_REG LONG_SRL \temp, PTEBASE_SHIFT +#ifdef CONFIG_KVM_MIPSVZ + andi k0, CPU_ID_MASK /* high bits indicate guest mode. */ +#endif LONG_S \stackp, kernelsp(\temp) .endm + + .macro set_mips_kvm_rootsp stackp temp + CPU_ID_MFC0 \temp, CPU_ID_REG + LONG_SRL \temp, PTEBASE_SHIFT + andi k0, CPU_ID_MASK /* high bits indicate guest mode. */ + LONG_S \stackp, mips_kvm_rootsp(\temp) + .endm #else .macro get_saved_sp /* Uniprocessor variation */ #ifdef CONFIG_CPU_JUMP_WORKAROUNDS
@@ -152,9 +189,27 @@ LONG_L k1, %lo(kernelsp)(k1) .endm + .macro get_mips_kvm_rootsp /* Uniprocessor variation */ +#if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32) + lui k1, %hi(mips_kvm_rootsp) +#else + lui k1, %highest(mips_kvm_rootsp) + daddiu k1, %higher(mips_kvm_rootsp) + dsll k1, k1, 16 + daddiu k1, %hi(mips_kvm_rootsp) + dsll k1, k1, 16 +#endif + LONG_L k1, %lo(mips_kvm_rootsp)(k1) + .endm + + .macro set_saved_sp stackp temp temp2 LONG_S \stackp, kernelsp .endm + + .macro set_mips_kvm_rootsp stackp temp + LONG_S \stackp, mips_kvm_rootsp + .endm #endif .macro SAVE_SOME
@@ -164,11 +219,21 @@mfc0 k0,CP0_STATUS sll k0, 3 /* extract cu0 bit */ .set noreorder +#ifdef CONFIG_KVM_MIPSVZ + bgez k0, 7f + CPU_ID_MFC0 k0, CPU_ID_REG + bgez k0, 8f + move k1, sp + get_mips_kvm_rootsp + b 8f + nop +#else bltz k0, 8f move k1, sp +#endif .set reorder /* Called from user mode, new stack. */ - get_saved_sp +7: get_saved_sp_for_save_some #ifndef CONFIG_CPU_DADDI_WORKAROUNDS 8: move k0, sp PTR_SUBU sp, k1, PT_SIZE
@@ -227,6 +292,35 @@ LONG_S $31, PT_R31(sp) ori $28, sp, _THREAD_MASK xori $28, _THREAD_MASK +#ifdef CONFIG_KVM_MIPSVZ + CPU_ID_MFC0 k0, CPU_ID_REG + .set noreorder + bgez k0, 8f +/* Must clear GuestCtl0[GM] */ + dins k0, zero, 63, 1 + .set reorder + dmtc0 k0, CPU_ID_REG + mfc0 k0, CP0_GUESTCTL0 + ins k0, zero, MIPS_GUESTCTL0B_GM, 1 + mtc0 k0, CP0_GUESTCTL0 + LONG_L v0, TI_TASK($28) + lw v1, THREAD_MM_ASID(v0) + dmtc0 v1, CP0_ENTRYHI + LONG_L v1, TASK_MM(v0) + .set noreorder + jal tlbmiss_handler_setup_pgd_array + LONG_L a0, MM_PGD(v1) + .set reorder + /* + * With KVM_MIPSVZ, we must not clobber k0/k1 + * they were saved before they were used + */ +8: + MFC0 k0, CP0_KSCRATCH1 + MFC0 v1, CP0_KSCRATCH2 + LONG_S k0, PT_R26(sp) + LONG_S v1, PT_R27(sp) +#endif #ifdef CONFIG_CPU_CAVIUM_OCTEON .set mips64 pref 0, 0($28) /* Prefetch the current pointer */
@@ -439,10 +533,45 @@ .set mips0#endif /* CONFIG_MIPS_MT_SMTC */ LONG_L v1, PT_EPC(sp) + LONG_L $25, PT_R25(sp) MTC0 v1, CP0_EPC +#ifdef CONFIG_KVM_MIPSVZ + /* + * Only if TIF_GUESTMODE && sp is the saved KVM sp, return to + * guest mode. + */ + LONG_L v0, TI_FLAGS($28) + li k1, _TIF_GUESTMODE + and v0, v0, k1 + beqz v0, 8f + CPU_ID_MFC0 k0, CPU_ID_REG + get_mips_kvm_rootsp + PTR_SUBU k1, k1, PT_SIZE + bne k1, sp, 8f +/* Set the high order bit of CPU_ID_REG to indicate guest mode. */ + dli v0, 1 + dmfc0 v1, CPU_ID_REG + dins v1, v0, 63, 1 + dmtc0 v1, CPU_ID_REG +/* Must set GuestCtl0[GM] */ + mfc0 v1, CP0_GUESTCTL0 + ins v1, v0, MIPS_GUESTCTL0B_GM, 1 + mtc0 v1, CP0_GUESTCTL0 + + LONG_L v0, TI_TASK($28) + lw v1, THREAD_GUEST_ASID(v0) + dmtc0 v1, CP0_ENTRYHI + LONG_L v1, THREAD_VCPU(v0) + LONG_L v1, KVM_VCPU_KVM(v1) + LONG_L v1, KVM_ARCH_IMPL(v1) + .set noreorder + jal tlbmiss_handler_setup_pgd_array + LONG_L a0, KVM_MIPS_VZ_PGD(v1) + .set reorder +8: +#endif LONG_L $31, PT_R31(sp) LONG_L $28, PT_R28(sp) - LONG_L $25, PT_R25(sp)#ifdef CONFIG_64BIT LONG_L $8, PT_R8(sp) LONG_L $9, PT_R9(sp)
Signature · 1 line
1.7.11.7
PATCH 16/31 mips/kvm: Add exception handler for MIPSVZ Guest exceptions.
In reply to David DaneyFrom: David Daney <[email protected]>
--- arch/mips/kernel/genex.S | 3 +++ 1 file changed, 3 insertions(+)
arch/mips/kernel/genex.S +3 -0
@@ -486,6 +486,9 @@ NESTED(nmi_handler, PT_SIZE, sp) BUILD_HANDLER mcheck mcheck cli verbose /* #24 */ BUILD_HANDLER mt mt sti silent /* #25 */ BUILD_HANDLER dsp dsp sti silent /* #26 */ +#ifdef CONFIG_KVM_MIPSVZ + BUILD_HANDLER hypervisor hypervisor cli silent /* #27 */ +#endif BUILD_HANDLER reserved reserved sti verbose /* others */ .align 5
Signature · 1 line
1.7.11.7
PATCH 17/31 MIPS: Quit exposing Kconfig symbols in uapi headers.
In reply to David DaneyFrom: David Daney <[email protected]>
The kernel's struct pt_regs has many fields conditional on various Kconfig variables, we cannot be exporting this garbage to user-space.
Move the kernel's definition to asm/ptrace.h, and put a uapi only version in uapi/asm/ptrace.h gated by #ifndef __KERNEL__
--- arch/mips/include/asm/ptrace.h | 32 ++++++++++++++++++++++++++++++++ arch/mips/include/uapi/asm/ptrace.h | 17 ++--------------- 2 files changed, 34 insertions(+), 15 deletions(-)
arch/mips/include/asm/ptrace.h +32 -0
@@ -16,6 +16,38 @@#include <asm/isadep.h> #include <uapi/asm/ptrace.h> +/* +* This struct defines the way the registers are stored on the stack during a +* system call/exception. As usual the registers k0/k1 aren't being saved. +*/ +struct pt_regs { +#ifdef CONFIG_32BIT +/* Pad bytes for argument save space on the stack. */ +unsigned long pad0[6 ]; +#endif + +/* Saved main processor registers. */ +unsigned long regs[32 ]; + +/* Saved special registers. */ +unsigned long cp0_status; +unsigned long hi; +unsigned long lo; +#ifdef CONFIG_CPU_HAS_SMARTMIPS +unsigned long acx; +#endif +unsigned long cp0_badvaddr; +unsigned long cp0_cause; +unsigned long cp0_epc; +#ifdef CONFIG_MIPS_MT_SMTC +unsigned long cp0_tcstatus; +#endif /* CONFIG_MIPS_MT_SMTC */ +#ifdef CONFIG_CPU_CAVIUM_OCTEON +unsigned long long mpl[3 ];/* MTM{0,1,2} */ +unsigned long long mtp[3 ];/* MTP{0,1,2} */ +#endif +}__aligned(8) ; +struct task_struct ;extern int ptrace_getregs (struct task_struct *child,__s64 __user *data);
arch/mips/include/uapi/asm/ptrace.h +2 -15
@@ -22,16 +22,12 @@#define DSP_CONTROL 77#define ACX 78 +#ifndef __KERNEL__ /* * This struct defines the way the registers are stored on the stack during a * system call/exception. As usual the registers k0/k1 aren't being saved. */ struct pt_regs { -#ifdef CONFIG_32BIT -/* Pad bytes for argument save space on the stack. */ -unsigned long pad0[6 ]; -#endif - /* Saved main processor registers. */ unsigned long regs[32];
@@ -39,20 +35,11 @@ struct pt_regs {unsigned long cp0_status;unsigned long hi;unsigned long lo; -#ifdef CONFIG_CPU_HAS_SMARTMIPS -unsigned long acx; -#endif unsigned long cp0_badvaddr;unsigned long cp0_cause;unsigned long cp0_epc; -#ifdef CONFIG_MIPS_MT_SMTC -unsigned long cp0_tcstatus; -#endif /* CONFIG_MIPS_MT_SMTC */ -#ifdef CONFIG_CPU_CAVIUM_OCTEON -unsigned long long mpl[3 ];/* MTM{0,1,2} */ -unsigned long long mtp[3 ];/* MTP{0,1,2} */ -#endif } __attribute__ ((aligned (8))); +#endif /* __KERNEL__ */ /* Arbitrarily choose the same ptrace numbers as used by the Sparc code. */ #define PTRACE_GETREGS 12
Signature · 1 line
1.7.11.7
PATCH 18/31 mips/kvm: Add pt_regs slots for BadInstr and BadInstrP
In reply to David DaneyFrom: David Daney <[email protected]>
These save the instruction word to be used by MIPSVZ code for instruction emulation.
--- arch/mips/include/asm/ptrace.h | 4 ++++ arch/mips/kernel/asm-offsets.c | 4 ++++ 2 files changed, 8 insertions(+)
arch/mips/include/asm/ptrace.h +4 -0
@@ -46,6 +46,10 @@ struct pt_regs {unsigned long long mpl[3 ];/* MTM{0,1,2} */ unsigned long long mtp[3 ];/* MTP{0,1,2} */ #endif +#ifdef CONFIG_KVM_MIPSVZ +unsigned int cp0_badinstr;/* Only populated on do_page_fault_{0,1} */ +unsigned int cp0_badinstrp;/* Only populated on do_page_fault_{0,1} */ +#endif }__aligned(8) ;struct task_struct ;
arch/mips/kernel/asm-offsets.c +4 -0
@@ -71,6 +71,10 @@ void output_ptreg_defines(void)OFFSET (PT_MPL , pt_regs, mpl);OFFSET (PT_MTP , pt_regs, mtp);#endif /* CONFIG_CPU_CAVIUM_OCTEON */ +#ifdef CONFIG_KVM_MIPSVZ +OFFSET (PT_BADINSTR , pt_regs, cp0_badinstr); +OFFSET (PT_BADINSTRP , pt_regs, cp0_badinstrp); +#endif DEFINE (PT_SIZE ,sizeof (struct pt_regs ));BLANK (); }
Signature · 1 line
1.7.11.7
PATCH 19/31 mips/kvm: Add host definitions for MIPS VZ based host.
In reply to David DaneyFrom: David Daney <[email protected]>
--- arch/mips/include/asm/kvm_mips_vz.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 arch/mips/include/asm/kvm_mips_vz.h
arch/mips/include/asm/kvm_mips_vz.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* This file is subject to the terms and conditions of the GNU General Public +* License. See the file "COPYING" in the main directory of this archive +* for more details. +* +* Copyright (C) 2013 Cavium, Inc. +*/ +#ifndef _ASM_KVM_MIPS_VZ_H +#define _ASM_KVM_MIPS_VZ_H + +struct kvm ; + +struct kvm_mips_vz { +struct mutex guest_mm_lock; +pgd_t *pgd;/* Translations for this host. */ +spinlock_t irq_chip_lock; +struct page *irq_chip; +unsigned int asid[NR_CPUS ];/* Per CPU ASIDs for pgd. */ +}; + +bool mipsvz_page_fault (struct pt_regs *regs,unsigned long write, +unsigned long address); + +bool mipsvz_cp_unusable (struct pt_regs *regs); +int mipsvz_arch_init (void *opaque); +int mipsvz_arch_hardware_enable (void *garbage); +int mipsvz_init_vm (struct kvm *kvm,unsigned long type); + +#endif /* _ASM_KVM_MIPS_VZ_H */
Signature · 1 line
1.7.11.7
PATCH 21/31 mips/kvm: Allow set_except_vector() to be used from MIPSVZ code.
In reply to David DaneyFrom: David Daney <[email protected]>
We need to move it out of __init so we don't have section mismatch problems.
--- arch/mips/include/asm/uasm.h | 2 +- arch/mips/kernel/traps.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/mips/include/asm/uasm.h +1 -1
@@ -11,7 +11,7 @@#include <linux/types.h> -#ifdef CONFIG_EXPORT_UASM +#if defined(CONFIG_EXPORT_UASM ) ||IS_ENABLED (CONFIG_KVM_MIPSVZ )#include <linux/export.h> #define __uasminit#define __uasminitdata
arch/mips/kernel/traps.c +1 -1
@@ -1457,7 +1457,7 @@ unsigned long ebase;unsigned long exception_handlers[32 ];unsigned long vi_handlers[64 ]; -void __init *set_except_vector (int n,void *addr) +void __uasminit *set_except_vector(int n, void *addr) {unsigned long handler = (unsigned long ) addr;unsigned long old_handler;
Signature · 1 line
1.7.11.7
PATCH 22/31 mips/kvm: Split get_new_mmu_context into two parts.
In reply to David DaneyFrom: David Daney <[email protected]>
The new function (part) get_new_asid() can now be used from MIPSVZ code.
--- arch/mips/include/asm/mmu_context.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
arch/mips/include/asm/mmu_context.h +8 -2
@@ -108,8 +108,8 @@ static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)#ifndef CONFIG_MIPS_MT_SMTC /* Normal, classic MIPS get_new_mmu_context */ -static inline void -get_new_mmu_context (struct mm_struct *mm,unsigned long cpu) +static inline unsigned long +get_new_asid (unsigned long cpu) {extern void kvm_local_flush_tlb_all (void );unsigned long asid =asid_cache (cpu);
@@ -125,7 +125,13 @@ get_new_mmu_context(struct mm_struct *mm, unsigned long cpu)if (!asid)/* fix version if needed */ asid =ASID_FIRST_VERSION ; } +return asid; +} +static inline void +get_new_mmu_context (struct mm_struct *mm,unsigned long cpu) +{ +unsigned long asid =get_new_asid (cpu);cpu_context (cpu, mm) =asid_cache (cpu) = asid; }
Signature · 1 line
1.7.11.7
PATCH 23/31 mips/kvm: Hook into CP unusable exception handler.
In reply to David DaneyFrom: David Daney <[email protected]>
The MIPS VZ KVM code needs this to be able to manage the FPU.
--- arch/mips/kernel/traps.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/mips/kernel/traps.c +8 -0
@@ -56,6 +56,7 @@#include <asm/types.h> #include <asm/stacktrace.h> #include <asm/uasm.h> +#include <asm/kvm_mips_vz.h> extern void check_wait (void ); extern asmlinkage void rollback_handle_int(void);
@@ -1045,6 +1046,13 @@ asmlinkage void do_cpu(struct pt_regs *regs)int status;unsigned long __maybe_unused flags; +#ifdef CONFIG_KVM_MIPSVZ +if (test_tsk_thread_flag (current,TIF_GUESTMODE )) { +if (mipsvz_cp_unusable (regs)) +return ; + } +#endif +die_if_kernel ("do_cpu invoked from kernel context!" , regs); cpid = (regs->cp0_cause >>CAUSEB_CE ) &3 ;
Signature · 1 line
1.7.11.7
PATCH 24/31 mips/kvm: Add thread_struct fields used by MIPSVZ hosts.
In reply to David DaneyFrom: David Daney <[email protected]>
... and their accessors in asm-offsets.c
--- arch/mips/include/asm/processor.h | 6 ++++++ arch/mips/kernel/asm-offsets.c | 5 +++++ 2 files changed, 11 insertions(+)
arch/mips/include/asm/processor.h +6 -0
@@ -198,6 +198,7 @@ typedef struct {#define ARCH_MIN_TASKALIGN 8struct mips_abi ; +struct kvm_vcpu ;/* * If you change thread_struct remember to change the #defines below too!
@@ -230,6 +231,11 @@ struct thread_struct {unsigned long cp0_badvaddr;/* Last user fault */ unsigned long cp0_baduaddr;/* Last kernel fault accessing USEG */ unsigned long error_code; +#ifdef CONFIG_KVM_MIPSVZ +struct kvm_vcpu *vcpu; +unsigned int mm_asid; +unsigned int guest_asid; +#endif #ifdef CONFIG_CPU_CAVIUM_OCTEON struct octeon_cop2_state cp2 __attribute__ ((__aligned__(128))); struct octeon_cvmseg_state cvmseg __attribute__ ((__aligned__(128)));
arch/mips/kernel/asm-offsets.c +5 -0
@@ -132,6 +132,11 @@ void output_thread_defines(void) thread.cp0_baduaddr);OFFSET (THREAD_ECODE , task_struct, \ thread.error_code); +#ifdef CONFIG_KVM_MIPSVZ +OFFSET (THREAD_VCPU , task_struct, thread.vcpu); +OFFSET (THREAD_MM_ASID , task_struct, thread.mm_asid); +OFFSET (THREAD_GUEST_ASID , task_struct, thread.guest_asid); +#endif BLANK (); }
Signature · 1 line
1.7.11.7
PATCH 25/31 mips/kvm: Add some asm-offsets constants used by MIPSVZ.
In reply to David DaneyFrom: David Daney <[email protected]>
--- arch/mips/kernel/asm-offsets.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/mips/kernel/asm-offsets.c +7 -0
@@ -19,6 +19,7 @@#include <linux/kvm_host.h> #include <asm/kvm_mips_te.h> +#include <asm/kvm_mips_vz.h> void output_ptreg_defines (void ) {
@@ -345,6 +346,8 @@ void output_pbe_defines(void)void output_kvm_defines (void ) {COMMENT (" KVM/MIPS Specfic offsets. " ); +OFFSET (KVM_ARCH_IMPL , kvm, arch.impl); +OFFSET (KVM_VCPU_KVM , kvm_vcpu, kvm);DEFINE (VCPU_ARCH_SIZE ,sizeof (struct kvm_vcpu_arch ));OFFSET (VCPU_RUN , kvm_vcpu, run);OFFSET (VCPU_HOST_ARCH , kvm_vcpu, arch);
@@ -411,5 +414,9 @@ void output_kvm_defines(void)OFFSET (COP0_TLB_HI , mips_coproc, reg[MIPS_CP0_TLB_HI ][0 ]);OFFSET (COP0_STATUS , mips_coproc, reg[MIPS_CP0_STATUS ][0 ]);BLANK (); + +COMMENT (" Linux struct kvm mipsvz offsets. " ); +OFFSET (KVM_MIPS_VZ_PGD , kvm_mips_vz, pgd); + BLANK(); }#endif
Signature · 1 line
1.7.11.7
PATCH 26/31 mips/kvm: Split up Kconfig and Makefile definitions in preperation for MIPSVZ.
In reply to David DaneyFrom: David Daney <[email protected]>
Create the symbol KVM_MIPSTE, and use it to select the trap and emulate specific things.
--- arch/mips/kvm/Kconfig | 14 +++++++++----- arch/mips/kvm/Makefile | 14 ++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-)
arch/mips/kvm/Kconfig +9 -5
@@ -16,18 +16,22 @@ menuconfig VIRTUALIZATION if VIRTUALIZATION config KVM - tristate "Kernel-based Virtual Machine (KVM) support" - depends on HAVE_KVM + tristate select PREEMPT_NOTIFIERS + +config KVM_MIPSTE + tristate "Kernel-based Virtual Machine (KVM) 32-bit trap-and-emulate" + depends on HAVE_KVM + select KVM select ANON_INODES select KVM_MMIO ---help--- - Support for hosting Guest kernels. + Support for hosting Guest kernels with modified address space layout. Currently supported on MIPS32 processors. config KVM_MIPS_DYN_TRANS bool "KVM/MIPS: Dynamic binary translation to reduce traps" - depends on KVM + depends on KVM_MIPSTE ---help--- When running in Trap & Emulate mode patch privileged instructions to reduce the number of traps.
@@ -36,7 +40,7 @@ config KVM_MIPS_DYN_TRANS config KVM_MIPS_DEBUG_COP0_COUNTERS bool "Maintain counters for COP0 accesses" - depends on KVM + depends on KVM_MIPSTE ---help--- Maintain statistics for Guest COP0 accesses. A histogram of COP0 accesses is printed when the VM is
arch/mips/kvm/Makefile +8 -6
@@ -1,13 +1,15 @@ # Makefile for KVM support for MIPS # -common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o coalesced_mmio.o) +common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o) EXTRA_CFLAGS += -Ivirt/kvm -Iarch/mips/kvm -kvm-objs := $(common-objs) kvm_mips.o kvm_mips_emul.o kvm_locore.o \ - kvm_mips_int.o kvm_mips_stats.o kvm_mips_commpage.o \ - kvm_mips_dyntrans.o kvm_trap_emul.o +kvm_mipste-objs := kvm_mips_emul.o kvm_locore.o kvm_mips_int.o \ + kvm_mips_stats.o kvm_mips_commpage.o \ + kvm_mips_dyntrans.o kvm_trap_emul.o kvm_cb.o \ + kvm_tlb.o \ + $(addprefix ../../../virt/kvm/, coalesced_mmio.o) -obj-$(CONFIG_KVM) += kvm.o -obj-y += kvm_cb.o kvm_tlb.o +obj-$(CONFIG_KVM) += $(common-objs) kvm_mips.o +obj-$(CONFIG_KVM_MIPSTE) += kvm_mipste.o
Signature · 1 line
1.7.11.7
PATCH 27/31 mips/kvm: Gate the use of kvm_local_flush_tlb_all() by KVM_MIPSTE
In reply to David DaneyFrom: David Daney <[email protected]>
Only the trap-and-emulate KVM code needs a Special tlb flusher. All other configurations should use the regular version.
--- arch/mips/include/asm/mmu_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/include/asm/mmu_context.h +1 -1
@@ -117,7 +117,7 @@ get_new_asid(unsigned long cpu)if (! ((asid +=ASID_INC ) &ASID_MASK ) ) {if (cpu_has_vtag_icache)flush_icache_all (); -#ifdef CONFIG_VIRTUALIZATION +#if IS_ENABLED (CONFIG_KVM_MIPSTE )kvm_local_flush_tlb_all ();/* start new asid cycle */ #else local_flush_tlb_all ();/* start new asid cycle */
Signature · 1 line
1.7.11.7
PATCH 28/31 mips/kvm: Only use KVM_COALESCED_MMIO_PAGE_OFFSET with KVM_MIPSTE
In reply to David DaneyFrom: David Daney <[email protected]>
The forthcoming MIPSVZ code doesn't currently use this, so it must only be enabled for KVM_MIPSTE.
--- arch/mips/include/asm/kvm_host.h | 2 ++ 1 file changed, 2 insertions(+)
arch/mips/include/asm/kvm_host.h +2 -0
@@ -25,7 +25,9 @@/* memory slots that does not exposed to userspace */ #define KVM_PRIVATE_MEM_SLOTS 0 +#ifdef CONFIG_KVM_MIPSTE #define KVM_COALESCED_MMIO_PAGE_OFFSET 1 +#endif /* Don't support huge pages */ #define KVM_HPAGE_GFN_SHIFT (x) 0
Signature · 1 line
1.7.11.7
PATCH 29/31 mips/kvm: Add MIPSVZ support.
In reply to David DaneyFrom: David Daney <[email protected]>
This doen't share much from the trap-and-emulate implementation.
Included is a virtual interrupt controller and I/O emulation. Currently these have hard coded addresses at:
0x1e000000 - 64K of I/O space.
0x1e010000 - virtual interrupt controller.
Future work will allow these windows to be positioned via ioctl.
The MIPSVZ specification has some optional and implementation defined parts. This implementation uses the OCTEON III behavior. For use with other implementations, we would have to split out the implementation specific parts.
--- arch/mips/kvm/kvm_mips.c | 31 +- arch/mips/kvm/kvm_mipsvz.c | 1894 ++++++++++++++++++++++++++++++++++++++ arch/mips/kvm/kvm_mipsvz_guest.S | 234 +++++ 3 files changed, 2156 insertions(+), 3 deletions(-) create mode 100644 arch/mips/kvm/kvm_mipsvz.c create mode 100644 arch/mips/kvm/kvm_mipsvz_guest.S
arch/mips/kvm/kvm_mips.c +28 -3
@@ -21,6 +21,7 @@#include <asm/cacheflush.h> #include <asm/mmu_context.h> #include <asm/kvm_mips_te.h> +#include <asm/kvm_mips_vz.h> #define VCPU_STAT (x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPUstruct kvm_stats_debugfs_item debugfs_entries[] = {
@@ -62,7 +63,11 @@ int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)int kvm_arch_hardware_enable (void *garbage) { +#if IS_ENABLED (CONFIG_KVM_MIPSVZ ) +return mipsvz_arch_hardware_enable (garbage); +#else return 0 ; +#endif }void kvm_arch_hardware_disable (void *garbage)
@@ -89,8 +94,15 @@ int kvm_mips_te_init_vm(struct kvm *kvm, unsigned long type);int kvm_arch_init_vm (struct kvm *kvm,unsigned long type) { +#if IS_ENABLED (CONFIG_KVM_MIPSTE )if (type ==0 )return kvm_mips_te_init_vm (kvm, type); +#endif +#if IS_ENABLED (CONFIG_KVM_MIPSVZ ) +if (type ==1 ) +return mipsvz_init_vm (kvm, type); +#endif +return -EINVAL ; }
@@ -411,27 +423,38 @@ out:long kvm_arch_vm_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) { +struct kvm *kvm = filp->private_data;long r;switch (ioctl) {default : - r = -ENOIOCTLCMD ; + r = kvm->arch.ops->vm_ioctl (kvm, ioctl, arg); }return r; } -int kvm_mips_te_arch_init (void *opaque);void kvm_mips_te_arch_exit (void );int kvm_arch_init (void *opaque) { -return kvm_mips_te_arch_init (opaque); +int r =0 ; +#if IS_ENABLED (CONFIG_KVM_MIPSTE ) + r =kvm_mips_te_arch_init (opaque); +if (r) +return r; +#endif +#if IS_ENABLED (CONFIG_KVM_MIPSVZ ) + r =mipsvz_arch_init (opaque); +#endif +return r; }void kvm_arch_exit (void ) { +#if IS_ENABLED (CONFIG_KVM_MIPSTE )kvm_mips_te_arch_exit (); +#endif }void kvm_arch_vcpu_load (struct kvm_vcpu *vcpu,int cpu)
@@ -508,9 +531,11 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_ONE_REG : r =1 ;break ; +#ifndef CONFIG_KVM_MIPSVZ case KVM_CAP_COALESCED_MMIO : r =KVM_COALESCED_MMIO_PAGE_OFFSET ;break ; +#endif default : r =0 ;break ;
arch/mips/kvm/kvm_mipsvz.c new file +1894 -0
1,894 lines not on this page · raw message
arch/mips/kvm/kvm_mipsvz_guest.S new file +234 -0
234 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH 31/31 mips/kvm: Allow for upto 8 KVM vcpus per vm.
In reply to David DaneyFrom: David Daney <[email protected]>
The mipsvz implementation allows for SMP, so let's be able to create all those vcpus.
--- arch/mips/include/asm/kvm_host.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/include/asm/kvm_host.h +1 -1
@@ -20,7 +20,7 @@#include <linux/spinlock.h> -#define KVM_MAX_VCPUS 1 +#define KVM_MAX_VCPUS 8#define KVM_USER_MEM_SLOTS 8/* memory slots that does not exposed to userspace */ #define KVM_PRIVATE_MEM_SLOTS 0
Signature · 1 line
1.7.11.7
PATCH 1/31 MIPS: Move allocate_kscratch to cpu-probe.c and make it public.
In reply to David DaneyFrom: David Daney <[email protected]>
--- arch/mips/include/asm/mipsregs.h | 2 ++ arch/mips/kernel/cpu-probe.c | 29 +++++++++++++++++++++++++++++ arch/mips/mm/tlbex.c | 20 +------------------- 3 files changed, 32 insertions(+), 19 deletions(-)
arch/mips/include/asm/mipsregs.h +2 -0
@@ -1806,6 +1806,8 @@ __BUILD_SET_C0(brcm_cmt_ctrl) __BUILD_SET_C0(brcm_config) __BUILD_SET_C0(brcm_mode) +int allocate_kscratch(void); +#endif /* !__ASSEMBLY__ */ #endif /* _ASM_MIPSREGS_H */
arch/mips/kernel/cpu-probe.c +29 -0
@@ -1064,3 +1064,32 @@ __cpuinit void cpu_report(void)if (c->options &MIPS_CPU_FPU )printk (KERN_INFO "FPU revision is: %08x\n" , c->fpu_id); } + +static DEFINE_SPINLOCK (kscratch_used_lock); + +static unsigned int kscratch_used_mask; + +int allocate_kscratch (void ) +{ +int r; +unsigned int a; + +spin_lock (&kscratch_used_lock); + + a = cpu_data[0 ].kscratch_mask & ~kscratch_used_mask; + + r =ffs (a); + +if (r ==0 ) { + r =-1 ; + goto out; + } + + r--;/* make it zero based */ + + kscratch_used_mask |= (1 << r); +out: +spin_unlock (&kscratch_used_lock); + +return r; +}
arch/mips/mm/tlbex.c +1 -19
@@ -30,6 +30,7 @@#include <linux/cache.h> #include <asm/cacheflush.h> +#include <asm/mipsregs.h> #include <asm/pgtable.h> #include <asm/war.h> #include <asm/uasm.h>
@@ -307,25 +308,6 @@ static int check_for_high_segbits __cpuinitdata;static int check_for_high_segbits__cpuinitdata ; -static unsigned int kscratch_used_mask__cpuinitdata ; - -static int __cpuinit allocate_kscratch (void ) -{ -int r; -unsigned int a = cpu_data[0 ].kscratch_mask & ~kscratch_used_mask; - - r =ffs (a); - -if (r ==0 ) -return -1 ; - - r--;/* make it zero based */ - - kscratch_used_mask |= (1 << r); - -return r; -} -static int scratch_reg__cpuinitdata ;static int pgd_reg__cpuinitdata ;enum vmalloc64_mode {not_refill, refill_scratch, refill_noscratch};
Signature · 1 line
1.7.11.7
PATCH 20/31 mips/kvm: Hook into TLB fault handlers.
In reply to David DaneyFrom: David Daney <[email protected]>
If the CPU is operating in guest mode when a TLB related excpetion occurs, give KVM a chance to do emulation.
--- arch/mips/mm/fault.c | 8 ++++++++ arch/mips/mm/tlbex-fault.S | 6 ++++++ 2 files changed, 14 insertions(+)
arch/mips/mm/fault.c +8 -0
@@ -26,6 +26,7 @@#include <asm/ptrace.h> #include <asm/highmem.h> /* For VMALLOC_END */ #include <linux/kdebug.h> +#include <asm/kvm_mips_vz.h> /* * This routine handles page faults. It determines the address,
@@ -50,6 +51,13 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs, unsigned long writ field, regs->cp0_epc);#endif +#ifdef CONFIG_KVM_MIPSVZ +if (test_tsk_thread_flag (current,TIF_GUESTMODE )) { +if (mipsvz_page_fault (regs, write, address)) +return ; + } +#endif +#ifdef CONFIG_KPROBES /* * This is to notify the fault handler of the kprobes. The
arch/mips/mm/tlbex-fault.S +6 -0
@@ -14,6 +14,12 @@ NESTED(tlb_do_page_fault_\write, PT_SIZE, sp) SAVE_ALL MFC0 a2, CP0_BADVADDR +#ifdef CONFIG_KVM_MIPSVZ + mfc0 v0, CP0_BADINSTR + mfc0 v1, CP0_BADINSTRP + sw v0, PT_BADINSTR(sp) + sw v1, PT_BADINSTRP(sp) +#endif KMODE move a0, sp REG_S a2, PT_BVADDR(sp)
Signature · 1 line
1.7.11.7
PATCH 30/31 mips/kvm: Enable MIPSVZ in Kconfig/Makefile
In reply to David DaneyFrom: David Daney <[email protected]>
Also let CPU_CAVIUM_OCTEON select KVM.
--- arch/mips/Kconfig | 1 + arch/mips/kvm/Kconfig | 9 +++++++++ arch/mips/kvm/Makefile | 1 + 3 files changed, 11 insertions(+)
arch/mips/Kconfig +1 -0
@@ -1426,6 +1426,7 @@ config CPU_CAVIUM_OCTEON select LIBFDT select USE_OF select USB_EHCI_BIG_ENDIAN_MMIO + select HAVE_KVM help The Cavium Octeon processor is a highly integrated chip containing many ethernet hardware widgets for networking tasks. The processor
arch/mips/kvm/Kconfig +9 -0
@@ -48,6 +48,15 @@ config KVM_MIPS_DEBUG_COP0_COUNTERS If unsure, say N. +config KVM_MIPSVZ + bool "Kernel-based Virtual Machine (KVM) using hardware MIPS-VZ support" + depends on HAVE_KVM + select KVM + ---help--- + Support for hosting Guest kernels on hardware with the + MIPS-VZ hardware module. + + source drivers/vhost/Kconfig endif # VIRTUALIZATION
arch/mips/kvm/Makefile +1 -0
@@ -13,3 +13,4 @@ kvm_mipste-objs := kvm_mips_emul.o kvm_locore.o kvm_mips_int.o \ obj-$(CONFIG_KVM) += $(common-objs) kvm_mips.o obj-$(CONFIG_KVM_MIPSTE) += kvm_mipste.o +obj-$(CONFIG_KVM_MIPSVZ) += kvm_mipsvz.o kvm_mipsvz_guest.o
Signature · 1 line
1.7.11.7
I should also add that I will shortly send patches for the kvm tool required to drive this VM as well as a small set of patches that create a para-virtualized MIPS/Linux guest kernel.
The idea is that because there is no standard SMP linux system, we create a standard para-virtualized system that uses a handful of hypercalls, but mostly just uses virtio devices. It has no emulated real hardware (no 8250 UART, no emulated legacy anything...)
David Daney
Quoted 111 lines · David Daney
From: David Daney <[email protected]>
These patches take a somewhat different approach to MIPS virtualization via the MIPS-VZ extensions than the patches previously sent by Sanjay Lal.
Several facts about the code:
o Existing exception handlers are modified to hook in to KVM instead of intercepting all exceptions via the EBase register, and then chaining to real exception handlers.
o Able to boot 64-bit SMP guests that use the FPU (I have booted 4-way SMP 64-bit MIPS/Linux).
o Additional overhead on every exception even when *no* vCPU is running.
o Lower interrupt overhead, than the EBase interception method, when vCPU *is* running.
o This code is somewhat smaller than the existing trap/emulate implementation (about 2100 lines vs. about 5300 lines)
o Currently probably only usable on the OCTEON III CPU model, as some MIPS-VZ implementation-defined behaviors were assumed to have the OCTEON III behavior.
Note: I think Ralf already has the 17/31 (MIPS: Quit exposing
Kconfigsymbols in uapi headers.) queued, but I also include it here.David Daney (31):
MIPS: Moveallocate_kscratchtocpu-probe.cand make it public.
MIPS: Save and restore K0/K1 whenCONFIG_KVM_MIPSVZmips/kvm: Fix 32-bitisms inkvm_locore.S
mips/kvm: Add casts to avoid pointer width mismatch build failures. mips/kvm: Use generic cache flushing functions.
mips/kvm: Rename kvm_vcpu_arch.pc to kvm_vcpu_arch.epc mips/kvm: RenameVCPU_registernametoKVM_VCPU_ARCH_registernamemips/kvm: Fix code formatting inarch/mips/kvm/kvm_locore.Smips/kvm: Factor trap-and-emulate support into a pluggable
implementation.
mips/kvm: Implement ioctls to get and set FPU registers.
MIPS: Rearrangebranch.cso it can be used by kvm code.
MIPS: Add instruction format information for WAIT, MTC0, MFC0, et al. mips/kvm: Add accessors for MIPS VZ registers.
mips/kvm: Addthread_infoflag to indicate operation in MIPS VZ Guest
Mode.
mips/kvm: Exception handling to leave and reenter guest mode. mips/kvm: Add exception handler for MIPSVZ Guest exceptions.
MIPS: Quit exposingKconfigsymbols in uapi headers. mips/kvm: Addpt_regsslots for BadInstr and BadInstrP mips/kvm: Add host definitions for MIPS VZ based host. mips/kvm: Hook into TLB fault handlers.
mips/kvm: Allowset_except_vector()to be used from MIPSVZ code. mips/kvm: Splitget_new_mmu_contextinto two parts. mips/kvm: Hook into CP unusable exception handler. mips/kvm: Addthread_structfields used by MIPSVZ hosts. mips/kvm: Add some asm-offsets constants used by MIPSVZ. mips/kvm: Split upKconfigandMakefiledefinitions in preperation
for MIPSVZ.
mips/kvm: Gate the use ofkvm_local_flush_tlb_all()byKVM_MIPSTEmips/kvm: Only useKVM_COALESCED_MMIO_PAGE_OFFSETwithKVM_MIPSTEmips/kvm: Add MIPSVZ support.
mips/kvm: Enable MIPSVZ in Kconfig/Makefile
mips/kvm: Allow for upto 8 KVM vcpus per vm.arch/mips/Kconfig | 1 + arch/mips/include/asm/branch.h | 7 + arch/mips/include/asm/kvm_host.h | 622 +----------- arch/mips/include/asm/kvm_mips_te.h | 589 +++++++++++ arch/mips/include/asm/kvm_mips_vz.h | 29 + arch/mips/include/asm/mipsregs.h | 264 +++++ arch/mips/include/asm/mmu_context.h | 12 +- arch/mips/include/asm/processor.h | 6 + arch/mips/include/asm/ptrace.h | 36 + arch/mips/include/asm/stackframe.h | 150 ++- arch/mips/include/asm/thread_info.h | 2 + arch/mips/include/asm/uasm.h | 2 +- arch/mips/include/uapi/asm/inst.h | 23 +- arch/mips/include/uapi/asm/ptrace.h | 17 +- arch/mips/kernel/asm-offsets.c | 124 ++- arch/mips/kernel/branch.c | 63 +- arch/mips/kernel/cpu-probe.c | 34 + arch/mips/kernel/genex.S | 8 + arch/mips/kernel/scall64-64.S | 12 + arch/mips/kernel/scall64-n32.S | 12 + arch/mips/kernel/traps.c | 15 +- arch/mips/kvm/Kconfig | 23 +- arch/mips/kvm/Makefile | 15 +- arch/mips/kvm/kvm_locore.S | 980 +++++++++--------- arch/mips/kvm/kvm_mips.c | 768 ++------------ arch/mips/kvm/kvm_mips_comm.h | 1 + arch/mips/kvm/kvm_mips_commpage.c | 9 +- arch/mips/kvm/kvm_mips_dyntrans.c | 4 +- arch/mips/kvm/kvm_mips_emul.c | 312 +++--- arch/mips/kvm/kvm_mips_int.c | 53 +- arch/mips/kvm/kvm_mips_int.h | 2 - arch/mips/kvm/kvm_mips_stats.c | 6 +- arch/mips/kvm/kvm_mipsvz.c | 1894 +++++++++++++++++++++++++++++++++++ arch/mips/kvm/kvm_mipsvz_guest.S | 234 +++++ arch/mips/kvm/kvm_tlb.c | 140 +-- arch/mips/kvm/kvm_trap_emul.c | 932 +++++++++++++++-- arch/mips/mm/fault.c | 8 + arch/mips/mm/tlbex-fault.S | 6 + arch/mips/mm/tlbex.c | 45 +- 39 files changed, 5299 insertions(+), 2161 deletions(-)create mode 100644
arch/mips/include/asm/kvm_mips_te.hcreate mode 100644arch/mips/include/asm/kvm_mips_vz.hcreate mode 100644arch/mips/kvm/kvm_mipsvz.ccreate mode 100644arch/mips/kvm/kvm_mipsvz_guest.S
Re: [PATCH 20/31] mips/kvm: Hook into TLB fault handlers.
In reply to David DaneyHello.
Quoted 15 lines · David Daney
From: David Daney <[email protected]>
If the CPU is operating in guest mode when a TLB related excpetion occurs, give KVM a chance to do emulation.
Signed-off-by David Daney <[email protected]>--- arch/mips/mm/fault.c | 8 ++++++++ arch/mips/mm/tlbex-fault.S | 6 ++++++ 2 files changed, 14 insertions(+)arch/mips/mm/fault.c +0
-0
[...]
arch/mips/mm/fault.c asmlinkage void __kprobes do_page_fault(struct pt_regs *regs, unsigned long writ · line 56
Quoted 7 lines
arch/mips/mm/fault.c +3
-0@@ -50,6 +51,13 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs, unsigned long writ field, regs->cp0_epc);#endif +#ifdef CONFIG_KVM_MIPSVZ +if (test_tsk_thread_flag (current,TIF_GUESTMODE )) { +if (mipsvz_page_fault (regs, write, address))
Any reason not to collapse these into single *if*?
Quoted 5 lines
arch/mips/mm/fault.c +4
-0+ return; + } +#endif +
Re: [PATCH 20/31] mips/kvm: Hook into TLB fault handlers.
Quoted 20 lines · Sergei Shtylyov
Hello.
Quoted 15 lines · David Daney
From: David Daney <[email protected]>
If the CPU is operating in guest mode when a TLB related excpetion occurs, give KVM a chance to do emulation.
Signed-off-by David Daney <[email protected]>--- arch/mips/mm/fault.c | 8 ++++++++ arch/mips/mm/tlbex-fault.S | 6 ++++++ 2 files changed, 14 insertions(+)arch/mips/mm/fault.c +0
-0[...]
Quoted 10 lines
arch/mips/mm/fault.c asmlinkage void __kprobes do_page_fault(struct pt_regs *regs, unsigned long writ · line 56
Quoted 7 lines
arch/mips/mm/fault.c +0
-0@@ -50,6 +51,13 @@ asmlinkage void __kprobes do_page_fault(struct
pt_regs*regs, unsigned long writfield, regs->cp0_epc);#endif
arch/mips/mm/fault.c +3
-0+#ifdef CONFIG_KVM_MIPSVZ +if (test_tsk_thread_flag (current,TIF_GUESTMODE )) { +if (mipsvz_page_fault (regs, write, address))Any reason not to collapse these into single *if*?
It makes the conditional call to mipsvz_page_fault() less obvious.
Certainly the same semantics can be achieved several different ways.
David Daney
Quoted 7 lines
Quoted 5 lines
arch/mips/mm/fault.c +4
-0+ return; + } +#endif +
Quoted 9 lines · David Daney
I should also add that I will shortly send patches for the kvm tool required to drive this VM as well as a small set of patches that create a para-virtualized MIPS/Linux guest kernel.
The idea is that because there is no standard SMP linux system, we create a standard para-virtualized system that uses a handful of hypercalls, but mostly just uses virtio devices. It has no emulated real hardware (no 8250 UART, no emulated legacy anything...)
Virtualization is useful for running legacy code. Why dismiss support for non pv guests so easily? How different MIPS SMP systems are? What about running non pv UP systems?
Quoted 117 lines
David Daney
Quoted 102 lines · David Daney
From: David Daney <[email protected]>
These patches take a somewhat different approach to MIPS virtualization via the MIPS-VZ extensions than the patches previously sent by Sanjay Lal.
Several facts about the code:
o Existing exception handlers are modified to hook in to KVM instead of intercepting all exceptions via the EBase register, and then chaining to real exception handlers.
o Able to boot 64-bit SMP guests that use the FPU (I have booted 4-way SMP 64-bit MIPS/Linux).
o Additional overhead on every exception even when *no* vCPU is running.
o Lower interrupt overhead, than the EBase interception method, when vCPU *is* running.
o This code is somewhat smaller than the existing trap/emulate implementation (about 2100 lines vs. about 5300 lines)
o Currently probably only usable on the OCTEON III CPU model, as some MIPS-VZ implementation-defined behaviors were assumed to have the OCTEON III behavior.
Note: I think Ralf already has the 17/31 (MIPS: Quit exposing
Kconfigsymbols in uapi headers.) queued, but I also include it here.David Daney (31):
MIPS: Moveallocate_kscratchtocpu-probe.cand make it public.
MIPS: Save and restore K0/K1 whenCONFIG_KVM_MIPSVZmips/kvm: Fix 32-bitisms inkvm_locore.S
mips/kvm: Add casts to avoid pointer width mismatch build failures. mips/kvm: Use generic cache flushing functions.
mips/kvm: Rename kvm_vcpu_arch.pc to kvm_vcpu_arch.epc mips/kvm: RenameVCPU_registernametoKVM_VCPU_ARCH_registernamemips/kvm: Fix code formatting inarch/mips/kvm/kvm_locore.Smips/kvm: Factor trap-and-emulate support into a pluggable
implementation.
mips/kvm: Implement ioctls to get and set FPU registers.
MIPS: Rearrangebranch.cso it can be used by kvm code.
MIPS: Add instruction format information for WAIT, MTC0, MFC0, et al. mips/kvm: Add accessors for MIPS VZ registers.
mips/kvm: Addthread_infoflag to indicate operation in MIPS VZ Guest
Mode.
mips/kvm: Exception handling to leave and reenter guest mode. mips/kvm: Add exception handler for MIPSVZ Guest exceptions.
MIPS: Quit exposingKconfigsymbols in uapi headers. mips/kvm: Addpt_regsslots for BadInstr and BadInstrP mips/kvm: Add host definitions for MIPS VZ based host. mips/kvm: Hook into TLB fault handlers.
mips/kvm: Allowset_except_vector()to be used from MIPSVZ code. mips/kvm: Splitget_new_mmu_contextinto two parts. mips/kvm: Hook into CP unusable exception handler. mips/kvm: Addthread_structfields used by MIPSVZ hosts. mips/kvm: Add some asm-offsets constants used by MIPSVZ. mips/kvm: Split upKconfigandMakefiledefinitions in preperation
for MIPSVZ.
mips/kvm: Gate the use ofkvm_local_flush_tlb_all()byKVM_MIPSTEmips/kvm: Only useKVM_COALESCED_MMIO_PAGE_OFFSETwithKVM_MIPSTEmips/kvm: Add MIPSVZ support.
mips/kvm: Enable MIPSVZ in Kconfig/Makefile
mips/kvm: Allow for upto 8 KVM vcpus per vm.arch/mips/Kconfig | 1 + arch/mips/include/asm/branch.h | 7 + arch/mips/include/asm/kvm_host.h | 622 +----------- arch/mips/include/asm/kvm_mips_te.h | 589 +++++++++++ arch/mips/include/asm/kvm_mips_vz.h | 29 + arch/mips/include/asm/mipsregs.h | 264 +++++ arch/mips/include/asm/mmu_context.h | 12 +- arch/mips/include/asm/processor.h | 6 + arch/mips/include/asm/ptrace.h | 36 + arch/mips/include/asm/stackframe.h | 150 ++- arch/mips/include/asm/thread_info.h | 2 + arch/mips/include/asm/uasm.h | 2 +- arch/mips/include/uapi/asm/inst.h | 23 +- arch/mips/include/uapi/asm/ptrace.h | 17 +- arch/mips/kernel/asm-offsets.c | 124 ++- arch/mips/kernel/branch.c | 63 +- arch/mips/kernel/cpu-probe.c | 34 + arch/mips/kernel/genex.S | 8 + arch/mips/kernel/scall64-64.S | 12 + arch/mips/kernel/scall64-n32.S | 12 + arch/mips/kernel/traps.c | 15 +- arch/mips/kvm/Kconfig | 23 +- arch/mips/kvm/Makefile | 15 +- arch/mips/kvm/kvm_locore.S | 980 +++++++++--------- arch/mips/kvm/kvm_mips.c | 768 ++------------ arch/mips/kvm/kvm_mips_comm.h | 1 + arch/mips/kvm/kvm_mips_commpage.c | 9 +- arch/mips/kvm/kvm_mips_dyntrans.c | 4 +- arch/mips/kvm/kvm_mips_emul.c | 312 +++--- arch/mips/kvm/kvm_mips_int.c | 53 +- arch/mips/kvm/kvm_mips_int.h | 2 - arch/mips/kvm/kvm_mips_stats.c | 6 +- arch/mips/kvm/kvm_mipsvz.c | 1894 +++++++++++++++++++++++++++++++++++ arch/mips/kvm/kvm_mipsvz_guest.S | 234 +++++ arch/mips/kvm/kvm_tlb.c | 140 +-- arch/mips/kvm/kvm_trap_emul.c | 932 +++++++++++++++--Quoted 9 lines
arch/mips/mm/fault.c | 8 + arch/mips/mm/tlbex-fault.S | 6 + arch/mips/mm/tlbex.c | 45 +- 39 files changed, 5299 insertions(+), 2161 deletions(-) create mode 100644 arch/mips/include/asm/kvm_mips_te.h create mode 100644 arch/mips/include/asm/kvm_mips_vz.h create mode 100644 arch/mips/kvm/kvm_mipsvz.c create mode 100644 arch/mips/kvm/kvm_mipsvz_guest.S
Quoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
--
Gleb.
Quoted 5 lines · Gleb Natapov
Quoted 4 lines · David Daney
I should also add that I will shortly send patches for the kvm tool required to drive this VM as well as a small set of patches that create a para-virtualized MIPS/Linux guest kernel.
Quoted 7 lines
Quoted 5 lines
The idea is that because there is no standard SMP linux system, we create a standard para-virtualized system that uses a handful of hypercalls, but mostly just uses virtio devices. It has no emulated real hardware (no 8250 UART, no emulated legacy anything...)
Virtualization is useful for running legacy code. Why dismiss support for non pv guests so easily?
Just because we create standard PV system devices, doesn't preclude emulating real hardware. In fact Sanjay Lal's work includes QEMU support for doing just this for a MIPS malta board. I just wanted a very simple system I could implement with the kvm tool in a couple of days, so that is what I initially did.
The problem is that almost nobody has real malta boards, they are really only of interest because QEMU implements a virtual malta board.
Personally, I see the most interesting us cases of MIPS KVM being a deployment platform for new services, so legacy support is not so important to me. That doesn't mean that other people wouldn't want some sort of legacy support. The problem with 'legacy' on MIPS is that there are hundreds of legacies to choose from (Old SGI and DEC hardware, various network hardware from many different vendors, etc.). Which would you choose?
Quoted 1 line
How different MIPS SMP systems are?
o Old SGI heavy metal (several different system architectures).
o Cavium OCTEON SMP SoCs.
o Broadcom (several flavors) SoCs
o Loongson
Come to think of it, Emulating SGI hardware might be an interesting case. There may be old IRIX systems and applications that could be running low on real hardware. Some of those systems take up a whole room and draw a lot of power. They might run faster and at much lower power consumption on a modern 48-Way SMP SoC based system.
Quoted 2 lines
What
about running non pv UP systems?
See above. I think this is what Sanjay Lal is doing.
Quoted 125 lines
Quoted 117 lines
David Daney
Quoted 106 lines · David Daney
From: David Daney <[email protected]>
These patches take a somewhat different approach to MIPS virtualization via the MIPS-VZ extensions than the patches previously sent by Sanjay Lal.
Several facts about the code:
o Existing exception handlers are modified to hook in to KVM instead of intercepting all exceptions via the EBase register, and then chaining to real exception handlers.
o Able to boot 64-bit SMP guests that use the FPU (I have booted 4-way SMP 64-bit MIPS/Linux).
o Additional overhead on every exception even when *no* vCPU is running.
o Lower interrupt overhead, than the EBase interception method, when vCPU *is* running.
o This code is somewhat smaller than the existing trap/emulate implementation (about 2100 lines vs. about 5300 lines)
o Currently probably only usable on the OCTEON III CPU model, as some MIPS-VZ implementation-defined behaviors were assumed to have the OCTEON III behavior.
Note: I think Ralf already has the 17/31 (MIPS: Quit exposing
Kconfigsymbols in uapi headers.) queued, but I also include it here.David Daney (31):
MIPS: Moveallocate_kscratchtocpu-probe.cand make it public.
MIPS: Save and restore K0/K1 whenCONFIG_KVM_MIPSVZmips/kvm: Fix 32-bitisms inkvm_locore.S
mips/kvm: Add casts to avoid pointer width mismatch build failures. mips/kvm: Use generic cache flushing functions.
mips/kvm: Rename kvm_vcpu_arch.pc to kvm_vcpu_arch.epc mips/kvm: RenameVCPU_registernametoKVM_VCPU_ARCH_registernamemips/kvm: Fix code formatting inarch/mips/kvm/kvm_locore.Smips/kvm: Factor trap-and-emulate support into a pluggable
implementation.
mips/kvm: Implement ioctls to get and set FPU registers.
MIPS: Rearrangebranch.cso it can be used by kvm code.
MIPS: Add instruction format information for WAIT, MTC0, MFC0, et al. mips/kvm: Add accessors for MIPS VZ registers.
mips/kvm: Addthread_infoflag to indicate operation in MIPS VZ Guest
Mode.
mips/kvm: Exception handling to leave and reenter guest mode. mips/kvm: Add exception handler for MIPSVZ Guest exceptions.
MIPS: Quit exposingKconfigsymbols in uapi headers. mips/kvm: Addpt_regsslots for BadInstr and BadInstrP mips/kvm: Add host definitions for MIPS VZ based host. mips/kvm: Hook into TLB fault handlers.
mips/kvm: Allowset_except_vector()to be used from MIPSVZ code. mips/kvm: Splitget_new_mmu_contextinto two parts. mips/kvm: Hook into CP unusable exception handler. mips/kvm: Addthread_structfields used by MIPSVZ hosts. mips/kvm: Add some asm-offsets constants used by MIPSVZ. mips/kvm: Split upKconfigandMakefiledefinitions in preperation
for MIPSVZ.
mips/kvm: Gate the use ofkvm_local_flush_tlb_all()byKVM_MIPSTEmips/kvm: Only useKVM_COALESCED_MMIO_PAGE_OFFSETwithKVM_MIPSTEmips/kvm: Add MIPSVZ support.
mips/kvm: Enable MIPSVZ in Kconfig/Makefile
mips/kvm: Allow for upto 8 KVM vcpus per vm.arch/mips/Kconfig | 1 + arch/mips/include/asm/branch.h | 7 + arch/mips/include/asm/kvm_host.h | 622 +----------- arch/mips/include/asm/kvm_mips_te.h | 589 +++++++++++ arch/mips/include/asm/kvm_mips_vz.h | 29 + arch/mips/include/asm/mipsregs.h | 264 +++++ arch/mips/include/asm/mmu_context.h | 12 +- arch/mips/include/asm/processor.h | 6 + arch/mips/include/asm/ptrace.h | 36 + arch/mips/include/asm/stackframe.h | 150 ++- arch/mips/include/asm/thread_info.h | 2 + arch/mips/include/asm/uasm.h | 2 +- arch/mips/include/uapi/asm/inst.h | 23 +- arch/mips/include/uapi/asm/ptrace.h | 17 +- arch/mips/kernel/asm-offsets.c | 124 ++- arch/mips/kernel/branch.c | 63 +- arch/mips/kernel/cpu-probe.c | 34 + arch/mips/kernel/genex.S | 8 + arch/mips/kernel/scall64-64.S | 12 + arch/mips/kernel/scall64-n32.S | 12 + arch/mips/kernel/traps.c | 15 +- arch/mips/kvm/Kconfig | 23 +- arch/mips/kvm/Makefile | 15 +- arch/mips/kvm/kvm_locore.S | 980 +++++++++--------- arch/mips/kvm/kvm_mips.c | 768 ++------------ arch/mips/kvm/kvm_mips_comm.h | 1 + arch/mips/kvm/kvm_mips_commpage.c | 9 +- arch/mips/kvm/kvm_mips_dyntrans.c | 4 +- arch/mips/kvm/kvm_mips_emul.c | 312 +++--- arch/mips/kvm/kvm_mips_int.c | 53 +- arch/mips/kvm/kvm_mips_int.h | 2 - arch/mips/kvm/kvm_mips_stats.c | 6 +- arch/mips/kvm/kvm_mipsvz.c | 1894 +++++++++++++++++++++++++++++++++++ arch/mips/kvm/kvm_mipsvz_guest.S | 234 +++++ arch/mips/kvm/kvm_tlb.c | 140 +-- arch/mips/kvm/kvm_trap_emul.c | 932 +++++++++++++++-- arch/mips/mm/fault.c | 8 + arch/mips/mm/tlbex-fault.S | 6 + arch/mips/mm/tlbex.c | 45 +- 39 files changed, 5299 insertions(+), 2161 deletions(-)Quoted 5 lines
create mode 100644
arch/mips/include/asm/kvm_mips_te.hcreate mode 100644arch/mips/include/asm/kvm_mips_vz.hcreate mode 100644arch/mips/kvm/kvm_mipsvz.ccreate mode 100644arch/mips/kvm/kvm_mipsvz_guest.SQuoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/--
Gleb.
Quoted 9 lines · David Daney
Quoted 1 line
How different MIPS SMP systems are?
o Old SGI heavy metal (several different system architectures).
o Cavium OCTEON SMP SoCs.
o Broadcom (several flavors) SoCs
o Loongson
o Old DEC hardware (DECsystem 58x0, R3000-based).
o Malta-based MIPS Technologies CMP solutions (1004K, 1074K, interAptiv).
Maciej
Quoted 11 lines · David Daney
Quoted 10 lines · Gleb Natapov
Quoted 9 lines · David Daney
I should also add that I will shortly send patches for the kvm tool required to drive this VM as well as a small set of patches that create a para-virtualized MIPS/Linux guest kernel.
The idea is that because there is no standard SMP linux system, we create a standard para-virtualized system that uses a handful of hypercalls, but mostly just uses virtio devices. It has no emulated real hardware (no 8250 UART, no emulated legacy anything...)
Quoted 9 lines
Quoted 2 lines
Virtualization is useful for running legacy code. Why dismiss support for non pv guests so easily?
Just because we create standard PV system devices, doesn't preclude emulating real hardware. In fact Sanjay Lal's work includes QEMU support for doing just this for a MIPS malta board. I just wanted a very simple system I could implement with the kvm tool in a couple of days, so that is what I initially did.
That makes sense. From your wording I misunderstood that there is something in proposed patches that requires PV to run a guest.
--
Gleb.
Quoted 6 lines · Maciej W. Rozycki
Quoted 6 lines
Quoted 1 line
How different MIPS SMP systems are?
o Old SGI heavy metal (several different system architectures).
o Cavium OCTEON SMP SoCs.
Quoted 7 lines
Quoted 3 lines
o Broadcom (several flavors) SoCs
o Loongson
o Old DEC hardware (DECsystem 58x0, R3000-based).
o Malta-based MIPS Technologies CMP solutions (1004K, 1074K, interAptiv).
And more. It's fairly accurate that MIPS SMP system tend to have little of their system architecture in common beyond the underlying processor architecture and everything else should be treated as a lucky coincidence.
Ralf
Quoted 31 lines · David Daney
Quoted 5 lines · Gleb Natapov
Quoted 4 lines · David Daney
I should also add that I will shortly send patches for the kvm tool required to drive this VM as well as a small set of patches that create a para-virtualized MIPS/Linux guest kernel.
Quoted 7 lines
Quoted 5 lines
The idea is that because there is no standard SMP linux system, we create a standard para-virtualized system that uses a handful of hypercalls, but mostly just uses virtio devices. It has no emulated real hardware (no 8250 UART, no emulated legacy anything...)
Virtualization is useful for running legacy code. Why dismiss support for non pv guests so easily?
Just because we create standard PV system devices, doesn't preclude emulating real hardware. In fact Sanjay Lal's work includes QEMU support for doing just this for a MIPS malta board. I just wanted a very simple system I could implement with the kvm tool in a couple of days, so that is what I initially did.
The problem is that almost nobody has real malta boards, they are really only of interest because QEMU implements a virtual malta board.
Personally, I see the most interesting us cases of MIPS KVM being a deployment platform for new services, so legacy support is not so important to me. That doesn't mean that other people wouldn't want some sort of legacy support. The problem with 'legacy' on MIPS is that there are hundreds of legacies to choose from (Old SGI and DEC hardware, various network hardware from many different vendors, etc.). Which would you choose?
Quoted 1 line
How different MIPS SMP systems are?
o Old SGI heavy metal (several different system architectures).
o Cavium OCTEON SMP SoCs.
o Broadcom (several flavors) SoCs
o Loongson
Quoted 6 lines
Come to think of it, Emulating SGI hardware might be an interesting case. There may be old IRIX systems and applications that could be running low on real hardware. Some of those systems take up a whole room and draw a lot of power. They might run faster and at much lower power consumption on a modern 48-Way SMP SoC based system.
Quoted 2 lines
What
about running non pv UP systems?See above. I think this is what Sanjay Lal is doing.
The KVM implementation from MIPS (currently in mainline) supports UP systems in trap and emulate mode. The patch set I posted earlier adding VZ support also supports SMP. We leverage the Malta board emulation in QEMU to offer full non-PV virtualization:
UP system: Malta board with a MIPS 24K processor
SMP system: Malta board with a 1074K CMP processor cluster with a GIC.
When it comes to PV/non-PV support, I see the two implementations as complementary. If people want full legacy system emulation without any kernel modifications, then they can run the full QEMU/KVM stack, while people interested in pure PV solutions can run the lkvm version.
Regards
Sanjay
Quoted 6 lines · David Daney
From: David Daney <[email protected]>
These patches take a somewhat different approach to MIPS virtualization via the MIPS-VZ extensions than the patches previously sent by Sanjay Lal.
Quoted 7 lines
Several facts about the code:
o Currently probably only usable on the OCTEON III CPU model, as some MIPS-VZ implementation-defined behaviors were assumed to have the OCTEON III behavior.
I've only briefly gone over the patches, but I was wondering if the Cavium implementation has support for GuestIDs, which are optional in the VZ-ASE?
Regards
Sanjay
Quoted 12 lines · Sanjay Lal
Quoted 9 lines · David Daney
From: David Daney <[email protected]>
These patches take a somewhat different approach to MIPS virtualization via the MIPS-VZ extensions than the patches previously sent by Sanjay Lal.
Several facts about the code:
Quoted 8 lines
Quoted 4 lines
o Currently probably only usable on the OCTEON III CPU model, as some MIPS-VZ implementation-defined behaviors were assumed to have the OCTEON III behavior.
I've only briefly gone over the patches, but I was wondering if the Cavium implementation has support for GuestIDs, which are optional in the VZ-ASE?
No, OCTEON III does not support this optional behavior. For the most part this only impacts TLB management. I think in the context of KVM, you cannot leave foreign Guest's TLB entries present in the Guest TLB anyhow, so the feature is of little use.
Since MIPS TLBs are managed by software, it is valid for a guest to populate the TLB in any way it desires. To have the hypervisor (KVM) come and randomly invalidate the TLB, via the GuestID mechanism, would both be detectable by the guest, and potentially make the guest operate incorrectly.
David Daney
Quoted 6 lines
Regards
Sanjay
Quoted 26 lines · David Daney
Subject: [PATCH 00/31] KVM/MIPS: Implement hardware virtualization via the
MIPS-VZ extensions.From: David Daney <[email protected]>
These patches take a somewhat different approach to MIPS virtualization via the MIPS-VZ extensions than the patches previously sent by Sanjay Lal.
Several facts about the code:
o Existing exception handlers are modified to hook in to KVM instead of intercepting all exceptions via the EBase register, and then chaining to real exception handlers.
o Able to boot 64-bit SMP guests that use the FPU (I have booted 4-way SMP 64-bit MIPS/Linux).
o Additional overhead on every exception even when *no* vCPU is running.
o Lower interrupt overhead, than the EBase interception method, when vCPU *is* running.
o This code is somewhat smaller than the existing trap/emulate implementation (about 2100 lines vs. about 5300 lines)
Quoted 6 lines
o Currently probably only usable on the OCTEON III CPU model, as some MIPS-VZ implementation-defined behaviors were assumed to have the OCTEON III behavior.
Note: I think Ralf already has the 17/31 (MIPS: Quit exposing
Kconfigsymbols in uapi headers.) queued, but I also include it here.
Yes; as the references to CONFIG_* symbols in UAPI were a bug, I've already merged this patch for 3.10 as 8f657933a3c2086d4731350c98f91a990783c0d3 [MIPS: Quit exposing Kconfig symbols in uapi headers.]
Ralf
Re: [PATCH 17/31] MIPS: Quit exposing Kconfig symbols in uapi headers.
In reply to David DaneySo this one can be dropped.
Ralf
Re: [PATCH 01/31] MIPS: Move allocate_kscratch to cpu-probe.c and make it public.
In reply to David DaneyQuoted 9 lines · David Daney
Date: Fri, 7 Jun 2013 16:03:05 -0700
From: David Daney <[email protected]>
To: [email protected], [email protected], [email protected],
Sanjay Lal <[email protected]>
Cc: [email protected], David Daney <[email protected]>
Subject: [PATCH 01/31] MIPS: Moveallocate_kscratchtocpu-probe.cand make
it public.From: David Daney <[email protected]>
I'd just like to add a note about compatibility. Code optimized for LL/SC-less CPUs has made use of the fact that exception handlers will clobber k0/k1 to a non-zero value. On a MIPS II or better CPU a branch likely instruction could be used to atomically test k0/k1 and depending on the test, execute a store instruction like:
.set noreorder beqzl $k0, ok sw $reg, offset($reg) /* if we get here, our SC emulation has failed */
ok: ...
In particular Sony had elected to do this for the R5900 (after I explained the concept to somebody and told it'd be a _bad_ idea for compatibility reasons). Bad ideas are infectious so I'm sure others have used it, too.
I don't think this should stop your patch nor should we unless this turns out to be an actual problem add any kludges to support such cowboy style hacks. But I wanted to mention and document the issue; maybe this should be mentioned in the log message of the next version of this patch.
Ralf
Re: [PATCH 03/31] mips/kvm: Fix 32-bitisms in kvm_locore.S
In reply to David DaneyQuoted 31 lines · David Daney
arch/mips/kvm/kvm_locore.S +3
-3@@ -310,7 +310,7 @@ NESTED (MIPSX(GuestException), CALLFRAME_SIZ, ra) LONG_S t0, VCPU_R26(k1) /* Get GUEST k1 and save it in VCPU */ - la t1, ~0x2ff + PTR_LI t1, ~0x2ff mfc0 t0, CP0_EBASE and t0, t0, t1 LONG_L t0, 0x3000(t0)@@ -384,14 +384,14 @@ NESTED (MIPSX(GuestException), CALLFRAME_SIZ, ra) mtc0 k0, CP0_DDATA_LO /* Restore RDHWR access */ - la k0, 0x2000000F + PTR_LI k0, 0x2000000F mtc0 k0, CP0_HWRENA /* Jump to handler */ FEXPORT(__kvm_mips_jump_to_handler) /* XXXKYMA: not sure if this is safe, how large is the stack?? */ /* Now jump to the kvm_mips_handle_exit() to see if we can deal with this in the kernel */ - la t9,kvm_mips_handle_exit + PTR_LA t9, kvm_mips_handle_exit jalr.hb t9 addiu sp,sp, -CALLFRAME_SIZ /* BD Slot */
arch/mips/kvm/kvm_locore.S __kvm_mips_return_to_host: · line 570
Quoted 6 lines
arch/mips/kvm/kvm_locore.S +1
-1@@ -566,7 +566,7 @@ __kvm_mips_return_to_host: mtlo k0 /* Restore RDHWR access */ - la k0, 0x2000000F + PTR_LI k0, 0x2000000F mtc0 k0, CP0_HWRENA
Technically ok, there's only a formatting issue because you indent the changed lines with tabs while the existing file uses tab characters. I suggest you insert an extra cleanup patch to properly re-indent the entire file into the series before this one?
So with that sorted:
Ralf
Ralf Baechle
Acked-byRe: [PATCH 01/31] MIPS: Move allocate_kscratch to cpu-probe.c and make it public.
In reply to Ralf BaechleQuoted 37 lines · Ralf Baechle
Date: Fri, 14 Jun 2013 13:41:18 +0200
From: Ralf Baechle <[email protected]>
To: James Hogan <[email protected]>
Cc: [email protected], [email protected], Sanjay Lal
<[email protected]>, [email protected], David Daney <[email protected]>
Subject: Re: [PATCH 01/31] MIPS: Moveallocate_kscratchtocpu-probe.cand
make it public.
Content-Type: text/plain; charset=us-asciiQuoted 9 lines · David Daney
Date: Fri, 7 Jun 2013 16:03:05 -0700
From: David Daney <[email protected]>
To: [email protected], [email protected], [email protected],
Sanjay Lal <[email protected]>
Cc: [email protected], David Daney <[email protected]>
Subject: [PATCH 01/31] MIPS: Moveallocate_kscratchtocpu-probe.cand make
it public.From: David Daney <[email protected]>
I'd just like to add a note about compatibility. Code optimized for LL/SC-less CPUs has made use of the fact that exception handlers will clobber k0/k1 to a non-zero value. On a MIPS II or better CPU a branch likely instruction could be used to atomically test k0/k1 and depending on the test, execute a store instruction like:
.set noreorder beqzl $k0, ok sw $reg, offset($reg) /* if we get here, our SC emulation has failed */ok: ...
In particular Sony had elected to do this for the R5900 (after I explained the concept to somebody and told it'd be a _bad_ idea for compatibility reasons). Bad ideas are infectious so I'm sure others have used it, too.
Quoted 6 lines
I don't think this should stop your patch nor should we unless this turns out to be an actual problem add any kludges to support such cowboy style hacks. But I wanted to mention and document the issue; maybe this should be mentioned in the log message of the next version of this patch.
Acked-by Ralf Baechle <[email protected]>
Bleh. I fatfingered mutt. This of course was the reply intended for "[PATCH 02/31] MIPS: Save and restore K0/K1 when CONFIG_KVM_MIPSVZ".
As for 1/31:
Ralf
Re: [PATCH 04/31] mips/kvm: Add casts to avoid pointer width mismatch build failures.
In reply to David DaneyCast are always a bit ugly, in particular the one double casts - but a necessary evil here.
Ralf
Re: [PATCH 05/31] mips/kvm: Use generic cache flushing functions.
In reply to David DaneyQuoted 25 lines · David Daney
From: David Daney <[email protected]>
We don't know if we have the r4k specific functions available, so use universally available
__flush_cache_all()instead. This takes longer as it flushes both i-cache and d-cache, but is available for all CPUs.Signed-off-by David Daney <[email protected]>--- arch/mips/kvm/kvm_mips_emul.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)arch/mips/kvm/kvm_mips_emul.c +0
-2@@ -916,8 +916,6 @@ kvm_mips_emulate_cache(uint32_t inst, uint32_t *opc, uint32_t cause, struct kvm_run *run, struct kvm_vcpu *vcpu) { struct mips_coproc *cop0 = vcpu->arch.cop0; -extern void (*r4k_blast_dcache) (void ); -extern void (*r4k_blast_icache) (void );enum emulation_result er =EMULATE_DONE ;int32_t offset, cache, op_inst, op, base;struct kvm_vcpu_arch *arch = &vcpu->arch;
arch/mips/kvm/kvm_mips_emul.c kvm_mips_emulate_cache(uint32_t inst, uint32_t *opc, uint32_t cause, · line 957
Quoted 4 lines
arch/mips/kvm/kvm_mips_emul.c +0
-1@@ -954,9 +952,9 @@ kvm_mips_emulate_cache(uint32_t inst, uint32_t *opc, uint32_t cause, arch->gprs[base], offset);if (cache ==MIPS_CACHE_DCACHE ) -r4k_blast_dcache ();
Only nukes the D-cache.
arch/mips/kvm/kvm_mips_emul.c kvm_mips_emulate_cache(uint32_t inst, uint32_t *opc, uint32_t cause, · line 955
Quoted 1 line
arch/mips/kvm/kvm_mips_emul.c +1
-0+__flush_cache_all ();
This is also going to blow away the I-cache, so will be slower.
arch/mips/kvm/kvm_mips_emul.c kvm_mips_emulate_cache(uint32_t inst, uint32_t *opc, uint32_t cause, · line 959
Quoted 2 lines
arch/mips/kvm/kvm_mips_emul.c +0
-1else if (cache ==MIPS_CACHE_ICACHE ) -r4k_blast_icache ();
Only nukes the I-cache.
arch/mips/kvm/kvm_mips_emul.c kvm_mips_emulate_cache(uint32_t inst, uint32_t *opc, uint32_t cause, · line 957
Quoted 1 line
arch/mips/kvm/kvm_mips_emul.c +1
-0+__flush_cache_all ();
This is also going to blow away the D-cache, so will be slower.
Ralf
Re: [PATCH 06/31] mips/kvm: Rename kvm_vcpu_arch.pc to kvm_vcpu_arch.epc
In reply to David DaneyRalf
Re: [PATCH 07/31] mips/kvm: Rename VCPU_registername to KVM_VCPU_ARCH_registername
In reply to David DaneyRalf
Re: [PATCH 08/31] mips/kvm: Fix code formatting in arch/mips/kvm/kvm_locore.S
In reply to David DaneyAh, here's you're taking care of my eariler complaint about the formatting of kvm_locore.S. I'd have done things in a different order to avoid the inconsistent formatting - even if that was only a temporary state. But anyway,
Ralf
Re: [PATCH 03/31] mips/kvm: Fix 32-bitisms in kvm_locore.S
In reply to Ralf BaechleHello.
Quoted 33 lines · Ralf Baechle
Quoted 33 lines
arch/mips/kvm/kvm_locore.S +3
-3@@ -310,7 +310,7 @@ NESTED (MIPSX(GuestException), CALLFRAME_SIZ, ra) LONG_S t0, VCPU_R26(k1) /* Get GUEST k1 and save it in VCPU */ - la t1, ~0x2ff + PTR_LI t1, ~0x2ff mfc0 t0, CP0_EBASE and t0, t0, t1 LONG_L t0, 0x3000(t0)@@ -384,14 +384,14 @@ NESTED (MIPSX(GuestException), CALLFRAME_SIZ, ra) mtc0 k0, CP0_DDATA_LO /* Restore RDHWR access */ - la k0, 0x2000000F + PTR_LI k0, 0x2000000F mtc0 k0, CP0_HWRENA /* Jump to handler */ FEXPORT(__kvm_mips_jump_to_handler) /* XXXKYMA: not sure if this is safe, how large is the stack?? */ /* Now jump to the kvm_mips_handle_exit() to see if we can deal with this in the kernel */ - la t9,kvm_mips_handle_exit + PTR_LA t9, kvm_mips_handle_exit jalr.hb t9 addiu sp,sp, -CALLFRAME_SIZ /* BD Slot */@@ -566,7 +566,7 @@ __kvm_mips_return_to_host: mtlo k0
Quoted 7 lines
arch/mips/kvm/kvm_locore.S NESTED (MIPSX(GuestException), CALLFRAME_SIZ, ra) · line 388
Quoted 4 lines
arch/mips/kvm/kvm_locore.S +1
-1/* Restore RDHWR access */ - la k0, 0x2000000F + PTR_LI k0, 0x2000000F mtc0 k0, CP0_HWRENATechnically ok, there's only a formatting issue because you indent the changed lines with tabs while the existing file uses tab characters.
I hope you meant the space characters? :-)
Quoted 8 lines
I suggest you insert an extra cleanup patch to properly re-indent the entire file into the series before this one?
So with that sorted:
Acked-by Ralf Baechle <[email protected]>Ralf
WBR, Sergei
Re: [PATCH 09/31] mips/kvm: Factor trap-and-emulate support into a pluggable implementation.
In reply to David DaneyRalf
Re: [PATCH 10/31] mips/kvm: Implement ioctls to get and set FPU registers.
In reply to David DaneyQuoted 4 lines · David Daney
From: David Daney <[email protected]>
The current implementation does nothing with them, but future MIPSVZ work need them. Also add the asm-offsets accessors for the fields.
Just as a note, older MIPS FPUs only have fcr0 and fcr31.
Ralf
Re: [PATCH 11/31] MIPS: Rearrange branch.c so it can be used by kvm code.
In reply to David DaneyRalf
Re: [PATCH 12/31] MIPS: Add instruction format information for WAIT, MTC0, MFC0, et al.
In reply to David DaneyQuoted 5 lines · David Daney
To: [email protected], [email protected], [email protected],
Sanjay Lal <[email protected]>
Cc: [email protected], David Daney <[email protected]>
Subject: [PATCH 12/31] MIPS: Add instruction format information for WAIT,
MTC0, MFC0, et al.
Looks good.
I wonder if somebody could throw in microMIPS equivalent to this patch?
Ralf
Re: [PATCH 13/31] mips/kvm: Add accessors for MIPS VZ registers.
In reply to David DaneyRalf
Re: [PATCH 14/31] mips/kvm: Add thread_info flag to indicate operation in MIPS VZ Guest Mode.
In reply to David DaneyRalf
Re: [PATCH 15/31] mips/kvm: Exception handling to leave and reenter guest mode.
In reply to David DaneyQuoted 1 line · David Daney
Currently this is a little complex, here are the facts about how it works:
I'm not so much worried about the intrinic complexity of the job your code is trying to do rather than stackframe.h getting every more complex. We're reaching the point where reimplementing is using uasm.c is looking like a good thing. But certainly not now.
Ralf
Re: [PATCH 16/31] mips/kvm: Add exception handler for MIPSVZ Guest exceptions.
In reply to David DaneyOn Fri, Jun 07, 2013 at 04:03:20PM -0700, David Daney wrote:
Re: [PATCH 18/31] mips/kvm: Add pt_regs slots for BadInstr and BadInstrP
In reply to David DaneyPaolo Bonzini
maintainerRe: [PATCH 17/31] MIPS: Quit exposing Kconfig symbols in uapi headers.
In reply to David DaneyIl 07/06/2013 19:03, David Daney ha scritto:
Quoted 66 lines
From: David Daney <[email protected]>
The kernel's struct
pt_regshas many fields conditional on variousKconfigvariables, we cannot be exporting this garbage to user-space.Move the kernel's definition to
asm/ptrace.h, and put a uapi only version inuapi/asm/ptrace.hgated by #ifndef__KERNEL__Signed-off-by David Daney <[email protected]>--- arch/mips/include/asm/ptrace.h | 32 ++++++++++++++++++++++++++++++++ arch/mips/include/uapi/asm/ptrace.h | 17 ++--------------- 2 files changed, 34 insertions(+), 15 deletions(-)arch/mips/include/asm/ptrace.h +32
-0@@ -16,6 +16,38 @@#include <asm/isadep.h> #include <uapi/asm/ptrace.h> +/* +* This struct defines the way the registers are stored on the stack during a +* system call/exception. As usual the registers k0/k1 aren't being saved. +*/ +struct pt_regs { +#ifdef CONFIG_32BIT +/* Pad bytes for argument save space on the stack. */ +unsigned long pad0[6 ]; +#endif + +/* Saved main processor registers. */ +unsigned long regs[32 ]; + +/* Saved special registers. */ +unsigned long cp0_status; +unsigned long hi; +unsigned long lo; +#ifdef CONFIG_CPU_HAS_SMARTMIPS +unsigned long acx; +#endif +unsigned long cp0_badvaddr; +unsigned long cp0_cause; +unsigned long cp0_epc; +#ifdef CONFIG_MIPS_MT_SMTC +unsigned long cp0_tcstatus; +#endif /* CONFIG_MIPS_MT_SMTC */ +#ifdef CONFIG_CPU_CAVIUM_OCTEON +unsigned long long mpl[3 ];/* MTM{0,1,2} */ +unsigned long long mtp[3 ];/* MTP{0,1,2} */ +#endif +}__aligned(8) ; +struct task_struct ;extern int ptrace_getregs (struct task_struct *child,__s64 __user *data);arch/mips/include/uapi/asm/ptrace.h +1
-0@@ -22,16 +22,12 @@#define DSP_CONTROL 77#define ACX 78 +#ifndef __KERNEL__
arch/mips/include/uapi/asm/ptrace.h line 34
Quoted 10 lines
arch/mips/include/uapi/asm/ptrace.h +0
-5/* * This struct defines the way the registers are stored on the stack during a * system call/exception. As usual the registers k0/k1 aren't being saved. */ struct pt_regs { -#ifdef CONFIG_32BIT -/* Pad bytes for argument save space on the stack. */ -unsigned long pad0[6 ]; -#endif -
Out of curiosity, how has this ever worked (and how will this work) on 32-bit arches? :) I can see that maybe no one uses pt_regs beyond .lo, but these are at the beginning. Maybe for the uapi version you can use the __mips__ preprocessor symbol?
Paolo
Quoted 26 lines
arch/mips/include/uapi/asm/ptrace.h +1
-10/* Saved main processor registers. */ unsigned long regs[32 ];@@ -39,20 +35,11 @@ struct pt_regs {unsigned long cp0_status;unsigned long hi;unsigned long lo; -#ifdef CONFIG_CPU_HAS_SMARTMIPS -unsigned long acx; -#endif unsigned long cp0_badvaddr;unsigned long cp0_cause;unsigned long cp0_epc; -#ifdef CONFIG_MIPS_MT_SMTC -unsigned long cp0_tcstatus; -#endif /* CONFIG_MIPS_MT_SMTC */ -#ifdef CONFIG_CPU_CAVIUM_OCTEON -unsigned long long mpl[3 ];/* MTM{0,1,2} */ -unsigned long long mtp[3 ];/* MTP{0,1,2} */ -#endif } __attribute__ ((aligned (8))); +#endif /* __KERNEL__ */ /* Arbitrarily choose the same ptrace numbers as used by the Sparc code. */ #define PTRACE_GETREGS 12
Re: [PATCH 19/31] mips/kvm: Add host definitions for MIPS VZ based host.
In reply to David DaneyRalf
Re: [PATCH 20/31] mips/kvm: Hook into TLB fault handlers.
In reply to David DaneyRalf
Re: [PATCH 21/31] mips/kvm: Allow set_except_vector() to be used from MIPSVZ code.
In reply to David DaneyQuoted 15 lines · David Daney
From: David Daney <[email protected]>
We need to move it out of
__initso we don't have section mismatch problems.Signed-off-by David Daney <[email protected]>--- arch/mips/include/asm/uasm.h | 2 +- arch/mips/kernel/traps.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)arch/mips/include/asm/uasm.h +0
-0
arch/mips/include/asm/uasm.h line 17
Quoted 8 lines
arch/mips/include/asm/uasm.h +1
-1@@ -11,7 +11,7 @@#include <linux/types.h> -#ifdef CONFIG_EXPORT_UASM +#if defined(CONFIG_EXPORT_UASM ) ||IS_ENABLED (CONFIG_KVM_MIPSVZ )#include <linux/export.h> #define __uasminit#define __uasminitdata
I'd rather keep KVM bits out of uasm.h. A select EXPORT_UASM in Kconfig would have been cleaner - but read below.
arch/mips/kernel/traps.c unsigned long ebase; · line 1460
Quoted 10 lines
arch/mips/kernel/traps.c +1
-1@@ -1457,7 +1457,7 @@ unsigned long ebase;unsigned long exception_handlers[32 ];unsigned long vi_handlers[64 ]; -void __init *set_except_vector (int n,void *addr) +void __uasminit *set_except_vector(int n, void *addr)
A __uasminit tag is a bit unobvious because set_except_vector is not part of uasm. I could understand __cpuinit - but of course that doesn't sort your problem. Maybe we should just drop the __init tag alltogether? Or if we really want set_except_vector to become part of the uasm subsystem, then probably it's declaration should move from setup.h to uasm.h.
Ralf
Re: [PATCH 22/31] mips/kvm: Split get_new_mmu_context into two parts.
In reply to David DaneyRalf
Re: [PATCH 23/31] mips/kvm: Hook into CP unusable exception handler.
In reply to David DaneyQuoted 5 lines · David Daney
From: David Daney <[email protected]>
The MIPS VZ KVM code needs this to be able to manage the FPU.
Signed-off-by David Daney <[email protected]>
Looks good, Acked-by: Ralf Baechle <[email protected]>.
However I get cold shivers at the thought of SMTC FPU management with VZ, it sounds like a source of new entertainment ... But thinkin gaobu this is something for another rainy day, not now.
Ralf
Re: [PATCH 24/31] mips/kvm: Add thread_struct fields used by MIPSVZ hosts.
In reply to David DaneyRalf
Re: [PATCH 25/31] mips/kvm: Add some asm-offsets constants used by MIPSVZ.
In reply to David DaneyPatch looks ok but why not combine this patch with the previous one?
Ralf
Re: [PATCH 26/31] mips/kvm: Split up Kconfig and Makefile definitions in preperation for MIPSVZ.
In reply to David DaneyThe Trademark guys (and readability in general) sould probably be happier if MIPSTE was spelled as MIPS_TE and for that matter, MIPZVZ as MIPS_VZ?
Other than that,
Ralf
Re: [PATCH 31/31] mips/kvm: Allow for upto 8 KVM vcpus per vm.
In reply to David DaneyRalf
Re: [PATCH 27/31] mips/kvm: Gate the use of kvm_local_flush_tlb_all() by KVM_MIPSTE
In reply to David DaneyQuoted 15 lines · David Daney
From: David Daney <[email protected]>
Only the trap-and-emulate KVM code needs a Special tlb flusher. All other configurations should use the regular version.
Signed-off-by David Daney <[email protected]>--- arch/mips/include/asm/mmu_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/mips/include/asm/mmu_context.h +0
-0
arch/mips/include/asm/mmu_context.h get_new_asid(unsigned long cpu) · line 123
Quoted 8 lines
arch/mips/include/asm/mmu_context.h +1
-1@@ -117,7 +117,7 @@ get_new_asid(unsigned long cpu)if (! ((asid +=ASID_INC ) &ASID_MASK ) ) {if (cpu_has_vtag_icache)flush_icache_all (); -#ifdef CONFIG_VIRTUALIZATION +#if IS_ENABLED (CONFIG_KVM_MIPSTE )kvm_local_flush_tlb_all ();/* start new asid cycle */ #else local_flush_tlb_all ();/* start new asid cycle */
Sanjay,
it would seem this is actually a bug if KVM is built as a module and should be fixed for 3.10?
Ralf
Re: [PATCH 30/31] mips/kvm: Enable MIPSVZ in Kconfig/Makefile
In reply to David DaneyRalf
Re: [PATCH 29/31] mips/kvm: Add MIPSVZ support.
In reply to David DaneyRalf
Quoted 5 lines · David Daney
Come to think of it, Emulating SGI hardware might be an interesting case. There may be old IRIX systems and applications that could be running low on real hardware. Some of those systems take up a whole room and draw a lot of power. They might run faster and at much lower power consumption on a modern 48-Way SMP SoC based system.
Many SGI MIPS system have RTCs powered by builtin batteries with a nominal livetime of ten years and for which no more replacements are available. This is beginning to limit usable SGI MIPS systems to those who know how to solve these issues with a Dremel and a soldering iron.
That said, SGI platforms are all more or less weird custom architectures so the platform emulation - let alone the firmware blobs - will be a chunk of work.
Ralf
Re: [PATCH 28/31] mips/kvm: Only use KVM_COALESCED_MMIO_PAGE_OFFSET with KVM_MIPSTE
In reply to David DaneyQuoted 15 lines · David Daney
From: David Daney <[email protected]>
The forthcoming MIPSVZ code doesn't currently use this, so it must only be enabled for
KVM_MIPSTE.Signed-off-by David Daney <[email protected]>--- arch/mips/include/asm/kvm_host.h | 2 ++ 1 file changed, 2 insertions(+)arch/mips/include/asm/kvm_host.h +0
-0
arch/mips/include/asm/kvm_host.h line 30
Quoted 6 lines
arch/mips/include/asm/kvm_host.h +2
-0@@ -25,7 +25,9 @@/* memory slots that does not exposed to userspace */ #define KVM_PRIVATE_MEM_SLOTS 0 +#ifdef CONFIG_KVM_MIPSTE #define KVM_COALESCED_MMIO_PAGE_OFFSET 1 +#endif
What if KVM_MIPSTE and KVM_MIPSVZ both get enabled?
Ralf
FYI, Since you intend to resubmit anyway I just dropped the entire series from patchwork.
Ralf
Re: [PATCH 25/31] mips/kvm: Add some asm-offsets constants used by MIPSVZ.
In reply to Ralf BaechleQuoted 2 lines · Ralf Baechle
Patch looks ok but why not combine this patch with the previous one?
Because even though they both touch asm-offsets.c, they are offsets for unrelated structures. I could try distributing these changes across several other patches, but getting the patch dependencies/ordering correct can be tricky.
David Daney
Quoted 2 lines
Ralf
Re: [PATCH 15/31] mips/kvm: Exception handling to leave and reenter guest mode.
In reply to David DaneyHi David,
I know it's been a while since you posted this patchset, but thought you might appreciate the feedback anyway.
Some of my comments/suggestions relate to portability with MIPS32. I don't object if you respond to those by just adding "depends on 64BIT" so that I & others can fix it up in subsequent patches.
Quoted 52 lines · David Daney
From: David Daney <[email protected]>
Currently this is a little complex, here are the facts about how it works:
o When running in Guest mode we set the high bit of
CP0_XCONTEXT. If this bit is clear, we don't do anything special on an exception.o If we are in guest mode, upon an exception we:
1) load the stack pointer from the
mips_kvm_rootsparray instead of kernelsp.2) Clear GuestCtl[GM] and high bit of
CP0_XCONTEXT.3) Restore host ASID and PGD pointer.
o Upon restarting from an exception we test the task
TIF_GUESTMODEflag if it is clear, nothing special is done.o If Guest mode is active for the thread we:
1) Compare the stack pointer to
mips_kvm_rootsp, if it doesn't match we are not reentering guest mode, so no more special processing is done.2) If reentering guest mode:
2a) Set high bit of
CP0_XCONTEXTand GuestCtl[GM].2b) Set Guest mode ASID and PGD pointer.
This allows a single set of exception handlers to be used for both host and guest mode operation.
Signed-off-by David Daney <[email protected]>--- arch/mips/include/asm/stackframe.h | 135 ++++++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 3 deletions(-)arch/mips/include/asm/stackframe.h +1
-0@@ -17,6 +17,7 @@#include <asm/asmmacro.h> #include <asm/mipsregs.h> #include <asm/asm-offsets.h> +#include <asm/thread_info.h> /* * For SMTC kernel, global IE should be left set, and interrupts
arch/mips/include/asm/stackframe.h line 102
Quoted 5 lines
arch/mips/include/asm/stackframe.h +1
-1@@ -98,7 +99,9 @@#define CPU_ID_REG CP0_CONTEXT#define CPU_ID_MFC0 MFC0#endif - .macro get_saved_sp /* SMP variation */ +#define CPU_ID_MASK ((1 << 13) - 1)
(I was going to say this could be made more portable by using the lowest bit of PTEBASE (i.e. bit PTEBASE_SHIFT) for the guest mode state instead of bit 63, and setting CPU_ID_MASK to -2 to mask off the lowest instead of highest bit, but now I see you test it with bgez... In that case I suppose it makes sense to use bit 31 for 32BIT, which still leaves 6 bits for the processor id - potentially expandable back to 7 by shifting the processor id down a couple of bits and utilising the masking that you've added).
arch/mips/include/asm/stackframe.h line 105
Quoted 3 lines
arch/mips/include/asm/stackframe.h +2
-0+ + .macro get_saved_sp_for_save_some /* SMP variation */CPU_ID_MFC0 k0,CPU_ID_REG
I suspect this shouldn't be here since both users of the macro already seem to ensure it's done.
Quoted 37 lines
arch/mips/include/asm/stackframe.h +24
-0#if defined(CONFIG_32BIT ) || defined(KBUILD_64BIT_SYM32 ) lui k1, %hi(kernelsp)@@ -110,15 +113,49 @@ dsll k1, 16#endif LONG_SRL k0, PTEBASE_SHIFT +#ifdef CONFIG_KVM_MIPSVZ +andi k0,CPU_ID_MASK /* high bits indicate guest mode. */ +#endif LONG_ADDU k1, k0 LONG_L k1, %lo(kernelsp)(k1) .endm + .macro get_saved_sp + CPU_ID_MFC0 k0, CPU_ID_REG + get_saved_sp_for_save_some + .endm + + .macro get_mips_kvm_rootsp /* SMP variation */ +#if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32) + lui k1, %hi(mips_kvm_rootsp) +#else + lui k1, %highest(mips_kvm_rootsp) + daddiu k1, %higher(mips_kvm_rootsp) + dsll k1, 16 + daddiu k1, %hi(mips_kvm_rootsp) + dsll k1, 16 +#endif + LONG_SRL k0, PTEBASE_SHIFT + andi k0, CPU_ID_MASK /* high bits indicate guest mode. */ + LONG_ADDU k1, k0 + LONG_L k1, %lo(mips_kvm_rootsp)(k1) + .endm + .macro set_saved_sp stackp temp temp2 CPU_ID_MFC0 \temp, CPU_ID_REG LONG_SRL \temp, PTEBASE_SHIFT
arch/mips/include/asm/stackframe.h line 156
Quoted 10 lines
arch/mips/include/asm/stackframe.h +8
-0+#ifdef CONFIG_KVM_MIPSVZ +andi k0,CPU_ID_MASK /* high bits indicate guest mode. */ +#endif LONG_S \stackp, kernelsp(\temp) .endm + + .macro set_mips_kvm_rootsp stackp temp + CPU_ID_MFC0 \temp, CPU_ID_REG + LONG_SRL \temp, PTEBASE_SHIFT + andi k0, CPU_ID_MASK /* high bits indicate guest mode. */
Should that be s/k0/\temp/?
Quoted 34 lines
arch/mips/include/asm/stackframe.h +20
-0+ LONG_S \stackp, mips_kvm_rootsp(\temp) + .endm #else .macro get_saved_sp /* Uniprocessor variation */#ifdef CONFIG_CPU_JUMP_WORKAROUNDS @@ -152,9 +189,27 @@ LONG_L k1, %lo(kernelsp)(k1) .endm + .macro get_mips_kvm_rootsp /* Uniprocessor variation */ +#if defined(CONFIG_32BIT) || defined(KBUILD_64BIT_SYM32) + lui k1, %hi(mips_kvm_rootsp) +#else + lui k1, %highest(mips_kvm_rootsp) + daddiu k1, %higher(mips_kvm_rootsp) + dsll k1, k1, 16 + daddiu k1, %hi(mips_kvm_rootsp) + dsll k1, k1, 16 +#endif + LONG_L k1, %lo(mips_kvm_rootsp)(k1) + .endm + + .macro set_saved_sp stackp temp temp2 LONG_S \stackp, kernelsp .endm + + .macro set_mips_kvm_rootsp stackp temp + LONG_S \stackp, mips_kvm_rootsp + .endm #endif .macro SAVE_SOME
arch/mips/include/asm/stackframe.h line 223
Quoted 5 lines
arch/mips/include/asm/stackframe.h +2
-0@@ -164,11 +219,21 @@mfc0 k0,CP0_STATUS sll k0, 3 /* extract cu0 bit */ .set noreorder +#ifdef CONFIG_KVM_MIPSVZ + bgez k0, 7f
brief comments around here would make it easier to follow, e.g. /* from kernel */
...
arch/mips/include/asm/stackframe.h line 225
Quoted 2 lines
arch/mips/include/asm/stackframe.h +2
-0+CPU_ID_MFC0 k0,CPU_ID_REG + bgez k0, 8f
/* from userland */
arch/mips/include/asm/stackframe.h line 226
Quoted 1 line
arch/mips/include/asm/stackframe.h +1
-0+move k1, sp
/* from guest */
arch/mips/include/asm/stackframe.h line 236
Quoted 11 lines
arch/mips/include/asm/stackframe.h +6
-1+get_mips_kvm_rootsp + b 8f + nop +#else bltz k0, 8f move k1, sp +#endif .set reorder /* Called from user mode, new stack. */ - get_saved_sp +7: get_saved_sp_for_save_some
you don't appear to have defined a !CONFIG_SMP version of get_saved_sp_for_save_some?
arch/mips/include/asm/stackframe.h line 300
Quoted 13 lines
arch/mips/include/asm/stackframe.h +6
-0#ifndef CONFIG_CPU_DADDI_WORKAROUNDS 8: move k0, sp PTR_SUBU sp, k1, PT_SIZE@@ -227,6 +292,35 @@ LONG_S $31, PT_R31(sp) ori $28, sp, _THREAD_MASK xori $28, _THREAD_MASK +#ifdef CONFIG_KVM_MIPSVZ + CPU_ID_MFC0 k0, CPU_ID_REG + .set noreorder + bgez k0, 8f +/* Must clear GuestCtl0[GM] */ + dins k0, zero, 63, 1
Looks like we need a LONG_INS (and friends) defined in asm.h for this
arch/mips/include/asm/stackframe.h line 302
Quoted 2 lines
arch/mips/include/asm/stackframe.h +2
-0+ .set reorder +dmtc0 k0,CPU_ID_REG
Lets define a CPU_ID_MTC0 similar to CPU_ID_MFC0.
arch/mips/include/asm/stackframe.h line 308
Quoted 6 lines
arch/mips/include/asm/stackframe.h +6
-0+mfc0 k0,CP0_GUESTCTL0 + ins k0, zero, MIPS_GUESTCTL0B_GM, 1 + mtc0 k0, CP0_GUESTCTL0 + LONG_L v0, TI_TASK($28) + lw v1, THREAD_MM_ASID(v0) + dmtc0 v1, CP0_ENTRYHI
MTC0.
Quoted 19 lines
arch/mips/include/asm/stackframe.h +15
-0+ LONG_L v1, TASK_MM(v0) + .set noreorder + jal tlbmiss_handler_setup_pgd_array + LONG_L a0, MM_PGD(v1) + .set reorder + /* + * With KVM_MIPSVZ, we must not clobber k0/k1 + * they were saved before they were used + */ +8: + MFC0 k0, CP0_KSCRATCH1 + MFC0 v1, CP0_KSCRATCH2 + LONG_S k0, PT_R26(sp) + LONG_S v1, PT_R27(sp) +#endif #ifdef CONFIG_CPU_CAVIUM_OCTEON .set mips64 pref 0, 0($28) /* Prefetch the current pointer */
arch/mips/include/asm/stackframe.h line 536
Quoted 4 lines
arch/mips/include/asm/stackframe.h +1
-0@@ -439,10 +533,45 @@ .set mips0#endif /* CONFIG_MIPS_MT_SMTC */ LONG_L v1, PT_EPC(sp) + LONG_L $25, PT_R25(sp)
Is this an optimisation? It's unclear why it's been moved.
Quoted 6 lines
arch/mips/include/asm/stackframe.h +5
-0MTC0 v1, CP0_EPC +#ifdef CONFIG_KVM_MIPSVZ +/* +* Only if TIF_GUESTMODE && sp is the saved KVM sp, return to +* guest mode. +*/
arch/mips/include/asm/stackframe.h line 552
Quoted 10 lines
arch/mips/include/asm/stackframe.h +10
-0+ LONG_L v0, TI_FLAGS($28) + li k1, _TIF_GUESTMODE + and v0, v0, k1 + beqz v0, 8f + CPU_ID_MFC0 k0, CPU_ID_REG + get_mips_kvm_rootsp + PTR_SUBU k1, k1, PT_SIZE + bne k1, sp, 8f +/* Set the high order bit of CPU_ID_REG to indicate guest mode. */ + dli v0, 1
I think li will do here.
arch/mips/include/asm/stackframe.h line 553
Quoted 1 line
arch/mips/include/asm/stackframe.h +1
-0+dmfc0 v1,CPU_ID_REG
CPU_ID_MFC0
arch/mips/include/asm/stackframe.h line 554
Quoted 1 line
arch/mips/include/asm/stackframe.h +1
-0+ dins v1, v0, 63, 1
LONG_INS
arch/mips/include/asm/stackframe.h line 555
Quoted 1 line
arch/mips/include/asm/stackframe.h +1
-0+dmtc0 v1,CPU_ID_REG
CPU_ID_MTC0
arch/mips/include/asm/stackframe.h line 563
Quoted 8 lines
arch/mips/include/asm/stackframe.h +8
-0+/* Must set GuestCtl0[GM] */ +mfc0 v1,CP0_GUESTCTL0 + ins v1, v0, MIPS_GUESTCTL0B_GM, 1 + mtc0 v1, CP0_GUESTCTL0 + + LONG_L v0, TI_TASK($28) + lw v1, THREAD_GUEST_ASID(v0) + dmtc0 v1, CP0_ENTRYHI
MTC0
Quoted 6 lines
arch/mips/include/asm/stackframe.h +5
-0+ LONG_L v1, THREAD_VCPU(v0) + LONG_L v1, KVM_VCPU_KVM(v1) + LONG_L v1, KVM_ARCH_IMPL(v1) + .set noreorder + jal tlbmiss_handler_setup_pgd_array
arch/mips/include/asm/stackframe.h line 577
Quoted 10 lines
arch/mips/include/asm/stackframe.h +4
-1+ LONG_L a0, KVM_MIPS_VZ_PGD(v1) + .set reorder +8: +#endif LONG_L $31, PT_R31(sp) LONG_L $28, PT_R28(sp) - LONG_L $25, PT_R25(sp)#ifdef CONFIG_64BIT LONG_L $8, PT_R8(sp) LONG_L $9, PT_R9(sp)
Cheers
James