All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf/x86/amd: Explicitly define PERF_COUNT_HW_REF_CPU_CYCLES as undefined.
@ 2016-04-27  1:19 Adam Borowski
  2016-04-27  8:03 ` Ingo Molnar
  0 siblings, 1 reply; 5+ messages in thread
From: Adam Borowski @ 2016-04-27  1:19 UTC (permalink / raw)
  To: linux-kernel, Stephane Eranian, Peter Zijlstra, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin, x86, Borislav Petkov
  Cc: Adam Borowski

filter_events() relies on the value of 0 to remove events that are not
applicable, like this one.

UBSAN: Undefined behaviour in arch/x86/events/amd/core.c:132:30
index 9 is out of range for type 'u64 [9]'
UBSAN: Undefined behaviour in arch/x86/events/amd/core.c:132:9
load of address ffffffff81c021c8 with insufficient space
for an object of type 'const u64'

Signed-off-by: Adam Borowski <kilobyte@angband.pl>
---
 arch/x86/events/amd/core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
index 86a9bec..5fa1b8e 100644
--- a/arch/x86/events/amd/core.c
+++ b/arch/x86/events/amd/core.c
@@ -125,6 +125,7 @@ static const u64 amd_perfmon_event_map[] =
   [PERF_COUNT_HW_BRANCH_MISSES]			= 0x00c3,
   [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND]	= 0x00d0, /* "Decoder empty" event */
   [PERF_COUNT_HW_STALLED_CYCLES_BACKEND]	= 0x00d1, /* "Dispatch stalls" event */
+  [PERF_COUNT_HW_REF_CPU_CYCLES]		=      0,
 };
 
 static u64 amd_pmu_event_map(int hw_event)
-- 
2.8.1

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

* Re: [PATCH] perf/x86/amd: Explicitly define PERF_COUNT_HW_REF_CPU_CYCLES as undefined.
  2016-04-27  1:19 [PATCH] perf/x86/amd: Explicitly define PERF_COUNT_HW_REF_CPU_CYCLES as undefined Adam Borowski
@ 2016-04-27  8:03 ` Ingo Molnar
  2016-04-27  9:32   ` Adam Borowski
  0 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2016-04-27  8:03 UTC (permalink / raw)
  To: Adam Borowski
  Cc: linux-kernel, Stephane Eranian, Peter Zijlstra, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin, x86, Borislav Petkov


* Adam Borowski <kilobyte@angband.pl> wrote:

> filter_events() relies on the value of 0 to remove events that are not
> applicable, like this one.
> 
> UBSAN: Undefined behaviour in arch/x86/events/amd/core.c:132:30
> index 9 is out of range for type 'u64 [9]'
> UBSAN: Undefined behaviour in arch/x86/events/amd/core.c:132:9
> load of address ffffffff81c021c8 with insufficient space
> for an object of type 'const u64'
> 
> Signed-off-by: Adam Borowski <kilobyte@angband.pl>
> ---
>  arch/x86/events/amd/core.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
> index 86a9bec..5fa1b8e 100644
> --- a/arch/x86/events/amd/core.c
> +++ b/arch/x86/events/amd/core.c
> @@ -125,6 +125,7 @@ static const u64 amd_perfmon_event_map[] =
>    [PERF_COUNT_HW_BRANCH_MISSES]			= 0x00c3,
>    [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND]	= 0x00d0, /* "Decoder empty" event */
>    [PERF_COUNT_HW_STALLED_CYCLES_BACKEND]	= 0x00d1, /* "Dispatch stalls" event */
> +  [PERF_COUNT_HW_REF_CPU_CYCLES]		=      0,
>  };

Hm, I think it would be cleaner and more robust to change this (and all other 
similar, if any) arrays to [PERF_COUNT_HW_MAX] instead.

Thanks,

	Ingo

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

* Re: [PATCH] perf/x86/amd: Explicitly define PERF_COUNT_HW_REF_CPU_CYCLES as undefined.
  2016-04-27  8:03 ` Ingo Molnar
@ 2016-04-27  9:32   ` Adam Borowski
  2016-04-27  9:35     ` [PATCH] perf/x86/amd: Set the size of event map array to PERF_COUNT_HW_MAX Adam Borowski
  0 siblings, 1 reply; 5+ messages in thread
From: Adam Borowski @ 2016-04-27  9:32 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Stephane Eranian, Peter Zijlstra, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin, x86, Borislav Petkov

On Wed, Apr 27, 2016 at 10:03:45AM +0200, Ingo Molnar wrote:
> * Adam Borowski <kilobyte@angband.pl> wrote:
> > diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
> > index 86a9bec..5fa1b8e 100644
> > --- a/arch/x86/events/amd/core.c
> > +++ b/arch/x86/events/amd/core.c
> > @@ -125,6 +125,7 @@ static const u64 amd_perfmon_event_map[] =
> >    [PERF_COUNT_HW_BRANCH_MISSES]			= 0x00c3,
> >    [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND]	= 0x00d0, /* "Decoder empty" event */
> >    [PERF_COUNT_HW_STALLED_CYCLES_BACKEND]	= 0x00d1, /* "Dispatch stalls" event */
> > +  [PERF_COUNT_HW_REF_CPU_CYCLES]		=      0,
> >  };
> 
> Hm, I think it would be cleaner and more robust to change this (and all other 
> similar, if any) arrays to [PERF_COUNT_HW_MAX] instead.

