UPSTREAM: dynamic_debug: allow to work if debugfs is disabled

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, also create the "control" file for dynamic_debug in
procfs.  This allows people turn on debugging as needed at runtime for
individual driverfs and subsystems.

Bug: 145162121
Reported-by: many different companies
Cc: Jason Baron <jbaron@akamai.com>
Acked-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20200210211142.GB1373304@kroah.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 239a5791ffd5559f51815df442c4dbbe7fc21ade)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: Icd892ea823af6254726847700fd9c251d13b556b
This commit is contained in:
Greg Kroah-Hartman 2020-02-10 13:11:42 -08:00 committed by Greg Kroah-Hartman
parent 6e400aa37e
commit d936a940f4
3 changed files with 22 additions and 8 deletions

View File

@ -54,6 +54,9 @@ If you make a mistake with the syntax, the write will fail thus::
<debugfs>/dynamic_debug/control <debugfs>/dynamic_debug/control
-bash: echo: write error: Invalid argument -bash: echo: write error: Invalid argument
Note, for systems without 'debugfs' enabled, the control file can be
found in ``/proc/dynamic_debug/control``.
Viewing Dynamic Debug Behaviour Viewing Dynamic Debug Behaviour
=============================== ===============================

View File

@ -80,7 +80,7 @@ config DYNAMIC_DEBUG
bool "Enable dynamic printk() support" bool "Enable dynamic printk() support"
default n default n
depends on PRINTK depends on PRINTK
depends on DEBUG_FS depends on (DEBUG_FS || PROC_FS)
help help
Compiles debug level messages into the kernel, which would not Compiles debug level messages into the kernel, which would not
@ -98,8 +98,9 @@ config DYNAMIC_DEBUG
Usage: Usage:
Dynamic debugging is controlled via the 'dynamic_debug/control' file, Dynamic debugging is controlled via the 'dynamic_debug/control' file,
which is contained in the 'debugfs' filesystem. Thus, the debugfs which is contained in the 'debugfs' filesystem or procfs.
filesystem must first be mounted before making use of this feature. Thus, the debugfs or procfs filesystem must first be mounted before
making use of this feature.
We refer the control file as: <debugfs>/dynamic_debug/control. This We refer the control file as: <debugfs>/dynamic_debug/control. This
file contains a list of the debug statements that can be enabled. The file contains a list of the debug statements that can be enabled. The
format for each line of the file is: format for each line of the file is:

View File

@ -954,15 +954,25 @@ static void ddebug_remove_all_tables(void)
static __initdata int ddebug_init_success; 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) if (!ddebug_init_success)
return -ENODEV; return -ENODEV;
dir = debugfs_create_dir("dynamic_debug", NULL); /* Create the control file in debugfs if it is enabled */
debugfs_create_file("control", 0644, dir, NULL, &ddebug_proc_fops); if (debugfs_initialized()) {
debugfs_dir = debugfs_create_dir("dynamic_debug", NULL);
debugfs_create_file("control", 0644, debugfs_dir, NULL,
&ddebug_proc_fops);
}
/* Also create the control file in procfs */
procfs_dir = proc_mkdir("dynamic_debug", NULL);
if (procfs_dir)
proc_create("control", 0644, procfs_dir, &ddebug_proc_fops);
return 0; return 0;
} }
@ -1040,4 +1050,4 @@ out_err:
early_initcall(dynamic_debug_init); early_initcall(dynamic_debug_init);
/* Debugfs setup must be done later */ /* Debugfs setup must be done later */
fs_initcall(dynamic_debug_init_debugfs); fs_initcall(dynamic_debug_init_control);