From: sashiko-bot@kernel.org
To: "Atharva Tiwari" <atharvatiwarilinuxdev@gmail.com>
Cc: "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 07/14] rtc: add support for x86 macs in macsmc-rtc
Date: Fri, 04 Dec 2026 14:16:25 +0000 [thread overview]
Message-ID: <sashiko-outbox-249947@kernel.org> (raw)
In-Reply-To: <20261204131619.5059-8-atharvatiwarilinuxdev@gmail.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] rtc: macsmc: shift underflow and UB on invalid CLKR in
macsmc_rtc_probe()
- [Medium] rtc: macsmc: valid timestamps rejected with -EAGAIN in
macsmc_rtc_read_clkl()
- [Medium] rtc: macsmc: unthrottled CLKL retries amplify SMC timeouts to
160+ seconds
- [Low] rtc: macsmc: inconsistent CLKR and key logging in
macsmc_rtc_probe()
- [Low] rtc: macsmc: undocumented CLKL protocol, magic values, and
force_clkm param
--
commit 6ab7cff8bec4fb4d17c73d18ad219c5e9e888129
Author: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
> rtc: add support for x86 macs in macsmc-rtc
>
> Make macsmc-rtc work on Intel Macs. The ACPI RTC doesn't
> work correctly on T2 Macs, so the clock from the SMC is
> used instead.
>
> On these machines the time offset is kept in the SMC instead
> of NVMEM, and the clock rate is read from the SMC too.
>
> Tested-by: Aditya Garg <aditya.garg@linux.dev>
> Signed-off-by: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
[Severity: Low]
This isn't a bug, but the commit message does not explain the new CLKL
latch/poll protocol or the force_clkm module parameter. Documenting why CLKL
is needed over CLKM and what its magic values (0xffffffffffffULL, 0x7fff, 5,
6) mean in the changelog and comments would help maintainability.
Also, the CLKL/CLKM read logic is duplicated in macsmc_rtc_get_time() and
macsmc_rtc_set_time(), and macsmc_rtc_probe() splits the rtc->smc->is_acpi
check across two adjacent if blocks.
> diff --git a/drivers/rtc/rtc-macsmc.c b/drivers/rtc/rtc-macsmc.c
> index 8fe8830669569..900a46339f72f 100644
> --- a/drivers/rtc/rtc-macsmc.c
> +++ b/drivers/rtc/rtc-macsmc.c
[ ... ]
> +static int macsmc_rtc_read_clkl(struct macsmc_rtc *rtc, u64 *ctr)
> +{
> + u64 request = 0xffffffffffffULL;
> + u64 response = 0;
> + int i, j, ret;
> +
> + for (i = 0; i < 4; i++) {
> + for (j = 0; j < 40; j++) {
> + ret = apple_smc_write(rtc->smc, SMC_KEY(CLKL), &request, RTC_BYTES);
> + if (ret == RTC_BYTES)
> + break;
> + }
> + if (ret != RTC_BYTES)
> + continue;
> +
> + msleep(20);
> +
> + for (j = 0; j < 20; j++) {
> + ret = apple_smc_read(rtc->smc, SMC_KEY(CLKL), &response, RTC_BYTES);
[Severity: Medium]
Can these retry loops block for 160+ seconds when the SMC is unresponsive?
The outer and inner loops perform up to 160 apple_smc_write() attempts with
no delay, backoff, timeout bailout, or signal check, followed by msleep(20)
and up to 80 apple_smc_read() attempts. In macsmc-acpi.c, SMC_TIMEOUT_MS is
1000 ms, so timed-out CLKL transactions amplify into multi-minute stalls.
Because RTC callers hold rtc->ops_lock and every SMC transaction takes the
shared smc->mutex, a stall exceeds the hung-task timeout and blocks sibling
SMC subdevices as well as boot, suspend/resume, and sysfs RTC readers. Even
on healthy hardware, msleep(20) adds at least 20 ms to every CLKL access.
> + if (ret == RTC_BYTES) {
> + if ((response & 0x7fff) == 5 || (response & 0x7fff) == 6)
> + return -EAGAIN;
> +
> + if (response != 0xffffffffffffULL) {
> + *ctr = response;
> + return RTC_BYTES;
> + }
> + }
[Severity: Medium]
Will masking response with 0x7fff reject valid timestamps with -EAGAIN?
The lower 15 bits of the 48-bit counter are the sub-second ticks at 32768 Hz,
so any valid counter value whose low 15 bits equal 5 or 6 (twice every second)
aborts immediately. Neither macsmc_rtc_read_clkl() nor RTC core callers such
as rtc_hctosys() retry on -EAGAIN, causing sporadic RTC read/write failures.
[ ... ]
> @@ -102,18 +171,40 @@ static int macsmc_rtc_probe(struct platform_device *pdev)
[ ... ]
> + if (rtc->smc->is_acpi) {
> + ret = apple_smc_read_u32(rtc->smc, SMC_KEY(CLKR), &clkr);
> + if (ret < 0 || clkr == 0xFFFFFFFF)
> + rtc->shift = RTC_SEC_SHIFT;
> + else
> + rtc->shift = ffs(clkr) - 1;
[Severity: Medium]
Can an invalid CLKR value underflow rtc->shift and cause shift-out-of-bounds
undefined behavior?
If firmware returns clkr == 0, ffs(0) - 1 wraps uint8_t rtc->shift to 255.
That makes the 64-bit shifts for range_min/range_max in macsmc_rtc_probe()
(by 271 bits) and the shifts in macsmc_rtc_get_time() and
macsmc_rtc_set_time() (by 255 bits) undefined behavior.
Any non-power-of-two clkr also silently computes the wrong shift. Checking
ret < 0 || !is_power_of_2(clkr) rejects 0, 0xFFFFFFFF, and non-powers of two
while keeping rtc->shift in 0..31.
[ ... ]
> + dev_info(&pdev->dev, "%u clock, using %s key\n", (clkr != 0xFFFFFFFF) ? clkr : 32768,
> + rtc->async_rtc ? "CLKL" : "CLKM");
[Severity: Low]
Can this dev_info() log a bogus clock rate or the wrong key?
If apple_smc_acpi_port_read() fails partway through reading CLKR, it has
already written partial bytes into clkr before returning -EIO, so clkr is no
longer 0xFFFFFFFF even though rtc->shift fell back to RTC_SEC_SHIFT. Using
1U << rtc->shift avoids printing that corrupted value.
Also, rtc->async_rtc ? "CLKL" : "CLKM" ignores force_clkm, so with
force_clkm=1 on a CLKL system probe logs "using CLKL key" while get/set_time
actually use CLKM.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com?part=7
next prev parent reply other threads:[~2026-12-04 14:16 UTC|newest]
Thread overview: 53+ 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
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 [this message]
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 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-249947@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=rafael@kernel.org \
--cc=roberto.sassu@huawei.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=serge@hallyn.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