From patchwork Mon May 16 22:56:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Cromie X-Patchwork-Id: 12851652 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 9B46BC433EF for ; Mon, 16 May 2022 23:03:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ow/dE+fEIexUXUcXcFSgCMJSzjExS2dwUoQqPtbnVzw=; b=d1JHsISWtS8AyZ 3UURkbt7d3tY7hko8R6C2auG0dOn2z8Jb++SqhweSBcUJ9YyLDDh8ojNUgyTU7e2Cj33MvzHY6b8R rA10ZOgYOxHQDFMreXu2nkzO0nGDOqy8yNQqiFCNRpRTT04FHRZ3t/aGnRmqJyUIZbIVNElPzo44q JZUQIaWC1ykdtE9hOC0KvAiwly1ZauY4djlnzN/HKluWlH1hVhPf5W84yb7ZV41zAcJxs0p1vpLQE mnPTpWsSc8bJdul1F3H/Xf9ZZ2XqZNJsSOfRkcuDdImdpjDWjoC0410hRhE/g3XALT4j+liCnByz1 TdNjeHM0+6Kuoue3gXYw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nqjiw-00Ac1u-F8; Mon, 16 May 2022 23:01:58 +0000 Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nqjeK-00AZPv-8f for linux-arm-kernel@lists.infradead.org; Mon, 16 May 2022 22:57:15 +0000 Received: by mail-io1-xd2f.google.com with SMTP id z26so17596348iot.8 for ; Mon, 16 May 2022 15:57:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oowxXNKCjHWnLn3p6Ic/6Uo3PByaWnVU9pS3Z8uXSpQ=; b=laqZYh+7BRG4JmqbTRUuBXSeJoX3qpeXSKyN4W6lB9YEap+oHbdDxololCguGAMh5j nHo+iMbV1KgWacmGr6OLitd9c+OJnO/2tWVL5454+sTXI5fwoIeNvVDZP+BTxyk5yGlH ZjrvfoQIdRrFxg9V0mySCwKU+ZLqJSv6aNnoGqrEzRufoLC8tKnYJtycpQMjFWGmDDr3 XyoPA0hWE6dcKb4E22Yos6Ma/DhT6NxLI9xKOdKQ8d4wyL2WZgmmBqcUF5zLa+EHROcJ OQLF0z+uPf11CatazTyEpY+D3XSh3bsCN33how5DTmDELfXhYvgRWRLTGHM4+RVfuC7n KmeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oowxXNKCjHWnLn3p6Ic/6Uo3PByaWnVU9pS3Z8uXSpQ=; b=IYJ8hQVL/uPn1AMhAe+Meu9X251DL4wFjXO0fn3R8ji457h24pWD2kVovukJhspWeL +lnLysXn359dteU06+itcebWtTOFz2JS4CvNcmDaUJkSmPh0I59sW6xoGnWQai5sBRo8 GvDYFH5rNm8xCm9/orsyU7ZiErydkvsRsgk3+vpzQA/DsocIaly/t0SjACe/Qf+gGwMu 0Ig+XqnYsuFiYzmumhOVvfbJ9X2hAdRnJ/5Rs62+Boy+OIZg4qfDl7ADWUOhtK4Lsrqq hbV2SE+K4Em9WA9bNxamhkOK7QtbonM6VKhgcrWFmyVNkdcdM/0OtSH7P8kQvT2v0T0J bNGg== X-Gm-Message-State: AOAM532KMYxzo2S55vylKct7HAfEpyG+us1VbB7sC47UiT8JePF7rCR8 3eXRHdRZq2JBVzbV3z4ZxE4= X-Google-Smtp-Source: ABdhPJwp2CUlJ62GPweaP9pCG2DJx2i+qE3mjO0+Bwn7/YiIM+8Fh1IYWcLxvILiLSzZdTx4mDun4g== X-Received: by 2002:a05:6638:504:b0:32e:55a0:dee9 with SMTP id i4-20020a056638050400b0032e55a0dee9mr162907jar.82.1652741828844; Mon, 16 May 2022 15:57:08 -0700 (PDT) Received: from frodo.hsd1.co.comcast.net ([2601:284:8204:2010::dd9f]) by smtp.googlemail.com with ESMTPSA id k26-20020a02661a000000b0032b74686763sm3133949jac.76.2022.05.16.15.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 15:57:08 -0700 (PDT) From: Jim Cromie To: jbaron@akamai.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Cc: gregkh@linuxfoundation.org, daniel.vetter@ffwll.ch, seanpaul@chromium.org, robdclark@gmail.com, rostedt@goodmis.org, mathieu.desnoyers@efficios.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 v2 07/27] dyndbg: validate class FOO on module Date: Mon, 16 May 2022 16:56:20 -0600 Message-Id: <20220516225640.3102269-8-jim.cromie@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220516225640.3102269-1-jim.cromie@gmail.com> References: <20220516225640.3102269-1-jim.cromie@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220516_155712_388524_27B3786E X-CRM114-Status: GOOD ( 22.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add module-to-class validation, in #> echo class DRM_UT_KMS +p > /proc/dynamic_debug/control If a query has "class FOO", ddebug_validate_classname (called from ddebug_change) requires that FOO is known to module X, otherwize X is skipped entirely. The choice of FOO is highly selective, giving isolation and/or coordinated sharing of FOOs. For example, only DRM modules should know and respond to DRM_UT_KMS. So this, combined with module's opt-in declaration of known classes, effectively privatizes the .class_id space for each module (or coordinated set of modules). Ignoring a bad query, with dynamic_debug.verbose=3: (lots of modules will not know other module's classes) bash-5.1# echo module drm class FOO +p > /proc/dynamic_debug/control [ 54.507983] dyndbg: read 24 bytes from userspace [ 54.509549] dyndbg: query 0: "module drm class FOO +p" mod:* [ 54.511502] dyndbg: split into words: "module" "drm" "class" "FOO" "+p" [ 54.513672] dyndbg: op='+' [ 54.514575] dyndbg: flags=0x1 [ 54.515547] dyndbg: *flagsp=0x1 *maskp=0xffffffff [ 54.517112] dyndbg: parsed: func="" file="" module="drm" format="" lineno=0-0 class=FOO [ 54.519707] dyndbg: class: drm.FOO unknown [ 54.521302] dyndbg: no matches for query [ 54.522581] dyndbg: no-match: func="" file="" module="drm" format="" lineno=0-0 class=FOO [ 54.525236] dyndbg: processed 1 queries, with 0 matches, 0 errs Also add a new column to control-file output, displaying the class-name when its not default. If a module has pr_debugs with non-default .class_id's, and has not registered them, "" is issued. Signed-off-by: Jim Cromie --- . split out validate_classnames() --- lib/dynamic_debug.c | 70 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 8f600c13048a..b1aaf8893cdf 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -56,6 +56,7 @@ struct ddebug_query { const char *module; const char *function; const char *format; + const char *class_string; unsigned int first_lineno, last_lineno; }; @@ -136,13 +137,40 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg) fmtlen--; } - v3pr_info("%s: func=\"%s\" file=\"%s\" module=\"%s\" format=\"%.*s\" lineno=%u-%u\n", - msg, - query->function ?: "", - query->filename ?: "", - query->module ?: "", - fmtlen, query->format ?: "", - query->first_lineno, query->last_lineno); + v3pr_info("%s: func=\"%s\" file=\"%s\" module=\"%s\" format=\"%.*s\" lineno=%u-%u class=%s\n", + msg, + query->function ?: "", + query->filename ?: "", + query->module ?: "", + fmtlen, query->format ?: "", + query->first_lineno, query->last_lineno, query->class_string); +} + +/* return <0 if class-name is unknown/invalid, 0..CLASS_DFLT otherwise */ +static int ddebug_validate_classname(struct ddebug_table *dt, const char *class_string) +{ + int query_class = -ENOENT; + int idx; + + if (!class_string) + /* all queries w/o class given work only on default class */ + return _DPRINTK_CLASS_DFLT; + + /* + * XXX single list will need to be a for-list + * so that modules can have 2 sets of class-decls + */ + if (!dt->map) + return -ENOENT; + + idx = match_string(dt->map->classes, dt->map->length, class_string); + if (idx < 0) { + v3pr_info("class: %s.%s unknown\n", dt->mod_name, class_string); + return -ENOENT; + } + query_class = idx + dt->map->base; + + return query_class; } /* @@ -159,6 +187,7 @@ static int ddebug_change(const struct ddebug_query *query, unsigned int newflags; unsigned int nfound = 0; struct flagsbuf fbuf, nbuf; + int query_class; /* search for matching ddebugs */ mutex_lock(&ddebug_lock); @@ -169,9 +198,18 @@ static int ddebug_change(const struct ddebug_query *query, !match_wildcard(query->module, dt->mod_name)) continue; + /* validate class-string against module's known classes */ + query_class = ddebug_validate_classname(dt, query->class_string); + if (query_class < 0) + continue; + for (i = 0; i < dt->num_ddebugs; i++) { struct _ddebug *dp = &dt->ddebugs[i]; + /* match against query-class, either valid input or default */ + if (query_class != dp->class_id) + continue; + /* match against the source filename */ if (query->filename && !match_wildcard(query->filename, dp->filename) && @@ -424,6 +462,8 @@ static int ddebug_parse_query(char *words[], int nwords, } else if (!strcmp(keyword, "line")) { if (parse_linerange(query, arg)) return -EINVAL; + } else if (!strcmp(keyword, "class")) { + rc = check_set(&query->class_string, arg, "class"); } else { pr_err("unknown keyword \"%s\"\n", keyword); return -EINVAL; @@ -851,6 +891,13 @@ static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos) return dp; } +static const char *ddebug_class_name(struct ddebug_iter *iter, struct _ddebug *dp) +{ + if (iter->table->map) + return iter->table->map->classes[dp->class_id]; + return NULL; +} + /* * Seq_ops show method. Called several times within a read() * call from userspace, with ddebug_lock held. Formats the @@ -862,6 +909,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p) struct ddebug_iter *iter = m->private; struct _ddebug *dp = p; struct flagsbuf flags; + char const *class; if (p == SEQ_START_TOKEN) { seq_puts(m, @@ -874,7 +922,13 @@ static int ddebug_proc_show(struct seq_file *m, void *p) iter->table->mod_name, dp->function, ddebug_describe_flags(dp->flags, &flags)); seq_escape(m, dp->format, "\t\r\n\""); - seq_puts(m, "\"\n"); + seq_puts(m, "\""); + + if (dp->class_id != _DPRINTK_CLASS_DFLT) { + class = ddebug_class_name(iter, dp); + seq_printf(m, " class:%s", class ?: ""); + } + seq_puts(m, "\n"); return 0; }