From: Marcus Folkesson <marcus.folkesson@gmail.com>
To: Wim Van Sebroeck <wim@linux-watchdog.org>,
Guenter Roeck <linux@roeck-us.net>
Cc: linux-watchdog@vger.kernel.org,
Marcus Folkesson <marcus.folkesson@gmail.com>
Subject: [PATCH] watchdog: core: add option to make timeouts read-only
Date: Tue, 27 Mar 2018 10:09:41 +0200 [thread overview]
Message-ID: <20180327080941.29235-2-marcus.folkesson@gmail.com> (raw)
In-Reply-To: <20180327080941.29235-1-marcus.folkesson@gmail.com>
Some systems may not allow applications to configure the watchdog
timer at all. This restriction is not limited to stop the watchdog,
but also change timeouts as well.
This adds a kernel parameter to disable the ability to change the
watchdog timouts from userspace.
Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
---
drivers/watchdog/Kconfig | 9 +++++++++
drivers/watchdog/watchdog_dev.c | 12 ++++++++++--
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index aff773bcebdb..bcba48b5c88b 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -46,6 +46,15 @@ config WATCHDOG_NOWAYOUT
get killed. If you say Y here, the watchdog cannot be stopped once
it has been started.
+config WATCHDOG_TIMEOUT_READONLY
+ bool "Make timeouts read-only from userspace"
+ help
+ Say Y here if you want the watchdog timeout/pretimeout to be read-only
+ from userspace. This requires that the timeout is configured before
+ userspace takes over.
+
+ Say N if you are unsure.
+
config WATCHDOG_HANDLE_BOOT_ENABLED
bool "Update boot-enabled watchdog until userspace takes over"
default y
diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index ffbdc4642ea5..6064806a2a8d 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -87,6 +87,9 @@ static struct kthread_worker *watchdog_kworker;
static bool handle_boot_enabled =
IS_ENABLED(CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED);
+static bool timeout_is_readonly =
+ IS_ENABLED(CONFIG_WATCHDOG_TIMEOUT_READONLY);
+
static inline bool watchdog_need_worker(struct watchdog_device *wdd)
{
/* All variables in milli-seconds */
@@ -359,7 +362,7 @@ static int watchdog_set_timeout(struct watchdog_device *wdd,
{
int err = 0;
- if (!(wdd->info->options & WDIOF_SETTIMEOUT))
+ if (!(wdd->info->options & WDIOF_SETTIMEOUT) || timeout_is_readonly)
return -EOPNOTSUPP;
if (watchdog_timeout_invalid(wdd, timeout))
@@ -390,7 +393,7 @@ static int watchdog_set_pretimeout(struct watchdog_device *wdd,
{
int err = 0;
- if (!(wdd->info->options & WDIOF_PRETIMEOUT))
+ if (!(wdd->info->options & WDIOF_PRETIMEOUT) || timeout_is_readonly)
return -EOPNOTSUPP;
if (watchdog_pretimeout_invalid(wdd, timeout))
@@ -1181,3 +1184,8 @@ module_param(handle_boot_enabled, bool, 0444);
MODULE_PARM_DESC(handle_boot_enabled,
"Watchdog core auto-updates boot enabled watchdogs before userspace takes over (default="
__MODULE_STRING(IS_ENABLED(CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED)) ")");
+
+module_param(timeout_is_readonly, bool, 0444);
+MODULE_PARM_DESC(timeout_is_readonly,
+ "Watchdog timeouts is readonly from userspace (default="
+ __MODULE_STRING(IS_ENABLED(CONFIG_WATCHDOG_TIMEOUT_READONLY)) ")");
--
2.16.2
next prev parent reply other threads:[~2018-03-27 8:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-27 8:09 [PATCH 0/1] watchdog: core: add option to make timeouts read-only Marcus Folkesson
2018-03-27 8:09 ` Marcus Folkesson [this message]
2018-03-27 10:37 ` [PATCH] " Guenter Roeck
2018-03-27 11:17 ` Marcus Folkesson
2018-03-27 15:34 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180327080941.29235-2-marcus.folkesson@gmail.com \
--to=marcus.folkesson@gmail.com \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=wim@linux-watchdog.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.