From nobody Sun Feb 8 15:58:26 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9E4D6FE03 for ; Thu, 14 Mar 2024 14:21:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426083; cv=none; b=coHqG7l+xGXrG1jjbj2UKhfmeyO5d5ct+AC5zNLJhCfaiW1bGPDGb9IqZnr8+5Vi2aCulWR5J6twuELwwsnxoCbgXaBcEYEaRH8RB9CmCN7a6UlVmC+YzrcWoTKx7q6dniwnN6C3Lf4cDF/D+d3baqX9IA5UcKWpqMzecbfPe60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426083; c=relaxed/simple; bh=RTzlXiEm7qBjG5506f5UyvsLg1u9zWSESZpJ4FB8jzI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=InjNwnGb1yx/Sr8s4JOTHwdavr7VYkzpmxzZxAPpoKMdU3gqpt5X7BDOoAWECohNcp7Z74LC6BVH1dKjmfDUApIfEQeoxLs9gNOr6APyI1Md9f4b58+85TRLExynoow3AnLr8h1aQ2etab7obbctTH7GwSIs7fuqZHSzV/DXuu4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 766D4C433F1; Thu, 14 Mar 2024 14:21:23 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rklza-00000002dd0-3XXn; Thu, 14 Mar 2024 10:23:34 -0400 Message-ID: <20240314142334.701302805@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 14 Mar 2024 10:23:02 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Ross Zwisler , , , , , Huang Yiwei Subject: [for-next][PATCH 1/8] tracing: Support to dump instance traces by ftrace_dump_on_oops References: <20240314142301.170713485@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Huang Yiwei Currently ftrace only dumps the global trace buffer on an OOPs. For debugging a production usecase, instance trace will be helpful to check specific problems since global trace buffer may be used for other purposes. This patch extend the ftrace_dump_on_oops parameter to dump a specific or multiple trace instances: - ftrace_dump_on_oops=3D0: as before -- don't dump - ftrace_dump_on_oops[=3D1]: as before -- dump the global trace buffer on all CPUs - ftrace_dump_on_oops=3D2 or =3Dorig_cpu: as before -- dump the global trace buffer on CPU that triggered the oops - ftrace_dump_on_oops=3D: new behavior -- dump the tracing instance matching - ftrace_dump_on_oops[=3D2/orig_cpu],[=3D2/orig_cpu], [=3D2/orig_cpu]: new behavior -- dump the global trace buffer and multiple instance buffer on all CPUs, or only dump on CPU that triggered the oops if =3D2 or =3Dorig_cpu is given Also, the sysctl node can handle the input accordingly. Link: https://lore.kernel.org/linux-trace-kernel/20240223083126.1817731-1-q= uic_hyiwei@quicinc.com Cc: Ross Zwisler Cc: Cc: Cc: Cc: Cc: Cc: Cc: Signed-off-by: Huang Yiwei Signed-off-by: Steven Rostedt (Google) --- .../admin-guide/kernel-parameters.txt | 26 ++- Documentation/admin-guide/sysctl/kernel.rst | 30 +++- include/linux/ftrace.h | 4 +- include/linux/kernel.h | 1 + kernel/sysctl.c | 4 +- kernel/trace/trace.c | 156 +++++++++++++----- kernel/trace/trace_selftest.c | 2 +- 7 files changed, 168 insertions(+), 55 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 31b3a25680d0..3d6ea8e80c2f 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1561,12 +1561,28 @@ The above will cause the "foo" tracing instance to trigger a snapshot at the end of boot up. =20 - ftrace_dump_on_oops[=3Dorig_cpu] + ftrace_dump_on_oops[=3D2(orig_cpu) | =3D][, | + ,=3D2(orig_cpu)] [FTRACE] will dump the trace buffers on oops. - If no parameter is passed, ftrace will dump - buffers of all CPUs, but if you pass orig_cpu, it will - dump only the buffer of the CPU that triggered the - oops. + If no parameter is passed, ftrace will dump global + buffers of all CPUs, if you pass 2 or orig_cpu, it + will dump only the buffer of the CPU that triggered + the oops, or the specific instance will be dumped if + its name is passed. Multiple instance dump is also + supported, and instances are separated by commas. Each + instance supports only dump on CPU that triggered the + oops by passing 2 or orig_cpu to it. + + ftrace_dump_on_oops=3Dfoo=3Dorig_cpu + + The above will dump only the buffer of "foo" instance + on CPU that triggered the oops. + + ftrace_dump_on_oops,foo,bar=3Dorig_cpu + + The above will dump global buffer on all CPUs, the + buffer of "foo" instance on all CPUs and the buffer + of "bar" instance on CPU that triggered the oops. =20 ftrace_filter=3D[function-list] [FTRACE] Limit the functions traced by the function diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/ad= min-guide/sysctl/kernel.rst index 6584a1f9bfe3..ea8e5f152edc 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -296,12 +296,30 @@ kernel panic). This will output the contents of the f= trace buffers to the console. This is very useful for capturing traces that lead to crashes and outputting them to a serial console. =20 -=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D -0 Disabled (default). -1 Dump buffers of all CPUs. -2 Dump the buffer of the CPU that triggered the oops. -=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D - +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +0 Disabled (default). +1 Dump buffers of all CPUs. +2(orig_cpu) Dump the buffer of the CPU that triggered the + oops. + Dump the specific instance buffer on all CPUs. +=3D2(orig_cpu) Dump the specific instance buffer on the CPU + that triggered the oops. +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Multiple instance dump is also supported, and instances are separated +by commas. If global buffer also needs to be dumped, please specify +the dump mode (1/2/orig_cpu) first for global buffer. + +So for example to dump "foo" and "bar" instance buffer on all CPUs, +user can:: + + echo "foo,bar" > /proc/sys/kernel/ftrace_dump_on_oops + +To dump global buffer and "foo" instance buffer on all +CPUs along with the "bar" instance buffer on CPU that triggered the +oops, user can:: + + echo "1,foo,bar=3D2" > /proc/sys/kernel/ftrace_dump_on_oops =20 ftrace_enabled, stack_tracer_enabled =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index e8921871ef9a..54d53f345d14 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -1151,7 +1151,9 @@ static inline void unpause_graph_tracing(void) { } #ifdef CONFIG_TRACING enum ftrace_dump_mode; =20 -extern enum ftrace_dump_mode ftrace_dump_on_oops; +#define MAX_TRACER_SIZE 100 +extern char ftrace_dump_on_oops[]; +extern int ftrace_dump_on_oops_enabled(void); extern int tracepoint_printk; =20 extern void disable_trace_on_warning(void); diff --git a/include/linux/kernel.h b/include/linux/kernel.h index d9ad21058eed..b142a4f41d34 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -255,6 +255,7 @@ enum ftrace_dump_mode { DUMP_NONE, DUMP_ALL, DUMP_ORIG, + DUMP_PARAM, }; =20 #ifdef CONFIG_TRACING diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 157f7ce2942d..81cc974913bb 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1710,9 +1710,9 @@ static struct ctl_table kern_table[] =3D { { .procname =3D "ftrace_dump_on_oops", .data =3D &ftrace_dump_on_oops, - .maxlen =3D sizeof(int), + .maxlen =3D MAX_TRACER_SIZE, .mode =3D 0644, - .proc_handler =3D proc_dointvec, + .proc_handler =3D proc_dostring, }, { .procname =3D "traceoff_on_warning", diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 1bcfbc21fb3e..ff0b0a999171 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -130,9 +130,12 @@ cpumask_var_t __read_mostly tracing_buffer_mask; * /proc/sys/kernel/ftrace_dump_on_oops * Set 1 if you want to dump buffers of all CPUs * Set 2 if you want to dump the buffer of the CPU that triggered oops + * Set instance name if you want to dump the specific trace instance + * Multiple instance dump is also supported, and instances are seperated + * by commas. */ - -enum ftrace_dump_mode ftrace_dump_on_oops; +/* Set to string format zero to disable by default */ +char ftrace_dump_on_oops[MAX_TRACER_SIZE] =3D "0"; =20 /* When set, tracing will stop when a WARN*() is hit */ int __disable_trace_on_warning; @@ -178,7 +181,6 @@ static void ftrace_trace_userstack(struct trace_array *= tr, struct trace_buffer *buffer, unsigned int trace_ctx); =20 -#define MAX_TRACER_SIZE 100 static char bootup_tracer_buf[MAX_TRACER_SIZE] __initdata; static char *default_bootup_tracer; =20 @@ -201,19 +203,33 @@ static int __init set_cmdline_ftrace(char *str) } __setup("ftrace=3D", set_cmdline_ftrace); =20 +int ftrace_dump_on_oops_enabled(void) +{ + if (!strcmp("0", ftrace_dump_on_oops)) + return 0; + else + return 1; +} + static int __init set_ftrace_dump_on_oops(char *str) { - if (*str++ !=3D '=3D' || !*str || !strcmp("1", str)) { - ftrace_dump_on_oops =3D DUMP_ALL; + if (!*str) { + strscpy(ftrace_dump_on_oops, "1", MAX_TRACER_SIZE); return 1; } =20 - if (!strcmp("orig_cpu", str) || !strcmp("2", str)) { - ftrace_dump_on_oops =3D DUMP_ORIG; - return 1; - } + if (*str =3D=3D ',') { + strscpy(ftrace_dump_on_oops, "1", MAX_TRACER_SIZE); + strscpy(ftrace_dump_on_oops + 1, str, MAX_TRACER_SIZE - 1); + return 1; + } + + if (*str++ =3D=3D '=3D') { + strscpy(ftrace_dump_on_oops, str, MAX_TRACER_SIZE); + return 1; + } =20 - return 0; + return 0; } __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); =20 @@ -9932,14 +9948,14 @@ static struct notifier_block trace_die_notifier =3D= { static int trace_die_panic_handler(struct notifier_block *self, unsigned long ev, void *unused) { - if (!ftrace_dump_on_oops) + if (!ftrace_dump_on_oops_enabled()) return NOTIFY_DONE; =20 /* The die notifier requires DIE_OOPS to trigger */ if (self =3D=3D &trace_die_notifier && ev !=3D DIE_OOPS) return NOTIFY_DONE; =20 - ftrace_dump(ftrace_dump_on_oops); + ftrace_dump(DUMP_PARAM); =20 return NOTIFY_DONE; } @@ -9980,12 +9996,12 @@ trace_printk_seq(struct trace_seq *s) trace_seq_init(s); } =20 -void trace_init_global_iter(struct trace_iterator *iter) +static void trace_init_iter(struct trace_iterator *iter, struct trace_arra= y *tr) { - iter->tr =3D &global_trace; + iter->tr =3D tr; iter->trace =3D iter->tr->current_trace; iter->cpu_file =3D RING_BUFFER_ALL_CPUS; - iter->array_buffer =3D &global_trace.array_buffer; + iter->array_buffer =3D &tr->array_buffer; =20 if (iter->trace && iter->trace->open) iter->trace->open(iter); @@ -10005,22 +10021,19 @@ void trace_init_global_iter(struct trace_iterator= *iter) iter->fmt_size =3D STATIC_FMT_BUF_SIZE; } =20 -void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) +void trace_init_global_iter(struct trace_iterator *iter) +{ + trace_init_iter(iter, &global_trace); +} + +static void ftrace_dump_one(struct trace_array *tr, enum ftrace_dump_mode = dump_mode) { /* use static because iter can be a bit big for the stack */ static struct trace_iterator iter; - static atomic_t dump_running; - struct trace_array *tr =3D &global_trace; unsigned int old_userobj; unsigned long flags; int cnt =3D 0, cpu; =20 - /* Only allow one dump user at a time. */ - if (atomic_inc_return(&dump_running) !=3D 1) { - atomic_dec(&dump_running); - return; - } - /* * Always turn off tracing when we dump. * We don't need to show trace output of what happens @@ -10029,12 +10042,12 @@ void ftrace_dump(enum ftrace_dump_mode oops_dump_= mode) * If the user does a sysrq-z, then they can re-enable * tracing with echo 1 > tracing_on. */ - tracing_off(); + tracer_tracing_off(tr); =20 local_irq_save(flags); =20 /* Simulate the iterator */ - trace_init_global_iter(&iter); + trace_init_iter(&iter, tr); =20 for_each_tracing_cpu(cpu) { atomic_inc(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled); @@ -10045,21 +10058,15 @@ void ftrace_dump(enum ftrace_dump_mode oops_dump_= mode) /* don't look at user memory in panic mode */ tr->trace_flags &=3D ~TRACE_ITER_SYM_USEROBJ; =20 - switch (oops_dump_mode) { - case DUMP_ALL: - iter.cpu_file =3D RING_BUFFER_ALL_CPUS; - break; - case DUMP_ORIG: + if (dump_mode =3D=3D DUMP_ORIG) iter.cpu_file =3D raw_smp_processor_id(); - break; - case DUMP_NONE: - goto out_enable; - default: - printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n"); + else iter.cpu_file =3D RING_BUFFER_ALL_CPUS; - } =20 - printk(KERN_TRACE "Dumping ftrace buffer:\n"); + if (tr =3D=3D &global_trace) + printk(KERN_TRACE "Dumping ftrace buffer:\n"); + else + printk(KERN_TRACE "Dumping ftrace instance %s buffer:\n", tr->name); =20 /* Did function tracer already get disabled? */ if (ftrace_is_dead()) { @@ -10101,15 +10108,84 @@ void ftrace_dump(enum ftrace_dump_mode oops_dump_= mode) else printk(KERN_TRACE "---------------------------------\n"); =20 - out_enable: tr->trace_flags |=3D old_userobj; =20 for_each_tracing_cpu(cpu) { atomic_dec(&per_cpu_ptr(iter.array_buffer->data, cpu)->disabled); } - atomic_dec(&dump_running); local_irq_restore(flags); } + +static void ftrace_dump_by_param(void) +{ + bool first_param =3D true; + char dump_param[MAX_TRACER_SIZE]; + char *buf, *token, *inst_name; + struct trace_array *tr; + + strscpy(dump_param, ftrace_dump_on_oops, MAX_TRACER_SIZE); + buf =3D dump_param; + + while ((token =3D strsep(&buf, ",")) !=3D NULL) { + if (first_param) { + first_param =3D false; + if (!strcmp("0", token)) + continue; + else if (!strcmp("1", token)) { + ftrace_dump_one(&global_trace, DUMP_ALL); + continue; + } + else if (!strcmp("2", token) || + !strcmp("orig_cpu", token)) { + ftrace_dump_one(&global_trace, DUMP_ORIG); + continue; + } + } + + inst_name =3D strsep(&token, "=3D"); + tr =3D trace_array_find(inst_name); + if (!tr) { + printk(KERN_TRACE "Instance %s not found\n", inst_name); + continue; + } + + if (token && (!strcmp("2", token) || + !strcmp("orig_cpu", token))) + ftrace_dump_one(tr, DUMP_ORIG); + else + ftrace_dump_one(tr, DUMP_ALL); + } +} + +void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) +{ + static atomic_t dump_running; + + /* Only allow one dump user at a time. */ + if (atomic_inc_return(&dump_running) !=3D 1) { + atomic_dec(&dump_running); + return; + } + + switch (oops_dump_mode) { + case DUMP_ALL: + ftrace_dump_one(&global_trace, DUMP_ALL); + break; + case DUMP_ORIG: + ftrace_dump_one(&global_trace, DUMP_ORIG); + break; + case DUMP_PARAM: + ftrace_dump_by_param(); + break; + case DUMP_NONE: + break; + default: + printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n"); + ftrace_dump_one(&global_trace, DUMP_ALL); + } + + atomic_dec(&dump_running); +} EXPORT_SYMBOL_GPL(ftrace_dump); =20 #define WRITE_BUFSIZE 4096 diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c index 529590499b1f..e9c5058a8efd 100644 --- a/kernel/trace/trace_selftest.c +++ b/kernel/trace/trace_selftest.c @@ -768,7 +768,7 @@ static int trace_graph_entry_watchdog(struct ftrace_gra= ph_ent *trace) if (unlikely(++graph_hang_thresh > GRAPH_MAX_FUNC_TEST)) { ftrace_graph_stop(); printk(KERN_WARNING "BUG: Function graph tracer hang!\n"); - if (ftrace_dump_on_oops) { + if (ftrace_dump_on_oops_enabled()) { ftrace_dump(DUMP_ALL); /* ftrace_dump() disables tracing */ tracing_on(); --=20 2.43.0 From nobody Sun Feb 8 15:58:26 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 052FE6FE0F for ; Thu, 14 Mar 2024 14:21:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426084; cv=none; b=IViWT315Df1YquE01todT/S987sa4r1PDjgdyODAGkD779xt4EEZeBpjcSMSCYuUBm4jpdzK2xWYjOddFXNqYUB/PLn6W65UNzHg8H8kc6G4lFLKZZU2o0LY/MQGTzhl2h+yd45+BHA1vRHHW1QB3T5KxEgnHi/eqQ3kwPyyHyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426084; c=relaxed/simple; bh=QL6JFa2A3kh9PwqYA8gfLfmL2FQ7h1al6AGFkd/Ktr0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=PjhtHHDjFdItvX1XJH691F/NBg1RW/PeRWjcsvo2JE6dtupS22gOg28zSikv/pEv5Wi2H6MtWFqTLSFPv+YJ9VWorVN4PEFKm5LxAWB1mZze3PzHpycJy9RKMf7UkmpzF0Wt1OYZhcvPx1DvmsJ/p2Uam4yPZncbuTVtWxHuI94= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D321C43390; Thu, 14 Mar 2024 14:21:23 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rklzb-00000002ddU-00K4; Thu, 14 Mar 2024 10:23:35 -0400 Message-ID: <20240314142334.863961009@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 14 Mar 2024 10:23:03 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Chengming Zhou Subject: [for-next][PATCH 2/8] tracefs: Remove SLAB_MEM_SPREAD flag usage References: <20240314142301.170713485@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Chengming Zhou The SLAB_MEM_SPREAD flag is already a no-op as of 6.8-rc1, remove its usage so we can delete it from slab. No functional change. Link: https://lore.kernel.org/linux-trace-kernel/20240224135206.830300-1-ch= engming.zhou@linux.dev Signed-off-by: Chengming Zhou Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/inode.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index d65ffad4c327..5545e6bf7d26 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -731,7 +731,6 @@ static int __init tracefs_init(void) tracefs_inode_cachep =3D kmem_cache_create("tracefs_inode_cache", sizeof(struct tracefs_inode), 0, (SLAB_RECLAIM_ACCOUNT| - SLAB_MEM_SPREAD| SLAB_ACCOUNT), init_once); if (!tracefs_inode_cachep) --=20 2.43.0 From nobody Sun Feb 8 15:58:26 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFFF46FE0D for ; Thu, 14 Mar 2024 14:21:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426084; cv=none; b=Ip6k00wM/pNONuzfDJkmNMKfMpJmM59WelPQAlrPGlmGx2pYbzHEXKQ/4hC2eFZ1zjp+8JQ4YRWB38u+0Ib92/qWkb/w9Eqdy4WsxyCrF9CkQbZ7YopIU5reqkN2r8L/WLc0dUoK8F205uy64pwiB6QvPq2X5rEndWxhUGcaF1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426084; c=relaxed/simple; bh=6FabPEmpFyErLk7bCi4d6jupuxTDRYUNdQe7UwgjFms=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=K/eYb0c2AYXj4Ux9GJXdAnkl1A4ElUNPrCW+c8oLLBN9RV1gOg3m+QbEZnBXSLzI8TRuPUJmMNv/F+LrL1UGzJY+ND/1qmA7bcziA5hTiy65+UHyJx72byANGDKgVVkg7sGHLq/u9C7QLQcd1usqcecnJZ+kDyObe+n3NBdKf4w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB5CEC43399; Thu, 14 Mar 2024 14:21:23 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rklzb-00000002ddy-0ftb; Thu, 14 Mar 2024 10:23:35 -0400 Message-ID: <20240314142335.022580885@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 14 Mar 2024 10:23:04 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thorsten Blum Subject: [for-next][PATCH 3/8] tracing: Use div64_u64() instead of do_div() References: <20240314142301.170713485@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thorsten Blum Fixes Coccinelle/coccicheck warnings reported by do_div.cocci. Compared to do_div(), div64_u64() does not implicitly cast the divisor and does not unnecessarily calculate the remainder. Link: https://lore.kernel.org/linux-trace-kernel/20240225164507.232942-2-th= orsten.blum@toblux.com Cc: Mathieu Desnoyers Signed-off-by: Thorsten Blum Acked-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_benchmark.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/trace/trace_benchmark.c b/kernel/trace/trace_benchmark.c index 54d5fa35c90a..811b08439406 100644 --- a/kernel/trace/trace_benchmark.c +++ b/kernel/trace/trace_benchmark.c @@ -92,7 +92,6 @@ static void trace_do_benchmark(void) bm_total +=3D delta; bm_totalsq +=3D delta * delta; =20 - if (bm_cnt > 1) { /* * Apply Welford's method to calculate standard deviation: @@ -105,7 +104,7 @@ static void trace_do_benchmark(void) stddev =3D 0; =20 delta =3D bm_total; - do_div(delta, bm_cnt); + delta =3D div64_u64(delta, bm_cnt); avg =3D delta; =20 if (stddev > 0) { @@ -127,7 +126,7 @@ static void trace_do_benchmark(void) seed =3D stddev; if (!last_seed) break; - do_div(seed, last_seed); + seed =3D div64_u64(seed, last_seed); seed +=3D last_seed; do_div(seed, 2); } while (i++ < 10 && last_seed !=3D seed); --=20 2.43.0 From nobody Sun Feb 8 15:58:26 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23DE96FE1E for ; Thu, 14 Mar 2024 14:21:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426084; cv=none; b=gqbWosaCaB+Ipf6w2gapnKrqfJuWRDq8u6IFI8qozqGKwVbb+cW+F2FCKDVtxMuYWFeMLlmWvsL+mTguM3DGvgsDqQEkBjy5bfM1LhdMuqMgvOd+HpUF8NPtxAvcxTXbQHqIfc+MqvhiLUbQtbsYMTR+kbK3+bis3D9fRmqqxP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426084; c=relaxed/simple; bh=4ttIfC8PYF+Gki5Csa2Sakq4v+hP+Coh+x0QO+LZc1o=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=utGSJho51TBudrEZQwe0oAUCTLjJgzcCMtmSr+bsF72DY+82Be4/s5lgAU7kdpj+CH0C71SgTCcBkI7TQ6Uk0YT5WKbGkM0+pNXfoDfWQi8Eqi0kb0c/W3ud8oQdXqa2q2D+qdcTZ5QosnsI13Ng8pVJ1SIlrxyaGWXBuIae8DQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07634C43609; Thu, 14 Mar 2024 14:21:24 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rklzb-00000002deS-1LaB; Thu, 14 Mar 2024 10:23:35 -0400 Message-ID: <20240314142335.181319952@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 14 Mar 2024 10:23:05 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Borislav Petkov , "Paul E. McKenney" Subject: [for-next][PATCH 4/8] tracepoints: Use WARN() and not WARN_ON() for warnings References: <20240314142301.170713485@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" There are two WARN_ON*() warnings in tracepoint.h that deal with RCU usage. But when they trigger, especially from using a TRACE_EVENT() macro, the information is not very helpful and is confusing: ------------[ cut here ]------------ WARNING: CPU: 0 PID: 0 at include/trace/events/lock.h:24 lock_acquire+0x2b= 2/0x2d0 Where the above warning takes you to: TRACE_EVENT(lock_acquire, <<<--- line 24 in lock.h TP_PROTO(struct lockdep_map *lock, unsigned int subclass, int trylock, int read, int check, struct lockdep_map *next_lock, unsigned long ip), [..] Change the WARN_ON_ONCE() to WARN_ONCE() and add a string that allows someone to search for exactly where the bug happened. Link: https://lore.kernel.org/linux-trace-kernel/20240228133112.0d64fb1b@ga= ndalf.local.home Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Thomas Gleixner Reported-by: Borislav Petkov Tested-by: Borislav Petkov (AMD) Reviewed-by: Paul E. McKenney Signed-off-by: Steven Rostedt (Google) --- include/linux/tracepoint.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 88c0ba623ee6..689b6d71590e 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -199,7 +199,8 @@ static inline struct tracepoint *tracepoint_ptr_deref(t= racepoint_ptr_t *p) if (!(cond)) \ return; \ \ - if (WARN_ON_ONCE(RCUIDLE_COND(rcuidle))) \ + if (WARN_ONCE(RCUIDLE_COND(rcuidle), \ + "Bad RCU usage for tracepoint")) \ return; \ \ /* keep srcu and sched-rcu usage consistent */ \ @@ -259,7 +260,8 @@ static inline struct tracepoint *tracepoint_ptr_deref(t= racepoint_ptr_t *p) TP_ARGS(args), \ TP_CONDITION(cond), 0); \ if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) { \ - WARN_ON_ONCE(!rcu_is_watching()); \ + WARN_ONCE(!rcu_is_watching(), \ + "RCU not watching for tracepoint"); \ } \ } \ __DECLARE_TRACE_RCU(name, PARAMS(proto), PARAMS(args), \ --=20 2.43.0 From nobody Sun Feb 8 15:58:26 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8086C70CB0 for ; Thu, 14 Mar 2024 14:21:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426084; cv=none; b=N6o0bZRqkXsjSRRo8oElWpZ9fST5Z3h9tcdKVmKxFQg4K414r9bAIv244QoCba62H4fZEKp/byendrCOPlSlpHiP77Ad1JSGVDljfcu0Dk0Xi/OWvonhpf/kCiMB2fjBqXrdGoJIaBUZ0baXzQH+k7cAdu9+4HlRPgnCSRK4OA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426084; c=relaxed/simple; bh=gtQrW/f+7C+gaOAoZH/KhR7pyutOL5DABu1wR3iLb6A=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=CWs4LFV1B0KOwxeD8ZsPhFQFgSnMR/6sKiqfG6X+L5KdhmojKnN9d21wMY/BpuSWn+2DUQ8coK2wFe49TbLlyzBTjf1697oePHZYM8UFlPPacnZedp+BNLXRo9bfsNe0anSOVyPXK/KeDDAJw7auOqydgpanp8AGun6PaeQInts= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AAD6C433F1; Thu, 14 Mar 2024 14:21:24 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rklzb-00000002dew-20cT; Thu, 14 Mar 2024 10:23:35 -0400 Message-ID: <20240314142335.342287656@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 14 Mar 2024 10:23:06 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , linke li Subject: [for-next][PATCH 5/8] ring-buffer: use READ_ONCE() to read cpu_buffer->commit_page in concurrent environment References: <20240314142301.170713485@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: linke li In function ring_buffer_iter_empty(), cpu_buffer->commit_page is read while other threads may change it. It may cause the time_stamp that read in the next line come from a different page. Use READ_ONCE() to avoid having to reason about compiler optimizations now and in future. Link: https://lore.kernel.org/linux-trace-kernel/tencent_DFF7D3561A0686B5E8= FC079150A02505180A@qq.com Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Signed-off-by: linke li Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ring_buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 1d7d7a701867..13250856a3a8 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -4346,7 +4346,7 @@ int ring_buffer_iter_empty(struct ring_buffer_iter *i= ter) cpu_buffer =3D iter->cpu_buffer; reader =3D cpu_buffer->reader_page; head_page =3D cpu_buffer->head_page; - commit_page =3D cpu_buffer->commit_page; + commit_page =3D READ_ONCE(cpu_buffer->commit_page); commit_ts =3D commit_page->page->time_stamp; =20 /* --=20 2.43.0 From nobody Sun Feb 8 15:58:26 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97D6470CBA for ; Thu, 14 Mar 2024 14:21:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426084; cv=none; b=EhIORN1GKx7DannceoPdWyHXsHR75+NkRqFZYxAoub8TS00GJJEYuddt9s/bF2AHRm9eQP83HlzOC9qdN5nIeV9QBdgGhh9jkakWRwdIJdlBIZPZxcK+YUiXoWZAHwrTh9Khn3U4Ask9XwrQBlSkoSrYWqqZGqhJmwk0TfooOO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426084; c=relaxed/simple; bh=CVSsFYmyGUkTrIHbnXpwN8BPoUk0bIDiVFtTIOZJC3M=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=ggYUaP+j8vdYJDhMavV0zlGMtZNkx6ngLloMQ1FnQxfrQPccucfcYpb9A8/geNifJqigrkb+smXECHtRYlhKGwUu5bEn8VcTJxQANAq67WQF8RDlmziM4Hkmyo2w6oEe834jf3QSnk6CLmyImbkXjVJTQyNNVg5mD332DeOBNmc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35889C43390; Thu, 14 Mar 2024 14:21:24 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rklzb-00000002dfQ-2gJL; Thu, 14 Mar 2024 10:23:35 -0400 Message-ID: <20240314142335.498943015@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 14 Mar 2024 10:23:07 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Vincent Donnefort Subject: [for-next][PATCH 6/8] ring-buffer: Have mmapped ring buffer keep track of missed events References: <20240314142301.170713485@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" While testing libtracefs on the mmapped ring buffer, the test that checks if missed events are accounted for failed when using the mapped buffer. This is because the mapped page does not update the missed events that were dropped because the writer filled up the ring buffer before the reader could catch it. Add the missed events to the reader page/sub-buffer when the IOCTL is done and a new reader page is acquired. Note that all accesses to the reader_page via rb_page_commit() had to be switched to rb_page_size(), and rb_page_size() which was just a copy of rb_page_commit() but now it masks out the RB_MISSED bits. This is needed as the mapped reader page is still active in the ring buffer code and where it reads the commit field of the bpage for the size, it now must mask it otherwise the missed bits that are now set will corrupt the size returned. Link: https://lore.kernel.org/linux-trace-kernel/20240312175405.12fb6726@ga= ndalf.local.home Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Vincent Donnefort Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ring_buffer.c | 53 +++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 13250856a3a8..abe21c47fb49 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -313,6 +313,8 @@ static u64 rb_event_time_stamp(struct ring_buffer_event= *event) /* Missed count stored at end */ #define RB_MISSED_STORED (1 << 30) =20 +#define RB_MISSED_MASK (3 << 30) + struct buffer_data_page { u64 time_stamp; /* page time stamp */ local_t commit; /* write committed index */ @@ -2274,7 +2276,7 @@ rb_iter_head_event(struct ring_buffer_iter *iter) /* Size is determined by what has been committed */ static __always_inline unsigned rb_page_size(struct buffer_page *bpage) { - return rb_page_commit(bpage); + return rb_page_commit(bpage) & ~RB_MISSED_MASK; } =20 static __always_inline unsigned @@ -3901,7 +3903,7 @@ static bool rb_per_cpu_empty(struct ring_buffer_per_c= pu *cpu_buffer) return true; =20 /* Reader should exhaust content in reader page */ - if (reader->read !=3D rb_page_commit(reader)) + if (reader->read !=3D rb_page_size(reader)) return false; =20 /* @@ -4372,7 +4374,7 @@ int ring_buffer_iter_empty(struct ring_buffer_iter *i= ter) return ((iter->head_page =3D=3D commit_page && iter->head >=3D commit) || (iter->head_page =3D=3D reader && commit_page =3D=3D head_page && head_page->read =3D=3D commit && - iter->head =3D=3D rb_page_commit(cpu_buffer->reader_page))); + iter->head =3D=3D rb_page_size(cpu_buffer->reader_page))); } EXPORT_SYMBOL_GPL(ring_buffer_iter_empty); =20 @@ -5701,7 +5703,7 @@ int ring_buffer_read_page(struct trace_buffer *buffer, event =3D rb_reader_event(cpu_buffer); =20 read =3D reader->read; - commit =3D rb_page_commit(reader); + commit =3D rb_page_size(reader); =20 /* Check if any events were dropped */ missed_events =3D cpu_buffer->lost_events; @@ -5778,7 +5780,7 @@ int ring_buffer_read_page(struct trace_buffer *buffer, } else { /* update the entry counter */ cpu_buffer->read +=3D rb_page_entries(reader); - cpu_buffer->read_bytes +=3D rb_page_commit(reader); + cpu_buffer->read_bytes +=3D rb_page_size(reader); =20 /* swap the pages */ rb_init_page(bpage); @@ -6331,6 +6333,8 @@ struct page *ring_buffer_map_fault(struct trace_buffe= r *buffer, int cpu, int ring_buffer_map_get_reader(struct trace_buffer *buffer, int cpu) { struct ring_buffer_per_cpu *cpu_buffer; + struct buffer_page *reader; + unsigned long missed_events; unsigned long reader_size; unsigned long flags; =20 @@ -6356,9 +6360,46 @@ int ring_buffer_map_get_reader(struct trace_buffer *= buffer, int cpu) goto out; } =20 - if (WARN_ON(!rb_get_reader_page(cpu_buffer))) + reader =3D rb_get_reader_page(cpu_buffer); + if (WARN_ON(!reader)) goto out; =20 + /* Check if any events were dropped */ + missed_events =3D cpu_buffer->lost_events; + + if (cpu_buffer->reader_page !=3D cpu_buffer->commit_page) { + if (missed_events) { + struct buffer_data_page *bpage =3D reader->page; + unsigned int commit; + /* + * Use the real_end for the data size, + * This gives us a chance to store the lost events + * on the page. + */ + if (reader->real_end) + local_set(&bpage->commit, reader->real_end); + /* + * If there is room at the end of the page to save the + * missed events, then record it there. + */ + commit =3D rb_page_size(reader); + if (buffer->subbuf_size - commit >=3D sizeof(missed_events)) { + memcpy(&bpage->data[commit], &missed_events, + sizeof(missed_events)); + local_add(RB_MISSED_STORED, &bpage->commit); + } + local_add(RB_MISSED_EVENTS, &bpage->commit); + } + } else { + /* + * There really shouldn't be any missed events if the commit + * is on the reader page. + */ + WARN_ON_ONCE(missed_events); + } + + cpu_buffer->lost_events =3D 0; + goto consume; out: /* Some archs do not have data cache coherency between kernel and user-sp= ace */ --=20 2.43.0 From nobody Sun Feb 8 15:58:26 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA69470CC0; Thu, 14 Mar 2024 14:21:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426084; cv=none; b=LqwwFzXULYvKpcT6O3/XqZI/wB4ij3HEmyZbhNzx9DycLAaxk4dqaBmMeJQE223OnmK09FsI4SEtFim6iSTuBZIPjEjFL8YoIDv/FKUWYnCF7GcMyJcNL6zpKMxBEn0mnP7bvHQIRhbOI6mvqxjsYAOiXIOpvcN2IbeVN+O7W6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426084; c=relaxed/simple; bh=gh+s32d1vpsepJ1j28wwn4mGeO+mRxbbskY1P++hY1Y=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=E8v4NcoAwjh9IGbjV6gzdNNqkptAyHwmTM+Qwl0L/5w6BS7gdXfhFwOKDPxOmtwBp9ovFFt3frEHd1xqjadSBvUUL/54O0e8vdDCpBb/4urZ/BZ31FiFTwvwqx/QIUzqn16rm44ZTV/j87DGDeIflQSvgff0ylbrDppIJLWR+GA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DA10C4167E; Thu, 14 Mar 2024 14:21:24 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rklzb-00000002dfu-3MQH; Thu, 14 Mar 2024 10:23:35 -0400 Message-ID: <20240314142335.659018886@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 14 Mar 2024 10:23:08 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , netdev , Yisen Zhuang , Salil Mehta , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Yufeng Mo , Huazhong Tan , Jijie Shao Subject: [for-next][PATCH 7/8] net: hns3: tracing: fix hclgevf trace event strings References: <20240314142301.170713485@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: "Steven Rostedt (Google)" The __string() and __assign_str() helper macros of the TRACE_EVENT() macro are going through some optimizations where only the source string of __string() will be used and the __assign_str() source will be ignored and later removed. To make sure that there's no issues, a new check is added between the __string() src argument and the __assign_str() src argument that does a strcmp() to make sure they are the same string. The hclgevf trace events have: __assign_str(devname, &hdev->nic.kinfo.netdev->name); Which triggers the warning: hclgevf_trace.h:34:39: error: passing argument 1 of =E2=80=98strcmp=E2=80= =99 from incompatible pointer type [-Werror=3Dincompatible-pointer-types] 34 | __assign_str(devname, &hdev->nic.kinfo.netdev->name= ); [..] arch/x86/include/asm/string_64.h:75:24: note: expected =E2=80=98const char = *=E2=80=99 but argument is of type =E2=80=98char (*)[16]=E2=80=99 75 | int strcmp(const char *cs, const char *ct); | ~~~~~~~~~~~~^~ Because __assign_str() now has: WARN_ON_ONCE(__builtin_constant_p(src) ? \ strcmp((src), __data_offsets.dst##_ptr_) : \ (src) !=3D __data_offsets.dst##_ptr_); \ The problem is the '&' on hdev->nic.kinfo.netdev->name. That's because that name is: char name[IFNAMSIZ] Where passing an address '&' of a char array is not compatible with strcmp(= ). The '&' is not necessary, remove it. Link: https://lore.kernel.org/linux-trace-kernel/20240313093454.3909afe7@ga= ndalf.local.home Cc: netdev Cc: Yisen Zhuang Cc: Salil Mehta Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: Yufeng Mo Cc: Huazhong Tan Reviewed-by: Jijie Shao Fixes: d8355240cf8fb ("net: hns3: add trace event support for PF/VF mailbox= ") Signed-off-by: Steven Rostedt (Google) --- drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_trace.h | 8 ++++---- .../net/ethernet/hisilicon/hns3/hns3vf/hclgevf_trace.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_trace.h b/dri= vers/net/ethernet/hisilicon/hns3/hns3pf/hclge_trace.h index 8510b88d4982..f3cd5a376eca 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_trace.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_trace.h @@ -24,7 +24,7 @@ TRACE_EVENT(hclge_pf_mbx_get, __field(u8, code) __field(u8, subcode) __string(pciname, pci_name(hdev->pdev)) - __string(devname, &hdev->vport[0].nic.kinfo.netdev->name) + __string(devname, hdev->vport[0].nic.kinfo.netdev->name) __array(u32, mbx_data, PF_GET_MBX_LEN) ), =20 @@ -33,7 +33,7 @@ TRACE_EVENT(hclge_pf_mbx_get, __entry->code =3D req->msg.code; __entry->subcode =3D req->msg.subcode; __assign_str(pciname, pci_name(hdev->pdev)); - __assign_str(devname, &hdev->vport[0].nic.kinfo.netdev->name); + __assign_str(devname, hdev->vport[0].nic.kinfo.netdev->name); memcpy(__entry->mbx_data, req, sizeof(struct hclge_mbx_vf_to_pf_cmd)); ), @@ -56,7 +56,7 @@ TRACE_EVENT(hclge_pf_mbx_send, __field(u8, vfid) __field(u16, code) __string(pciname, pci_name(hdev->pdev)) - __string(devname, &hdev->vport[0].nic.kinfo.netdev->name) + __string(devname, hdev->vport[0].nic.kinfo.netdev->name) __array(u32, mbx_data, PF_SEND_MBX_LEN) ), =20 @@ -64,7 +64,7 @@ TRACE_EVENT(hclge_pf_mbx_send, __entry->vfid =3D req->dest_vfid; __entry->code =3D le16_to_cpu(req->msg.code); __assign_str(pciname, pci_name(hdev->pdev)); - __assign_str(devname, &hdev->vport[0].nic.kinfo.netdev->name); + __assign_str(devname, hdev->vport[0].nic.kinfo.netdev->name); memcpy(__entry->mbx_data, req, sizeof(struct hclge_mbx_pf_to_vf_cmd)); ), diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_trace.h b/d= rivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_trace.h index 5d4895bb57a1..b259e95dd53c 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_trace.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_trace.h @@ -23,7 +23,7 @@ TRACE_EVENT(hclge_vf_mbx_get, __field(u8, vfid) __field(u16, code) __string(pciname, pci_name(hdev->pdev)) - __string(devname, &hdev->nic.kinfo.netdev->name) + __string(devname, hdev->nic.kinfo.netdev->name) __array(u32, mbx_data, VF_GET_MBX_LEN) ), =20 @@ -31,7 +31,7 @@ TRACE_EVENT(hclge_vf_mbx_get, __entry->vfid =3D req->dest_vfid; __entry->code =3D le16_to_cpu(req->msg.code); __assign_str(pciname, pci_name(hdev->pdev)); - __assign_str(devname, &hdev->nic.kinfo.netdev->name); + __assign_str(devname, hdev->nic.kinfo.netdev->name); memcpy(__entry->mbx_data, req, sizeof(struct hclge_mbx_pf_to_vf_cmd)); ), @@ -55,7 +55,7 @@ TRACE_EVENT(hclge_vf_mbx_send, __field(u8, code) __field(u8, subcode) __string(pciname, pci_name(hdev->pdev)) - __string(devname, &hdev->nic.kinfo.netdev->name) + __string(devname, hdev->nic.kinfo.netdev->name) __array(u32, mbx_data, VF_SEND_MBX_LEN) ), =20 @@ -64,7 +64,7 @@ TRACE_EVENT(hclge_vf_mbx_send, __entry->code =3D req->msg.code; __entry->subcode =3D req->msg.subcode; __assign_str(pciname, pci_name(hdev->pdev)); - __assign_str(devname, &hdev->nic.kinfo.netdev->name); + __assign_str(devname, hdev->nic.kinfo.netdev->name); memcpy(__entry->mbx_data, req, sizeof(struct hclge_mbx_vf_to_pf_cmd)); ), --=20 2.43.0 From nobody Sun Feb 8 15:58:26 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16DE870CDE for ; Thu, 14 Mar 2024 14:21:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426085; cv=none; b=FGViZUwskk3P7QETA13hs+ksjLaAsWQ75Px44DscqQ0nFsqTf1+NKufbSdm/fnqNEH3hXM4m6IstsMODABpqhhR0CZNuygxFr0NnuAhbytBL8DKtGdz7MYw+aXVehK7vxD1fkiW0JugAdVHqEJaEjrj79XxmR8XvJfm1ISeZnuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710426085; c=relaxed/simple; bh=ITYjfWzRNvPA40h3ntsvuJ1TUwwxrgRbD4mfqfcOLvo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=dtKM4Ek0tP9N2gzeXQ83upfLJ3Q8ZrKr2mFq+12Q9zCoAX4RZ3sdHHviIikfGMIXkHlyDBcozWNn5WlcYpkDBH/TM3RrWB4Juzv6q2xYSdftjIj8Udf3aiL55KBQ+RZlry59MSGPU7jlo96Qjh9vt8AQ1lnhZOcGhOtn33lGp7A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85401C43394; Thu, 14 Mar 2024 14:21:24 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rklzb-00000002dgP-41ND; Thu, 14 Mar 2024 10:23:35 -0400 Message-ID: <20240314142335.820517632@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 14 Mar 2024 10:23:09 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Nathan Chancellor , kernel test robot Subject: [for-next][PATCH 8/8] tracing: Use strcmp() in __assign_str() WARN_ON() check References: <20240314142301.170713485@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" The WARN_ON() check in __assign_str() to catch where the source variable to the macro doesn't match the source variable to __string() gives an error in clang: >> include/trace/events/sunrpc.h:703:4: warning: result of comparison again= st a string literal is unspecified (use an explicit string comparison funct= ion instead) [-Wstring-compare] 670 | __assign_str(progname, "unknown"); That's because the __assign_str() macro has: WARN_ON_ONCE((src) !=3D __data_offsets.dst##_ptr_); Where "src" is a string literal. Clang warns when comparing a string literal directly as it is undefined to what the value of the literal is. Since this is still to make sure the same string that goes to __string() is the same as __assign_str(), for string literals do a test for that and then use strcmp() in those cases Note that this depends on commit 51270d573a8d ("tracing/net_sched: Fix tracepoints that save qdisc_dev() as a string") being applied, as this was what found that bug. Link: https://lore.kernel.org/linux-trace-kernel/20240312113002.00031668@ga= ndalf.local.home Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Nathan Chancellor Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202402292111.KIdExylU-lkp@int= el.com/ Fixes: 433e1d88a3be ("tracing: Add warning if string in __assign_str() does= not match __string()") Signed-off-by: Steven Rostedt (Google) --- include/trace/stages/stage6_event_callback.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/trace/stages/stage6_event_callback.h b/include/trace/s= tages/stage6_event_callback.h index a0c15f67eabe..83da83a0c14f 100644 --- a/include/trace/stages/stage6_event_callback.h +++ b/include/trace/stages/stage6_event_callback.h @@ -35,7 +35,9 @@ do { \ char *__str__ =3D __get_str(dst); \ int __len__ =3D __get_dynamic_array_len(dst) - 1; \ - WARN_ON_ONCE((src) !=3D __data_offsets.dst##_ptr_); \ + WARN_ON_ONCE(__builtin_constant_p(src) ? \ + strcmp((src), __data_offsets.dst##_ptr_) : \ + (src) !=3D __data_offsets.dst##_ptr_); \ memcpy(__str__, __data_offsets.dst##_ptr_ ? : \ EVENT_NULL_STR, __len__); \ __str__[__len__] =3D '\0'; \ --=20 2.43.0