All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jim Cromie" <jim.cromie@gmail.com>,
	"Jason Baron" <jbaron@akamai.com>,
	"Shuah Khan" <shuah@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Luis Chamberlain" <mcgrof@kernel.org>,
	"Petr Pavlu" <petr.pavlu@suse.com>,
	"Daniel Gomez" <da.gomez@kernel.org>,
	"Sami Tolvanen" <samitolvanen@google.com>,
	"Aaron Tomlin" <atomlin@atomlin.com>,
	"Jonathan Corbet" <corbet@net.net>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nsc@kernel.org>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Pavel Machek" <pavel@kernel.org>, "Len Brown" <lenb@kernel.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Petr Mladek" <pmladek@suse.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"John Ogness" <john.ogness@linutronix.de>,
	"Sergey Senozhatsky" <senozhatsky@chromium.org>,
	"Thomas Weißschuh" <linux@weissschuh.net>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: dri-devel@lists.freedesktop.org, linux-modules@vger.kernel.org,
	linux-kbuild@vger.kernel.org, "Jason Baron" <jbaron@redhat.com>
Subject: Re: [PATCH v13 01/39] selftests/dyndbg: Add kselftest script to verify dynamic-debug
Date: Wed, 28 Oct 2026 20:25:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-188377@kernel.org> (raw)
In-Reply-To: <20261027-dd-cmap-part2-clean-v13-1-9267923be612@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] selftests/dyndbg: stale record check in audit_golden_records() never fails
- [Medium] selftests/dyndbg: broken LACK_DD_BUILTIN fallback and missing root check
--

commit d24db61e852431796c45358b620c1c921638c8b3
Author: Jim Cromie <jim.cromie@gmail.com>

selftests/dyndbg: Add kselftest script to verify dynamic-debug

This commit introduces a kselftest script and a syslog/control-file hash
validation helper library to test dynamic_debug grammar and query execution
against a database of golden MD5 fingerprints.

> diff --git a/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
> new file mode 100755
> index 0000000000000..c1475c7555429
> --- /dev/null
> +++ b/tools/testing/selftests/dynamic_debug/dyndbg_selftest.sh
[ ... ]
> +[ -e /proc/dynamic_debug/control ] || {
> +    echo -e "${RED}: this test requires CONFIG_DYNAMIC_DEBUG=y ${NC}"
> +    exit $ksft_skip # nothing to test here, no good reason to fail.
> +}
> +
> +lsmod >/dev/null 2>&1 || {
> +    echo -e "${RED}: lsmod requires /proc/modules ${NC}"
> +    # exit $ksft_skip # maybe later we can do more
> +}
> +
> +# need info to avoid failures due to untestable configs
> +
> +[ -f "$KCONFIG_CONFIG" ] || KCONFIG_CONFIG=".config"
> +if [ -f "$KCONFIG_CONFIG" ]; then
> +    v_echo "# consulting KCONFIG_CONFIG: $KCONFIG_CONFIG"
> +    grep -q "CONFIG_DYNAMIC_DEBUG=y" $KCONFIG_CONFIG ; LACK_DD_BUILTIN=$?
> +    grep -q "CONFIG_TEST_DYNAMIC_DEBUG=m" $KCONFIG_CONFIG ; LACK_TMOD=$?
> +else
> +    # if no config, try runtime probes
> +    modprobe -n test_dynamic_debug 2>/dev/null ; LACK_TMOD=$?
> +    # assume builtin dyndbg if control exists (checked above)
> +    LACK_DD_BUILTIN=0
> +fi

[Severity: Medium]
When kselftest runs dyndbg_selftest.sh via runner.sh, it first changes the
working directory into tools/testing/selftests/dynamic_debug/ (or the
installed selftest directory), where .config is not present unless
KCONFIG_CONFIG is set to an absolute path.

In that case, the fallback branch unconditionally sets LACK_DD_BUILTIN=0.
However, on a kernel built with CONFIG_DYNAMIC_DEBUG_CORE=y and
CONFIG_DYNAMIC_DEBUG=n, /proc/dynamic_debug/control still exists, while
built-in files such as kernel/params.c have no dynamic debug descriptors.
Will FT_basic_queries() then fail to skip and report false DRIFTED failures
on empty diffs? Could the runtime fallback instead probe
/proc/dynamic_debug/control for ^kernel/params.c: to set LACK_DD_BUILTIN?

Also, /proc/dynamic_debug/control is created with mode 0644, so the
[ -e /proc/dynamic_debug/control ] check succeeds for unprivileged users,
causing the script to fail with $ksft_fail on the first write in ddcmd()
or /dev/kmsg instead of skipping. Should this check for write permission
(-w /proc/dynamic_debug/control) or root privileges before running the
tests?

[ ... ]
> +audit_golden_records
> +
> +# Output consolidated blocks of unregistered and drifted fingerprints
> +failed=0
> +
> +if [ -s "$UNREG_HASHES_FILE" ]; then
> +    if [ "$K" -ne 2 ]; then
> +        echo -e "${YELLOW}\n# --- Unregistered Baselines ---"
> +        cat "$UNREG_HASHES_FILE"
> +        echo -e "# ------------------------------${NC}"
> +    fi
> +    : > "$UNREG_HASHES_FILE"
> +    failed=1
> +fi
> +
> +if [ -s "$DRIFT_HASHES_FILE" ]; then
> +    if [ "$K" -ne 2 ]; then
> +        echo -e "${RED}\n# --- Drifted Baselines ---"
> +        cat "$DRIFT_HASHES_FILE"
> +        echo -e "# -------------------------${NC}"
> +    fi
> +    : > "$DRIFT_HASHES_FILE"
> +    failed=1
> +fi
> +
> +if [ $failed -eq 1 ]; then
> +    [ "$K" -eq 1 ] && echo "fake success" && exit $ksft_pass
> +    [ "$K" -eq 2 ] && exit $ksft_pass
> +    exit $ksft_fail
> +fi
> +
> +exit $ksft_pass
> +
> diff --git a/tools/testing/selftests/dynamic_debug/syslog_hash_validation.sh b/tools/testing/selftests/dynamic_debug/syslog_hash_validation.sh
> new file mode 100644
> index 0000000000000..8c6e91f5d9c27
> --- /dev/null
> +++ b/tools/testing/selftests/dynamic_debug/syslog_hash_validation.sh
[ ... ]
> +    # Strictly verify that the computed fingerprint matches any
> +    # expected hash for this label
> +    if [ -n "$expected_hash_field" ] && [ $matched -eq 1 ]; then
> +        local short_hash="${fingerprint:0:12}"
> +        [ "$V" -ge 1 ] && echo -e "${GREEN}✔ Verified '${label}' " \
> +            "(${short_hash}) [via: '${DDCMD_LOG}']${NC}"
> +
> +        if [ "$V" -ge 2 ]; then
> +            echo -e "${CYAN}--- Captured Invariant ${capture_desc} Output ($label) ---"
> +	    printf "#K= %-32s %-24s\n" "${fingerprint}" "${label}"
> +            echo "$raw_capture"
> +            echo -e "-----------------------------------${NC}"
> +        fi
> +        echo "$fingerprint" >> "$SEEN_HASHES_FILE"
> +    else
[ ... ]
> +function audit_golden_records {
> +    local seen_file="$SEEN_HASHES_FILE"
> +
> +    if [ ! -f "$seen_file" ]; then
> +        return
> +    fi
> +
> +    # Require GOLDEN_RECORDS to be defined in the caller script
> +    if ! declare -f GOLDEN_RECORDS >/dev/null; then
> +        return
> +    fi
> +
> +    [ "${V:-0}" -ge 1 ] && echo -e "${YELLOW}# --- GOLDEN_RECORDS Audit ---${NC}"
> +    local stale_found=0
> +    local total_records=$(GOLDEN_RECORDS | grep -c "^#K=")
> +
> +    # Read each active record line from GOLDEN_RECORDS
> +    while read -r line; do
> +        # Extract the hash/hashes (second word) from the #K= line
> +        local hash_field=$(echo "$line" | awk '{print $2}')
> +
> +        # Check if at least one of the comma-separated hashes was seen
> +        local hash_seen=0
> +        local h
> +        local OLD_IFS="$IFS"
> +        IFS=","
> +        for h in $hash_field; do
> +            if grep -q "$h" "$seen_file" 2>/dev/null; then
> +                hash_seen=1
> +                break
> +            fi
> +        done
> +        IFS="$OLD_IFS"
> +
> +        # Check if this hash field was seen during the run
> +        if [ $hash_seen -eq 0 ]; then
> +            if [ "${K:-0}" -ne 2 ]; then
> +                if [ $stale_found -eq 0 ]; then
> +                    # On first failure, print header if not already printed
> +                    [ "${V:-0}" -eq 0 ] && \
> +                        echo -e "${YELLOW}# --- GOLDEN_RECORDS Audit ---${NC}"
> +                    echo -e "${YELLOW}# The following GOLDEN_RECORDS entries " \
> +                        "were never hit and may be stale:${NC}"
> +                fi
> +                echo -e "${YELLOW}#K_STALE= $line${NC}"
> +            fi
> +            stale_found=1
> +        fi
> +    done < <(GOLDEN_RECORDS | grep "^#K=" | grep -v "<md5_hash>")
> +
> +    if [ $stale_found -eq 0 ] && [ "${V:-0}" -ge 1 ]; then
> +        echo -e "${GREEN}# All $total_records GOLDEN_RECORDS entries " \
> +            "were successfully hit!${NC}"
> +    fi
> +
> +    # Detect duplicate labels in the database
> +    local dupes=$(GOLDEN_RECORDS | grep "^#K=" | awk '{print $3}' | sort | uniq -d)
> +    if [ -n "$dupes" ]; then
> +        echo -e "\n${RED}# WARNING: Duplicate labels detected in GOLDEN_RECORDS():${NC}"
> +        echo "$dupes" | sed 's/^/#   /'
> +    fi
> +
> +    # Clean up
> +    rm -f "$seen_file"
> +}

