Skip to content

feat(watchdog): add x86 hardware watchdog support - #2019

Closed
filippocarletti wants to merge 1 commit into
mainfrom
feat/watchdog
Closed

filippocarletti wants to merge 1 commit into
mainfrom
feat/watchdog

Conversation

@filippocarletti

@filippocarletti filippocarletti commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

I want NethSecurity to reset itself when the kernel or the init process (procd) hangs, instead of waiting for someone to power-cycle the box. procd already pings /dev/watchdog every 5 seconds with a 30 seconds timeout; what was missing is loading the right driver.

Loading every upstream watchdog driver is not enough. The first device that registers owns /dev/watchdog. On a PC Engines APU, the ib700wdt driver took it without checking the hardware, so procd was pinging a watchdog that could not reset the board. This PR adds the ns-watchdog package, which picks the driver at boot before procd opens the device. It is enabled by default on x86, also after an upgrade.

  • I ship only drivers bound to a chipset or a PCI device: i6300esb (QEMU/KVM/Proxmox), iTCO_wdt (Intel), sp5100_tco (AMD, APU). softdog is shipped but used only when configured. I left out the Super I/O drivers (w83627hf_wdt, it87_wdt, f71808e_wdt), ib700wdt and mlx_wdt.
  • The package blacklists the watchdog modules in /etc/modules.conf (owned by ubox, edited in a marked block), so kmodloader never loads them on its own, neither before preinit nor in /etc/init.d/boot. /etc/modules.conf is saved by sysupgrade and backups, so the hook writes the block again at boot if a restored copy dropped or changed it.
  • A preinit hook (/lib/preinit/83_ns_watchdog) loads them with insmod, which ignores the blacklist, in priority order and keeps only the ones that find a device.
  • The watchdog can be disabled with system.@system[0].watchdog=0, or with ns.watchdog=0 on the kernel command line from the GRUB menu.

What I tested on the current PR image, on a PC Engines APU and on a KVM Q35 VM with an i6300esb watchdog:

  • At boot only the chosen driver is loaded: sp5100_tco on the APU, i6300esb on the VM (with iTCO_wdt kept as a secondary device). Nothing is reloaded after the selection.
  • Stopping procd pings resets both machines after about 31 seconds.
  • system.@system[0].watchdog=0 on the APU: after reboot no watchdog module is loaded and there is no /dev/watchdog. Removing the option turns the watchdog back on.
  • ns.watchdog=0 added in GRUB menu also disabled the watchdog.
  • On the VM I removed the block from /etc/modules.conf: before preinit nothing was loaded (that step reads the image copy), but /etc/init.d/boot loaded softdog as watchdog2. With ns-watchdog 0.0.3 the same test logs restored the modules blacklist, the block is back identical to the image copy, and softdog is not loaded. A normal reboot does not rewrite the file. The other 0.0.3 fixes (log messages when a watchdog module cannot be unloaded) are tested only in a busybox simulation.

How to test

  • Boot: dmesg | grep ns-watchdog shows the chosen driver, ubus call system watchdog reports running, /etc/modules.conf contains the ns-watchdog block, and lsmod shows no softdog and no watchdog module without a device.
  • Run ubus call system watchdog '{"stop":true}': the machine resets after about 30 seconds and comes back with all services running.
  • VM without a watchdog device: no /dev/watchdog and no watchdog module loaded.
  • uci set system.@system[0].watchdog=0; uci commit system; reboot: no /dev/watchdog, also after boot completes. Same with ns.watchdog=0 added in the GRUB menu.
  • Remove the ns-watchdog block from /etc/modules.conf and reboot: dmesg shows restored the modules blacklist, the block is back and softdog is not loaded.
  • Upgrade a VM from the current stable release: the watchdog is active after the upgrade.
  • Test with a fork bomb: :(){ :|:& };:

See also

procd pings /dev/watchdog, but no driver was shipped. Loading all
upstream drivers is not enough: the first registered device owns
/dev/watchdog, and ib700wdt registers without probing the hardware.

ns-watchdog ships i6300esb, iTCO_wdt, sp5100_tco and softdog (opt-in),
blacklists them for kmodloader in /etc/modules.conf and picks the
driver in preinit, before procd opens the device. The blacklist is
rewritten at boot if a restored config changed it.

Disable with system.@System[0].watchdog=0 or ns.watchdog=0 on the
kernel command line. Document it in the package README and a design
note.

Assisted-by: Claude Code:Claude Opus 5.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant