KVM: PPC: Book3S HV: Fix CR0 setting in TM emulation
Subsystems (2)
PATCH 1/1 KVM: PPC: Book3S HV: Fix CR0 setting in TM emulation
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] || 0This fixes the bit shift to put the bits in the correct location.
--- arch/powerpc/kvm/book3s_hv_tm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/kvm/book3s_hv_tm.c +3 -3
@@ -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 ; }
Signature · 1 line
2.21.0
Michael Ellerman
reviewerQuoted 5 lines · Michael Neuling
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
Seems bad, what's the worst case impact?
Do we have a test case for this?
Quoted 1 line
This fixes the bit shift to put the bits in the correct location.
cheers
Quoted 33 lines
arch/powerpc/kvm/book3s_hv_tm.c +3
-3@@ -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 ; }Signature · 1 line
2.21.0
Quoted 8 lines · Michael Ellerman
Quoted 5 lines · Michael Neuling
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] || 0Seems bad, what's the worst case impact?
It's a data integrity issue as CR0 is corrupted.
Quoted 1 line
Do we have a test case for this?
Suraj has a KVM unit test for it.
Quoted 3 lines
Quoted 1 line
This fixes the bit shift to put the bits in the correct location.
Fixes ?
It's been around since we first wrote the code so:
Mikey
Michael Ellerman
AppliedQuoted 10 lines · Michael Neuling
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] || 0This fixes the bit shift to put the bits in the correct location.
Tested-by Suraj Jitindar Singh <[email protected]>Signed-off-by Michael Neuling <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/3fefd1cd95df04da67c83c1cb93b663f04b3324f
cheers