* [PATCH] perf,x86: fix uninitialized pt_regs in intel_pmu_drain_bts_buffer()
@ 2013-03-18 13:46 Stephane Eranian
2013-03-19 12:43 ` Peter Zijlstra
0 siblings, 1 reply; 5+ messages in thread
From: Stephane Eranian @ 2013-03-18 13:46 UTC (permalink / raw)
To: linux-kernel; +Cc: peterz, mingo, jolsa, sqazi, ak
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.
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..208f0c8 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_ds.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c
@@ -302,6 +302,8 @@ int intel_pmu_drain_bts_buffer(void)
struct perf_sample_data data;
struct pt_regs regs;
+ memset(®s, 0, sizeof(regs));
+
if (!event)
return 0;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] perf,x86: fix uninitialized pt_regs in intel_pmu_drain_bts_buffer()
2013-03-18 13:46 [PATCH] perf,x86: fix uninitialized pt_regs in intel_pmu_drain_bts_buffer() Stephane Eranian
@ 2013-03-19 12:43 ` Peter Zijlstra
2013-03-19 12:50 ` Stephane Eranian
0 siblings, 1 reply; 5+ messages in thread
From: Peter Zijlstra @ 2013-03-19 12:43 UTC (permalink / raw)
To: Stephane Eranian; +Cc: linux-kernel, mingo, jolsa, sqazi, ak
On Mon, 2013-03-18 at 14:46 +0100, Stephane Eranian wrote:
>
> 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.
>
> 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..208f0c8 100644
> --- a/arch/x86/kernel/cpu/perf_event_intel_ds.c
> +++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c
> @@ -302,6 +302,8 @@ int intel_pmu_drain_bts_buffer(void)
> struct perf_sample_data data;
> struct pt_regs regs;
>
> + memset(®s, 0, sizeof(regs));
> +
> if (!event)
> return 0;
>
Should we not replace:
regs.ip = 0;
with that memset? It avoids the memset work in a few cases and removes
the then superfluous clearing of the IP field.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] perf,x86: fix uninitialized pt_regs in intel_pmu_drain_bts_buffer()
2013-03-19 12:43 ` Peter Zijlstra
@ 2013-03-19 12:50 ` Stephane Eranian
2013-03-19 12:58 ` Peter Zijlstra
0 siblings, 1 reply; 5+ messages in thread
From: Stephane Eranian @ 2013-03-19 12:50 UTC (permalink / raw)
To: Peter Zijlstra
Cc: LKML, mingo@elte.hu, Jiri Olsa, Salman Qazi, ak@linux.intel.com
On Tue, Mar 19, 2013 at 1:43 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Mon, 2013-03-18 at 14:46 +0100, Stephane Eranian wrote:
>>
>> 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.
>>
>> 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..208f0c8 100644
>> --- a/arch/x86/kernel/cpu/perf_event_intel_ds.c
>> +++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c
>> @@ -302,6 +302,8 @@ int intel_pmu_drain_bts_buffer(void)
>> struct perf_sample_data data;
>> struct pt_regs regs;
>>
>> + memset(®s, 0, sizeof(regs));
>> +
>> if (!event)
>> return 0;
>>
>
> Should we not replace:
>
> regs.ip = 0;
>
> with that memset? It avoids the memset work in a few cases and removes
> the then superfluous clearing of the IP field.
>
We could drop it because it's covered by the memset().
The issue here was that you eventually end up in code_segment_base() which
looks at other uninitialized fields in pt_regs and may cause breakage.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] perf,x86: fix uninitialized pt_regs in intel_pmu_drain_bts_buffer()
2013-03-19 12:50 ` Stephane Eranian
@ 2013-03-19 12:58 ` Peter Zijlstra
2013-03-19 13:02 ` Stephane Eranian
0 siblings, 1 reply; 5+ messages in thread
From: Peter Zijlstra @ 2013-03-19 12:58 UTC (permalink / raw)
To: Stephane Eranian
Cc: LKML, mingo@elte.hu, Jiri Olsa, Salman Qazi, ak@linux.intel.com
On Tue, 2013-03-19 at 13:50 +0100, Stephane Eranian wrote:
> > Should we not replace:
> >
> > regs.ip = 0;
> >
> > with that memset? It avoids the memset work in a few cases and
> removes
> > the then superfluous clearing of the IP field.
> >
> We could drop it because it's covered by the memset().
Yeah, but also place the memset a little lower than you did, avoids the
stack writes when not needed.
> The issue here was that you eventually end up in code_segment_base()
> which
> looks at other uninitialized fields in pt_regs and may cause breakage.
Right, your changelog said so ;-)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] perf,x86: fix uninitialized pt_regs in intel_pmu_drain_bts_buffer()
2013-03-19 12:58 ` Peter Zijlstra
@ 2013-03-19 13:02 ` Stephane Eranian
0 siblings, 0 replies; 5+ messages in thread
From: Stephane Eranian @ 2013-03-19 13:02 UTC (permalink / raw)
To: Peter Zijlstra
Cc: LKML, mingo@elte.hu, Jiri Olsa, Salman Qazi, ak@linux.intel.com
On Tue, Mar 19, 2013 at 1:58 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Tue, 2013-03-19 at 13:50 +0100, Stephane Eranian wrote:
>> > Should we not replace:
>> >
>> > regs.ip = 0;
>> >
>> > with that memset? It avoids the memset work in a few cases and
>> removes
>> > the then superfluous clearing of the IP field.
>> >
>> We could drop it because it's covered by the memset().
>
> Yeah, but also place the memset a little lower than you did, avoids the
> stack writes when not needed.
>
Ok, I get it now. Yes, we can move it after the test and drop reg.val = 0.
>> The issue here was that you eventually end up in code_segment_base()
>> which
>> looks at other uninitialized fields in pt_regs and may cause breakage.
>
> Right, your changelog said so ;-)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-03-19 13:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-18 13:46 [PATCH] perf,x86: fix uninitialized pt_regs in intel_pmu_drain_bts_buffer() Stephane Eranian
2013-03-19 12:43 ` Peter Zijlstra
2013-03-19 12:50 ` Stephane Eranian
2013-03-19 12:58 ` Peter Zijlstra
2013-03-19 13:02 ` Stephane Eranian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox