Wang Wensheng (2): watchdog: Add interface to config timeout and pretimeout in sysfs watchdog: Enable CONFIG_ASCEND_WATCHDOG_SYSFS_CONFIGURE in hulk_defconfig
arch/arm64/Kconfig | 10 +++++ arch/arm64/configs/hulk_defconfig | 1 + drivers/watchdog/watchdog_dev.c | 63 +++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+)
From: Wang Wensheng wangwensheng4@huawei.com
ascend inclusion category: feature bugzilla: NA CVE: NA
Those interfaces exist already in sysfs of watchdog driver core, but they are readonly. This patch add write hook so we can config timeout and pretimeout by writing those files.
Use Kconfig ASCEND_WATCHDOG_SYSFS_CONFIGURE to select this feature.
Signed-off-by: Wang Wensheng wangwensheng4@huawei.com Acked-by: Weilong Chen chenweilong@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- arch/arm64/Kconfig | 10 ++++++ drivers/watchdog/watchdog_dev.c | 63 +++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 20d490c6b4b6..545f9cc6f5e4 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1476,6 +1476,16 @@ config ASCEND_CHARGE_MIGRATE_HUGEPAGES This option enable the feature to charge migrate hugepages to memory cgroup.
+config ASCEND_WATCHDOG_SYSFS_CONFIGURE + bool "Configure watchdog timeout and pretimeout via sysfs" + depends on WATCHDOG_SYSFS + help + Add interface for user to configure timeout and pretimeout through + sysfs. Enable this config carefully since a user could change the + timeout value without notifying the userspace process that pings the + watchdog. The kernel thread could be notified so it's ok to make that + change when the watchdog is pinged by kernel thread. + endif
endmenu diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c index 1c322caecf7f..17d91eaceafb 100644 --- a/drivers/watchdog/watchdog_dev.c +++ b/drivers/watchdog/watchdog_dev.c @@ -485,7 +485,41 @@ static ssize_t timeout_show(struct device *dev, struct device_attribute *attr,
return sprintf(buf, "%u\n", wdd->timeout); } + +#ifdef CONFIG_ASCEND_WATCHDOG_SYSFS_CONFIGURE +static int sysfs_write; +module_param(sysfs_write, int, 0); +MODULE_PARM_DESC(sysfs_write, + "enable configuring timeout and pretimeout via sysfs"); + +static ssize_t timeout_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + int ret; + unsigned int val; + struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchdog_core_data *wd_data = wdd->wd_data; + + if (!sysfs_write) + return -EOPNOTSUPP; + + ret = kstrtouint(buf, 0, &val); + if (ret) + return ret; + + mutex_lock(&wd_data->lock); + ret = watchdog_set_timeout(wdd, val); + mutex_unlock(&wd_data->lock); + + if (!ret) + ret = count; + + return ret; +} +static DEVICE_ATTR_RW(timeout); +#else static DEVICE_ATTR_RO(timeout); +#endif
static ssize_t pretimeout_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -494,7 +528,36 @@ static ssize_t pretimeout_show(struct device *dev,
return sprintf(buf, "%u\n", wdd->pretimeout); } + +#ifdef CONFIG_ASCEND_WATCHDOG_SYSFS_CONFIGURE +static ssize_t pretimeout_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + int ret; + unsigned int val; + struct watchdog_device *wdd = dev_get_drvdata(dev); + struct watchdog_core_data *wd_data = wdd->wd_data; + + if (!sysfs_write) + return -EOPNOTSUPP; + + ret = kstrtouint(buf, 0, &val); + if (ret) + return ret; + + mutex_lock(&wd_data->lock); + ret = watchdog_set_pretimeout(wdd, val); + mutex_unlock(&wd_data->lock); + + if (!ret) + ret = count; + + return ret; +} +static DEVICE_ATTR_RW(pretimeout); +#else static DEVICE_ATTR_RO(pretimeout); +#endif
static ssize_t identity_show(struct device *dev, struct device_attribute *attr, char *buf)
From: Wang Wensheng wangwensheng4@huawei.com
ascend inclusion category: bugfix bugzilla: NA CVE: NA
Enable CONFIG_ASCEND_WATCHDOG_SYSFS_CONFIGURE in hulk_defconfig
Signed-off-by: Wang Wensheng wangwensheng4@huawei.com Acked-by: Weilong Chen chenweilong@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- arch/arm64/configs/hulk_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/arch/arm64/configs/hulk_defconfig b/arch/arm64/configs/hulk_defconfig index 32be4952da5e..92b8b1e361fa 100644 --- a/arch/arm64/configs/hulk_defconfig +++ b/arch/arm64/configs/hulk_defconfig @@ -479,6 +479,7 @@ CONFIG_ASCEND_DVPP_MMAP=y CONFIG_ASCEND_OOM=y CONFIG_ASCEND_IOPF_HIPRI=y CONFIG_ASCEND_CHARGE_MIGRATE_HUGEPAGES=y +CONFIG_ASCEND_WATCHDOG_SYSFS_CONFIGURE=y CONFIG_ARM64_CNP=y
#