Good idea!  Both of Intel's copies (one for p4, one for core+) already set
the size this way.

-- 
A tit a day keeps the vet away.

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

* [PATCH] perf/x86/amd: Set the size of event map array to PERF_COUNT_HW_MAX.
  2016-04-27  9:32   ` Adam Borowski
@ 2016-04-27  9:35     ` Adam Borowski
  2016-04-28  8:24       ` [tip:perf/urgent] " tip-bot for Adam Borowski
  0 siblings, 1 reply; 5+ messages in thread
From: Adam Borowski @ 2016-04-27  9:35 UTC (permalink / raw)
  To: Ingo Molnar, linux-kernel, Stephane Eranian, Peter Zijlstra,
	Thomas Gleixner, H. Peter Anvin, x86, Borislav Petkov
  Cc: Adam Borowski

The entry for PERF_COUNT_HW_REF_CPU_CYCLES is not used on AMD, but is
referenced by filter_events() which expects undefined events to have a
value of 0.

UBSAN: Undefined behaviour in arch/x86/events/amd/core.c:132:30
index 9 is out of range for type 'u64 [9]'
UBSAN: Undefined behaviour in arch/x86/events/amd/core.c:132:9
load of address ffffffff81c021c8 with insufficient space
for an object of type 'const u64'

Signed-off-by: Adam Borowski <kilobyte@angband.pl>
---
 arch/x86/events/amd/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
index 86a9bec..bd3e842 100644
--- a/arch/x86/events/amd/core.c
+++ b/arch/x86/events/amd/core.c
@@ -115,7 +115,7 @@ static __initconst const u64 amd_hw_cache_event_ids
 /*
  * AMD Performance Monitor K7 and later.
  */
-static const u64 amd_perfmon_event_map[] =
+static const u64 amd_perfmon_event_map[PERF_COUNT_HW_MAX] =
 {
   [PERF_COUNT_HW_CPU_CYCLES]			= 0x0076,
   [PERF_COUNT_HW_INSTRUCTIONS]			= 0x00c0,
-- 
2.8.1

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

* [tip:perf/urgent] perf/x86/amd: Set the size of event map array to PERF_COUNT_HW_MAX
  2016-04-27  9:35     ` [PATCH] perf/x86/amd: Set the size of event map array to PERF_COUNT_HW_MAX Adam Borowski
@ 2016-04-28  8:24       ` tip-bot for Adam Borowski
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Adam Borowski @ 2016-04-28  8:24 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: jolsa, bp, alexander.shishkin, mingo, eranian, tglx,
	vincent.weaver, acme, efault, linux-kernel, kilobyte, peterz,
	hpa

Commit-ID:  0a25556f84d5f79e68e9502bb1f32a43377ab2bf
Gitweb:     http://git.kernel.org/tip/0a25556f84d5f79e68e9502bb1f32a43377ab2bf
Author:     Adam Borowski <kilobyte@angband.pl>
AuthorDate: Wed, 27 Apr 2016 11:35:31 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 28 Apr 2016 10:20:25 +0200

perf/x86/amd: Set the size of event map array to PERF_COUNT_HW_MAX

The entry for PERF_COUNT_HW_REF_CPU_CYCLES is not used on AMD, but is
referenced by filter_events() which expects undefined events to have a
value of 0.

Found via KASAN:

  UBSAN: Undefined behaviour in arch/x86/events/amd/core.c:132:30
  index 9 is out of range for type 'u64 [9]'
  UBSAN: Undefined behaviour in arch/x86/events/amd/core.c:132:9
  load of address ffffffff81c021c8 with insufficient space for an object of type 'const u64'

Signed-off-by: Adam Borowski <kilobyte@angband.pl>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Link: http://lkml.kernel.org/r/1461749731-30979-1-git-send-email-kilobyte@angband.pl
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/events/amd/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
index 86a9bec..bd3e842 100644
--- a/arch/x86/events/amd/core.c
+++ b/arch/x86/events/amd/core.c
@@ -115,7 +115,7 @@ static __initconst const u64 amd_hw_cache_event_ids
 /*
  * AMD Performance Monitor K7 and later.
  */
-static const u64 amd_perfmon_event_map[] =
+static const u64 amd_perfmon_event_map[PERF_COUNT_HW_MAX] =
 {
   [PERF_COUNT_HW_CPU_CYCLES]			= 0x0076,
   [PERF_COUNT_HW_INSTRUCTIONS]			= 0x00c0,

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

end of thread, other threads:[~2016-04-28  8:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-27  1:19 [PATCH] perf/x86/amd: Explicitly define PERF_COUNT_HW_REF_CPU_CYCLES as undefined Adam Borowski
2016-04-27  8:03 ` Ingo Molnar
2016-04-27  9:32   ` Adam Borowski
2016-04-27  9:35     ` [PATCH] perf/x86/amd: Set the size of event map array to PERF_COUNT_HW_MAX Adam Borowski
2016-04-28  8:24       ` [tip:perf/urgent] " tip-bot for Adam Borowski

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.