From nobody Thu Dec 18 22:00:55 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46171C83F2C for ; Sat, 2 Sep 2023 11:51:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352101AbjIBLvS (ORCPT ); Sat, 2 Sep 2023 07:51:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352071AbjIBLvN (ORCPT ); Sat, 2 Sep 2023 07:51:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C692E6A for ; Sat, 2 Sep 2023 04:51:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E533BB826CD for ; Sat, 2 Sep 2023 11:51:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73E93C433C9; Sat, 2 Sep 2023 11:51:06 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qcP9q-000Jva-1I; Sat, 02 Sep 2023 07:51:18 -0400 Message-ID: <20230902115118.216006582@goodmis.org> User-Agent: quilt/0.66 Date: Sat, 02 Sep 2023 07:50:36 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , kernel test robot , Yu Liao , Daniel Bristot de Oliveira Subject: [for-linus][PATCH 01/11] rv: Set variable da_mon_##name to static References: <20230902115035.786076237@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yu Liao gcc with W=3D1 reports kernel/trace/rv/monitors/wip/wip.c:20:1: sparse: sparse: symbol 'da_mon_wip= ' was not declared. Should it be static? The per-cpu variable 'da_mon_##name' is only used in its defining file, so it should be static. Link: https://lore.kernel.org/linux-trace-kernel/20230823020051.3184953-1-l= iaoyu15@huawei.com Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202307280030.7EjUG9gR-lkp@int= el.com/ Signed-off-by: Yu Liao Acked-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- include/rv/da_monitor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h index 9eb75683e012..9705b2a98e49 100644 --- a/include/rv/da_monitor.h +++ b/include/rv/da_monitor.h @@ -262,7 +262,7 @@ static inline void da_monitor_destroy_##name(void) = \ /* \ * per-cpu monitor variables \ */ \ -DEFINE_PER_CPU(struct da_monitor, da_mon_##name); \ +static DEFINE_PER_CPU(struct da_monitor, da_mon_##name); \ \ /* \ * da_get_monitor_##name - return current CPU monitor address \ --=20 2.40.1 From nobody Thu Dec 18 22:00:55 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EBC3C71153 for ; Sat, 2 Sep 2023 11:51:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352086AbjIBLvQ (ORCPT ); Sat, 2 Sep 2023 07:51:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350327AbjIBLvM (ORCPT ); Sat, 2 Sep 2023 07:51:12 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E92410D2 for ; Sat, 2 Sep 2023 04:51:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id F07C7B8277C for ; Sat, 2 Sep 2023 11:51:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98A1CC433CA; Sat, 2 Sep 2023 11:51:06 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qcP9q-000Jw8-1x; Sat, 02 Sep 2023 07:51:18 -0400 Message-ID: <20230902115118.423134788@goodmis.org> User-Agent: quilt/0.66 Date: Sat, 02 Sep 2023 07:50:37 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Mikhail Kobuk , Alexey Khoroshilov , Daniel Bristot de Oliveira Subject: [for-linus][PATCH 02/11] tracing: Remove extra space at the end of hwlat_detector/mode References: <20230902115035.786076237@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mikhail Kobuk Space is printed after each mode value including the last one: $ echo \"$(sudo cat /sys/kernel/tracing/hwlat_detector/mode)\" "none [round-robin] per-cpu " Found by Linux Verification Center (linuxtesting.org) with SVACE. Link: https://lore.kernel.org/linux-trace-kernel/20230825103432.7750-1-m.ko= buk@ispras.ru Cc: Masami Hiramatsu Fixes: 8fa826b7344d ("trace/hwlat: Implement the mode config option") Signed-off-by: Mikhail Kobuk Reviewed-by: Alexey Khoroshilov Acked-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_hwlat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c index 2f37a6e68aa9..b791524a6536 100644 --- a/kernel/trace/trace_hwlat.c +++ b/kernel/trace/trace_hwlat.c @@ -635,7 +635,7 @@ static int s_mode_show(struct seq_file *s, void *v) else seq_printf(s, "%s", thread_mode_str[mode]); =20 - if (mode !=3D MODE_MAX) + if (mode < MODE_MAX - 1) /* if mode is any but last */ seq_puts(s, " "); =20 return 0; --=20 2.40.1 From nobody Thu Dec 18 22:00:55 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 670D8C83F2C for ; Sat, 2 Sep 2023 11:51:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352078AbjIBLvO (ORCPT ); Sat, 2 Sep 2023 07:51:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233449AbjIBLvL (ORCPT ); Sat, 2 Sep 2023 07:51:11 -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 CE817E7E for ; Sat, 2 Sep 2023 04:51:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 63A3960B27 for ; Sat, 2 Sep 2023 11:51:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCB73C43395; Sat, 2 Sep 2023 11:51:06 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qcP9q-000Jwg-2d; Sat, 02 Sep 2023 07:51:18 -0400 Message-ID: <20230902115118.629845964@goodmis.org> User-Agent: quilt/0.66 Date: Sat, 02 Sep 2023 07:50:38 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Zheng Yejian Subject: [for-linus][PATCH 03/11] tracing: Fix race issue between cpu buffer write and swap References: <20230902115035.786076237@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Zheng Yejian Warning happened in rb_end_commit() at code: if (RB_WARN_ON(cpu_buffer, !local_read(&cpu_buffer->committing))) WARNING: CPU: 0 PID: 139 at kernel/trace/ring_buffer.c:3142 rb_commit+0x402/0x4a0 Call Trace: ring_buffer_unlock_commit+0x42/0x250 trace_buffer_unlock_commit_regs+0x3b/0x250 trace_event_buffer_commit+0xe5/0x440 trace_event_buffer_reserve+0x11c/0x150 trace_event_raw_event_sched_switch+0x23c/0x2c0 __traceiter_sched_switch+0x59/0x80 __schedule+0x72b/0x1580 schedule+0x92/0x120 worker_thread+0xa0/0x6f0 It is because the race between writing event into cpu buffer and swapping cpu buffer through file per_cpu/cpu0/snapshot: Write on CPU 0 Swap buffer by per_cpu/cpu0/snapshot on CPU 1 -------- -------- tracing_snapshot_write() [...] ring_buffer_lock_reserve() cpu_buffer =3D buffer->buffers[cpu]; // 1. Suppose find 'cpu_buffer_a'; [...] rb_reserve_next_event() [...] ring_buffer_swap_cpu() if (local_read(&cpu_buffer_a->committing)) goto out_dec; if (local_read(&cpu_buffer_b->committing)) goto out_dec; buffer_a->buffers[cpu] =3D cpu_buffer_b; buffer_b->buffers[cpu] =3D cpu_buffer_a; // 2. cpu_buffer has swapped here. rb_start_commit(cpu_buffer); if (unlikely(READ_ONCE(cpu_buffer->buffer) !=3D buffer)) { // 3. This check passed due to 'cpu_buffer->buffe= r' [...] // has not changed here. return NULL; } cpu_buffer_b->buffer =3D buffer_a; cpu_buffer_a->buffer =3D buffer_b; [...] // 4. Reserve event from 'cpu_buffer_a'. ring_buffer_unlock_commit() [...] cpu_buffer =3D buffer->buffers[cpu]; // 5. Now find 'cpu_buffer_b' !!! rb_commit(cpu_buffer) rb_end_commit() // 6. WARN for the wrong 'committing' state !!! Based on above analysis, we can easily reproduce by following testcase: ``` bash #!/bin/bash dmesg -n 7 sysctl -w kernel.panic_on_warn=3D1 TR=3D/sys/kernel/tracing echo 7 > ${TR}/buffer_size_kb echo "sched:sched_switch" > ${TR}/set_event while [ true ]; do echo 1 > ${TR}/per_cpu/cpu0/snapshot done & while [ true ]; do echo 1 > ${TR}/per_cpu/cpu0/snapshot done & while [ true ]; do echo 1 > ${TR}/per_cpu/cpu0/snapshot done & ``` To fix it, IIUC, we can use smp_call_function_single() to do the swap on the target cpu where the buffer is located, so that above race would be avoided. Link: https://lore.kernel.org/linux-trace-kernel/20230831132739.4070878-1-z= hengyejian1@huawei.com Cc: Fixes: f1affcaaa861 ("tracing: Add snapshot in the per_cpu trace directorie= s") Signed-off-by: Zheng Yejian Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 3e55375f47e0..23579fba1a57 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -7599,6 +7599,11 @@ static int tracing_snapshot_open(struct inode *inode= , struct file *file) return ret; } =20 +static void tracing_swap_cpu_buffer(void *tr) +{ + update_max_tr_single((struct trace_array *)tr, current, smp_processor_id(= )); +} + static ssize_t tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t = cnt, loff_t *ppos) @@ -7657,13 +7662,15 @@ tracing_snapshot_write(struct file *filp, const cha= r __user *ubuf, size_t cnt, ret =3D tracing_alloc_snapshot_instance(tr); if (ret < 0) break; - local_irq_disable(); /* Now, we're going to swap */ - if (iter->cpu_file =3D=3D RING_BUFFER_ALL_CPUS) + if (iter->cpu_file =3D=3D RING_BUFFER_ALL_CPUS) { + local_irq_disable(); update_max_tr(tr, current, smp_processor_id(), NULL); - else - update_max_tr_single(tr, current, iter->cpu_file); - local_irq_enable(); + local_irq_enable(); + } else { + smp_call_function_single(iter->cpu_file, tracing_swap_cpu_buffer, + (void *)tr, 1); + } break; default: if (tr->allocated_snapshot) { --=20 2.40.1 From nobody Thu Dec 18 22:00:55 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34A87C83F2D for ; Sat, 2 Sep 2023 11:51:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233449AbjIBLvV (ORCPT ); Sat, 2 Sep 2023 07:51:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352076AbjIBLvN (ORCPT ); Sat, 2 Sep 2023 07:51:13 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E152110F5 for ; Sat, 2 Sep 2023 04:51:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id DBCCFCE18E3 for ; Sat, 2 Sep 2023 11:51:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 095F1C43397; Sat, 2 Sep 2023 11:51:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qcP9r-000JxE-05; Sat, 02 Sep 2023 07:51:19 -0400 Message-ID: <20230902115118.838838036@goodmis.org> User-Agent: quilt/0.66 Date: Sat, 02 Sep 2023 07:50:39 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Kees Cook , Azeem Shaikh Subject: [for-linus][PATCH 04/11] tracing: Replace strlcpy with strscpy in trace/events/task.h References: <20230902115035.786076237@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Azeem Shaikh strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy(). No return values were used, so direct replacement is safe. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [2] https://github.com/KSPP/linux/issues/89 Link: https://lore.kernel.org/linux-trace-kernel/20230831194212.1529941-1-a= zeemshaikh38@gmail.com Cc: Masami Hiramatsu Reviewed-by: Kees Cook Signed-off-by: Azeem Shaikh Signed-off-by: Steven Rostedt (Google) --- include/trace/events/task.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/trace/events/task.h b/include/trace/events/task.h index 64d160930b0d..47b527464d1a 100644 --- a/include/trace/events/task.h +++ b/include/trace/events/task.h @@ -47,7 +47,7 @@ TRACE_EVENT(task_rename, TP_fast_assign( __entry->pid =3D task->pid; memcpy(entry->oldcomm, task->comm, TASK_COMM_LEN); - strlcpy(entry->newcomm, comm, TASK_COMM_LEN); + strscpy(entry->newcomm, comm, TASK_COMM_LEN); __entry->oom_score_adj =3D task->signal->oom_score_adj; ), =20 --=20 2.40.1 From nobody Thu Dec 18 22:00:55 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D441C71153 for ; Sat, 2 Sep 2023 11:51:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352116AbjIBLvY (ORCPT ); Sat, 2 Sep 2023 07:51:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352079AbjIBLvO (ORCPT ); Sat, 2 Sep 2023 07:51:14 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED26710F6 for ; Sat, 2 Sep 2023 04:51:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 25F8BCE25C7 for ; Sat, 2 Sep 2023 11:51:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F195C4339A; Sat, 2 Sep 2023 11:51:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qcP9r-000Jxm-0l; Sat, 02 Sep 2023 07:51:19 -0400 Message-ID: <20230902115119.048419430@goodmis.org> User-Agent: quilt/0.66 Date: Sat, 02 Sep 2023 07:50:40 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Levi Yun Subject: [for-linus][PATCH 05/11] ftrace: Use within_module to check rec->ip within specified module. References: <20230902115035.786076237@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Levi Yun within_module_core && within_module_init condition is same to within module but it's more readable. Use within_module instead of former condition to check rec->ip within specified module area or not. Link: https://lore.kernel.org/linux-trace-kernel/20230803205236.32201-1-ppb= uk5246@gmail.com Signed-off-by: Levi Yun Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 05c0024815bf..c46dd6d97afe 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -6779,8 +6779,7 @@ void ftrace_release_mod(struct module *mod) last_pg =3D &ftrace_pages_start; for (pg =3D ftrace_pages_start; pg; pg =3D *last_pg) { rec =3D &pg->records[0]; - if (within_module_core(rec->ip, mod) || - within_module_init(rec->ip, mod)) { + if (within_module(rec->ip, mod)) { /* * As core pages are first, the first * page should never be a module page. @@ -6852,8 +6851,7 @@ void ftrace_module_enable(struct module *mod) * not part of this module, then skip this pg, * which the "break" will do. */ - if (!within_module_core(rec->ip, mod) && - !within_module_init(rec->ip, mod)) + if (!within_module(rec->ip, mod)) break; =20 /* Weak functions should still be ignored */ --=20 2.40.1 From nobody Thu Dec 18 22:00:55 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FA21C83F2D for ; Sat, 2 Sep 2023 11:51:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352093AbjIBLvR (ORCPT ); Sat, 2 Sep 2023 07:51:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231146AbjIBLvN (ORCPT ); Sat, 2 Sep 2023 07:51:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAF58E7E for ; Sat, 2 Sep 2023 04:51:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B4DA0B826E7 for ; Sat, 2 Sep 2023 11:51:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A80AC433AD; Sat, 2 Sep 2023 11:51:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qcP9r-000JyL-1R; Sat, 02 Sep 2023 07:51:19 -0400 Message-ID: <20230902115119.259781292@goodmis.org> User-Agent: quilt/0.66 Date: Sat, 02 Sep 2023 07:50:41 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Ruan Jinjie Subject: [for-linus][PATCH 06/11] ftrace: Use LIST_HEAD to initialize clear_hash References: <20230902115035.786076237@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ruan Jinjie Use LIST_HEAD() to initialize clear_hash instead of open-coding it. Link: https://lore.kernel.org/linux-trace-kernel/20230809071551.913041-1-ru= anjinjie@huawei.com Cc: Masami Hiramatsu Cc: Mark Rutland Signed-off-by: Ruan Jinjie Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index c46dd6d97afe..8de8bec5f366 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -7140,9 +7140,7 @@ void ftrace_free_mem(struct module *mod, void *start_= ptr, void *end_ptr) struct dyn_ftrace key; struct ftrace_mod_map *mod_map =3D NULL; struct ftrace_init_func *func, *func_next; - struct list_head clear_hash; - - INIT_LIST_HEAD(&clear_hash); + LIST_HEAD(clear_hash); =20 key.ip =3D start; key.flags =3D end; /* overload flags, as it is unsigned long */ --=20 2.40.1 From nobody Thu Dec 18 22:00:55 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5C48C71153 for ; Sat, 2 Sep 2023 11:51:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348585AbjIBLvd (ORCPT ); Sat, 2 Sep 2023 07:51:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352091AbjIBLvR (ORCPT ); Sat, 2 Sep 2023 07:51:17 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46C29E7E; Sat, 2 Sep 2023 04:51:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 73AD9CE25CA; Sat, 2 Sep 2023 11:51:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2115C433B8; Sat, 2 Sep 2023 11:51:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qcP9r-000Jyx-27; Sat, 02 Sep 2023 07:51:19 -0400 Message-ID: <20230902115119.470238399@goodmis.org> User-Agent: quilt/0.66 Date: Sat, 02 Sep 2023 07:50:42 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , stable@vger.kernel.org, Zheng Yejian , Brian Foster Subject: [for-linus][PATCH 07/11] tracing: Zero the pipe cpumask on alloc to avoid spurious -EBUSY References: <20230902115035.786076237@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Brian Foster The pipe cpumask used to serialize opens between the main and percpu trace pipes is not zeroed or initialized. This can result in spurious -EBUSY returns if underlying memory is not fully zeroed. This has been observed by immediate failure to read the main trace_pipe file on an otherwise newly booted and idle system: # cat /sys/kernel/debug/tracing/trace_pipe cat: /sys/kernel/debug/tracing/trace_pipe: Device or resource busy Zero the allocation of pipe_cpumask to avoid the problem. Link: https://lore.kernel.org/linux-trace-kernel/20230831125500.986862-1-bf= oster@redhat.com Cc: stable@vger.kernel.org Fixes: c2489bb7e6be ("tracing: Introduce pipe_cpumask to avoid race on trac= e_pipes") Reviewed-by: Zheng Yejian Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Brian Foster Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 23579fba1a57..35783a7baf15 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -9474,7 +9474,7 @@ static struct trace_array *trace_array_create(const c= har *name) if (!alloc_cpumask_var(&tr->tracing_cpumask, GFP_KERNEL)) goto out_free_tr; =20 - if (!alloc_cpumask_var(&tr->pipe_cpumask, GFP_KERNEL)) + if (!zalloc_cpumask_var(&tr->pipe_cpumask, GFP_KERNEL)) goto out_free_tr; =20 tr->trace_flags =3D global_trace.trace_flags & ~ZEROED_TRACE_FLAGS; @@ -10419,7 +10419,7 @@ __init static int tracer_alloc_buffers(void) if (trace_create_savedcmd() < 0) goto out_free_temp_buffer; =20 - if (!alloc_cpumask_var(&global_trace.pipe_cpumask, GFP_KERNEL)) + if (!zalloc_cpumask_var(&global_trace.pipe_cpumask, GFP_KERNEL)) goto out_free_savedcmd; =20 /* TODO: make the number of buffers hot pluggable with CPUS */ --=20 2.40.1 From nobody Thu Dec 18 22:00:55 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40D4FC83F2C for ; Sat, 2 Sep 2023 11:51:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352105AbjIBLv3 (ORCPT ); Sat, 2 Sep 2023 07:51:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352080AbjIBLvO (ORCPT ); Sat, 2 Sep 2023 07:51:14 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D476E6A for ; Sat, 2 Sep 2023 04:51:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 8ABF9CE25C8 for ; Sat, 2 Sep 2023 11:51:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9893C433B9; Sat, 2 Sep 2023 11:51:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qcP9r-000JzW-2m; Sat, 02 Sep 2023 07:51:19 -0400 Message-ID: <20230902115119.676231106@goodmis.org> User-Agent: quilt/0.66 Date: Sat, 02 Sep 2023 07:50:43 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Josh Poimboeuf , Valentin Schneider Subject: [for-linus][PATCH 08/11] tracing/filters: Fix error-handling of cpulist parsing buffer References: <20230902115035.786076237@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Valentin Schneider parse_pred() allocates a string buffer to parse the user-provided cpulist, but doesn't check the allocation result nor does it free the buffer once it is no longer needed. Add an allocation check, and free the buffer as soon as it is no longer needed. Link: https://lkml.kernel.org/r/20230901151039.125186-2-vschneid@redhat.com Cc: Masami Hiramatsu Reported-by: Steven Rostedt Reported-by: Josh Poimboeuf Signed-off-by: Valentin Schneider Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_filter.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events= _filter.c index 3a529214a21b..c06e1d596f4b 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -1744,17 +1744,23 @@ static int parse_pred(const char *str, void *data, =20 /* Copy the cpulist between { and } */ tmp =3D kmalloc((i - maskstart) + 1, GFP_KERNEL); - strscpy(tmp, str + maskstart, (i - maskstart) + 1); + if (!tmp) + goto err_mem; =20 + strscpy(tmp, str + maskstart, (i - maskstart) + 1); pred->mask =3D kzalloc(cpumask_size(), GFP_KERNEL); - if (!pred->mask) + if (!pred->mask) { + kfree(tmp); goto err_mem; + } =20 /* Now parse it */ if (cpulist_parse(tmp, pred->mask)) { + kfree(tmp); parse_error(pe, FILT_ERR_INVALID_CPULIST, pos + i); goto err_free; } + kfree(tmp); =20 /* Move along */ i++; --=20 2.40.1 From nobody Thu Dec 18 22:00:55 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D7F0C71153 for ; Sat, 2 Sep 2023 11:51:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352108AbjIBLvT (ORCPT ); Sat, 2 Sep 2023 07:51:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352073AbjIBLvN (ORCPT ); Sat, 2 Sep 2023 07:51:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A194E10D2 for ; Sat, 2 Sep 2023 04:51:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4C00FB8277B for ; Sat, 2 Sep 2023 11:51:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15288C433BA; Sat, 2 Sep 2023 11:51:08 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qcP9s-000K05-0F; Sat, 02 Sep 2023 07:51:20 -0400 Message-ID: <20230902115119.889766881@goodmis.org> User-Agent: quilt/0.66 Date: Sat, 02 Sep 2023 07:50:44 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Valentin Schneider Subject: [for-linus][PATCH 09/11] tracing/filters: Fix double-free of struct filter_pred.mask References: <20230902115035.786076237@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Valentin Schneider When a cpulist filter is found to contain a single CPU, that CPU is saved as a scalar and the backing cpumask storage is freed. Also NULL the mask to avoid a double-free once we get down to free_predicate(). Link: https://lkml.kernel.org/r/20230901151039.125186-3-vschneid@redhat.com Cc: Masami Hiramatsu Reported-by: Steven Rostedt Signed-off-by: Valentin Schneider Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_filter.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events= _filter.c index c06e1d596f4b..eb331e8b00b6 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -1773,6 +1773,7 @@ static int parse_pred(const char *str, void *data, if (single) { pred->val =3D cpumask_first(pred->mask); kfree(pred->mask); + pred->mask =3D NULL; } =20 if (field->filter_type =3D=3D FILTER_CPUMASK) { --=20 2.40.1 From nobody Thu Dec 18 22:00:55 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3562FC83F2D for ; Sat, 2 Sep 2023 11:51:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352076AbjIBLvb (ORCPT ); Sat, 2 Sep 2023 07:51:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352092AbjIBLvR (ORCPT ); Sat, 2 Sep 2023 07:51:17 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B8C710F9 for ; Sat, 2 Sep 2023 04:51:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id D5F89CE25CC for ; Sat, 2 Sep 2023 11:51:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49BBCC433C8; Sat, 2 Sep 2023 11:51:08 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qcP9s-000K0e-0u; Sat, 02 Sep 2023 07:51:20 -0400 Message-ID: <20230902115120.096623405@goodmis.org> User-Agent: quilt/0.66 Date: Sat, 02 Sep 2023 07:50:45 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Valentin Schneider Subject: [for-linus][PATCH 10/11] tracing/filters: Change parse_pred() cpulist ternary into an if block References: <20230902115035.786076237@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Valentin Schneider Review comments noted that an if block would be clearer than a ternary, so swap it out. No change in behaviour intended Link: https://lkml.kernel.org/r/20230901151039.125186-4-vschneid@redhat.com Cc: Masami Hiramatsu Signed-off-by: Valentin Schneider Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_filter.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events= _filter.c index eb331e8b00b6..09b4733a2933 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -1782,13 +1782,17 @@ static int parse_pred(const char *str, void *data, FILTER_PRED_FN_CPUMASK; } else if (field->filter_type =3D=3D FILTER_CPU) { if (single) { - pred->op =3D pred->op =3D=3D OP_BAND ? OP_EQ : pred->op; + if (pred->op =3D=3D OP_BAND) + pred->op =3D OP_EQ; + pred->fn_num =3D FILTER_PRED_FN_CPU; } else { pred->fn_num =3D FILTER_PRED_FN_CPU_CPUMASK; } } else if (single) { - pred->op =3D pred->op =3D=3D OP_BAND ? OP_EQ : pred->op; + if (pred->op =3D=3D OP_BAND) + pred->op =3D OP_EQ; + pred->fn_num =3D select_comparison_fn(pred->op, field->size, false); if (pred->op =3D=3D OP_NE) pred->not =3D 1; --=20 2.40.1 From nobody Thu Dec 18 22:00:55 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73F5AC71153 for ; Sat, 2 Sep 2023 11:51:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243754AbjIBLv1 (ORCPT ); Sat, 2 Sep 2023 07:51:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352077AbjIBLvN (ORCPT ); Sat, 2 Sep 2023 07:51:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F35A710F8 for ; Sat, 2 Sep 2023 04:51:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A3513B82782 for ; Sat, 2 Sep 2023 11:51:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F2E0C433BB; Sat, 2 Sep 2023 11:51:08 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qcP9s-000K1D-1Y; Sat, 02 Sep 2023 07:51:20 -0400 Message-ID: <20230902115120.303318989@goodmis.org> User-Agent: quilt/0.66 Date: Sat, 02 Sep 2023 07:50:46 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Valentin Schneider Subject: [for-linus][PATCH 11/11] tracing/filters: Fix coding style issues References: <20230902115035.786076237@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Valentin Schneider Recent commits have introduced some coding style issues, fix those up. Link: https://lkml.kernel.org/r/20230901151039.125186-5-vschneid@redhat.com Cc: Masami Hiramatsu Signed-off-by: Valentin Schneider Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_filter.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events= _filter.c index 09b4733a2933..33264e510d16 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c @@ -1360,7 +1360,7 @@ int filter_assign_type(const char *type) return FILTER_DYN_STRING; if (strstr(type, "cpumask_t")) return FILTER_CPUMASK; - } + } =20 if (strstr(type, "__rel_loc") && strstr(type, "char")) return FILTER_RDYN_STRING; @@ -1731,7 +1731,9 @@ static int parse_pred(const char *str, void *data, maskstart =3D i; =20 /* Walk the cpulist until closing } */ - for (; str[i] && str[i] !=3D '}'; i++); + for (; str[i] && str[i] !=3D '}'; i++) + ; + if (str[i] !=3D '}') { parse_error(pe, FILT_ERR_MISSING_BRACE_CLOSE, pos + i); goto err_free; --=20 2.40.1