KVM: PPC: Unify FP/VMX/VSX state handling between KVM and main kernel
Subsystems (3)
cover KVM: PPC: Unify FP/VMX/VSX state handling between KVM and main kernel
This series makes use of the new thread_fp_state and thread_vr_state structures to unify the way that floating-point and vector state is handled. With both KVM and the main kernel using the same structures to store this state for various contexts, we can reduce the amount of code for loading and storing this state and also eliminate some extra copies. Overall, this series removes a net 240 lines of code.
This series also provides the foundation for implementing support for POWER8 transactional memory in KVM.
These patches are against the merge of Ben Herrenschmidt's for-kvm branch and Alex Graf's kvm-ppc-queue branch.
Paul.
--- arch/powerpc/include/asm/kvm_book3s.h | 3 - arch/powerpc/include/asm/kvm_host.h | 12 +-- arch/powerpc/include/asm/switch_to.h | 2 - arch/powerpc/kernel/asm-offsets.c | 9 +- arch/powerpc/kvm/book3s.c | 38 +++++-- arch/powerpc/kvm/book3s_exports.c | 4 - arch/powerpc/kvm/book3s_hv.c | 42 -------- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 82 ++++----------- arch/powerpc/kvm/book3s_paired_singles.c | 169 +++++++++++++++---------------- arch/powerpc/kvm/book3s_pr.c | 137 +++++-------------------- arch/powerpc/kvm/book3s_rmhandlers.S | 47 --------- arch/powerpc/kvm/booke.c | 20 ---- arch/powerpc/kvm/booke.h | 5 +- arch/powerpc/kvm/powerpc.c | 4 +- 14 files changed, 167 insertions(+), 407 deletions(-)
PATCH 1/4 KVM: PPC: Use load_fp/vr_state rather than load_up_fpu/altivec
The load_up_fpu and load_up_altivec functions were never intended to be called from C, and do things like modifying the MSR value in their callers' stack frames, which are assumed to be interrupt frames. In addition, on 32-bit Book S they require the MMU to be off.
This makes KVM use the new load_fp_state() and load_vr_state() functions instead of load_up_fpu/altivec. This means we can remove the assembler glue in book3s_rmhandlers.S, and potentially fixes a bug on Book E, where load_up_fpu was called directly from C.
--- arch/powerpc/include/asm/kvm_book3s.h | 3 --- arch/powerpc/include/asm/switch_to.h | 2 -- arch/powerpc/kvm/book3s_exports.c | 4 --- arch/powerpc/kvm/book3s_pr.c | 18 +++++++++----- arch/powerpc/kvm/book3s_rmhandlers.S | 47 ----------------------------------- arch/powerpc/kvm/booke.h | 3 ++- 6 files changed, 14 insertions(+), 63 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +0 -3
@@ -187,9 +187,6 @@ extern void kvmppc_update_lpcr(struct kvm *kvm, unsigned long lpcr,extern void kvmppc_entry_trampoline (void );extern void kvmppc_hv_entry_trampoline (void ); -extern void kvmppc_load_up_fpu (void ); -extern void kvmppc_load_up_altivec (void ); -extern void kvmppc_load_up_vsx (void );extern u32 kvmppc_alignment_dsisr (struct kvm_vcpu *vcpu,unsigned int inst);extern ulong kvmppc_alignment_dar (struct kvm_vcpu *vcpu,unsigned int inst);extern int kvmppc_h_pr (struct kvm_vcpu *vcpu,unsigned long cmd);
arch/powerpc/include/asm/switch_to.h +0 -2
@@ -25,10 +25,8 @@ static inline void save_tar(struct thread_struct *prev)static inline void save_tar (struct thread_struct *prev) {}#endif -extern void load_up_fpu (void );extern void enable_kernel_fp (void );extern void enable_kernel_altivec (void ); -extern void load_up_altivec (struct task_struct *);extern int emulate_altivec (struct pt_regs *);extern void __giveup_vsx (struct task_struct *);extern void giveup_vsx (struct task_struct *);
arch/powerpc/kvm/book3s_exports.c +0 -4
@@ -24,9 +24,5 @@EXPORT_SYMBOL_GPL (kvmppc_hv_entry_trampoline);#else EXPORT_SYMBOL_GPL (kvmppc_entry_trampoline); -EXPORT_SYMBOL_GPL (kvmppc_load_up_fpu); -#ifdef CONFIG_ALTIVEC -EXPORT_SYMBOL_GPL (kvmppc_load_up_altivec); -#endif #endif
arch/powerpc/kvm/book3s_pr.c +12 -6
@@ -685,7 +685,8 @@ static int kvmppc_handle_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr,#endif t->fp_state.fpscr = vcpu->arch.fpscr; t->fpexc_mode =0 ; -kvmppc_load_up_fpu (); +enable_kernel_fp (); +load_fp_state (&t->fp_state); }if (msr &MSR_VEC ) {
@@ -693,7 +694,8 @@ static int kvmppc_handle_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr,memcpy (t->vr_state.vr, vcpu->arch.vr,sizeof (vcpu->arch.vr)); t->vr_state.vscr = vcpu->arch.vscr; t->vrsave =-1 ; -kvmppc_load_up_altivec (); +enable_kernel_altivec (); +load_vr_state (&t->vr_state);#endif }
@@ -716,11 +718,15 @@ static void kvmppc_handle_lost_ext(struct kvm_vcpu *vcpu)if (!lost_ext)return ; -if (lost_ext &MSR_FP ) -kvmppc_load_up_fpu (); +if (lost_ext &MSR_FP ) { +enable_kernel_fp (); +load_fp_state (¤t->thread.fp_state); + }#ifdef CONFIG_ALTIVEC -if (lost_ext &MSR_VEC ) -kvmppc_load_up_altivec (); +if (lost_ext &MSR_VEC ) { +enable_kernel_altivec (); +load_vr_state (¤t->thread.vr_state); + }#endif current->thread.regs->msr |= lost_ext; }
arch/powerpc/kvm/book3s_rmhandlers.S +0 -47
51 lines not on this page · raw message
arch/powerpc/kvm/booke.h +2 -1
@@ -112,7 +112,8 @@ static inline void kvmppc_load_guest_fp(struct kvm_vcpu *vcpu) {#ifdef CONFIG_PPC_FPU if (vcpu->fpu_active && !(current->thread.regs->msr &MSR_FP )) { -load_up_fpu (); +enable_kernel_fp (); +load_fp_state (¤t->thread.fp_state); current->thread.regs->msr |=MSR_FP ; }#endif
Signature · 1 line
1.8.4.rc3
PATCH 2/4 KVM: PPC: Store FP/VSX/VMX state in thread_fp/vr_state structures
In reply to Paul MackerrasThis uses struct thread_fp_state and struct thread_vr_state to store the floating-point, VMX/Altivec and VSX state, rather than flat arrays. This makes transferring the state to/from the thread_struct simpler and allows us to unify the get/set_one_reg implementations for the VSX registers.
--- arch/powerpc/include/asm/kvm_host.h | 12 +-- arch/powerpc/kernel/asm-offsets.c | 11 +- arch/powerpc/kvm/book3s.c | 38 +++++-- arch/powerpc/kvm/book3s_hv.c | 42 -------- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 4 +- arch/powerpc/kvm/book3s_paired_singles.c | 169 +++++++++++++++---------------- arch/powerpc/kvm/book3s_pr.c | 63 +----------- arch/powerpc/kvm/booke.c | 8 +- arch/powerpc/kvm/powerpc.c | 4 +- 9 files changed, 131 insertions(+), 220 deletions(-)
arch/powerpc/include/asm/kvm_host.h +4 -8
@@ -414,8 +414,7 @@ struct kvm_vcpu_arch {ulong gpr[32 ]; -u64 fpr[32 ]; -u64 fpscr; +struct thread_fp_state fp;#ifdef CONFIG_SPE ulong evr[32 ];
@@ -424,12 +423,7 @@ struct kvm_vcpu_arch {u64 acc;#endif #ifdef CONFIG_ALTIVEC -vector128 vr[32 ]; -vector128 vscr; -#endif - -#ifdef CONFIG_VSX -u64 vsr[64 ]; +struct thread_vr_state vr;#endif #ifdef CONFIG_KVM_BOOKE_HV
@@ -623,6 +617,8 @@ struct kvm_vcpu_arch {#endif }; +#define VCPU_FPR (vcpu, i) (vcpu)->arch.fp.fpr[i][TS_FPROFFSET] +/* Values for vcpu->arch.state */ #define KVMPPC_VCPU_NOTREADY 0#define KVMPPC_VCPU_RUNNABLE 1
arch/powerpc/kernel/asm-offsets.c +4 -7
@@ -425,14 +425,11 @@ int main(void) DEFINE(VCPU_GUEST_PID, offsetof(struct kvm_vcpu, arch.pid)); DEFINE(VCPU_GPRS, offsetof(struct kvm_vcpu, arch.gpr)); DEFINE(VCPU_VRSAVE, offsetof(struct kvm_vcpu, arch.vrsave)); - DEFINE(VCPU_FPRS, offsetof(struct kvm_vcpu, arch.fpr)); - DEFINE(VCPU_FPSCR, offsetof(struct kvm_vcpu, arch.fpscr)); + DEFINE(VCPU_FPRS, offsetof(struct kvm_vcpu, arch.fp.fpr)); + DEFINE(VCPU_FPSCR, offsetof(struct kvm_vcpu, arch.fp.fpscr));#ifdef CONFIG_ALTIVEC - DEFINE(VCPU_VRS, offsetof(struct kvm_vcpu, arch.vr)); - DEFINE(VCPU_VSCR, offsetof(struct kvm_vcpu, arch.vscr)); -#endif -#ifdef CONFIG_VSX - DEFINE(VCPU_VSRS, offsetof(struct kvm_vcpu, arch.vsr)); + DEFINE(VCPU_VRS, offsetof(struct kvm_vcpu, arch.vr.vr)); + DEFINE(VCPU_VSCR, offsetof(struct kvm_vcpu, arch.vr.vscr));#endif DEFINE(VCPU_XER, offsetof(struct kvm_vcpu, arch.xer)); DEFINE(VCPU_CTR, offsetof(struct kvm_vcpu, arch.ctr));
arch/powerpc/kvm/book3s.c +30 -8
@@ -511,10 +511,10 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)break ; case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31: i = reg->id -KVM_REG_PPC_FPR0 ; - val =get_reg_val (reg->id, vcpu->arch.fpr[i]); + val =get_reg_val (reg->id,VCPU_FPR (vcpu, i));break ;case KVM_REG_PPC_FPSCR : - val =get_reg_val (reg->id, vcpu->arch.fpscr); + val =get_reg_val (reg->id, vcpu->arch.fp.fpscr);break ;#ifdef CONFIG_ALTIVEC case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
@@ -522,19 +522,30 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) r = -ENXIO ;break ; } - val.vval = vcpu->arch.vr[reg->id -KVM_REG_PPC_VR0 ]; + val.vval = vcpu->arch.vr.vr[reg->id -KVM_REG_PPC_VR0 ];break ;case KVM_REG_PPC_VSCR :if (!cpu_has_feature (CPU_FTR_ALTIVEC )) { r = -ENXIO ;break ; } - val =get_reg_val (reg->id, vcpu->arch.vscr.u[3 ]); + val =get_reg_val (reg->id, vcpu->arch.vr.vscr.u[3 ]);break ;case KVM_REG_PPC_VRSAVE : val =get_reg_val (reg->id, vcpu->arch.vrsave);break ;#endif /* CONFIG_ALTIVEC */ +#ifdef CONFIG_VSX + case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31: +if (cpu_has_feature (CPU_FTR_VSX )) { +long int i = reg->id -KVM_REG_PPC_VSR0 ; + val.vsxval[0 ] = vcpu->arch.fp.fpr[i][0 ]; + val.vsxval[1 ] = vcpu->arch.fp.fpr[i][1 ]; + }else { + r = -ENXIO ; + } +break ; +#endif /* CONFIG_VSX */ case KVM_REG_PPC_DEBUG_INST : {u32 opcode =INS_TW ; r = copy_to_user((u32 __user *)(long)reg->addr,
@@ -591,10 +602,10 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)break ; case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31: i = reg->id -KVM_REG_PPC_FPR0 ; - vcpu->arch.fpr[i] =set_reg_val (reg->id, val); +VCPU_FPR (vcpu, i) =set_reg_val (reg->id, val);break ;case KVM_REG_PPC_FPSCR : - vcpu->arch.fpscr =set_reg_val (reg->id, val); + vcpu->arch.fp.fpscr =set_reg_val (reg->id, val);break ;#ifdef CONFIG_ALTIVEC case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
@@ -602,14 +613,14 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) r = -ENXIO ;break ; } - vcpu->arch.vr[reg->id -KVM_REG_PPC_VR0 ] = val.vval; + vcpu->arch.vr.vr[reg->id -KVM_REG_PPC_VR0 ] = val.vval;break ;case KVM_REG_PPC_VSCR :if (!cpu_has_feature (CPU_FTR_ALTIVEC )) { r = -ENXIO ;break ; } - vcpu->arch.vscr.u[3 ] =set_reg_val (reg->id, val); + vcpu->arch.vr.vscr.u[3 ] =set_reg_val (reg->id, val);break ;case KVM_REG_PPC_VRSAVE :if (!cpu_has_feature (CPU_FTR_ALTIVEC )) {
@@ -619,6 +630,17 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) vcpu->arch.vrsave =set_reg_val (reg->id, val);break ;#endif /* CONFIG_ALTIVEC */ +#ifdef CONFIG_VSX + case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31: +if (cpu_has_feature (CPU_FTR_VSX )) { +long int i = reg->id -KVM_REG_PPC_VSR0 ; + vcpu->arch.fp.fpr[i][0 ] = val.vsxval[0 ]; + vcpu->arch.fp.fpr[i][1 ] = val.vsxval[1 ]; + }else { + r = -ENXIO ; + } +break ; +#endif /* CONFIG_VSX */ #ifdef CONFIG_KVM_XICS case KVM_REG_PPC_ICP_STATE :if (!vcpu->arch.icp) {
arch/powerpc/kvm/book3s_hv.c +0 -42
54 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_rmhandlers.S +2 -2
@@ -1867,7 +1867,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_VSX) BEGIN_FTR_SECTION reg = 0 .rept 32 - li r6,reg*16+VCPU_VSRS + li r6,reg*16+VCPU_FPRS STXVD2X(reg,R6,R3) reg = reg + 1 .endr
@@ -1929,7 +1929,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_VSX) BEGIN_FTR_SECTION reg = 0 .rept 32 - li r7,reg*16+VCPU_VSRS + li r7,reg*16+VCPU_FPRS LXVD2X(reg,R7,R4) reg = reg + 1 .endr
arch/powerpc/kvm/book3s_paired_singles.c +83 -86
455 lines not on this page · raw message
arch/powerpc/kvm/book3s_pr.c +4 -59
111 lines not on this page · raw message
arch/powerpc/kvm/booke.c +2 -6
@@ -705,9 +705,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) fpexc_mode = current->thread.fpexc_mode;/* Restore guest FPU state to thread */ -memcpy (current->thread.fp_state.fpr, vcpu->arch.fpr, -sizeof (vcpu->arch.fpr)); - current->thread.fp_state.fpscr = vcpu->arch.fpscr; + current->thread.fp_state = vcpu->arch.fp;/* * Since we can't trap on MSR_FP in GS-mode, we consider the guest
@@ -743,9 +741,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) vcpu->fpu_active =0 ;/* Save guest FPU state from thread */ -memcpy (vcpu->arch.fpr, current->thread.fp_state.fpr, -sizeof (vcpu->arch.fpr)); - vcpu->arch.fpscr = current->thread.fp_state.fpscr; + vcpu->arch.fp = current->thread.fp_state;/* Restore userspace FPU state from stack */ current->thread.fp_state = fp;
arch/powerpc/kvm/powerpc.c +2 -2
@@ -608,14 +608,14 @@ static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu,kvmppc_set_gpr (vcpu, vcpu->arch.io_gpr, gpr);break ;case KVM_MMIO_REG_FPR : - vcpu->arch.fpr[vcpu->arch.io_gpr &KVM_MMIO_REG_MASK ] = gpr; +VCPU_FPR (vcpu, vcpu->arch.io_gpr &KVM_MMIO_REG_MASK ) = gpr;break ;#ifdef CONFIG_PPC_BOOK3S case KVM_MMIO_REG_QPR : vcpu->arch.qpr[vcpu->arch.io_gpr &KVM_MMIO_REG_MASK ] = gpr;break ;case KVM_MMIO_REG_FQPR : - vcpu->arch.fpr[vcpu->arch.io_gpr &KVM_MMIO_REG_MASK ] = gpr; +VCPU_FPR (vcpu, vcpu->arch.io_gpr &KVM_MMIO_REG_MASK ) = gpr; vcpu->arch.qpr[vcpu->arch.io_gpr &KVM_MMIO_REG_MASK ] = gpr;break ;#endif
Signature · 1 line
1.8.4.rc3
PATCH 3/4 KVM: PPC: Load/save FP/VMX/VSX state directly to/from vcpu struct
In reply to Paul MackerrasNow that we have the vcpu floating-point and vector state stored in the same type of struct as the main kernel uses, we can load that state directly from the vcpu struct instead of having extra copies to/from the thread_struct. Similarly, when the guest state needs to be saved, we can have it saved it directly to the vcpu struct by setting the current->thread.fp_save_area and current->thread.vr_save_area pointers. That also means that we don't need to back up and restore userspace's FP/vector state. This all makes the code simpler and faster.
Note that it's not necessary to save or modify current->thread.fpexc_mode, since nothing in KVM uses or is affected by its value. Nor is it necessary to touch used_vr or used_vsr.
--- arch/powerpc/kvm/book3s_pr.c | 72 ++++++++++---------------------------------- arch/powerpc/kvm/booke.c | 16 ---------- arch/powerpc/kvm/booke.h | 4 ++- 3 files changed, 19 insertions(+), 73 deletions(-)
arch/powerpc/kvm/book3s_pr.c +16 -56
@@ -561,16 +561,16 @@ void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr)* both the traditional FP registers and the added VSX * registers into thread.fp_state.fpr[]. */ -if (current->thread.regs->msr &MSR_FP ) +if (t->regs->msr &MSR_FP )giveup_fpu (current); - vcpu->arch.fp = t->fp_state; + t->fp_save_area =NULL ; }#ifdef CONFIG_ALTIVEC if (msr &MSR_VEC ) {if (current->thread.regs->msr &MSR_VEC )giveup_altivec (current); - vcpu->arch.vr = t->vr_state; + t->vr_save_area =NULL ; }#endif
@@ -655,22 +655,20 @@ static int kvmppc_handle_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr,#endif if (msr &MSR_FP ) { - t->fp_state = vcpu->arch.fp; - t->fpexc_mode =0 ;enable_kernel_fp (); -load_fp_state (&t->fp_state); +load_fp_state (&vcpu->arch.fp); + t->fp_save_area = &vcpu->arch.fp; }if (msr &MSR_VEC ) {#ifdef CONFIG_ALTIVEC - t->vr_state = vcpu->arch.vr; - t->vrsave =-1 ;enable_kernel_altivec (); -load_vr_state (&t->vr_state); +load_vr_state (&vcpu->arch.vr); + t->vr_save_area = &vcpu->arch.vr;#endif } - current->thread.regs->msr |= msr; + t->regs->msr |= msr; vcpu->arch.guest_owned_ext |= msr;kvmppc_recalc_shadow_msr (vcpu);
@@ -691,12 +689,12 @@ static void kvmppc_handle_lost_ext(struct kvm_vcpu *vcpu)if (lost_ext &MSR_FP ) {enable_kernel_fp (); -load_fp_state (¤t->thread.fp_state); +load_fp_state (&vcpu->arch.fp); }#ifdef CONFIG_ALTIVEC if (lost_ext &MSR_VEC ) {enable_kernel_altivec (); -load_vr_state (¤t->thread.vr_state); +load_vr_state (&vcpu->arch.vr); }#endif current->thread.regs->msr |= lost_ext;
@@ -1200,17 +1198,9 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)int kvmppc_vcpu_run (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu) {int ret; -struct thread_fp_state fp; -int fpexc_mode;#ifdef CONFIG_ALTIVEC -struct thread_vr_state vr;unsigned long uninitialized_var (vrsave ); -int used_vr;#endif -#ifdef CONFIG_VSX -int used_vsr; -#endif -ulong ext_msr;/* Check if we can run the vcpu at all */ if (!vcpu->arch.sane) {
@@ -1232,33 +1222,22 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) goto out; } -/* Save FPU state in stack */ +/* Save FPU state in thread_struct */ if (current->thread.regs->msr &MSR_FP )giveup_fpu (current); - fp = current->thread.fp_state; - fpexc_mode = current->thread.fpexc_mode;#ifdef CONFIG_ALTIVEC -/* Save Altivec state in stack */ - used_vr = current->thread.used_vr; -if (used_vr) { -if (current->thread.regs->msr &MSR_VEC ) -giveup_altivec (current); - vr = current->thread.vr_state; - vrsave = current->thread.vrsave; - } +/* Save Altivec state in thread_struct */ +if (current->thread.regs->msr &MSR_VEC ) +giveup_altivec (current);#endif #ifdef CONFIG_VSX -/* Save VSX state in stack */ - used_vsr = current->thread.used_vsr; -if (used_vsr && (current->thread.regs->msr &MSR_VSX )) +/* Save VSX state in thread_struct */ +if (current->thread.regs->msr &MSR_VSX )__giveup_vsx (current);#endif -/* Remember the MSR with disabled extensions */ - ext_msr = current->thread.regs->msr; -/* Preload FPU if it's enabled */ if (vcpu->arch.shared->msr &MSR_FP )kvmppc_handle_ext (vcpu,BOOK3S_INTERRUPT_FP_UNAVAIL ,MSR_FP );
@@ -1273,25 +1252,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)/* Make sure we save the guest FPU/Altivec/VSX state */ kvmppc_giveup_ext (vcpu,MSR_FP |MSR_VEC |MSR_VSX ); - current->thread.regs->msr = ext_msr; - -/* Restore FPU/VSX state from stack */ - current->thread.fp_state = fp; - current->thread.fpexc_mode = fpexc_mode; - -#ifdef CONFIG_ALTIVEC -/* Restore Altivec state from stack */ -if (used_vr && current->thread.used_vr) { - current->thread.vr_state = vr; - current->thread.vrsave = vrsave; - } - current->thread.used_vr = used_vr; -#endif - -#ifdef CONFIG_VSX - current->thread.used_vsr = used_vsr; -#endif - out: vcpu->mode =OUTSIDE_GUEST_MODE ;return ret;
arch/powerpc/kvm/booke.c +0 -16
@@ -680,10 +680,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) {int ret, s;struct thread_struct thread; -#ifdef CONFIG_PPC_FPU -struct thread_fp_state fp; -int fpexc_mode; -#endif if (!vcpu->arch.sane) { kvm_run->exit_reason =KVM_EXIT_INTERNAL_ERROR ;
@@ -701,11 +697,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)#ifdef CONFIG_PPC_FPU /* Save userspace FPU state in stack */ enable_kernel_fp (); - fp = current->thread.fp_state; - fpexc_mode = current->thread.fpexc_mode; - -/* Restore guest FPU state to thread */ - current->thread.fp_state = vcpu->arch.fp;/* * Since we can't trap on MSR_FP in GS-mode, we consider the guest
@@ -739,13 +730,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)kvmppc_save_guest_fp (vcpu); vcpu->fpu_active =0 ; - -/* Save guest FPU state from thread */ - vcpu->arch.fp = current->thread.fp_state; - -/* Restore userspace FPU state from stack */ - current->thread.fp_state = fp; - current->thread.fpexc_mode = fpexc_mode;#endif out:
arch/powerpc/kvm/booke.h +3 -1
@@ -113,7 +113,8 @@ static inline void kvmppc_load_guest_fp(struct kvm_vcpu *vcpu)#ifdef CONFIG_PPC_FPU if (vcpu->fpu_active && !(current->thread.regs->msr &MSR_FP )) {enable_kernel_fp (); -load_fp_state (¤t->thread.fp_state); +load_fp_state (&vcpu->arch.fp); + current->thread.fp_save_area = &vcpu->arch.fp; current->thread.regs->msr |=MSR_FP ; }#endif
@@ -128,6 +129,7 @@ static inline void kvmppc_save_guest_fp(struct kvm_vcpu *vcpu)#ifdef CONFIG_PPC_FPU if (vcpu->fpu_active && (current->thread.regs->msr &MSR_FP ))giveup_fpu (current); + current->thread.fp_save_area =NULL ;#endif }
Signature · 1 line
1.8.4.rc3
PATCH 4/4 KVM: PPC: Book3S HV: Use load/store_fp_state functions in HV guest entry/exit
In reply to Paul MackerrasThis modifies kvmppc_load_fp and kvmppc_save_fp to use the generic FP/VSX and VMX load/store functions instead of open-coding the FP/VSX/VMX load/store instructions. Since kvmppc_load/save_fp don't follow C calling conventions, we make them private symbols within book3s_hv_rmhandlers.S.
--- arch/powerpc/kernel/asm-offsets.c | 2 - arch/powerpc/kvm/book3s_hv_rmhandlers.S | 86 +++++++++------------------------ 2 files changed, 22 insertions(+), 66 deletions(-)
arch/powerpc/kernel/asm-offsets.c +0 -2
@@ -426,10 +426,8 @@ int main(void) DEFINE(VCPU_GPRS, offsetof(struct kvm_vcpu, arch.gpr)); DEFINE(VCPU_VRSAVE, offsetof(struct kvm_vcpu, arch.vrsave)); DEFINE(VCPU_FPRS, offsetof(struct kvm_vcpu, arch.fp.fpr)); - DEFINE(VCPU_FPSCR, offsetof(struct kvm_vcpu, arch.fp.fpscr));#ifdef CONFIG_ALTIVEC DEFINE(VCPU_VRS, offsetof(struct kvm_vcpu, arch.vr.vr)); - DEFINE(VCPU_VSCR, offsetof(struct kvm_vcpu, arch.vr.vscr));#endif DEFINE(VCPU_XER, offsetof(struct kvm_vcpu, arch.xer)); DEFINE(VCPU_CTR, offsetof(struct kvm_vcpu, arch.ctr));
arch/powerpc/kvm/book3s_hv_rmhandlers.S +22 -64
137 lines not on this page · raw message
Signature · 1 line
1.8.4.rc3
Alexander Graf
AppliedQuoted 7 lines · Paul Mackerras
This series makes use of the new
thread_fp_stateandthread_vr_statestructures to unify the way that floating-point and vector state is handled. With both KVM and the main kernel using the same structures to store this state for various contexts, we can reduce the amount of code for loading and storing this state and also eliminate some extra copies. Overall, this series removes a net 240 lines of code.
Quoted 5 lines
This series also provides the foundation for implementing support for POWER8 transactional memory in KVM.
These patches are against the merge of Ben Herrenschmidt's for-kvm branch and Alex Graf's kvm-ppc-queue branch.
Thanks, applied all to kvm-ppc-queue.
Alex