Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2887294rwb; Mon, 15 Aug 2022 13:20:15 -0700 (PDT) X-Google-Smtp-Source: AA6agR4yBZFNdLxIy7bdKSY7jKhwochIDN2LlDB1dNMwOV3cZ7v1zVmJuisY1sVrncfLsyXTcsy6 X-Received: by 2002:a17:906:29d:b0:6f0:18d8:7be0 with SMTP id 29-20020a170906029d00b006f018d87be0mr11045447ejf.561.1660594815351; Mon, 15 Aug 2022 13:20:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660594815; cv=none; d=google.com; s=arc-20160816; b=YD78btxaR51x9JXJuYlWct8toifg5IonsRJUFknjgCtV7VNg3vrRL68CGS358OHtZW H7htZPRK4LvR8TmbD5iJXLMx9wPInIZlQ23dIM1eL38KQ3JvL9Nh1+Lg5QZHjyLzIMje Q7Oyhyr0uhRgXTSvjT4q6k765c9Emb2E8R9Ab4tnQncYrNX3adIO3FrZLuXCfSVKQv8r A+d4+7bSO2YzJchSQSZ8FQQnNH0AJD/FovHkCu7fS6Vs+HoXPlXvYpEy1RNuQrWFKvYF 7Z+el5ZT3Ov74LvcVhR9c05DWHrQiWZ4s3rPzkJmW1hiPcE1VjSIKrsjBhQFVC3JnRLZ gYLg== 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=QtSn+PXHXVXn5nIcEPZBDVWQvBKCknQCIEQnTCwueaU=; b=QYi9198gziRmnmdUnf6x6xJdF+DH9mnCx9Hk6NgpVh1A8tsjfjsTDDN5xiCdaLjqAa +9ORBgAjnod0OMY5DEi93eDyIumKYQGgKYQDxMPlhhbYaSIhQaD+aa3dYqEmps0Hm+90 pMydPhKa2QBtTzVB+Rp/l6w2pPyO7N+qn1X9iijymKIlOd4eVbEhmnx+f6r7gAMnNR9M Ow8p0VgslYXeeO7jzaImFTYxL9GPl+8Vt+JfIh0gz7FRSR8ZkjlntWoAuM6tLDtiWZ5v rrki+dSdFC1sboqs93zsLCjH+xXF2S72arAa3rPH7z7/biy1iJBY1hGBs5ebHBUfQTbj irsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yOXhaAMs; 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 y13-20020a17090614cd00b0073123a3bea1si7895497ejc.532.2022.08.15.13.19.48; Mon, 15 Aug 2022 13:20:15 -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=yOXhaAMs; 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 S244646AbiHOT7W (ORCPT + 99 others); Mon, 15 Aug 2022 15:59:22 -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-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) 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 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) +#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 @@ -500,7 +502,7 @@ static struct trace_event_functions trac #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