From patchwork Mon Apr 3 21:21:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 78752 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2592523vqo; Mon, 3 Apr 2023 14:23:36 -0700 (PDT) X-Google-Smtp-Source: AKy350aWNhXoeXXp6xSrOQF7NlJQwSkWDp+4DFaGq2QjTN9J0KQuRWN0r79HMJs6iI7VJDkFr35i X-Received: by 2002:a05:6a20:4c9f:b0:d9:ecba:b9fc with SMTP id fq31-20020a056a204c9f00b000d9ecbab9fcmr41428pzb.54.1680557016431; Mon, 03 Apr 2023 14:23:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680557016; cv=none; d=google.com; s=arc-20160816; b=aydOTIfR84E5SZHs7HNIy9KVe2qAeWL3TeavsLtlnLXnQlUK6ukQHnCag/LNBRhtt0 06CLt91scARn/SzF0VEt7DZUoYHAF5stMQTBnmz1/RFAVSlME9xM4uvDdd/cYtaY1XLe mcFoYPgi4dIbQAL/ucMCOJeJxrHRWbDcSPidH+EJ9c2F/a++P8lHshvklV5tsyKaY+6w +X62xNDPzh11TTuyoXTmAcE9YpLY7xDzj2D289J3Oi9GmLbxA9wSoX2H1lonPRoT1Hy2 H2hMMs/tj7R4RLsQ+ThC0q5tkpwh+pXDepQyTL8KQeNVb0JMZXCwJjZEnQLVj05ip4XN uxtA== 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=LvfCKV4jfJPmD0UG8JDe2eS8aW/qtcW1JztK0ks/3ew=; b=h3Ok/al9i/gurBmyblQCPHOjvwtelJER/7Z7eFCuNrFBC+JYI5pJsqRW2+QmMn9blr OBwtRIbzi8DRkFaNYO+epwrwByDvtBnmFRkxk6KlZ57dY8hntucMHWv3VZsLlXTUSjjR a7u9J4z2iyc6yyA7n8e+UWO4DuEdoPzJ4B2HrMaKxPXUEw4wrj2Xp7dOWH0uNBg0yIwj 3BTmXsDmQfojPZOaaA8tlpZdKzMWYf3fwGLYMQXCINiC4cKJwRjCwEuC34CCNQK9NVEi uPR5OYhREY2kUU3vvXXM97vHJMCKp4SyxSUUysycuveSls0XGcf57kmK8b6uwCCM36iB 7vRA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a3-20020a624d03000000b0058bbe6710absi8975310pfb.261.2023.04.03.14.23.24; Mon, 03 Apr 2023 14:23:36 -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 S233314AbjDCVWs (ORCPT + 99 others); Mon, 3 Apr 2023 17:22:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232711AbjDCVWq (ORCPT ); Mon, 3 Apr 2023 17:22:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DB623AA0; Mon, 3 Apr 2023 14:22:44 -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 CB94B62C05; Mon, 3 Apr 2023 21:22:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36ACCC433EF; Mon, 3 Apr 2023 21:22:43 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1pjRdS-000FOp-0R; Mon, 03 Apr 2023 17:22:42 -0400 Message-ID: <20230403212241.951576680@goodmis.org> User-Agent: quilt/0.66 Date: Mon, 03 Apr 2023 17:21:26 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , stable@vger.kernel.org, Matthias Brugger , AngeloGioacchino Del Regno , "Tom Zanussi" , Tze-nan Wu Subject: [for-linus][PATCH 1/6] tracing/synthetic: Fix races on freeing last_cmd References: <20230403212125.244064799@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762191754102607987?= X-GMAIL-MSGID: =?utf-8?q?1762191754102607987?= From: Tze-nan Wu Currently, the "last_cmd" variable can be accessed by multiple processes asynchronously when multiple users manipulate synthetic_events node at the same time, it could lead to use-after-free or double-free. This patch add "lastcmd_mutex" to prevent "last_cmd" from being accessed asynchronously. ================================================================ It's easy to reproduce in the KASAN environment by running the two scripts below in different shells. script 1: while : do echo -n -e '\x88' > /sys/kernel/tracing/synthetic_events done script 2: while : do echo -n -e '\xb0' > /sys/kernel/tracing/synthetic_events done ================================================================ double-free scenario: process A process B ------------------- --------------- 1.kstrdup last_cmd 2.free last_cmd 3.free last_cmd(double-free) ================================================================ use-after-free scenario: process A process B ------------------- --------------- 1.kstrdup last_cmd 2.free last_cmd 3.tracing_log_err(use-after-free) ================================================================ Appendix 1. KASAN report double-free: BUG: KASAN: double-free in kfree+0xdc/0x1d4 Free of addr ***** by task sh/4879 Call trace: ... kfree+0xdc/0x1d4 create_or_delete_synth_event+0x60/0x1e8 trace_parse_run_command+0x2bc/0x4b8 synth_events_write+0x20/0x30 vfs_write+0x200/0x830 ... Allocated by task 4879: ... kstrdup+0x5c/0x98 create_or_delete_synth_event+0x6c/0x1e8 trace_parse_run_command+0x2bc/0x4b8 synth_events_write+0x20/0x30 vfs_write+0x200/0x830 ... Freed by task 5464: ... kfree+0xdc/0x1d4 create_or_delete_synth_event+0x60/0x1e8 trace_parse_run_command+0x2bc/0x4b8 synth_events_write+0x20/0x30 vfs_write+0x200/0x830 ... ================================================================ Appendix 2. KASAN report use-after-free: BUG: KASAN: use-after-free in strlen+0x5c/0x7c Read of size 1 at addr ***** by task sh/5483 sh: CPU: 7 PID: 5483 Comm: sh ... __asan_report_load1_noabort+0x34/0x44 strlen+0x5c/0x7c tracing_log_err+0x60/0x444 create_or_delete_synth_event+0xc4/0x204 trace_parse_run_command+0x2bc/0x4b8 synth_events_write+0x20/0x30 vfs_write+0x200/0x830 ... Allocated by task 5483: ... kstrdup+0x5c/0x98 create_or_delete_synth_event+0x80/0x204 trace_parse_run_command+0x2bc/0x4b8 synth_events_write+0x20/0x30 vfs_write+0x200/0x830 ... Freed by task 5480: ... kfree+0xdc/0x1d4 create_or_delete_synth_event+0x74/0x204 trace_parse_run_command+0x2bc/0x4b8 synth_events_write+0x20/0x30 vfs_write+0x200/0x830 ... Link: https://lore.kernel.org/linux-trace-kernel/20230321110444.1587-1-Tze-nan.Wu@mediatek.com Fixes: 27c888da9867 ("tracing: Remove size restriction on synthetic event cmd error logging") Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Matthias Brugger Cc: AngeloGioacchino Del Regno Cc: "Tom Zanussi" Signed-off-by: Tze-nan Wu Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_synth.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c index 46d0abb32d0f..f0ff730125bf 100644 --- a/kernel/trace/trace_events_synth.c +++ b/kernel/trace/trace_events_synth.c @@ -44,14 +44,21 @@ enum { ERRORS }; static const char *err_text[] = { ERRORS }; +DEFINE_MUTEX(lastcmd_mutex); static char *last_cmd; static int errpos(const char *str) { + int ret = 0; + + mutex_lock(&lastcmd_mutex); if (!str || !last_cmd) - return 0; + goto out; - return err_pos(last_cmd, str); + ret = err_pos(last_cmd, str); + out: + mutex_unlock(&lastcmd_mutex); + return ret; } static void last_cmd_set(const char *str) @@ -59,18 +66,22 @@ static void last_cmd_set(const char *str) if (!str) return; + mutex_lock(&lastcmd_mutex); kfree(last_cmd); - last_cmd = kstrdup(str, GFP_KERNEL); + mutex_unlock(&lastcmd_mutex); } static void synth_err(u8 err_type, u16 err_pos) { + mutex_lock(&lastcmd_mutex); if (!last_cmd) - return; + goto out; tracing_log_err(NULL, "synthetic_events", last_cmd, err_text, err_type, err_pos); + out: + mutex_unlock(&lastcmd_mutex); } static int create_synth_event(const char *raw_command); From patchwork Mon Apr 3 21:21:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 78755 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2594034vqo; Mon, 3 Apr 2023 14:27:05 -0700 (PDT) X-Google-Smtp-Source: AKy350ZtL0mIi/CO1VHPAeq7lXs8Ay+UIGZW6HZW3WxDOupxycEb3Mhh7P0pHy22z2F3bj0di+za X-Received: by 2002:a17:90b:38c5:b0:234:f77:d6d2 with SMTP id nn5-20020a17090b38c500b002340f77d6d2mr178299pjb.45.1680557224829; Mon, 03 Apr 2023 14:27:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680557224; cv=none; d=google.com; s=arc-20160816; b=LHMJulT0jnn5hO25R6xi3FPlkGrHNGYlUoUV6jpqQg5cvGZUN6EPLsXBVv77I534i2 IXxzRbiZrJCJFEJDBrx6g43kWZKa6qRNC/U7uNL/i4EP8Zp+aJT0bB2C+XUYz9O+Eqs9 44j9RGwCQLfFO727WYEutSYTgIOZrH/pdTtCxW6VnzVKL9x10qzW9wTUZVIVVXKyQLMK Ngcur2QgSatp8C9qvBIejGfvTx8qlIZcoHhOpXswdOuKpzEhkc2Y3MafaTiiKKcm57/0 zH5sMBvMEwCB9wlfMOh2s2kHvnKfWnFeSaJ0JSatDb0pONgCGQe5hs4POvOoLDgRr7Gu gILA== 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=H/F5P8lsSqbw3qBibkwFbkVz74qBZG+2xjXVAbhLMnQ=; b=mG7M7tbgcoSErNVPx24+6ZWCZy/vAgHivht/Euq7e5dEcTnWk7x5o74ImQTLIsU8xY wRqNl4ychCJsS0HU0v1vvjeIEVeae/82FlHSLFaq0CkRu98q/L1brMAPob39glMf8Rop 6GST8jgPWaA9PoXSYHjo0F8TOstMta7ZkaQcn8Hri3BnttQOz6Sv16YSoUGHAJrgYM8q rLvjM+/7vVGgGxYO1cmhoUms6iImYPupJgRZdyFp7x4jvT9It+Vaki+r9wLFiUlJP5Pn 0nB5znClWIvIOdRWRz6cB+DKBci2fT92ICpQ+DmHx9zLVYD/9IrZNWg1oXFG2iSPJDxF f4Rw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y15-20020a17090a644f00b00230a19ce84asi814936pjm.147.2023.04.03.14.26.51; Mon, 03 Apr 2023 14:27:04 -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 S233563AbjDCVXF (ORCPT + 99 others); Mon, 3 Apr 2023 17:23:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232923AbjDCVWq (ORCPT ); Mon, 3 Apr 2023 17:22:46 -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 7D9B63AAB; Mon, 3 Apr 2023 14:22:44 -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 F41D062C14; Mon, 3 Apr 2023 21:22:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64733C433A1; Mon, 3 Apr 2023 21:22:43 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1pjRdS-000FPO-16; Mon, 03 Apr 2023 17:22:42 -0400 Message-ID: <20230403212242.155778891@goodmis.org> User-Agent: quilt/0.66 Date: Mon, 03 Apr 2023 17:21:27 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , stable@vger.kernel.org, Zheng Yejian Subject: [for-linus][PATCH 2/6] ring-buffer: Fix race while reader and writer are on the same page References: <20230403212125.244064799@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762191972718855739?= X-GMAIL-MSGID: =?utf-8?q?1762191972718855739?= From: Zheng Yejian When user reads file 'trace_pipe', kernel keeps printing following logs that warn at "cpu_buffer->reader_page->read > rb_page_size(reader)" in rb_get_reader_page(). It just looks like there's an infinite loop in tracing_read_pipe(). This problem occurs several times on arm64 platform when testing v5.10 and below. Call trace: rb_get_reader_page+0x248/0x1300 rb_buffer_peek+0x34/0x160 ring_buffer_peek+0xbc/0x224 peek_next_entry+0x98/0xbc __find_next_entry+0xc4/0x1c0 trace_find_next_entry_inc+0x30/0x94 tracing_read_pipe+0x198/0x304 vfs_read+0xb4/0x1e0 ksys_read+0x74/0x100 __arm64_sys_read+0x24/0x30 el0_svc_common.constprop.0+0x7c/0x1bc do_el0_svc+0x2c/0x94 el0_svc+0x20/0x30 el0_sync_handler+0xb0/0xb4 el0_sync+0x160/0x180 Then I dump the vmcore and look into the problematic per_cpu ring_buffer, I found that tail_page/commit_page/reader_page are on the same page while reader_page->read is obviously abnormal: tail_page == commit_page == reader_page == { .write = 0x100d20, .read = 0x8f9f4805, // Far greater than 0xd20, obviously abnormal!!! .entries = 0x10004c, .real_end = 0x0, .page = { .time_stamp = 0x857257416af0, .commit = 0xd20, // This page hasn't been full filled. // .data[0...0xd20] seems normal. } } The root cause is most likely the race that reader and writer are on the same page while reader saw an event that not fully committed by writer. To fix this, add memory barriers to make sure the reader can see the content of what is committed. Since commit a0fcaaed0c46 ("ring-buffer: Fix race between reset page and reading page") has added the read barrier in rb_get_reader_page(), here we just need to add the write barrier. Link: https://lore.kernel.org/linux-trace-kernel/20230325021247.2923907-1-zhengyejian1@huawei.com Cc: stable@vger.kernel.org Fixes: 77ae365eca89 ("ring-buffer: make lockless") Suggested-by: Steven Rostedt (Google) Signed-off-by: Zheng Yejian Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ring_buffer.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index c6f47b6cfd5f..76a2d91eecad 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -3098,6 +3098,10 @@ rb_set_commit_to_write(struct ring_buffer_per_cpu *cpu_buffer) if (RB_WARN_ON(cpu_buffer, rb_is_reader_page(cpu_buffer->tail_page))) return; + /* + * No need for a memory barrier here, as the update + * of the tail_page did it for this page. + */ local_set(&cpu_buffer->commit_page->page->commit, rb_page_write(cpu_buffer->commit_page)); rb_inc_page(&cpu_buffer->commit_page); @@ -3107,6 +3111,8 @@ rb_set_commit_to_write(struct ring_buffer_per_cpu *cpu_buffer) while (rb_commit_index(cpu_buffer) != rb_page_write(cpu_buffer->commit_page)) { + /* Make sure the readers see the content of what is committed. */ + smp_wmb(); local_set(&cpu_buffer->commit_page->page->commit, rb_page_write(cpu_buffer->commit_page)); RB_WARN_ON(cpu_buffer, @@ -4684,7 +4690,12 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer) /* * Make sure we see any padding after the write update - * (see rb_reset_tail()) + * (see rb_reset_tail()). + * + * In addition, a writer may be writing on the reader page + * if the page has not been fully filled, so the read barrier + * is also needed to make sure we see the content of what is + * committed by the writer (see rb_set_commit_to_write()). */ smp_rmb(); From patchwork Mon Apr 3 21:21:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 78757 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2598183vqo; Mon, 3 Apr 2023 14:36:34 -0700 (PDT) X-Google-Smtp-Source: AKy350YRksTqSdjX+9UJb+CK2BvQ388/TluJYHLAMsi6dbauSxl/Aw+uOBjvtETF6RmLiRFaTed3 X-Received: by 2002:a05:6a20:a11b:b0:e4:152:e920 with SMTP id q27-20020a056a20a11b00b000e40152e920mr15289372pzk.11.1680557794127; Mon, 03 Apr 2023 14:36:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680557794; cv=none; d=google.com; s=arc-20160816; b=h5uILUdmtCWGL7rtBVDKlSj/K8hKxUncRQr/SgzZAu477bgvj6q37P/HvLAj+C70jz Fd/pddweGM+CB9lpZChG2efPkPSjLF94uwvkpH9yVRL7BWPz0iWbscJUIUrSdBKhMcbc 10+ub5EU44mqc2lVmTrOkyj7xf5l9jkVyVPFeHEjTsiBB0QcLF89cHADC5Tt+GOTaJ7C mAgOQAiRwYW3P/uXPd/JG2Yb1u8vn3Oqpi70ukRJGJt6Tx2qDoxYVt+dRMtljej3En1R UPNghRiaBmUKR+frVqipzqtV3lVB35SRaL0k+m9aaxXIm1rcLTHNsJ2PClicohSCvBQN 6iCA== 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=ZQPPMVTPy6pzvLBBZNvy6DzFhb2NkWHIHO7FHG7TmUY=; b=JTYbLJeXxSN0X4MIpoJU6iTvJ/T8nppzGHazbl1ANvHCTkGYthS8L0nl+8v3Mvk1Ps 4pfSG3ldR2Gojk+aHnZ58/aUH7C9F5zYhzw9PPok/QRgGwDKwV2bW/Z5w85nGKtf3EYn c5fUC07zOBv74hTN3/aXvII9/rjq6TuIgRXrKOqpNelnSxvqA510XBr+lAcXAoRuOjh5 19yvzAUOvtmBwTKGhMU/AQBPJXsrh01Ta+6HjaXivfVPxbb736CCA5LgODTEied0Nd5m n/rv1i7itvuxvje6EDt1uOXp4c+3oFhXuxbecFKfWo8urTDpawUvfzC/qlxAxeyPngDB UBbQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v185-20020a6389c2000000b00513234112b5si9111796pgd.897.2023.04.03.14.36.22; Mon, 03 Apr 2023 14:36:34 -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 S233494AbjDCVW6 (ORCPT + 99 others); Mon, 3 Apr 2023 17:22:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232743AbjDCVWq (ORCPT ); Mon, 3 Apr 2023 17:22:46 -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 7FC7A3AB3; Mon, 3 Apr 2023 14:22:44 -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 1B33862C15; Mon, 3 Apr 2023 21:22:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84768C433A7; Mon, 3 Apr 2023 21:22:43 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1pjRdS-000FPw-1m; Mon, 03 Apr 2023 17:22:42 -0400 Message-ID: <20230403212242.363523650@goodmis.org> User-Agent: quilt/0.66 Date: Mon, 03 Apr 2023 17:21:28 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , stable@vger.kernel.org, John Keeping Subject: [for-linus][PATCH 3/6] ftrace: Mark get_lock_parent_ip() __always_inline References: <20230403212125.244064799@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762192569299061873?= X-GMAIL-MSGID: =?utf-8?q?1762192569299061873?= From: John Keeping If the compiler decides not to inline this function then preemption tracing will always show an IP inside the preemption disabling path and never the function actually calling preempt_{enable,disable}. Link: https://lore.kernel.org/linux-trace-kernel/20230327173647.1690849-1-john@metanate.com Cc: Masami Hiramatsu Cc: Mark Rutland Cc: stable@vger.kernel.org Fixes: f904f58263e1d ("sched/debug: Fix preempt_disable_ip recording for preempt_disable()") Signed-off-by: John Keeping Signed-off-by: Steven Rostedt (Google) --- include/linux/ftrace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 366c730beaa3..402fc061de75 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -980,7 +980,7 @@ static inline void __ftrace_enabled_restore(int enabled) #define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5)) #define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6)) -static inline unsigned long get_lock_parent_ip(void) +static __always_inline unsigned long get_lock_parent_ip(void) { unsigned long addr = CALLER_ADDR0; From patchwork Mon Apr 3 21:21:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 78753 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2592581vqo; Mon, 3 Apr 2023 14:23:44 -0700 (PDT) X-Google-Smtp-Source: AKy350bM/uA0j7FbGmqIcZlYbRa4O42F9UPFjiLAG+YdGUop5HZ0/UtZnYBYLcxh1sGtV/hEie1t X-Received: by 2002:a17:902:f98c:b0:1a1:8860:70d7 with SMTP id ky12-20020a170902f98c00b001a1886070d7mr355027plb.48.1680557024184; Mon, 03 Apr 2023 14:23:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680557024; cv=none; d=google.com; s=arc-20160816; b=GRJylNHuah49AYd9LHm9wlECGQc8P2UYmRZQpM2m6bXt4GWkvj+wTJDFBY50hb3+pq QP5o7TCa7jdVyoNZhleClB6hluKPpbY0sauZkAc3wnLWHDKPtVoaFGZl8qdYo1nb0vkh 1m4eFp362u1i/mngTBoHqjSg0oKhNowHzfXSJX7/ANeyOwgg73Q3H5mAcSJtnsjMp3qG dRQERvtpKFMvOOAOiqf3Sj6NGLcHrbwbUMD4sV2t2DSaQ2BeYU4nRP8z8caLvGstOu9l T4jSAddGo+3grs0Iiy1Uqlk6iwtr5Z5Brk9EKQuND5Mpi9qqeJMwYlGGzfF9XSrBp89/ Lesw== 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=e0vmZgXJVyPX13V6jnZSqFom1FvVAE4TwbNsD94xgm4=; b=Iyb5l2UhNMlBXKVJKkfaNtL6xvD0V9WvxAg0AfaAmdP/unRcPYAhyJre3E8sqd26Ty 2NNlrG3E9EW4EGuy/w22lBulskNqApVyY2yC2dvM1MNk7RTZi9hIViFWr7/kjcD+NG0F Qx+zCWpb9Wn+Z65QU3XCGV9t1ifGQqOFdob3jPMCK6IJYguTE9tjze/rzykJaFFJsXD8 icyiAtsbf1A9LIm0xd3b7aTaTbKV9Vjx3G8/rCfNYexjK5wi8saGEUz/VjiyqZPa7NQ+ mU4fhqnLQ9Eag986TuzdVQ6mr1BXXhir4cKsMdKcfClXpw5DhG0GahpRpjBgOk0d5rnW yPPQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l16-20020a170903121000b0019f79ba4a01si9261319plh.443.2023.04.03.14.23.31; Mon, 03 Apr 2023 14:23:44 -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 S233471AbjDCVWy (ORCPT + 99 others); Mon, 3 Apr 2023 17:22:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232656AbjDCVWq (ORCPT ); Mon, 3 Apr 2023 17:22:46 -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 C4DCC3C00; Mon, 3 Apr 2023 14:22:44 -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 5CA5A62C18; Mon, 3 Apr 2023 21:22:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2C74C433A8; Mon, 3 Apr 2023 21:22:43 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1pjRdS-000FQU-2R; Mon, 03 Apr 2023 17:22:42 -0400 Message-ID: <20230403212242.571580896@goodmis.org> User-Agent: quilt/0.66 Date: Mon, 03 Apr 2023 17:21:29 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , stable@vger.kernel.org, Daniel Bristot de Oliveira Subject: [for-linus][PATCH 4/6] tracing/timerlat: Notify new max thread latency References: <20230403212125.244064799@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762191762115471877?= X-GMAIL-MSGID: =?utf-8?q?1762191762115471877?= From: Daniel Bristot de Oliveira timerlat is not reporting a new tracing_max_latency for the thread latency. The reason is that it is not calling notify_new_max_latency() function after the new thread latency is sampled. Call notify_new_max_latency() after computing the thread latency. Link: https://lkml.kernel.org/r/16e18d61d69073d0192ace07bf61e405cca96e9c.1680104184.git.bristot@kernel.org Cc: stable@vger.kernel.org Fixes: dae181349f1e ("tracing/osnoise: Support a list of trace_array *tr") Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_osnoise.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index 9176bb7a9bb4..e8116094bed8 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -1738,6 +1738,8 @@ static int timerlat_main(void *data) trace_timerlat_sample(&s); + notify_new_max_latency(diff); + timerlat_dump_stack(time_to_us(diff)); tlat->tracing_thread = false; From patchwork Mon Apr 3 21:21:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 78756 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2597474vqo; Mon, 3 Apr 2023 14:34:52 -0700 (PDT) X-Google-Smtp-Source: AKy350Yt1qLNyTVooDVn/1/yulq9NcyUBjIJBxYFh3y3Ky77bmSCV7pDzFosiN3kjIj1gFxNKe1D X-Received: by 2002:a62:1c43:0:b0:625:cf03:e8cb with SMTP id c64-20020a621c43000000b00625cf03e8cbmr515730pfc.4.1680557691755; Mon, 03 Apr 2023 14:34:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680557691; cv=none; d=google.com; s=arc-20160816; b=uyDodYcxy5GLc2uzB+H5x1ZFZJyma+by81Jmwgsa1ngNIXQlDMR2QSGZg3E0w+I5Dd qbHhrWh1zAcDFvlBe1EbtGj54Z3PwO2/q1JfsYW4fr/XE27Trdv0vz8ELEI0yBLk+Le0 loTw3iNRcvm7P12zIfE+IovaKqbiQY2trnljmaqGUHE9XjMosqHf8eVfYalkzyY49OSG rENoQCt/1K9VbEnWyEqyJMzEHnxKfS2+6er3jfoCcbaugiRMFWYzhnKk4xu5g0dHtiRp xl+84MclE77eyOhR+rtq4/v2XlNT2Z7/a+2x/E3gEY7hKS9ovG5Uoi/eP+5ANcfkFw5U dvgw== 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=wP4Xvq/2SbhJwRzUvNDEP+Ib8AtgcdOclkvNUd5eicE=; b=omK/AahuNXYxa+q6iZ9bXUF8AgC9dx6c/Eb+Bg/swe6WgMkvRK+y4vj4vNdpiniSZj GEzLtY70ZYLPkpPtzhMSnZ98ep0IlhO7ZY2i3fmAG9SDYpR8WeGK8SkULJb1/bix5zBc mhLcdL+rYh5ZLhChmNycv4h040/Pfi+X2klF3rXtzUQ1H1U37QtmMtUC7xy77n0WYnda 6nDNoCAQZXUERXWtVahu/BTjeJhC4/POLPEydt/fuKidhAwHl6OHPufes8e4m1JrWvCl fjZw2w5Cw5L65fUJxyTdv+iogt0OH+X5wNtL1V1Yi4F2DW9Q/p/DWlSRm/dLheb7x6JN asKg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 126-20020a630584000000b0050bfc1d1b6dsi9053094pgf.132.2023.04.03.14.34.38; Mon, 03 Apr 2023 14:34:51 -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 S233538AbjDCVXB (ORCPT + 99 others); Mon, 3 Apr 2023 17:23:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233075AbjDCVWq (ORCPT ); Mon, 3 Apr 2023 17:22:46 -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 E34B63A97; Mon, 3 Apr 2023 14:22:45 -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 761E362C28; Mon, 3 Apr 2023 21:22:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB46CC433D2; Mon, 3 Apr 2023 21:22:43 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1pjRdS-000FR2-36; Mon, 03 Apr 2023 17:22:42 -0400 Message-ID: <20230403212242.777821662@goodmis.org> User-Agent: quilt/0.66 Date: Mon, 03 Apr 2023 17:21:30 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , stable@vger.kernel.org, Daniel Bristot de Oliveira Subject: [for-linus][PATCH 5/6] tracing/osnoise: Fix notify new tracing_max_latency References: <20230403212125.244064799@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762192462312095628?= X-GMAIL-MSGID: =?utf-8?q?1762192462312095628?= From: Daniel Bristot de Oliveira osnoise/timerlat tracers are reporting new max latency on instances where the tracing is off, creating inconsistencies between the max reported values in the trace and in the tracing_max_latency. Thus only report new tracing_max_latency on active tracing instances. Link: https://lkml.kernel.org/r/ecd109fde4a0c24ab0f00ba1e9a144ac19a91322.1680104184.git.bristot@kernel.org Cc: stable@vger.kernel.org Fixes: dae181349f1e ("tracing/osnoise: Support a list of trace_array *tr") Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_osnoise.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index e8116094bed8..4496975f2029 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -1296,7 +1296,7 @@ static void notify_new_max_latency(u64 latency) rcu_read_lock(); list_for_each_entry_rcu(inst, &osnoise_instances, list) { tr = inst->tr; - if (tr->max_latency < latency) { + if (tracer_tracing_is_on(tr) && tr->max_latency < latency) { tr->max_latency = latency; latency_fsnotify(tr); } From patchwork Mon Apr 3 21:21:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 78754 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2592750vqo; Mon, 3 Apr 2023 14:24:10 -0700 (PDT) X-Google-Smtp-Source: AKy350a7xSVbggwCQPUtNVcirkQ+DeytDCfnrEmySy9QDqpQVI3UFXd5lLnIOGKY9NEOPd8u3A9D X-Received: by 2002:a05:6a20:8c1e:b0:e5:5895:3550 with SMTP id j30-20020a056a208c1e00b000e558953550mr133321pzh.24.1680557049848; Mon, 03 Apr 2023 14:24:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680557049; cv=none; d=google.com; s=arc-20160816; b=Ww6FDc6T8iOZ1uKgdRZHVkPlEcyXyQWECmtFZVz16DxyL45saVao8v9KinQCkpxa7v HSa3GRhq3n7NeF7waEffU1G25tQgOA4kreHRqLUY31dJ/MSvw5VlcUohYCC+tJQ1tTDo UyjBno04SseB+D0FSzLs/EqpnZhs3vjkPTUAdehwMPio+NRXZ3vb06251kKKADj6G2ci 4wxDkfze7ct5Pii5NKPVtpqP8qjkybXRS8YYH3xmxrxCVtlklQ71Habl6z4/7cUPZkRW yUV5BP2Ov9A55YI2mY0jIFGQvKxzSaH2VNrYWiMxW6reacyNHMuW9xJEHnzCsaWMOSrY 8XYw== 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=Ot6/pc+pi714WVt4NwM7p9u5jTJMosEMNqlmchFwrw0=; b=vQIpXZz9eu8EeSuRs613Qd6B1/pvqK3d/yMoVpUhFBz3ZIUcuUpNdF6vMVbRhijv+H SVZbmZjbzFoCRD0UZnHKW+SYqNenOrQYOGXSJH7MB56ud+9/WXwJrk7KB7GcbKnzJUuJ p0b2itIjaA0iV+jlpSDfPozrDKZKhCL38ecGi/Oed3b2ZDlUxBxAMK5l62hfL7o1yKuC Z4fcfIrD1EIxBFgrdq+l2IOLL0TPUuDnLn8Iwq8JP9SW+dyviryLr7gBU+9yPMoBjK4r VMuTw8gpKB66L4ohoPj3VyMNmo3J/iR6Mzd2GXffqid1dbpr4DFtgQiABb6aVFGv7Lg8 K7qw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m3-20020a6545c3000000b00513f070aaabsi2692249pgr.613.2023.04.03.14.23.57; Mon, 03 Apr 2023 14:24:09 -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 S233696AbjDCVXI (ORCPT + 99 others); Mon, 3 Apr 2023 17:23:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233207AbjDCVWr (ORCPT ); Mon, 3 Apr 2023 17:22:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E46013C07 for ; Mon, 3 Apr 2023 14:22:45 -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 9B39762C43 for ; Mon, 3 Apr 2023 21:22:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11F78C433EF; Mon, 3 Apr 2023 21:22:44 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1pjRdT-000FRa-0Z; Mon, 03 Apr 2023 17:22:43 -0400 Message-ID: <20230403212242.984727709@goodmis.org> User-Agent: quilt/0.66 Date: Mon, 03 Apr 2023 17:21:31 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Douglas RAILLARD Subject: [for-linus][PATCH 6/6] tracing: Error if a trace event has an array for a __field() References: <20230403212125.244064799@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762191788590712444?= X-GMAIL-MSGID: =?utf-8?q?1762191788590712444?= From: "Steven Rostedt (Google)" A __field() in the TRACE_EVENT() macro is used to set up the fields of the trace event data. It is for single storage units (word, char, int, pointer, etc) and not for complex structures or arrays. Unfortunately, there's nothing preventing the build from accepting: __field(int, arr[5]); from building. It will turn into a array value. This use to work fine, as the offset and size use to be determined by the macro using the field name, but things have changed and the offset and size are now determined by the type. So the above would only be size 4, and the next field will be located 4 bytes from it (instead of 20). The proper way to declare static arrays is to use the __array() macro. Instead of __field(int, arr[5]) it should be __array(int, arr, 5). Add some macro tricks to the building of a trace event from the TRACE_EVENT() macro such that __field(int, arr[5]) will fail to build. A comment by the failure will explain why the build failed. Link: https://lore.kernel.org/lkml/20230306122549.236561-1-douglas.raillard@arm.com/ Link: https://lore.kernel.org/linux-trace-kernel/20230309221302.642e82d9@gandalf.local.home Reported-by: Douglas RAILLARD Signed-off-by: Steven Rostedt (Google) Acked-by: Masami Hiramatsu (Google) --- include/trace/stages/stage5_get_offsets.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/include/trace/stages/stage5_get_offsets.h b/include/trace/stages/stage5_get_offsets.h index ac5c24d3beeb..e30a13be46ba 100644 --- a/include/trace/stages/stage5_get_offsets.h +++ b/include/trace/stages/stage5_get_offsets.h @@ -9,17 +9,30 @@ #undef __entry #define __entry entry +/* + * Fields should never declare an array: i.e. __field(int, arr[5]) + * If they do, it will cause issues in parsing and possibly corrupt the + * events. To prevent that from happening, test the sizeof() a fictitious + * type called "struct _test_no_array_##item" which will fail if "item" + * contains array elements (like "arr[5]"). + * + * If you hit this, use __array(int, arr, 5) instead. + */ #undef __field -#define __field(type, item) +#define __field(type, item) \ + { (void)sizeof(struct _test_no_array_##item *); } #undef __field_ext -#define __field_ext(type, item, filter_type) +#define __field_ext(type, item, filter_type) \ + { (void)sizeof(struct _test_no_array_##item *); } #undef __field_struct -#define __field_struct(type, item) +#define __field_struct(type, item) \ + { (void)sizeof(struct _test_no_array_##item *); } #undef __field_struct_ext -#define __field_struct_ext(type, item, filter_type) +#define __field_struct_ext(type, item, filter_type) \ + { (void)sizeof(struct _test_no_array_##item *); } #undef __array #define __array(type, item, len)