From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796393787; b=vYl5dT/jqHKV77/pLmRyKeQ63ZsKCKjvJQInt5xF/DRNpeLMwcPRlLf6uioSQWZGpkXj 0AmcrFLR07WVqv4IbNgKOkZd+OGvnkZJmWFSkpa1tMwx62hA6+KGp4YFYI5WcaNLCwvBE y7cx9iubn1ytS4pYN1UnbRF/7TNT81u+EF3xFT8/w4LO4vJC9n9gM1Bd5X4fEA0Ozu251 i6KVzEHnsUJZAk25AaC6v+YVbPA2Jjqc8kWHTjqnhmRphLKRSC0nF8B9a4PhbHmTvXuTM 50bjig7qN9wNX5QdjH3cQRMdAnECsdRkaEHMsCKr3VMidOloya2Q6iAagfo64Muku7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796393787; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=sHNNLgcTnC5eqVs2xi4+pVYgScY0AADVPb/ze12eL9g=; b=cXoW/qZs8E2+D8iYsYYW5OlsyLo1Ii5rb1C0pQNBhV/VcXd6phQLCJulpeI/GmRqhvlg Jtk0WeKrlb83ci2Yb3pXIdXK1HCzvl6ETHzMgetvMB9pkZl2pKlyHVXCpGwOZO4bOddPq NPnBLVtulju2gN7DtkAuZhyYFgSQVd24QiPFBIgagqKfA0zKKES8mPpqX6WdRVq2hgzHo m5axUyFk6j+UjYXne3jBTvNU1ptSxDdRGc03vlLWiabodu4SSHQfG14wi4S/a8FVdDv7N gkVIWKdNeUwDg+bTac7N1cT1iAQ3VANU8P398px4D1DvE6DvqAWb9zYEzZyR4cHWeIQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=V4b9G4ig; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CCF2606A335; Fri, 4 Dec 2026 14:16:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=V4b9G4ig Received: by smtp.kernel.org (Postfix) with ESMTPSA id 939581F000C2; Fri, 4 Dec 2026 14:16:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796393787; bh=sHNNLgcTnC5eqVs2xi4+pVYgScY0AADVPb/ze12eL9g=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=V4b9G4igCBV3CcvoYv2N3IxwhbGB6/IVGM0h3PrFfE8zrU51xMC0NYQvjqp0qwaCN WB2T0279vc7ZZqoGz1jqwHEbRXOmTYdINX/OHFaMBTV7HST5Jm1GAi/eDov+1tO2zb zKXuV99uY3qaCRwOpI6ZUvFGUln56JtvMA8R3jfB+tzRpoTFM5SiWJfYXpkdV3uhFp Ko43AjrEuK2BG6+7zr9WVs0XTujKOFAL+Ecuj0azihq5d5+feD5me8a8wPQPdBFJ62 nzi79U/PA4MntrmUMwe/7Y7ofqrGfqhk3ugSDvPFcS4lq//EIqAF86CahSOwiDIb1a FWKcB8hvkWx0Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc Reply-To: sashiko-reviews@lists.linux.dev To: "Atharva Tiwari" Cc: "Aditya Garg" , "Bjorn Helgaas" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , x86@kernel.org, "H. Peter Anvin" , "Rafael J. Wysocki" , "Len Brown" , "Linus Walleij" , "Bartosz Golaszewski" , "Sven Peter" , "Janne Grunau" , "Neal Gompa" , "Guenter Roeck" , "Jonathan Cameron" , "David Lechner" , =?utf-8?b?TnVubyBTw6E=?= , "Andy Shevchenko" , "Lee Jones" , "Pavel Machek" , "Griffin Kroah-Hartman" , "Hans de Goede" , =?utf-8?b?SWxwbyBKw6RydmluZW4=?= , "Sebastian Reichel" , "Alexandre Belloni" , "Wim Van Sebroeck" , "Jarkko Sakkinen" , "Mimi Zohar" , "Roberto Sassu" , "Dmitry Kasatkin" , "Eric Snowberg" , "Paul Moore" , "James Morris" , "Serge E. Hallyn" , 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 In-Reply-To: <20261204131619.5059-8-atharvatiwarilinuxdev@gmail.com> References: <20261204131619.5059-1-atharvatiwarilinuxdev@gmail.com> <20261204131619.5059-8-atharvatiwarilinuxdev@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 14:16:25 +0000 X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 > 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 > Signed-off-by: Atharva Tiwari [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 CL= KL 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 =3D 0xffffffffffffULL; > + u64 response =3D 0; > + int i, j, ret; > + > + for (i =3D 0; i < 4; i++) { > + for (j =3D 0; j < 40; j++) { > + ret =3D apple_smc_write(rtc->smc, SMC_KEY(CLKL), &request, RTC_BYTES); > + if (ret =3D=3D RTC_BYTES) > + break; > + } > + if (ret !=3D RTC_BYTES) > + continue; > + > + msleep(20); > + > + for (j =3D 0; j < 20; j++) { > + ret =3D 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 =3D=3D RTC_BYTES) { > + if ((response & 0x7fff) =3D=3D 5 || (response & 0x7fff) =3D=3D 6) > + return -EAGAIN; > + > + if (response !=3D 0xffffffffffffULL) { > + *ctr =3D 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 H= z, so any valid counter value whose low 15 bits equal 5 or 6 (twice every seco= nd) aborts immediately. Neither macsmc_rtc_read_clkl() nor RTC core callers su= ch 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 =3D apple_smc_read_u32(rtc->smc, SMC_KEY(CLKR), &clkr); > + if (ret < 0 || clkr =3D=3D 0xFFFFFFFF) > + rtc->shift =3D RTC_SEC_SHIFT; > + else > + rtc->shift =3D 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 =3D=3D 0, ffs(0) - 1 wraps uint8_t rtc->shift to 2= 55. 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 !=3D 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=3D1 on a CLKL system probe logs "using CLKL key" while get/set_t= ime actually use CLKM. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204131619.5059= -1-atharvatiwarilinuxdev@gmail.com?part=3D7