From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-il1-f176.google.com (mail-il1-f176.google.com [209.85.166.176]) (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 3BC07225766 for ; Sat, 25 Jan 2025 06:47:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737787668; cv=none; b=CuX5dwOBT4r01eZzRcYWKS6XEZtiqVq4XWFeqbPuphHqH0YpQv1e/P6PaCDsUOJT78aB9SSAbkk+NlR+bSBE64hqO6B/Q9kkeVvZQYJbWx5+nJzCyrlDcYc5H9GZn5ZHEx4q7iuwKmDdrqFcGbrjAqeY2lvwCHvcSJjhN002Yzk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737787668; c=relaxed/simple; bh=Ot0J76Q5usj6KabNAeB/dsUvje+eLsX+v5fdDEod8Oc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oYgDr64sU4OWPd/Z24W+CwDFzZQJussgTnVXbY9tWAQNHEDlWP+J6HP34qiXBT3BFLDqlm5Nlv+TmNEfK2XHdZj+LmWaukBoJRF4Vdy67WU391i4ggQQv+HTqCdMUhWayE+/ZinQb3FEktuKASdMtu4ZQW1A5VeGzGEySsrXNws= 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=dl7x8xXX; arc=none smtp.client-ip=209.85.166.176 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="dl7x8xXX" Received: by mail-il1-f176.google.com with SMTP id e9e14a558f8ab-3cfc79a8a95so4740075ab.2 for ; Fri, 24 Jan 2025 22:47:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737787665; x=1738392465; 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=T6GCuzeAmDEU4hGwplnvXwuVetfxA5yWhKc4RU1kN3E=; b=dl7x8xXX0+FLcJbxEa4Q+BHn8oho6zrJFNeSthMweyUWSZp0U23vb0RKED99Zh+RXh OzQJqTzvvd7YZqFp1vHX035VarfPp6Ix41edN5+J20TszPKAQeyHUUdQnOYLdrPVnKBG vrTp3GEbhI0XqugHlxRMQX3xbUz+/FxVsQhdsPGuVS2YyRTNEggLiisqo/DkYjbxiRJS NEsDOn9+0iXQeH6M5Hw/5mqNBBDfQuyyilXkc6DbZdir7BAHYS0npGbGAMA3WcsYt4fJ acC9PYKgftR/BsZ7YlXZk+DV3O+FFu4pvleH1x5XMlQCuDPh2vB53+ddj7z7QW/74WXq /Rbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737787665; x=1738392465; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T6GCuzeAmDEU4hGwplnvXwuVetfxA5yWhKc4RU1kN3E=; b=Dt1+N0ID1Xs1zSdKL/RLIViXwmuowugNblmryx4M2a+4rFsooAe9P8vWGJtmTAvGiO 6ahcHaqaiHnNJtOsZMx9LHEPwqR03J3YYrmIREpiBciLJVKdnsv//fyCzgtlGaXEWH3M PCEH20aC0Li8gEIIsHe5JBPx0Yb3R7KikAM4AqwSLF/mIJK3TESKPBMvkR7eUUzBxtxk 77i8oj17i7nnFXIiraqSTfqbPFFxaG0032LiaoaWTJvBf90+C9Co6f5r3bvHtFpqW0n/ h9x5ZYoG2pUhrxpA8mXZvKTppLD6PDX4n6RwLOD37sUQGhsXWhhAwqj4QEcvgVFELoA0 SmtQ== X-Gm-Message-State: AOJu0YzJ1KEHO7d7rd3CRy1cE8QMHBzxdatVaj+yVbQ/MjKKMvSd3Yyl O2KLi2T39/KqpQUUNRH1a0ZvtIHyuRndZs6upLwio31MtbLFAMOPt2xCLA== X-Gm-Gg: ASbGnctlN/ozzodNNpFDJCc+F3o/UnOmPrO9XvCm+Hyu7mr3ngFNZZINxXUAyJ2H7PB 6ReY+RRc2DIFdBuTWnSddkpT89tQEzsa9HP8RPFAjMUzK1FlZhwtV0wdo82/f0EuTh8JaEpZBCk Pwp/T0rMX+yJpTeoKHXcRB6cl6t7BC+NnNS+6Gn13S7c8nHvkfrhchiwm7qIxb6ivNhgJVokVFu lxMGldvJAtoGO0Pb/AKf0v/yG3l86FUGzuU1AH9M7DCIWh7UO6bdr9ZPSt72nYOkO9M1onOAWet v4vDlXD5TePxURNxyEN22T9um7OKwzaLm+u3wg== X-Google-Smtp-Source: AGHT+IEujLOtg9gkMTa7OzcouFF4HjwPZbpakCrytdnwwqxtjFJ2Exad5qI/+pzTRXAa2s9JlPkT4Q== X-Received: by 2002:a05:6602:48c:b0:834:d7b6:4fea with SMTP id ca18e2360f4ac-851b61f1347mr3241540439f.6.1737787665030; Fri, 24 Jan 2025 22:47:45 -0800 (PST) Received: from gandalf.. (c-67-165-245-5.hsd1.co.comcast.net. [67.165.245.5]) by smtp.googlemail.com with ESMTPSA id 8926c6da1cb9f-4ec1da476fesm1174144173.58.2025.01.24.22.47.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 22:47:44 -0800 (PST) From: Jim Cromie To: linux-kernel@vger.kernel.org, jbaron@akamai.com, gregkh@linuxfoundation.org, ukaszb@chromium.org Cc: intel-gfx-trybot@lists.freedesktop.org, 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, Jim Cromie Subject: [PATCH 64/64] This series fixes dyndbg (dynamic debug) classmap support for DRM. Date: Fri, 24 Jan 2025 23:46:18 -0700 Message-ID: <20250125064619.8305-65-jim.cromie@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250125064619.8305-1-jim.cromie@gmail.com> References: <20250125064619.8305-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: 8bit Despite a few latent flaws (1-3 below), classmaps-v1 went in with: ee7d633f2dfb drm-print.h: include dyndbg header 84ec67288c10 drm_print: wrap drm_*_dbg in dyndbg descriptor factory macro e820f52577b1 drm_print: interpose drm_*dbg with forwarding macros f158936b60a7 drm: POC drm on dyndbg - use in core, 2 helpers, 3 drivers. 0406faf25fb1 drm_print: condense enum drm_debug_category and 6ea3bf466ac6 dyndbg: test DECLARE_DYNDBG_CLASSMAP, sysfs nodes b9400852c080 dyndbg: add drm.debug style (drm/parameters/debug) bitmap support ace7c4bbb240 doc-dyndbg: edit dynamic-debug-howto for brevity, audience 753914ed85ac doc-dyndbg: describe "class CLASS_NAME" query support a4a2a427413e dyndbg: validate class FOO by checking with module c45f67ace832 dyndbg: add ddebug_attach_module_classes 66f4006b6ace kernel/module: add __dyndbg_classes section aad0214f3026 dyndbg: add DECLARE_DYNDBG_CLASSMAP macro 3fc95d80a536 dyndbg: add __pr_debug_cls for testing ca90fca7f7b5 dyndbg: add class_id to pr_debug callsites b7b4eebdba7b dyndbg: gather __dyndbg[] state into struct _ddebug_info Those flaws: 1. Regression during initialization. classmaps-v1 inits drm-dbg callsites' static-keys when drm is "modprobed/initd" with drm.debug=, but not during driver & helper modprobes. Previously __drm_debug vs DRM_UT_* was checked at runtime, which made this a non-issue. My test scripts passed dyndbg=, which obscured this lack of "propagation" to drivers, and I didn't pick up on it. 2. DECLARE_DYNDBG_CLASSMAP violated a K&R rule "define once, refer after", and is the root cause under 1. 3. classmaps-v1 was something of a flag-day patchset; dyndbg & DRM parts were overly coupled, and test-dyndbg didn't validate multi- module classes. Consequently we got: commit bb2ff6c27bc9 ("drm: Disable dynamic debug as broken") Classmaps-v2 fixes these as follows: 2. replace DECLARE_DYNDBG_CLASSMAP with DYNDBG_CLASSMAP_DEFINE (invoked once in drm-core) and DYNDBG_CLASSMAP_USE (repeatedly, in drivers & helpers). _DEFINE now exports the classmap, which _USE can repeatedly refer to. _USE adds a usage/linkage record referring to the _DEFINEd (& exported) classmap, in a new __dyndbg_class_users section. 1. Now at modprobe, dyndbg scans the new section, follows the linkage to the _DEFINEr module, finds the (optional) kernel-param controlling the classmap, examines its drm.debug=, and applies it to the module being initialized. 3. test/validate dyndbg for multi-module classes wo DRM involvement. A. add test_dynamic_debug_submod.ko, a clone of parent. This allows recapitulating various multi-module scenarios. B. add tools/testing/selftests/dynamic_debug/* This verifies spec'd behavior, including the multi-module scenarios made available in 3a. C. to decouple dyndbg from DRM, DECLARE_DYNDBG_CLASSMAP is preserved until after DRM adapts to the api change. Since the last rev sent here/LKML: https://lore.kernel.org/lkml/20240716185806.1572048-1-jim.cromie@gmail.com/ Ive rebased onto recent drm-tip, and tested with drm-trybot: https://patchwork.freedesktop.org/series/139147/ and made the following additions: 1- drop class "protection" special case, per JBaron's preference. current use is marked BROKEN so nobody to affect. now framed as policy-choice: #define ddebug_client_module_protects_classes false 2- compile-time arg-tests in DYNDBG_CLASSMAP_DEFINE implement several required constraints, fail obviously. 3- modprobe time check of conflicting class-id reservations only affects 2+classmaps users. compile-time solution not apparent. 4- dyndbg can now cause modprobe to fail. needed toq catch 3. maybe some loose ends here on failure. 5- refactor & rename ddebug_attach_*module_classes reduce repetetive boilerplate on 2 types: maps, users. rework mostly brought forward in patchset to reduce churn TBD: maybe squash more. The recent trybot submissions (against drm-tip) pass CI.BAT, and fail one or few CI.IGT tests randomly; re-tests do not repeat the failures. its also at github.com:jimc/linux.git commit c0f15eda9c3676149dedbc5a5fc0faee9550a2f7 (HEAD -> dd-fix-9s-ontip, ghlinux/dd-fix-9s-ontip) Im running it on my laptop & desktop w/o issues. The drivers/gpu/drm patches are RFC, I think there might be a place to put a single DRM_CLASSMAP_USE(drm_ddbug_classes) to replace the sprinkling of USEs in drivers and helpers. IIRC, I tried adding a _DEFINE into drm_drv.c, that didn't do it. I think the dyndbg core additions are ready for review and merging into a (next-next) test/integration tree, I'd like to find out. Jim Cromie (63): pre-cleanup: docs/dyndbg: update examples \012 to \n test-dyndbg: fixup CLASSMAP usage error dyndbg: reword "class unknown," to "class:_UNKNOWN_" dyndbg: make ddebug_class_param union members same size dyndbg: replace classmap list with a vector dyndbg: ddebug_apply_class_bitmap - add module arg, select on it dyndbg: split param_set_dyndbg_classes to _module & wrapper fns dyndbg: drop NUM_TYPE_ARRAY dyndbg: reduce verbose/debug clutter dyndbg: silence debugs with no-change updates dyndbg: tighten ddebug_class_name() 1st arg type dyndbg: tighten fn-sig of ddebug_apply_class_bitmap dyndbg: reduce verbose=3 messages in ddebug_add_module dyndbg-API: remove DD_CLASS_TYPE_(DISJOINT|LEVEL)_NAMES and code checkpatch: add an exception to the do-while wrapper advice core change: dyndbg-API: replace DECLARE_DYNDBG_CLASSMAP dyndbg: check DYNDBG_CLASSMAP_DEFINE args at compile-time dyndbg: add/use for_subvec() to reduce boilerplate dyndbg: make proper substructs in _ddebug_info dyndbg: drop premature optimization in ddebug_add_module dyndbg: allow ddebug_add_module to fail dyndbg: rework ddebug_attach_*module_classes() dyndbg: fail modprobe on ddebug_class_range_overlap() dyndbg: hoist the range-overlap checks ddebug: cleanup-range-overlap fails dyndbg-test: change do_prints testpoint to accept a loopct selftests-dyndbg: add tools/testing/selftests/dynamic_debug/* dyndbg-API: promote DYNDBG_CLASSMAP_PARAM to API dyndbg-doc: add classmap info to howto new features: dyndbg: treat comma as a token separator selftests-dyndbg: add comma_terminator_tests dyndbg: split multi-query strings with % selftests-dyndbg: test_percent_splitting docs/dyndbg: explain new delimiters: comma, percent finishing: selftests-dyndbg: add test_mod_submod docs/dyndbg: explain flags parse 1st dyndbg: change __dynamic_func_call_cls* macros into expressions dyndbg: drop "protection" of class'd pr_debugs from legacy queries DRM: (phase 2) drm: use correct ccflags-y spelling checkpatch: dont warn about unused macro arg on empty body drm-dyndbg: adapt drm core to use dyndbg classmaps-v2 drm-dyndbg: adapt DRM to invoke DYNDBG_CLASSMAP_PARAM drm-print: fix config-dependent unused variable drm-dyndbg: DRM_CLASSMAP_USE in amdgpu driver drm-dyndbg: DRM_CLASSMAP_USE in i915 driver drm-dyndbg: DRM_CLASSMAP_USE in drm_crtc_helper drm-dyndbg: DRM_CLASSMAP_USE in drm_dp_helper drm-dyndbg: DRM_CLASSMAP_USE in nouveau drm-dyndbg: add DRM_CLASSMAP_USE to Xe driver drm-dyndbg: add DRM_CLASSMAP_USE to virtio_gpu drm-dyndbg: add DRM_CLASSMAP_USE to simpledrm drm-dyndbg: add DRM_CLASSMAP_USE to bochs drm-dyndbg: add DRM_CLASSMAP_USE to etnaviv drm-dyndbg: add DRM_CLASSMAP_USE to gma500 driver drm-dyndbg: add DRM_CLASSMAP_USE to radeon drm-dyndbg: add DRM_CLASSMAP_USE to vmwgfx driver drm-dyndbg: add DRM_CLASSMAP_USE to vkms driver drm-dyndbg: add DRM_CLASSMAP_USE to udl driver drm-dyndbg: add DRM_CLASSMAP_USE to mgag200 driver drm-dyndbg: add DRM_CLASSMAP_USE to the gud driver drm-dyndbg: add DRM_CLASSMAP_USE to the qxl driver drm-dyndbg: add DRM_CLASSMAP_USE to the drm_gem_shmem_helper driver drm: restore CONFIG_DRM_USE_DYNAMIC_DEBUG un-BROKEN .../admin-guide/dynamic-debug-howto.rst | 116 +++- MAINTAINERS | 3 +- drivers/gpu/drm/Kconfig | 3 +- drivers/gpu/drm/Makefile | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 12 +- drivers/gpu/drm/display/drm_dp_helper.c | 12 +- drivers/gpu/drm/drm_crtc_helper.c | 12 +- drivers/gpu/drm/drm_gem_shmem_helper.c | 2 + drivers/gpu/drm/drm_print.c | 38 +- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 2 + drivers/gpu/drm/gma500/psb_drv.c | 2 + drivers/gpu/drm/gud/gud_drv.c | 2 + drivers/gpu/drm/i915/i915_params.c | 12 +- drivers/gpu/drm/mgag200/mgag200_drv.c | 2 + drivers/gpu/drm/nouveau/nouveau_drm.c | 12 +- drivers/gpu/drm/qxl/qxl_drv.c | 2 + drivers/gpu/drm/radeon/radeon_drv.c | 2 + drivers/gpu/drm/tiny/bochs.c | 2 + drivers/gpu/drm/tiny/simpledrm.c | 2 + drivers/gpu/drm/udl/udl_main.c | 2 + drivers/gpu/drm/virtio/virtgpu_drv.c | 2 + drivers/gpu/drm/vkms/vkms_drv.c | 2 + drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 2 + drivers/gpu/drm/xe/xe_drm_client.c | 2 + include/asm-generic/vmlinux.lds.h | 1 + include/drm/drm_print.h | 12 + include/linux/dynamic_debug.h | 193 ++++-- kernel/module/main.c | 15 +- lib/Kconfig.debug | 24 +- lib/Makefile | 3 + lib/dynamic_debug.c | 555 +++++++++++------- lib/test_dynamic_debug.c | 181 +++--- lib/test_dynamic_debug_submod.c | 17 + scripts/checkpatch.pl | 3 +- tools/testing/selftests/Makefile | 1 + .../testing/selftests/dynamic_debug/Makefile | 9 + tools/testing/selftests/dynamic_debug/config | 2 + .../dynamic_debug/dyndbg_selftest.sh | 364 ++++++++++++ 38 files changed, 1206 insertions(+), 425 deletions(-) create mode 100644 lib/test_dynamic_debug_submod.c create mode 100644 tools/testing/selftests/dynamic_debug/Makefile create mode 100644 tools/testing/selftests/dynamic_debug/config create mode 100755 tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh -- 2.47.0 -- 2.47.1