Skip to content

rust: add watchdog abstraction and Rust softdog driver

Artem Lytkin linux-watchdog lkml oe-kbuild-all rust-for-linux 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 0 repliesNew
  2. v12 patches 0 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3rust: watchdog: add watchdog device abstractionMAINTAINERS rust/bindings/bindings_helper.h rust/helpers/helpers.c +3 more+566 -00 replies
2/3rust: reboot: add emergency_restart() wrapperrust/bindings/bindings_helper.h rust/kernel/lib.rs rust/kernel/reboot.rs+21 -00 replies
3/3watchdog: softdog_rs: add Rust software watchdog driverdrivers/watchdog/Kconfig drivers/watchdog/Makefile drivers/watchdog/softdog_rs.rs+156 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/3] rust: add watchdog abstraction and Rust softdog driver

This series adds Rust abstractions for the watchdog subsystem and a Rust software watchdog driver functionally equivalent to the core of the C softdog.

Patch 1 adds the watchdog abstraction: a Device wrapper, an Info wrapper with option flags, an Options configuration struct, a #[vtable] WatchdogOps trait with an associated Data type for driver private data, and a generic Registration that owns the device, the ops table and the driver data in a single heap allocation.

Patch 2 adds a minimal kernel::reboot module wrapping emergency_restart(), needed by the softdog driver.

Patch 3 adds the softdog_rs driver: an hrtimer is armed on start and re-armed on every keepalive ping; if userspace stops pinging, the timer expires and the system is restarted via emergency_restart().

Changes since v1 [1]:

Most of v2 is a redesign addressing the review feedback from Guenter (via the Sashiko review [2]), Miguel, and the kernel test robot:

- The ops table is no longer a &'static mut supplied by the driver; it is built by the abstraction and embedded in the per-device heap allocation, so multiple device instances need no static mutable state (Sashiko).
- Driver private data is now supported via an associated Data type; every callback receives a reference to it (Sashiko).
- Callbacks now take only shared references and Data must be Sync:
the watchdog core does not hold its lock on every callback path (the first start/ping on open, the reboot notifier stop, and the stop on unregistration run without it), so exclusive references would be unsound.
- max_hw_heartbeat_ms is configurable and the stop()-or-heartbeat registration requirement is documented (Sashiko).
- Removed the Registration::device() accessor that allowed aliasing with the references used in callbacks (Sashiko).
- stop_on_reboot is now opt-in and rejected with EINVAL for drivers without stop(); nowayout defaults to CONFIG_WATCHDOG_NOWAYOUT (Sashiko).
- The watchdog is always stopped on unregistration so no callback can run after the driver data is freed.
- softdog_rs now actually bites: it arms an hrtimer and calls emergency_restart() on expiry, instead of relying on the (wrong) assumption that the core handles expiry (Sashiko).
- Kconfig mutual exclusion fixed to SOFT_WATCHDOG=n; !SOFT_WATCHDOG still allowed both drivers as modules (Sashiko).
- C helpers marked __rust_helper (Miguel), and updated for the const-qualified watchdog_active()/watchdog_hw_running().
- Fixed rustfmt and clippy issues reported by the kernel test robot.
- Drivers no longer use raw bindings: added the Info wrapper, the flags module, and the kernel::reboot module.
- Added the new rust watchdog files to MAINTAINERS.
- Rebased onto current mainline (post-v7.2-rc4).

[1] https://lore.kernel.org/linux-watchdog/[email protected]/
[2] https://sashiko.dev/#/patchset/20260323195138.5541-1-iprintercanon%40gmail.com

Artem Lytkin (3):
rust: watchdog: add watchdog device abstraction
rust: reboot: add emergency_restart() wrapper
watchdog: softdog_rs: add Rust software watchdog driver

 MAINTAINERS                     |   2 +
 drivers/watchdog/Kconfig        |  12 +
 drivers/watchdog/Makefile       |   1 +
 drivers/watchdog/softdog_rs.rs  | 143 +++++++++++
 rust/bindings/bindings_helper.h |   2 +
 rust/helpers/helpers.c          |   1 +
 rust/helpers/watchdog.c         |  38 +++
 rust/kernel/lib.rs              |   3 +
 rust/kernel/reboot.rs           |  19 ++
 rust/kernel/watchdog.rs         | 522 ++++++++++++++++++++++++++++++++++++++++
 10 files changed, 743 insertions(+)
 create mode 100644 drivers/watchdog/softdog_rs.rs
 create mode 100644 rust/helpers/watchdog.c
 create mode 100644 rust/kernel/reboot.rs
 create mode 100644 rust/kernel/watchdog.rs
Signature · 1 line
2.43.0