[RFC PATCH 09/10] dyndbg: add dd_clear_range to prune mtrees
From: Jim Cromie
Date: Thu Oct 12 2023 - 15:49:46 EST
Call new dd_clear_range() from ddebug_remove_module(). It calls
mtree_erase() on the trees storing the function, filename, modname
intervals, and passing the 1st descriptor of the interval (ie the
index used on the insert).
dd_clear_range() should properly undo the 3 mtree_insert_ranges done
by dd_store_range.
RFC: it doesnt work as I expected. What am I missing ?
The following log shows that 'rmmod amdgpu' only removes 1 entry from
each maple-tree, not the whole interval. My index is the 1st
descriptor in each interval.
ISTM (naive reader) this contradicts the documented behavior.
void *mtree_erase(struct maple_tree *mt, unsigned long index)
Find an index and erase the entire range.
what is my "entire range" ?
bash-5.2# modprobe amdgpu
....
[ 74.256006] dyndbg: attach-client-module: module:amdgpu nd:4652 nc:0 nu:1
[ 74.256968] dyndbg: 4652 debug prints in module amdgpu
bash-5.2# echo 2 > /sys/module/dynamic_debug/parameters/do_scan
[ 81.370509] dyndbg: cache: funcs has 3741 entries
[ 81.371233] dyndbg: cache: files has 911 entries
[ 81.371819] dyndbg: cache: mods has 323 entries
bash-5.2# rmmod amdgpu
[ 102.325851] dyndbg: removed module "amdgpu"
bash-5.2# echo 2 > /sys/module/dynamic_debug/parameters/do_scan
[ 105.277439] dyndbg: cache: funcs has 3740 entries
[ 105.278163] dyndbg: cache: files has 910 entries
[ 105.278756] dyndbg: cache: mods has 322 entries
cc: Liam R. Howlett <Liam.Howlett@xxxxxxxxxx>
cc: linux-mm@xxxxxxxxx
Signed-off-by: Jim Cromie <jim.cromie@xxxxxxxxx>
---
lib/dynamic_debug.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index fb72a7b05b01..92ffd70a07de 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -1426,6 +1426,14 @@ static void dd_store_range(struct maple_tree *mt, const struct _ddebug *start,
v4pr_info(" ok %s at %lx\n", val, first);
}
+static void dd_clear_range(const struct _ddebug *start)
+{
+ v3pr_info("clearing %px\n", start);
+ mtree_erase(&mt_funcs, (unsigned long)start);
+ mtree_erase(&mt_files, (unsigned long)start);
+ mtree_erase(&mt_mods, (unsigned long)start);
+}
+
#define site_function(s) (s)->_function
#define site_filename(s) (s)->_filename
#define site_modname(s) (s)->_modname
@@ -1578,6 +1586,8 @@ static int ddebug_remove_module(const char *mod_name)
mutex_lock(&ddebug_lock);
list_for_each_entry_safe(dt, nextdt, &ddebug_tables, link) {
if (dt->mod_name == mod_name) {
+ /* free mtree entries on descs */
+ dd_clear_range(dt->ddebugs);
ddebug_table_free(dt);
ret = 0;
break;
--
2.41.0