mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/2] perf/x86: fixes and improvements for Intel Atom PEBS/LBR support
@ 2015-12-03 22:33 Stephane Eranian
  2015-12-03 22:33 ` [PATCH v3 1/4] perf/x86: fix LBR issues on Intel Atom Stephane Eranian
  2015-12-03 22:33 ` [PATCH v3 2/4] perf/x86: fix PEBS issues on Intel Atom/Core2 Stephane Eranian
  0 siblings, 2 replies; 5+ messages in thread
From: Stephane Eranian @ 2015-12-03 22:33 UTC (permalink / raw)
  To: linux-kernel; +Cc: acme, peterz, mingo, ak, kan.liang

This short series fixes breakage of Intel Atom PEBS and LBR support in recent kernels.
The problems were introduced with the changes in the PEBS logic to handle deeper buffer.
Refer to the changelog in the specific commits for SHA1.

The first patch fixes LBR assumption that 64-bit LBR format implies LBR_SELECT msr.
The second patch fixes PEBS support and wrong pointer arithmetic and assumption about
Atom/Core2 PEBS record layout.

The third patch adds an alias for cycles:pp to Intel Atom given that perf record/top
uses cycles:pp nowadays.

The fourth patch allows using precise sampling attribute on all events on Intel Atom.
When used on non-PEBS events, no samples are generated. No error is reported, this is
consistent with the behavior for other Intel processors.

In V2, we removed the alias function specific to Atom use use the one from Core2
because it is identical as suggested by Kan Liang.

In V3, we split up the series into 4 patches and referenced the commits which introduced
the issues.

Stephane Eranian (4):
  perf/x86: fix LBR issues on Intel Atom
  perf/x86: fix PEBS issues on Intel Atom/Core2
  perf/x86: enable cycles:pp for Intel Atom
  perf/x86: allow precise mode on all events for Intel Atom

 arch/x86/kernel/cpu/perf_event_intel.c     |  1 +
 arch/x86/kernel/cpu/perf_event_intel_ds.c  | 11 ++++++++++-
 arch/x86/kernel/cpu/perf_event_intel_lbr.c | 11 +++++++----
 3 files changed, 18 insertions(+), 5 deletions(-)

-- 
1.9.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/4] perf/x86: fix LBR issues on Intel Atom
  2015-12-03 22:33 [PATCH v3 0/2] perf/x86: fixes and improvements for Intel Atom PEBS/LBR support Stephane Eranian
@ 2015-12-03 22:33 ` Stephane Eranian
  2016-01-06 18:52   ` [tip:perf/core] perf/x86: Fix LBR related crashes " tip-bot for Stephane Eranian
  2015-12-03 22:33 ` [PATCH v3 2/4] perf/x86: fix PEBS issues on Intel Atom/Core2 Stephane Eranian
  1 sibling, 1 reply; 5+ messages in thread
From: Stephane Eranian @ 2015-12-03 22:33 UTC (permalink / raw)
  To: linux-kernel; +Cc: acme, peterz, mingo, ak, kan.liang

This patches fixes the LBR kernel crashes on Intel Atom.

The kernel was assuming that if the CPU supports 64-bit format
LBR, then it has an LBR_SELECT MSR. Atom uses 64-bit LBR format
but does not have LBR_SELECT. That was causing NULL pointer
dereferences in a couple of places.

Fixes: 96f3eda6 ("perf/x86/intel: Fix static checker warning in lbr enable")

Signed-off-by: Stephane Eranian <eranian@google.com>
---
 arch/x86/kernel/cpu/perf_event_intel_lbr.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event_intel_lbr.c b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
index e2fad0c..1390148 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_lbr.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
@@ -161,7 +161,7 @@ static void __intel_pmu_lbr_enable(bool pmi)
 	 */
 	if (cpuc->lbr_sel)
 		lbr_select = cpuc->lbr_sel->config & x86_pmu.lbr_sel_mask;
-	if (!pmi)
+	if (!pmi && cpuc->lbr_sel)
 		wrmsrl(MSR_LBR_SELECT, lbr_select);
 
 	rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
@@ -430,7 +430,7 @@ static void intel_pmu_lbr_read_32(struct cpu_hw_events *cpuc)
  */
 static void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc)
 {
-	bool need_info = !(cpuc->lbr_sel->config & LBR_NO_INFO);
+	bool need_info = false;
 	unsigned long mask = x86_pmu.lbr_nr - 1;
 	int lbr_format = x86_pmu.intel_cap.lbr_format;
 	u64 tos = intel_pmu_lbr_tos();
@@ -438,8 +438,11 @@ static void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc)
 	int out = 0;
 	int num = x86_pmu.lbr_nr;
 
-	if (cpuc->lbr_sel->config & LBR_CALL_STACK)
-		num = tos;
+	if (cpuc->lbr_sel) {
+		need_info = !(cpuc->lbr_sel->config & LBR_NO_INFO);
+		if (cpuc->lbr_sel->config & LBR_CALL_STACK)
+			num = tos;
+	}
 
 	for (i = 0; i < num; i++) {
 		unsigned long lbr_idx = (tos - i) & mask;
-- 
1.9.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 2/4] perf/x86: fix PEBS issues on Intel Atom/Core2
  2015-12-03 22:33 [PATCH v3 0/2] perf/x86: fixes and improvements for Intel Atom PEBS/LBR support Stephane Eranian
  2015-12-03 22:33 ` [PATCH v3 1/4] perf/x86: fix LBR issues on Intel Atom Stephane Eranian
