Skip to content

Commit a5d05b0

Browse files
Uwe Kleine-Königkees
authored andcommitted
pstore/ftrace: Allow immediate recording
Without a module param knob there was no way to enable pstore ftrace recording early enough to debug hangs happening during the boot process before userspace is up enough to enable it via the regular debugfs knobs. Signed-off-by: Uwe Kleine-König <[email protected]> Co-developed-by: Kees Cook <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fa55b7d commit a5d05b0

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

fs/pstore/ftrace.c

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,12 @@ static struct ftrace_ops pstore_ftrace_ops __read_mostly = {
6464
static DEFINE_MUTEX(pstore_ftrace_lock);
6565
static bool pstore_ftrace_enabled;
6666

67-
static ssize_t pstore_ftrace_knob_write(struct file *f, const char __user *buf,
68-
size_t count, loff_t *ppos)
67+
static int pstore_set_ftrace_enabled(bool on)
6968
{
70-
u8 on;
7169
ssize_t ret;
7270

73-
ret = kstrtou8_from_user(buf, count, 2, &on);
74-
if (ret)
75-
return ret;
76-
77-
mutex_lock(&pstore_ftrace_lock);
78-
79-
if (!on ^ pstore_ftrace_enabled)
80-
goto out;
71+
if (on == pstore_ftrace_enabled)
72+
return 0;
8173

8274
if (on) {
8375
ftrace_ops_set_global_filter(&pstore_ftrace_ops);
@@ -89,15 +81,30 @@ static ssize_t pstore_ftrace_knob_write(struct file *f, const char __user *buf,
8981
if (ret) {
9082
pr_err("%s: unable to %sregister ftrace ops: %zd\n",
9183
__func__, on ? "" : "un", ret);
92-
goto err;
84+
} else {
85+
pstore_ftrace_enabled = on;
9386
}
9487

95-
pstore_ftrace_enabled = on;
96-
out:
97-
ret = count;
98-
err:
88+
return ret;
89+
}
90+
91+
static ssize_t pstore_ftrace_knob_write(struct file *f, const char __user *buf,
92+
size_t count, loff_t *ppos)
93+
{
94+
u8 on;
95+
ssize_t ret;
96+
97+
ret = kstrtou8_from_user(buf, count, 2, &on);
98+
if (ret)
99+
return ret;
100+
101+
mutex_lock(&pstore_ftrace_lock);
102+
ret = pstore_set_ftrace_enabled(on);
99103
mutex_unlock(&pstore_ftrace_lock);
100104

105+
if (ret == 0)
106+
ret = count;
107+
101108
return ret;
102109
}
103110

@@ -117,13 +124,20 @@ static const struct file_operations pstore_knob_fops = {
117124

118125
static struct dentry *pstore_ftrace_dir;
119126

127+
static bool record_ftrace;
128+
module_param(record_ftrace, bool, 0400);
129+
MODULE_PARM_DESC(record_ftrace,
130+
"enable ftrace recording immediately (default: off)");
131+
120132
void pstore_register_ftrace(void)
121133
{
122134
if (!psinfo->write)
123135
return;
124136

125137
pstore_ftrace_dir = debugfs_create_dir("pstore", NULL);
126138

139+
pstore_set_ftrace_enabled(record_ftrace);
140+
127141
debugfs_create_file("record_ftrace", 0600, pstore_ftrace_dir, NULL,
128142
&pstore_knob_fops);
129143
}

0 commit comments

Comments
 (0)