KVM: PPC: Book3S HV: Fix CR0 setting in TM emulation
authorMichael Neuling <mikey@neuling.org>
Thu, 20 Jun 2019 06:00:40 +0000 (16:00 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 3 Jul 2019 05:19:36 +0000 (15:19 +1000)
When emulating tsr, treclaim and trechkpt, we incorrectly set CR0. The
code currently sets:
    CR0 <- 00 || MSR[TS]
but according to the ISA it should be:
    CR0 <-  0 || MSR[TS] || 0

This fixes the bit shift to put the bits in the correct location.

This is a data integrity issue as CR0 is corrupted.

Fixes: 4bb3c7a0208f ("KVM: PPC: Book3S HV: Work around transactional memory bugs in POWER9")
Cc: stable@vger.kernel.org # v4.17+
Tested-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Signed-off-by: Michael Neuling <mikey@neuling.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/kvm/book3s_hv_tm.c

index 888e2609e3f156322cac1ac0bde0529db7193359..31cd0f327c8a2d5af48401001be86a1747b8ae51 100644 (file)
@@ -131,7 +131,7 @@ int kvmhv_p9_tm_emulation(struct kvm_vcpu *vcpu)
                }
                /* Set CR0 to indicate previous transactional state */
                vcpu->arch.regs.ccr = (vcpu->arch.regs.ccr & 0x0fffffff) |
-                       (((msr & MSR_TS_MASK) >> MSR_TS_S_LG) << 28);
+                       (((msr & MSR_TS_MASK) >> MSR_TS_S_LG) << 29);
                /* L=1 => tresume, L=0 => tsuspend */
                if (instr & (1 << 21)) {
                        if (MSR_TM_SUSPENDED(msr))
@@ -175,7 +175,7 @@ int kvmhv_p9_tm_emulation(struct kvm_vcpu *vcpu)
 
                /* Set CR0 to indicate previous transactional state */
                vcpu->arch.regs.ccr = (vcpu->arch.regs.ccr & 0x0fffffff) |
-                       (((msr & MSR_TS_MASK) >> MSR_TS_S_LG) << 28);
+                       (((msr & MSR_TS_MASK) >> MSR_TS_S_LG) << 29);
                vcpu->arch.shregs.msr &= ~MSR_TS_MASK;
                return RESUME_GUEST;
 
@@ -205,7 +205,7 @@ int kvmhv_p9_tm_emulation(struct kvm_vcpu *vcpu)
 
                /* Set CR0 to indicate previous transactional state */
                vcpu->arch.regs.ccr = (vcpu->arch.regs.ccr & 0x0fffffff) |
-                       (((msr & MSR_TS_MASK) >> MSR_TS_S_LG) << 28);
+                       (((msr & MSR_TS_MASK) >> MSR_TS_S_LG) << 29);
                vcpu->arch.shregs.msr = msr | MSR_TS_S;
                return RESUME_GUEST;
        }