From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) (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 7F326331232 for ; Mon, 22 Dec 2025 08:28:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766392100; cv=none; b=ZbMSIXCMK+qp99mOhac+sMiEzE3s/rKfoZu4mO3nTpJaFHBaMzVTc2R/oT+LphOkKukNip37XMw+JOL6JcohMvE6VsX5psmJwHHSG0n+X7RRzRwMFS0R9N+ja//b/H9D8ZVHe+rhiS7nJYvYLJv6B2zJ9MkfAlPvKtLsmsiL2ww= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766392100; c=relaxed/simple; bh=v7EQfK3CYeK6tip0DHETnwNdDCpTZ1+hTqxgdsKnjQs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=khHCdLbdl6Y1HFcPhHEj12zPN21PL0pcSLP7VQE4gfr2XsWp7NjBGSfmmD6IAU20A4sZNu9Z6VIvrTQYkVevqJxQn9sd/GMt2ZYNRYH5Y4reROkVhejR5yPuvy9LPKXyi6NabTgH0S9jAM4d6WV/rNPsUqw8//3IFezKhanABrA= 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=VZMmdrLh; arc=none smtp.client-ip=209.85.210.194 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="VZMmdrLh" Received: by mail-pf1-f194.google.com with SMTP id d2e1a72fcca58-7aae5f2633dso3694596b3a.3 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=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=8P0CFiKDyHYpNA2hwruS1Ng/YcTesu5+S1IYSukvEWU=; b=VZMmdrLh49LS9xhxzwHyTOiSgMcERcGZLyp5m3OigRk0TTqboX8vZjBJJaE9tsOZLo JIRB7IxCZKKIi47jW5kr5ZBBo01kUaf2yrFxeT8c29FzKGUQurIeYUuyXJp1TuMlYpOR 2+YvXp/MhwiHn9YAmJNh4IsYi3gzmrJQnBv9LTi6VCIAJfnAYJV08P/197025SO33Rix n1dzQI1pyXk/TMWpMS9g2DaAbUnKukqRf5vpFIrvO9pyDoBDyxOLXS88jSEkiKfavk0m vrlIgGggaW4eFeFaI7wP8fqe9VE2u1C9NGcefgaxW4UQ+1Gwy13C6gsafyyu2s6ubmJd ZnbA== 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=Op3k8ksFMhxl/9jHC8z+OftPn/0jOW7wynJkxS9n6gDvg/yEZ0c+ZrT9Tw1CfdNEbr UssDGNpcYtTkyq5mKyC+/EymLicJ71TqOGCXTIfzKvYcwb/Anz098PxWMRUkXhJRUOH8 wUKcdEYEo08pwRQGiWy6UBExLhMmidR2X2YCSSw7UxdBI6FrwlBxrP95BKV8JIIsGwp8 uahOnrvunW2MX44LyDWGE6mabUHGOoLb4xabnWn4fbT5Kr7PJGlwxWXVODXCDiQGVA+/ d7/6rs2mXbsm1brQSniyXGK4mVbo2PtIJm5H4Efn5Yga4Y3EFO2ll8SMeRIWOPzrXDjf 3tDw== X-Gm-Message-State: AOJu0Yx7RIiy5L/e9JmqHS+VX9XpkouR0J+Hq4bXv+0/pC/YagwpMsQf f5MS1+XrfJLS6ALEpZbiyjB8bqrbs2CiuFLdhsM1Bum5vaEikZfq8vHaMX4F/kAPOA4O4w== X-Gm-Gg: AY/fxX4DGc4zrsJz2BbNzzKsDcoKxnLquMx1mkRvR7pbGR3o2cn7NtbjAtnonhZ0ef4 hqZy74yeSS5yZ654D32aIM069WgMc708ZSDOItj1Mp5hptu4HromCCyPeSQnmSgqignujRX1aMW oTeQOOsTMg/zH19pzc9HRK2UO7899GYtBb/s3vtr5BMdkgFDYZ4f8qejlUVXllOeBPjo/7fYrb1 MaBYtbgxirsNt4rydYg8w4uHmA1FFygE8UXRQdFnHd7WQzi91JS1H8ecI5Pez02QYmzD99XyWhP fULgfEs5SOV5AqKqV+ps/ye7vINlp/krAa76Zca/AI5RxIjIL5PjU2shRqOug5gy/bPjzfqntW2 7e3S48yWFooLA+SXs9E60ICfKtAVkBZtfSb3bgOUluAzsbAqXWWxVDK9KAoR2yi0MjL1ZYHY79B A9Xc3Pf+ss 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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