Skip to content

Commit 4c3d2f9

Browse files
committed
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/[email protected] Cc: Ingo Molnar <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: [email protected] Fixes: 04ae87a ("ftrace: Rework event_create_dir()") Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent e88043c commit 4c3d2f9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

include/trace/stages/stage4_event_fields.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
/* Stage 4 definitions for creating trace events */
44

5+
#define ALIGN_STRUCTFIELD(type) ((int)(offsetof(struct {char a; type b;}, b)))
6+
57
#undef __field_ext
68
#define __field_ext(_type, _item, _filter_type) { \
79
.type = #_type, .name = #_item, \
8-
.size = sizeof(_type), .align = __alignof__(_type), \
10+
.size = sizeof(_type), .align = ALIGN_STRUCTFIELD(_type), \
911
.is_signed = is_signed_type(_type), .filter_type = _filter_type },
1012

1113
#undef __field_struct_ext
1214
#define __field_struct_ext(_type, _item, _filter_type) { \
1315
.type = #_type, .name = #_item, \
14-
.size = sizeof(_type), .align = __alignof__(_type), \
16+
.size = sizeof(_type), .align = ALIGN_STRUCTFIELD(_type), \
1517
0, .filter_type = _filter_type },
1618

1719
#undef __field
@@ -23,7 +25,7 @@
2325
#undef __array
2426
#define __array(_type, _item, _len) { \
2527
.type = #_type"["__stringify(_len)"]", .name = #_item, \
26-
.size = sizeof(_type[_len]), .align = __alignof__(_type), \
28+
.size = sizeof(_type[_len]), .align = ALIGN_STRUCTFIELD(_type), \
2729
.is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
2830

2931
#undef __dynamic_array

0 commit comments

Comments
 (0)