@@ -2687,6 +2687,10 @@ static int kvmppc_vcpu_run_hv(struct kvm_run *run, struct kvm_vcpu *vcpu)
26872687{
26882688 int r ;
26892689 int srcu_idx ;
2690+ unsigned long ebb_regs [3 ] = {}; /* shut up GCC */
2691+ unsigned long user_tar = 0 ;
2692+ unsigned long proc_fscr = 0 ;
2693+ unsigned int user_vrsave ;
26902694
26912695 if (!vcpu -> arch .sane ) {
26922696 run -> exit_reason = KVM_EXIT_INTERNAL_ERROR ;
@@ -2707,10 +2711,11 @@ static int kvmppc_vcpu_run_hv(struct kvm_run *run, struct kvm_vcpu *vcpu)
27072711 run -> fail_entry .hardware_entry_failure_reason = 0 ;
27082712 return - EINVAL ;
27092713 }
2714+ /* Enable TM so we can read the TM SPRs */
2715+ mtmsr (mfmsr () | MSR_TM );
27102716 current -> thread .tm_tfhar = mfspr (SPRN_TFHAR );
27112717 current -> thread .tm_tfiar = mfspr (SPRN_TFIAR );
27122718 current -> thread .tm_texasr = mfspr (SPRN_TEXASR );
2713- current -> thread .regs -> msr &= ~MSR_TM ;
27142719 }
27152720#endif
27162721
@@ -2736,6 +2741,17 @@ static int kvmppc_vcpu_run_hv(struct kvm_run *run, struct kvm_vcpu *vcpu)
27362741 flush_fp_to_thread (current );
27372742 flush_altivec_to_thread (current );
27382743 flush_vsx_to_thread (current );
2744+
2745+ /* Save userspace EBB and other register values */
2746+ if (cpu_has_feature (CPU_FTR_ARCH_207S )) {
2747+ ebb_regs [0 ] = mfspr (SPRN_EBBHR );
2748+ ebb_regs [1 ] = mfspr (SPRN_EBBRR );
2749+ ebb_regs [2 ] = mfspr (SPRN_BESCR );
2750+ user_tar = mfspr (SPRN_TAR );
2751+ proc_fscr = mfspr (SPRN_FSCR );
2752+ }
2753+ user_vrsave = mfspr (SPRN_VRSAVE );
2754+
27392755 vcpu -> arch .wqp = & vcpu -> arch .vcore -> wq ;
27402756 vcpu -> arch .pgdir = current -> mm -> pgd ;
27412757 vcpu -> arch .state = KVMPPC_VCPU_BUSY_IN_HOST ;
@@ -2757,6 +2773,29 @@ static int kvmppc_vcpu_run_hv(struct kvm_run *run, struct kvm_vcpu *vcpu)
27572773 }
27582774 } while (is_kvmppc_resume_guest (r ));
27592775
2776+ /* Restore userspace EBB and other register values */
2777+ if (cpu_has_feature (CPU_FTR_ARCH_207S )) {
2778+ mtspr (SPRN_EBBHR , ebb_regs [0 ]);
2779+ mtspr (SPRN_EBBRR , ebb_regs [1 ]);
2780+ mtspr (SPRN_BESCR , ebb_regs [2 ]);
2781+ mtspr (SPRN_TAR , user_tar );
2782+ mtspr (SPRN_FSCR , proc_fscr );
2783+ }
2784+ mtspr (SPRN_VRSAVE , user_vrsave );
2785+
2786+ /*
2787+ * Since we don't do lazy TM reload, we need to reload
2788+ * the TM registers here.
2789+ */
2790+ #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
2791+ if (cpu_has_feature (CPU_FTR_TM ) && current -> thread .regs &&
2792+ (current -> thread .regs -> msr & MSR_TM )) {
2793+ mtspr (SPRN_TFHAR , current -> thread .tm_tfhar );
2794+ mtspr (SPRN_TFIAR , current -> thread .tm_tfiar );
2795+ mtspr (SPRN_TEXASR , current -> thread .tm_texasr );
2796+ }
2797+ #endif
2798+
27602799 out :
27612800 vcpu -> arch .state = KVMPPC_VCPU_NOTREADY ;
27622801 atomic_dec (& vcpu -> kvm -> arch .vcpus_running );
0 commit comments