From nobody Fri Dec 19 10:57:29 2025 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 F40FF21D58F for ; Sat, 12 Apr 2025 21:03:42 +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=1744491823; cv=none; b=sC0WUgSaMKfidxQOytG0qNpXTbEJJPvka3Uy2j8XX5ycrTCf8brdFBADELuwWucIBjNKkYjZ3cYAttG/8uqrsbMbGt9upNJMH4+YFzvSXkBtRNbff4C2YFYZxeQlPoisx2Rv32l4DSpqmh84UcFMJPJsDA9+Jf8YhswwmB1TgN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744491823; c=relaxed/simple; bh=Ck57P88/cufB2DmsK9iWuM8HKUfwVvvEim98nv6CAqk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=B+//k5AcNbYaWMA4CvNdFKGmbJmpc1KR5gkWnd38ZqJSsrYgLn8WMdpSEBYcneomCoHRWfTcmDq4FsOfrqKqCbMBQfrvcm/WGDI8+/rgWJEVPlQeyHJuLPE1fIjYbIXjcmOds/MuQSb+cxX06N1pE4PRA8VtGS97e7oUyig2240= 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 8A151C4CEE5; Sat, 12 Apr 2025 21:03:42 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1u3i2I-0000000AEDO-1r4L; Sat, 12 Apr 2025 17:05:10 -0400 Message-ID: <20250412210510.290174642@goodmis.org> User-Agent: quilt/0.68 Date: Sat, 12 Apr 2025 17:04:47 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Guenter Roeck Subject: [for-linus][PATCH 1/7] tracing: Hide get_vm_area() from MMUless builds References: <20250412210446.338481957@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 function get_vm_area() is not defined for non-MMU builds and causes a build error if it is used. Hide the map_pages() function around a: #ifdef CONFIG_MMU to keep it from being compiled when CONFIG_MMU is not set. Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20250407120111.2ccc9319@gandalf.local.home Reported-by: Guenter Roeck Tested-by: Guenter Roeck Closes: https://lore.kernel.org/all/4f8ece8b-8862-4f7c-8ede-febd28f8a9fe@ro= eck-us.net/ Fixes: 394f3f02de531 ("tracing: Use vmap_page_range() to map memmap ring bu= ffer") Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index b581e388a9d9..8ddf6b17215c 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -9806,6 +9806,7 @@ static int instance_mkdir(const char *name) return ret; } =20 +#ifdef CONFIG_MMU static u64 map_pages(unsigned long start, unsigned long size) { unsigned long vmap_start, vmap_end; @@ -9828,6 +9829,12 @@ static u64 map_pages(unsigned long start, unsigned l= ong size) =20 return (u64)vmap_start; } +#else +static inline u64 map_pages(unsigned long start, unsigned long size) +{ + return 0; +} +#endif =20 /** * trace_array_get_by_name - Create/Lookup a trace array, given its name. --=20 2.47.2 From nobody Fri Dec 19 10:57:29 2025 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 CC191170A23; Sat, 12 Apr 2025 21:03:42 +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=1744491822; cv=none; b=eA88iBO00hCMQ+kS9oT4AdWjkXIWVuP0kZsFPFPt5idpLZkxDED1LHNo6MwE3kDdWkrK7VcwPixmbVNC8uJysCsXzqC2TC2U3+pdX4f1ikZo4Z3cLswQCICQyMk23VTCbLiFvYu2H24vAofwMhU/2Mzz+f1V+LkTa0MOFXwffYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744491822; c=relaxed/simple; bh=/dxTjvf1nwp47obOQpKc/nAnFrDcdVF8sqdQbGww0ns=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=htWavPlSPQ9otk1b9eoBnNrkl5v8m/5hq2hBo29xCBNtrjZmsP3/a0EQQ1zopRyrb6aWsMFvaFwltPVubsiLNRlIvbMDmolbrzcnEA1dkin8RgZLvwyR1Ry8f8YRt2Nox8p/yTXwlXosXlmPEFO1b8LxGagZS8exIoIPj89ejU0= 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 ABF1AC4CEEC; Sat, 12 Apr 2025 21:03:42 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1u3i2I-0000000AEDs-2aS5; Sat, 12 Apr 2025 17:05:10 -0400 Message-ID: <20250412210510.464408595@goodmis.org> User-Agent: quilt/0.68 Date: Sat, 12 Apr 2025 17:04:48 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Tom Zanussi , Douglas Raillard Subject: [for-linus][PATCH 2/7] tracing: Do not add length to print format in synthetic events References: <20250412210446.338481957@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 following causes a vsnprintf fault: # echo 's:wake_lat char[] wakee; u64 delta;' >> /sys/kernel/tracing/dynam= ic_events # echo 'hist:keys=3Dpid:ts=3Dcommon_timestamp.usecs if !(common_flags & 0= x18)' > /sys/kernel/tracing/events/sched/sched_waking/trigger # echo 'hist:keys=3Dnext_pid:delta=3Dcommon_timestamp.usecs-$ts:onmatch(s= ched.sched_waking).trace(wake_lat,next_comm,$delta)' > /sys/kernel/tracing/= events/sched/sched_switch/trigger Because the synthetic event's "wakee" field is created as a dynamic string (even though the string copied is not). The print format to print the dynamic string changed from "%*s" to "%s" because another location (__set_synth_event_print_fmt()) exported this to user space, and user space did not need that. But it is still used in print_synth_event(), and the output looks like: -0 [001] d..5. 193.428167: wake_lat: wakee=3D(efaul= t)sshd-sessiondelta=3D155 sshd-session-879 [001] d..5. 193.811080: wake_lat: wakee=3D(efaul= t)kworker/u34:5delta=3D58 -0 [002] d..5. 193.811198: wake_lat: wakee=3D(efaul= t)bashdelta=3D91 bash-880 [002] d..5. 193.811371: wake_lat: wakee=3D(efaul= t)kworker/u35:2delta=3D21 -0 [001] d..5. 193.811516: wake_lat: wakee=3D(efaul= t)sshd-sessiondelta=3D129 sshd-session-879 [001] d..5. 193.967576: wake_lat: wakee=3D(efaul= t)kworker/u34:5delta=3D50 The length isn't needed as the string is always nul terminated. Just print the string and not add the length (which was hard coded to the max string length anyway). Cc: stable@vger.kernel.org Cc: Mathieu Desnoyers Cc: Tom Zanussi Cc: Douglas Raillard Acked-by: Masami Hiramatsu (Google) Link: https://lore.kernel.org/20250407154139.69955768@gandalf.local.home Fixes: 4d38328eb442d ("tracing: Fix synth event printk format for str field= s"); Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_synth.c | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_= synth.c index 969f48742d72..33cfbd4ed76d 100644 --- a/kernel/trace/trace_events_synth.c +++ b/kernel/trace/trace_events_synth.c @@ -370,7 +370,6 @@ static enum print_line_t print_synth_event(struct trace= _iterator *iter, union trace_synth_field *data =3D &entry->fields[n_u64]; =20 trace_seq_printf(s, print_fmt, se->fields[i]->name, - STR_VAR_LEN_MAX, (char *)entry + data->as_dynamic.offset, i =3D=3D se->n_fields - 1 ? "" : " "); n_u64++; --=20 2.47.2 From nobody Fri Dec 19 10:57:29 2025 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 2D797224AE9; Sat, 12 Apr 2025 21:03:42 +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=1744491823; cv=none; b=JHrFSOr/LktSWjFekx3xQFVocgxZhkE/oayknmIl1WxXA3whoA2h1l6vJG8kHPtXQknuz9Y92BUU6mg1Ffw727b+/MTF6ROEBWLvtMR/H29fJmNPVTZZHYL4/g21oLO8mr28yrwso/bcWrCj2/CidLZAPgYX7cyiU4oGOqqVyqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744491823; c=relaxed/simple; bh=/7sePx7POrKj9P/1s80fgQXpzWu41bRLoFG3jSTo7ZY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=gCn9mxX0sejaCFAZRVATkrZScOkrUK4IXKnLuMphpzSUUcV162oAmkfZdDE1ieNoB9F2w+V+io5rG+G6u+KE0VkB8GftNSUcZIz45fQNM9PzCAuzUXs+jkMAHBdkSevW/va//dHQCOuCFNrT+JdnU0cHfHeK+H6VnhJwUcXyjp0= 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 B6FABC4CEEA; Sat, 12 Apr 2025 21:03:42 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1u3i2I-0000000AEEM-3IYV; Sat, 12 Apr 2025 17:05:10 -0400 Message-ID: <20250412210510.639390059@goodmis.org> User-Agent: quilt/0.68 Date: Sat, 12 Apr 2025 17:04:49 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Andy Chiu Subject: [for-linus][PATCH 3/7] ftrace: Properly merge notrace hashes References: <20250412210446.338481957@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: Andy Chiu The global notrace hash should be jointly decided by the intersection of each subops's notrace hash, but not the filter hash. Cc: stable@vger.kernel.org Link: https://lore.kernel.org/20250408160258.48563-1-andybnac@gmail.com Fixes: 5fccc7552ccb ("ftrace: Add subops logic to allow one ops to manage m= any") Signed-off-by: Andy Chiu [ fixed removing of freeing of filter_hash ] Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 1a48aedb5255..8939eeebb02e 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -3526,16 +3526,16 @@ int ftrace_startup_subops(struct ftrace_ops *ops, s= truct ftrace_ops *subops, int ftrace_hash_empty(subops->func_hash->notrace_hash)) { notrace_hash =3D EMPTY_HASH; } else { - size_bits =3D max(ops->func_hash->filter_hash->size_bits, - subops->func_hash->filter_hash->size_bits); + size_bits =3D max(ops->func_hash->notrace_hash->size_bits, + subops->func_hash->notrace_hash->size_bits); notrace_hash =3D alloc_ftrace_hash(size_bits); if (!notrace_hash) { free_ftrace_hash(filter_hash); return -ENOMEM; } =20 - ret =3D intersect_hash(¬race_hash, ops->func_hash->filter_hash, - subops->func_hash->filter_hash); + ret =3D intersect_hash(¬race_hash, ops->func_hash->notrace_hash, + subops->func_hash->notrace_hash); if (ret < 0) { free_ftrace_hash(filter_hash); free_ftrace_hash(notrace_hash); --=20 2.47.2 From nobody Fri Dec 19 10:57:29 2025 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 852E4227B9A for ; Sat, 12 Apr 2025 21:03:43 +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=1744491823; cv=none; b=lzNby2YYRchJ6QPBDTeWFF5nBKhorc6fhwCNgMQuMX3gpPFwwx09gDNwTJbK9S5L8zVtjYhxwUCNuQcjD3/bEoUliLpW5GWyOv5K0gxCr/2AupDjCwU+JG9rLsNAecuyZe3AJCQ3AMkjHsWuSEyCbpvAByN/O6dYLtuxT1L6R+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744491823; c=relaxed/simple; bh=2WQfvLyPxdm61LBtW2Ou+PGxqgh8VBxCiNNVuYyvNwY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=qUej0stTy1AG9ry4i3y/zUBo2l6KH7e0m8cWqItJxfjn11RXv31v9un5DjKEXIIWu/gHZGehQCJKi/jOE5wftD7UCOjbohN/ZbJvBk9xUfn+z1m2roHU8Rx65Tx0SfnT9iijIl1PaJvIm58mn6eBgcYVxlV4tAZpBnQyp5Wkxdo= 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 E9975C4CEE7; Sat, 12 Apr 2025 21:03:42 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1u3i2I-0000000AEEr-41NP; Sat, 12 Apr 2025 17:05:10 -0400 Message-ID: <20250412210510.807353126@goodmis.org> User-Agent: quilt/0.68 Date: Sat, 12 Apr 2025 17:04:50 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Shuah Khan , Andy Chiu Subject: [for-linus][PATCH 4/7] ftrace: Fix accounting of subop hashes References: <20250412210446.338481957@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 function graph infrastructure uses ftrace to hook to functions. It has a single ftrace_ops to manage all the users of function graph. Each individual user (tracing, bpf, fprobes, etc) has its own ftrace_ops to track the functions it will have its callback called from. These ftrace_ops are "subops" to the main ftrace_ops of the function graph infrastructure. Each ftrace_ops has a filter_hash and a notrace_hash that is defined as: Only trace functions that are in the filter_hash but not in the notrace_hash. If the filter_hash is empty, it means to trace all functions. If the notrace_hash is empty, it means do not disable any function. The function graph main ftrace_ops needs to be a superset containing all the functions to be traced by all the subops it has. The algorithm to perform this merge was incorrect. When the first subops was added to the main ops, it simply made the main ops a copy of the subops (same filter_hash and notrace_hash). When a second ops was added, it joined the new subops filter_hash with the main ops filter_hash as a union of the two sets. The intersect between the new subops notrace_hash and the main ops notrace_hash was created as the new notrace_hash of the main ops. The issue here is that it would then start tracing functions than no subops were tracing. For example if you had two subops that had: subops 1: filter_hash =3D '*sched*' # trace all functions with "sched" in it notrace_hash =3D '*time*' # except do not trace functions with "time" subops 2: filter_hash =3D '*lock*' # trace all functions with "lock" in it notrace_hash =3D '*clock*' # except do not trace functions with "clock" The intersect of '*time*' functions with '*clock*' functions could be the empty set. That means the main ops will be tracing all functions with '*time*' and all "*clock*" in it! Instead, modify the algorithm to be a bit simpler and correct. First, when adding a new subops, even if it's the first one, do not add the notrace_hash if the filter_hash is not empty. Instead, just add the functions that are in the filter_hash of the subops but not in the notrace_hash of the subops into the main ops filter_hash. There's no reason to add anything to the main ops notrace_hash. The notrace_hash of the main ops should only be non empty iff all subops filter_hashes are empty (meaning to trace all functions) and all subops notrace_hashes include the same functions. That is, the main ops notrace_hash is empty if any subops filter_hash is non empty. The main ops notrace_hash only has content in it if all subops filter_hashes are empty, and the content are only functions that intersect all the subops notrace_hashes. If any subops notrace_hash is empty, then so is the main ops notrace_hash. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Shuah Khan Cc: Andy Chiu Link: https://lore.kernel.org/20250409152720.216356767@goodmis.org Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 314 ++++++++++++++++++++++++------------------ 1 file changed, 177 insertions(+), 137 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 8939eeebb02e..a8a02868b435 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -3255,6 +3255,31 @@ static int append_hash(struct ftrace_hash **hash, st= ruct ftrace_hash *new_hash, return 0; } =20 +/* + * Remove functions from @hash that are in @notrace_hash + */ +static void remove_hash(struct ftrace_hash *hash, struct ftrace_hash *notr= ace_hash) +{ + struct ftrace_func_entry *entry; + struct hlist_node *tmp; + int size; + int i; + + /* If the notrace hash is empty, there's nothing to do */ + if (ftrace_hash_empty(notrace_hash)) + return; + + size =3D 1 << hash->size_bits; + for (i =3D 0; i < size; i++) { + hlist_for_each_entry_safe(entry, tmp, &hash->buckets[i], hlist) { + if (!__ftrace_lookup_ip(notrace_hash, entry->ip)) + continue; + remove_hash_entry(hash, entry); + kfree(entry); + } + } +} + /* * Add to @hash only those that are in both @new_hash1 and @new_hash2 * @@ -3295,67 +3320,6 @@ static int intersect_hash(struct ftrace_hash **hash,= struct ftrace_hash *new_has return 0; } =20 -/* Return a new hash that has a union of all @ops->filter_hash entries */ -static struct ftrace_hash *append_hashes(struct ftrace_ops *ops) -{ - struct ftrace_hash *new_hash =3D NULL; - struct ftrace_ops *subops; - int size_bits; - int ret; - - if (ops->func_hash->filter_hash) - size_bits =3D ops->func_hash->filter_hash->size_bits; - else - size_bits =3D FTRACE_HASH_DEFAULT_BITS; - - list_for_each_entry(subops, &ops->subop_list, list) { - ret =3D append_hash(&new_hash, subops->func_hash->filter_hash, size_bits= ); - if (ret < 0) { - free_ftrace_hash(new_hash); - return NULL; - } - /* Nothing more to do if new_hash is empty */ - if (ftrace_hash_empty(new_hash)) - break; - } - /* Can't return NULL as that means this failed */ - return new_hash ? : EMPTY_HASH; -} - -/* Make @ops trace evenything except what all its subops do not trace */ -static struct ftrace_hash *intersect_hashes(struct ftrace_ops *ops) -{ - struct ftrace_hash *new_hash =3D NULL; - struct ftrace_ops *subops; - int size_bits; - int ret; - - list_for_each_entry(subops, &ops->subop_list, list) { - struct ftrace_hash *next_hash; - - if (!new_hash) { - size_bits =3D subops->func_hash->notrace_hash->size_bits; - new_hash =3D alloc_and_copy_ftrace_hash(size_bits, ops->func_hash->notr= ace_hash); - if (!new_hash) - return NULL; - continue; - } - size_bits =3D new_hash->size_bits; - next_hash =3D new_hash; - new_hash =3D alloc_ftrace_hash(size_bits); - ret =3D intersect_hash(&new_hash, next_hash, subops->func_hash->notrace_= hash); - free_ftrace_hash(next_hash); - if (ret < 0) { - free_ftrace_hash(new_hash); - return NULL; - } - /* Nothing more to do if new_hash is empty */ - if (ftrace_hash_empty(new_hash)) - break; - } - return new_hash; -} - static bool ops_equal(struct ftrace_hash *A, struct ftrace_hash *B) { struct ftrace_func_entry *entry; @@ -3427,6 +3391,93 @@ static int ftrace_update_ops(struct ftrace_ops *ops,= struct ftrace_hash *filter_ return 0; } =20 +static int add_first_hash(struct ftrace_hash **filter_hash, struct ftrace_= hash **notrace_hash, + struct ftrace_ops_hash *func_hash) +{ + /* If the filter hash is not empty, simply remove the nohash from it */ + if (!ftrace_hash_empty(func_hash->filter_hash)) { + *filter_hash =3D copy_hash(func_hash->filter_hash); + if (!*filter_hash) + return -ENOMEM; + remove_hash(*filter_hash, func_hash->notrace_hash); + *notrace_hash =3D EMPTY_HASH; + + } else { + *notrace_hash =3D copy_hash(func_hash->notrace_hash); + if (!*notrace_hash) + return -ENOMEM; + *filter_hash =3D EMPTY_HASH; + } + return 0; +} + +static int add_next_hash(struct ftrace_hash **filter_hash, struct ftrace_h= ash **notrace_hash, + struct ftrace_ops_hash *ops_hash, struct ftrace_ops_hash *subops_hash) +{ + int size_bits; + int ret; + + /* If the subops trace all functions so must the main ops */ + if (ftrace_hash_empty(ops_hash->filter_hash) || + ftrace_hash_empty(subops_hash->filter_hash)) { + *filter_hash =3D EMPTY_HASH; + } else { + /* + * The main ops filter hash is not empty, so its + * notrace_hash had better be, as the notrace hash + * is only used for empty main filter hashes. + */ + WARN_ON_ONCE(!ftrace_hash_empty(ops_hash->notrace_hash)); + + size_bits =3D max(ops_hash->filter_hash->size_bits, + subops_hash->filter_hash->size_bits); + + /* Copy the subops hash */ + *filter_hash =3D alloc_and_copy_ftrace_hash(size_bits, subops_hash->filt= er_hash); + if (!filter_hash) + return -ENOMEM; + /* Remove any notrace functions from the copy */ + remove_hash(*filter_hash, subops_hash->notrace_hash); + + ret =3D append_hash(filter_hash, ops_hash->filter_hash, + size_bits); + if (ret < 0) { + free_ftrace_hash(*filter_hash); + return ret; + } + } + + /* + * Only process notrace hashes if the main filter hash is empty + * (tracing all functions), otherwise the filter hash will just + * remove the notrace hash functions, and the notrace hash is + * not needed. + */ + if (ftrace_hash_empty(*filter_hash)) { + /* + * Intersect the notrace functions. That is, if two + * subops are not tracing a set of functions, the + * main ops will only not trace the functions that are + * in both subops, but has to trace the functions that + * are only notrace in one of the subops, for the other + * subops to be able to trace them. + */ + size_bits =3D max(ops_hash->notrace_hash->size_bits, + subops_hash->notrace_hash->size_bits); + *notrace_hash =3D alloc_ftrace_hash(size_bits); + if (!*notrace_hash) + return -ENOMEM; + + ret =3D intersect_hash(notrace_hash, ops_hash->notrace_hash, + subops_hash->notrace_hash); + if (ret < 0) { + free_ftrace_hash(*notrace_hash); + return ret; + } + } + return 0; +} + /** * ftrace_startup_subops - enable tracing for subops of an ops * @ops: Manager ops (used to pick all the functions of its subops) @@ -3443,7 +3494,6 @@ int ftrace_startup_subops(struct ftrace_ops *ops, str= uct ftrace_ops *subops, int struct ftrace_hash *notrace_hash; struct ftrace_hash *save_filter_hash; struct ftrace_hash *save_notrace_hash; - int size_bits; int ret; =20 if (unlikely(ftrace_disabled)) @@ -3467,14 +3517,14 @@ int ftrace_startup_subops(struct ftrace_ops *ops, s= truct ftrace_ops *subops, int =20 /* For the first subops to ops just enable it normally */ if (list_empty(&ops->subop_list)) { - /* Just use the subops hashes */ - filter_hash =3D copy_hash(subops->func_hash->filter_hash); - notrace_hash =3D copy_hash(subops->func_hash->notrace_hash); - if (!filter_hash || !notrace_hash) { - free_ftrace_hash(filter_hash); - free_ftrace_hash(notrace_hash); - return -ENOMEM; - } + + /* The ops was empty, should have empty hashes */ + WARN_ON_ONCE(!ftrace_hash_empty(ops->func_hash->filter_hash)); + WARN_ON_ONCE(!ftrace_hash_empty(ops->func_hash->notrace_hash)); + + ret =3D add_first_hash(&filter_hash, ¬race_hash, subops->func_hash); + if (ret < 0) + return ret; =20 save_filter_hash =3D ops->func_hash->filter_hash; save_notrace_hash =3D ops->func_hash->notrace_hash; @@ -3500,48 +3550,16 @@ int ftrace_startup_subops(struct ftrace_ops *ops, s= truct ftrace_ops *subops, int =20 /* * Here there's already something attached. Here are the rules: - * o If either filter_hash is empty then the final stays empty - * o Otherwise, the final is a superset of both hashes - * o If either notrace_hash is empty then the final stays empty - * o Otherwise, the final is an intersection between the hashes + * If the new subops and main ops filter hashes are not empty: + * o Make a copy of the subops filter hash + * o Remove all functions in the nohash from it. + * o Add in the main hash filter functions + * o Remove any of these functions from the main notrace hash */ - if (ftrace_hash_empty(ops->func_hash->filter_hash) || - ftrace_hash_empty(subops->func_hash->filter_hash)) { - filter_hash =3D EMPTY_HASH; - } else { - size_bits =3D max(ops->func_hash->filter_hash->size_bits, - subops->func_hash->filter_hash->size_bits); - filter_hash =3D alloc_and_copy_ftrace_hash(size_bits, ops->func_hash->fi= lter_hash); - if (!filter_hash) - return -ENOMEM; - ret =3D append_hash(&filter_hash, subops->func_hash->filter_hash, - size_bits); - if (ret < 0) { - free_ftrace_hash(filter_hash); - return ret; - } - } - - if (ftrace_hash_empty(ops->func_hash->notrace_hash) || - ftrace_hash_empty(subops->func_hash->notrace_hash)) { - notrace_hash =3D EMPTY_HASH; - } else { - size_bits =3D max(ops->func_hash->notrace_hash->size_bits, - subops->func_hash->notrace_hash->size_bits); - notrace_hash =3D alloc_ftrace_hash(size_bits); - if (!notrace_hash) { - free_ftrace_hash(filter_hash); - return -ENOMEM; - } =20 - ret =3D intersect_hash(¬race_hash, ops->func_hash->notrace_hash, - subops->func_hash->notrace_hash); - if (ret < 0) { - free_ftrace_hash(filter_hash); - free_ftrace_hash(notrace_hash); - return ret; - } - } + ret =3D add_next_hash(&filter_hash, ¬race_hash, ops->func_hash, subops= ->func_hash); + if (ret < 0) + return ret; =20 list_add(&subops->list, &ops->subop_list); =20 @@ -3557,6 +3575,42 @@ int ftrace_startup_subops(struct ftrace_ops *ops, st= ruct ftrace_ops *subops, int return ret; } =20 +static int rebuild_hashes(struct ftrace_hash **filter_hash, struct ftrace_= hash **notrace_hash, + struct ftrace_ops *ops) +{ + struct ftrace_ops_hash temp_hash; + struct ftrace_ops *subops; + bool first =3D true; + int ret; + + temp_hash.filter_hash =3D EMPTY_HASH; + temp_hash.notrace_hash =3D EMPTY_HASH; + + list_for_each_entry(subops, &ops->subop_list, list) { + *filter_hash =3D EMPTY_HASH; + *notrace_hash =3D EMPTY_HASH; + + if (first) { + ret =3D add_first_hash(filter_hash, notrace_hash, subops->func_hash); + if (ret < 0) + return ret; + first =3D false; + } else { + ret =3D add_next_hash(filter_hash, notrace_hash, + &temp_hash, subops->func_hash); + if (ret < 0) { + free_ftrace_hash(temp_hash.filter_hash); + free_ftrace_hash(temp_hash.notrace_hash); + return ret; + } + } + + temp_hash.filter_hash =3D *filter_hash; + temp_hash.notrace_hash =3D *notrace_hash; + } + return 0; +} + /** * ftrace_shutdown_subops - Remove a subops from a manager ops * @ops: A manager ops to remove @subops from @@ -3605,14 +3659,9 @@ int ftrace_shutdown_subops(struct ftrace_ops *ops, s= truct ftrace_ops *subops, in } =20 /* Rebuild the hashes without subops */ - filter_hash =3D append_hashes(ops); - notrace_hash =3D intersect_hashes(ops); - if (!filter_hash || !notrace_hash) { - free_ftrace_hash(filter_hash); - free_ftrace_hash(notrace_hash); - list_add(&subops->list, &ops->subop_list); - return -ENOMEM; - } + ret =3D rebuild_hashes(&filter_hash, ¬race_hash, ops); + if (ret < 0) + return ret; =20 ret =3D ftrace_update_ops(ops, filter_hash, notrace_hash); if (ret < 0) { @@ -3628,11 +3677,11 @@ int ftrace_shutdown_subops(struct ftrace_ops *ops, = struct ftrace_ops *subops, in =20 static int ftrace_hash_move_and_update_subops(struct ftrace_ops *subops, struct ftrace_hash **orig_subhash, - struct ftrace_hash *hash, - int enable) + struct ftrace_hash *hash) { struct ftrace_ops *ops =3D subops->managed; - struct ftrace_hash **orig_hash; + struct ftrace_hash *notrace_hash; + struct ftrace_hash *filter_hash; struct ftrace_hash *save_hash; struct ftrace_hash *new_hash; int ret; @@ -3649,24 +3698,15 @@ static int ftrace_hash_move_and_update_subops(struc= t ftrace_ops *subops, return -ENOMEM; } =20 - /* Create a new_hash to hold the ops new functions */ - if (enable) { - orig_hash =3D &ops->func_hash->filter_hash; - new_hash =3D append_hashes(ops); - } else { - orig_hash =3D &ops->func_hash->notrace_hash; - new_hash =3D intersect_hashes(ops); - } - - /* Move the hash over to the new hash */ - ret =3D __ftrace_hash_move_and_update_ops(ops, orig_hash, new_hash, enabl= e); - - free_ftrace_hash(new_hash); + ret =3D rebuild_hashes(&filter_hash, ¬race_hash, ops); + if (!ret) + ret =3D ftrace_update_ops(ops, filter_hash, notrace_hash); =20 if (ret) { /* Put back the original hash */ - free_ftrace_hash_rcu(*orig_subhash); + new_hash =3D *orig_subhash; *orig_subhash =3D save_hash; + free_ftrace_hash_rcu(new_hash); } else { free_ftrace_hash_rcu(save_hash); } @@ -4890,7 +4930,7 @@ static int ftrace_hash_move_and_update_ops(struct ftr= ace_ops *ops, int enable) { if (ops->flags & FTRACE_OPS_FL_SUBOP) - return ftrace_hash_move_and_update_subops(ops, orig_hash, hash, enable); + return ftrace_hash_move_and_update_subops(ops, orig_hash, hash); =20 /* * If this ops is not enabled, it could be sharing its filters @@ -4909,7 +4949,7 @@ static int ftrace_hash_move_and_update_ops(struct ftr= ace_ops *ops, list_for_each_entry(subops, &op->subop_list, list) { if ((subops->flags & FTRACE_OPS_FL_ENABLED) && subops->func_hash =3D=3D ops->func_hash) { - return ftrace_hash_move_and_update_subops(subops, orig_hash, hash, en= able); + return ftrace_hash_move_and_update_subops(subops, orig_hash, hash); } } } while_for_each_ftrace_op(op); --=20 2.47.2 From nobody Fri Dec 19 10:57:29 2025 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 550E0224B15 for ; Sat, 12 Apr 2025 21:03:43 +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=1744491823; cv=none; b=Hyeqm507rUsmgBT7J6E7IdCT3DaOTAlDHelkq+8KYGiPDbWtLk51PRrfzghqSfr5cmleHJGUAMawe2OLBMVwZUC6YPMMlGx7awz2Hy9GxBaJHyPZfBz9LCfuWRjZxAIIzc+SHx38Kl/h9HpM5AJJb0jDlBLJZij2uw9jmhdIDHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744491823; c=relaxed/simple; bh=Ml/bTbNtyyxIDpxkxfJcPetzMR28RnViCGd9T4KpVf8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=uAb+h4BbEZ1Cqd616nI9LPrJ7siryh+hEfRWK/tlooGCpUIbxcZJIbfAxN4ntnA407tBuCzPQEMUwh6pQ4c8Txkqt8YbcS1bi+tqaAUs3ebXIHMt79dqTekT0hBGW3+ytjDshB8AMzvbRuR97xjRi1rQKTL0Hz0T1bxvfIyIioo= 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 33BDBC4CEED; Sat, 12 Apr 2025 21:03:43 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1u3i2J-0000000AEFL-0XUe; Sat, 12 Apr 2025 17:05:11 -0400 Message-ID: <20250412210510.980606091@goodmis.org> User-Agent: quilt/0.68 Date: Sat, 12 Apr 2025 17:04:51 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Shuah Khan , Andy Chiu Subject: [for-linus][PATCH 5/7] tracing/selftest: Add test to better test subops filtering of function graph References: <20250412210446.338481957@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 that showed the accounting of the subops of the ftrace_ops filtering was incorrect. Add a new test to better test the filtering. This test creates two instances, where it will add various filters to both the set_ftrace_filter and the set_ftrace_notrace files and enable function_graph. Then it looks into the enabled_functions file to make sure that the filters are behaving correctly. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Shuah Khan Cc: Andy Chiu Link: https://lore.kernel.org/20250409152720.380778379@goodmis.org Signed-off-by: Steven Rostedt (Google) --- .../test.d/ftrace/fgraph-multi-filter.tc | 177 ++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 tools/testing/selftests/ftrace/test.d/ftrace/fgraph-mul= ti-filter.tc diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-multi-filt= er.tc b/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-multi-filter.tc new file mode 100644 index 000000000000..b6d6a312ead5 --- /dev/null +++ b/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-multi-filter.tc @@ -0,0 +1,177 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# description: ftrace - function graph filters +# requires: set_ftrace_filter function_graph:tracer + +# Make sure that function graph filtering works + +INSTANCE1=3D"instances/test1_$$" +INSTANCE2=3D"instances/test2_$$" + +WD=3D`pwd` + +do_reset() { + cd $WD + if [ -d $INSTANCE1 ]; then + echo nop > $INSTANCE1/current_tracer + rmdir $INSTANCE1 + fi + if [ -d $INSTANCE2 ]; then + echo nop > $INSTANCE2/current_tracer + rmdir $INSTANCE2 + fi +} + +mkdir $INSTANCE1 +if ! grep -q function_graph $INSTANCE1/available_tracers; then + echo "function_graph not allowed with instances" + rmdir $INSTANCE1 + exit_unsupported +fi + +mkdir $INSTANCE2 + +fail() { # msg + do_reset + echo $1 + exit_fail +} + +disable_tracing +clear_trace + +function_count() { + search=3D$1 + vsearch=3D$2 + + if [ -z "$search" ]; then + cat enabled_functions | wc -l + elif [ -z "$vsearch" ]; then + grep $search enabled_functions | wc -l + else + grep $search enabled_functions | grep $vsearch| wc -l + fi +} + +set_fgraph() { + instance=3D$1 + filter=3D"$2" + notrace=3D"$3" + + echo "$filter" > $instance/set_ftrace_filter + echo "$notrace" > $instance/set_ftrace_notrace + echo function_graph > $instance/current_tracer +} + +check_functions() { + orig_cnt=3D$1 + test=3D$2 + + cnt=3D`function_count $test` + if [ $cnt -gt $orig_cnt ]; then + fail + fi +} + +check_cnt() { + orig_cnt=3D$1 + search=3D$2 + vsearch=3D$3 + + cnt=3D`function_count $search $vsearch` + if [ $cnt -gt $orig_cnt ]; then + fail + fi +} + +reset_graph() { + instance=3D$1 + echo nop > $instance/current_tracer +} + +# get any functions that were enabled before the test +total_cnt=3D`function_count` +sched_cnt=3D`function_count sched` +lock_cnt=3D`function_count lock` +time_cnt=3D`function_count time` +clock_cnt=3D`function_count clock` +locks_clock_cnt=3D`function_count locks clock` +clock_locks_cnt=3D`function_count clock locks` + +# Trace functions with "sched" but not "time" +set_fgraph $INSTANCE1 '*sched*' '*time*' + +# Make sure "time" isn't listed +check_functions $time_cnt 'time' +instance1_cnt=3D`function_count` + +# Trace functions with "lock" but not "clock" +set_fgraph $INSTANCE2 '*lock*' '*clock*' +instance1_2_cnt=3D`function_count` + +# Turn off the first instance +reset_graph $INSTANCE1 + +# The second instance doesn't trace "clock" functions +check_functions $clock_cnt 'clock' +instance2_cnt=3D`function_count` + +# Start from a clean slate +reset_graph $INSTANCE2 +check_functions $total_cnt + +# Trace functions with "lock" but not "clock" +set_fgraph $INSTANCE2 '*lock*' '*clock*' + +# This should match the last time instance 2 was by itself +cnt=3D`function_count` +if [ $instance2_cnt -ne $cnt ]; then + fail +fi + +# And it should not be tracing "clock" functions +check_functions $clock_cnt 'clock' + +# Trace functions with "sched" but not "time" +set_fgraph $INSTANCE1 '*sched*' '*time*' + +# This should match the last time both instances were enabled +cnt=3D`function_count` +if [ $instance1_2_cnt -ne $cnt ]; then + fail +fi + +# Turn off the second instance +reset_graph $INSTANCE2 + +# This should match the last time instance 1 was by itself +cnt=3D`function_count` +if [ $instance1_cnt -ne $cnt ]; then + fail +fi + +# And it should not be tracing "time" functions +check_functions $time_cnt 'time' + +# Start from a clean slate +reset_graph $INSTANCE1 +check_functions $total_cnt + +# Enable all functions but those that have "locks" +set_fgraph $INSTANCE1 '' '*locks*' + +# Enable all functions but those that have "clock" +set_fgraph $INSTANCE2 '' '*clock*' + +# If a function has "locks" it should not have "clock" +check_cnt $locks_clock_cnt locks clock + +# If a function has "clock" it should not have "locks" +check_cnt $clock_locks_cnt clock locks + +reset_graph $INSTANCE1 +reset_graph $INSTANCE2 + +do_reset + +exit 0 --=20 2.47.2 From nobody Fri Dec 19 10:57:29 2025 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 619F22253F6 for ; Sat, 12 Apr 2025 21:03:43 +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=1744491823; cv=none; b=L00/BNTc8ufD5CuUNU/6gNdcO18NVQEjENMw7g+Bshz5OkyPvXJazJu73vuCNItfVJRNns3eFpWM/1ZZN7K8aZpE2hsY1AborbEsAaxAdbvgrDAoGQdP/VciDBVeAYKfMdqceTOmLCoqmhCZ9REnIgB0gB4KP1pL1Y9Bz7wWiv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744491823; c=relaxed/simple; bh=vlcadWhN1kpMYnw+3E7ZcAlZv9dphSozdaw8cKl3E4M=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=VagA78VL9wn7Bf5ZiIlkp5WcxFjL8ay9XGQb8POQVkSjjbCGsKsygvwa/oMLDrKd8Cbs+gAerLD020/uJAv4FexHoSl1sdJZYxRGNX7dB+833ANnqc9me6YsQ+DgiB2ztKWcwwZYEwhJJOOcYmRWeLEMYOJg3GlDxJt+mjETBTk= 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 3DEDEC4CEE3; Sat, 12 Apr 2025 21:03:43 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1u3i2J-0000000AEFq-1FNU; Sat, 12 Apr 2025 17:05:11 -0400 Message-ID: <20250412210511.150486416@goodmis.org> User-Agent: quilt/0.68 Date: Sat, 12 Apr 2025 17:04:52 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Mark Brown Subject: [for-linus][PATCH 6/7] ftrace: Do not have print_graph_retval() add a newline References: <20250412210446.338481957@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 retval and retaddr options for function_graph tracer will add a comment at the end of a function for both leaf and non leaf functions that looks like: __wake_up_common(); /* ret=3D0x1 */ } /* pick_next_task_fair ret=3D0x0 */ The function print_graph_retval() adds a newline after the "*/". But if that's not called, the caller function needs to make sure there's a newline added. This is confusing and when the function parameters code was added, it added a newline even when calling print_graph_retval() as the fact that the print_graph_retval() function prints a newline isn't obvious. This caused an extra newline to be printed and that made it fail the selftests when the retval option was set, as the selftests were not expecting blank lines being injected into the trace. Instead of having print_graph_retval() print a newline, just have the caller always print the newline regardless if it calls print_graph_retval() or not. This not only fixes this bug, but it also simplifies the code. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20250411133015.015ca393@gandalf.local.home Reported-by: Mark Brown Tested-by: Mark Brown Closes: https://lore.kernel.org/all/ccc40f2b-4b9e-4abd-8daf-d22fce2a86f0@si= rena.org.uk/ Fixes: ff5c9c576e754 ("ftrace: Add support for function argument to graph t= racer") Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_functions_graph.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_func= tions_graph.c index 2f077d4158e5..0c357a89c58e 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c @@ -880,8 +880,6 @@ static void print_graph_retval(struct trace_seq *s, str= uct ftrace_graph_ent_entr =20 if (print_retval || print_retaddr) trace_seq_puts(s, " /*"); - else - trace_seq_putc(s, '\n'); } else { print_retaddr =3D false; trace_seq_printf(s, "} /* %ps", func); @@ -899,7 +897,7 @@ static void print_graph_retval(struct trace_seq *s, str= uct ftrace_graph_ent_entr } =20 if (!entry || print_retval || print_retaddr) - trace_seq_puts(s, " */\n"); + trace_seq_puts(s, " */"); } =20 #else @@ -975,7 +973,7 @@ print_graph_entry_leaf(struct trace_iterator *iter, } else trace_seq_puts(s, "();"); } - trace_seq_printf(s, "\n"); + trace_seq_putc(s, '\n'); =20 print_graph_irq(iter, graph_ret->func, TRACE_GRAPH_RET, cpu, iter->ent->pid, flags); @@ -1313,10 +1311,11 @@ print_graph_return(struct ftrace_graph_ret_entry *r= etentry, struct trace_seq *s, * that if the funcgraph-tail option is enabled. */ if (func_match && !(flags & TRACE_GRAPH_PRINT_TAIL)) - trace_seq_puts(s, "}\n"); + trace_seq_puts(s, "}"); else - trace_seq_printf(s, "} /* %ps */\n", (void *)func); + trace_seq_printf(s, "} /* %ps */", (void *)func); } + trace_seq_putc(s, '\n'); =20 /* Overrun */ if (flags & TRACE_GRAPH_PRINT_OVERRUN) --=20 2.47.2 From nobody Fri Dec 19 10:57:29 2025 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 83374227B8E; Sat, 12 Apr 2025 21:03:43 +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=1744491823; cv=none; b=jB+gDBDK8JwiVDZUdY9AJ+AlRL6xLKRqmuwB4wjVTM4TX7HpOFj26AH9LJgqs72kqejobiFD+H+EQ7abPoE1i3aG7s9+V1mEADOZWGCEpX8fC//ao1MaJt6J4g/6wkb0PM6YywoZ7V9iRVWr3Khxi0vm0tOSCQpUeWilBIU+Yzs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744491823; c=relaxed/simple; bh=z8sTYKbHMCcEu+d5dLCKvRyatcQgaCISPyMbtmKmOSg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=cUi5qP1PWBq01LttU9PPNx3d7pjK2cThpSBxPn1OFGKBgORUPLf8kAIG+N4lP2HtzJNI/rId8M5xX62Ekg0QMHv/upp3T70QAXJZKHQBXZZQzSiyC2WMuyXxhrR0i+b6U665LMc58BLjiDA46C9Jb5JNh1TDW+QRIij3OlX8avc= 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 6F91CC4CEEE; Sat, 12 Apr 2025 21:03:43 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1u3i2J-0000000AEGK-1y8E; Sat, 12 Apr 2025 17:05:11 -0400 Message-ID: <20250412210511.320072168@goodmis.org> User-Agent: quilt/0.68 Date: Sat, 12 Apr 2025 17:04:53 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Gabriele Monaco , Nam Cao Subject: [for-linus][PATCH 7/7] rv: Fix out-of-bound memory access in rv_is_container_monitor() References: <20250412210446.338481957@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: Nam Cao When rv_is_container_monitor() is called on the last monitor in rv_monitors_list, KASAN yells: BUG: KASAN: global-out-of-bounds in rv_is_container_monitor+0x101/0x110 Read of size 8 at addr ffffffff97c7c798 by task setup/221 The buggy address belongs to the variable: rv_monitors_list+0x18/0x40 This is due to list_next_entry() is called on the last entry in the list. It wraps around to the first list_head, and the first list_head is not embedded in struct rv_monitor_def. Fix it by checking if the monitor is last in the list. Cc: stable@vger.kernel.org Cc: Gabriele Monaco Fixes: cb85c660fcd4 ("rv: Add option for nested monitors and include sched") Link: https://lore.kernel.org/e85b5eeb7228bfc23b8d7d4ab5411472c54ae91b.1744= 355018.git.namcao@linutronix.de Signed-off-by: Nam Cao Signed-off-by: Steven Rostedt (Google) --- kernel/trace/rv/rv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/trace/rv/rv.c b/kernel/trace/rv/rv.c index 968c5c3b0246..e4077500a91d 100644 --- a/kernel/trace/rv/rv.c +++ b/kernel/trace/rv/rv.c @@ -225,7 +225,12 @@ bool rv_is_nested_monitor(struct rv_monitor_def *mdef) */ bool rv_is_container_monitor(struct rv_monitor_def *mdef) { - struct rv_monitor_def *next =3D list_next_entry(mdef, list); + struct rv_monitor_def *next; + + if (list_is_last(&mdef->list, &rv_monitors_list)) + return false; + + next =3D list_next_entry(mdef, list); =20 return next->parent =3D=3D mdef->monitor || !mdef->monitor->enable; } --=20 2.47.2