Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1160607pxk; Mon, 31 Aug 2020 11:25:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmsUjFhD3fEkKUR/ypOJieD1KmOhBfXroCLTZwWH8DL/LWeGpgaAJ8H5g8J3WPx9cvWc3s X-Received: by 2002:a17:906:c108:: with SMTP id do8mr2310695ejc.88.1598898335682; Mon, 31 Aug 2020 11:25:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598898335; cv=none; d=google.com; s=arc-20160816; b=ZcifxYt5DoldO565Nx/tBP05jX3Ljb9PcJ7Ml8BzEQskP2luzXs7X+uypMnpIVG0HN n/Zy5oq5mURVkIElxxPwJMbLNCvorZnMUZ9RoN8FE6wJIDHORs7axDfejyBlIMQY3/wN abW6w3JYRbuP6kB1lmbhFNplosAr6BkBPfioQWAMgXWJ81VzFtOjVNTyVrlvd84QFGL0 vVtw1uySIKGdGIY8c4nCA1xyzCjTuaMYsCxlHMZWKdNMiLV9wL2N2OFY4KNmLwy3tEpz SRkZb3JCpDOaDzTW+0plu1RiApdHPyn6AQWGuQPxurvWN0Y0O4lEl545AWd2R/qICZa6 zCDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/YEL2sT07e48hoT0+vsetk/IvirpQ7LEfHojHk2BQCs=; b=F+Pd5ozRnjHVkrnsVnxopVfzA8BYPR5uhsZgc7Yk1V09tvqp0677OA48ZXn65t748+ 9WSVO8TX017Blvt0B+Rw8f2WcWPJYC6zRJ8oxk2NlxHWnKK979rfyg1j43uWj+v69RxB 1C4dmJearHVqkjDOQwZyj97Mt5pUN0ltjhHfAqpEo/NEeAt7ZA26TU7r5m4Neg8ZgUdV C5umEdj4H15k73cdmQiQHSYEmHNB7Ae6Y9KJpkpfZlgiUkVN9nPlXmD5Yqz1miQIkX+X v5GGsc5qbEMX+BJhwLHz+A6BJ36DRBJO+jZx9QKznrTq6YFpROd/kb3WbrAxF06hEf83 1s/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="ck/m3fO1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bm19si5517549ejb.332.2020.08.31.11.25.12; Mon, 31 Aug 2020 11:25:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="ck/m3fO1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729908AbgHaSXJ (ORCPT + 99 others); Mon, 31 Aug 2020 14:23:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729725AbgHaSXE (ORCPT ); Mon, 31 Aug 2020 14:23:04 -0400 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED39AC061573 for ; Mon, 31 Aug 2020 11:23:03 -0700 (PDT) Received: by mail-io1-xd44.google.com with SMTP id j2so7040530ioj.7 for ; Mon, 31 Aug 2020 11:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/YEL2sT07e48hoT0+vsetk/IvirpQ7LEfHojHk2BQCs=; b=ck/m3fO1xWI/k1U6ETZWVA2a0KrXgETKMqcl2K0S1DHKhyCHJGiV74e9C3fs+XMY3R 2GKQEcBeq9Izm6EHz3ELyej4jqSZ9QMhO6gaAQTlZuGjcddzjD0c+9qOIJ5rhAludUdT Z/vdzqy4MxRdcey/xsapf14Iqc11rYN/d3+NVJl88UGD3IIOyudChKVQyACdmHkPaCYC Ur6OHZktnK02NAIXcoVSldYHPsK6RFVPQPI1RS9mSB99SVUKYbqMGN0rC6mO30JMwnOW izGat9ltRwo7BKRDhIISCxyC6hElN8WXnjGyE6vdGwxntMrIvWtL5uHLD1b+cudX22cM SKTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/YEL2sT07e48hoT0+vsetk/IvirpQ7LEfHojHk2BQCs=; b=iYOI8Xh5KjxMID12uHzBX1smX114eKTH44VNDpJEvLVjMUyYOjkM+DGjC6JspziVef MazakQEoLYhMT8BeU4Shwc9Hni2doGz0FL6Nd6aj/Oqnvg5/UrBhtkMan1w7fW/hb/4G pFb3t70E7JUMbsDLhFjKiY1Ls+CWk88UTpGW90hJMt0+OpniffWLgBtIWc55K7KUTbSG YpDZfTCZhxE2JcU4oCh3tKBvVsvfkA871jFYgjQxxItDGFMrPMJnloQyp86M9yrabrV5 veQy+xGUA+Hwzd3aDVFjP3Hg70e/uRTWLz0KG1zA+jiwDBCec1kBCXBGRFd9lo0n7UYq Famw== X-Gm-Message-State: AOAM531NAApthepas2p/VLqXW7miNKRXpmamJX4GhcyKGii9ZgkE9d/Z +I0pAy+IUtX76r9u4amMwp0= X-Received: by 2002:a02:1004:: with SMTP id 4mr2430142jay.127.1598898183259; Mon, 31 Aug 2020 11:23:03 -0700 (PDT) Received: from frodo.hsd1.co.comcast.net ([2601:284:8203:5970::dc2e]) by smtp.googlemail.com with ESMTPSA id p18sm4129017iog.1.2020.08.31.11.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2020 11:23:02 -0700 (PDT) From: Jim Cromie To: jbaron@akamai.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org Cc: Jim Cromie Subject: [PATCH v3 2/3] dyndbg: refine export, rename to dynamic_debug_exec_queries() Date: Mon, 31 Aug 2020 12:22:09 -0600 Message-Id: <20200831182210.850852-3-jim.cromie@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200831182210.850852-1-jim.cromie@gmail.com> References: <20200831182210.850852-1-jim.cromie@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit 4c0d77828d4f ("dyndbg: export ddebug_exec_queries") had a few problems: - broken non DYNAMIC_DEBUG_CORE configs, sparse warning - the exported function modifies query string, breaks on RO strings. - func name follows internal convention, shouldn't be exposed as is. 1st is fixed in header with ifdefd function prototype or stub defn. Also remove an obsolete HAVE-symbol ifdef-comment, and add others. Fix others by wrapping existing internal function with a new one, named in accordance with module-prefix naming convention, before export hits v5.9.0. In new function, copy query string to a local buffer, so users can pass hard-coded/RO queries, and internal function can be used unchanged. Fixes: 4c0d77828d4f ("dyndbg: export ddebug_exec_queries") --- v2- code improvements, per Joe Perches v3- commit message fixups Signed-off-by: Jim Cromie --- include/linux/dynamic_debug.h | 20 ++++++++++++++++---- lib/dynamic_debug.c | 27 +++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h index aa9ff9e1c0b3..8aa0c7c2608c 100644 --- a/include/linux/dynamic_debug.h +++ b/include/linux/dynamic_debug.h @@ -49,6 +49,10 @@ struct _ddebug { #if defined(CONFIG_DYNAMIC_DEBUG_CORE) + +/* exported for module authors to exercise >control */ +int dynamic_debug_exec_queries(const char *query, const char *modname); + int ddebug_add_module(struct _ddebug *tab, unsigned int n, const char *modname); extern int ddebug_remove_module(const char *mod_name); @@ -105,7 +109,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor, static_branch_unlikely(&descriptor.key.dd_key_false) #endif -#else /* !HAVE_JUMP_LABEL */ +#else /* !CONFIG_JUMP_LABEL */ #define _DPRINTK_KEY_INIT @@ -117,7 +121,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor, unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) #endif -#endif +#endif /* CONFIG_JUMP_LABEL */ #define __dynamic_func_call(id, fmt, func, ...) do { \ DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt); \ @@ -172,10 +176,11 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor, KERN_DEBUG, prefix_str, prefix_type, \ rowsize, groupsize, buf, len, ascii) -#else +#else /* !CONFIG_DYNAMIC_DEBUG_CORE */ #include #include +#include static inline int ddebug_add_module(struct _ddebug *tab, unsigned int n, const char *modname) @@ -210,6 +215,13 @@ static inline int ddebug_dyndbg_module_param_cb(char *param, char *val, print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, \ rowsize, groupsize, buf, len, ascii); \ } while (0) -#endif + +static inline int dynamic_debug_exec_queries(const char *query, const char *modname) +{ + pr_warn("kernel not built with CONFIG_DYNAMIC_DEBUG_CORE\n"); + return 0; +} + +#endif /* !CONFIG_DYNAMIC_DEBUG_CORE */ #endif diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 01b7d0210412..08e4b057514c 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -525,7 +525,7 @@ static int ddebug_exec_query(char *query_string, const char *modname) last error or number of matching callsites. Module name is either in param (for boot arg) or perhaps in query string. */ -int ddebug_exec_queries(char *query, const char *modname) +static int ddebug_exec_queries(char *query, const char *modname) { char *split; int i, errs = 0, exitcode = 0, rc, nfound = 0; @@ -557,7 +557,30 @@ int ddebug_exec_queries(char *query, const char *modname) return exitcode; return nfound; } -EXPORT_SYMBOL_GPL(ddebug_exec_queries); + +/** + * dynamic_debug_exec_queries - select and change dynamic-debug prints + * @query: query-string described in admin-guide/dynamic-debug-howto + * @modname: string containing module name, usually &module.mod_name + * + * This uses the >/proc/dynamic_debug/control reader, allowing module + * authors to modify their dynamic-debug callsites. The modname is + * canonically struct module.mod_name, but can also be null or a + * module-wildcard, for example: "drm*". + */ +int dynamic_debug_exec_queries(const char *query, const char *modname) +{ + int rc; + char *qry = kstrndup(query, PAGE_SIZE, GFP_KERNEL); + + if (!query) + return -ENOMEM; + + rc = ddebug_exec_queries(qry, modname); + kfree(qry); + return rc; +} +EXPORT_SYMBOL_GPL(dynamic_debug_exec_queries); #define PREFIX_SIZE 64 -- 2.26.2