Skip to content

Commit 3afdc59

Browse files
Rishabh Bhatnagarandersson
Rishabh Bhatnagar
authored andcommitted
remoteproc: Add coredump debugfs entry
Add coredump debugfs entry to configure the type of dump that will be collected during recovery. User can select between default or inline coredump functionality. Also coredump collection can be disabled through this interface. This functionality can be configured differently for different remote processors. Signed-off-by: Rishabh Bhatnagar <[email protected]> Reviewed-by: Bjorn Andersson <[email protected]> Reviewed-by: Mathieu Poirier <[email protected]> Tested-by: Sibi Sankar <[email protected]> Reviewed-by: Sibi Sankar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bjorn Andersson <[email protected]>
1 parent c973198 commit 3afdc59

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

drivers/remoteproc/remoteproc_debugfs.c

+90
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,94 @@
2727
/* remoteproc debugfs parent dir */
2828
static struct dentry *rproc_dbg;
2929

30+
/*
31+
* A coredump-configuration-to-string lookup table, for exposing a
32+
* human readable configuration via debugfs. Always keep in sync with
33+
* enum rproc_coredump_mechanism
34+
*/
35+
static const char * const rproc_coredump_str[] = {
36+
[RPROC_COREDUMP_DEFAULT] = "default",
37+
[RPROC_COREDUMP_INLINE] = "inline",
38+
[RPROC_COREDUMP_DISABLED] = "disabled",
39+
};
40+
41+
/* Expose the current coredump configuration via debugfs */
42+
static ssize_t rproc_coredump_read(struct file *filp, char __user *userbuf,
43+
size_t count, loff_t *ppos)
44+
{
45+
struct rproc *rproc = filp->private_data;
46+
char buf[20];
47+
int len;
48+
49+
len = scnprintf(buf, sizeof(buf), "%s\n",
50+
rproc_coredump_str[rproc->dump_conf]);
51+
52+
return simple_read_from_buffer(userbuf, count, ppos, buf, len);
53+
}
54+
55+
/*
56+
* By writing to the 'coredump' debugfs entry, we control the behavior of the
57+
* coredump mechanism dynamically. The default value of this entry is "default".
58+
*
59+
* The 'coredump' debugfs entry supports these commands:
60+
*
61+
* default: This is the default coredump mechanism. When the remoteproc
62+
* crashes the entire coredump will be copied to a separate buffer
63+
* and exposed to userspace.
64+
*
65+
* inline: The coredump will not be copied to a separate buffer and the
66+
* recovery process will have to wait until data is read by
67+
* userspace. But this avoid usage of extra memory.
68+
*
69+
* disabled: This will disable coredump. Recovery will proceed without
70+
* collecting any dump.
71+
*/
72+
static ssize_t rproc_coredump_write(struct file *filp,
73+
const char __user *user_buf, size_t count,
74+
loff_t *ppos)
75+
{
76+
struct rproc *rproc = filp->private_data;
77+
int ret, err = 0;
78+
char buf[20];
79+
80+
if (count > sizeof(buf))
81+
return -EINVAL;
82+
83+
ret = copy_from_user(buf, user_buf, count);
84+
if (ret)
85+
return -EFAULT;
86+
87+
/* remove end of line */
88+
if (buf[count - 1] == '\n')
89+
buf[count - 1] = '\0';
90+
91+
if (rproc->state == RPROC_CRASHED) {
92+
dev_err(&rproc->dev, "can't change coredump configuration\n");
93+
err = -EBUSY;
94+
goto out;
95+
}
96+
97+
if (!strncmp(buf, "disable", count)) {
98+
rproc->dump_conf = RPROC_COREDUMP_DISABLED;
99+
} else if (!strncmp(buf, "inline", count)) {
100+
rproc->dump_conf = RPROC_COREDUMP_INLINE;
101+
} else if (!strncmp(buf, "default", count)) {
102+
rproc->dump_conf = RPROC_COREDUMP_DEFAULT;
103+
} else {
104+
dev_err(&rproc->dev, "Invalid coredump configuration\n");
105+
err = -EINVAL;
106+
}
107+
out:
108+
return err ? err : count;
109+
}
110+
111+
static const struct file_operations rproc_coredump_fops = {
112+
.read = rproc_coredump_read,
113+
.write = rproc_coredump_write,
114+
.open = simple_open,
115+
.llseek = generic_file_llseek,
116+
};
117+
30118
/*
31119
* Some remote processors may support dumping trace logs into a shared
32120
* memory buffer. We expose this trace buffer using debugfs, so users
@@ -337,6 +425,8 @@ void rproc_create_debug_dir(struct rproc *rproc)
337425
rproc, &rproc_rsc_table_fops);
338426
debugfs_create_file("carveout_memories", 0400, rproc->dbg_dir,
339427
rproc, &rproc_carveouts_fops);
428+
debugfs_create_file("coredump", 0600, rproc->dbg_dir,
429+
rproc, &rproc_coredump_fops);
340430
}
341431

342432
void __init rproc_init_debugfs(void)

0 commit comments

Comments
 (0)