[PATCH 61/64] dyndbg: allow ddebug_add_module to fail
Jim Cromie
jim.cromie at gmail.com
Sun Oct 6 19:22:41 UTC 2024
To prep for failing modprobe on classid conflicts, upgrade the
call-chain around ddebug_add_module(), in 2 ways:
1. return int from both ddebug_attach_{,user_}module_classes(), up to
ddebug_add_module(), then to ddebug_module_notify().
2. add reserved_ids to ddebug_add_module() to accumulate reservations,
pass it by ref to ddebug_attach_{,user_}module_classes() so they can
examine the reservations as they work.
No conflicts are currently detected or returned.
Signed-off-by: Jim Cromie <jim.cromie at gmail.com>
---
lib/dynamic_debug.c | 41 +++++++++++++++++++++++++++++------------
1 file changed, 29 insertions(+), 12 deletions(-)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 788e579b4504..3faa8e5f63de 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -1246,8 +1246,9 @@ static void ddebug_apply_params(const struct ddebug_class_map *cm, const char *m
* modular classmap vector/section. Save the start and length of the
* subrange at its edges.
*/
-static void ddebug_attach_module_classes(struct ddebug_table *dt,
- const struct _ddebug_info *di)
+static int ddebug_attach_module_classes(struct ddebug_table *dt,
+ const struct _ddebug_info *di,
+ u64 *reserved_ids)
{
struct ddebug_class_map *cm;
int i, nc = 0;
@@ -1260,13 +1261,14 @@ static void ddebug_attach_module_classes(struct ddebug_table *dt,
}
}
if (!nc)
- return;
+ return 0;
vpr_info("module:%s attached %d classes\n", dt->mod_name, nc);
dt->num_classes = nc;
for (i = 0, cm = dt->classes; i < dt->num_classes; i++, cm++)
ddebug_apply_params(cm, cm->mod_name);
+ return 0;
}
/*
@@ -1274,8 +1276,9 @@ static void ddebug_attach_module_classes(struct ddebug_table *dt,
* means a query against the dt/module, which means it must be on the
* list to be seen by ddebug_change.
*/
-static void ddebug_attach_user_module_classes(struct ddebug_table *dt,
- const struct _ddebug_info *di)
+static int ddebug_attach_user_module_classes(struct ddebug_table *dt,
+ const struct _ddebug_info *di,
+ u64 *reserved_ids)
{
struct ddebug_class_user *cli;
int i, nc = 0;
@@ -1296,7 +1299,7 @@ static void ddebug_attach_user_module_classes(struct ddebug_table *dt,
}
}
if (!nc)
- return;
+ return 0;
dt->num_class_users = nc;
@@ -1305,6 +1308,7 @@ static void ddebug_attach_user_module_classes(struct ddebug_table *dt,
ddebug_apply_params(cli->map, cli->mod_name);
vpr_dt_info(dt, "attach-client-module: ");
+ return 0;
}
/*
@@ -1314,6 +1318,8 @@ static void ddebug_attach_user_module_classes(struct ddebug_table *dt,
static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
{
struct ddebug_table *dt;
+ u64 reserved_ids = 0;
+ int rc;
if (!di->num_descs)
return 0;
@@ -1337,16 +1343,22 @@ static int ddebug_add_module(struct _ddebug_info *di, const char *modname)
INIT_LIST_HEAD(&dt->link);
- if (di->num_classes)
- ddebug_attach_module_classes(dt, di);
-
+ if (di->num_classes) {
+ rc = ddebug_attach_module_classes(dt, di, &reserved_ids);
+ if (rc) {
+ kfree(dt);
+ return rc;
+ }
+ }
mutex_lock(&ddebug_lock);
list_add_tail(&dt->link, &ddebug_tables);
mutex_unlock(&ddebug_lock);
- if (di->num_class_users)
- ddebug_attach_user_module_classes(dt, di);
-
+ if (di->num_class_users) {
+ rc = ddebug_attach_user_module_classes(dt, di, &reserved_ids);
+ if (rc)
+ return rc;
+ }
vpr_info("%3u debug prints in module %s\n", di->num_descs, modname);
return 0;
}
@@ -1431,6 +1443,11 @@ static int ddebug_module_notify(struct notifier_block *self, unsigned long val,
switch (val) {
case MODULE_STATE_COMING:
ret = ddebug_add_module(&mod->dyndbg_info, mod->name);
+ if (ret == -EINVAL) {
+ pr_err("conflicting dyndbg-classmap reservations\n");
+ ddebug_remove_module(mod->name);
+ break;
+ }
if (ret)
WARN(1, "Failed to allocate memory: dyndbg may not work properly.\n");
break;
--
2.46.2
More information about the Intel-gfx-trybot
mailing list