Skip to contentSkip to conversation

x86,perf: Disable intel_bts when PTI

PATCH In review Peter Zijlstra 5 participants 6 messages Jan 14, 2018

Subsystems (2)
lore
Share & tools
lore

Peter Zijlstra

author maintainer
#0 lore raw

PATCH 1/1 x86,perf: Disable intel_bts when PTI

The intel_bts driver does not use the 'normal' BTS buffer we allocated space for in the cpu_entry_area but instead uses the memory allocated for the perf AUX buffer.

This obviously comes apart when using PTI because then the kernel mapping; which includes that AUX buffer memory; disappears.

For now disable this driver when PTI is enabled, we'll try and sort something out later.

---
 arch/x86/events/intel/bts.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
arch/x86/events/intel/bts.c +18 -0
index 141e07b06216..24ffa1e88cf9 100644
@@ -582,6 +582,24 @@ static __init int bts_init(void)
 	if (!boot_cpu_has(X86_FEATURE_DTES64) || !x86_pmu.bts)
 		return -ENODEV;
 
+	if (boot_cpu_has(X86_FEATURE_PTI)) {
+		/*
+		 * BTS hardware writes through a virtual memory map we must
+		 * either use the kernel physical map, or the user mapping of
+		 * the AUX buffer.
+		 *
+		 * However, since this driver supports per-CPU and per-task inherit
+		 * we cannot use the user mapping since it will not be availble
+		 * if we're not running the owning process.
+		 *
+		 * With PTI we can't use the kernal map either, because its not
+		 * there when we run userspace.
+		 *
+		 * For now, disable this driver when using PTI.
+		 */
+		return -ENODEV;
+	}
+
 	bts_pmu.capabilities	= PERF_PMU_CAP_AUX_NO_SG | PERF_PMU_CAP_ITRACE |
 				  PERF_PMU_CAP_EXCLUSIVE;
 	bts_pmu.task_ctx_nr	= perf_sw_context;
#1 lore raw
Quoted 8 lines · Peter Zijlstra

The intel_bts driver does not use the 'normal' BTS buffer we allocated space for in the cpu_entry_area but instead uses the memory allocated for the perf AUX buffer.

This obviously comes apart when using PTI because then the kernel mapping; which includes that AUX buffer memory; disappears.

Quoted 7 lines

For now disable this driver when PTI is enabled, we'll try and sort something out later.

Can you add a:
Cc: stable <[email protected]>
please?

thanks,

greg k-h

#2 lore raw
Quoted 12 lines · Greg KH
Quoted 11 lines · Peter Zijlstra

The intel_bts driver does not use the 'normal' BTS buffer we allocated space for in the cpu_entry_area but instead uses the memory allocated for the perf AUX buffer.

This obviously comes apart when using PTI because then the kernel mapping; which includes that AUX buffer memory; disappears.

For now disable this driver when PTI is enabled, we'll try and sort something out later.

Quoted 8 lines
Quoted 4 lines

Can you add a:
Cc: stable <[email protected]>
please?

Already in the commit ...

#3 lore raw
In reply to Greg KH
Quoted 12 lines · Greg KH
Quoted 11 lines · Peter Zijlstra

The intel_bts driver does not use the 'normal' BTS buffer we allocated space for in the cpu_entry_area but instead uses the memory allocated for the perf AUX buffer.

This obviously comes apart when using PTI because then the kernel mapping; which includes that AUX buffer memory; disappears.

For now disable this driver when PTI is enabled, we'll try and sort something out later.

Quoted 8 lines
Quoted 4 lines

Can you add a:
Cc: stable <[email protected]>
please?

Note that these fixes are all going into tip:x86/pti, which is still a backporting friendly linear set of commits that should all be backported.

So once 99a9dc98ba52 goes upstream, all of v4.14..99a9dc98ba52 the remaining bits can go to -stable as well.

Will keep you updated about the latest status periodically, right now the latest that is already upstream is:

