From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9979FE674B2 for ; Mon, 22 Dec 2025 14:00:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 37BF110E68E; Mon, 22 Dec 2025 14:00:08 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Mzs2Cly6"; dkim-atps=neutral Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id 251E110E5DE for ; Mon, 22 Dec 2025 08:28:18 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id d2e1a72fcca58-7d26a7e5639so4236160b3a.1 for ; Mon, 22 Dec 2025 00:28:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766392098; x=1766996898; darn=lists.freedesktop.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=8P0CFiKDyHYpNA2hwruS1Ng/YcTesu5+S1IYSukvEWU=; b=Mzs2Cly62l0Hxlp/nqXqOaiweX+DteRDw9bMzHvDR4gq5PiJyDwtK6DExR2c55COVl Fync1WNS0Jq+mQR6cCt1nCf6g1m8H9a+8UxhqKpA7ReRrud2SKfmixtXsE5MGwwcCxvt UD0xd/5Mz353p6OjUZ2XruQXhSKubCtqRNpSXvzXfLcWWV/RvnURUtw+H4RpEbKvOAs2 oAPx30vIY0roIjtMOB0UkLj3SaeYwThwHirUGkH8kv2sRoLRn7PzpBJ9UWdzI6WT+SiY 9CcoD6+XQAkyotpMktBDrdGA4Wb3oEfwnsKkbQldeaYalk5QCES4lLacVLQi5AZdiY2n 1uaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766392098; x=1766996898; 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=8P0CFiKDyHYpNA2hwruS1Ng/YcTesu5+S1IYSukvEWU=; b=JTfTLr4SK5bpWzeHDdB5vTg43oaNnSlK1kpRkMscXDm8aW1S2JtHrn0GsQ2gg98qYT L1vdAWL7rGJCN9lGXGy2A9N9UiheLwl+5VcJZv32o5GNXuXeIVefqpv+dUsyepVdn3UH 1ETqc2VktWzAdrl0PDjKi71vhI0aLbXUdZtxC8nrAxcDfp2/zn45IQUej4dPIUx70Fsw 3kVi1BJF0iwSOQGVaSoHlImojLfkIFTRwU55KagQyD72Y10eRSoC6xkOyMHnrLUuWIVC ls1Wb2MpEQfizNgpseOl/QhHqioi3yo+zvlcm/cjtHmdrgPeE3RI2++2QBFM37wgwAxa 9f+g== X-Forwarded-Encrypted: i=1; AJvYcCXbnWUbcUB3NSr8lu+a2e4y96te9JZMLg2+2rWRU1nO8261qb05ZHjMLXJ8IURfx45ysepl82xKBgQ=@lists.freedesktop.org X-Gm-Message-State: AOJu0YzOPOm5WrczSdUEQnDYwIai5NAFv3iTGSNbysHOw5znMaQNx18L yp+w25cz5ds+wEicX5y9alTqHxpJ0mxTziYVzJZKXuj/NY8SbhbCf/IT X-Gm-Gg: AY/fxX4R+Fjph7QoLnlBLO3Oqj28tWI08dNJr2DNwcsQTEhZY8bYGYunPK1OkRcaexE 1u4kMkq0h1K2Y+ZrQRjqRRKRAl28uYi/N79qTDfgQMIICtsKNv2GBGjbPa9WRUw3HHp0VEywJFY 4LqdnEi+gAwTMUTrK5tF2uZN42h4vf19hKNuSD80gaz35ElvN2k2gvEpGc8hHnWauXlzHbVlx2m L6kvjWa+Q+Fq3Or8GAdRnSjESVmRLuEUB01oH9utq3WKRV6Oc9sd5D5lYA7MCXvP4KQqVF9zvdz FIBy9aka+75/NjOghNTnHOTS8vzCvWE5gBCzW0Upmvabq90CEkjqBZzjPcNtM+kp8J/EcHTn3xc Z502tiimjKHvF7U9ToglDV/BQgcBG3BQRKuQbI9yyj4wG3IIJUlkfVvSzXLj80Ew0FJmRXiLBUu JEdfwcYFAV X-Google-Smtp-Source: AGHT+IEq8X6Bf+OWPyqj+l6muxtsExzlcI9be65S5oPokexgEe5xk3Q6PIlmP0iqLo1vmkdJvgYYyA== X-Received: by 2002:a05:6a00:a386:b0:7aa:17f0:f63c with SMTP id d2e1a72fcca58-7ff64eca463mr9195347b3a.29.1766392097555; Mon, 22 Dec 2025 00:28:17 -0800 (PST) Received: from frodo ([2404:4400:417e:3d00:8b90:7f55:1261:772f]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-7ff7e493123sm9540699b3a.50.2025.12.22.00.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Dec 2025 00:28:17 -0800 (PST) From: Jim Cromie To: linux-kernel@vger.kernel.org, jbaron@akamai.com, gregkh@linuxfoundation.org, ukaszb@chromium.org, louis.chauvet@bootlin.com Cc: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, daniel.vetter@ffwll.ch, tvrtko.ursulin@linux.intel.com, jani.nikula@intel.com, ville.syrjala@linux.intel.com, seanpaul@chromium.org, robdclark@gmail.com, groeck@google.com, yanivt@google.com, bleung@google.com, quic_saipraka@quicinc.com, will@kernel.org, catalin.marinas@arm.com, quic_psodagud@quicinc.com, maz@kernel.org, arnd@arndb.de, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, mingo@redhat.com, jim.cromie@gmail.com Subject: [PATCH v7 30/31] dyndbg: add DYNAMIC_DEBUG_CLASSMAP_USE_(dd_class_name, offset) Date: Mon, 22 Dec 2025 21:20:47 +1300 Message-ID: <20251222082049.1782440-31-jim.cromie@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251222082049.1782440-3-jim.cromie@gmail.com> References: <20251222082049.1782440-3-jim.cromie@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 22 Dec 2025 14:00:06 +0000 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 --- 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 */ }; /* @@ -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_user)) + +#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 = { \ .mod_name = KBUILD_MODNAME, \ .map = &(_var), \ - .base = _base \ + .offset = _offset \ } /** diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index f60a723a441b..b0da3dd4ac44 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 >= 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->offset; return cli->map; } } @@ -206,12 +206,17 @@ ddebug_find_valid_class(struct _ddebug_info const *di, const char *query_class, return NULL; } -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 _ddebug_class_map *map) { return (class_id >= map->base && class_id < map->base + map->length); } +static bool ddebug_class_user_in_range(const int class_id, const struct _ddebug_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; 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; 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; return NULL; @@ -1177,12 +1182,12 @@ static const char *ddebug_class_name(struct _ddebug_info *di, struct _ddebug *dp int i; 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]; 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->offset]; return NULL; } -- 2.52.0