Skip to content

Commit 26c9da5

Browse files
Puranjay Mohanmathieupoirier
authored andcommitted
remoteproc: Introduce sysfs_read_only flag
The remoteproc framework provides sysfs interfaces for changing the firmware name and for starting/stopping a remote processor through the sysfs files 'state' and 'firmware'. The 'coredump' file is used to set the coredump configuration. The 'recovery' sysfs file can also be used similarly to control the error recovery state machine of a remoteproc. These interfaces are currently allowed irrespective of how the remoteprocs were booted (like remoteproc self auto-boot, remoteproc client-driven boot etc). These interfaces can adversely affect a remoteproc and its clients especially when a remoteproc is being controlled by a remoteproc client driver(s). Also, not all remoteproc drivers may want to support the sysfs interfaces by default. Add support to make the remoteproc sysfs files read only by introducing a state flag 'sysfs_read_only' that the individual remoteproc drivers can set based on their usage needs. The default behavior is to allow the sysfs operations as before. Implement attribute_group->is_visible() to make the sysfs entries read only when 'sysfs_read_only' flag is set. Signed-off-by: Puranjay Mohan <p-mohan@ti.com> Link: https://lore.kernel.org/r/20220216081224.9956-2-p-mohan@ti.com Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
1 parent f89672c commit 26c9da5

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

drivers/remoteproc/remoteproc_sysfs.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,22 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr,
230230
}
231231
static DEVICE_ATTR_RO(name);
232232

233+
static umode_t rproc_is_visible(struct kobject *kobj, struct attribute *attr,
234+
int n)
235+
{
236+
struct device *dev = kobj_to_dev(kobj);
237+
struct rproc *rproc = to_rproc(dev);
238+
umode_t mode = attr->mode;
239+
240+
if (rproc->sysfs_read_only && (attr == &dev_attr_recovery.attr ||
241+
attr == &dev_attr_firmware.attr ||
242+
attr == &dev_attr_state.attr ||
243+
attr == &dev_attr_coredump.attr))
244+
mode = 0444;
245+
246+
return mode;
247+
}
248+
233249
static struct attribute *rproc_attrs[] = {
234250
&dev_attr_coredump.attr,
235251
&dev_attr_recovery.attr,
@@ -240,7 +256,8 @@ static struct attribute *rproc_attrs[] = {
240256
};
241257

242258
static const struct attribute_group rproc_devgroup = {
243-
.attrs = rproc_attrs
259+
.attrs = rproc_attrs,
260+
.is_visible = rproc_is_visible,
244261
};
245262

246263
static const struct attribute_group *rproc_devgroups[] = {

include/linux/remoteproc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ struct rproc_dump_segment {
523523
* @table_sz: size of @cached_table
524524
* @has_iommu: flag to indicate if remote processor is behind an MMU
525525
* @auto_boot: flag to indicate if remote processor should be auto-started
526+
* @sysfs_read_only: flag to make remoteproc sysfs files read only
526527
* @dump_segments: list of segments in the firmware
527528
* @nb_vdev: number of vdev currently handled by rproc
528529
* @elf_class: firmware ELF class
@@ -562,6 +563,7 @@ struct rproc {
562563
size_t table_sz;
563564
bool has_iommu;
564565
bool auto_boot;
566+
bool sysfs_read_only;
565567
struct list_head dump_segments;
566568
int nb_vdev;
567569
u8 elf_class;

0 commit comments

Comments
 (0)