2019-06-21 00:28:46 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-07-23 02:55:18 +08:00
|
|
|
/*
|
|
|
|
* watchdog_dev.c
|
|
|
|
*
|
|
|
|
* (c) Copyright 2008-2011 Alan Cox <alan@lxorguk.ukuu.org.uk>,
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* (c) Copyright 2008-2011 Wim Van Sebroeck <wim@iguana.be>.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This source code is part of the generic code that can be used
|
|
|
|
* by all the watchdog timer drivers.
|
|
|
|
*
|
|
|
|
* This part of the generic code takes care of the following
|
|
|
|
* misc device: /dev/watchdog.
|
|
|
|
*
|
|
|
|
* Based on source code of the following authors:
|
|
|
|
* Matt Domsch <Matt_Domsch@dell.com>,
|
|
|
|
* Rob Radez <rob@osinvestor.com>,
|
|
|
|
* Rusty Lynch <rusty@linux.co.intel.com>
|
|
|
|
* Satyam Sharma <satyam@infradead.org>
|
|
|
|
* Randy Dunlap <randy.dunlap@oracle.com>
|
|
|
|
*
|
|
|
|
* Neither Alan Cox, CymruNet Ltd., Wim Van Sebroeck nor Iguana vzw.
|
|
|
|
* admit liability nor provide warranty for any of this software.
|
|
|
|
* This material is provided "AS-IS" and at no charge.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
#include <linux/cdev.h> /* For character device */
|
2011-07-23 02:55:18 +08:00
|
|
|
#include <linux/errno.h> /* For the -ENODEV/... values */
|
|
|
|
#include <linux/fs.h> /* For file operations */
|
|
|
|
#include <linux/init.h> /* For __init/__exit/... */
|
2018-01-18 19:11:21 +08:00
|
|
|
#include <linux/hrtimer.h> /* For hrtimers */
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
#include <linux/kernel.h> /* For printk/panic/... */
|
2018-01-18 19:11:21 +08:00
|
|
|
#include <linux/kthread.h> /* For kthread_work */
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
#include <linux/miscdevice.h> /* For handling misc devices */
|
|
|
|
#include <linux/module.h> /* For module stuff/... */
|
|
|
|
#include <linux/mutex.h> /* For mutexes */
|
|
|
|
#include <linux/slab.h> /* For memory functions */
|
|
|
|
#include <linux/types.h> /* For standard types (like size_t) */
|
|
|
|
#include <linux/watchdog.h> /* For watchdog specific items */
|
2011-07-23 02:55:18 +08:00
|
|
|
#include <linux/uaccess.h> /* For copy_to_user/put_user/... */
|
|
|
|
|
2017-12-08 18:18:35 +08:00
|
|
|
#include <uapi/linux/sched/types.h> /* For struct sched_param */
|
|
|
|
|
2012-05-21 21:31:06 +08:00
|
|
|
#include "watchdog_core.h"
|
2016-10-07 20:39:54 +08:00
|
|
|
#include "watchdog_pretimeout.h"
|
2012-04-21 04:28:24 +08:00
|
|
|
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
/*
|
|
|
|
* struct watchdog_core_data - watchdog core internal data
|
2019-10-08 19:29:34 +08:00
|
|
|
* @dev: The watchdog's internal device
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
* @cdev: The watchdog's Character device.
|
|
|
|
* @wdd: Pointer to watchdog device.
|
|
|
|
* @lock: Lock for watchdog core.
|
|
|
|
* @status: Watchdog core internal status bits.
|
|
|
|
*/
|
|
|
|
struct watchdog_core_data {
|
2019-10-08 19:29:34 +08:00
|
|
|
struct device dev;
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
struct cdev cdev;
|
|
|
|
struct watchdog_device *wdd;
|
|
|
|
struct mutex lock;
|
2018-01-18 19:11:21 +08:00
|
|
|
ktime_t last_keepalive;
|
|
|
|
ktime_t last_hw_keepalive;
|
watchdog: introduce watchdog.open_timeout commandline parameter
The watchdog framework takes care of feeding a hardware watchdog until
userspace opens /dev/watchdogN. If that never happens for some reason
(buggy init script, corrupt root filesystem or whatnot) but the kernel
itself is fine, the machine stays up indefinitely. This patch allows
setting an upper limit for how long the kernel will take care of the
watchdog, thus ensuring that the watchdog will eventually reset the
machine.
A value of 0 (the default) means infinite timeout, preserving the
current behaviour.
This is particularly useful for embedded devices where some fallback
logic is implemented in the bootloader (e.g., use a different root
partition, boot from network, ...).
There is already handle_boot_enabled serving a similar purpose. However,
such a binary choice is unsuitable if the hardware watchdog cannot be
programmed by the bootloader to provide a timeout long enough for
userspace to get up and running. Many of the embedded devices we see use
external (gpio-triggered) watchdogs with a fixed timeout of the order of
1-2 seconds.
The open timeout only applies for the first open from
userspace. Should userspace need to close the watchdog device, with
the intention of re-opening it shortly, the application can emulate
the open timeout feature by combining the nowayout feature with an
appropriate WDIOC_SETTIMEOUT immediately prior to closing the device.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
2019-06-05 22:06:41 +08:00
|
|
|
ktime_t open_deadline;
|
2018-01-18 19:11:21 +08:00
|
|
|
struct hrtimer timer;
|
|
|
|
struct kthread_work work;
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
unsigned long status; /* Internal status bits */
|
|
|
|
#define _WDOG_DEV_OPEN 0 /* Opened ? */
|
|
|
|
#define _WDOG_ALLOW_RELEASE 1 /* Did we receive the magic char ? */
|
2016-07-18 06:04:11 +08:00
|
|
|
#define _WDOG_KEEPALIVE 2 /* Did we receive a keepalive ? */
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
};
|
|
|
|
|
2012-05-11 03:48:59 +08:00
|
|
|
/* the dev_t structure to store the dynamically allocated watchdog devices */
|
|
|
|
static dev_t watchdog_devt;
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
/* Reference to watchdog device behind /dev/watchdog */
|
|
|
|
static struct watchdog_core_data *old_wd_data;
|
2011-07-23 02:55:18 +08:00
|
|
|
|
2017-12-08 18:18:35 +08:00
|
|
|
static struct kthread_worker *watchdog_kworker;
|
2016-02-29 05:12:15 +08:00
|
|
|
|
2017-05-12 20:05:32 +08:00
|
|
|
static bool handle_boot_enabled =
|
|
|
|
IS_ENABLED(CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED);
|
|
|
|
|
2019-06-05 22:06:43 +08:00
|
|
|
static unsigned open_timeout = CONFIG_WATCHDOG_OPEN_TIMEOUT;
|
watchdog: introduce watchdog.open_timeout commandline parameter
The watchdog framework takes care of feeding a hardware watchdog until
userspace opens /dev/watchdogN. If that never happens for some reason
(buggy init script, corrupt root filesystem or whatnot) but the kernel
itself is fine, the machine stays up indefinitely. This patch allows
setting an upper limit for how long the kernel will take care of the
watchdog, thus ensuring that the watchdog will eventually reset the
machine.
A value of 0 (the default) means infinite timeout, preserving the
current behaviour.
This is particularly useful for embedded devices where some fallback
logic is implemented in the bootloader (e.g., use a different root
partition, boot from network, ...).
There is already handle_boot_enabled serving a similar purpose. However,
such a binary choice is unsuitable if the hardware watchdog cannot be
programmed by the bootloader to provide a timeout long enough for
userspace to get up and running. Many of the embedded devices we see use
external (gpio-triggered) watchdogs with a fixed timeout of the order of
1-2 seconds.
The open timeout only applies for the first open from
userspace. Should userspace need to close the watchdog device, with
the intention of re-opening it shortly, the application can emulate
the open timeout feature by combining the nowayout feature with an
appropriate WDIOC_SETTIMEOUT immediately prior to closing the device.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
2019-06-05 22:06:41 +08:00
|
|
|
|
|
|
|
static bool watchdog_past_open_deadline(struct watchdog_core_data *data)
|
|
|
|
{
|
|
|
|
return ktime_after(ktime_get(), data->open_deadline);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void watchdog_set_open_deadline(struct watchdog_core_data *data)
|
|
|
|
{
|
|
|
|
data->open_deadline = open_timeout ?
|
|
|
|
ktime_get() + ktime_set(open_timeout, 0) : KTIME_MAX;
|
|
|
|
}
|
|
|
|
|
2016-02-29 05:12:15 +08:00
|
|
|
static inline bool watchdog_need_worker(struct watchdog_device *wdd)
|
|
|
|
{
|
|
|
|
/* All variables in milli-seconds */
|
|
|
|
unsigned int hm = wdd->max_hw_heartbeat_ms;
|
|
|
|
unsigned int t = wdd->timeout * 1000;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A worker to generate heartbeat requests is needed if all of the
|
|
|
|
* following conditions are true.
|
|
|
|
* - Userspace activated the watchdog.
|
|
|
|
* - The driver provided a value for the maximum hardware timeout, and
|
|
|
|
* thus is aware that the framework supports generating heartbeat
|
|
|
|
* requests.
|
|
|
|
* - Userspace requests a longer timeout than the hardware can handle.
|
watchdog: change watchdog_need_worker logic
If the driver indicates that the watchdog is running, the framework
should feed it until userspace opens the device, regardless of whether
the driver has set max_hw_heartbeat_ms.
This patch only affects the case where wdd->max_hw_heartbeat_ms is
zero, wdd->timeout is non-zero, the watchdog is not active and the
hardware device is running (*):
- If wdd->timeout is zero, watchdog_need_worker() returns false both
before and after this patch, and watchdog_next_keepalive() is not
called.
- If watchdog_active(wdd), the return value from watchdog_need_worker
is also the same as before (namely, hm && t > hm). Hence in that case,
watchdog_next_keepalive() is only called if hm == max_hw_heartbeat_ms
is non-zero, so the change to min_not_zero there is a no-op.
- If the watchdog is not active and the device is not running, we
return false from watchdog_need_worker just as before.
That leaves the watchdog_hw_running(wdd) && !watchdog_active(wdd) &&
wdd->timeout case. Again, it's easy to see that if
wdd->max_hw_heartbeat_ms is non-zero, we return true from
watchdog_need_worker with and without this patch, and the logic in
watchdog_next_keepalive is unchanged. Finally, if
wdd->max_hw_heartbeat_ms is 0, we used to end up in the
cancel_delayed_work branch, whereas with this patch we end up
scheduling a ping timeout_ms/2 from now.
(*) This should imply that no current kernel drivers are affected,
since the only drivers which explicitly set WDOG_HW_RUNNING are
imx2_wdt.c and dw_wdt.c, both of which also provide a non-zero value
for max_hw_heartbeat_ms. The watchdog core also sets WDOG_HW_RUNNING,
but only when the driver doesn't provide ->stop, in which case it
must, according to Documentation/watchdog/watchdog-kernel-api.txt, set
max_hw_heartbeat_ms.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2016-07-14 17:16:26 +08:00
|
|
|
*
|
|
|
|
* Alternatively, if userspace has not opened the watchdog
|
|
|
|
* device, we take care of feeding the watchdog if it is
|
|
|
|
* running.
|
2016-02-29 05:12:15 +08:00
|
|
|
*/
|
watchdog: change watchdog_need_worker logic
If the driver indicates that the watchdog is running, the framework
should feed it until userspace opens the device, regardless of whether
the driver has set max_hw_heartbeat_ms.
This patch only affects the case where wdd->max_hw_heartbeat_ms is
zero, wdd->timeout is non-zero, the watchdog is not active and the
hardware device is running (*):
- If wdd->timeout is zero, watchdog_need_worker() returns false both
before and after this patch, and watchdog_next_keepalive() is not
called.
- If watchdog_active(wdd), the return value from watchdog_need_worker
is also the same as before (namely, hm && t > hm). Hence in that case,
watchdog_next_keepalive() is only called if hm == max_hw_heartbeat_ms
is non-zero, so the change to min_not_zero there is a no-op.
- If the watchdog is not active and the device is not running, we
return false from watchdog_need_worker just as before.
That leaves the watchdog_hw_running(wdd) && !watchdog_active(wdd) &&
wdd->timeout case. Again, it's easy to see that if
wdd->max_hw_heartbeat_ms is non-zero, we return true from
watchdog_need_worker with and without this patch, and the logic in
watchdog_next_keepalive is unchanged. Finally, if
wdd->max_hw_heartbeat_ms is 0, we used to end up in the
cancel_delayed_work branch, whereas with this patch we end up
scheduling a ping timeout_ms/2 from now.
(*) This should imply that no current kernel drivers are affected,
since the only drivers which explicitly set WDOG_HW_RUNNING are
imx2_wdt.c and dw_wdt.c, both of which also provide a non-zero value
for max_hw_heartbeat_ms. The watchdog core also sets WDOG_HW_RUNNING,
but only when the driver doesn't provide ->stop, in which case it
must, according to Documentation/watchdog/watchdog-kernel-api.txt, set
max_hw_heartbeat_ms.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2016-07-14 17:16:26 +08:00
|
|
|
return (hm && watchdog_active(wdd) && t > hm) ||
|
|
|
|
(t && !watchdog_active(wdd) && watchdog_hw_running(wdd));
|
2016-02-29 05:12:15 +08:00
|
|
|
}
|
|
|
|
|
2018-01-18 19:11:21 +08:00
|
|
|
static ktime_t watchdog_next_keepalive(struct watchdog_device *wdd)
|
2016-02-29 05:12:15 +08:00
|
|
|
{
|
|
|
|
struct watchdog_core_data *wd_data = wdd->wd_data;
|
|
|
|
unsigned int timeout_ms = wdd->timeout * 1000;
|
2018-01-18 19:11:21 +08:00
|
|
|
ktime_t keepalive_interval;
|
|
|
|
ktime_t last_heartbeat, latest_heartbeat;
|
|
|
|
ktime_t virt_timeout;
|
2016-02-29 05:12:15 +08:00
|
|
|
unsigned int hw_heartbeat_ms;
|
|
|
|
|
2019-06-05 22:06:44 +08:00
|
|
|
if (watchdog_active(wdd))
|
|
|
|
virt_timeout = ktime_add(wd_data->last_keepalive,
|
|
|
|
ms_to_ktime(timeout_ms));
|
|
|
|
else
|
|
|
|
virt_timeout = wd_data->open_deadline;
|
|
|
|
|
watchdog: change watchdog_need_worker logic
If the driver indicates that the watchdog is running, the framework
should feed it until userspace opens the device, regardless of whether
the driver has set max_hw_heartbeat_ms.
This patch only affects the case where wdd->max_hw_heartbeat_ms is
zero, wdd->timeout is non-zero, the watchdog is not active and the
hardware device is running (*):
- If wdd->timeout is zero, watchdog_need_worker() returns false both
before and after this patch, and watchdog_next_keepalive() is not
called.
- If watchdog_active(wdd), the return value from watchdog_need_worker
is also the same as before (namely, hm && t > hm). Hence in that case,
watchdog_next_keepalive() is only called if hm == max_hw_heartbeat_ms
is non-zero, so the change to min_not_zero there is a no-op.
- If the watchdog is not active and the device is not running, we
return false from watchdog_need_worker just as before.
That leaves the watchdog_hw_running(wdd) && !watchdog_active(wdd) &&
wdd->timeout case. Again, it's easy to see that if
wdd->max_hw_heartbeat_ms is non-zero, we return true from
watchdog_need_worker with and without this patch, and the logic in
watchdog_next_keepalive is unchanged. Finally, if
wdd->max_hw_heartbeat_ms is 0, we used to end up in the
cancel_delayed_work branch, whereas with this patch we end up
scheduling a ping timeout_ms/2 from now.
(*) This should imply that no current kernel drivers are affected,
since the only drivers which explicitly set WDOG_HW_RUNNING are
imx2_wdt.c and dw_wdt.c, both of which also provide a non-zero value
for max_hw_heartbeat_ms. The watchdog core also sets WDOG_HW_RUNNING,
but only when the driver doesn't provide ->stop, in which case it
must, according to Documentation/watchdog/watchdog-kernel-api.txt, set
max_hw_heartbeat_ms.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2016-07-14 17:16:26 +08:00
|
|
|
hw_heartbeat_ms = min_not_zero(timeout_ms, wdd->max_hw_heartbeat_ms);
|
2018-01-18 19:11:21 +08:00
|
|
|
keepalive_interval = ms_to_ktime(hw_heartbeat_ms / 2);
|
2016-02-29 05:12:15 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To ensure that the watchdog times out wdd->timeout seconds
|
|
|
|
* after the most recent ping from userspace, the last
|
|
|
|
* worker ping has to come in hw_heartbeat_ms before this timeout.
|
|
|
|
*/
|
2018-01-18 19:11:21 +08:00
|
|
|
last_heartbeat = ktime_sub(virt_timeout, ms_to_ktime(hw_heartbeat_ms));
|
|
|
|
latest_heartbeat = ktime_sub(last_heartbeat, ktime_get());
|
|
|
|
if (ktime_before(latest_heartbeat, keepalive_interval))
|
|
|
|
return latest_heartbeat;
|
|
|
|
return keepalive_interval;
|
2016-02-29 05:12:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void watchdog_update_worker(struct watchdog_device *wdd)
|
|
|
|
{
|
|
|
|
struct watchdog_core_data *wd_data = wdd->wd_data;
|
|
|
|
|
|
|
|
if (watchdog_need_worker(wdd)) {
|
2018-01-18 19:11:21 +08:00
|
|
|
ktime_t t = watchdog_next_keepalive(wdd);
|
2016-02-29 05:12:15 +08:00
|
|
|
|
|
|
|
if (t > 0)
|
2019-11-05 22:45:06 +08:00
|
|
|
hrtimer_start(&wd_data->timer, t,
|
|
|
|
HRTIMER_MODE_REL_HARD);
|
2016-02-29 05:12:15 +08:00
|
|
|
} else {
|
2018-01-18 19:11:21 +08:00
|
|
|
hrtimer_cancel(&wd_data->timer);
|
2016-02-29 05:12:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __watchdog_ping(struct watchdog_device *wdd)
|
|
|
|
{
|
2016-02-29 05:12:18 +08:00
|
|
|
struct watchdog_core_data *wd_data = wdd->wd_data;
|
2018-01-18 19:11:21 +08:00
|
|
|
ktime_t earliest_keepalive, now;
|
2016-02-29 05:12:15 +08:00
|
|
|
int err;
|
|
|
|
|
2018-01-18 19:11:21 +08:00
|
|
|
earliest_keepalive = ktime_add(wd_data->last_hw_keepalive,
|
|
|
|
ms_to_ktime(wdd->min_hw_heartbeat_ms));
|
|
|
|
now = ktime_get();
|
|
|
|
|
|
|
|
if (ktime_after(earliest_keepalive, now)) {
|
|
|
|
hrtimer_start(&wd_data->timer,
|
|
|
|
ktime_sub(earliest_keepalive, now),
|
2019-11-05 22:45:06 +08:00
|
|
|
HRTIMER_MODE_REL_HARD);
|
2016-02-29 05:12:18 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-18 19:11:21 +08:00
|
|
|
wd_data->last_hw_keepalive = now;
|
2016-02-29 05:12:18 +08:00
|
|
|
|
2016-02-29 05:12:15 +08:00
|
|
|
if (wdd->ops->ping)
|
|
|
|
err = wdd->ops->ping(wdd); /* ping the watchdog */
|
|
|
|
else
|
|
|
|
err = wdd->ops->start(wdd); /* restart watchdog */
|
|
|
|
|
|
|
|
watchdog_update_worker(wdd);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-07-23 02:55:18 +08:00
|
|
|
/*
|
|
|
|
* watchdog_ping: ping the watchdog.
|
2015-09-29 16:27:25 +08:00
|
|
|
* @wdd: the watchdog device to ping
|
2011-07-23 02:55:18 +08:00
|
|
|
*
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
* The caller must hold wd_data->lock.
|
|
|
|
*
|
2011-07-23 02:55:18 +08:00
|
|
|
* If the watchdog has no own ping operation then it needs to be
|
|
|
|
* restarted via the start operation. This wrapper function does
|
|
|
|
* exactly that.
|
2011-07-23 02:57:55 +08:00
|
|
|
* We only ping when the watchdog device is running.
|
2011-07-23 02:55:18 +08:00
|
|
|
*/
|
|
|
|
|
2015-09-29 16:27:25 +08:00
|
|
|
static int watchdog_ping(struct watchdog_device *wdd)
|
2011-07-23 02:55:18 +08:00
|
|
|
{
|
2016-02-29 05:12:15 +08:00
|
|
|
struct watchdog_core_data *wd_data = wdd->wd_data;
|
2012-05-22 17:40:26 +08:00
|
|
|
|
2016-02-29 05:12:16 +08:00
|
|
|
if (!watchdog_active(wdd) && !watchdog_hw_running(wdd))
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
return 0;
|
2012-05-22 17:40:26 +08:00
|
|
|
|
2016-07-18 06:04:11 +08:00
|
|
|
set_bit(_WDOG_KEEPALIVE, &wd_data->status);
|
|
|
|
|
2018-01-18 19:11:21 +08:00
|
|
|
wd_data->last_keepalive = ktime_get();
|
2016-02-29 05:12:15 +08:00
|
|
|
return __watchdog_ping(wdd);
|
|
|
|
}
|
2012-05-22 17:40:26 +08:00
|
|
|
|
2017-05-30 16:56:45 +08:00
|
|
|
static bool watchdog_worker_should_ping(struct watchdog_core_data *wd_data)
|
|
|
|
{
|
|
|
|
struct watchdog_device *wdd = wd_data->wdd;
|
|
|
|
|
watchdog: introduce watchdog.open_timeout commandline parameter
The watchdog framework takes care of feeding a hardware watchdog until
userspace opens /dev/watchdogN. If that never happens for some reason
(buggy init script, corrupt root filesystem or whatnot) but the kernel
itself is fine, the machine stays up indefinitely. This patch allows
setting an upper limit for how long the kernel will take care of the
watchdog, thus ensuring that the watchdog will eventually reset the
machine.
A value of 0 (the default) means infinite timeout, preserving the
current behaviour.
This is particularly useful for embedded devices where some fallback
logic is implemented in the bootloader (e.g., use a different root
partition, boot from network, ...).
There is already handle_boot_enabled serving a similar purpose. However,
such a binary choice is unsuitable if the hardware watchdog cannot be
programmed by the bootloader to provide a timeout long enough for
userspace to get up and running. Many of the embedded devices we see use
external (gpio-triggered) watchdogs with a fixed timeout of the order of
1-2 seconds.
The open timeout only applies for the first open from
userspace. Should userspace need to close the watchdog device, with
the intention of re-opening it shortly, the application can emulate
the open timeout feature by combining the nowayout feature with an
appropriate WDIOC_SETTIMEOUT immediately prior to closing the device.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
2019-06-05 22:06:41 +08:00
|
|
|
if (!wdd)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (watchdog_active(wdd))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return watchdog_hw_running(wdd) && !watchdog_past_open_deadline(wd_data);
|
2017-05-30 16:56:45 +08:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:18:35 +08:00
|
|
|
static void watchdog_ping_work(struct kthread_work *work)
|
2016-02-29 05:12:15 +08:00
|
|
|
{
|
|
|
|
struct watchdog_core_data *wd_data;
|
|
|
|
|
2018-01-18 19:11:21 +08:00
|
|
|
wd_data = container_of(work, struct watchdog_core_data, work);
|
2016-02-29 05:12:15 +08:00
|
|
|
|
|
|
|
mutex_lock(&wd_data->lock);
|
2017-05-30 16:56:45 +08:00
|
|
|
if (watchdog_worker_should_ping(wd_data))
|
|
|
|
__watchdog_ping(wd_data->wdd);
|
2016-02-29 05:12:15 +08:00
|
|
|
mutex_unlock(&wd_data->lock);
|
2011-07-23 02:57:55 +08:00
|
|
|
}
|
|
|
|
|
2018-01-18 19:11:21 +08:00
|
|
|
static enum hrtimer_restart watchdog_timer_expired(struct hrtimer *timer)
|
|
|
|
{
|
|
|
|
struct watchdog_core_data *wd_data;
|
|
|
|
|
|
|
|
wd_data = container_of(timer, struct watchdog_core_data, timer);
|
|
|
|
|
|
|
|
kthread_queue_work(watchdog_kworker, &wd_data->work);
|
|
|
|
return HRTIMER_NORESTART;
|
|
|
|
}
|
|
|
|
|
2011-07-23 02:57:55 +08:00
|
|
|
/*
|
|
|
|
* watchdog_start: wrapper to start the watchdog.
|
2015-09-29 16:27:25 +08:00
|
|
|
* @wdd: the watchdog device to start
|
2011-07-23 02:57:55 +08:00
|
|
|
*
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
* The caller must hold wd_data->lock.
|
|
|
|
*
|
2011-07-23 02:57:55 +08:00
|
|
|
* Start the watchdog if it is not active and mark it active.
|
|
|
|
* This function returns zero on success or a negative errno code for
|
|
|
|
* failure.
|
|
|
|
*/
|
|
|
|
|
2015-09-29 16:27:25 +08:00
|
|
|
static int watchdog_start(struct watchdog_device *wdd)
|
2011-07-23 02:57:55 +08:00
|
|
|
{
|
2016-02-29 05:12:15 +08:00
|
|
|
struct watchdog_core_data *wd_data = wdd->wd_data;
|
2018-01-18 19:11:21 +08:00
|
|
|
ktime_t started_at;
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
int err;
|
2012-05-22 17:40:26 +08:00
|
|
|
|
2015-09-29 16:27:25 +08:00
|
|
|
if (watchdog_active(wdd))
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
return 0;
|
2011-07-23 02:57:55 +08:00
|
|
|
|
2016-07-18 06:04:11 +08:00
|
|
|
set_bit(_WDOG_KEEPALIVE, &wd_data->status);
|
|
|
|
|
2018-01-18 19:11:21 +08:00
|
|
|
started_at = ktime_get();
|
2016-02-29 05:12:16 +08:00
|
|
|
if (watchdog_hw_running(wdd) && wdd->ops->ping)
|
|
|
|
err = wdd->ops->ping(wdd);
|
|
|
|
else
|
|
|
|
err = wdd->ops->start(wdd);
|
2016-02-29 05:12:15 +08:00
|
|
|
if (err == 0) {
|
2015-09-29 16:27:25 +08:00
|
|
|
set_bit(WDOG_ACTIVE, &wdd->status);
|
2016-02-29 05:12:15 +08:00
|
|
|
wd_data->last_keepalive = started_at;
|
2020-03-12 17:58:06 +08:00
|
|
|
wd_data->last_hw_keepalive = started_at;
|
2016-02-29 05:12:15 +08:00
|
|
|
watchdog_update_worker(wdd);
|
|
|
|
}
|
2012-05-22 17:40:26 +08:00
|
|
|
|
|
|
|
return err;
|
2011-07-23 02:57:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* watchdog_stop: wrapper to stop the watchdog.
|
2015-09-29 16:27:25 +08:00
|
|
|
* @wdd: the watchdog device to stop
|
2011-07-23 02:57:55 +08:00
|
|
|
*
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
* The caller must hold wd_data->lock.
|
|
|
|
*
|
2011-07-23 02:57:55 +08:00
|
|
|
* Stop the watchdog if it is still active and unmark it active.
|
|
|
|
* This function returns zero on success or a negative errno code for
|
|
|
|
* failure.
|
2011-07-23 02:59:17 +08:00
|
|
|
* If the 'nowayout' feature was set, the watchdog cannot be stopped.
|
2011-07-23 02:57:55 +08:00
|
|
|
*/
|
|
|
|
|
2015-09-29 16:27:25 +08:00
|
|
|
static int watchdog_stop(struct watchdog_device *wdd)
|
2011-07-23 02:57:55 +08:00
|
|
|
{
|
2016-02-29 05:12:16 +08:00
|
|
|
int err = 0;
|
2012-05-22 17:40:26 +08:00
|
|
|
|
2015-09-29 16:27:25 +08:00
|
|
|
if (!watchdog_active(wdd))
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
return 0;
|
2011-07-23 02:59:17 +08:00
|
|
|
|
2015-09-29 16:27:25 +08:00
|
|
|
if (test_bit(WDOG_NO_WAY_OUT, &wdd->status)) {
|
2016-01-04 07:11:58 +08:00
|
|
|
pr_info("watchdog%d: nowayout prevents watchdog being stopped!\n",
|
|
|
|
wdd->id);
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
return -EBUSY;
|
2011-07-23 02:59:17 +08:00
|
|
|
}
|
2011-07-23 02:57:55 +08:00
|
|
|
|
2016-07-22 05:21:56 +08:00
|
|
|
if (wdd->ops->stop) {
|
|
|
|
clear_bit(WDOG_HW_RUNNING, &wdd->status);
|
2016-02-29 05:12:17 +08:00
|
|
|
err = wdd->ops->stop(wdd);
|
2016-07-22 05:21:56 +08:00
|
|
|
} else {
|
2016-02-29 05:12:17 +08:00
|
|
|
set_bit(WDOG_HW_RUNNING, &wdd->status);
|
2016-07-22 05:21:56 +08:00
|
|
|
}
|
2016-02-29 05:12:17 +08:00
|
|
|
|
2016-02-29 05:12:15 +08:00
|
|
|
if (err == 0) {
|
2015-09-29 16:27:25 +08:00
|
|
|
clear_bit(WDOG_ACTIVE, &wdd->status);
|
2016-02-29 05:12:16 +08:00
|
|
|
watchdog_update_worker(wdd);
|
2016-02-29 05:12:15 +08:00
|
|
|
}
|
2012-05-22 17:40:26 +08:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* watchdog_get_status: wrapper to get the watchdog status
|
2015-09-29 16:27:25 +08:00
|
|
|
* @wdd: the watchdog device to get the status from
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
*
|
|
|
|
* The caller must hold wd_data->lock.
|
2012-05-22 17:40:26 +08:00
|
|
|
*
|
|
|
|
* Get the watchdog's status flags.
|
|
|
|
*/
|
|
|
|
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
static unsigned int watchdog_get_status(struct watchdog_device *wdd)
|
2012-05-22 17:40:26 +08:00
|
|
|
{
|
2016-07-18 06:04:11 +08:00
|
|
|
struct watchdog_core_data *wd_data = wdd->wd_data;
|
|
|
|
unsigned int status;
|
2012-05-22 17:40:26 +08:00
|
|
|
|
2016-07-18 06:04:11 +08:00
|
|
|
if (wdd->ops->status)
|
|
|
|
status = wdd->ops->status(wdd);
|
|
|
|
else
|
|
|
|
status = wdd->bootstatus & (WDIOF_CARDRESET |
|
|
|
|
WDIOF_OVERHEAT |
|
|
|
|
WDIOF_FANFAULT |
|
|
|
|
WDIOF_EXTERN1 |
|
|
|
|
WDIOF_EXTERN2 |
|
|
|
|
WDIOF_POWERUNDER |
|
|
|
|
WDIOF_POWEROVER);
|
|
|
|
|
|
|
|
if (test_bit(_WDOG_ALLOW_RELEASE, &wd_data->status))
|
|
|
|
status |= WDIOF_MAGICCLOSE;
|
|
|
|
|
|
|
|
if (test_and_clear_bit(_WDOG_KEEPALIVE, &wd_data->status))
|
|
|
|
status |= WDIOF_KEEPALIVEPING;
|
|
|
|
|
|
|
|
return status;
|
2012-05-22 17:40:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* watchdog_set_timeout: set the watchdog timer timeout
|
2015-09-29 16:27:25 +08:00
|
|
|
* @wdd: the watchdog device to set the timeout for
|
2012-05-22 17:40:26 +08:00
|
|
|
* @timeout: timeout to set in seconds
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
*
|
|
|
|
* The caller must hold wd_data->lock.
|
2012-05-22 17:40:26 +08:00
|
|
|
*/
|
|
|
|
|
2015-09-29 16:27:25 +08:00
|
|
|
static int watchdog_set_timeout(struct watchdog_device *wdd,
|
2012-05-22 17:40:26 +08:00
|
|
|
unsigned int timeout)
|
|
|
|
{
|
2016-02-29 05:12:14 +08:00
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (!(wdd->info->options & WDIOF_SETTIMEOUT))
|
2012-05-22 17:40:26 +08:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2015-09-29 16:27:25 +08:00
|
|
|
if (watchdog_timeout_invalid(wdd, timeout))
|
2012-05-22 17:40:26 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2016-08-31 19:52:41 +08:00
|
|
|
if (wdd->ops->set_timeout) {
|
2016-02-29 05:12:14 +08:00
|
|
|
err = wdd->ops->set_timeout(wdd, timeout);
|
2016-08-31 19:52:41 +08:00
|
|
|
} else {
|
2016-02-29 05:12:14 +08:00
|
|
|
wdd->timeout = timeout;
|
2016-08-31 19:52:41 +08:00
|
|
|
/* Disable pretimeout if it doesn't fit the new timeout */
|
|
|
|
if (wdd->pretimeout >= wdd->timeout)
|
|
|
|
wdd->pretimeout = 0;
|
|
|
|
}
|
2016-02-29 05:12:14 +08:00
|
|
|
|
2016-02-29 05:12:15 +08:00
|
|
|
watchdog_update_worker(wdd);
|
|
|
|
|
2016-02-29 05:12:14 +08:00
|
|
|
return err;
|
2012-05-22 17:40:26 +08:00
|
|
|
}
|
|
|
|
|
2016-08-31 19:52:41 +08:00
|
|
|
/*
|
|
|
|
* watchdog_set_pretimeout: set the watchdog timer pretimeout
|
|
|
|
* @wdd: the watchdog device to set the timeout for
|
|
|
|
* @timeout: pretimeout to set in seconds
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int watchdog_set_pretimeout(struct watchdog_device *wdd,
|
|
|
|
unsigned int timeout)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (!(wdd->info->options & WDIOF_PRETIMEOUT))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
if (watchdog_pretimeout_invalid(wdd, timeout))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (wdd->ops->set_pretimeout)
|
|
|
|
err = wdd->ops->set_pretimeout(wdd, timeout);
|
|
|
|
else
|
|
|
|
wdd->pretimeout = timeout;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-05-22 17:40:26 +08:00
|
|
|
/*
|
|
|
|
* watchdog_get_timeleft: wrapper to get the time left before a reboot
|
2015-09-29 16:27:25 +08:00
|
|
|
* @wdd: the watchdog device to get the remaining time from
|
2012-05-22 17:40:26 +08:00
|
|
|
* @timeleft: the time that's left
|
|
|
|
*
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
* The caller must hold wd_data->lock.
|
|
|
|
*
|
2012-05-22 17:40:26 +08:00
|
|
|
* Get the time before a watchdog will reboot (if not pinged).
|
|
|
|
*/
|
|
|
|
|
2015-09-29 16:27:25 +08:00
|
|
|
static int watchdog_get_timeleft(struct watchdog_device *wdd,
|
2012-05-22 17:40:26 +08:00
|
|
|
unsigned int *timeleft)
|
|
|
|
{
|
|
|
|
*timeleft = 0;
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
|
2015-09-29 16:27:25 +08:00
|
|
|
if (!wdd->ops->get_timeleft)
|
2012-05-22 17:40:26 +08:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2015-09-29 16:27:25 +08:00
|
|
|
*timeleft = wdd->ops->get_timeleft(wdd);
|
2012-05-22 17:40:26 +08:00
|
|
|
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
return 0;
|
2012-05-22 17:40:26 +08:00
|
|
|
}
|
|
|
|
|
2015-12-17 20:23:59 +08:00
|
|
|
#ifdef CONFIG_WATCHDOG_SYSFS
|
|
|
|
static ssize_t nowayout_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct watchdog_device *wdd = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
return sprintf(buf, "%d\n", !!test_bit(WDOG_NO_WAY_OUT, &wdd->status));
|
|
|
|
}
|
2019-11-06 04:51:18 +08:00
|
|
|
|
|
|
|
static ssize_t nowayout_store(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct watchdog_device *wdd = dev_get_drvdata(dev);
|
|
|
|
unsigned int value;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = kstrtouint(buf, 0, &value);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
if (value > 1)
|
|
|
|
return -EINVAL;
|
|
|
|
/* nowayout cannot be disabled once set */
|
|
|
|
if (test_bit(WDOG_NO_WAY_OUT, &wdd->status) && !value)
|
|
|
|
return -EPERM;
|
|
|
|
watchdog_set_nowayout(wdd, value);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RW(nowayout);
|
2015-12-17 20:23:59 +08:00
|
|
|
|
|
|
|
static ssize_t status_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct watchdog_device *wdd = dev_get_drvdata(dev);
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
struct watchdog_core_data *wd_data = wdd->wd_data;
|
|
|
|
unsigned int status;
|
2015-12-17 20:23:59 +08:00
|
|
|
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
mutex_lock(&wd_data->lock);
|
|
|
|
status = watchdog_get_status(wdd);
|
|
|
|
mutex_unlock(&wd_data->lock);
|
2015-12-17 20:23:59 +08:00
|
|
|
|
2016-07-18 06:04:11 +08:00
|
|
|
return sprintf(buf, "0x%x\n", status);
|
2015-12-17 20:23:59 +08:00
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(status);
|
|
|
|
|
|
|
|
static ssize_t bootstatus_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct watchdog_device *wdd = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
return sprintf(buf, "%u\n", wdd->bootstatus);
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(bootstatus);
|
|
|
|
|
|
|
|
static ssize_t timeleft_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct watchdog_device *wdd = dev_get_drvdata(dev);
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
struct watchdog_core_data *wd_data = wdd->wd_data;
|
2015-12-17 20:23:59 +08:00
|
|
|
ssize_t status;
|
|
|
|
unsigned int val;
|
|
|
|
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
mutex_lock(&wd_data->lock);
|
2015-12-17 20:23:59 +08:00
|
|
|
status = watchdog_get_timeleft(wdd, &val);
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
mutex_unlock(&wd_data->lock);
|
2015-12-17 20:23:59 +08:00
|
|
|
if (!status)
|
|
|
|
status = sprintf(buf, "%u\n", val);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(timeleft);
|
|
|
|
|
|
|
|
static ssize_t timeout_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct watchdog_device *wdd = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
return sprintf(buf, "%u\n", wdd->timeout);
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(timeout);
|
|
|
|
|
2016-08-31 19:52:41 +08:00
|
|
|
static ssize_t pretimeout_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct watchdog_device *wdd = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
return sprintf(buf, "%u\n", wdd->pretimeout);
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(pretimeout);
|
|
|
|
|
2015-12-17 20:23:59 +08:00
|
|
|
static ssize_t identity_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct watchdog_device *wdd = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
return sprintf(buf, "%s\n", wdd->info->identity);
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(identity);
|
|
|
|
|
|
|
|
static ssize_t state_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct watchdog_device *wdd = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
if (watchdog_active(wdd))
|
|
|
|
return sprintf(buf, "active\n");
|
|
|
|
|
|
|
|
return sprintf(buf, "inactive\n");
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(state);
|
|
|
|
|
2016-10-07 20:39:57 +08:00
|
|
|
static ssize_t pretimeout_available_governors_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
return watchdog_pretimeout_available_governors_get(buf);
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(pretimeout_available_governors);
|
|
|
|
|
2016-10-07 20:39:54 +08:00
|
|
|
static ssize_t pretimeout_governor_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct watchdog_device *wdd = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
return watchdog_pretimeout_governor_get(wdd, buf);
|
|
|
|
}
|
2016-10-07 20:37:00 +08:00
|
|
|
|
|
|
|
static ssize_t pretimeout_governor_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct watchdog_device *wdd = dev_get_drvdata(dev);
|
|
|
|
int ret = watchdog_pretimeout_governor_set(wdd, buf);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
ret = count;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RW(pretimeout_governor);
|
2016-10-07 20:39:54 +08:00
|
|
|
|
2015-12-17 20:23:59 +08:00
|
|
|
static umode_t wdt_is_visible(struct kobject *kobj, struct attribute *attr,
|
|
|
|
int n)
|
|
|
|
{
|
|
|
|
struct device *dev = container_of(kobj, struct device, kobj);
|
|
|
|
struct watchdog_device *wdd = dev_get_drvdata(dev);
|
|
|
|
umode_t mode = attr->mode;
|
|
|
|
|
2016-07-18 06:04:11 +08:00
|
|
|
if (attr == &dev_attr_timeleft.attr && !wdd->ops->get_timeleft)
|
2015-12-17 20:23:59 +08:00
|
|
|
mode = 0;
|
2016-08-31 19:52:41 +08:00
|
|
|
else if (attr == &dev_attr_pretimeout.attr &&
|
|
|
|
!(wdd->info->options & WDIOF_PRETIMEOUT))
|
|
|
|
mode = 0;
|
2016-10-07 20:39:57 +08:00
|
|
|
else if ((attr == &dev_attr_pretimeout_governor.attr ||
|
|
|
|
attr == &dev_attr_pretimeout_available_governors.attr) &&
|
2016-10-07 20:39:54 +08:00
|
|
|
(!(wdd->info->options & WDIOF_PRETIMEOUT) ||
|
|
|
|
!IS_ENABLED(CONFIG_WATCHDOG_PRETIMEOUT_GOV)))
|
|
|
|
mode = 0;
|
2015-12-17 20:23:59 +08:00
|
|
|
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
static struct attribute *wdt_attrs[] = {
|
|
|
|
&dev_attr_state.attr,
|
|
|
|
&dev_attr_identity.attr,
|
|
|
|
&dev_attr_timeout.attr,
|
2016-08-31 19:52:41 +08:00
|
|
|
&dev_attr_pretimeout.attr,
|
2015-12-17 20:23:59 +08:00
|
|
|
&dev_attr_timeleft.attr,
|
|
|
|
&dev_attr_bootstatus.attr,
|
|
|
|
&dev_attr_status.attr,
|
|
|
|
&dev_attr_nowayout.attr,
|
2016-10-07 20:39:54 +08:00
|
|
|
&dev_attr_pretimeout_governor.attr,
|
2016-10-07 20:39:57 +08:00
|
|
|
&dev_attr_pretimeout_available_governors.attr,
|
2015-12-17 20:23:59 +08:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct attribute_group wdt_group = {
|
|
|
|
.attrs = wdt_attrs,
|
|
|
|
.is_visible = wdt_is_visible,
|
|
|
|
};
|
|
|
|
__ATTRIBUTE_GROUPS(wdt);
|
|
|
|
#else
|
|
|
|
#define wdt_groups NULL
|
|
|
|
#endif
|
|
|
|
|
2012-05-22 17:40:26 +08:00
|
|
|
/*
|
|
|
|
* watchdog_ioctl_op: call the watchdog drivers ioctl op if defined
|
2015-09-29 16:27:25 +08:00
|
|
|
* @wdd: the watchdog device to do the ioctl on
|
2012-05-22 17:40:26 +08:00
|
|
|
* @cmd: watchdog command
|
|
|
|
* @arg: argument pointer
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
*
|
|
|
|
* The caller must hold wd_data->lock.
|
2012-05-22 17:40:26 +08:00
|
|
|
*/
|
|
|
|
|
2015-09-29 16:27:25 +08:00
|
|
|
static int watchdog_ioctl_op(struct watchdog_device *wdd, unsigned int cmd,
|
2012-05-22 17:40:26 +08:00
|
|
|
unsigned long arg)
|
|
|
|
{
|
2015-09-29 16:27:25 +08:00
|
|
|
if (!wdd->ops->ioctl)
|
2012-05-22 17:40:26 +08:00
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
return wdd->ops->ioctl(wdd, cmd, arg);
|
2011-07-23 02:55:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* watchdog_write: writes to the watchdog.
|
|
|
|
* @file: file from VFS
|
|
|
|
* @data: user address of data
|
|
|
|
* @len: length of data
|
|
|
|
* @ppos: pointer to the file offset
|
|
|
|
*
|
|
|
|
* A write to a watchdog device is defined as a keepalive ping.
|
2011-07-23 02:58:54 +08:00
|
|
|
* Writing the magic 'V' sequence allows the next close to turn
|
2011-07-23 02:59:17 +08:00
|
|
|
* off the watchdog (if 'nowayout' is not set).
|
2011-07-23 02:55:18 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
static ssize_t watchdog_write(struct file *file, const char __user *data,
|
|
|
|
size_t len, loff_t *ppos)
|
|
|
|
{
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
struct watchdog_core_data *wd_data = file->private_data;
|
|
|
|
struct watchdog_device *wdd;
|
|
|
|
int err;
|
2011-07-23 02:55:18 +08:00
|
|
|
size_t i;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return 0;
|
|
|
|
|
2011-07-23 02:58:54 +08:00
|
|
|
/*
|
|
|
|
* Note: just in case someone wrote the magic character
|
|
|
|
* five months ago...
|
|
|
|
*/
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
clear_bit(_WDOG_ALLOW_RELEASE, &wd_data->status);
|
2011-07-23 02:58:54 +08:00
|
|
|
|
|
|
|
/* scan to see whether or not we got the magic character */
|
2011-07-23 02:55:18 +08:00
|
|
|
for (i = 0; i != len; i++) {
|
|
|
|
if (get_user(c, data + i))
|
|
|
|
return -EFAULT;
|
2011-07-23 02:58:54 +08:00
|
|
|
if (c == 'V')
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
set_bit(_WDOG_ALLOW_RELEASE, &wd_data->status);
|
2011-07-23 02:55:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* someone wrote to us, so we send the watchdog a keepalive ping */
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
|
|
|
|
err = -ENODEV;
|
|
|
|
mutex_lock(&wd_data->lock);
|
|
|
|
wdd = wd_data->wdd;
|
|
|
|
if (wdd)
|
|
|
|
err = watchdog_ping(wdd);
|
|
|
|
mutex_unlock(&wd_data->lock);
|
|
|
|
|
2015-10-26 20:07:58 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2011-07-23 02:55:18 +08:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2011-07-23 02:56:38 +08:00
|
|
|
/*
|
|
|
|
* watchdog_ioctl: handle the different ioctl's for the watchdog device.
|
|
|
|
* @file: file handle to the device
|
|
|
|
* @cmd: watchdog command
|
|
|
|
* @arg: argument pointer
|
|
|
|
*
|
|
|
|
* The watchdog API defines a common set of functions for all watchdogs
|
|
|
|
* according to their available features.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static long watchdog_ioctl(struct file *file, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
struct watchdog_core_data *wd_data = file->private_data;
|
2011-07-23 02:56:38 +08:00
|
|
|
void __user *argp = (void __user *)arg;
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
struct watchdog_device *wdd;
|
2011-07-23 02:56:38 +08:00
|
|
|
int __user *p = argp;
|
|
|
|
unsigned int val;
|
2011-07-23 02:57:55 +08:00
|
|
|
int err;
|
2011-07-23 02:56:38 +08:00
|
|
|
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
mutex_lock(&wd_data->lock);
|
|
|
|
|
|
|
|
wdd = wd_data->wdd;
|
|
|
|
if (!wdd) {
|
|
|
|
err = -ENODEV;
|
|
|
|
goto out_ioctl;
|
|
|
|
}
|
|
|
|
|
2012-05-22 17:40:26 +08:00
|
|
|
err = watchdog_ioctl_op(wdd, cmd, arg);
|
|
|
|
if (err != -ENOIOCTLCMD)
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
goto out_ioctl;
|
2011-07-23 02:59:49 +08:00
|
|
|
|
2011-07-23 02:56:38 +08:00
|
|
|
switch (cmd) {
|
|
|
|
case WDIOC_GETSUPPORT:
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
err = copy_to_user(argp, wdd->info,
|
2011-07-23 02:56:38 +08:00
|
|
|
sizeof(struct watchdog_info)) ? -EFAULT : 0;
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
break;
|
2011-07-23 02:56:38 +08:00
|
|
|
case WDIOC_GETSTATUS:
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
val = watchdog_get_status(wdd);
|
|
|
|
err = put_user(val, p);
|
|
|
|
break;
|
2011-07-23 02:56:38 +08:00
|
|
|
case WDIOC_GETBOOTSTATUS:
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
err = put_user(wdd->bootstatus, p);
|
|
|
|
break;
|
2011-07-23 02:57:55 +08:00
|
|
|
case WDIOC_SETOPTIONS:
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
if (get_user(val, p)) {
|
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
2011-07-23 02:57:55 +08:00
|
|
|
if (val & WDIOS_DISABLECARD) {
|
|
|
|
err = watchdog_stop(wdd);
|
|
|
|
if (err < 0)
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
break;
|
2011-07-23 02:57:55 +08:00
|
|
|
}
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
if (val & WDIOS_ENABLECARD)
|
2011-07-23 02:57:55 +08:00
|
|
|
err = watchdog_start(wdd);
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
break;
|
2011-07-23 02:57:23 +08:00
|
|
|
case WDIOC_KEEPALIVE:
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
if (!(wdd->info->options & WDIOF_KEEPALIVEPING)) {
|
|
|
|
err = -EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
err = watchdog_ping(wdd);
|
|
|
|
break;
|
2011-07-23 02:58:21 +08:00
|
|
|
case WDIOC_SETTIMEOUT:
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
if (get_user(val, p)) {
|
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
2012-05-22 17:40:26 +08:00
|
|
|
err = watchdog_set_timeout(wdd, val);
|
2011-07-23 02:58:21 +08:00
|
|
|
if (err < 0)
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
break;
|
2011-07-23 02:58:21 +08:00
|
|
|
/* If the watchdog is active then we send a keepalive ping
|
|
|
|
* to make sure that the watchdog keep's running (and if
|
|
|
|
* possible that it takes the new timeout) */
|
2015-10-26 20:07:58 +08:00
|
|
|
err = watchdog_ping(wdd);
|
|
|
|
if (err < 0)
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
break;
|
2017-11-04 07:03:27 +08:00
|
|
|
/* fall through */
|
2011-07-23 02:58:21 +08:00
|
|
|
case WDIOC_GETTIMEOUT:
|
|
|
|
/* timeout == 0 means that we don't know the timeout */
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
if (wdd->timeout == 0) {
|
|
|
|
err = -EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
err = put_user(wdd->timeout, p);
|
|
|
|
break;
|
2012-03-16 16:14:00 +08:00
|
|
|
case WDIOC_GETTIMELEFT:
|
2012-05-22 17:40:26 +08:00
|
|
|
err = watchdog_get_timeleft(wdd, &val);
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
if (err < 0)
|
|
|
|
break;
|
|
|
|
err = put_user(val, p);
|
|
|
|
break;
|
2016-08-31 19:52:41 +08:00
|
|
|
case WDIOC_SETPRETIMEOUT:
|
|
|
|
if (get_user(val, p)) {
|
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
err = watchdog_set_pretimeout(wdd, val);
|
|
|
|
break;
|
|
|
|
case WDIOC_GETPRETIMEOUT:
|
|
|
|
err = put_user(wdd->pretimeout, p);
|
|
|
|
break;
|
2011-07-23 02:56:38 +08:00
|
|
|
default:
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
err = -ENOTTY;
|
|
|
|
break;
|
2011-07-23 02:56:38 +08:00
|
|
|
}
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
|
|
|
|
out_ioctl:
|
|
|
|
mutex_unlock(&wd_data->lock);
|
|
|
|
return err;
|
2011-07-23 02:56:38 +08:00
|
|
|
}
|
|
|
|
|
2011-07-23 02:55:18 +08:00
|
|
|
/*
|
2012-05-11 03:48:59 +08:00
|
|
|
* watchdog_open: open the /dev/watchdog* devices.
|
2011-07-23 02:55:18 +08:00
|
|
|
* @inode: inode of device
|
|
|
|
* @file: file handle to device
|
|
|
|
*
|
2012-05-11 03:48:59 +08:00
|
|
|
* When the /dev/watchdog* device gets opened, we start the watchdog.
|
2011-07-23 02:55:18 +08:00
|
|
|
* Watch out: the /dev/watchdog device is single open, so we make sure
|
|
|
|
* it can only be opened once.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int watchdog_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
struct watchdog_core_data *wd_data;
|
2012-05-11 03:48:59 +08:00
|
|
|
struct watchdog_device *wdd;
|
2017-09-26 00:17:01 +08:00
|
|
|
bool hw_running;
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
int err;
|
2012-05-11 03:48:59 +08:00
|
|
|
|
|
|
|
/* Get the corresponding watchdog device */
|
|
|
|
if (imajor(inode) == MISC_MAJOR)
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
wd_data = old_wd_data;
|
2012-05-11 03:48:59 +08:00
|
|
|
else
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
wd_data = container_of(inode->i_cdev, struct watchdog_core_data,
|
|
|
|
cdev);
|
2011-07-23 02:55:18 +08:00
|
|
|
|
|
|
|
/* the watchdog is single open! */
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
if (test_and_set_bit(_WDOG_DEV_OPEN, &wd_data->status))
|
2011-07-23 02:55:18 +08:00
|
|
|
return -EBUSY;
|
|
|
|
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
wdd = wd_data->wdd;
|
|
|
|
|
2011-07-23 02:55:18 +08:00
|
|
|
/*
|
|
|
|
* If the /dev/watchdog device is open, we don't want the module
|
|
|
|
* to be unloaded.
|
|
|
|
*/
|
2017-09-26 00:17:01 +08:00
|
|
|
hw_running = watchdog_hw_running(wdd);
|
|
|
|
if (!hw_running && !try_module_get(wdd->ops->owner)) {
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
err = -EBUSY;
|
|
|
|
goto out_clear;
|
|
|
|
}
|
2011-07-23 02:55:18 +08:00
|
|
|
|
2011-07-23 02:57:55 +08:00
|
|
|
err = watchdog_start(wdd);
|
2011-07-23 02:55:18 +08:00
|
|
|
if (err < 0)
|
|
|
|
goto out_mod;
|
|
|
|
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
file->private_data = wd_data;
|
2012-05-11 03:48:59 +08:00
|
|
|
|
2017-09-26 00:17:01 +08:00
|
|
|
if (!hw_running)
|
2019-10-08 19:29:34 +08:00
|
|
|
get_device(&wd_data->dev);
|
2012-05-22 17:40:26 +08:00
|
|
|
|
watchdog: introduce watchdog.open_timeout commandline parameter
The watchdog framework takes care of feeding a hardware watchdog until
userspace opens /dev/watchdogN. If that never happens for some reason
(buggy init script, corrupt root filesystem or whatnot) but the kernel
itself is fine, the machine stays up indefinitely. This patch allows
setting an upper limit for how long the kernel will take care of the
watchdog, thus ensuring that the watchdog will eventually reset the
machine.
A value of 0 (the default) means infinite timeout, preserving the
current behaviour.
This is particularly useful for embedded devices where some fallback
logic is implemented in the bootloader (e.g., use a different root
partition, boot from network, ...).
There is already handle_boot_enabled serving a similar purpose. However,
such a binary choice is unsuitable if the hardware watchdog cannot be
programmed by the bootloader to provide a timeout long enough for
userspace to get up and running. Many of the embedded devices we see use
external (gpio-triggered) watchdogs with a fixed timeout of the order of
1-2 seconds.
The open timeout only applies for the first open from
userspace. Should userspace need to close the watchdog device, with
the intention of re-opening it shortly, the application can emulate
the open timeout feature by combining the nowayout feature with an
appropriate WDIOC_SETTIMEOUT immediately prior to closing the device.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
2019-06-05 22:06:41 +08:00
|
|
|
/*
|
|
|
|
* open_timeout only applies for the first open from
|
|
|
|
* userspace. Set open_deadline to infinity so that the kernel
|
|
|
|
* will take care of an always-running hardware watchdog in
|
|
|
|
* case the device gets magic-closed or WDIOS_DISABLECARD is
|
|
|
|
* applied.
|
|
|
|
*/
|
|
|
|
wd_data->open_deadline = KTIME_MAX;
|
|
|
|
|
2011-07-23 02:55:18 +08:00
|
|
|
/* dev/watchdog is a virtual (and thus non-seekable) filesystem */
|
2019-03-27 04:51:19 +08:00
|
|
|
return stream_open(inode, file);
|
2011-07-23 02:55:18 +08:00
|
|
|
|
|
|
|
out_mod:
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
module_put(wd_data->wdd->ops->owner);
|
|
|
|
out_clear:
|
|
|
|
clear_bit(_WDOG_DEV_OPEN, &wd_data->status);
|
2011-07-23 02:55:18 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2019-10-08 19:29:34 +08:00
|
|
|
static void watchdog_core_data_release(struct device *dev)
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
{
|
|
|
|
struct watchdog_core_data *wd_data;
|
|
|
|
|
2019-10-08 19:29:34 +08:00
|
|
|
wd_data = container_of(dev, struct watchdog_core_data, dev);
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
|
|
|
|
kfree(wd_data);
|
|
|
|
}
|
|
|
|
|
2011-07-23 02:55:18 +08:00
|
|
|
/*
|
2012-05-11 03:48:59 +08:00
|
|
|
* watchdog_release: release the watchdog device.
|
|
|
|
* @inode: inode of device
|
|
|
|
* @file: file handle to device
|
2011-07-23 02:55:18 +08:00
|
|
|
*
|
2011-07-23 02:58:54 +08:00
|
|
|
* This is the code for when /dev/watchdog gets closed. We will only
|
2011-07-23 02:59:17 +08:00
|
|
|
* stop the watchdog when we have received the magic char (and nowayout
|
|
|
|
* was not set), else the watchdog will keep running.
|
2011-07-23 02:55:18 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
static int watchdog_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
struct watchdog_core_data *wd_data = file->private_data;
|
|
|
|
struct watchdog_device *wdd;
|
2011-07-23 02:58:54 +08:00
|
|
|
int err = -EBUSY;
|
2016-03-09 10:46:13 +08:00
|
|
|
bool running;
|
2011-07-23 02:58:54 +08:00
|
|
|
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
mutex_lock(&wd_data->lock);
|
|
|
|
|
|
|
|
wdd = wd_data->wdd;
|
|
|
|
if (!wdd)
|
|
|
|
goto done;
|
|
|
|
|
2011-07-23 02:58:54 +08:00
|
|
|
/*
|
|
|
|
* We only stop the watchdog if we received the magic character
|
2011-07-23 02:59:17 +08:00
|
|
|
* or if WDIOF_MAGICCLOSE is not set. If nowayout was set then
|
|
|
|
* watchdog_stop will fail.
|
2011-07-23 02:58:54 +08:00
|
|
|
*/
|
2013-04-08 23:06:32 +08:00
|
|
|
if (!test_bit(WDOG_ACTIVE, &wdd->status))
|
|
|
|
err = 0;
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
else if (test_and_clear_bit(_WDOG_ALLOW_RELEASE, &wd_data->status) ||
|
2013-04-08 23:06:32 +08:00
|
|
|
!(wdd->info->options & WDIOF_MAGICCLOSE))
|
2011-07-23 02:58:54 +08:00
|
|
|
err = watchdog_stop(wdd);
|
2011-07-23 02:55:18 +08:00
|
|
|
|
2011-07-23 02:58:54 +08:00
|
|
|
/* If the watchdog was not stopped, send a keepalive ping */
|
2011-07-23 02:57:55 +08:00
|
|
|
if (err < 0) {
|
2016-01-04 07:11:58 +08:00
|
|
|
pr_crit("watchdog%d: watchdog did not stop!\n", wdd->id);
|
2011-07-23 02:55:18 +08:00
|
|
|
watchdog_ping(wdd);
|
|
|
|
}
|
|
|
|
|
2016-02-29 05:12:16 +08:00
|
|
|
watchdog_update_worker(wdd);
|
2016-02-29 05:12:15 +08:00
|
|
|
|
2011-07-23 02:55:18 +08:00
|
|
|
/* make sure that /dev/watchdog can be re-opened */
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
clear_bit(_WDOG_DEV_OPEN, &wd_data->status);
|
2012-05-22 17:40:26 +08:00
|
|
|
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
done:
|
2016-03-09 10:46:13 +08:00
|
|
|
running = wdd && watchdog_hw_running(wdd);
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
mutex_unlock(&wd_data->lock);
|
2016-02-29 05:12:16 +08:00
|
|
|
/*
|
|
|
|
* Allow the owner module to be unloaded again unless the watchdog
|
|
|
|
* is still running. If the watchdog is still running, it can not
|
|
|
|
* be stopped, and its driver must not be unloaded.
|
|
|
|
*/
|
2016-03-09 10:46:13 +08:00
|
|
|
if (!running) {
|
|
|
|
module_put(wd_data->cdev.owner);
|
2019-10-08 19:29:34 +08:00
|
|
|
put_device(&wd_data->dev);
|
2016-02-29 05:12:16 +08:00
|
|
|
}
|
2011-07-23 02:55:18 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations watchdog_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.write = watchdog_write,
|
2011-07-23 02:56:38 +08:00
|
|
|
.unlocked_ioctl = watchdog_ioctl,
|
2019-06-03 20:23:09 +08:00
|
|
|
.compat_ioctl = compat_ptr_ioctl,
|
2011-07-23 02:55:18 +08:00
|
|
|
.open = watchdog_open,
|
|
|
|
.release = watchdog_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice watchdog_miscdev = {
|
|
|
|
.minor = WATCHDOG_MINOR,
|
|
|
|
.name = "watchdog",
|
|
|
|
.fops = &watchdog_fops,
|
|
|
|
};
|
|
|
|
|
2019-10-08 19:29:34 +08:00
|
|
|
static struct class watchdog_class = {
|
|
|
|
.name = "watchdog",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.dev_groups = wdt_groups,
|
|
|
|
};
|
|
|
|
|
2011-07-23 02:55:18 +08:00
|
|
|
/*
|
2015-12-26 08:01:40 +08:00
|
|
|
* watchdog_cdev_register: register watchdog character device
|
2015-09-29 16:27:25 +08:00
|
|
|
* @wdd: watchdog device
|
2011-07-23 02:55:18 +08:00
|
|
|
*
|
2015-12-26 08:01:40 +08:00
|
|
|
* Register a watchdog character device including handling the legacy
|
2012-05-11 03:48:59 +08:00
|
|
|
* /dev/watchdog node. /dev/watchdog is actually a miscdevice and
|
|
|
|
* thus we set it up like that.
|
2011-07-23 02:55:18 +08:00
|
|
|
*/
|
|
|
|
|
2019-10-08 19:29:34 +08:00
|
|
|
static int watchdog_cdev_register(struct watchdog_device *wdd)
|
2011-07-23 02:55:18 +08:00
|
|
|
{
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
struct watchdog_core_data *wd_data;
|
2015-12-26 08:01:40 +08:00
|
|
|
int err;
|
2012-05-11 03:48:59 +08:00
|
|
|
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
wd_data = kzalloc(sizeof(struct watchdog_core_data), GFP_KERNEL);
|
|
|
|
if (!wd_data)
|
|
|
|
return -ENOMEM;
|
|
|
|
mutex_init(&wd_data->lock);
|
|
|
|
|
|
|
|
wd_data->wdd = wdd;
|
|
|
|
wdd->wd_data = wd_data;
|
|
|
|
|
2017-12-08 18:18:35 +08:00
|
|
|
if (IS_ERR_OR_NULL(watchdog_kworker))
|
2016-02-29 05:12:15 +08:00
|
|
|
return -ENODEV;
|
|
|
|
|
2018-01-18 19:11:21 +08:00
|
|
|
kthread_init_work(&wd_data->work, watchdog_ping_work);
|
2019-11-05 22:45:06 +08:00
|
|
|
hrtimer_init(&wd_data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD);
|
2018-01-18 19:11:21 +08:00
|
|
|
wd_data->timer.function = watchdog_timer_expired;
|
2016-02-29 05:12:15 +08:00
|
|
|
|
2015-09-29 16:27:25 +08:00
|
|
|
if (wdd->id == 0) {
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
old_wd_data = wd_data;
|
2015-09-29 16:27:25 +08:00
|
|
|
watchdog_miscdev.parent = wdd->parent;
|
2012-05-11 03:48:59 +08:00
|
|
|
err = misc_register(&watchdog_miscdev);
|
|
|
|
if (err != 0) {
|
|
|
|
pr_err("%s: cannot register miscdev on minor=%d (err=%d).\n",
|
2015-09-29 16:27:25 +08:00
|
|
|
wdd->info->identity, WATCHDOG_MINOR, err);
|
2012-05-11 03:48:59 +08:00
|
|
|
if (err == -EBUSY)
|
|
|
|
pr_err("%s: a legacy watchdog module is probably present.\n",
|
2015-09-29 16:27:25 +08:00
|
|
|
wdd->info->identity);
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
old_wd_data = NULL;
|
|
|
|
kfree(wd_data);
|
2012-05-11 03:48:59 +08:00
|
|
|
return err;
|
|
|
|
}
|
2011-07-23 02:55:18 +08:00
|
|
|
}
|
|
|
|
|
2019-10-08 19:29:34 +08:00
|
|
|
device_initialize(&wd_data->dev);
|
|
|
|
wd_data->dev.devt = MKDEV(MAJOR(watchdog_devt), wdd->id);
|
|
|
|
wd_data->dev.class = &watchdog_class;
|
|
|
|
wd_data->dev.parent = wdd->parent;
|
|
|
|
wd_data->dev.groups = wdd->groups;
|
|
|
|
wd_data->dev.release = watchdog_core_data_release;
|
|
|
|
dev_set_drvdata(&wd_data->dev, wdd);
|
|
|
|
dev_set_name(&wd_data->dev, "watchdog%d", wdd->id);
|
|
|
|
|
2012-05-11 03:48:59 +08:00
|
|
|
/* Fill in the data structures */
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
cdev_init(&wd_data->cdev, &watchdog_fops);
|
2012-05-11 03:48:59 +08:00
|
|
|
|
|
|
|
/* Add the device */
|
2019-10-08 19:29:34 +08:00
|
|
|
err = cdev_device_add(&wd_data->cdev, &wd_data->dev);
|
2012-05-11 03:48:59 +08:00
|
|
|
if (err) {
|
|
|
|
pr_err("watchdog%d unable to add device %d:%d\n",
|
2015-09-29 16:27:25 +08:00
|
|
|
wdd->id, MAJOR(watchdog_devt), wdd->id);
|
|
|
|
if (wdd->id == 0) {
|
2012-05-11 03:48:59 +08:00
|
|
|
misc_deregister(&watchdog_miscdev);
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
old_wd_data = NULL;
|
2019-10-08 19:29:34 +08:00
|
|
|
put_device(&wd_data->dev);
|
2012-05-11 03:48:59 +08:00
|
|
|
}
|
2016-02-29 05:12:16 +08:00
|
|
|
return err;
|
2011-07-23 02:55:18 +08:00
|
|
|
}
|
2016-02-29 05:12:16 +08:00
|
|
|
|
2019-10-08 19:29:34 +08:00
|
|
|
wd_data->cdev.owner = wdd->ops->owner;
|
|
|
|
|
2016-02-29 05:12:18 +08:00
|
|
|
/* Record time of most recent heartbeat as 'just before now'. */
|
2018-01-18 19:11:21 +08:00
|
|
|
wd_data->last_hw_keepalive = ktime_sub(ktime_get(), 1);
|
watchdog: introduce watchdog.open_timeout commandline parameter
The watchdog framework takes care of feeding a hardware watchdog until
userspace opens /dev/watchdogN. If that never happens for some reason
(buggy init script, corrupt root filesystem or whatnot) but the kernel
itself is fine, the machine stays up indefinitely. This patch allows
setting an upper limit for how long the kernel will take care of the
watchdog, thus ensuring that the watchdog will eventually reset the
machine.
A value of 0 (the default) means infinite timeout, preserving the
current behaviour.
This is particularly useful for embedded devices where some fallback
logic is implemented in the bootloader (e.g., use a different root
partition, boot from network, ...).
There is already handle_boot_enabled serving a similar purpose. However,
such a binary choice is unsuitable if the hardware watchdog cannot be
programmed by the bootloader to provide a timeout long enough for
userspace to get up and running. Many of the embedded devices we see use
external (gpio-triggered) watchdogs with a fixed timeout of the order of
1-2 seconds.
The open timeout only applies for the first open from
userspace. Should userspace need to close the watchdog device, with
the intention of re-opening it shortly, the application can emulate
the open timeout feature by combining the nowayout feature with an
appropriate WDIOC_SETTIMEOUT immediately prior to closing the device.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
2019-06-05 22:06:41 +08:00
|
|
|
watchdog_set_open_deadline(wd_data);
|
2016-02-29 05:12:18 +08:00
|
|
|
|
2016-02-29 05:12:16 +08:00
|
|
|
/*
|
|
|
|
* If the watchdog is running, prevent its driver from being unloaded,
|
|
|
|
* and schedule an immediate ping.
|
|
|
|
*/
|
|
|
|
if (watchdog_hw_running(wdd)) {
|
2017-09-26 00:17:02 +08:00
|
|
|
__module_get(wdd->ops->owner);
|
2019-10-08 19:29:34 +08:00
|
|
|
get_device(&wd_data->dev);
|
2017-09-26 00:17:02 +08:00
|
|
|
if (handle_boot_enabled)
|
2019-11-05 22:45:06 +08:00
|
|
|
hrtimer_start(&wd_data->timer, 0,
|
|
|
|
HRTIMER_MODE_REL_HARD);
|
2017-09-26 00:17:02 +08:00
|
|
|
else
|
2017-05-12 20:05:32 +08:00
|
|
|
pr_info("watchdog%d running and kernel based pre-userspace handler disabled\n",
|
2017-09-26 00:17:02 +08:00
|
|
|
wdd->id);
|
2016-02-29 05:12:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2011-07-23 02:55:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-12-26 08:01:40 +08:00
|
|
|
* watchdog_cdev_unregister: unregister watchdog character device
|
2011-07-23 02:55:18 +08:00
|
|
|
* @watchdog: watchdog device
|
|
|
|
*
|
2015-12-26 08:01:40 +08:00
|
|
|
* Unregister watchdog character device and if needed the legacy
|
|
|
|
* /dev/watchdog device.
|
2011-07-23 02:55:18 +08:00
|
|
|
*/
|
|
|
|
|
2015-12-26 08:01:40 +08:00
|
|
|
static void watchdog_cdev_unregister(struct watchdog_device *wdd)
|
2011-07-23 02:55:18 +08:00
|
|
|
{
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
struct watchdog_core_data *wd_data = wdd->wd_data;
|
2012-05-22 17:40:26 +08:00
|
|
|
|
2019-10-08 19:29:34 +08:00
|
|
|
cdev_device_del(&wd_data->cdev, &wd_data->dev);
|
2015-09-29 16:27:25 +08:00
|
|
|
if (wdd->id == 0) {
|
2012-05-11 03:48:59 +08:00
|
|
|
misc_deregister(&watchdog_miscdev);
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
old_wd_data = NULL;
|
2011-07-23 02:55:18 +08:00
|
|
|
}
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
|
2017-01-26 06:21:10 +08:00
|
|
|
if (watchdog_active(wdd) &&
|
|
|
|
test_bit(WDOG_STOP_ON_UNREGISTER, &wdd->status)) {
|
|
|
|
watchdog_stop(wdd);
|
|
|
|
}
|
|
|
|
|
2018-08-28 18:13:47 +08:00
|
|
|
mutex_lock(&wd_data->lock);
|
|
|
|
wd_data->wdd = NULL;
|
|
|
|
wdd->wd_data = NULL;
|
|
|
|
mutex_unlock(&wd_data->lock);
|
|
|
|
|
2018-01-18 19:11:21 +08:00
|
|
|
hrtimer_cancel(&wd_data->timer);
|
|
|
|
kthread_cancel_work_sync(&wd_data->work);
|
2016-02-29 05:12:15 +08:00
|
|
|
|
2019-10-08 19:29:34 +08:00
|
|
|
put_device(&wd_data->dev);
|
2011-07-23 02:55:18 +08:00
|
|
|
}
|
2012-05-11 03:48:59 +08:00
|
|
|
|
2015-12-26 08:01:40 +08:00
|
|
|
/*
|
|
|
|
* watchdog_dev_register: register a watchdog device
|
|
|
|
* @wdd: watchdog device
|
|
|
|
*
|
|
|
|
* Register a watchdog device including handling the legacy
|
|
|
|
* /dev/watchdog node. /dev/watchdog is actually a miscdevice and
|
|
|
|
* thus we set it up like that.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int watchdog_dev_register(struct watchdog_device *wdd)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2019-10-08 19:29:34 +08:00
|
|
|
ret = watchdog_cdev_register(wdd);
|
2015-12-26 08:01:40 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-10-07 20:39:54 +08:00
|
|
|
ret = watchdog_register_pretimeout(wdd);
|
2020-01-08 20:53:47 +08:00
|
|
|
if (ret)
|
2016-10-07 20:39:54 +08:00
|
|
|
watchdog_cdev_unregister(wdd);
|
|
|
|
|
2015-12-26 08:01:40 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* watchdog_dev_unregister: unregister a watchdog device
|
|
|
|
* @watchdog: watchdog device
|
|
|
|
*
|
|
|
|
* Unregister watchdog device and if needed the legacy
|
|
|
|
* /dev/watchdog device.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void watchdog_dev_unregister(struct watchdog_device *wdd)
|
|
|
|
{
|
2016-10-07 20:39:54 +08:00
|
|
|
watchdog_unregister_pretimeout(wdd);
|
watchdog: Separate and maintain variables based on variable lifetime
All variables required by the watchdog core to manage a watchdog are
currently stored in struct watchdog_device. The lifetime of those
variables is determined by the watchdog driver. However, the lifetime
of variables used by the watchdog core differs from the lifetime of
struct watchdog_device. To remedy this situation, watchdog drivers
can implement ref and unref callbacks, to be used by the watchdog
core to lock struct watchdog_device in memory.
While this solves the immediate problem, it depends on watchdog drivers
to actually implement the ref/unref callbacks. This is error prone,
often not implemented in the first place, or not implemented correctly.
To solve the problem without requiring driver support, split the variables
in struct watchdog_device into two data structures - one for variables
associated with the watchdog driver, one for variables associated with
the watchdog core. With this approach, the watchdog core can keep track
of its variable lifetime and no longer depends on ref/unref callbacks
in the driver. As a side effect, some of the variables originally in
struct watchdog_driver are now private to the watchdog core and no longer
visible in watchdog drivers.
As a side effect of the changes made, an ioctl will now always fail
with -ENODEV after a watchdog device was unregistered with the character
device still open. Previously, it would only fail with -ENODEV in some
situations. Also, ioctl operations are now atomic from driver perspective.
With this change, it is now guaranteed that the driver will not unregister
a watchdog between a timeout change and the subsequent ping.
The 'ref' and 'unref' callbacks in struct watchdog_driver are no longer
used and marked as deprecated.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
2015-12-26 08:01:42 +08:00
|
|
|
watchdog_cdev_unregister(wdd);
|
2015-12-26 08:01:40 +08:00
|
|
|
}
|
|
|
|
|
2012-05-11 03:48:59 +08:00
|
|
|
/*
|
|
|
|
* watchdog_dev_init: init dev part of watchdog core
|
|
|
|
*
|
|
|
|
* Allocate a range of chardev nodes to use for watchdog devices
|
|
|
|
*/
|
|
|
|
|
2015-12-26 08:01:40 +08:00
|
|
|
int __init watchdog_dev_init(void)
|
2012-05-11 03:48:59 +08:00
|
|
|
{
|
2015-12-17 20:23:58 +08:00
|
|
|
int err;
|
2017-12-08 18:18:35 +08:00
|
|
|
struct sched_param param = {.sched_priority = MAX_RT_PRIO - 1,};
|
2015-12-17 20:23:58 +08:00
|
|
|
|
2017-12-08 18:18:35 +08:00
|
|
|
watchdog_kworker = kthread_create_worker(0, "watchdogd");
|
|
|
|
if (IS_ERR(watchdog_kworker)) {
|
|
|
|
pr_err("Failed to create watchdog kworker\n");
|
|
|
|
return PTR_ERR(watchdog_kworker);
|
2016-02-29 05:12:15 +08:00
|
|
|
}
|
2017-12-08 18:18:35 +08:00
|
|
|
sched_setscheduler(watchdog_kworker->task, SCHED_FIFO, ¶m);
|
2016-02-29 05:12:15 +08:00
|
|
|
|
2015-12-17 20:23:58 +08:00
|
|
|
err = class_register(&watchdog_class);
|
|
|
|
if (err < 0) {
|
|
|
|
pr_err("couldn't register class\n");
|
2016-07-19 19:22:34 +08:00
|
|
|
goto err_register;
|
2015-12-17 20:23:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
err = alloc_chrdev_region(&watchdog_devt, 0, MAX_DOGS, "watchdog");
|
|
|
|
if (err < 0) {
|
2012-05-11 03:48:59 +08:00
|
|
|
pr_err("watchdog: unable to allocate char dev region\n");
|
2016-07-19 19:22:34 +08:00
|
|
|
goto err_alloc;
|
2015-12-17 20:23:58 +08:00
|
|
|
}
|
|
|
|
|
2015-12-26 08:01:40 +08:00
|
|
|
return 0;
|
2016-07-19 19:22:34 +08:00
|
|
|
|
|
|
|
err_alloc:
|
|
|
|
class_unregister(&watchdog_class);
|
|
|
|
err_register:
|
2017-12-08 18:18:35 +08:00
|
|
|
kthread_destroy_worker(watchdog_kworker);
|
2016-07-19 19:22:34 +08:00
|
|
|
return err;
|
2012-05-11 03:48:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* watchdog_dev_exit: exit dev part of watchdog core
|
|
|
|
*
|
|
|
|
* Release the range of chardev nodes used for watchdog devices
|
|
|
|
*/
|
|
|
|
|
|
|
|
void __exit watchdog_dev_exit(void)
|
|
|
|
{
|
|
|
|
unregister_chrdev_region(watchdog_devt, MAX_DOGS);
|
2015-12-17 20:23:58 +08:00
|
|
|
class_unregister(&watchdog_class);
|
2017-12-08 18:18:35 +08:00
|
|
|
kthread_destroy_worker(watchdog_kworker);
|
2012-05-11 03:48:59 +08:00
|
|
|
}
|
2017-05-12 20:05:32 +08:00
|
|
|
|
|
|
|
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)) ")");
|
watchdog: introduce watchdog.open_timeout commandline parameter
The watchdog framework takes care of feeding a hardware watchdog until
userspace opens /dev/watchdogN. If that never happens for some reason
(buggy init script, corrupt root filesystem or whatnot) but the kernel
itself is fine, the machine stays up indefinitely. This patch allows
setting an upper limit for how long the kernel will take care of the
watchdog, thus ensuring that the watchdog will eventually reset the
machine.
A value of 0 (the default) means infinite timeout, preserving the
current behaviour.
This is particularly useful for embedded devices where some fallback
logic is implemented in the bootloader (e.g., use a different root
partition, boot from network, ...).
There is already handle_boot_enabled serving a similar purpose. However,
such a binary choice is unsuitable if the hardware watchdog cannot be
programmed by the bootloader to provide a timeout long enough for
userspace to get up and running. Many of the embedded devices we see use
external (gpio-triggered) watchdogs with a fixed timeout of the order of
1-2 seconds.
The open timeout only applies for the first open from
userspace. Should userspace need to close the watchdog device, with
the intention of re-opening it shortly, the application can emulate
the open timeout feature by combining the nowayout feature with an
appropriate WDIOC_SETTIMEOUT immediately prior to closing the device.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
2019-06-05 22:06:41 +08:00
|
|
|
|
|
|
|
module_param(open_timeout, uint, 0644);
|
|
|
|
MODULE_PARM_DESC(open_timeout,
|
2019-06-05 22:06:43 +08:00
|
|
|
"Maximum time (in seconds, 0 means infinity) for userspace to take over a running watchdog (default="
|
|
|
|
__MODULE_STRING(CONFIG_WATCHDOG_OPEN_TIMEOUT) ")");
|