From nobody Tue Dec 2 02:41:48 2025 Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) (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 6F2353A5E80 for ; Tue, 18 Nov 2025 20:19:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763497180; cv=none; b=r+kjlsRj2aoO1/Uird4GWc+wY8ch5nKtffat0KYqz+d7VZTEBqHjEsln8JTL4B8aoXURAcPvlCNmrfn+JrzkDVifJbeUgGCl202TAdmcSS2bdskHyKHc0l2Q0grz7+t//0urCbgfgdOeLRMiwehaZy6xK5KsZlzxCexsXhrZwuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763497180; c=relaxed/simple; bh=vxiSdOuWHjMkhFL7/D/79Vvo3vOXK3Mpgsiu+raXiNY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NTssAi2CYo9cShmo6Q7NUmiNV+Ev55cCReihaDexHTIra0qm9ujqfRau7VqW1c64W9u2PrC4TB4BRBXa+yvK0JO/vGTOvDxk85sTpz5kCgk43gO5TGHO1eFd6IJm7+KvraLjSqZQv78XuudUlqoaCyQKYTn9FVyAXQgPYFWfrKs= 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=Z2QnSOJU; arc=none smtp.client-ip=209.85.166.179 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="Z2QnSOJU" Received: by mail-il1-f179.google.com with SMTP id e9e14a558f8ab-433692bbe4fso26137445ab.0 for ; Tue, 18 Nov 2025 12:19:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763497174; x=1764101974; 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=Pzl7FKRTTqXJnEcqZYC3kmINB8k+XvKVj8HTxhUS64o=; b=Z2QnSOJUJmRHMAkOCrv0F5w4AaIeACW2Rt//Dide7dW4RvqY9WWrZJEw3xBnY9p03P LjCkwjgbLOrrpUTmiytDe78RhqcmleMORjCuDoNWpDlEEFIn5X4LU0eN2UZvzDbv7DPB CLLAO1sMYUuu67ZYgUSj1IFwAO1SNY9+90zT6bJUcSmjSdGUpdBR11SAZnxwSJKRundt 3A3te8ZCvxC/h8L7jiN59hR1vMzGEVp4+7S+3a051b6PaAYVGWYbQtIVfQZNq8ptqaWL 9OZdxl7+HKnKipNGAXEDspDZ9wDhjj1rUG+8vDxOKxkG7Ly+Y0vn3D2BqK4zeJKy1mGV sPbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763497174; x=1764101974; 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=Pzl7FKRTTqXJnEcqZYC3kmINB8k+XvKVj8HTxhUS64o=; b=RXr0SOYkx1CZtPRB+uzfTK6xgtKrb4Yzl9UHAkItDGuOFXCvjW3rQf+upmFvW0tvP4 hJgpX4h7IdSfjn9Zx+TuKV6EmlGnyRAXyqhNGD9OHv2nMMxlAfuwWounFhDDKRoupASN 20rGS41zJf9uMe4CK3sT3CqYmljVy6kjAtu/oH2WUjypp1cXPH/C5jv89j5NGAbolVIm m2nOAmdFKA9WWxDHLGjKT2mz2Ht6Yso87LYbWEDNbfHyFodBpbUPgVQw1OdAiW1OImZg cwlJh0Vfnj5guq+5jcZY5NDvVVcA0KjLU9kgiuCYTOALmDWdPA4XfRPuheEPecHq9MCm sfUg== X-Gm-Message-State: AOJu0YwbjYNzvB36j2oJM1rXKjZ0+51d8t8ZEMSVEZhLyAi2N2RzYg3z btKRIrWer4W3dPp5xadKxSpW26VV+Q9yl4Tr5BknTyMeBrS62sIDjci9m7/ONMI8 X-Gm-Gg: ASbGncvWeuZp3cxptvmQXetc3FKjvTWH5XRo1MJps57pk66XtxNEPga9k6xHYZvtOhx xhU8DxGeRHAW6UOmxIND/HAxNUHP1mXw3fYukWVrBlQfFlbrla3BPHiEpzeorSn2Vwegg9ziYbO 7+XJ/DZzlSBTtNoWGwMvYT5TWEJLXcB5b2HQddJw0AXpT9mkOHMsCfWdB32Q7nPwgw4aQ+GleWE RJG3AkrFlg2Yhpqcm9pyAy8tOTvgqxzs2C2RikN6Rbk2N75S82uyZbRrHj7OSqlOllYYPrvdpgP Jdf4JLm8SeVOu6jctddjmCHSFNoDyY+Qy+rSuYOUnU0q8kUCCiBZocvNpD+luWP6bbIk/hqquy2 /3A8KZNYjaIWrHowFWIF6jUc69xyCYPhbiacT6Woxn8STspkSFmet/HIOlYhtaWvet49KNUxOFf SkuLkHUNcF3TD6jzovfkjbR3mTO43QZXgVnByxhpVTsPWplNVtB8G0eg2v1Nd2tLqFR+M= X-Google-Smtp-Source: AGHT+IHrOtzMdyakNuObdh3/HwiaoIGSX4ghGN1icypqK5mgUjKfASizUVusxgNRAZI5rl5+uPN7mA== X-Received: by 2002:a05:6e02:1527:b0:433:30e0:6f68 with SMTP id e9e14a558f8ab-4348c94e1bdmr189470205ab.24.1763497174345; Tue, 18 Nov 2025 12:19:34 -0800 (PST) Received: from godzilla.raven-morpho.ts.net (c-98-38-17-99.hsd1.co.comcast.net. [98.38.17.99]) by smtp.googlemail.com with ESMTPSA id ca18e2360f4ac-948fd4c273bsm419823939f.18.2025.11.18.12.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 12:19:33 -0800 (PST) From: Jim Cromie To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, gregkh@linuxfoundation.org, jbaron@akamai.com Cc: ukaszb@chromium.org, louis.chauvet@bootlin.com, Jim Cromie Subject: [PATCH v6 30/31] dyndbg: add DYNAMIC_DEBUG_CLASSMAP_USE_(dd_class_name, offset) Date: Tue, 18 Nov 2025 13:18:40 -0700 Message-ID: <20251118201842.1447666-31-jim.cromie@gmail.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251118201842.1447666-1-jim.cromie@gmail.com> References: <20251118201842.1447666-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" Allow a module to use 2 classmaps together that would otherwise have a class_id range conflict. Suppose drm-driver does: DYNAMIC_DEBUG_CLASSMAP_USE(drm_debug_classes); DYNAMIC_DEBUG_CLASSMAP_USE(drm_accel_xfer_debug); And (for some reason) drm-accel will not define their constants to avoid DRM's 0..10 reservations (seems a long stretch). So I dont think this potential conflict would become an issue until we have at least a 3-X-3 of classmap-defns X classmap-users So drop this if its too speculative, knowing theres at least a notional solution should the situation arise. Signed-off-by: Jim Cromie --- re-ref of an lvalue is fine. CHECK: Macro argument reuse '_var' - possible side-effects? -v5+ less hand-wavy --- include/linux/dynamic_debug.h | 30 +++++++++++++++++++++++------- lib/dynamic_debug.c | 19 ++++++++++++------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h index b22da40e2583..5307be8da5c1 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 offset; /* offset from map->base */ }; =20 /* @@ -235,21 +235,37 @@ 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. + * @_offset: 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 + * only 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, _offset) \ + __DYNAMIC_DEBUG_CLASSMAP_USE(_var, _offset, __UNIQUE_ID(_ddebug_class_use= r)) + +#define __DYNAMIC_DEBUG_CLASSMAP_USE(_var, _offset, _uname) \ extern struct _ddebug_class_map _var; \ static struct _ddebug_class_user __aligned(8) __used \ __section("__dyndbg_class_users") _uname =3D { \ .mod_name =3D KBUILD_MODNAME, \ .map =3D &(_var), \ - .base =3D _base \ + .offset =3D _offset \ } =20 /** diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 1082e0273f0e..bf1ff29cca95 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -198,7 +198,7 @@ ddebug_find_valid_class(struct _ddebug_info const *di, = const char *query_class, if (idx >=3D 0) { vpr_di_info(di, "class-ref: %s -> %s.%s ", cli->mod_name, cli->map->mod_name, query_class); - *class_id =3D idx + cli->map->base; + *class_id =3D idx + cli->map->base - cli->offset; return cli->map; } } @@ -206,12 +206,17 @@ ddebug_find_valid_class(struct _ddebug_info const *di= , const char *query_class, return NULL; } =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 struct _ddebug_class_map * ddebug_find_map_by_class_id(struct _ddebug_info *di, int class_id) { @@ -220,11 +225,11 @@ ddebug_find_map_by_class_id(struct _ddebug_info *di, = int class_id) int i; =20 for_subvec(i, map, di, maps) - if (ddebug_class_in_range(class_id, map)) + if (ddebug_class_map_in_range(class_id, map)) return map; =20 for_subvec(i, cli, di, users) - if (ddebug_class_in_range(class_id, cli->map)) + if (ddebug_class_user_in_range(class_id, cli)) return cli->map; =20 return NULL; @@ -1177,12 +1182,12 @@ 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)) - 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->offse= t]; =20 return NULL; } --=20 2.51.1