From nobody Sun Dec 14 08:04:33 2025 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 08B66C00140 for ; Mon, 15 Aug 2022 19:59:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345828AbiHOT7X (ORCPT ); Mon, 15 Aug 2022 15:59:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346109AbiHOT5L (ORCPT ); Mon, 15 Aug 2022 15:57:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8CC7785A3; Mon, 15 Aug 2022 11:52:56 -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 0815B611ED; Mon, 15 Aug 2022 18:52:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB991C433C1; Mon, 15 Aug 2022 18:52:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660589575; bh=zm5yPCSka08KCN9psAi49vcukmwi+nuzh5ZWb1E34GA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yOXhaAMsxTcUB3DUPgaPMgfEkfdfMHAXOozOQTXdzilp8tLCzOVsLeWz4XSfKDBLy QFhqMPSfct3lfbOIISnPC5DXQkeCiZXXJkEI69rXr8Tt6TFCyi5LJi8k+zWtBeNVL6 jnf5OloM7SesjNP+2IAwx9k/AKO3h4bZY0pcRgG4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ingo Molnar , Andrew Morton , Peter Zijlstra , Thomas Gleixner , Masami Hiramatsu , "Steven Rostedt (Google)" Subject: [PATCH 5.15 760/779] tracing: Use a struct alignof to determine trace event field alignment Date: Mon, 15 Aug 2022 20:06:44 +0200 Message-Id: <20220815180409.926703705@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 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) commit 4c3d2f9388d36eb28640a220a6f908328442d873 upstream. 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 Cc: Andrew Morton Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Masami Hiramatsu Cc: stable@vger.kernel.org Fixes: 04ae87a52074e ("ftrace: Rework event_create_dir()") Signed-off-by: Steven Rostedt (Google) Signed-off-by: Greg Kroah-Hartman --- include/trace/trace_events.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/include/trace/trace_events.h +++ b/include/trace/trace_events.h @@ -479,16 +479,18 @@ static struct trace_event_functions trac =20 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) =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 @@ -500,7 +502,7 @@ static struct trace_event_functions trac #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