Repository navigation
Conversation
scottjones
left a comment
There was a problem hiding this comment.
Thanks @ilyasakin, this is a really clear write-up. The zero-offset check is right and matches what the t8140 path already does, and the J514S repro and testing make it easy to follow.
One blocking thing, in a line this PR doesn't touch but that patch 2 now exercises. In the tick format, macsmc_rtc_set_time returns nvmem_cell_write()'s result directly (rtc-macsmc.c:155), and on success that's the byte count, 6, not 0. rtc_set_time passes it through, so with RTC_SYSTOHC=y, sync_hw_clock sees a nonzero result and re-arms every ~2 s instead of every 11 minutes, on every M1-M3 Mac. Nothing is logged, so your J514S run wouldn't have shown it.
The fix is to do what the seconds-format path at :149-150 already does:
ret = nvmem_cell_write(rtc->rtc_offset, &off, RTC_BYTES);
return ret < 0 ? ret : 0;Could you add that, and confirm with the rtc:rtc_set_time tracepoint that writes land about every 11 minutes?
The same line is upstream too (torvalds and AsahiLinux rtc-macsmc.c), and Fedora Asahi ships SYSTOHC=y, so it's probably worth reporting there as well.
A couple of small notes, not blockers:
- M4 (t8132), t8142-j813 and t8152-j873g have no RTC node, so SYSTOHC just gets -ENODEV there. That's harmless.
- macOS dual boot on M3 hasn't been tested after Linux rewrites the RTC. Worth one boot if you can.
Happy to approve with the fix.
macsmc_rtc_set_time() returns nvmem_cell_write()'s result in the tick-offset format, which on success is the number of bytes written, 6. rtc_set_time() passes that on, so callers take a successful write for a failure. With RTC_SYSTOHC, sync_hw_clock() retries at once: on a J514S (MacBook Pro 14", M3 Pro), the rtc:rtc_set_time tracepoint showed 270 writes in 30 seconds, each returning 6, instead of one every 11 minutes. Return 0 on success, as the offset-in-seconds format already does. Scott Jones found this in the review of the RTC_SYSTOHC change. Link: omacom#482 Assisted-by: Claude:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Ilyas Akin <[email protected]>
With the offset kept in RTC ticks, an offset of zero is read as a valid
time: the bare counter, the time since the PMU powered up. After the PMU
lost its RTC state on a J514S (MacBook Pro 14", M3 Pro), the offset read
as zero and the counter as about three days, so the RTC reported
1970-01-04. macsmc-rtc probes late, after systemd has set the clock from
its last saved timestamp, and RTC_HCTOSYS then set the system clock back
to 1970:
macsmc-rtc macsmc-rtc: setting system clock to 1970-01-04T09:09:21 UTC (292161)
Until NTP corrected it about 30 seconds later, TLS failed, and
tailscaled, which had started in that window, stayed logged out
("x509: certificate has expired or is not yet valid: current time
1970-01-04") until it was restarted.
Return -EINVAL for a zero offset, as the offset-in-seconds format
already does, so that the RTC core does not take it for the time.
Assisted-by: Claude:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Ilyas Akin <[email protected]>
Without RTC_SYSTOHC nothing writes the RTC back once NTP has set the clock: systemd-timesyncd does not, and the Omarchy kernel configuration disables it. An RTC that lost its time therefore stays wrong across every boot, until macOS or hwclock sets it. On a J514S whose PMU had lost its RTC offset, every boot started at 1970 until 'hwclock --systohc' stored it again. Enable it, as upstream's default and Omarchy's other kernels do, so the kernel stores the NTP time in rtc0 about every 11 minutes. Assisted-by: Claude:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Ilyas Akin <[email protected]>
|
Thanks, good catch. It's worse than every ~2 s on this machine. With I added the fix as a separate first commit ( Verified on the J514S with the fixed module and NTP synchronized, tracing That's two writes, both returning 0, 658 s apart. I'll report the return value upstream as well. macOS dual boot after Linux rewrites the RTC is still untested; I'll do one boot when I can and report back. |
|
Same issue on a MacBook Pro 14" M1 Pro (J314s / T6000), linux-aurora Boot log (monotonic): Side effects in the ~30 s window before NTP: Chromium web apps started in that window (Teams, Outlook) obtained Microsoft 365 tokens/cookies with expiry times based on the wrong clock and required a fresh sign-in after the jump, and files/sockets created then carry 1970 timestamps. Workaround that helped here: after NTP sync, a one-time Update after a reboot (warm reboot, no macOS boot in between): the offset persisted. No more 1970:
|
|
Same issue on a MacBook Pro 14" M1 Pro (J314s / T6000), linux-aurora Boot log (monotonic): Side effects in the ~30 s window before NTP: Chromium web apps started in that window (Teams, Outlook) obtained Microsoft 365 tokens/cookies with expiry times based on the wrong clock and required a fresh sign-in after the jump, and files/sockets created then carry 1970 timestamps. Workaround that helped here: after NTP sync, a one-time So on this machine the offset cell is writable and persists. Without |
|
One more board, plus a power-cycle result for the "survives the next reboot after the manual write" After Offset survived, clock correct at bind, 0 journal lines stamped 1970 that boot. Caveat: a minute of shutdown leaves the PMU battery-backed, so this does not cover a full battery Side note for #782: the gap between PID 1's restore and the rtc0 bind was 448 ms with a 114 s initrd |
What this changes and why
After the PMU on my J514S (MacBook Pro 14", M3 Pro) lost its RTC offset, every boot set the clock to 1970. TLS then failed in the window before NTP, and tailscaled, which starts in that window, stayed logged out until it was restarted.
What happened:
The T6030 offset cell (
rtc-offset@2100, 6 bytes of 32768 Hz ticks) read all zero, while the counter read about three days. Two things combined, plus a bug found in review:RTC_SYSTOHCsync_hw_clock()retried at once: 270 writes in 30 s on a J514S. It now returns 0, as the seconds format does. With the fix, a 25-minutertc:rtc_set_timetrace shows two writes, both returning 0, 658 s apart.macsmc-rtcprobes late, after systemd has set the clock from its saved timestamp, soRTC_HCTOSYSput the clock back to 1970.-EINVALfor a zero offset. This adds the same check to the tick format.RTC_SYSTOHC, and systemd-timesyncd does not write the RTC itself.hwclock --systohc.RTC_SYSTOHC, which is upstream's default and is on in Omarchy's other kernels (linux-omarchy,linux-omarchy-aarch64).What was tested
47e98d0b7was built with the omarchy-pkgslinux-aurorarecipe, pointed at the commit withtools/aurora-ci/prepare-recipe.py, as7.2.11.aurora16-1.2. It was installed and booted.CONFIG_RTC_SYSTOHC=y.I recreated the failure by writing six zero bytes to the PMU's
rtc-offset@2100through thespmi_nvmemnvmem file. Before the reboot, rtc0 read1970-01-04.Then I rebooted into the patched kernel:
The clock was not set back.
tailscaled logged in on the first try, with no x509 errors.
Four minutes after boot, rtc0 read the correct UTC time again (
2026-11-15 12:04:33), written by the kernel after NTP synced.timedatectlshowedRTCTimeUSec=Sun 1970-01-04even while NTP-synchronized.make W=1 drivers/rtc/rtc-macsmc.o(clang) is clean. checkpatch is clean apart from the trailers and the quoted log line.What was NOT tested
hwclock --systohchas always written it there.Risk
hwclockandRTC_HCTOSYSnow report an invalid time instead of 1970.AI assistance
🤖 Generated with Claude Code