Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3260200rwb; Mon, 15 Aug 2022 22:34:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR5II+I6eMLoR2C4ztBDM9kod5MaskvDqo1u0LRhTvBrC+xf1vP0b1EvquKNyt4XV9b2RTKL X-Received: by 2002:a17:903:2286:b0:16f:8f52:c952 with SMTP id b6-20020a170903228600b0016f8f52c952mr20801218plh.126.1660628071569; Mon, 15 Aug 2022 22:34:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660628071; cv=none; d=google.com; s=arc-20160816; b=meQBIRfc+bZHx2q09s2TEQtbkGD5UMJ4/XVyYQrQkgNFWmTLlDacV0rU4Upfk0nE7q uurHjqD+57J9EIlJfIDt+AsUsI7+EC97pFk65bAt5qJKPhwCbUbKGxx+lsS9r2gSs8Bz RvOhtMaLK9prrQgSnN0T1EhSylifNCUfO6SWkq8EWRLl4DyRK6bbTeIIGO1aLCYnf9TF C5dPtZwFWIXmbi7kKzRhbU8nm269FWrLTr7m/GsM/vp72q/aOw5FnmXLjiCG2XgKnrH1 IlrFm66NBRm+xsrKWYK/Vrm57cUNYHpKvK/YhHrqJvsfbxfq2VFDfVkTI0FJLN8YajKJ jOqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5rVOz5k8IBJStuTro5txd6vPGg4uqXsU3SICfqFx+AA=; b=t2fOpZG8liMrv82z4OHrMxpVjXKft3KXtmom0o48lUkgCx8kDonAwQDWCiyhxyoEh2 Pbz5JtbUmb227lx8ogA7KThiLFERHCP/Z6GiSP98K7r2u0domU1PcRlna0c8ybRj52Jp +MgHUwpl+4eBbBXT4+xerFU1WTO4KR5+uMoyPhqvpGwFwg3L2syljcxRZ4zC2o13aT/D 6/rzntLAzXv4jb8QtPFJoOJ+cy06aofeYxhTtxfEjnZx6BKbclcdJA9sW/cFKydW4iIN nRsvt/U4prZtJCBaCCD5mi8tmWSsMCKG1hHnv+FI3VDS3JqjMDb4WQ5EVmMK2qfES6rs +mUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ic1xFufP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o186-20020a6341c3000000b0041d4b75332csi13009194pga.339.2022.08.15.22.34.21; Mon, 15 Aug 2022 22:34:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ic1xFufP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233524AbiHPEyS (ORCPT + 99 others); Tue, 16 Aug 2022 00:54:18 -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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/stages/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 @@ /* Stage 4 definitions for creating trace events */ +#define ALIGN_STRUCTFIELD(type) ((int)(offsetof(struct {char a; type b;}, b))) + #undef __field_ext #define __field_ext(_type, _item, _filter_type) { \ .type = #_type, .name = #_item, \ - .size = sizeof(_type), .align = __alignof__(_type), \ + .size = sizeof(_type), .align = ALIGN_STRUCTFIELD(_type), \ .is_signed = is_signed_type(_type), .filter_type = _filter_type }, #undef __field_struct_ext #define __field_struct_ext(_type, _item, _filter_type) { \ .type = #_type, .name = #_item, \ - .size = sizeof(_type), .align = __alignof__(_type), \ + .size = sizeof(_type), .align = ALIGN_STRUCTFIELD(_type), \ 0, .filter_type = _filter_type }, #undef __field @@ -23,7 +25,7 @@ #undef __array #define __array(_type, _item, _len) { \ .type = #_type"["__stringify(_len)"]", .name = #_item, \ - .size = sizeof(_type[_len]), .align = __alignof__(_type), \ + .size = sizeof(_type[_len]), .align = ALIGN_STRUCTFIELD(_type), \ .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER }, #undef __dynamic_array -- 2.35.1