Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3084140rwb; Mon, 15 Aug 2022 17:44:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR7jETN1HktSOBn0kyb5s4ZjGFe2mcObiwUYx1YEB3+hEJSLNbeuNFj5ZFLiTy18i1OsDeKj X-Received: by 2002:a17:902:d50c:b0:16f:736:33a0 with SMTP id b12-20020a170902d50c00b0016f073633a0mr20193883plg.137.1660610664077; Mon, 15 Aug 2022 17:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660610664; cv=none; d=google.com; s=arc-20160816; b=y8RVIvACA3uZZMsEAfhqazItAC6irnc9G3LtffSJwopnRmQ6aIGpxiJzTn8i2La1LN dXEuKcjY+r3tVdVMCuz4GXgpWrkO0C/Y3A4d5X/yxrVFRZtPeZ17yFDu6W7nOKmHR31j ygN2F494JsNKjlqZLwMXMu9UaVUJkozDju+nvWJH8BKhD2owq/7fapmWOsINFq4XIZ6u OgU/nvA2u4kSrttjkvEEy2KVQ0gokUzwG3j1mh6S2yEbnKZFqfWD6v1iMHnH/pkXPoIi oGnkbiI3eyffp3r1p+/+uewDgrH8XL0ibVDfBa/IgXT0MpDHqo4wS9AX+zbocDJ37+56 riXA== 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=ByZTDSCkgBlOV9q6Cj8b/EZJYCWbNF+YEXJUCiQJsKyLWG5kLRaCsohos7b1K4IF0n PTbkCTmjET8AxhOI2lp0hpY0LuTGZBGrj0hnYBDOwPKy14iYG7GF6zrAgk9wWI3DfE61 zeNjg9qndS13mGnSpoKyT9zHKaGtKlaBs5d+NCNIB6zisF/CQW2cnTa0Ev5hqodz2Eg/ jYntt/e3/rVMdf7/BR9iPLi5SfVaskMvBXv9tM4cJUnkcGqviFLNpinMixLbd9ODUqJm EOJz9iUHVj7qQfNfijiSTSCvpuJe1Pewmr7QOKbAmzf604I1lnCf/AnidvR4lboITMuo 96Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QfdhulPr; 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 mu14-20020a17090b388e00b001f7353b22b7si20986014pjb.135.2022.08.15.17.44.13; Mon, 15 Aug 2022 17:44:24 -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=QfdhulPr; 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 S1353434AbiHOXev (ORCPT + 99 others); Mon, 15 Aug 2022 19:34:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353352AbiHOX14 (ORCPT ); Mon, 15 Aug 2022 19:27:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA1D114E113; Mon, 15 Aug 2022 13:07:29 -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 ams.source.kernel.org (Postfix) with ESMTPS id 57F20B81142; Mon, 15 Aug 2022 20:07:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70FA7C433C1; Mon, 15 Aug 2022 20:07:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594046; bh=fKV254h6rlaIOkZW+7MI6wx3Yxyt5S+adxZmtrAb6Ks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QfdhulPrNobuY0bmXMLIAgevj3ALf0SW/XRtFxsYIchArZF8qliXdm39RSXQxlIc7 zDzYByMxoRTppNAz2OR024dzWxcPvYd1NW6vcKnISOFiN6ZtMch4uLOVNZyShuS44T sR0In83F8ybFljbKj0jRuoGFG+/z5U/0aub1yuwI= 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.18 1047/1095] tracing: Use a struct alignof to determine trace event field alignment Date: Mon, 15 Aug 2022 20:07:26 +0200 Message-Id: <20220815180512.392209275@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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