de791821c295: x86/pti: Rename BUG_CPU_INSECURE to BUG_CPU_MELTDOWN

i.e. all 194 commits in the v4.14..de791821c295 range should be queued up for -stable. (And most of them already are.)

There are 28 new commits in tip:x86/pti that will (hopefully) go upstream later today.

Thanks,

Ingo

#4 lore raw
Quoted 30 lines · Ingo Molnar
Quoted 12 lines · Greg KH
Quoted 11 lines · Peter Zijlstra

The intel_bts driver does not use the 'normal' BTS buffer we allocated space for in the cpu_entry_area but instead uses the memory allocated for the perf AUX buffer.

This obviously comes apart when using PTI because then the kernel mapping; which includes that AUX buffer memory; disappears.

For now disable this driver when PTI is enabled, we'll try and sort something out later.

Quoted 8 lines
Quoted 4 lines

Can you add a:
Cc: stable <[email protected]>
please?

Note that these fixes are all going into tip:x86/pti, which is still a backporting friendly linear set of commits that should all be backported.

So once 99a9dc98ba52 goes upstream, all of v4.14..99a9dc98ba52 the remaining bits can go to -stable as well.

Quoted 7 lines

Will keep you updated about the latest status periodically, right now the latest that is already upstream is:

de791821c295: x86/pti: Rename BUG_CPU_INSECURE to BUG_CPU_MELTDOWN

i.e. all 194 commits in the v4.14..de791821c295 range should be queued up for -stable. (And most of them already are.)

I hope I got all of those in that branch already, as I've been watching it :)

Quoted 2 lines

There are 28 new commits in tip:x86/pti that will (hopefully) go upstream later today.

Great, again, thanks for doing it this way, it has made it much easier for me.

greg k-h

#5 lore raw
In reply to Peter Zijlstra
x86,perf: Disable intel_bts when PTI
Commit-ID:  99a9dc98ba52267ce5e062b52de88ea1f1b2a7d8
Gitweb:     https://git.kernel.org/tip/99a9dc98ba52267ce5e062b52de88ea1f1b2a7d8
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Sun, 14 Jan 2018 11:27:13 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Sun, 14 Jan 2018 11:42:10 +0100

x86,perf: Disable intel_bts when PTI

The intel_bts driver does not use the 'normal' BTS buffer which is exposed through the cpu_entry_area but instead uses the memory allocated for the perf AUX buffer.

This obviously comes apart when using PTI because then the kernel mapping; which includes that AUX buffer memory; disappears. Fixing this requires to expose a mapping which is visible in all context and that's not trivial.

As a quick fix disable this driver when PTI is enabled to prevent malfunction.

---
 arch/x86/events/intel/bts.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
arch/x86/events/intel/bts.c +18 -0
index 141e07b..24ffa1e 100644
@@ -582,6 +582,24 @@ static __init int bts_init(void)
 	if (!boot_cpu_has(X86_FEATURE_DTES64) || !x86_pmu.bts)
 		return -ENODEV;
 
+	if (boot_cpu_has(X86_FEATURE_PTI)) {
+		/*
+		 * BTS hardware writes through a virtual memory map we must
+		 * either use the kernel physical map, or the user mapping of
+		 * the AUX buffer.
+		 *
+		 * However, since this driver supports per-CPU and per-task inherit
+		 * we cannot use the user mapping since it will not be availble
+		 * if we're not running the owning process.
+		 *
+		 * With PTI we can't use the kernal map either, because its not
+		 * there when we run userspace.
+		 *
+		 * For now, disable this driver when using PTI.
+		 */
+		return -ENODEV;
+	}
+
 	bts_pmu.capabilities	= PERF_PMU_CAP_AUX_NO_SG | PERF_PMU_CAP_ITRACE |
 				  PERF_PMU_CAP_EXCLUSIVE;
 	bts_pmu.task_ctx_nr	= perf_sw_context;