Linux LED subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Atharva Tiwari" <atharvatiwarilinuxdev@gmail.com>
Cc: "Ihor Odainyi" <pv4k@odayny.com>,
	"Antoine Sidem" <sidemantoine@gmail.com>,
	"Aditya Garg" <aditya.garg@linux.dev>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Len Brown" <lenb@kernel.org>,
	"Linus Walleij" <linusw@kernel.org>,
	"Bartosz Golaszewski" <brgl@kernel.org>,
	"Sven Peter" <sven@kernel.org>, "Janne Grunau" <j@jannau.net>,
	"Neal Gompa" <neal@gompa.dev>,
	"Guenter Roeck" <linux@roeck-us.net>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>, "Lee Jones" <lee@kernel.org>,
	"Pavel Machek" <pavel@kernel.org>,
	"Griffin Kroah-Hartman" <griffin@kroah.com>,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Sebastian Reichel" <sre@kernel.org>,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	"Wim Van Sebroeck" <wim@linux-watchdog.org>,
	"Jarkko Sakkinen" <jarkko@kernel.org>,
	"Mimi Zohar" <zohar@linux.ibm.com>,
	"Roberto Sassu" <roberto.sassu@huawei.com>,
	"Dmitry Kasatkin" <dmitry.kasatkin@gmail.com>,
	"Eric Snowberg" <eric.snowberg@oracle.com>,
	"Paul Moore" <paul@paul-moore.com>,
	"James Morris" <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	linux-pci@vger.kernel.org, linux-gpio@vger.kernel.org,
	linux-hwmon@vger.kernel.org, linux-leds@vger.kernel.org,
	mfd@lists.linux.dev, linux-rtc@vger.kernel.org,
	linux-watchdog@vger.kernel.org, keyrings@vger.kernel.org,
	linux-security-module@vger.kernel.org
Subject: Re: [PATCH 03/14] watchdog: add driver for apple smc
Date: Fri, 04 Dec 2026 13:48:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-249898@kernel.org> (raw)
In-Reply-To: <20261204131619.5059-4-atharvatiwarilinuxdev@gmail.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] watchdog: macsmc_wdt: missing suspend/resume PM callbacks
- [Medium] mfd: macsmc: apple_smc_probe() checks only NATJ for
  macsmc-wdt
- [Medium] watchdog: macsmc_wdt: unsynchronized NATJ/NATi writes can
  force reset
- [Medium] watchdog: macsmc_wdt: apple_smc_key_exists() causes 1s PIO
  timeout stalls
- [Low] watchdog: macsmc_wdt uses obsolete __MODULE_STRING() and omits
  direct headers
--

commit dd87f5854d512b3a6e66e9d3cd77fe418fb3e73a
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>

watchdog: add driver for apple smc

This commit adds a watchdog driver for the Apple SMC on Intel Macs,
supporting both newer OSWD and legacy NATJ/NATi SMC keys, and registers
the platform device from macsmc-core.

> diff --git a/drivers/mfd/macsmc-core.c b/drivers/mfd/macsmc-core.c
> index b8905c834c448..1c14698285456 100644
> --- a/drivers/mfd/macsmc-core.c
> +++ b/drivers/mfd/macsmc-core.c

[ ... ]

> @@ -147,6 +151,13 @@ int apple_smc_probe(struct device *dev, const struct apple_smc_backend_ops *ops,
>  				return ret;
>  		}
>  
> +		if (apple_smc_key_exists(smc, SMC_KEY(NATJ))) {
> +			ret = devm_mfd_add_devices(dev, -1, apple_smc_acpi_wdt,
> +				ARRAY_SIZE(apple_smc_acpi_wdt), NULL, 0, NULL);
> +			if (ret < 0)
> +				return ret;
> +		}
> +
>  	} else

[Severity: Medium]
Should this check also accept SMC_KEY(OSWD) and require SMC_KEY(NATi)
alongside SMC_KEY(NATJ)?

On newer Intel Macs that expose OSWD without the legacy NATJ key,
apple_smc_probe() never registers macsmc-wdt.  Conversely, on an SMC with
NATJ but without OSWD or NATi, macsmc_wdt_probe() falls back to
has_oswd = false and registers a watchdog whose operations fail with -EIO.

Checking for OSWD or both NATJ and NATi in apple_smc_probe() and
macsmc_wdt_probe() avoids both cases.

[ ... ]

> diff --git a/drivers/watchdog/macsmc_wdt.c b/drivers/watchdog/macsmc_wdt.c
> new file mode 100644
> index 0000000000000..e2fc7f4e3e4b7
> --- /dev/null
> +++ b/drivers/watchdog/macsmc_wdt.c
> @@ -0,0 +1,158 @@

