This patch adds the specification for /sys/devices/.../coredump_disabled
attribute which allows the userspace to enable/disable devcoredump for a
particular device and drivers can use it to enable/disable functionality
accordingly. It is available when the CONFIG_DEV_COREDUMP is enabled and
driver has implemented the .coredump() callback.
Reviewed-by: Abhishek Pandit-Subedi <[email protected]>
Signed-off-by: Manish Mandlik <[email protected]>
---
Hi Arend, Greg,
The existing /sys/class/devcoredump/disabled provides only a one-way
disable functionality for devcoredump. It also disables the devcoredump
for everyone who is using it.
This and the next patch provides a way to selectively enable/disable the
devcoredump by creating a /sys/devices/.../coredump_disabled sysfs entry.
The userspace can write 0/1 to it to enable/disable devcoredump for that
particular device and drivers can use it accordingly. It will only be
available along with the /sys/devices/.../coredump sysfs entry when the
CONFIG_DEV_COREDUMP is enabled and the driver has implemented the
.coredump() callback.
Please let me know what you think about this.
Thanks,
Manish.
(no changes since v4)
Changes in v4:
- New patch in the series
Documentation/ABI/testing/sysfs-devices-coredump | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-devices-coredump b/Documentation/ABI/testing/sysfs-devices-coredump
index e459368533a4..4bcfc7dbad67 100644
--- a/Documentation/ABI/testing/sysfs-devices-coredump
+++ b/Documentation/ABI/testing/sysfs-devices-coredump
@@ -8,3 +8,17 @@ Description:
file will trigger the .coredump() callback.
Available when CONFIG_DEV_COREDUMP is enabled.
+
+What: /sys/devices/.../coredump_disabled
+Date: July 2022
+Contact: Manish Mandlik <[email protected]>
+Description:
+ The /sys/devices/.../coredump_disabled attribute can be used by
+ drivers to selectively enable/disable devcoredump functionality
+ for a device. The userspace can write 0/1 to it to control
+ enabling/disabling of devcoredump for that particular device.
+ This attribute is present only when the device is bound to a
+ driver which implements the .coredump() callback. The attribute
+ is readable and writeable.
+
+ Available when CONFIG_DEV_COREDUMP is enabled.
--
2.37.1.559.g78731f0fdb-goog
The /sys/class/devcoredump/disabled provides only one-way disable
functionality. Also, disabling devcoredump using it disables the
devcoredump functionality for everyone who is using it.
Provide a way to selectively enable/disable devcoredump for the device
which is bound to a driver that implements the '.coredump()' callback.
This adds the 'coredump_disabled' driver attribute. When the driver
implements the '.coredump()' callback, 'coredump_disabled' file is added
along with the 'coredump' file in the sysfs folder of the device upon
driver binding. The file is removed when the driver is unbound.
Drivers can use this attribute to enable/disable devcoredump and the
userspace can write 0 or 1 to /sys/devices/.../coredump_disabled sysfs
entry to control enabling/disabling of devcoredump for that device.
Signed-off-by: Manish Mandlik <[email protected]>
Reviewed-by: Abhishek Pandit-Subedi <[email protected]>
---
Changes in v5:
- Use sysfs_emit(), kstrtobool() and attribute groups
- Move 'coredump_disabled' at appropriate location in 'struct device'
Changes in v4:
- New patch in the series
drivers/base/dd.c | 33 +++++++++++++++++++++++++++++++--
drivers/base/devcoredump.c | 2 +-
include/linux/device.h | 3 +++
3 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 11b0fb6414d3..fa01901983c8 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -426,6 +426,35 @@ static ssize_t coredump_store(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_WO(coredump);
+static ssize_t coredump_disabled_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ return sysfs_emit(buf, "%d\n", dev->coredump_disabled);
+}
+
+static ssize_t coredump_disabled_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ bool disabled;
+
+ if (kstrtobool(buf, &disabled) < 0)
+ return -EINVAL;
+
+ dev->coredump_disabled = disabled;
+
+ return count;
+}
+static DEVICE_ATTR_RW(coredump_disabled);
+
+static struct attribute *dev_coredump_attrs[] = {
+ &dev_attr_coredump.attr,
+ &dev_attr_coredump_disabled.attr,
+ NULL,
+};
+ATTRIBUTE_GROUPS(dev_coredump);
+
static int driver_sysfs_add(struct device *dev)
{
int ret;
@@ -447,7 +476,7 @@ static int driver_sysfs_add(struct device *dev)
if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump)
return 0;
- ret = device_create_file(dev, &dev_attr_coredump);
+ ret = device_add_groups(dev, dev_coredump_groups);
if (!ret)
return 0;
@@ -467,7 +496,7 @@ static void driver_sysfs_remove(struct device *dev)
if (drv) {
if (drv->coredump)
- device_remove_file(dev, &dev_attr_coredump);
+ device_remove_groups(dev, dev_coredump_groups);
sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj));
sysfs_remove_link(&dev->kobj, "driver");
}
diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c
index f4d794d6bb85..c5e9af9f3181 100644
--- a/drivers/base/devcoredump.c
+++ b/drivers/base/devcoredump.c
@@ -255,7 +255,7 @@ void dev_coredumpm(struct device *dev, struct module *owner,
struct devcd_entry *devcd;
struct device *existing;
- if (devcd_disabled)
+ if (devcd_disabled || dev->coredump_disabled)
goto free;
existing = class_find_device(&devcd_class, NULL, dev,
diff --git a/include/linux/device.h b/include/linux/device.h
index dc941997795c..41aedc74a5a8 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -526,6 +526,8 @@ struct device_physical_location {
* should be set by the subsystem / bus driver that discovered
* the device.
*
+ * @coredump_disabled: Can be used to selectively enable/disable the coredump
+ * functionality for a particular device via sysfs entry.
* @offline_disabled: If set, the device is permanently online.
* @offline: Set after successful invocation of bus type's .offline().
* @of_node_reused: Set if the device-tree node is shared with an ancestor
@@ -637,6 +639,7 @@ struct device {
enum device_removable removable;
+ bool coredump_disabled:1;
bool offline_disabled:1;
bool offline:1;
bool of_node_reused:1;
--
2.37.1.559.g78731f0fdb-goog