* [PATCH v2] perf,x86: fix uninitialized pt_regs in intel_pmu_drain_bts_buffer()
@ 2013-03-19 15:10 Stephane Eranian
2013-03-21 18:15 ` [tip:perf/urgent] perf/x86: Fix " tip-bot for Stephane Eranian
0 siblings, 1 reply; 2+ messages in thread
From: Stephane Eranian @ 2013-03-19 15:10 UTC (permalink / raw)
To: linux-kernel; +Cc: peterz, mingo, sqazi, ak, jolsa
This patch fixes an uninitialized pt_regs struct in drain BTS
function. The pt_regs struct is propagated all the way to the
code_get_segment() function from perf_instruction_pointer()
and may get garbage.
We cannot simply inherit the actual pt_regs from the interrupt
because BTS must be flushed on context-switch or when the associated
event is disabled. And there we do not have a pt_regs handy.
Setting pt_regs to all zeroes may not be the best option but it is
not clear what else to do given where the drain_bts_buffer() is called
from.
In V2, we move the memset() later in the code to avoid doing it when
we end up returning early without doing the actual BTS processing.
Also dropped the reg.val initialization because it is redundant with
the memset() as suggested by PeterZ.
Signed-off-by: Stephane Eranian <eranian@google.com>
---
diff --git a/arch/x86/kernel/cpu/perf_event_intel_ds.c b/arch/x86/kernel/cpu/perf_event_intel_ds.c
index b05a575..26830f3 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_ds.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c
@@ -314,10 +314,11 @@ int intel_pmu_drain_bts_buffer(void)
if (top <= at)
return 0;
+ memset(®s, 0, sizeof(regs));
+
ds->bts_index = ds->bts_buffer_base;
perf_sample_data_init(&data, 0, event->hw.last_period);
- regs.ip = 0;
/*
* Prepare a generic sample, i.e. fill in the invariant fields.
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [tip:perf/urgent] perf/x86: Fix uninitialized pt_regs in intel_pmu_drain_bts_buffer()
2013-03-19 15:10 [PATCH v2] perf,x86: fix uninitialized pt_regs in intel_pmu_drain_bts_buffer() Stephane Eranian
@ 2013-03-21 18:15 ` tip-bot for Stephane Eranian
0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Stephane Eranian @ 2013-03-21 18:15 UTC (permalink / raw)
To: linux-tip-commits; +Cc: linux-kernel, eranian, hpa, mingo, a.p.zijlstra, tglx
Commit-ID: 0e48026ae7abf871e51eaa9183c81ab5bef4c267
Gitweb: http://git.kernel.org/tip/0e48026ae7abf871e51eaa9183c81ab5bef4c267
Author: Stephane Eranian <eranian@google.com>
AuthorDate: Tue, 19 Mar 2013 16:10:38 +0100
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 21 Mar 2013 12:03:29 +0100
perf/x86: Fix uninitialized pt_regs in intel_pmu_drain_bts_buffer()
This patch fixes an uninitialized pt_regs struct in drain BTS
function. The pt_regs struct is propagated all the way to the
code_get_segment() function from perf_instruction_pointer()
and may get garbage.
We cannot simply inherit the actual pt_regs from the interrupt
because BTS must be flushed on context-switch or when the
associated event is disabled. And there we do not have a pt_regs
handy.
Setting pt_regs to all zeroes may not be the best option but it
is not clear what else to do given where the drain_bts_buffer()
is called from.
In V2, we move the memset() later in the code to avoid doing it
when we end up returning early without doing the actual BTS
processing. Also dropped the reg.val initialization because it
is redundant with the memset() as suggested by PeterZ.
Signed-off-by: Stephane Eranian <eranian@google.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: peterz@infradead.org
Cc: sqazi@google.com
Cc: ak@linux.intel.com
Cc: jolsa@redhat.com
Link: http://lkml.kernel.org/r/20130319151038.GA25439@quad
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
arch/x86/kernel/cpu/perf_event_intel_ds.c | 3 ++-
1 file changed, 2 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 826054a..f71c9f0 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_ds.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c
@@ -314,10 +314,11 @@ int intel_pmu_drain_bts_buffer(void)
if (top <= at)
return 0;
+ memset(®s, 0, sizeof(regs));
+
ds->bts_index = ds->bts_buffer_base;
perf_sample_data_init(&data, 0, event->hw.last_period);
- regs.ip = 0;
/*
* Prepare a generic sample, i.e. fill in the invariant fields.
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-03-21 18:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-19 15:10 [PATCH v2] perf,x86: fix uninitialized pt_regs in intel_pmu_drain_bts_buffer() Stephane Eranian
2013-03-21 18:15 ` [tip:perf/urgent] perf/x86: Fix " 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