[ ... ]

> +#include <linux/mfd/macsmc.h>
> +#include <linux/platform_device.h>
> +#include <linux/watchdog.h>
> +
> +#define WATCHDOG_TIMEOUT 60 /* 60 sec default timeout */
> +
> +static bool nowayout = WATCHDOG_NOWAYOUT;
> +module_param(nowayout, bool, 0);
> +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started default="
> +		 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
> +
> +static int timeout = WATCHDOG_TIMEOUT; /* in secounds */
> +module_param(timeout, int, 0);
> +MODULE_PARM_DESC(timeout,
> +		 "Watchdog timeout in seconds. 1 <= timeout <= 255, default="
> +		 __MODULE_STRING(WATCHDOG_TIMEOUT) ".");

[Severity: Low]
Can __MODULE_STRING() be replaced with __stringify() here?  It is marked
obsolete and scheduled for removal in include/linux/module.h, and no other
callers remain in the tree.

The file also omits direct includes of linux/module.h and linux/stringify.h
despite using module macros, and the nowayout MODULE_PARM_DESC() has an
unmatched closing parenthesis before the end of the string.

[ ... ]

> +		if (timeout == 0) {
> +			ret = apple_smc_write_u8(drv->smc, SMC_KEY(NATJ), 0);
> +			if (ret < 0)
> +				return ret;
> +		}
> +		ret = apple_smc_write_u16(drv->smc, SMC_KEY(NATi), (u16)(timeout << 8));
> +		if (ret < 0)
> +			return ret;
> +
> +		if (timeout != 0) {
> +			ret = apple_smc_write_u8(drv->smc, SMC_KEY(NATJ), 2);
> +			if (ret < 0)
> +				return ret;
> +		}

[Severity: Medium]
Can concurrent stop and start/set_timeout calls interleave these NATJ and
NATi writes into a forced reset?

macsmc_wdt_probe() enables watchdog_stop_on_reboot(), which calls
macsmc_wdt_stop() without wd_data->lock while userspace can still issue
watchdog ioctls.  Because apple_smc_write() only holds smc->mutex per
key write, the two-key sequence can interleave:

CPU0 (ioctl)                      CPU1 (reboot notifier)
macsmc_wdt_set_timeout()          watchdog_reboot_notifier()
  macsmc_wdt_write_timeout(t)       macsmc_wdt_stop()
    write(NATi, t << 8)               macsmc_wdt_write_timeout(0)
                                        write(NATJ, 0)
                                        write(NATi, 0)
    write(NATJ, 2)  <-- NATi == 0, NATJ == 2: forced reset

Leaving NATi == 0 with NATJ == 2 triggers an immediate forced restart on
legacy !has_oswd Macs.  Serializing macsmc_wdt_write_timeout() and
macsmc_wdt_ping() with a mutex in struct macsmc_wdt prevents this race.

[ ... ]

> +	drv->smc = dev_get_drvdata(pdev->dev.parent);
> +	if (apple_smc_key_exists(drv->smc, SMC_KEY(OSWD)))
> +		drv->has_oswd = true;
> +	else
> +		drv->has_oswd = false;

[Severity: Medium]
Does probing a missing key via apple_smc_key_exists() stall for 1 second
on PIO-based Intel Macs?

On PIO Macs (!smc->is_mmio), apple_smc_get_key_info() dispatches to
apple_smc_acpi_port_read(), which has no error-status check and only fails
when apple_smc_acpi_port_wait() times out after SMC_TIMEOUT_MS (1000 ms).

This deterministically stalls probe for 1 second while holding smc->mutex
on every older PIO Mac without OSWD (and likewise for the NATJ check in
apple_smc_probe() on PIO Macs without NATJ), blocking concurrent SMC
accesses from sibling MFD drivers.

[ ... ]

> +static struct platform_driver macsmc_wdt_driver = {
> +	.probe = macsmc_wdt_probe,
> +	.driver = {
> +		.name = "macsmc-wdt",
> +	},
> +};

[Severity: High]
Does macsmc_wdt_driver need suspend and resume PM callbacks to stop an
active watchdog across system sleep?

The watchdog core does not stop hardware watchdogs in
watchdog_dev_suspend(), so an armed SMC watchdog (at most 255 seconds)
will expire while the host CPU is suspended and force a hard reset.

