From nobody Mon Sep 29 21:18:49 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 8D3A6C282E7 for ; Tue, 16 Aug 2022 04:54:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233545AbiHPEyT (ORCPT ); Tue, 16 Aug 2022 00:54:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233750AbiHPEvp (ORCPT ); Tue, 16 Aug 2022 00:51:45 -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 9301EDB07F; Mon, 15 Aug 2022 13:49:17 -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 09CB561275; Mon, 15 Aug 2022 20:49:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E87E3C433C1; Mon, 15 Aug 2022 20:49:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596553; bh=fKV254h6rlaIOkZW+7MI6wx3Yxyt5S+adxZmtrAb6Ks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ic1xFufPguzJ5gaNTk23OipVHQn+Y2vknPFr3gaY8ZJ+uahO4sMRjNtov4gJ85cya 6wy8QuoC+r7pMSyzKILrec3vlbDMcnNwb13G8K9fx07fh8W1MVpyd3GdY9At2WVkQG va41SWtJCF+9w2K6j26oewqnJkc1sVJ4LqX4psmY= 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)" , Sasha Levin Subject: [PATCH 5.19 1115/1157] tracing: Use a struct alignof to determine trace event field alignment Date: Mon, 15 Aug 2022 20:07:51 +0200 Message-Id: <20220815180524.924236844@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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) [ Upstream commit 4c3d2f9388d36eb28640a220a6f908328442d873 ] 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: Sasha Levin --- 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