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


Groups > linux.kernel > #1553488

[PATCH 4.8 53/96] arm64: KVM: pmu: Reset PMSELR_EL0.SEL to a sane value before entering the guest

From Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Newsgroups linux.kernel
Subject [PATCH 4.8 53/96] arm64: KVM: pmu: Reset PMSELR_EL0.SEL to a sane value before entering the guest
Date 2017-01-07 00:10 +0100
Message-ID <sWLO3-sV-67@gated-at.bofh.it> (permalink)
References <sWKyC-7RC-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

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

From: Marc Zyngier <marc.zyngier@arm.com>

commit 21cbe3cc8a48ff17059912e019fbde28ed54745a upstream.

The ARMv8 architecture allows the cycle counter to be configured
by setting PMSELR_EL0.SEL==0x1f and then accessing PMXEVTYPER_EL0,
hence accessing PMCCFILTR_EL0. But it disallows the use of
PMSELR_EL0.SEL==0x1f to access the cycle counter itself through
PMXEVCNTR_EL0.

Linux itself doesn't violate this rule, but we may end up with
PMSELR_EL0.SEL being set to 0x1f when we enter a guest. If that
guest accesses PMXEVCNTR_EL0, the access may UNDEF at EL1,
despite the guest not having done anything wrong.

In order to avoid this unfortunate course of events (haha!), let's
sanitize PMSELR_EL0 on guest entry. This ensures that the guest
won't explode unexpectedly.

Acked-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 arch/arm64/kvm/hyp/switch.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

--- a/arch/arm64/kvm/hyp/switch.c
+++ b/arch/arm64/kvm/hyp/switch.c
@@ -82,7 +82,13 @@ static void __hyp_text __activate_traps(
 	write_sysreg(val, hcr_el2);
 	/* Trap on AArch32 cp15 c15 accesses (EL1 or EL0) */
 	write_sysreg(1 << 15, hstr_el2);
-	/* Make sure we trap PMU access from EL0 to EL2 */
+	/*
+	 * Make sure we trap PMU access from EL0 to EL2. Also sanitize
+	 * PMSELR_EL0 to make sure it never contains the cycle
+	 * counter, which could make a PMXEVCNTR_EL0 access UNDEF at
+	 * EL1 instead of being trapped to EL2.
+	 */
+	write_sysreg(0, pmselr_el0);
 	write_sysreg(ARMV8_PMU_USERENR_MASK, pmuserenr_el0);
 	write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2);
 	__activate_traps_arch()();

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


Thread

[PATCH 4.8 00/96] 4.8.17-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-07 00:10 +0100
  [PATCH 4.8 17/96] hv: acquire vmbus_connection.channel_mutex in vmbus_free_channels() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-07 00:10 +0100
  [PATCH 4.8 52/96] s390/kexec: use node 0 when re-adding crash kernel memory Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-07 00:10 +0100
  [PATCH 4.8 26/96] drm/nouveau/ltc: protect clearing of comptags with mutex Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-07 00:10 +0100
  [PATCH 4.8 03/96] perf/x86: Fix exclusion of BTS and LBR for Goldmont Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-07 00:10 +0100
  [PATCH 4.8 53/96] arm64: KVM: pmu: Reset PMSELR_EL0.SEL to a sane value before entering the guest Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-07 00:10 +0100
  [PATCH 4.8 06/96] cfg80211/mac80211: fix BSS leaks when abandoning assoc attempts Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-07 00:10 +0100
  [PATCH 4.8 55/96] md/raid5: limit request size according to implementation limits Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-07 00:10 +0100
  Re: [PATCH 4.8 00/96] 4.8.17-stable review Shuah Khan <shuah.kh@samsung.com> - 2017-01-07 03:10 +0100
  Re: [PATCH 4.8 00/96] 4.8.17-stable review Guenter Roeck <linux@roeck-us.net> - 2017-01-07 17:00 +0100

csiph-web