Skip to content

Commit 239a579

Browse files
committed
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. 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>
1 parent 3aef021 commit 239a579

3 files changed

Lines changed: 30 additions & 8 deletions

File tree

‎Documentation/admin-guide/dynamic-debug-howto.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ If you make a mistake with the syntax, the write will fail thus::
5454
<debugfs>/dynamic_debug/control
5555
-bash: echo: write error: Invalid argument
5656

57+
Note, for systems without 'debugfs' enabled, the control file can be
58+
found in ``/proc/dynamic_debug/control``.
59+
5760
Viewing Dynamic Debug Behaviour
5861
===============================
5962

‎lib/Kconfig.debug‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ config DYNAMIC_DEBUG
9898
bool "Enable dynamic printk() support"
9999
default n
100100
depends on PRINTK
101-
depends on DEBUG_FS
101+
depends on (DEBUG_FS || PROC_FS)
102102
help
103103

104104
Compiles debug level messages into the kernel, which would not
@@ -116,8 +116,9 @@ config DYNAMIC_DEBUG
116116
Usage:
117117

118118
Dynamic debugging is controlled via the 'dynamic_debug/control' file,
119-
which is contained in the 'debugfs' filesystem. Thus, the debugfs
120-
filesystem must first be mounted before making use of this feature.
119+
which is contained in the 'debugfs' filesystem or procfs.
120+
Thus, the debugfs or procfs filesystem must first be mounted before
121+
making use of this feature.
121122
We refer the control file as: <debugfs>/dynamic_debug/control. This
122123
file contains a list of the debug statements that can be enabled. The
123124
format for each line of the file is:

‎lib/dynamic_debug.c‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,14 @@ static const struct file_operations ddebug_proc_fops = {
876876
.write = ddebug_proc_write
877877
};
878878

879+
static const struct proc_ops proc_fops = {
880+
.proc_open = ddebug_proc_open,
881+
.proc_read = seq_read,
882+
.proc_lseek = seq_lseek,
883+
.proc_release = seq_release_private,
884+
.proc_write = ddebug_proc_write
885+
};
886+
879887
/*
880888
* Allocate a new ddebug_table for the given module
881889
* and add it to the global list.
@@ -991,15 +999,25 @@ static void ddebug_remove_all_tables(void)
991999

9921000
static __initdata int ddebug_init_success;
9931001

994-
static int __init dynamic_debug_init_debugfs(void)
1002+
static int __init dynamic_debug_init_control(void)
9951003
{
996-
struct dentry *dir;
1004+
struct proc_dir_entry *procfs_dir;
1005+
struct dentry *debugfs_dir;
9971006

9981007
if (!ddebug_init_success)
9991008
return -ENODEV;
10001009

1001-
dir = debugfs_create_dir("dynamic_debug", NULL);
1002-
debugfs_create_file("control", 0644, dir, NULL, &ddebug_proc_fops);
1010+
/* Create the control file in debugfs if it is enabled */
1011+
if (debugfs_initialized()) {
1012+
debugfs_dir = debugfs_create_dir("dynamic_debug", NULL);
1013+
debugfs_create_file("control", 0644, debugfs_dir, NULL,
1014+
&ddebug_proc_fops);
1015+
}
1016+
1017+
/* Also create the control file in procfs */
1018+
procfs_dir = proc_mkdir("dynamic_debug", NULL);
1019+
if (procfs_dir)
1020+
proc_create("control", 0644, procfs_dir, &proc_fops);
10031021

10041022
return 0;
10051023
}
@@ -1077,4 +1095,4 @@ static int __init dynamic_debug_init(void)
10771095
early_initcall(dynamic_debug_init);
10781096

10791097
/* Debugfs setup must be done later */
1080-
fs_initcall(dynamic_debug_init_debugfs);
1098+
fs_initcall(dynamic_debug_init_control);

0 commit comments

Comments
 (0)