]> git.baikalelectronics.ru Git - kernel.git/commit
tracing: Use a struct alignof to determine trace event field alignment
authorSteven Rostedt (Google) <rostedt@goodmis.org>
Sun, 31 Jul 2022 05:59:28 +0000 (01:59 -0400)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Sun, 31 Jul 2022 18:55:01 +0000 (14:55 -0400)
commit062237f79c41cc6edb4fbe78dfc1a6ad789c7867
tree82197710fc2f45100c5c3ebdbd9686d5c50f05f9
parent5ba33e51e32c9c5defae93e4e97de729da382605
tracing: Use a struct alignof to determine trace event field alignment

alignof() gives an alignment of types as they would be as standalone
variables. But alignment in structures might be different, and when
building the fields of events, the alignment must be the actual
alignment otherwise the field offsets may not match what they actually
are.

This caused trace-cmd to crash, as libtraceevent did not check if the
field offset was bigger than the event. The write_msr and read_msr
events on 32 bit had their fields incorrect, because it had a u64 field
between two ints. alignof(u64) would give 8, but the u64 field was at a
4 byte alignment.

Define a macro as:

   ALIGN_STRUCTFIELD(type) ((int)(offsetof(struct {char a; type b;}, b)))

which gives the actual alignment of types in a structure.

Link: https://lkml.kernel.org/r/20220731015928.7ab3a154@rorschach.local.home
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: stable@vger.kernel.org
Fixes: cdb7737c5d2df ("ftrace: Rework event_create_dir()")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
include/trace/stages/stage4_event_fields.h