From nobody Tue Apr 14 22:46:10 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC54FC3F6B0 for ; Sun, 31 Jul 2022 05:59:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236222AbiGaF7r (ORCPT ); Sun, 31 Jul 2022 01:59:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231243AbiGaF7o (ORCPT ); Sun, 31 Jul 2022 01:59:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68F6513CE9 for ; Sat, 30 Jul 2022 22:59:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7B90460DBF for ; Sun, 31 Jul 2022 05:59:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E42AC433C1; Sun, 31 Jul 2022 05:59:40 +0000 (UTC) Date: Sun, 31 Jul 2022 01:59:28 -0400 From: Steven Rostedt To: LKML Cc: Ingo Molnar , Andrew Morton , Peter Zijlstra , Thomas Gleixner , Masami Hiramatsu Subject: [PATCH] tracing: Use a struct alignof to determine trace event field alignment Message-ID: <20220731015928.7ab3a154@rorschach.local.home> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" 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. Cc: stable@vger.kernel.org Fixes: 04ae87a52074e ("ftrace: Rework event_create_dir()") Signed-off-by: Steven Rostedt (Google) --- include/trace/stages/stage4_event_fields.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/trace/stages/stage4_event_fields.h b/include/trace/sta= ges/stage4_event_fields.h index c3790ec7a453..80d34f396555 100644 --- a/include/trace/stages/stage4_event_fields.h +++ b/include/trace/stages/stage4_event_fields.h @@ -2,16 +2,18 @@ =20 /* Stage 4 definitions for creating trace events */ =20 +#define ALIGN_STRUCTFIELD(type) ((int)(offsetof(struct {char a; type b;}, = b))) + #undef __field_ext #define __field_ext(_type, _item, _filter_type) { \ .type =3D #_type, .name =3D #_item, \ - .size =3D sizeof(_type), .align =3D __alignof__(_type), \ + .size =3D sizeof(_type), .align =3D ALIGN_STRUCTFIELD(_type), \ .is_signed =3D is_signed_type(_type), .filter_type =3D _filter_type }, =20 #undef __field_struct_ext #define __field_struct_ext(_type, _item, _filter_type) { \ .type =3D #_type, .name =3D #_item, \ - .size =3D sizeof(_type), .align =3D __alignof__(_type), \ + .size =3D sizeof(_type), .align =3D ALIGN_STRUCTFIELD(_type), \ 0, .filter_type =3D _filter_type }, =20 #undef __field @@ -23,7 +25,7 @@ #undef __array #define __array(_type, _item, _len) { \ .type =3D #_type"["__stringify(_len)"]", .name =3D #_item, \ - .size =3D sizeof(_type[_len]), .align =3D __alignof__(_type), \ + .size =3D sizeof(_type[_len]), .align =3D ALIGN_STRUCTFIELD(_type), \ .is_signed =3D is_signed_type(_type), .filter_type =3D FILTER_OTHER }, =20 #undef __dynamic_array --=20 2.35.1