From: Frederic Weisbecker on
Hi,

While using the lock events through perf in a sparc box, I can see
the following message repeated many times:

Kernel unaligned access at TPC[49357c] perf_trace_lock_acquire+0xb4/0x180

It actually hangs the box as the messages are sent to a serial console.

When used with perf, the trace events use a per cpu buffer allocated
in kernel/trace/trace_event_perf.c, and the allocation appears to return
a misaligned percpu pointer. It is aligned to 4 while it seems it
requires to be aligned to 8.

The cpu offsets themselves are well aligned, below is a home made dump of
the per_cpu_offset(cpu) as they are attributed in arch/sparc/kernel/smp_64.c
in setup_per_cpu_areas():

[ 0.000000] cpu: 0 offset: fffff8001121e000
[ 0.000000] cpu: 1 offset: fffff8001141e000
[ 0.000000] cpu: 2 offset: fffff8001161e000
[ 0.000000] cpu: 3 offset: fffff8001181e000
[ 0.000000] cpu: 4 offset: fffff80011a1e000
[etc..]


But perf_trace_buf (which is the per cpu pointer) has the address
0000000000bae074, returned by alloc_percpu().
Adding this to the per_cpu_offset(cpu) gives the misaligned
address and sparc complains when it is dereferenced.

To reproduce, you can just go the tools/perf directory, build
it and launch:

./perf record -a -f -e lock:* sleep 1

I've attached the config.

Thanks.