linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86,perf: Disable intel_bts when PTI
@ 2018-01-14 10:27 Peter Zijlstra
  2018-01-14 10:46 ` [tip:x86/pti] " tip-bot for Peter Zijlstra
  2018-01-14 10:50 ` [PATCH] " Greg KH
  0 siblings, 2 replies; 6+ messages in thread
From: Peter Zijlstra @ 2018-01-14 10:27 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: linux-kernel, Vince Weaver, torvalds, robert, luto, mingo, hughd,
	greg, Alexander Shishkin


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.

Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Reported-by: Vince Weaver <vincent.weaver@maine.edu>
Reported-by: Robert Święcki <robert@swiecki.net>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 arch/x86/events/intel/bts.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/arch/x86/events/intel/bts.c b/arch/x86/events/intel/bts.c
index 141e07b06216..24ffa1e88cf9 100644
--- a/arch/x86/events/intel/bts.c
+++ b/arch/x86/events/intel/bts.c
@@ -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;

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

* [tip:x86/pti] x86,perf: Disable intel_bts when PTI
  2018-01-14 10:27 [PATCH] x86,perf: Disable intel_bts when PTI Peter Zijlstra
@ 2018-01-14 10:46 ` tip-bot for Peter Zijlstra
  2018-01-14 10:50 ` [PATCH] " Greg KH
  1 sibling, 0 replies; 6+ messages in thread
From: tip-bot for Peter Zijlstra @ 2018-01-14 10:46 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, linux-kernel, tglx, mingo, peterz, vince, vincent.weaver,
	alexander.shishkin, robert

Commit-ID:  99a9dc98ba52267ce5e062b52de88ea1f1b2a7d8
Gitweb:     https://git.kernel.org/tip/99a9dc98ba52267ce5e062b52de88ea1f1b2a7d8
Author:     Peter Zijlstra <peterz@infradead.org>
AuthorDate: Sun, 14 Jan 2018 11:27:13 +0100
Committer:  Thomas Gleixner <tglx@linutronix.de>
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.

Fixes: 385ce0ea4c07 ("x86/mm/pti: Add Kconfig")
Reported-by: Vince Weaver <vincent.weaver@maine.edu>
Reported-by: Robert Święcki <robert@swiecki.net>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: greg@kroah.com
Cc: hughd@google.com
Cc: luto@amacapital.net
Cc: Vince Weaver <vince@deater.net>
Cc: torvalds@linux-foundation.org
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/20180114102713.GB6166@worktop.programming.kicks-ass.net

---
 arch/x86/events/intel/bts.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/arch/x86/events/intel/bts.c b/arch/x86/events/intel/bts.c
index 141e07b..24ffa1e 100644
--- a/arch/x86/events/intel/bts.c
+++ b/arch/x86/events/intel/bts.c
@@ -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;

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

* Re: [PATCH] x86,perf: Disable intel_bts when PTI
  2018-01-14 10:27 [PATCH] x86,perf: Disable intel_bts when PTI Peter Zijlstra
  2018-01-14 10:46 ` [tip:x86/pti] " tip-bot for Peter Zijlstra
@ 2018-01-14 10:50 ` Greg KH
  2018-01-14 10:52   ` Thomas Gleixner
  2018-01-14 12:54   ` Ingo Molnar
  1 sibling, 2 replies; 6+ messages in thread
From: Greg KH @ 2018-01-14 10:50 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Thomas Gleixner, linux-kernel, Vince Weaver, torvalds, robert,
	luto, mingo, hughd, Alexander Shishkin

On Sun, Jan 14, 2018 at 11:27:13AM +0100, Peter Zijlstra wrote:
> 
> 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.
> 
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Reported-by: Vince Weaver <vincent.weaver@maine.edu>
> Reported-by: Robert Święcki <robert@swiecki.net>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>

Can you add a:
	Cc: stable <stable@vger.kernel.org>
please?

thanks,

greg k-h

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

* Re: [PATCH] x86,perf: Disable intel_bts when PTI
  2018-01-14 10:50 ` [PATCH] " Greg KH
@ 2018-01-14 10:52   ` Thomas Gleixner
  2018-01-14 12:54   ` Ingo Molnar
  1 sibling, 0 replies; 6+ messages in thread
From: Thomas Gleixner @ 2018-01-14 10:52 UTC (permalink / raw)
  To: Greg KH
  Cc: Peter Zijlstra, linux-kernel, Vince Weaver, torvalds, robert,
	luto, mingo, hughd, Alexander Shishkin

[-- Attachment #1: Type: text/plain, Size: 868 bytes --]

On Sun, 14 Jan 2018, Greg KH wrote:

> On Sun, Jan 14, 2018 at 11:27:13AM +0100, Peter Zijlstra wrote:
> > 
> > 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.
> > 
> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > Reported-by: Vince Weaver <vincent.weaver@maine.edu>
> > Reported-by: Robert Święcki <robert@swiecki.net>
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> 
> Can you add a:
> 	Cc: stable <stable@vger.kernel.org>
> please?

Already in the commit ...

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

* Re: [PATCH] x86,perf: Disable intel_bts when PTI
  2018-01-14 10:50 ` [PATCH] " Greg KH
  2018-01-14 10:52   ` Thomas Gleixner
@ 2018-01-14 12:54   ` Ingo Molnar
  2018-01-14 13:27     ` Greg KH
  1 sibling, 1 reply; 6+ messages in thread
From: Ingo Molnar @ 2018-01-14 12:54 UTC (permalink / raw)
  To: Greg KH
  Cc: Peter Zijlstra, Thomas Gleixner, linux-kernel, Vince Weaver,
	torvalds, robert, luto, hughd, Alexander Shishkin


* Greg KH <greg@kroah.com> wrote:

> On Sun, Jan 14, 2018 at 11:27:13AM +0100, Peter Zijlstra wrote:
> > 
> > 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.
> > 
> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > Reported-by: Vince Weaver <vincent.weaver@maine.edu>
> > Reported-by: Robert Święcki <robert@swiecki.net>
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> 
> Can you add a:
> 	Cc: stable <stable@vger.kernel.org>
> 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

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

* Re: [PATCH] x86,perf: Disable intel_bts when PTI
  2018-01-14 12:54   ` Ingo Molnar
@ 2018-01-14 13:27     ` Greg KH
  0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2018-01-14 13:27 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Peter Zijlstra, Thomas Gleixner, linux-kernel, Vince Weaver,
	torvalds, robert, luto, hughd, Alexander Shishkin

On Sun, Jan 14, 2018 at 01:54:44PM +0100, Ingo Molnar wrote:
> 
> * Greg KH <greg@kroah.com> wrote:
> 
> > On Sun, Jan 14, 2018 at 11:27:13AM +0100, Peter Zijlstra wrote:
> > > 
> > > 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.
> > > 
> > > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > > Reported-by: Vince Weaver <vincent.weaver@maine.edu>
> > > Reported-by: Robert Święcki <robert@swiecki.net>
> > > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > 
> > Can you add a:
> > 	Cc: stable <stable@vger.kernel.org>
> > 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.)

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

> 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

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

end of thread, other threads:[~2018-01-14 13:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-14 10:27 [PATCH] x86,perf: Disable intel_bts when PTI Peter Zijlstra
2018-01-14 10:46 ` [tip:x86/pti] " tip-bot for Peter Zijlstra
2018-01-14 10:50 ` [PATCH] " Greg KH
2018-01-14 10:52   ` Thomas Gleixner
2018-01-14 12:54   ` Ingo Molnar
2018-01-14 13:27     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).