Re: [PATCH 1/3] watchdog: pretimeout: Protect governor access with RCU for NMI safety

Guenter Roeck <[email protected]>
Newsgroups org.kernel.vger.linux-watchdog,org.kernel.vger.linux-arm-msm,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On 7/30/26 14:46, Doug Anderson wrote:
> Hi,
> 
> On Thu, Jul 30, 2026 at 2:33 PM Mayank Rungta via B4 Relay
> <[email protected]> wrote:
>>
>> From: Mayank Rungta <[email protected]>
>>
>> Currently, watchdog_notify_pretimeout() acquires pretimeout_lock using
>> spin_lock_irqsave() to safely dereference wdd->gov before invoking the
>> pretimeout callback.
>>
>> On architectures supporting pseudo-NMIs (ARM64 GICv3), watchdog drivers
>> may register their pretimeout warning interrupt (bark) as an NMI.
>> Because spin_lock_irqsave() disables regular interrupts but leaves NMIs
>> unmasked, if a pretimeout NMI fires while pretimeout_lock is already
>> held by normal process context, attempting to re-acquire pretimeout_lock
>> triggers an unrecoverable deadlock.
>>
>> To make pretimeout notifications completely safe to execute from NMI,
>> convert read access to wdd->gov inside watchdog_notify_pretimeout() from
>> a spinlock to lockless RCU. Use rcu_assign_pointer() when modifying
>> wdd->gov and invoke synchronize_rcu() during governor unregister and
>> pretimeout unregister routines.
>>
>> Signed-off-by: Mayank Rungta <[email protected]>
>> ---
>>   drivers/watchdog/watchdog_pretimeout.c | 47 +++++++++++++++++++---------------
>>   include/linux/watchdog.h               |  2 +-
>>   2 files changed, 27 insertions(+), 22 deletions(-)
> 
> I pre-reviewed this for Mayank. I'm not an RCU expert, but this looks
> right based on my understanding. My AI was also happy with it. ;-)
> 

Sashiko doesn't like it, claiming that some "const" are missing. And, indeed,
after applying it, I get:

drivers/watchdog/watchdog_pretimeout.c: In function ‘watchdog_pretimeout_governor_get’:
drivers/watchdog/watchdog_pretimeout.c:75:13: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
    75 |         gov = rcu_dereference(wdd->gov);
       |             ^
drivers/watchdog/watchdog_pretimeout.c: In function ‘watchdog_notify_pretimeout’:
drivers/watchdog/watchdog_pretimeout.c:110:13: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
   110 |         gov = rcu_dereference(wdd->gov);
       |             ^

Please fix.

Thanks,
Guenter
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.