Re: [PATCH 1/2] perf: Correctly align perf event tracing buffer

From: Peter Zijlstra
Date: Mon Mar 29 2010 - 05:11:44 EST


On Sun, 2010-03-28 at 07:11 +0200, Frederic Weisbecker wrote:
> The trace event buffer used by perf to record raw sample events
> is typed as an array of char and may then not be aligned to 8
> by alloc_percpu().
>
> But we need it to be aligned to 8 in sparc64 because we cast
> this buffer into a random structure type built by the TRACE_EVENT()
> macro to store the traces. So if a random 64 bits field is accessed
> inside, it may be not under an expected good alignment.
>
> Use an array of long instead to force the appropriate alignment, and
> perform a compile time check to ensure the size in byte of the buffer
> is a multiple of sizeof(long) so that its actual size doesn't get
> shrinked under us.
>
> This fixes unaligned accesses reported while using perf lock
> in sparc 64.
>
> Suggested-by: David Miller <davem@xxxxxxxxxxxxx>
> Suggested-by: Tejun Heo <htejun@xxxxxxxxx>
> Signed-off-by: Frederic Weisbecker <fweisbec@xxxxxxxxx>
> Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
> Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> Cc: Paul Mackerras <paulus@xxxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxx>
> Cc: David Miller <davem@xxxxxxxxxxxxx>
> Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
> ---
> kernel/trace/trace_event_perf.c | 11 +++++++++--
> 1 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c
> index 0709e4f..69941f3 100644
> --- a/kernel/trace/trace_event_perf.c
> +++ b/kernel/trace/trace_event_perf.c
> @@ -15,7 +15,12 @@ EXPORT_PER_CPU_SYMBOL_GPL(perf_trace_regs);
> static char *perf_trace_buf;
> static char *perf_trace_buf_nmi;
>
> -typedef typeof(char [PERF_MAX_TRACE_SIZE]) perf_trace_t ;
> +/*
> + * Force it to be aligned to unsigned long to avoid misaligned accesses
> + * suprises
> + */
> +typedef typeof(unsigned long [PERF_MAX_TRACE_SIZE / sizeof(unsigned long)])
> + perf_trace_t;
>

wouldn't __aligned(8) be simpler?

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/