diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index fb182c903088..6a6cd45e5571 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -536,6 +536,23 @@ void ddebug_increment_call_count(void);
#define DYNAMIC_DEBUG_BRANCH(descriptor) false
#define DECLARE_DYNDBG_CLASSMAP(...)
+#if defined(DEBUG)
+#define _dynamic_func_call_cls(cls, fmt, func, ...) \
+ do { func(NULL, ##__VA_ARGS__); } while (0)
+#define _dynamic_func_call_cls_no_desc(cls, fmt, func, ...) \
+ do { func(__VA_ARGS__); } while (0)
+#else
+#define _dynamic_func_call_cls(cls, fmt, func, ...) \
+ do { if (0) func(NULL, ##__VA_ARGS__); } while (0)
+#define _dynamic_func_call_cls_no_desc(cls, fmt, func, ...) \
+ do { if (0) func(__VA_ARGS__); } while (0)
+#endif
+
+#define _dynamic_func_call(fmt, func, ...) \
+ _dynamic_func_call_cls(_DPRINTK_CLASS_DFLT, fmt, func, ##__VA_ARGS__)
+#define _dynamic_func_call_no_desc(fmt, func, ...) \
+ _dynamic_func_call_cls_no_desc(_DPRINTK_CLASS_DFLT, fmt, func, ##__VA_ARGS__)
+
#define dynamic_pr_debug(fmt, ...) \
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#define dynamic_dev_dbg(dev, fmt, ...) \diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 027f7c31fe22..8c0a67ad9c92 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -329,7 +329,8 @@ static bool ddebug_match_desc(const struct ddebug_query *query,
/* site is class'd */
site_map = ddebug_find_map_by_class_id(di, dp->class_id);
if (!site_map) {
- WARN_ONCE(1, "unknown class_id %d, check %s's CLASSMAP definitions", dp->class_id, di->mod_name);
+ pr_warn_ratelimited("unknown class_id %d, check %s's CLASSMAP definitions\n",
+ dp->class_id, di->mod_name);
return false;
}
/* module(-param) decides protection */@@ -1583,18 +1584,80 @@ static void ddebug_apply_class_users(const struct _ddebug_info *di)
__di->_vec.start = __start; \
})
-static int ddebug_class_range_overlap(struct ddebug_class_map *cm, u64 *reserved_ids)
+static bool ddebug_validate_class_range(const char *modname,
+ const char *name,
+ int base, int length,
+ u64 *reserved_ids)
{
- u64 range = (((1ULL << cm->length) - 1) << cm->base);
+ u64 range;
+ if (base < 0 || length <= 0 ||
+ base + length > _DPRINTK_CLASS_DFLT) {
+ pr_err("module %s: base:%d len:%d (from %s) exceeds class_id limit %d\n",
+ modname, base, length, name, _DPRINTK_CLASS_DFLT);
+ return false;
+ }
+ range = (((1ULL << length) - 1) << base);
if (range & *reserved_ids) {
- pr_err("[%d..%d] on %s conflicts with %llx\n", cm->base,
- cm->base + cm->length - 1, cm->class_names[0],
- *reserved_ids);
- return -EINVAL;
+ pr_err("module %s: [%d..%d] (from %s) conflicts with 0x%llx\n",
+ modname, base, base + length - 1, name, *reserved_ids);
+ return false;
}
*reserved_ids |= range;
- return 0;
+ return true;
+}
+
+static bool ddebug_validate_classmaps(struct _ddebug_info *di)
+{
+ struct ddebug_class_map *cm;
+ struct ddebug_class_user *cli;
+ u64 reserved_ids = 0;
+ bool valid = true;
+ int i;
+
+ for_subvec(i, cm, di, maps)
+ if (!ddebug_validate_class_range(di->mod_name,
+ cm->class_names[0],
+ cm->base, cm->length,
+ &reserved_ids))
+ valid = false;
+
+ for_subvec(i, cli, di, users) {
+ if (!cli->map) {
+ pr_err("module %s: classmap not found for user\n",
+ di->mod_name);
+ valid = false;
+ continue;
+ }
+ if (!ddebug_validate_class_range(di->mod_name,
+ cli->map->class_names[0],
+ cli->map->base + cli->offset,
+ cli->map->length,
+ &reserved_ids))
+ valid = false;
+ }
+ return valid;
+}
+
+static void ddebug_validate_descs(struct _ddebug_info *di)
+{
+ struct _ddebug *dp;
+ u64 bad_ids = 0;
+ int i;
+
+ for (i = 0; i < di->descs.len; i++) {
+ dp = &di->descs.start[i];
+
+ if (dp->class_id == _DPRINTK_CLASS_DFLT)
+ continue;
+ if (bad_ids & (1ULL << dp->class_id))
+ continue;
+ if (!ddebug_find_map_by_class_id(di, dp->class_id)) {
+ pr_warn("module %s uses unknown class_id %d\n",
+ di->mod_name, dp->class_id);
+ bad_ids |= (1ULL << dp->class_id);
+ }
+ }
}
/*@@ -1606,7 +1669,6 @@ static int ddebug_add_module(struct _ddebug_info *di)
struct ddebug_table *dt;
struct ddebug_class_map *cm;
struct ddebug_class_user *cli;
- u64 reserved_ids = 0;
int i;
if (!di->descs.len)
@@ -1638,10 +1700,10 @@ static int ddebug_add_module(struct _ddebug_info *di)
dd_set_module_subrange(i, cm, &dt->info, maps);
dd_set_module_subrange(i, cli, &dt->info, users);
- /* insure 2+ classmaps share the per-module 0..62 class_id space */
- for_subvec(i, cm, &dt->info, maps)
- if (ddebug_class_range_overlap(cm, &reserved_ids))
- goto cleanup;
+ if (!ddebug_validate_classmaps(&dt->info))
+ goto cleanup;
+
+ ddebug_validate_descs(&dt->info);
/*
* Bind controlling_param before publishing dt to ddebug_tables so
@@ -1668,7 +1730,7 @@ static int ddebug_add_module(struct _ddebug_info *di)
dt->info.descs.len, dt->info.mod_name);
return 0;
cleanup:
- WARN_ONCE(1, "dyndbg multi-classmap conflict in %s\n", di->mod_name);
+ pr_err("dyndbg multi-classmap conflict in %s\n", di->mod_name);
kfree(dt);
return -EINVAL;
}@@ -1756,7 +1818,7 @@ static int ddebug_module_notify(struct notifier_block *self, unsigned long val,
mod->dyndbg_info.mod_name = mod->name;
ret = ddebug_add_module(&mod->dyndbg_info);
if (ret)
- WARN(1, "Failed to allocate memory: dyndbg may not work properly.\n");
+ pr_err("dyndbg: failed to add module %s: %d\n", mod->name, ret);
break;
case MODULE_STATE_GOING:
ddebug_remove_module(mod->name);diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
index 71cba798621c..2f19ecb1f295 100644
--- a/lib/test_dynamic_debug.c
+++ b/lib/test_dynamic_debug.c
@@ -173,14 +173,23 @@ DYNAMIC_DEBUG_CLASSMAP_DEFINE(fail_base_len, 0, 60,
#endif
#else /* TEST_DYNAMIC_DEBUG_SUBMOD */
-
/*
- * in submod/drm-drivers, use the classmaps defined in top/parent
- * module above.
+ * In submod (drm-drivers/helpers) use the classmaps defined in
+ * top/parent module above. We _USE_() with offset, to test the
+ * non-zero case.
*/
-
DYNAMIC_DEBUG_CLASSMAP_USE(map_disjoint_bits);
+
+#if defined(DD_RUNTIME_CLASS_CHECK)
+/*
+ * Force failure of compile-time sanity checks of (classmap.length +
+ * offset < 63) if -DDD_RUNTIME_CLASS_CHECK is given in compile
+ * command
+ */
+DYNAMIC_DEBUG_CLASSMAP_USE_(map_level_num, 55);
+#else
DYNAMIC_DEBUG_CLASSMAP_USE_(map_level_num, 8);
+#endif
#if defined(DD_MACRO_ARGCHECK)
DYNAMIC_DEBUG_CLASSMAP_USE_(fail_offset_big, 100);
diff --git a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
index b976fef40ef1..a4f78f6dbec2 100755
--- a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
+++ b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
@@ -576,7 +576,7 @@ function GOLDEN_RECORDS {
#K= c518a50ba30ba8099d0dc874a27ecf16 FT_multi_query.4
#K= 91838b4012c50a1dc1d9e210ba8d68f8 FT_test_classes.1
#K= a15ec4843acd721fbdfddc0b512c8032 FT_test_classes.2
-#K= 2cee6842c9cdee5cb3bf50b2e3914813 FT_test_classes.3
+#K= 370a0539784b821ec745bd74379ce00b FT_test_classes.3
#K= 1489b3b72dbdfdb553cc0c6594c4face FT_classmap_inheritance.1
#K= e11c22649735cedb6c30321378100e11 FT_classmap_inheritance.2
#K= 5d0f3701517aa3a461c8887c332bdb42 FT_classmap_inheritance.3
--
2.56.0