From nobody Sat Feb 7 16:39:23 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 7CB5C1E25E1; Fri, 13 Dec 2024 15:26:38 +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=1734103598; cv=none; b=N4lnOCGpz/Jyx0WB64ml+HuwEGo8RAPvx0cJrELxl7j/EPfWBN4ssszn6Wjm9asIXzAO3pw24n1ntkpikfDxhn4u0NZrAWBKRi1lBKdPcTb1hDOVZJpO0jedBBnu/SfWbk1XiYleDQi+cdh9oEJ+yGso1XELN6gjC8I8joFTUmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734103598; c=relaxed/simple; bh=hbXcFDcsPeKieMQYD3MUdlFFN9d9AAy2f0U+uADjD2E=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=KW0s/mLU0eZnCqffFqdD38LkZWDZFbgzcabr71g06I50Sh4XG9S5D8rdUkrxh7SHKvp47FOUC6ucEwKyLymdnApGhHBCiDQ9/uVK0mhSdBLbmwfUwad5e6ATx3cYw6gqK88sCbUs5OJygCej+gOtmvnHJfn6kk+CIyWqjTO2t1w= 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 615A3C4CEE1; Fri, 13 Dec 2024 15:26:38 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tM7ZI-00000005PGg-146l; Fri, 13 Dec 2024 10:27:04 -0500 Message-ID: <20241213152704.105004386@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 13 Dec 2024 10:26:48 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org Subject: [for-linus][PATCH 1/3] tracing: Fix trace output when pointer hash is disabled References: <20241213152647.904822987@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 The "%p" in the trace output is by default hashes the pointer. An option was added to disable the hashing as reading trace output is a privileged operation (just like reading kallsyms). When hashing is disabled, the iter->fmt temp buffer is used to add "x" to "%p" into "%px" before sending to the svnprintf() functions. The problem with using iter->fmt, is that the trace_check_vprintf() that makes sure that trace events "%pX" pointers are not dereferencing freed addresses (and prints a warning if it does) also uses the iter->fmt to save to and use to print out for the trace file. When the hash_ptr option is disabled, the "%px" version is added to the iter->fmt buffer, and that then is passed to the trace_check_vprintf() function that then uses the iter->fmt as a temp buffer. Obviously this caused bad results. This was noticed when backporting the persistent ring buffer to 5.10 and added this code without the option being disabled by default, so it failed one of the selftests because the sched_wakeup was missing the "comm" field: cat-907 [006] dN.4. 249.722403: sched_wakeup: comm=3D pid=3D74 p= rio=3D120 target_cpu=3D006 Instead of showing: -0 [004] dNs6. 49.076464: sched_wakeup: comm=3Dsshd-sessio= n pid=3D896 prio=3D120 target_cpu=3D0040 To fix this, change trace_check_vprintf() to modify the iter->fmt instead of copying to it. If the fmt passed in is not the iter->fmt, first copy the entire fmt string to iter->fmt and then iterate the iter->fmt. When the format needs to be processed, perform the following like actions: save_ch =3D p[i]; p[i] =3D '\0'; trace_seq_printf(&iter->seq, p, str); p[i] =3D save_ch; Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20241212105426.113f2be3@batman.local.home Fixes: efbbdaa22bb78 ("tracing: Show real address for trace event arguments= ") Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 90 +++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index be62f0ea1814..b44b1cdaa20e 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -3711,8 +3711,10 @@ void trace_check_vprintf(struct trace_iterator *iter= , const char *fmt, { long text_delta =3D 0; long data_delta =3D 0; - const char *p =3D fmt; const char *str; + char save_ch; + char *buf =3D NULL; + char *p; bool good; int i, j; =20 @@ -3720,7 +3722,7 @@ void trace_check_vprintf(struct trace_iterator *iter,= const char *fmt, return; =20 if (static_branch_unlikely(&trace_no_verify)) - goto print; + goto print_fmt; =20 /* * When the kernel is booted with the tp_printk command line @@ -3735,8 +3737,21 @@ void trace_check_vprintf(struct trace_iterator *iter= , const char *fmt, =20 /* Don't bother checking when doing a ftrace_dump() */ if (iter->fmt =3D=3D static_fmt_buf) - goto print; + goto print_fmt; =20 + if (fmt !=3D iter->fmt) { + int len =3D strlen(fmt); + while (iter->fmt_size < len + 1) { + /* + * If we can't expand the copy buffer, + * just print it. + */ + if (!trace_iter_expand_format(iter)) + goto print_fmt; + } + strscpy(iter->fmt, fmt, iter->fmt_size); + } + p =3D iter->fmt; while (*p) { bool star =3D false; int len =3D 0; @@ -3748,14 +3763,6 @@ void trace_check_vprintf(struct trace_iterator *iter= , const char *fmt, * as well as %p[sS] if delta is non-zero */ for (i =3D 0; p[i]; i++) { - if (i + 1 >=3D iter->fmt_size) { - /* - * If we can't expand the copy buffer, - * just print it. - */ - if (!trace_iter_expand_format(iter)) - goto print; - } =20 if (p[i] =3D=3D '\\' && p[i+1]) { i++; @@ -3788,10 +3795,11 @@ void trace_check_vprintf(struct trace_iterator *ite= r, const char *fmt, if (!p[i]) break; =20 - /* Copy up to the %s, and print that */ - strncpy(iter->fmt, p, i); - iter->fmt[i] =3D '\0'; - trace_seq_vprintf(&iter->seq, iter->fmt, ap); + /* Print up to the %s */ + save_ch =3D p[i]; + p[i] =3D '\0'; + trace_seq_vprintf(&iter->seq, p, ap); + p[i] =3D save_ch; =20 /* Add delta to %pS pointers */ if (p[i+1] =3D=3D 'p') { @@ -3837,6 +3845,8 @@ void trace_check_vprintf(struct trace_iterator *iter,= const char *fmt, good =3D trace_safe_str(iter, str, star, len); } =20 + p +=3D i; + /* * If you hit this warning, it is likely that the * trace event in question used %s on a string that @@ -3849,41 +3859,51 @@ void trace_check_vprintf(struct trace_iterator *ite= r, const char *fmt, if (WARN_ONCE(!good, "fmt: '%s' current_buffer: '%s'", fmt, seq_buf_str(&iter->seq.seq))) { int ret; +#define TEMP_BUFSIZ 1024 + + if (!buf) { + char *buf =3D kmalloc(TEMP_BUFSIZ, GFP_KERNEL); + if (!buf) { + /* Need buffer to read address */ + trace_seq_printf(&iter->seq, "(0x%px)[UNSAFE-MEMORY]", str); + p +=3D j + 1; + goto print; + } + } + if (len >=3D TEMP_BUFSIZ) + len =3D TEMP_BUFSIZ - 1; =20 /* Try to safely read the string */ if (star) { - if (len + 1 > iter->fmt_size) - len =3D iter->fmt_size - 1; - if (len < 0) - len =3D 0; - ret =3D copy_from_kernel_nofault(iter->fmt, str, len); - iter->fmt[len] =3D 0; - star =3D false; + ret =3D copy_from_kernel_nofault(buf, str, len); + buf[len] =3D 0; } else { - ret =3D strncpy_from_kernel_nofault(iter->fmt, str, - iter->fmt_size); + ret =3D strncpy_from_kernel_nofault(buf, str, TEMP_BUFSIZ); } if (ret < 0) trace_seq_printf(&iter->seq, "(0x%px)", str); else - trace_seq_printf(&iter->seq, "(0x%px:%s)", - str, iter->fmt); - str =3D "[UNSAFE-MEMORY]"; - strcpy(iter->fmt, "%s"); + trace_seq_printf(&iter->seq, "(0x%px:%s)", str, buf); + trace_seq_puts(&iter->seq, "[UNSAFE-MEMORY]"); } else { - strncpy(iter->fmt, p + i, j + 1); - iter->fmt[j+1] =3D '\0'; + save_ch =3D p[j + 1]; + p[j + 1] =3D '\0'; + if (star) + trace_seq_printf(&iter->seq, p, len, str); + else + trace_seq_printf(&iter->seq, p, str); + p[j + 1] =3D save_ch; } - if (star) - trace_seq_printf(&iter->seq, iter->fmt, len, str); - else - trace_seq_printf(&iter->seq, iter->fmt, str); =20 - p +=3D i + j + 1; + p +=3D j + 1; } print: if (*p) trace_seq_vprintf(&iter->seq, p, ap); + kfree(buf); + return; + print_fmt: + trace_seq_vprintf(&iter->seq, fmt, ap); } =20 const char *trace_event_format(struct trace_iterator *iter, const char *fm= t) --=20 2.45.2 From nobody Sat Feb 7 16:39:23 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 EDC931E2850; Fri, 13 Dec 2024 15:26:38 +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=1734103599; cv=none; b=DzFOV98okFSC7UVxVhJ0Nbzf67EMb73WiwRhaUCXSt9C3udaApzPyjsRyLt1ArV/rwoWgUSfWrbUiDrOZ+o3NNu3t97+aTbW+RON4s/Nvf3PJPGCluROK9WooFteLNN4rzNtI6Q+9GYHjRsIi7lri4aI4RqWlLB+umkpmYXCWpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734103599; c=relaxed/simple; bh=qDsAmNXR5n51iXB16Y3+OxPTekINrODSuNbEbMHwiJg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=nSA91j5whXSWmiNJDJPO95sn0a5bcDgUCXSE7idJVujGVotIJj3for0OcXGt6j6CPSIe2LBfsNVevdOPuws5rA0PWepz9HhWNF2GQGG4LwZwm9UN7ZLXQH9gcBksNTfJ5rzvswWCgAeKcST2rxHHIdjTzZL96gme7zxP8VBVfPs= 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 92335C4CEE2; Fri, 13 Dec 2024 15:26:38 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tM7ZI-00000005PHC-1nIt; Fri, 13 Dec 2024 10:27:04 -0500 Message-ID: <20241213152704.275936323@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 13 Dec 2024 10:26:49 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Linus Walleij Subject: [for-linus][PATCH 2/3] fgraph: Still initialize idle shadow stacks when starting References: <20241213152647.904822987@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 A bug was discovered where the idle shadow stacks were not initialized for offline CPUs when starting function graph tracer, and when they came online they were not traced due to the missing shadow stack. To fix this, the idle task shadow stack initialization was moved to using the CPU hotplug callbacks. But it removed the initialization when the function graph was enabled. The problem here is that the hotplug callbacks are called when the CPUs come online, but the idle shadow stack initialization only happens if function graph is currently active. This caused the online CPUs to not get their shadow stack initialized. The idle shadow stack initialization still needs to be done when the function graph is registered, as they will not be allocated if function graph is not registered. Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20241211135335.094ba282@batman.local.home Fixes: 2c02f7375e65 ("fgraph: Use CPU hotplug mechanism to initialize idle = shadow stacks") Reported-by: Linus Walleij Tested-by: Linus Walleij Closes: https://lore.kernel.org/all/CACRpkdaTBrHwRbbrphVy-=3DSeDz6MSsXhTKyp= OtLrTQ+DgGAOcQ@mail.gmail.com/ Signed-off-by: Steven Rostedt (Google) --- kernel/trace/fgraph.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 0bf78517b5d4..ddedcb50917f 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -1215,7 +1215,7 @@ void fgraph_update_pid_func(void) static int start_graph_tracing(void) { unsigned long **ret_stack_list; - int ret; + int ret, cpu; =20 ret_stack_list =3D kcalloc(FTRACE_RETSTACK_ALLOC_SIZE, sizeof(*ret_stack_list), GFP_KERNEL); @@ -1223,6 +1223,12 @@ static int start_graph_tracing(void) if (!ret_stack_list) return -ENOMEM; =20 + /* The cpu_boot init_task->ret_stack will never be freed */ + for_each_online_cpu(cpu) { + if (!idle_task(cpu)->ret_stack) + ftrace_graph_init_idle_task(idle_task(cpu), cpu); + } + do { ret =3D alloc_retstack_tasklist(ret_stack_list); } while (ret =3D=3D -EAGAIN); --=20 2.45.2 From nobody Sat Feb 7 16:39:23 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 BEC221E25FE for ; Fri, 13 Dec 2024 15:26:38 +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=1734103598; cv=none; b=GA4qvpN2HVG8gN8HlEJFOv5MowLSQ2ZXmfkneqdseCMTEPeOTgH4L+6mfSmgSYxqol+S/6HzMm2diMEYi2xeMf6bSLcZCOjaLWEZNoTLrE8TYgrzqTSbLbiKN5i5uK3dBDTsamkhpbrP2M4SRVpK49bkl5lHy56REMW2oPnGh2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734103598; c=relaxed/simple; bh=lmCm9UtAO2/cJpwPsH47vXHv0VeqqSpC/ZMVZXWHtHk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=P+yJrnHit93e79tzZpZBKcE0DQm0kSONM87aBlAIK5GQOCo9GEyC7p+XQeqc4GMc2vlcDlGHttroHRi5wUNuIamWW4+qNEZYel0O0Vy/60xSPo2BoeSqDXxX0LSyoWlLHhIEuiVo59HFVpYyz0OcoO8VnBTJfJEnyy/fHlJ6YTY= 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 9D4A5C4CEE4; Fri, 13 Dec 2024 15:26:38 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tM7ZI-00000005PHg-2Vt6; Fri, 13 Dec 2024 10:27:04 -0500 Message-ID: <20241213152704.448212590@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 13 Dec 2024 10:26:50 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Al Viro , Michal Simek , Al Viro Subject: [for-linus][PATCH 3/3] ftrace/microblaze: Do not find "true_parent" for return address References: <20241213152647.904822987@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 When function tracing and function graph tracing are both enabled (in different instances) the "parent" of some of the function tracing events is "return_to_handler" which is the trampoline used by function graph tracing. To fix this, ftrace_get_true_parent_ip() was introduced that returns the "true" parent ip instead of the trampoline. To do this, the ftrace_regs_get_stack_pointer() is used, which uses kernel_stack_pointer(). The problem is that microblaze does not implement kerenl_stack_pointer() so when function graph tracing is enabled, the build fails. Modify the #ifdef check to the code around ftrace_get_true_parent_ip() to include !defined(CONFIG_MICROBLAZE) which will default it to just return the parent ip passed in, which may still be the ip of the function garph trampoline. Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Al Viro Cc: Michal Simek Link: https://lore.kernel.org/20241211153634.69c75afa@batman.local.home Fixes: 60b1f578b578 ("ftrace: Get the true parent ip for function tracer") Reported-by: Al Viro Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_functions.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c index 74c353164ca1..a75d107a45f8 100644 --- a/kernel/trace/trace_functions.c +++ b/kernel/trace/trace_functions.c @@ -176,7 +176,8 @@ static void function_trace_start(struct trace_array *tr) tracing_reset_online_cpus(&tr->array_buffer); } =20 -#ifdef CONFIG_FUNCTION_GRAPH_TRACER +/* Microblaze currently doesn't implement kernel_stack_pointer() */ +#if defined(CONFIG_FUNCTION_GRAPH_TRACER) && !defined(CONFIG_MICROBLAZE) static __always_inline unsigned long function_get_true_parent_ip(unsigned long parent_ip, struct ftrace_regs *f= regs) { --=20 2.45.2