From nobody Thu Apr 2 20:20:45 2026 Received: from mail-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BE703A75A5 for ; Thu, 26 Mar 2026 18:55:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774551312; cv=none; b=dvmn/+qyx4fxqLumUWoZSq1XYTNbefB/EACAMT6zbA+A/RbIMCUFQVvrjOpwcLsCy90XZStS9miiL3gyqbPjxA+KS06ud54ydKsIqLoju9si/rrEA8Os2OZdOVnnLEGknEBOFbMjiP0I6xz8stYW0XTsf3Ssz1zi5e6upBK65+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774551312; c=relaxed/simple; bh=Zzx4Sn733ZM1tO7JuXAJ/z8qin9BcfpX6BljoYIv/Xw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XNvi4ZXZk8B/H6FB1ZeamkJQPXbmOyt6PIzafqr/JQqNgoBbBXy1s5p0KS/7qNC0r9wRd3ZflwO15qI3bQo+rp7TJO2b9IAcUiLsYhwPp0OdvilWyuzNxLQ8UWyIdWAr6JJjRPi9eKqB5wxC1IO9PCxeNxzWe8z4gJz5dSaJ5ZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lnkFy6XV; arc=none smtp.client-ip=209.85.160.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lnkFy6XV" Received: by mail-oa1-f53.google.com with SMTP id 586e51a60fabf-4043b27ddeaso852458fac.1 for ; Thu, 26 Mar 2026 11:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774551309; x=1775156109; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fhkUA1UVesD8yNrP4RsQIbF+Lt6WpQrbgggJ/VjIv9U=; b=lnkFy6XVQ2rHyvNlUuYWxY7R91dsb7KGw4blA3bvwhyXtvpmvqVfk25gATjjTsefx9 vB/TX7/OJFMzseMwqm13q2/iN51WRpsXoP47juSbr9ixaMu2mzXUwWgloUInn2lcIz/x bpZlYzPOcme2705NLyLT6K03u7rgBD6SpPt9droJWzaWWFXuT0E5uSNmIF+4sbH2A9qj LiWdql+CQwmP4u8dxTGNgAiSh7UqU2NTbn7qqhOT1NAfjpo9g5bDH1QsAO886MSh1rqG Ce6FuPHD/IRMw6BI/S8o5ZL7j2K31UhpLLfvT6+MuFF7TnlIPYeepgzJqA2DkfDf/DLH yJPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774551309; x=1775156109; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=fhkUA1UVesD8yNrP4RsQIbF+Lt6WpQrbgggJ/VjIv9U=; b=kwIwdgKumArMgmBQqMpKcCR39PX7UxCgiwVhO3PeEXg4iMMpFWPAe8405NyqCw6s3N TzXIoM/VUrAbQCDM9oD7EH9bU7XSasqV6JX2j7UGK5AshoGkn4UU6CJu9NyNHNYFBfUG fqFbm3vPsvvrKw0UfvE6PSVzlG7v72PCEPYeJl8W7mrXp7a7eYrxa3fOkKlfF7DjEECN zRfNhXiUj22jFveBP5ujatBKEzyDOVqUAAG15xLyIXDtsus2sANrAlnfLCcInQhbqVGl 1g0+G2uPbneXmUzHwZ8fr39m+PLOVws4DRRlsCrrmIgHShQ+e/S1y6npqLLjageFYT4Y PyGg== X-Gm-Message-State: AOJu0YwuXMeJ6w9umbPIuNp/PCiVyX2FTgLM+Z+iTURZ16AZe08wgTAe 4IDLm4WnWBBClI4u2PB1t4IvkaMllOzPfS97IRJIK/Gqwiw1NtwN5VK3jPKLLg== X-Gm-Gg: ATEYQzyhV5GKrKWuLiZr6ZVpLIenqwsNtx6Xyoeqtjs+FY/tSGdE1eihK2luoBs6LuW heA6h9m1XLx4Z75K55A2K+yG2AC76fxTxzxDvcBHpi/sChgNN8JMfY9Kj6ggCNCweVJOE2dAPYt ArGaPHwSEZD7jNi8UqQ2m2YbPpEU4d3el6S/QSwaJrm8Iwe2BTsLgy6idKl0ggtT2N60kkuynQp MR/Pg1U2nLvj+CrvaM0ApvVE6KNwHyAiZIQg+IpE1UDbXTfuGbm4H+x15pTT4VXOdeIPWKkYajB 4wo8BPwVGdddKmjHA4t1YMpJ1AV4iQi5at9WRJCfiYm5+LJkE3NLnMuZzZcOhqbLPJPwelIG4CT hARm2Qz31dBVbHEn5qjP/F4ZlC4aRBYr7ztlzrzHKCHZB9CrycTuKDQmTsQCsWPtIt+N4v/q0xB wc0rlZTKBtC4GJfTXAAdV9cFBKoWq20vbXtvGe6pC1vhimdCED X-Received: by 2002:a05:6871:820d:b0:404:1250:1c1f with SMTP id 586e51a60fabf-41ca6d160c2mr4341523fac.5.1774551309361; Thu, 26 Mar 2026 11:55:09 -0700 (PDT) Received: from frodo (c-98-38-17-99.hsd1.co.comcast.net. [98.38.17.99]) by smtp.googlemail.com with ESMTPSA id 586e51a60fabf-41cc7760c08sm3075171fac.4.2026.03.26.11.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 11:55:08 -0700 (PDT) From: Jim Cromie To: linux-kernel@vger.kernel.org, airlied@gmail.com, simona@ffwll.ch, jbaron@akamai.com, gregkh@linuxfoundation.org Cc: jim.cromie@gmail.com, mripard@kernel.org, tzimmermann@suse.de, maarten.lankhorst@linux.intel.com, jani.nikula@intel.com, ville.syrjala@linux.intel.com, christian.koenig@amd.com, matthew.auld@intel.com, arunpravin.paneerselvam@amd.com, louis.chauvet@bootlin.com, skhan@linuxfoundation.org, pmladek@suse.com, ukaszb@chromium.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [PATCH v12 26/69] dyndbg: detect class_id reservation conflicts Date: Thu, 26 Mar 2026 12:53:30 -0600 Message-ID: <20260326185413.1205870-27-jim.cromie@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260326185413.1205870-1-jim.cromie@gmail.com> References: <20260326185413.1205870-1-jim.cromie@gmail.com> 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" If a module _DEFINEs 2 or more classmaps, it must devise them to share the per-module 0..62 class-id space; ie their respective base,+length reservations cannot overlap. To detect conflicts at modprobe, add ddebug_class_range_overlap(), call it from ddebug_add_module(), and WARN and return -EINVAL when they're detected. This insures that class_id -> classname lookup has just 1 answer, so the 1st-found search in find-class-name works properly. test_dynamic_debug.c: If built with -DFORCE_CLASSID_CONFLICT, the test-modules invoke 2 conflicting DYNAMIC_DEBUG_CLASSMAP_DEFINE() declarations, into parent and the _submod. These conflict with one of the good ones in the parent (D2_CORE..etc), causing the modprobe(s) to WARN and fail. Reviewed-by: Louis Chauvet Signed-off-by: Jim Cromie --- v9 - fix WARN() by adding new 1st arg 1. v12 - drop maybe_unused on range-overlap fn --- lib/dynamic_debug.c | 25 +++++++++++++++++++------ lib/test_dynamic_debug.c | 8 ++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index ce512efaeffd..a7f67ecbc4d7 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -1085,12 +1085,17 @@ static void *ddebug_proc_next(struct seq_file *m, v= oid *p, loff_t *pos) return dp; } =20 -static bool ddebug_class_in_range(const int class_id, const struct _ddebug= _class_map *map) +static bool ddebug_class_map_in_range(const int class_id, const struct _dd= ebug_class_map *map) { return (class_id >=3D map->base && class_id < map->base + map->length); } =20 +static bool ddebug_class_user_in_range(const int class_id, const struct _d= debug_class_user *user) +{ + return ddebug_class_map_in_range(class_id - user->offset, user->map); +} + static const char *ddebug_class_name(struct _ddebug_info *di, struct _ddeb= ug *dp) { struct _ddebug_class_map *map; @@ -1098,11 +1103,11 @@ static const char *ddebug_class_name(struct _ddebug= _info *di, struct _ddebug *dp int i; =20 for_subvec(i, map, di, maps) - if (ddebug_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]; =20 for_subvec(i, cli, di, users) - if (ddebug_class_in_range(dp->class_id, cli->map)) + if (ddebug_class_user_in_range(dp->class_id, cli)) return cli->map->class_names[dp->class_id - cli->map->base - cli->offse= t]; =20 return NULL; @@ -1295,9 +1300,7 @@ static void ddebug_apply_class_users(const struct _dd= ebug_info *di) __di->_vec.len =3D __nc; \ }) =20 -static int __maybe_unused -ddebug_class_range_overlap(struct _ddebug_class_map *cm, - u64 *reserved_ids) +static int ddebug_class_range_overlap(struct _ddebug_class_map *cm, u64 *r= eserved_ids) { u64 range =3D (((1ULL << cm->length) - 1) << cm->base); =20 @@ -1320,6 +1323,7 @@ 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 =3D 0; int i; =20 if (!di->descs.len) @@ -1344,6 +1348,11 @@ static int ddebug_add_module(struct _ddebug_info *di) dd_set_module_subrange(i, cli, &dt->info, users); /* now di is stale */ =20 + /* 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; + mutex_lock(&ddebug_lock); list_add_tail(&dt->link, &ddebug_tables); mutex_unlock(&ddebug_lock); @@ -1356,6 +1365,10 @@ static int ddebug_add_module(struct _ddebug_info *di) vpr_info("%3u debug prints in module %s\n", dt->info.descs.len, dt->info.mod_name); return 0; +cleanup: + WARN_ONCE(1, "dyndbg multi-classmap conflict in %s\n", di->mod_name); + kfree(dt); + return -EINVAL; } =20 /* helper for ddebug_dyndbg_(boot|module)_param_cb */ diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c index 6c4548f63512..fc599bbe605e 100644 --- a/lib/test_dynamic_debug.c +++ b/lib/test_dynamic_debug.c @@ -128,6 +128,14 @@ DYNAMIC_DEBUG_CLASSMAP_DEFINE(map_level_num, DD_CLASS_= TYPE_LEVEL_NUM, DYNAMIC_DEBUG_CLASSMAP_PARAM(disjoint_bits, p); DYNAMIC_DEBUG_CLASSMAP_PARAM(level_num, p); =20 +#ifdef FORCE_CLASSID_CONFLICT +/* + * Enable with -Dflag on compile to test overlapping class-id range + * detection. This should warn on modprobes. + */ +DYNAMIC_DEBUG_CLASSMAP_DEFINE(classid_range_conflict, 0, D2_CORE + 1, "D3_= CORE"); +#endif + #else /* TEST_DYNAMIC_DEBUG_SUBMOD */ =20 /* --=20 2.53.0