Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1675678

[PATCH 3.18 04/16] KVM: PPC: Book3S HV: Preserve userspace HTM state properly

From Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Newsgroups linux.kernel
Subject [PATCH 3.18 04/16] KVM: PPC: Book3S HV: Preserve userspace HTM state properly
Date 2017-06-27 15:10 +0200
Message-ID <tWYpH-WT-5@gated-at.bofh.it> (permalink)
References <tWYg2-C4-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


3.18-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Paul Mackerras <paulus@ozlabs.org>

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: b005255e12a3 ("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>

---
 arch/powerpc/kvm/book3s_hv.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -1956,6 +1956,27 @@ static int kvmppc_vcpu_run_hv(struct kvm
 		return -EINVAL;
 	}
 
+	/*
+	 * Don't allow entry with a suspended transaction, because
+	 * the guest entry/exit code will lose it.
+	 * If the guest has TM enabled, save away their TM-related SPRs
+	 * (they will get restored by the TM unavailable interrupt).
+	 */
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+	if (cpu_has_feature(CPU_FTR_TM) && current->thread.regs &&
+	    (current->thread.regs->msr & MSR_TM)) {
+		if (MSR_TM_ACTIVE(current->thread.regs->msr)) {
+			run->exit_reason = KVM_EXIT_FAIL_ENTRY;
+			run->fail_entry.hardware_entry_failure_reason = 0;
+			return -EINVAL;
+		}
+		current->thread.tm_tfhar = mfspr(SPRN_TFHAR);
+		current->thread.tm_tfiar = mfspr(SPRN_TFIAR);
+		current->thread.tm_texasr = mfspr(SPRN_TEXASR);
+		current->thread.regs->msr &= ~MSR_TM;
+	}
+#endif
+
 	kvmppc_core_prepare_to_enter(vcpu);
 
 	/* No need to go into the guest when all we'll do is come back out */

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 3.18 00/16] 3.18.59-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-06-27 15:00 +0200
  [PATCH 3.18 02/16] autofs: sanity check status reported with AUTOFS_DEV_IOCTL_FAIL Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-06-27 15:00 +0200
  [PATCH 3.18 09/16] target: Fix kref->refcount underflow in transport_cmd_finish_abort Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-06-27 15:00 +0200
  [PATCH 3.18 03/16] lib/cmdline.c: fix get_options() overflow while parsing ranges Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-06-27 15:00 +0200
  [PATCH 3.18 06/16] signal: Only reschedule timers on signals timers have sent Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-06-27 15:00 +0200
  [PATCH 3.18 14/16] usb: gadget: f_fs: avoid out of bounds access on comp_desc Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-06-27 15:00 +0200
  [PATCH 3.18 13/16] powerpc/slb: Force a full SLB flush when we insert for a bad EA Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-06-27 15:10 +0200
  [PATCH 3.18 11/16] of: Add check to of_scan_flat_dt() before accessing initial_boot_params Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-06-27 15:10 +0200
  [PATCH 3.18 04/16] KVM: PPC: Book3S HV: Preserve userspace HTM state properly Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-06-27 15:10 +0200
  [PATCH 3.18 07/16] powerpc/kprobes: Pause function_graph tracing during jprobes handling Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-06-27 15:10 +0200
  [PATCH 3.18 15/16] net: phy: fix marvell phy status reading Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-06-27 15:10 +0200
  [PATCH 3.18 05/16] CIFS: Improve readdir verbosity Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-06-27 15:10 +0200
  Re: [PATCH 3.18 00/16] 3.18.59-stable review Guenter Roeck <linux@roeck-us.net> - 2017-06-27 21:00 +0200
  Re: [PATCH 3.18 00/16] 3.18.59-stable review Shuah Khan <shuahkh@osg.samsung.com> - 2017-06-28 16:00 +0200

csiph-web