Conversely, if the SMC clears its watchdog keys across sleep, the lack of
a resume callback leaves the hardware watchdog silently disabled after
resume while WDOG_ACTIVE remains set.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=3

  reply	other threads:[~2026-12-04 13:48 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
2026-12-04 13:12 ` [PATCH 01/14] treewide: Add backend for macsmc Atharva Tiwari
2026-12-04 13:56   ` sashiko-bot
2026-12-04 14:07   ` Andy Shevchenko
2026-12-04 16:45   ` Sven Peter
2026-12-04 13:12 ` [PATCH 02/14] platform/x86: add backend for macsmc in intel macs Atharva Tiwari
2026-12-04 13:58   ` sashiko-bot
2026-12-04 14:19   ` Andy Shevchenko
2026-12-04 14:52     ` Aditya Garg
2026-12-04 17:23       ` Andy Shevchenko
2026-12-04 18:34         ` Aditya Garg
2026-12-04 19:57     ` Atharva Tiwari
2026-12-04 20:23       ` Andy Shevchenko
2026-12-04 13:12 ` [PATCH 03/14] watchdog: add driver for apple smc Atharva Tiwari
2026-12-04 13:48   ` sashiko-bot [this message]
2026-12-04 13:12 ` [PATCH 04/14] iio/light: add new driver for macsmc Atharva Tiwari
2026-12-04 13:47   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 05/14] iio/accel: add driver for apple SMS Atharva Tiwari
2026-12-04 14:11   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 06/14] leds: add support for macsmc kbl Atharva Tiwari
2026-12-04 14:07   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc Atharva Tiwari
2026-12-04 14:12   ` Andy Shevchenko
2026-12-04 14:48     ` Aditya Garg
2026-12-04 17:06       ` Andy Shevchenko
2026-12-04 17:10         ` Aditya Garg
2026-12-04 17:18           ` Andy Shevchenko
2026-12-04 17:26       ` Sven Peter
2026-12-04 14:16   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 08/14] treewide: Add a flag to detect the Apple T2 chip Atharva Tiwari
2026-12-04 14:11   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 09/14] treewide: disable other rtc's in t2 macs Atharva Tiwari
2026-12-04 14:27   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power Atharva Tiwari
2026-12-04 14:39   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 11/14] acpi: disable battery and adapter for x86 apple machines Atharva Tiwari
2026-12-04 14:08   ` Andy Shevchenko
2026-12-04 14:56     ` Aditya Garg
2026-12-04 17:14       ` Andy Shevchenko
2026-12-04 18:51         ` Aditya Garg
2026-12-04 20:02           ` Andy Shevchenko
2026-12-04 20:13             ` Andy Shevchenko
2026-12-04 14:25   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 12/14] hwmon/macsmc: add more types Atharva Tiwari
2026-12-04 14:37   ` sashiko-bot
2026-12-04 18:44     ` Guenter Roeck
2026-12-04 13:12 ` [PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon Atharva Tiwari
2026-12-04 14:48   ` sashiko-bot
2026-12-04 18:45     ` Guenter Roeck
2026-12-04 20:13       ` Jarkko Sakkinen
2026-12-04 13:12 ` [PATCH 14/14] mfd/macsmc: add ioctl to access smc keys Atharva Tiwari
2026-12-04 13:40   ` Sasha Finkelstein
2026-12-04 19:43     ` Atharva Tiwari
2026-12-04 14:48   ` sashiko-bot
2026-12-04 14:20 ` [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Andy Shevchenko

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=sashiko-outbox-249898@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=aditya.garg@linux.dev \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andy@kernel.org \
    --cc=atharvatiwarilinuxdev@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=bp@alien8.de \
    --cc=brgl@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=dlechner@baylibre.com \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=eric.snowberg@oracle.com \
    --cc=griffin@kroah.com \
    --cc=hansg@kernel.org \
    --cc=hpa@zytor.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=j@jannau.net \
    --cc=jarkko@kernel.org \
    --cc=jic23@kernel.org \
    --cc=jmorris@namei.org \
    --cc=keyrings@vger.kernel.org \
    --cc=lee@kernel.org \
    --cc=lenb@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mfd@lists.linux.dev \
    --cc=mingo@redhat.com \
    --cc=neal@gompa.dev \
    --cc=nuno.sa@analog.com \
    --cc=paul@paul-moore.com \
    --cc=pavel@kernel.org \
    --cc=pv4k@odayny.com \
    --cc=rafael@kernel.org \
    --cc=roberto.sassu@huawei.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=serge@hallyn.com \
    --cc=sidemantoine@gmail.com \
    --cc=sre@kernel.org \
    --cc=sven@kernel.org \
    --cc=tglx@kernel.org \
    --cc=wim@linux-watchdog.org \
    --cc=x86@kernel.org \
    --cc=zohar@linux.ibm.com \
    /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