Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1569810imn; Sun, 31 Jul 2022 12:22:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uqw2mv7iBwo38pVvt1Kw8Kgf1vWS1VKuFvWG7lj6FOLEjE43nDM69HebsznOa/DO9Vojp/ X-Received: by 2002:a17:907:2ccc:b0:72b:6907:fce6 with SMTP id hg12-20020a1709072ccc00b0072b6907fce6mr10110704ejc.115.1659295346197; Sun, 31 Jul 2022 12:22:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659295346; cv=none; d=google.com; s=arc-20160816; b=F3nsCakABfbdf97Ep3G2nWAOnfKi9sK0hEzLsqp3MiTW5plELrs97Pg+oBPKPZI23o bvzFM/w09U7nka3Pt1ChbHzySdhnWOYgAYPSoI9uCgHGQHCwW7fNFpg/JhwjdX9Fayvq lwHV11jXLSrnzFMEGa4/6xqJrmUSbUwfrxHBkpK8HCS2sYdScwGoiXZm32nD560GxkHL ivTl0Oz+xoQbPP0UuUjzzr0CIbgQ14qCwK3P+qG9HCnXQF2yuV+esWyR0ROGVUJoof1R 2BhdY1VmVFUe5BJzx5ledCRnMHp9HgR6+ZSz1j0A778w87sbgHrDAgg7R2OWtrtN5RXb VhFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=CBN4Mc2laKrDxhQyCCZ9G5aRZZGVv/7ZV2YXN/HQQCo=; b=xlI2ILMAUU8QDiGaVzcHKnp9WnPgDp3EmG3ovtE4or3YBxE0YDdAqp1ryQkU73gmLV i7FmEiebvkf57g+isxkPIPIAhXnmHLd3Le3XlJTBsTkmbBcVHFceiz0uWrcJ6xrnixmf S26zSQ0W2Tiq7snnSo41gaQZnpj40KfJ/Ez0kgiens5n4hNLvLDIub76KN7LS9L0Gt07 xuHDPRyDS5Vtyzg4RzLPv0819mxak1cSsLrAAvmvAP5ro3YWNZQJFS1gCD+XLFgmwAx5 NTjppLObed2/FuzNe4GNlr7rUxfdbj4IPmD5h8lhjIfe0tV6wBFfeQzXzPlDcerZ0Zuk uKkw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di5-20020a170906730500b0073065f0ddbdsi2429446ejc.599.2022.07.31.12.22.00; Sun, 31 Jul 2022 12:22:26 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237649AbiGaTGX (ORCPT + 99 others); Sun, 31 Jul 2022 15:06:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237856AbiGaTEq (ORCPT ); Sun, 31 Jul 2022 15:04:46 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A09D10567; Sun, 31 Jul 2022 12:04:40 -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 sin.source.kernel.org (Postfix) with ESMTPS id 48AFFCE0FA6; Sun, 31 Jul 2022 19:04:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E5CCC4314C; Sun, 31 Jul 2022 19:04:36 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oIEEt-007GDP-2V; Sun, 31 Jul 2022 15:04:35 -0400 Message-ID: <20220731190435.611455708@goodmis.org> User-Agent: quilt/0.66 Date: Sun, 31 Jul 2022 15:03:50 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Ingo Molnar , Andrew Morton , Peter Zijlstra , Thomas Gleixner , Masami Hiramatsu , stable@vger.kernel.org Subject: [for-next][PATCH 21/21] tracing: Use a struct alignof to determine trace event field alignment References: <20220731190329.641602282@goodmis.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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)" 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) --- 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