Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp418387ybl; Thu, 23 Jan 2020 00:51:25 -0800 (PST) X-Google-Smtp-Source: APXvYqw1x1hmfHflqQz58jmVIKJk/giJZso3s7tusxVuZ1/aq4cyHivmkNh+zwCtJQ3vWJUR2tn8 X-Received: by 2002:a05:6830:4b9:: with SMTP id l25mr10650463otd.266.1579769485467; Thu, 23 Jan 2020 00:51:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579769485; cv=none; d=google.com; s=arc-20160816; b=rlwnyOlLOw+uuo9HqMyotSTA7NyKukbva1Rl5vmLYjXMzAq5KrLqm68/xjUcJOYIPN PlGrGhfP+be7FjZbRvNwWSZRAXS+Ni6oeVHSzfn3x/DIbrDt2y+uDbzwn9AVjP8w3AqQ miD775WW16+HakqHmAuSBYpnfSpZop1pgEQGgph8iWLsKO9v39mrtxEwoQouZBmDLpAe Q4Fm98edipcUjrGDMlcZQbspgKF3/QOGYbaQEKPE4BsW38ejEkZtGYcmCc7kT9BB98q1 gXepMmxF57BajV8bqbMiG/MJCJtfBKMrRRztD/uHOZI/q2dlu7Ubnjax7uJ9xm0tXxf/ m7Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=d24ua5fInccjj9/ZScLkcwrim2bMqlPNC1aqRFvBNwc=; b=q9tT7yEzOngjieaqGos5dqQrSWtj9s9YcMs6D7BUK/Nxi6Hq+uf3NyahtaDk9+DHND 1JaTltDnstKIqa7HK6y+FJaoCvMTkfbcW5RW1lD3znY9ja4HwPhviGJQG1dnFLpxzCXk AzngNXTrdGtvFVymGM7MLM02wNsL3DV4+YvY8zlZgTfGNiYckdS7xozPTsfP4g7oxhZN QwY/uKyDP8Tp3myh/JTI8bVyQsjPfMCxh5Z6M+HgMGO4sE5pxsx9HFvzp5OlVQftx2UK vXFxie7gsvVy5LjAtdIe4u9Xr8eDi1TiJeerz/+aUqhJWeFTOVxSXU4Co+kGfDRPDUhI LRMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U8WlXIzR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v18si817015otn.202.2020.01.23.00.51.13; Thu, 23 Jan 2020 00:51:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U8WlXIzR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726260AbgAWIuT (ORCPT + 99 others); Thu, 23 Jan 2020 03:50:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:57292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725785AbgAWIuT (ORCPT ); Thu, 23 Jan 2020 03:50:19 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 373E32087E; Thu, 23 Jan 2020 08:50:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579769417; bh=WmUzWil0Ci7WqA90ZgpGxlZoIZbsqRT3FGXduYBahT0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=U8WlXIzR56OYhxv2Xx5yrxdxxXUXq0Z5QV8Sj8YfBZOSvUanc1oF3VjEJ5kjVmC/w oatpmjsBUsvscfiYTHxSP1QvqCqMn8id2khfnQSZn55MMYAku3H3+EY0hNrS+ZNqWn bo0j7SXyjw1muS5+K1yflfMZFlSVVEQIfXHSy8LA= Date: Thu, 23 Jan 2020 09:50:15 +0100 From: Greg Kroah-Hartman To: Jason Baron Cc: Randy Dunlap , Will Deacon , linux-kernel@vger.kernel.org, kernel-team@android.com Subject: [PATCH v4] dynamic_debug: allow to work if debugfs is disabled Message-ID: <20200123085015.GA436361@kroah.com> References: <20200122074343.GA2099098@kroah.com> <20200122080352.GA15354@willie-the-truck> <20200122081205.GA2227985@kroah.com> <20200122135352.GA9458@kroah.com> <8d68b75c-05b8-b403-0a10-d17b94a73ba7@akamai.com> <20200122192940.GA88549@kroah.com> <20200122193118.GA88722@kroah.com> <20200123084847.GA435637@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200123084847.GA435637@kroah.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the realization that having debugfs enabled on "production" systems is generally not a good idea, debugfs is being disabled from more and more platforms over time. However, the functionality of dynamic debugging still is needed at times, and since it relies on debugfs for its user api, having debugfs disabled also forces dynamic debug to be disabled. To get around this, move the "control" file for dynamic_debug to procfs IFF debugfs is disabled. This lets people turn on debugging as needed at runtime for individual driverfs and subsystems. Reported-by: many different companies Cc: Jason Baron Signed-off-by: Greg Kroah-Hartman --- v4: tweaks to the .rst text thanks to Randy's review v3: rename init function as it is now no longer just for debugfs, thanks to Jason for the review. Fix build warning for debugfs_initialized call. v2: Fix up octal permissions and add procfs reference to the Kconfig entry, thanks to Will for the review. .../admin-guide/dynamic-debug-howto.rst | 3 +++ lib/Kconfig.debug | 7 ++++--- lib/dynamic_debug.c | 21 ++++++++++++++----- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Documentation/admin-guide/dynamic-debug-howto.rst b/Documentation/admin-guide/dynamic-debug-howto.rst index 252e5ef324e5..60679dda6007 100644 --- a/Documentation/admin-guide/dynamic-debug-howto.rst +++ b/Documentation/admin-guide/dynamic-debug-howto.rst @@ -54,6 +54,9 @@ If you make a mistake with the syntax, the write will fail thus:: /dynamic_debug/control -bash: echo: write error: Invalid argument +Note, for systems without 'debugfs' enabled, the control file is located +in ``/proc/dynamic_debug/control``. + Viewing Dynamic Debug Behaviour =============================== diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 5ffe144c9794..49980eb8c18e 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -98,7 +98,7 @@ config DYNAMIC_DEBUG bool "Enable dynamic printk() support" default n depends on PRINTK - depends on DEBUG_FS + depends on (DEBUG_FS || PROC_FS) help Compiles debug level messages into the kernel, which would not @@ -116,8 +116,9 @@ config DYNAMIC_DEBUG Usage: Dynamic debugging is controlled via the 'dynamic_debug/control' file, - which is contained in the 'debugfs' filesystem. Thus, the debugfs - filesystem must first be mounted before making use of this feature. + which is contained in the 'debugfs' filesystem or procfs if + debugfs is not present. Thus, the debugfs or procfs filesystem + must first be mounted before making use of this feature. We refer the control file as: /dynamic_debug/control. This file contains a list of the debug statements that can be enabled. The format for each line of the file is: diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index c60409138e13..118e928cdbda 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -991,15 +991,26 @@ static void ddebug_remove_all_tables(void) static __initdata int ddebug_init_success; -static int __init dynamic_debug_init_debugfs(void) +static int __init dynamic_debug_init_control(void) { - struct dentry *dir; + struct proc_dir_entry *procfs_dir; + struct dentry *debugfs_dir; if (!ddebug_init_success) return -ENODEV; - dir = debugfs_create_dir("dynamic_debug", NULL); - debugfs_create_file("control", 0644, dir, NULL, &ddebug_proc_fops); + /* Create the control file in debugfs if it is enabled */ + if (debugfs_initialized()) { + debugfs_dir = debugfs_create_dir("dynamic_debug", NULL); + debugfs_create_file("control", 0644, debugfs_dir, NULL, + &ddebug_proc_fops); + return 0; + } + + /* No debugfs so put it in procfs instead */ + procfs_dir = proc_mkdir("dynamic_debug", NULL); + if (procfs_dir) + proc_create("control", 0644, procfs_dir, &ddebug_proc_fops); return 0; } @@ -1077,4 +1088,4 @@ static int __init dynamic_debug_init(void) early_initcall(dynamic_debug_init); /* Debugfs setup must be done later */ -fs_initcall(dynamic_debug_init_debugfs); +fs_initcall(dynamic_debug_init_control); -- 2.25.0