Skip to content

Commit 824b950

Browse files
paulusmackgregkh
authored andcommitted
KVM: PPC: Book3S HV: Preserve userspace HTM state properly
commit 46a704f8409f79fd66567ad3f8a7304830a84293 upstream. If userspace attempts to call the KVM_RUN ioctl when it has hardware transactional memory (HTM) enabled, the values that it has put in the HTM-related SPRs TFHAR, TFIAR and TEXASR will get overwritten by guest values. To fix this, we detect this condition and save those SPR values in the thread struct, and disable HTM for the task. If userspace goes to access those SPRs or the HTM facility in future, a TM-unavailable interrupt will occur and the handler will reload those SPRs and re-enable HTM. If userspace has started a transaction and suspended it, we would currently lose the transactional state in the guest entry path and would almost certainly get a "TM Bad Thing" interrupt, which would cause the host to crash. To avoid this, we detect this case and return from the KVM_RUN ioctl with an EINVAL error, with the KVM exit reason set to KVM_EXIT_FAIL_ENTRY. Fixes: b005255 ("KVM: PPC: Book3S HV: Context-switch new POWER8 SPRs", 2014-01-08) Signed-off-by: Paul Mackerras <paulus@ozlabs.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7b88f76 commit 824b950

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

arch/powerpc/kvm/book3s_hv.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,6 +2693,27 @@ static int kvmppc_vcpu_run_hv(struct kvm_run *run, struct kvm_vcpu *vcpu)
26932693
return -EINVAL;
26942694
}
26952695

2696+
/*
2697+
* Don't allow entry with a suspended transaction, because
2698+
* the guest entry/exit code will lose it.
2699+
* If the guest has TM enabled, save away their TM-related SPRs
2700+
* (they will get restored by the TM unavailable interrupt).
2701+
*/
2702+
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
2703+
if (cpu_has_feature(CPU_FTR_TM) && current->thread.regs &&
2704+
(current->thread.regs->msr & MSR_TM)) {
2705+
if (MSR_TM_ACTIVE(current->thread.regs->msr)) {
2706+
run->exit_reason = KVM_EXIT_FAIL_ENTRY;
2707+
run->fail_entry.hardware_entry_failure_reason = 0;
2708+
return -EINVAL;
2709+
}
2710+
current->thread.tm_tfhar = mfspr(SPRN_TFHAR);
2711+
current->thread.tm_tfiar = mfspr(SPRN_TFIAR);
2712+
current->thread.tm_texasr = mfspr(SPRN_TEXASR);
2713+
current->thread.regs->msr &= ~MSR_TM;
2714+
}
2715+
#endif
2716+
26962717
kvmppc_core_prepare_to_enter(vcpu);
26972718

26982719
/* No need to go into the guest when all we'll do is come back out */

0 commit comments

Comments
 (0)