[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250911213823.374806-30-jim.cromie@gmail.com>
Date: Thu, 11 Sep 2025 15:38:22 -0600
From: Jim Cromie <jim.cromie@...il.com>
To: jbaron@...mai.com
Cc: gregkh@...uxfoundation.org,
ukaszb@...omium.org,
louis.chauvet@...tlin.com,
linux-kernel@...r.kernel.org,
Jim Cromie <jim.cromie@...il.com>
Subject: [PATCH 29/30] dyndbg: add DYNAMIC_DEBUG_CLASSMAP_USE_(clname,_base)
The @_base parameter in @DYNAMIC_DEBUG_CLASSMAP_DEFINE exists to
de-conflict a second classmap definition from a first, by setting
different .class_id constants for all of the second map's pr_debug
callsites.
This gives the same _base param, and thus more flexible usage via
@DYNAMIC_DEBUG_CLASSMAP_USE_(clname,_base). So now 2nd classmap used
can be deconflicted from the 1st used or defined.
1st the range-checking logic is refined into two distinct macros,
@ddebug_class_map_in_range() and @ddebug_class_user_in_range(), which
are then applied to the lookup functions: @ddebug_find_valid_class(),
@ddebug_find_map_by_class_id(), and @ddebug_class_name().
The @DYNAMIC_DEBUG_CLASSMAP_USE* macro API kdoc is adjusted accordingly.
Signed-off-by: Jim Cromie <jim.cromie@...il.com>
---
include/linux/dynamic_debug.h | 28 ++++++++++++++++++++++------
lib/dynamic_debug.c | 21 +++++++++++++--------
2 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 588e03e8d157..d1e38158c485 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -87,7 +87,7 @@ struct _ddebug_class_map {
struct _ddebug_class_user {
char *mod_name;
struct _ddebug_class_map *map;
- const int base; /* user offset to re-number the used map */
+ const int base; /* offset .class_id range to share space */
};
/*
@@ -235,15 +235,31 @@ struct _ddebug_class_param {
/**
* DYNAMIC_DEBUG_CLASSMAP_USE - refer to a classmap, DEFINEd elsewhere.
* @_var: name of the exported classmap var
- * @_not_yet: _base-like, but applies only to this USEr. (if needed)
*
* This tells dyndbg that the module has prdbgs with classids defined
* in the named classmap. This qualifies "class NAME" >controls on
- * the user module, and ignores unknown names.
+ * the user module, and ignores unknown names. This is a wrapper for
+ * DYNAMIC_DEBUG_CLASSMAP_USE_() with a base offset of 0.
*/
-#define DYNAMIC_DEBUG_CLASSMAP_USE(_var) \
- DYNAMIC_DEBUG_CLASSMAP_USE_(_var, 0, __UNIQUE_ID(_ddebug_class_user))
-#define DYNAMIC_DEBUG_CLASSMAP_USE_(_var, _base, _uname) \
+#define DYNAMIC_DEBUG_CLASSMAP_USE(_var) \
+ DYNAMIC_DEBUG_CLASSMAP_USE_(_var, 0)
+
+/**
+ * DYNAMIC_DEBUG_CLASSMAP_USE_ - refer to a classmap with a manual offset.
+ * @_var: name of the exported classmap var to use.
+ * @_base: an integer offset to add to the class IDs of the used map.
+ *
+ * This is an extended version of DYNAMIC_DEBUG_CLASSMAP_USE(). It should
+ * be used to resolve class ID conflicts when a module uses multiple
+ * classmaps that have overlapping ID ranges.
+ *
+ * The final class IDs for the used map will be calculated as:
+ * original_map_base + class_index + @_base.
+ */
+#define DYNAMIC_DEBUG_CLASSMAP_USE_(_var, _base) \
+ __DYNAMIC_DEBUG_CLASSMAP_USE(_var, _base, __UNIQUE_ID(_ddebug_class_user))
+
+#define __DYNAMIC_DEBUG_CLASSMAP_USE(_var, _base, _uname) \
extern struct _ddebug_class_map _var; \
static struct _ddebug_class_user __aligned(8) __used \
__section("__dyndbg_class_users") _uname = { \
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 97070ddf31c6..486aa68670d8 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -169,6 +169,12 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
_di->users.len); \
})
+#define ddebug_class_map_in_range(id, map) \
+ ((id) >= (map)->base && (id) < (map)->base + (map)->length)
+#define ddebug_class_user_in_range(id, user) \
+ ((id) >= ((user)->map->base + (user)->base) && \
+ (id) < ((user)->map->base + (user)->base + (user)->map->length))
+
static struct _ddebug_class_map *
ddebug_find_valid_class(struct _ddebug_info const *di, const char *query_class, int *class_id)
{
@@ -189,7 +195,7 @@ ddebug_find_valid_class(struct _ddebug_info const *di, const char *query_class,
if (idx >= 0) {
vpr_di_info(di, "class-ref: %s -> %s.%s ",
cli->mod_name, cli->map->mod_name, query_class);
- *class_id = idx + cli->map->base;
+ *class_id = idx + cli->map->base + cli->base;
return cli->map;
}
}
@@ -197,8 +203,7 @@ ddebug_find_valid_class(struct _ddebug_info const *di, const char *query_class,
return NULL;
}
-#define class_in_range(class_id, map) \
- (class_id >= map->base && class_id < map->base + map->length)
+
static struct _ddebug_class_map *
ddebug_find_map_by_class_id(struct _ddebug_info *di, int class_id)
@@ -208,11 +213,11 @@ ddebug_find_map_by_class_id(struct _ddebug_info *di, int class_id)
int i;
for_subvec(i, map, di, maps)
- if (class_in_range(class_id, map))
+ if (ddebug_class_map_in_range(class_id, map))
return map;
for_subvec(i, cli, di, users)
- if (class_in_range(class_id, cli->map))
+ if (ddebug_class_user_in_range(class_id, cli))
return cli->map;
return NULL;
@@ -1146,12 +1151,12 @@ static const char *ddebug_class_name(struct _ddebug_info *di, struct _ddebug *dp
int i;
for_subvec(i, map, di, maps)
- if (class_in_range(dp->class_id, map))
+ if (ddebug_class_map_in_range(dp->class_id, map))
return map->class_names[dp->class_id - map->base];
for_subvec(i, cli, di, users)
- if (class_in_range(dp->class_id, cli->map))
- return cli->map->class_names[dp->class_id - cli->map->base];
+ if (ddebug_class_user_in_range(dp->class_id, cli))
+ return cli->map->class_names[dp->class_id - cli->map->base - cli->base];
return NULL;
}
--
2.51.0
Powered by blists - more mailing lists