[Severity: Medium]
The header comment in dyndbg_selftest.sh documents that K=0 fails with exit 1
on checksum drift or stale records, and K=1 exits 0 with "fake success".

In audit_golden_records(), stale_found and dupes are local variables and the
function ends with rm -f "$seen_file", returning 0 without propagating the
failure to the caller in dyndbg_selftest.sh (which only sets failed=1 when
UNREG_HASHES_FILE or DRIFT_HASHES_FILE is non-empty). Doesn't this mean stale
records or duplicate labels in GOLDEN_RECORDS() will never cause K=0 to exit
with $ksft_fail or K=1 to report "fake success"?

In addition, verify_fingerprint() writes only "$fingerprint" to
SEEN_HASHES_FILE without the test label, and audit_golden_records() checks
only whether the hash appears in "$seen_file". When multiple test cases in
GOLDEN_RECORDS() share the same MD5 hash (for example, FT_grammar_errs.21 and
FT_grammar_errs.41 both have 94cdf3b32afa4f12a00a704208aa2e53, and
FT_grammar_errs.25 and FT_grammar_errs.45 both have
644b81753949ac1285e38ac995eeba46), won't running just one of those tests mark
the hash as seen for all of them and hide unexecuted labels? Should
SEEN_HASHES_FILE record both the fingerprint and label (and be truncated with
: > "$seen_file" instead of removed with rm -f)?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261027-dd-cmap-part2-clean-v13-0-9267923be612@gmail.com?part=1

  reply	other threads:[~2026-10-28 20:25 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 20:22 [PATCH v13 00/39] dyndbg: Fix classmaps API for subsystems, query extensions, selftests Jim Cromie via B4 Relay
2026-10-27 20:22 ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 01/39] selftests/dyndbg: Add kselftest script to verify dynamic-debug Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-28 20:25   ` sashiko-bot [this message]
2026-10-27 20:22 ` [PATCH v13 02/39] vmlinux.lds.h: refactor BOUNDED_SECTION_* macros into bounded_sections.lds.h Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 03/39] vmlinux.lds.h: drop unused HEADERED_SECTION* macros Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 04/39] vmlinux.lds.h: Fix ALIGN(8) omission causing NULL ptr on i386 Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 05/39] vmlinux.lds.h: remove redundant ALIGN(8) directives Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 06/39] dyndbg.lds.S: fix lost dyndbg sections in modules Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 07/39] dyndbg: factor ddebug_match_desc out from ddebug_change Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 08/39] dyndbg: add stub macro for DECLARE_DYNDBG_CLASSMAP Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 09/39] dyndbg: reword "class unknown," to "class:_UNKNOWN_" Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 10/39] dyndbg-API: remove DD_CLASS_TYPE_(DISJOINT|LEVEL)_NAMES and code Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 11/39] dyndbg: drop NUM_TYPE_ARGS Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 12/39] dyndbg: bump num-tokens in a query-cmd from 9 to 15 Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 13/39] dyndbg: reduce verbose/debug clutter Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 14/39] dyndbg: refactor param_set_dyndbg_classes and below Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 15/39] dyndbg: tighten fn-sig of ddebug_apply_class_bitmap Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 16/39] dyndbg: replace classmap list with an array-slice Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 17/39] dyndbg: macrofy a 2-index for-loop pattern Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 18/39] dyndbg: reduce class param storage to u32 Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 19/39] dyndbg,module: make proper substructs in _ddebug_info Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-28 20:25   ` sashiko-bot
2026-10-27 20:22 ` [PATCH v13 20/39] dyndbg: move mod_name down from struct ddebug_table to _ddebug_info Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 21/39] dyndbg: hoist classmap-filter-by-modname up to ddebug_add_module Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 22/39] dyndbg-API: replace DECLARE_DYNDBG_CLASSMAP Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-28 20:25   ` sashiko-bot
2026-10-27 20:22 ` [PATCH v13 23/39] selftests/dyndbg: add FT_classmap_inheritance Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 24/39] dyndbg: detect class_id reservation conflicts Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 25/39] dyndbg: check DYNAMIC_DEBUG_CLASSMAP_{DEFINE,USE_} args at compile-time Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 26/39] dyndbg-test: add do_bulk testpoint, rename do_prints to do_classes Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-28 20:25   ` sashiko-bot
2026-10-27 20:22 ` [PATCH v13 27/39] dyndbg-API: promote DYNAMIC_DEBUG_CLASSMAP_PARAM to API Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-28 20:25   ` sashiko-bot
2026-10-27 20:22 ` [PATCH v13 28/39] dyndbg: control-parser: treat comma as a token separator Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 29/39] selftests: enable comma-terminator tests Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 30/39] dyndbg: split multi-query strings with @ Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-28 20:25   ` sashiko-bot
2026-10-27 20:22 ` [PATCH v13 31/39] dyndbg: resolve "protection" of class'd pr_debug Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 32/39] docs/dyndbg: add classmap info to howto Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 33/39] dyndbg: add epilogue to dynamic_debug/control file Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 34/39] dyndbg: fix attempt to modify an RO string Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 35/39] dyndbg: add +c flag to count pr_debug calls without printing Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-28 20:25   ` sashiko-bot
2026-10-27 20:22 ` [PATCH v13 36/39] dyndbg: add DEBUG-biased fallback stubs for _dynamic_func_call_cls Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-28 20:25   ` sashiko-bot
2026-10-27 20:22 ` [PATCH v13 37/39] selftests/dyndbg: Add FT_count_calls to test +c flag Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 38/39] printk.h: fix overzealous pr_fmt in pr_debug_ratelimited Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie
2026-10-27 20:22 ` [PATCH v13 39/39] drm: Mark __drm_debug as __read_mostly Jim Cromie via B4 Relay
2026-10-27 20:22   ` Jim Cromie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-188377@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=airlied@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=atomlin@atomlin.com \
    --cc=corbet@lwn.net \
    --cc=corbet@net.net \
    --cc=da.gomez@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jbaron@akamai.com \
    --cc=jbaron@redhat.com \
    --cc=jim.cromie@gmail.com \
    --cc=john.ogness@linutronix.de \
    --cc=lenb@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mcgrof@kernel.org \
    --cc=mripard@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=pavel@kernel.org \
    --cc=petr.pavlu@suse.com \
    --cc=pmladek@suse.com \
    --cc=rafael@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=samitolvanen@google.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=senozhatsky@chromium.org \
    --cc=shuah@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=skhan@linuxfoundation.org \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.