From nobody Sun Feb 8 10:33:08 2026 Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85420267B07 for ; Fri, 6 Feb 2026 20:07:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.40.44.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770408448; cv=none; b=ESl88D+xjRfqDGyufvjPs9XCPRusFjbZ64eq/dKQMiaev2Guijt7mg6jsqySUDUCTl1H/2Szdd7cU8EKaig1SRuJxBvE7/P/SPWRVrKnvI2eTQT9KmB1P9o8c8A1ERQgn0DA+p80wMecpTiILHDeXZJS0/iLNvDzwAdeSPEv3u0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770408448; c=relaxed/simple; bh=CYjMyVxi1vf2r5X+ds7bCKYW8/FuOjhWpv2KNURsxEA=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=FD9/zno6dArHoFBmbjTTICMsusZbh/z5Av/czgXGDS8Q2jFhOA9+mrBgY5fSorsonhDBFnlq8q9qTSnC2d8NJzklW0zxNCSkSY6JvHjj08+L1M6+MkNgZ/x0I0FhsV2PGQ3+5/j4kr4udrxBPSfgh8cXPFppbsit94yAvXYduDg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=goodmis.org; spf=pass smtp.mailfrom=goodmis.org; arc=none smtp.client-ip=216.40.44.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=goodmis.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=goodmis.org Received: from omf20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 80E01B6FA5; Fri, 6 Feb 2026 20:07:20 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: rostedt@goodmis.org) by omf20.hostedemail.com (Postfix) with ESMTPA id 8C4E220029; Fri, 6 Feb 2026 20:07:18 +0000 (UTC) Date: Fri, 6 Feb 2026 15:07:56 -0500 From: Steven Rostedt To: LKML Cc: Masami Hiramatsu , Mathieu Desnoyers , Mark Rutland , "jempty.liang" Subject: [for-linus][PATCH] tracing: Fix ftrace event field alignments Message-ID: <20260206150756.36780f53@gandalf.local.home> X-Mailer: Claws Mail 3.20.0git84 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Stat-Signature: gxu53xew88osidqcjx394sromh8756px X-Rspamd-Server: rspamout01 X-Rspamd-Queue-Id: 8C4E220029 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Session-ID: U2FsdGVkX18qi9PyK7FeWZS6DGJlpmSpOqLGoc+emeM= X-HE-Tag: 1770408438-284476 X-HE-Meta: U2FsdGVkX1+c8CefcburoRi405nQGJlGpXf7gDTKkooXxHi+h85fxu/svWln/3AALVGX+Bw5C5Tae9ulZTwMfigUq9Uwl94qNoALXu88QrcX3SP1InB+zTSs98a200QdFxR88rcnPcpE0AWc3c4XK41vCkRyXC5moYv/hxs8iGUJXREma5+GlaCoSjR5ZkmI2GxQDIg0/LBojinVulwrmnalM0cpsHGo3lVIN/uBWasPRMRZqL4k4SkPA1qxg2DcVGSuLFKemnEd8FnYHFLw9SJEGkBbP7GafRToRM21o6cuhaNYMpxc/pd0S/ILDRI6qZOwnueApgzLoC9URKaFZxXqstQ6e0pIVfLYwY4tBFGx9yhYrHyh85Rr4/UuHrkQVKnu8jowQhrlLZ34sGDEIxYVHthfOfh1QKzqsciHmeTdhPD8W+UDmCQ8n0/rJ4I5z8VqVd7wNCHGFz8kMvf4SnNL0rG68sh68lS9QyyUtNTYvuxUqWkIQ3tPbgr2sLLOPzF32ABV3FeFDKewisd+BQcRfUDyAlN/7SF5IRyQirzOU01aU2X8OrYQUb1Q+ii3NbVfyqOdFiHVAKvz+nwauj/ocErarr29cfE/cOGTiRvEB6+0KDeTTDVfbfHBrhbH Content-Type: text/plain; charset="utf-8" tracing fix for v6.19: - Fix event format field alignments for 32 bit architectures The fields in the event format files are used to parse the raw binary buffer data by applications. If they are incorrect, then the application produces garbage. On 32 bit architectures, the function graph 64bit calltime and rettime were off by 4bytes. That's because the actual fields are in a packed structure but the macros used by the ftrace events did not mark them as packed, and instead, gave them their natural alignment which made their offsets off by 4 bytes. There are macros to have a packed field within an embedded structure of an event, but there's no macro for normal fields within a packed structure of the event. The macro __field_packed() was used for the packed embedded structure field. Rename that to __field_desc_pcaked() (to match the non-packed embedded field macro __field_desc()), and make __field_packed() for fields that are in a packed event structure (which matches the unpacked __field() macro). Switch the calltime and rettime fields of the function graph event to use the new __field_packed() and this makes the offsets correct. git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git trace/fixes Head SHA1: 033c55fe2e326bea022c3cc5178ecf3e0e459b82 Steven Rostedt (1): tracing: Fix ftrace event field alignments ---- kernel/trace/trace.h | 7 +++++-- kernel/trace/trace_entries.h | 32 ++++++++++++++++---------------- kernel/trace/trace_export.c | 21 +++++++++++++++------ 3 files changed, 36 insertions(+), 24 deletions(-) --------------------------- commit 033c55fe2e326bea022c3cc5178ecf3e0e459b82 Author: Steven Rostedt Date: Wed Feb 4 11:36:28 2026 -0500 tracing: Fix ftrace event field alignments =20 The fields of ftrace specific events (events used to save ftrace intern= al events like function traces and trace_printk) are generated similarly to how normal trace event fields are generated. That is, the fields are ad= ded to a trace_events_fields array that saves the name, offset, size, alignment and signness of the field. It is used to produce the output in the format file in tracefs so that tooling knows how to parse the binary data of the trace events. =20 The issue is that some of the ftrace event structures are packed. The function graph exit event structures are one of them. The 64 bit callti= me and rettime fields end up 4 byte aligned, but the algorithm to show to userspace shows them as 8 byte aligned. =20 The macros that create the ftrace events has one for embedded structure fields. There's two macros for theses fields: =20 __field_desc() and __field_packed() =20 The difference of the latter macro is that it treats the field as packe= d. =20 Rename that field to __field_desc_packed() and create replace the __field_packed() to be a normal field that is packed and have the callt= ime and rettime use those. =20 This showed up on 32bit architectures for function graph time fields. It had: =20 ~# cat /sys/kernel/tracing/events/ftrace/funcgraph_exit/format [..] field:unsigned long func; offset:8; size:4; signed:= 0; field:unsigned int depth; offset:12; size:4; signed:= 0; field:unsigned int overrun; offset:16; size:4; signed:= 0; field:unsigned long long calltime; offset:24; size:8;= signed:0; field:unsigned long long rettime; offset:32; size:8;= signed:0; =20 Notice that overrun is at offset 16 with size 4, where in the structure calltime is at offset 20 (16 + 4), but it shows the offset at 24. That's because it used the alignment of unsigned long long when used as a declaration and not as a member of a structure where it would be aligned by word size (in this case 4). =20 By using the proper structure alignment, the format has it at the corre= ct offset: =20 ~# cat /sys/kernel/tracing/events/ftrace/funcgraph_exit/format [..] field:unsigned long func; offset:8; size:4; signed:= 0; field:unsigned int depth; offset:12; size:4; signed:= 0; field:unsigned int overrun; offset:16; size:4; signed:= 0; field:unsigned long long calltime; offset:20; size:8;= signed:0; field:unsigned long long rettime; offset:28; size:8;= signed:0; =20 Cc: stable@vger.kernel.org Cc: Mathieu Desnoyers Cc: Mark Rutland Acked-by: Masami Hiramatsu (Google) Reported-by: "jempty.liang" Link: https://patch.msgid.link/20260204113628.53faec78@gandalf.local.ho= me Fixes: 04ae87a52074e ("ftrace: Rework event_create_dir()") Closes: https://lore.kernel.org/all/20260130015740.212343-1-imntjempty@= 163.com/ Closes: https://lore.kernel.org/all/20260202123342.2544795-1-imntjempty= @163.com/ Signed-off-by: Steven Rostedt (Google) diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index b6d42fe06115..c11edec5d8f5 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -68,14 +68,17 @@ enum trace_type { #undef __field_fn #define __field_fn(type, item) type item; =20 +#undef __field_packed +#define __field_packed(type, item) type item; + #undef __field_struct #define __field_struct(type, item) __field(type, item) =20 #undef __field_desc #define __field_desc(type, container, item) =20 -#undef __field_packed -#define __field_packed(type, container, item) +#undef __field_desc_packed +#define __field_desc_packed(type, container, item) =20 #undef __array #define __array(type, item, size) type item[size]; diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h index f6a8d29c0d76..54417468fdeb 100644 --- a/kernel/trace/trace_entries.h +++ b/kernel/trace/trace_entries.h @@ -79,8 +79,8 @@ FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry, =20 F_STRUCT( __field_struct( struct ftrace_graph_ent, graph_ent ) - __field_packed( unsigned long, graph_ent, func ) - __field_packed( unsigned long, graph_ent, depth ) + __field_desc_packed(unsigned long, graph_ent, func ) + __field_desc_packed(unsigned long, graph_ent, depth ) __dynamic_array(unsigned long, args ) ), =20 @@ -96,9 +96,9 @@ FTRACE_ENTRY_PACKED(fgraph_retaddr_entry, fgraph_retaddr_= ent_entry, =20 F_STRUCT( __field_struct( struct fgraph_retaddr_ent, graph_rent ) - __field_packed( unsigned long, graph_rent.ent, func ) - __field_packed( unsigned long, graph_rent.ent, depth ) - __field_packed( unsigned long, graph_rent, retaddr ) + __field_desc_packed( unsigned long, graph_rent.ent, func ) + __field_desc_packed( unsigned long, graph_rent.ent, depth ) + __field_desc_packed( unsigned long, graph_rent, retaddr ) __dynamic_array(unsigned long, args ) ), =20 @@ -123,12 +123,12 @@ FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_= entry, =20 F_STRUCT( __field_struct( struct ftrace_graph_ret, ret ) - __field_packed( unsigned long, ret, func ) - __field_packed( unsigned long, ret, retval ) - __field_packed( unsigned int, ret, depth ) - __field_packed( unsigned int, ret, overrun ) - __field(unsigned long long, calltime ) - __field(unsigned long long, rettime ) + __field_desc_packed( unsigned long, ret, func ) + __field_desc_packed( unsigned long, ret, retval ) + __field_desc_packed( unsigned int, ret, depth ) + __field_desc_packed( unsigned int, ret, overrun ) + __field_packed(unsigned long long, calltime) + __field_packed(unsigned long long, rettime ) ), =20 F_printk("<-- %ps (%u) (start: %llx end: %llx) over: %u retval: %lx", @@ -146,11 +146,11 @@ FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_= entry, =20 F_STRUCT( __field_struct( struct ftrace_graph_ret, ret ) - __field_packed( unsigned long, ret, func ) - __field_packed( unsigned int, ret, depth ) - __field_packed( unsigned int, ret, overrun ) - __field(unsigned long long, calltime ) - __field(unsigned long long, rettime ) + __field_desc_packed( unsigned long, ret, func ) + __field_desc_packed( unsigned int, ret, depth ) + __field_desc_packed( unsigned int, ret, overrun ) + __field_packed(unsigned long long, calltime ) + __field_packed(unsigned long long, rettime ) ), =20 F_printk("<-- %ps (%u) (start: %llx end: %llx) over: %u", diff --git a/kernel/trace/trace_export.c b/kernel/trace/trace_export.c index 1698fc22afa0..32a42ef31855 100644 --- a/kernel/trace/trace_export.c +++ b/kernel/trace/trace_export.c @@ -42,11 +42,14 @@ static int ftrace_event_register(struct trace_event_cal= l *call, #undef __field_fn #define __field_fn(type, item) type item; =20 +#undef __field_packed +#define __field_packed(type, item) type item; + #undef __field_desc #define __field_desc(type, container, item) type item; =20 -#undef __field_packed -#define __field_packed(type, container, item) type item; +#undef __field_desc_packed +#define __field_desc_packed(type, container, item) type item; =20 #undef __array #define __array(type, item, size) type item[size]; @@ -104,11 +107,14 @@ static void __always_unused ____ftrace_check_##name(v= oid) \ #undef __field_fn #define __field_fn(_type, _item) __field_ext(_type, _item, FILTER_TRACE_FN) =20 +#undef __field_packed +#define __field_packed(_type, _item) __field_ext_packed(_type, _item, FILT= ER_OTHER) + #undef __field_desc #define __field_desc(_type, _container, _item) __field_ext(_type, _item, F= ILTER_OTHER) =20 -#undef __field_packed -#define __field_packed(_type, _container, _item) __field_ext_packed(_type,= _item, FILTER_OTHER) +#undef __field_desc_packed +#define __field_desc_packed(_type, _container, _item) __field_ext_packed(_= type, _item, FILTER_OTHER) =20 #undef __array #define __array(_type, _item, _len) { \ @@ -146,11 +152,14 @@ static struct trace_event_fields ftrace_event_fields_= ##name[] =3D { \ #undef __field_fn #define __field_fn(type, item) =20 +#undef __field_packed +#define __field_packed(type, item) + #undef __field_desc #define __field_desc(type, container, item) =20 -#undef __field_packed -#define __field_packed(type, container, item) +#undef __field_desc_packed +#define __field_desc_packed(type, container, item) =20 #undef __array #define __array(type, item, len)