@ 2015-12-03 22:33 ` Stephane Eranian
  2016-01-06 18:52   ` [tip:perf/core] " tip-bot for Stephane Eranian
  1 sibling, 1 reply; 5+ messages in thread
From: Stephane Eranian @ 2015-12-03 22:33 UTC (permalink / raw)
  To: linux-kernel; +Cc: acme, peterz, mingo, ak, kan.liang

This patch fixes broken PEBS support on Intel Atom and Core2
due to wrong pointer arithmetic in intel_pmu_drain_pebs_core().

The get_next_pebs_record_by_bit() was called on PEBS format fmt0
which does not use the pebs_record_nhm layout.

Fixes: 21509084f ("perf/x86/intel: Handle multiple records in the PEBS buffer")

Signed-off-by: Stephane Eranian <eranian@google.com>
---
 arch/x86/kernel/cpu/perf_event_intel_ds.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/perf_event_intel_ds.c b/arch/x86/kernel/cpu/perf_event_intel_ds.c
index 5db1c77..dae5f93 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_ds.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c
@@ -1101,6 +1101,13 @@ get_next_pebs_record_by_bit(void *base, void *top, int bit)
 	void *at;
 	u64 pebs_status;
 
+	/*
+	 * fmt0 does not have a status bitfield (does not use
+	 * perf_record_nhm format)
+	 */
+	if (x86_pmu.intel_cap.pebs_format < 1)
+		return base;
+
 	if (base == NULL)
 		return NULL;
 
@@ -1186,7 +1193,7 @@ static void intel_pmu_drain_pebs_core(struct pt_regs *iregs)
 	if (!event->attr.precise_ip)
 		return;
 
-	n = (top - at) / x86_pmu.pebs_record_size;
+	n = top - at;
 	if (n <= 0)
 		return;
 
-- 
1.9.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tip:perf/core] perf/x86: Fix LBR related crashes on Intel Atom
  2015-12-03 22:33 ` [PATCH v3 1/4] perf/x86: fix LBR issues on Intel Atom Stephane Eranian
@ 2016-01-06 18:52   ` tip-bot for Stephane Eranian
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Stephane Eranian @ 2016-01-06 18:52 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, mingo, jolsa, linux-kernel, torvalds, vincent.weaver, tglx,
	peterz, eranian, acme

Commit-ID:  6fc2e83077b05a061afe9b24f2fdff7a0434eb67
Gitweb:     http://git.kernel.org/tip/6fc2e83077b05a061afe9b24f2fdff7a0434eb67
Author:     Stephane Eranian <eranian@google.com>
AuthorDate: Thu, 3 Dec 2015 23:33:17 +0100
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 6 Jan 2016 11:15:33 +0100

perf/x86: Fix LBR related crashes on Intel Atom

This patches fixes the LBR kernel crashes on Intel Atom.

The kernel was assuming that if the CPU supports 64-bit format
LBR, then it has an LBR_SELECT MSR. Atom uses 64-bit LBR format
but does not have LBR_SELECT. That was causing NULL pointer
dereferences in a couple of places.

Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: kan.liang@intel.com
Fixes: 96f3eda67fcf ("perf/x86/intel: Fix static checker warning in lbr enable")
Link: http://lkml.kernel.org/r/1449182000-31524-2-git-send-email-eranian@google.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/cpu/perf_event_intel_lbr.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event_intel_lbr.c b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
index e2fad0c..1390148 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_lbr.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
@@ -161,7 +161,7 @@ static void __intel_pmu_lbr_enable(bool pmi)
 	 */
 	if (cpuc->lbr_sel)
 		lbr_select = cpuc->lbr_sel->config & x86_pmu.lbr_sel_mask;
