Skip to content

wdt: the same fixes for hi3516cv100, built from source instead of the vendor blob - #302

Merged
widgetii merged 2 commits into
mainfrom
wdt-cv100-fixes
Nov 14, 2026
Merged

widgetii merged 2 commits into
mainfrom
wdt-cv100-fixes

Conversation

@widgetii

Copy link
Copy Markdown
Member

Fixes OpenIPC/firmware#1534.

hi3516cv100 is the generation #235 left out. Its kbuild linked the vendor wdt.o, so the wdt.ko that hisilicon-opensdk installs on hi3516cv100/hi3518cv100 still behaved like the vendor driver.

Before, measured on a hi3518cv100 (XM N51813L) running today's firmware:

  • majestic frozen (SIGSTOP) while holding /dev/watchdog, for 150 s: no reset. The driver's [hidog] thread kept feeding.
  • majestic's clean stop, which writes "V": HiDog: Unexpected close, not stopping watchdog! (the magic close inverted, as on cv200). The module's reference count stayed at 1, so rmmod failed with EAGAIN.

Change: the cv100 copy differed from cv200's pre-#235 hi_wdt.c by only twelve cosmetic lines, and the SP805 sits at the same 0x20040000 with the same clock gate at 0x20050000. So cv100 now carries the fixed cv200 driver verbatim, and the kbuild builds it from source, retiring obj/hi3516cv100/wdt.o and its init wrapper.

After, same board, this module in place of the firmware's wdt.ko, with majestic's defaults (300 s, fed every 150 s):

Test Result
crash (SIGSEGV) S95majestic restarted majestic after 5 s; it re-armed the watchdog; no reset
clean stop, then 330 s with nothing open Watchdog is disabled!, no reset
hang (SIGSTOP) board reset; back 287 s after the stop

The kernel thread still feeds from module load until userspace opens the device. A boot, or an update that runs without majestic, is therefore as safe as before. That was the concern holding back #1534's nodeamon=1.

Built against the firmware's Linux 3.0.8 (hi3518cv100_lite). The only warnings are the -Wmissing-attributes on module_init/module_exit that every module in the tree gets with this compiler.

… vendor blob

Fixes OpenIPC/firmware#1534.

hi3516cv100 was the generation #235 left out: its kbuild linked the vendor
wdt.o, so the source beside it was reference and reached no board. The
module hisilicon-opensdk installs as wdt.ko on hi3516cv100/hi3518cv100 was
that blob, with the vendor behaviour the rest of the tree has had fixed.

Measured on a hi3518cv100 (XM N51813L) running today's firmware, before:

  - majestic frozen (SIGSTOP), holding /dev/watchdog, 150 s: no reset.
    The driver's [hidog] thread went on feeding.
  - majestic's clean stop, which writes "V" ("magic close supported"):
    "HiDog: Unexpected close, not stopping watchdog!" -- the magic close
    inverted as on cv200 -- and the module's reference count stayed at 1,
    so rmmod failed with EAGAIN for the rest of the boot.

The cv100 copy differed from cv200's pre-#235 hi_wdt.c by twelve lines
(casts on ioremap_nocache, an IS_ERR typo, iounmap order, the author);
the SP805 is at the same 0x20040000 with the same clock gate at
0x20050000. So it now carries the fixed cv200 driver verbatim and the
kbuild builds it, retiring obj/hi3516cv100/wdt.o and its init wrapper.

After, same board, the module in place of the firmware's wdt.ko and
majestic's own defaults (300 s, fed every 150 s):

  - crash (SIGSEGV): S95majestic restarted majestic after 5 s, it
    re-armed the watchdog, no reset.
  - clean stop, then 330 s with nothing open: "Watchdog is disabled!",
    no reset.
  - hang (SIGSTOP): the board reset and was back 287 s after the stop.

The kernel thread still feeds from load until userspace opens the
device, so a boot or an update that runs without majestic is as safe as
before -- the concern that has held #1534's nodeamon=1 back.

Built against the firmware's Linux 3.0.8 (hi3518cv100_lite); the only
warnings are the -Wmissing-attributes on module_init/module_exit every
module in the tree gets with this compiler.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Build the fixed hi3516cv100 watchdog driver from source

🐞 Bug fix ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Replace the cv100 vendor watchdog blob with a source-built driver so firmware receives the fixes.
• Stop kernel feeding after userspace opens the watchdog, allowing a hung owner to trigger a reset.
• Correct magic close, timeout handling, ioctl compatibility, and shutdown behavior.
Diagram

graph TD
  Build["cv100 kbuild"] --> Driver["Source watchdog"] --> Chip["SP805 hardware"]
  Owner["Userspace owner"] --> Device["/dev/watchdog"] --> Driver
  Driver --> Feeder["Pre-open feeder"] --> Chip
  Reboot["Reboot notifier"] --> Driver
Loading
High-Level Assessment

Building the already-fixed cv200-derived driver for cv100 is appropriate given the matching SP805 addresses and clock gate. Retaining the vendor blob would preserve the failure to reset on hangs; a separate cv100 implementation would duplicate the existing fixes.

Files changed (2) +298 / -96

Bug fix (1) +290 / -94
hi_wdt.cCorrect cv100 watchdog ownership, timing, and API behavior +290/-94

Correct cv100 watchdog ownership, timing, and API behavior

• Ports the fixed watchdog behavior to cv100: kernel feeding ends after the first userspace open, magic close stops the timer when permitted, and releases balance module references. It also corrects SP805 timeout and keepalive behavior, accepts standard and vendor ioctl encodings, and coordinates opens with shutdown.

kernel/wdt/hi3516cv100/hi_wdt.c

Other (1) +8 / -2
hi3516cv100.kbuildLink the cv100 watchdog from source +8/-2

Link the cv100 watchdog from source

• Replaces the vendor watchdog object and init-wrapper linkage with wdt/hi3516cv100/hi_wdt.o. The module remains in the cv100 build, but now contains the fixed driver.

kernel/hi3516cv100.kbuild

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. A watchdog client can re-arm during shutdown ✓ Resolved
Description
hidog_notifier_sys() stops the timer and sets shutting_down, but the enable branch of
hidog_ioctl() neither checks that flag nor takes hidog_lifecycle. An existing owner can issue
WDIOC_SETOPTIONS with WDIOS_ENABLECARD after the notifier runs, leaving the watchdog armed
during shutdown.


Remediation recommended

2. Failed loads leak watchdog mappings ✓ Resolved
Description
watchdog_init() maps both register regions, but its error labels return without unmapping them,
despite the comment in hidog_init() claiming that failed loads release the registers. If notifier
registration, device registration, or feeder creation fails, the load reaches those labels and
leaves both mappings allocated; the misleading comment may also keep a later reader from adding the
missing cleanup.

3. Disabled watchdogs report time remaining ✓ Resolved
Description
WDIOC_GETTIMELEFT derives its answer from the counter without checking whether hidog_stop()
disabled the hardware. After a client disables the watchdog, the parked load value can therefore be
reported as an active countdown instead of zero.

4. Poweroff can leave the watchdog running ✓ Resolved
Description
hidog_notifier_sys() performs its new shutdown transition only for SYS_DOWN and SYS_HALT,
omitting the distinct SYS_POWER_OFF notification. If an armed watchdog reaches poweroff while
power is still present, the notifier neither stops it nor marks shutdown in progress.

View medium (1)
5. Concurrent timeout changes can misreport time ✓ Resolved
Description
hidog_set_heartbeat() assigns cur_margin before taking the register lock used to program the
hardware. If two threads issue timeout changes through a shared watchdog descriptor, one can program
its shorter timeout after the other has stored a longer cur_margin, so the reported margin no
longer matches the reset deadline.

Grey Divider

Tip of the day
💡 Did you know, you can ask Qodo to dismiss a finding you disagree with, with your reason on record

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

…p on a failed load, time left reads 0 when stopped, serialised SETTIMEOUT

Review on #302, in all four V2 copies (hi3516cv100, hi3516cv200,
hi3516av100, hi3520dv200), so they stay one driver:

- WDIOS_ENABLECARD takes hidog_lifecycle and refuses once the reboot
  notifier has run, as hidog_open() already did: an open descriptor could
  arm the watchdog again in the middle of a shutdown.
- The reboot notifier also handles SYS_POWER_OFF, so a poweroff with the
  board still powered does not leave the dog armed to reset it.
- watchdog_init()'s error path unmaps both register regions, which the
  comment in hidog_init() already said it did.
- WDIOC_GETTIMELEFT answers 0 while HIWDT_CTRL has the timer disabled;
  hidog_stop() parks the load at the maximum, which read as a deadline.
- WDIOC_SETTIMEOUT sets and reads back the margin under hidog_lifecycle, so
  two callers sharing a descriptor cannot leave cur_margin and the hardware
  disagreeing.

Re-checked on the hi3518cv100: majestic arms it and reads back 300 s, a
crash is restarted by the supervisor without a reset, a hang resets the
board.
@widgetii

Copy link
Copy Markdown
Member Author

Review addressed in 8839773. All five findings were valid. They live in the V2 driver this PR copies from cv200, so the fix goes into all four V2 copies (hi3516cv100, hi3516cv200, hi3516av100, hi3520dv200) to keep them one driver:

  1. Re-arm during shutdown: WDIOS_ENABLECARD now takes hidog_lifecycle and returns -ENODEV once shutting_down is set, the same refusal as hidog_open().
  2. Mappings leaked on a failed load: watchdog_init_errA now unmaps both regions and clears the pointers, which is what the comment in hidog_init() already said happened.
  3. Time left on a stopped watchdog: WDIOC_GETTIMELEFT returns 0 while HIWDT_CTRL bit 0 is clear.
  4. Poweroff: the reboot notifier handles SYS_POWER_OFF alongside SYS_DOWN and SYS_HALT.
  5. Concurrent SETTIMEOUT: setting the margin, the keepalive and the read-back all happen under hidog_lifecycle, and the caller gets the margin its own call set.

Re-checked on the hi3518cv100 with the rebuilt module:

  • majestic arms it and reads back 300 s;
  • crash (SIGSEGV): the supervisor restarted majestic, it re-armed, no reset;
  • hang (SIGSTOP): the board reset, back 206 s after the stop. The last feed was at arming, about 117 s before the stop, so the reset came on the 300 s deadline.

@widgetii
widgetii merged commit 6ce8b7f into main Nov 14, 2026
37 checks passed
@widgetii
widgetii deleted the wdt-cv100-fixes branch November 14, 2026 11:59
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