From nobody Thu Apr 2 20:20:42 2026 Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.49]) (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 78F4841C2F5 for ; Thu, 26 Mar 2026 18:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774551314; cv=none; b=quCn2yUKmr88fgTGEGlxbu6ZEiq8FZJEYkK6+ky8cSjp77F5LB7UTP7YIWaY54QSvalHyDzmtwin6BkvzVKXSZSpUz5qCjyV669p2X3bG5HdH8DnEFhv7m1PMDgpXzt5IWOiRW5DPyUkjSP8RzxNKP8QDN4Y7AHMirWo/NqJ+Bw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774551314; c=relaxed/simple; bh=H+0xsGZIBwrkk/b4jBgR9GkrHr0yKiHAF3ASxvB/fw4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s4+ay52+ZmoZzga7GXMKJRXUjfSZHi0tk1uydXpUA2ZxmeZ0cfI9voq1qkNRFTRZA0JXF3VOGwxnLsULM+KshSloP9Pg69p3HubM3kYd77jl7exdQO9EpOUffiVI7rfOqOcb6xgMT2abm/GIB9uYLXEHziBe0Jb1fmQ+0c1LyDs= 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=gG2uVxa0; arc=none smtp.client-ip=209.85.160.49 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="gG2uVxa0" Received: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-40429b1d8baso540358fac.0 for ; Thu, 26 Mar 2026 11:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774551311; x=1775156111; 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=5920cM3w/QFHxSwN5yK5lUkglylj8O6aZoTa/l3EtaQ=; b=gG2uVxa0gRFhY49nne58BdbSZrmNkFxg6YBzuQcHGwJqUH0z2Mjwp4R2Kd8yj6r/8a hb7ESMysdtyaSLjMzjMfjMoghR4B+uoeLLrkCEFL2LDEsZoiO2qqA77jrpW8634FbcQD enFWhch6/+mJwqT9u8R8gEwNLUi1qNp6JB2jep1gqdjH+FQsuVVtYqXxuf4hlr5rKlUN L349gTQYyElMQ5XpCP4T9PpEc2wtdP+IONCv0eloWIjtjPDfHZXSMWEB9OoWUVfeNbuH JP4VEC08wz9vNhouT/FHMo2icJxXvrpPr6G6p9qi4BxMKivjsEV28VhITbDnoP/e1YBV g4SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774551311; x=1775156111; 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=5920cM3w/QFHxSwN5yK5lUkglylj8O6aZoTa/l3EtaQ=; b=Nj+qTZWKpeFnsX1k1mCM57zHydAceV96Lhi/W5vEWhIqCtMpmjn7FLgc6b64BFPcMV 6KxN4fHLgqJUT8IyE1r3fzFNHKkfANZJEMYfpX0/LCAoAWrqqSHjub8aePVxRxLTVWzf /kWeYiVtc1DKCPV0ElAzxRaoCfilq1Byk0C7fV9c/t3hj/IaBSTti03kNVR2tOiYY6OV jXX1aV5HHwEGIF6dBk9YYdkVcEixgEnCZ0YPrrO3Zybrm0tUInhq7g7wC2MNJxOo76sq vgCVQ31cY5cU/Gdcz7h3mxOzSn+tsYIzPszIcHPT6hi/unzG3YkTc9XD3PHHdIDhDztI 9lWQ== X-Gm-Message-State: AOJu0YyBUDyZ3hG/5IDjSO/aROZ7uf5HsFkB1B7FPDMray7pDgbktYAj iq63+w5SVR3crbLlhq6tPCk+POAxq5U4kc5VFtLcW/mlcYhD5INO/ArCk2t7Xw== X-Gm-Gg: ATEYQzzRXl4IjGzB9gJJQr/YkmSlLB/34FPORihadSeGGWyA7PagJSIaWPHeCZRmsbJ YyVPQ+BCOnZ055jTe+4HexEbZReYRb1UT8WlxGMCFGA+30u3e+gH38SXxT6qeKEngOL9VDOCegv PCPbtC7f5owOaz0QxYdzop4oraS+R10aKeIsykNIuiBP1EcGHJPCPkUIHssos88vru3RfUlakRC azm/vhrDfWFB9nUsvM+Tmht/U+2uzfoxcRtEOvIwfhqNmllaT9uXg/0/6zhKcLfHtS8UXriAQAh O0/jlPxTo/h5n3LosL1QPp5JHlufdyErHEbDRR6zpecczDvwPK1qxeUfZSL7vg44ryzqdw3LnsL 1KueVvkpo1c8T3Eew4gaqvYVtZa/sBat6EA4Xky/1H4cet891LekfloXizAhPwskbv98iOky1au vyrE7ISxl2Yt7g2f2nL1Na6PcRurSE/rr0qWi9UL1lzyizy3jOBIRnkuE+LCs= X-Received: by 2002:a05:6870:8a21:b0:41c:976:374e with SMTP id 586e51a60fabf-41ca6fdc8e9mr4813996fac.30.1774551311110; Thu, 26 Mar 2026 11:55:11 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 11:55:10 -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 27/69] dyndbg: check DYNAMIC_DEBUG_CLASSMAP_DEFINE args at compile-time Date: Thu, 26 Mar 2026 12:53:31 -0600 Message-ID: <20260326185413.1205870-28-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" Add __DYNAMIC_DEBUG_CLASSMAP_CHECK to implement the following arg-checks at compile-time: 0 <=3D _base < 63 class_names is not empty class_names[0] is a string (class_names.length + _base) < 63 dd-map-type is known value These compile-time checks will prevent several simple misuses, and will issue obvious errors if violated. 4 such examples are added to test_dynamic_debug_submod.ko, and will fail compilation if -DDD_MACRO_ARGCHECK is added to cflags. This wouldn't be a useful CONFIG_ item, since it breaks the build. Signed-off-by: Jim Cromie --- -v12 check map-type at compile-time make base+len(classnames) check more explicit dyndbg-test: add more tests of compile-time CHECKs add 3 tests of static-asserts added to 2 macros: DYNAMIC_DEBUG_CLASSMAP_{DEFINE,USE_} _DEFINE(): 1- validates maptype, 2- validate classmap.length + base-offset < 63 _USE_(): 3- validate user-offset < 63 As before, these tests fail when activated: make KCPPFLAGS=3D"-DDD_MACRO_ARGCHECK" lib/test_dynamic_debug_submod.o NOTE: _USE_() cannot test classmap.length, since its a property of the referent, not the macro itself. --- include/linux/dynamic_debug.h | 12 ++++++++++++ lib/test_dynamic_debug.c | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h index 71c91bc8d3a6..a1c75237abaa 100644 --- a/include/linux/dynamic_debug.h +++ b/include/linux/dynamic_debug.h @@ -181,6 +181,17 @@ struct _ddebug_class_param { * __pr_debug_cls(22, "no such class"); compiles but is not reachable */ =20 +#define __DYNAMIC_DEBUG_CLASSMAP_CHECK(_clnames, _base, _mapty) \ + static_assert(((_base) >=3D 0 && (_base) < _DPRINTK_CLASS_DFLT), \ + "_base must be in 0..62"); \ + static_assert(ARRAY_SIZE(_clnames) > 0, \ + "classnames array size must be > 0"); \ + static_assert((ARRAY_SIZE(_clnames) + (_base)) < _DPRINTK_CLASS_DFLT, \ + "_base + classnames.length must be <=3D 62"); \ + static_assert(((_mapty) >=3D DD_CLASS_TYPE_DISJOINT_BITS) && \ + ((_mapty) <=3D DD_CLASS_TYPE_LEVEL_NUM), \ + "unknown class_map_type") + /** * DYNAMIC_DEBUG_CLASSMAP_DEFINE - define debug classes used by a module. * @_var: name of the classmap, exported for other modules coordinated u= se. @@ -194,6 +205,7 @@ struct _ddebug_class_param { */ #define DYNAMIC_DEBUG_CLASSMAP_DEFINE(_var, _mapty, _base, ...) \ static const char *_var##_classnames[] =3D { __VA_ARGS__ }; \ + __DYNAMIC_DEBUG_CLASSMAP_CHECK(_var##_classnames, (_base), (_mapty)); \ extern struct _ddebug_class_map _var; \ struct _ddebug_class_map __aligned(8) __used \ __section("__dyndbg_class_maps") _var =3D { \ diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c index fc599bbe605e..5036fd58d7c6 100644 --- a/lib/test_dynamic_debug.c +++ b/lib/test_dynamic_debug.c @@ -146,8 +146,22 @@ DYNAMIC_DEBUG_CLASSMAP_DEFINE(classid_range_conflict, = 0, D2_CORE + 1, "D3_CORE") DYNAMIC_DEBUG_CLASSMAP_USE(map_disjoint_bits); DYNAMIC_DEBUG_CLASSMAP_USE(map_level_num); =20 +#if defined(DD_MACRO_ARGCHECK) +/* + * Exersize compile-time arg-checks in DYNAMIC_DEBUG_CLASSMAP_DEFINE. + * These will break compilation. + */ +DYNAMIC_DEBUG_CLASSMAP_DEFINE(fail_base_neg, 0, -1, "NEGATIVE_BASE_ARG"); +DYNAMIC_DEBUG_CLASSMAP_DEFINE(fail_base_big, 0, 100, "TOOBIG_BASE_ARG"); +DYNAMIC_DEBUG_CLASSMAP_DEFINE(fail_str_type, 0, 0, 1 /* not a string */); +DYNAMIC_DEBUG_CLASSMAP_DEFINE(fail_emptyclass, 0, 0 /* ,empty */); +DYNAMIC_DEBUG_CLASSMAP_DEFINE(fail_maptype, 3, 10, "no such type"); +DYNAMIC_DEBUG_CLASSMAP_DEFINE(fail_base_len, 0, 60, "one", "two", "three"); +DYNAMIC_DEBUG_CLASSMAP_USE_(map_level_num, 100); #endif =20 +#endif /* TEST_DYNAMIC_DEBUG_SUBMOD */ + /* stand-in for all pr_debug etc */ #define prdbg(SYM) __pr_debug_cls(SYM, #SYM " msg\n") =20 --=20 2.53.0