-	if (!pmi)
+	if (!pmi && cpuc->lbr_sel)
 		wrmsrl(MSR_LBR_SELECT, lbr_select);
 
 	rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
@@ -430,7 +430,7 @@ static void intel_pmu_lbr_read_32(struct cpu_hw_events *cpuc)
  */
 static void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc)
 {
-	bool need_info = !(cpuc->lbr_sel->config & LBR_NO_INFO);
+	bool need_info = false;
 	unsigned long mask = x86_pmu.lbr_nr - 1;
 	int lbr_format = x86_pmu.intel_cap.lbr_format;
 	u64 tos = intel_pmu_lbr_tos();
@@ -438,8 +438,11 @@ static void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc)
 	int out = 0;
 	int num = x86_pmu.lbr_nr;
 
-	if (cpuc->lbr_sel->config & LBR_CALL_STACK)
-		num = tos;
+	if (cpuc->lbr_sel) {
+		need_info = !(cpuc->lbr_sel->config & LBR_NO_INFO);
+		if (cpuc->lbr_sel->config & LBR_CALL_STACK)
+			num = tos;
+	}
 
 	for (i = 0; i < num; i++) {
 		unsigned long lbr_idx = (tos - i) & mask;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tip:perf/core] perf/x86: fix PEBS issues on Intel Atom/Core2
  2015-12-03 22:33 ` [PATCH v3 2/4] perf/x86: fix PEBS issues on Intel Atom/Core2 Stephane Eranian
@ 2016-01-06 18:52   ` tip-bot for Stephane Eranian
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Stephane Eranian @ 2016-01-06 18:52 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, eranian, mingo, vincent.weaver, jolsa, torvalds,
	hpa, acme, peterz, tglx

Commit-ID:  1424a09a9e1839285e948d4ea9fdfca26c9a2086
Gitweb:     http://git.kernel.org/tip/1424a09a9e1839285e948d4ea9fdfca26c9a2086
Author:     Stephane Eranian <eranian@google.com>
AuthorDate: Thu, 3 Dec 2015 23:33:18 +0100
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 6 Jan 2016 11:15:34 +0100

perf/x86: fix PEBS issues on Intel Atom/Core2

This patch fixes broken PEBS support on Intel Atom and Core2
due to wrong pointer arithmetic in intel_pmu_drain_pebs_core().

The get_next_pebs_record_by_bit() was called on PEBS format fmt0
which does not use the pebs_record_nhm layout.

Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: kan.liang@intel.com
Fixes: 21509084f999 ("perf/x86/intel: Handle multiple records in the PEBS buffer")
Link: http://lkml.kernel.org/r/1449182000-31524-3-git-send-email-eranian@google.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/cpu/perf_event_intel_ds.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/perf_event_intel_ds.c b/arch/x86/kernel/cpu/perf_event_intel_ds.c
index 9c0f8d4..a7463ed 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_ds.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c
@@ -1106,6 +1106,13 @@ get_next_pebs_record_by_bit(void *base, void *top, int bit)
 	void *at;
 	u64 pebs_status;
 
+	/*
+	 * fmt0 does not have a status bitfield (does not use
+	 * perf_record_nhm format)
+	 */
+	if (x86_pmu.intel_cap.pebs_format < 1)
+		return base;
+
 	if (base == NULL)
 		return NULL;
 
@@ -1191,7 +1198,7 @@ static void intel_pmu_drain_pebs_core(struct pt_regs *iregs)
 	if (!event->attr.precise_ip)
 		return;
 
-	n = (top - at) / x86_pmu.pebs_record_size;
+	n = top - at;
 	if (n <= 0)
 		return;
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-01-06 18:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-03 22:33 [PATCH v3 0/2] perf/x86: fixes and improvements for Intel Atom PEBS/LBR support Stephane Eranian
2015-12-03 22:33 ` [PATCH v3 1/4] perf/x86: fix LBR issues on Intel Atom Stephane Eranian
2016-01-06 18:52   ` [tip:perf/core] perf/x86: Fix LBR related crashes " tip-bot for Stephane Eranian
2015-12-03 22:33 ` [PATCH v3 2/4] perf/x86: fix PEBS issues on Intel Atom/Core2 Stephane Eranian
2016-01-06 18:52   ` [tip:perf/core] " tip-bot for Stephane Eranian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome