Linux Watchdog driver development
 help / color / mirror / Atom feed
From: "Paul Louvel" <paul.louvel@bootlin.com>
To: "Guenter Roeck" <linux@roeck-us.net>,
	<sashiko-reviews@lists.linux.dev>,
	"Paul Louvel" <paul.louvel@bootlin.com>
Cc: <linux-watchdog@vger.kernel.org>
Subject: Re: [PATCH v2 5/8] watchdog: w83627hf_wdt: Add Super I/O configuration port as a platform device resource
Date: Wed, 23 Sep 2026 16:03:25 +0200	[thread overview]
Message-ID: <DLMR324EQEUG.2G5RGH1X4B6PY@bootlin.com> (raw)
In-Reply-To: <2368bc26-634e-4691-a369-25090913ec50@roeck-us.net>

Hi Guenter,

Sorry for not responding to your email earlier.

On Mon Jul 27, 2026 at 3:08 AM CEST, Guenter Roeck wrote:
> On 7/26/26 11:56, sashiko-bot@kernel.org wrote:
>> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>> - [Critical] Claiming the shared Super I/O configuration port as a static platform device resource causes a Use-After-Free and breaks global mutual exclusion upon module unload.
>> --
>> 
>> --- Patch [5]: [PATCH v2 5/8] watchdog: w83627hf_wdt: Add Super I/O configuration port as a platform device resource ---
>> commit 7147d011852b779a7e376729ecb29c06b86e9282
>> Author: Paul Louvel <paul.louvel@bootlin.com>
>> 
>> watchdog: w83627hf_wdt: Add Super I/O configuration port as a platform device resource
>> 
>> This commit changes the Super I/O configuration port address from a
>> global variable to a platform device resource. It uses
>> platform_device_register_resndata() to assign the IO resource during
>> module initialization.
>> 
>>> diff --git a/drivers/watchdog/w83627hf_wdt.c b/drivers/watchdog/w83627hf_wdt.c
>>> index 69d4230d8f6cc..a067b8ea6b289 100644
>>> --- a/drivers/watchdog/w83627hf_wdt.c
>>> +++ b/drivers/watchdog/w83627hf_wdt.c
>> [ ... ]
>>> @@ -594,8 +597,14 @@ static int __init wdt_init(void)
>>>   	if (ret)
>>>   		return ret;
>>>   
>>> -	wdt_pdev = platform_device_register_data(NULL, wdt_ids[chip].name,
>>> -						 PLATFORM_DEVID_NONE, NULL, 0);
>>> +	res.name = "Super I/O port";
>>> +	res.flags = IORESOURCE_IO;
>>> +	res.start = sioaddr;
>>> +	res.end = sioaddr + 1;
>>> +
>>> +	wdt_pdev = platform_device_register_resndata(NULL, wdt_ids[chip].name,
>>> +						     PLATFORM_DEVID_NONE, &res,
>>> +						     1, NULL, 0);
>> 
>> [Severity: Critical]
>> Does claiming the shared Super I/O configuration port as a static platform
>> device resource cause a use-after-free regression and break mutual exclusion
>> on module unload?
>> 
>> If this port is registered as a non-busy I/O resource, it becomes a
>> container node in the global ioport_resource tree. When another driver
>> calls request_muxed_region() for the same port, it might sleep on
>> muxed_resource_wait while holding a parent pointer to this container node.
>> 
>> If the wdt module is unloaded while that thread is sleeping,
>> platform_device_del() unlinks the container node and
>> platform_device_release() frees its memory. When the sleeping thread
>> wakes up, will it dereference the freed parent pointer in
>> __request_resource()?
>> 
>> Additionally, it appears that unlinking the container node orphans any
>> active child reservations from the tree. Could this allow concurrent
>> hardware access to the shared Super I/O port?
>> 
>
> That makes me wonder: Under which authority can the watchdog driver claim
> ownership of this resource ? What is the rationale ?
>
> Why should the owner not be, for example, the hardware monitoring driver ?
> Or the Bluetooth driver, if the chip has one ? Or some other driver ?
> Or some non-existent Super-IO core ?

Yes, it should not.
Was a misunderstanding of my part. Did not know that adding a resource in driver
registration would cause resource contention if other drivers try to access the
SIO extended function mode.

>
> On a higher level, why even risk the problem outlined by Sashiko above ?
> What is the benefit of doing this ? The patch description fails to
> explain _why_ this change is made. Actually, that is true for many
> of the patches. Quite often the description explain what is done,
> but not the reason for it. The reason may be obvious for you, but not
> or not always for me - and very much so for this patch.
>
> Please explain why you are making those changes.

My bad if it was not clear.
This series is an attempt of modernizing this driver to a platform driver so
that it can use modern kernel APIs, expose sysfs interface, and clean the
driver.

And also add minute mode counting that is a feature that is just missing from
the driver. Maybe it should be a subject for another patch, outside of this
series ?

>
> Also, I notice that at least in some cases it looks like you did not
> address the feedback from Sashiko. Partially that is because problems
> in one patch are addressed in a later patch of the series, but I am quite
> sure I have seen Sashiko's feedback about the missing parent device
> initialization before. Please ensure to address its feedback.

Sashiko reviews will be taken into account for the next iteration.

>
> Thanks,
> Guenter

Thanks,
Paul.




-- 
Paul Louvel, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


  reply	other threads:[~2026-09-23 14:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-26 18:44 [PATCH v2 0/8] watchdog: w83627hf_wdt: Convert driver to the driver model and add minute support Paul Louvel
2026-07-26 18:44 ` [PATCH v2 1/8] watchdog: w83627hf_wdt: Replace magic numbers with descriptive macros Paul Louvel
2026-07-26 18:44 ` [PATCH v2 2/8] watchdog: w83627hf_wdt: Convert to platform driver model Paul Louvel
2026-07-26 18:57   ` sashiko-bot
2026-07-26 18:44 ` [PATCH v2 3/8] watchdog: w83627hf_wdt: Use private driver data structure Paul Louvel
2026-07-26 18:44 ` [PATCH v2 4/8] watchdog: w83627hf_wdt: Move register offsets into driver data Paul Louvel
2026-07-26 18:44 ` [PATCH v2 5/8] watchdog: w83627hf_wdt: Add Super I/O configuration port as a platform device resource Paul Louvel
2026-07-26 18:56   ` sashiko-bot
2026-07-27  1:08     ` Guenter Roeck
2026-09-23 14:03       ` Paul Louvel [this message]
2026-07-26 18:44 ` [PATCH v2 6/8] watchdog: w83627hf_wdt: Store Super I/O unlocking sequence in platform data Paul Louvel
2026-07-26 18:55   ` sashiko-bot
2026-07-26 18:44 ` [PATCH v2 7/8] watchdog: w83627hf_wdt: Add minute mode counting Paul Louvel
2026-07-26 18:44 ` [PATCH v2 8/8] watchdog: w83627hf_wdt: Report all initialization failures in probe Paul Louvel
2026-07-26 18:56   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DLMR324EQEUG.2G5RGH1X4B6PY@bootlin.com \
    --to=paul.louvel@bootlin.com \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox