All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kamal Mostafa <kamal@canonical.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	kernel-team@lists.ubuntu.com
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Will Deacon <will.deacon@arm.com>,
	Kamal Mostafa <kamal@canonical.com>
Subject: [PATCH 3.19.y-ckt 20/47] arm64: kernel: fix architected PMU registers unconditional access
Date: Tue,  9 Feb 2016 14:44:34 -0800	[thread overview]
Message-ID: <1455057901-7468-21-git-send-email-kamal@canonical.com> (raw)
In-Reply-To: <1455057901-7468-1-git-send-email-kamal@canonical.com>

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

---8<------------------------------------------------------------

From: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>

commit f436b2ac90a095746beb6729b8ee8ed87c9eaede upstream.

The Performance Monitors extension is an optional feature of the
AArch64 architecture, therefore, in order to access Performance
Monitors registers safely, the kernel should detect the architected
PMU unit presence through the ID_AA64DFR0_EL1 register PMUVer field
before accessing them.

This patch implements a guard by reading the ID_AA64DFR0_EL1 register
PMUVer field to detect the architected PMU presence and prevent accessing
PMU system registers if the Performance Monitors extension is not
implemented in the core.

Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Fixes: 60792ad349f3 ("arm64: kernel: enforce pmuserenr_el0 initialization and restore")
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reported-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 arch/arm64/kernel/head.S    |  5 +++++
 arch/arm64/mm/proc-macros.S | 12 ++++++++++++
 arch/arm64/mm/proc.S        |  4 ++--
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index f985fc5..b6a4931 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -546,9 +546,14 @@ CPU_LE(	movk	x0, #0x30d0, lsl #16	)	// Clear EE and E0E on LE systems
 #endif
 
 	/* EL2 debug */
+	mrs	x0, id_aa64dfr0_el1		// Check ID_AA64DFR0_EL1 PMUVer
+	sbfx	x0, x0, #8, #4
+	cmp	x0, #1
+	b.lt	4f				// Skip if no PMU present
 	mrs	x0, pmcr_el0			// Disable debug access traps
 	ubfx	x0, x0, #11, #5			// to EL2 and allow access to
 	msr	mdcr_el2, x0			// all PMU counters from EL1
+4:
 
 	/* Stage-2 translation */
 	msr	vttbr_el2, xzr
diff --git a/arch/arm64/mm/proc-macros.S b/arch/arm64/mm/proc-macros.S
index 005d29e..99d2b5b 100644
--- a/arch/arm64/mm/proc-macros.S
+++ b/arch/arm64/mm/proc-macros.S
@@ -52,3 +52,15 @@
 	mov	\reg, #4			// bytes per word
 	lsl	\reg, \reg, \tmp		// actual cache line size
 	.endm
+
+/*
+ * reset_pmuserenr_el0 - reset PMUSERENR_EL0 if PMUv3 present
+ */
+	.macro	reset_pmuserenr_el0, tmpreg
+	mrs	\tmpreg, id_aa64dfr0_el1	// Check ID_AA64DFR0_EL1 PMUVer
+	sbfx	\tmpreg, \tmpreg, #8, #4
+	cmp	\tmpreg, #1			// Skip if no PMU present
+	b.lt	9000f
+	msr	pmuserenr_el0, xzr		// Disable PMU access from EL0
+9000:
+	.endm
diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
index 1e62ba6..62e6354 100644
--- a/arch/arm64/mm/proc.S
+++ b/arch/arm64/mm/proc.S
@@ -164,7 +164,7 @@ ENTRY(cpu_do_resume)
 	 */
 	ubfx	x11, x11, #1, #1
 	msr	oslar_el1, x11
-	msr	pmuserenr_el0, xzr		// Disable PMU access from EL0
+	reset_pmuserenr_el0 x0			// Disable PMU access from EL0
 	mov	x0, x12
 	dsb	nsh		// Make sure local tlb invalidation completed
 	isb
@@ -204,7 +204,7 @@ ENTRY(__cpu_setup)
 	msr	cpacr_el1, x0			// Enable FP/ASIMD
 	mov	x0, #1 << 12			// Reset mdscr_el1 and disable
 	msr	mdscr_el1, x0			// access to the DCC from EL0
-	msr	pmuserenr_el0, xzr		// Disable PMU access from EL0
+	reset_pmuserenr_el0 x0			// Disable PMU access from EL0
 	/*
 	 * Memory region attributes for LPAE:
 	 *
-- 
1.9.1

  parent reply	other threads:[~2016-02-09 22:45 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-09 22:44 [3.19.y-ckt stable] Linux 3.19.8-ckt15 stable review Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 01/47] x86/xen/p2m: hint at the last populated P2M entry Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 02/47] iio: adis_buffer: Fix out-of-bounds memory access Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 03/47] KVM: PPC: Fix emulation of H_SET_DABR/X on POWER8 Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 04/47] KVM: PPC: Fix ONE_REG AltiVec support Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 05/47] x86/irq: Call chip->irq_set_affinity in proper context Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 06/47] powerpc: Simplify module TOC handling Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 07/47] ACPI: Revert "ACPI / video: Add Dell Inspiron 5737 to the blacklist" Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 08/47] ACPI / PCI / hotplug: unlock in error path in acpiphp_enable_slot() Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 09/47] usb: cdc-acm: handle unlinked urb in acm read callback Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 10/47] usb: cdc-acm: send zero packet for intel 7260 modem Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 11/47] cdc-acm:exclude Samsung phone 04e8:685d Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 12/47] usb: hub: do not clear BOS field during reset device Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 13/47] USB: cp210x: add ID for IAI USB to RS485 adaptor Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 14/47] USB: visor: fix null-deref at probe Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 15/47] USB: serial: visor: fix crash on detecting device without write_urbs Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 16/47] USB: serial: option: Adding support for Telit LE922 Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 17/47] ALSA: seq: Fix incorrect sanity check at snd_seq_oss_synth_cleanup() Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 18/47] ALSA: seq: Degrade the error message for too many opens Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 19/47] USB: serial: ftdi_sio: add support for Yaesu SCU-18 cable Kamal Mostafa
2016-02-09 22:44 ` Kamal Mostafa [this message]
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 21/47] USB: option: fix Cinterion AHxx enumeration Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 22/47] ALSA: compress: Disable GET_CODEC_CAPS ioctl for some architectures Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 23/47] ALSA: usb-audio: Fix TEAC UD-501/UD-503/NT-503 usb delay Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 24/47] ALSA: bebob: Use a signed return type for get_formation_index Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 25/47] arm64: errata: Add -mpc-relative-literal-loads to build flags Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 26/47] arm64: mm: avoid calling apply_to_page_range on empty range Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 27/47] x86/mm: Fix types used in pgprot cacheability flags translations Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 28/47] powerpc/eeh: Fix PE location code Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 29/47] SCSI: fix crashes in sd and sr runtime PM Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 30/47] tty: Fix unsafe ldisc reference via ioctl(TIOCGETD) Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 31/47] n_tty: Fix unsafe reference to "other" ldisc Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 32/47] staging/speakup: Use tty_ldisc_ref() for paste kworker Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 33/47] irqchip/atmel-aic: Fix wrong bit operation for IRQ priority Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 34/47] seccomp: always propagate NO_NEW_PRIVS on tsync Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 35/47] ALSA: dummy: Disable switching timer backend via sysfs Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 36/47] drm/vmwgfx: respect 'nomodeset' Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 37/47] Staging: speakup: Fix getting port information Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 38/47] x86/mm/pat: Avoid truncation when converting cpa->numpages to address Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 39/47] serial: 8250_pci: Add Intel Broadwell ports Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 40/47] perf annotate browser: Fix behaviour of Shift-Tab with nothing focussed Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 41/47] perf hists: Fix HISTC_MEM_DCACHELINE width setting Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 42/47] powerpc/perf: Remove PPMU_HAS_SSLOT flag for Power8 Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 43/47] [media] usbvision fix overflow of interfaces array Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 44/47] [media] usbvision: fix leak of usb_dev on failure paths in usbvision_probe() Kamal Mostafa
2016-02-09 22:44 ` [PATCH 3.19.y-ckt 45/47] [media] usbvision: fix crash on detecting device with invalid configuration Kamal Mostafa
2016-02-09 22:45 ` [PATCH 3.19.y-ckt 46/47] ASN.1: Fix non-match detection failure on data overrun Kamal Mostafa
2016-02-09 22:45 ` [PATCH 3.19.y-ckt 47/47] KEYS: Fix keyring ref leak in join_session_keyring() Kamal Mostafa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1455057901-7468-21-git-send-email-kamal@canonical.com \
    --to=kamal@canonical.com \
    --cc=kernel-team@lists.ubuntu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=peter.maydell@linaro.org \
    --cc=stable@vger.kernel.org \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.