Message ID | 1515665499-31710-23-git-send-email-wei.guo.simon@gmail.com |
---|---|
State | Changes Requested |
Headers | show |
Series | [01/26] KVM: PPC: Book3S PR: Move kvmppc_save_tm/kvmppc_restore_tm to separate file | expand |
On Thu, Jan 11, 2018 at 06:11:35PM +0800, wei.guo.simon@gmail.com wrote: > From: Simon Guo <wei.guo.simon@gmail.com> > > This patch adds host emulation when guest PR KVM executes "trechkpt.", > which is a privileged instruction and will trap into host. > > We firstly copy vcpu ongoing content into vcpu tm checkpoint > content, then perform kvmppc_restore_tm_pr() to do trechkpt. > with updated vcpu tm checkpoint vals. > > Signed-off-by: Simon Guo <wei.guo.simon@gmail.com> [snip] > +static void kvmppc_emulate_trchkpt(struct kvm_vcpu *vcpu) > +{ > + unsigned long guest_msr = kvmppc_get_msr(vcpu); > + > + preempt_disable(); > + vcpu->arch.save_msr_tm = MSR_TS_S; > + vcpu->arch.save_msr_tm &= ~(MSR_FP | MSR_VEC | MSR_VSX); This looks odd, since you are clearing bits when you have just set save_msr_tm to a constant value that doesn't have these bits set. This could be taken as a sign that the previous line has a bug and you meant "|=" or something similar instead of "=". I think you probably did mean "=", in which case you should remove the line clearing FP/VEC/VSX. Paul. -- To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Paul, On Tue, Jan 23, 2018 at 08:36:44PM +1100, Paul Mackerras wrote: > On Thu, Jan 11, 2018 at 06:11:35PM +0800, wei.guo.simon@gmail.com wrote: > > From: Simon Guo <wei.guo.simon@gmail.com> > > > > This patch adds host emulation when guest PR KVM executes "trechkpt.", > > which is a privileged instruction and will trap into host. > > > > We firstly copy vcpu ongoing content into vcpu tm checkpoint > > content, then perform kvmppc_restore_tm_pr() to do trechkpt. > > with updated vcpu tm checkpoint vals. > > > > Signed-off-by: Simon Guo <wei.guo.simon@gmail.com> > > [snip] > > > +static void kvmppc_emulate_trchkpt(struct kvm_vcpu *vcpu) > > +{ > > + unsigned long guest_msr = kvmppc_get_msr(vcpu); > > + > > + preempt_disable(); > > + vcpu->arch.save_msr_tm = MSR_TS_S; > > + vcpu->arch.save_msr_tm &= ~(MSR_FP | MSR_VEC | MSR_VSX); > > This looks odd, since you are clearing bits when you have just set > save_msr_tm to a constant value that doesn't have these bits set. > This could be taken as a sign that the previous line has a bug and you > meant "|=" or something similar instead of "=". I think you probably > did mean "=", in which case you should remove the line clearing > FP/VEC/VSX. I will rework and remove "save_msr_tm" from the code. Thanks, - Simon -- To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/arch/powerpc/kvm/book3s_emulate.c b/arch/powerpc/kvm/book3s_emulate.c index 51c0e20..52a2e46 100644 --- a/arch/powerpc/kvm/book3s_emulate.c +++ b/arch/powerpc/kvm/book3s_emulate.c @@ -52,6 +52,7 @@ #define OP_31_XOP_TBEGIN 654 #define OP_31_XOP_TRECLAIM 942 +#define OP_31_XOP_TRCHKPT 1006 /* DCBZ is actually 1014, but we patch it to 1010 so we get a trap */ #define OP_31_XOP_DCBZ 1010 @@ -94,7 +95,7 @@ static bool spr_allowed(struct kvm_vcpu *vcpu, enum priv_level level) } #ifdef CONFIG_PPC_TRANSACTIONAL_MEM -void kvmppc_copyto_vcpu_tm(struct kvm_vcpu *vcpu) +static void kvmppc_copyto_vcpu_tm(struct kvm_vcpu *vcpu) { memcpy(&vcpu->arch.gpr_tm[0], &vcpu->arch.gpr[0], sizeof(vcpu->arch.gpr_tm)); @@ -166,6 +167,32 @@ static void kvmppc_emulate_treclaim(struct kvm_vcpu *vcpu, int ra_val) tm_disable(); preempt_enable(); } + +static void kvmppc_emulate_trchkpt(struct kvm_vcpu *vcpu) +{ + unsigned long guest_msr = kvmppc_get_msr(vcpu); + + preempt_disable(); + vcpu->arch.save_msr_tm = MSR_TS_S; + vcpu->arch.save_msr_tm &= ~(MSR_FP | MSR_VEC | MSR_VSX); + vcpu->arch.save_msr_tm |= (vcpu->arch.guest_owned_ext & + (MSR_FP | MSR_VEC | MSR_VSX)); + /* + * need flush FP/VEC/VSX to vcpu save area before + * copy. + */ + kvmppc_giveup_ext(vcpu, MSR_VSX); + kvmppc_copyto_vcpu_tm(vcpu); + kvmppc_restore_tm_pr(vcpu); + preempt_enable(); + + /* + * as a result of trecheckpoint. set TS to suspended. + */ + guest_msr &= ~(MSR_TS_MASK); + guest_msr |= MSR_TS_S; + kvmppc_set_msr(vcpu, guest_msr); +} #endif int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu, @@ -457,6 +484,34 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu, kvmppc_emulate_treclaim(vcpu, ra_val); break; } + case OP_31_XOP_TRCHKPT: + { + ulong guest_msr = kvmppc_get_msr(vcpu); + unsigned long texasr; + + /* generate interrupt based on priorities */ + if (guest_msr & MSR_PR) { + /* Privileged Instruction type Program Intr */ + kvmppc_core_queue_program(vcpu, SRR1_PROGPRIV); + emulated = EMULATE_AGAIN; + break; + } + + tm_enable(); + texasr = mfspr(SPRN_TEXASR); + tm_disable(); + + if (MSR_TM_ACTIVE(guest_msr) || + !(texasr & (TEXASR_FS))) { + /* TM bad thing interrupt */ + kvmppc_core_queue_program(vcpu, SRR1_PROGTM); + emulated = EMULATE_AGAIN; + break; + } + + kvmppc_emulate_trchkpt(vcpu); + break; + } #endif default: emulated = EMULATE_FAIL;