Repository navigation
Input: macsmc-input - confirm a lid-open report during system sleep - #1160
Conversation
RyanTheTide
left a comment
There was a problem hiding this comment.
The MSLD cross-check looks safe for every machine: it only drops an open report that the SMC's own lid key contradicts.
The lid_wake_settle_ms window is a wider change, though. It applies to every machine macsmc-input binds on, not only the J716s. On a machine whose SMC never sends the spurious report, closing the lid and opening it again within 2 s of .prepare now leaves the system asleep: MSLD agrees (0) and ms <= lid_wake_settle_ms, so the real open report is held. If the SMC sends no further lid event, the machine stays suspended until another wake source fires.
Could the settle window be limited to the SoCs where the false report has been seen (match data on the compatible, or a DT property on the input node), with 0 as the default elsewhere? The MSLD check could then stay for all machines.
Also, the hold-back path has not fired on hardware yet. A log from a sleep where it does, with lid after sleep: MSLD=... from .complete, would confirm that SW_LID resyncs as intended.
On the J716s (MacBook Pro 16-inch, M5 Pro) closing the lid starts a
suspend through logind, and the system is awake again 0.7 s later. The
SMC's own syslog shows the cause: about 230 ms after the close
("SMC HID Event: 03 01 00") it reports the lid open ("03 00 01", event
0x72030001, the same bytes as a real opening) while the lid stays shut,
at the same moment as the trackpad coprocessor logs "Sending Cumulus
Report to enter Dependent Mode" (Cumulus is the touch AFE). The driver
takes the report at face value: it is in the sleep window, so it reports
a hard wakeup, pm_system_wakeup() aborts the suspend or ends
suspend-to-idle, and logind then reads "Lid opened".
In the sleep window, between .prepare and .complete, check a lid-open
report before passing it on. Read the SMC's lid key MSLD, the one probe
reads the initial state from: if it says closed, the report is dropped.
If it agrees but the sleep has run for lid_settle_ms or less, the report
does not wake the system either. lid_settle_ms is 2000 on the J716s, the
only machine where the false report has been seen, and 0 everywhere
else, so other machines keep waking on the first open report that MSLD
confirms; the lid_wake_settle_ms module parameter overrides it at load
time (-1 = per-machine default, 0 = never hold). The machine is matched
with of_machine_is_compatible() because macsmc-input is an MFD cell
without a node of its own. A held-back report leaves SW_LID closed, and
.complete reports MSLD again, so the switch matches the SMC after any
wakeup. Each decision is logged with the event, the time into the sleep
and MSLD, so a test can tell which check fired.
The notifier runs in the SMC's RTKit worker and the SMC's replies are
taken from the mailbox interrupt (recv_message_early), so reading a key
there does not wait on the worker. The sleep time is taken from
CLOCK_BOOTTIME, which includes the time suspend-to-idle spends with
timekeeping suspended.
What this does not fix, on the J716s: if MSLD agrees with the false
report, the SMC already counts the lid as open, and the real opening
that follows may send no event at all. The system then stays asleep
until a key, a trackpad click or the power button wakes it, instead of
waking at once.
Not changed: lid-close reports, the power button, and any lid-open
report outside the sleep window.
Tested on the J716s with logind suspending on lid close (s2idle): the
close sleeps ("Timekeeping suspended for 39.477 seconds") and the real
opening wakes it through the confirm path ("lid open 72030001 at +40069
ms in sleep, MSLD=0: wakeup"). No spurious report came during that
sleep, so the hold-back path has not run on hardware yet.
Signed-off-by: Rolando Trevino <rolotrealanis@gmail.com>
Assisted-by: LLM Claude
238be1b to
9423412
Compare
|
Updated (9423412), rebased onto integration/aurora 0227cec.
The hold-back path still has not fired on hardware: the sleeps logged so far only took the confirm path. I will post a log with |
a31e6fc
into
aurora-silicon:integration/aurora
On the J716s (MacBook Pro 16-inch, M5 Pro) closing the lid starts an s2idle suspend through logind, and the system was awake again 0.7 s later. The SMC itself emits the lid-open event (
SMC HID Event: 03 00 01, notification 0x72030001, the same bytes as a real opening) about 230 ms after the close while the lid stays shut; macsmc-input reports it as a hard wakeup, the suspend aborts and logind reads "Lid opened". With no suspend configured, close and open (03 01 00/03 00 01) track the lid faithfully, so the false report only comes on the sleep path.During system sleep (between
.prepareand.complete) this patch confirms a lid-open report against the SMC'sMSLDkey (the one probe reads the initial state from) and ignores one that comes withinlid_wake_settle_ms(default 2000 ms, 0 restores today's behaviour) of the sleep's start, measured with CLOCK_BOOTTIME. A held-back report leaves SW_LID closed and.completeresynchronises it fromMSLD. Every decision is logged with the event, the time into the sleep andMSLD.Tested on: J716s, kernel = integration/aurora + the T6050 series + this patch, logind
HandleLidSwitch=suspend,SuspendState=mem(s2idle). Lid closed for 30 s:PM: suspend entry->Timekeeping suspended for 39.477 seconds->macsmc-input: lid open 72030001 at +40069 ms in sleep, MSLD=0: wakeup-> resume ->Lid opened.,suspend_statssuccess 1 / fail 0, USB and Ethernet back. That run had no spurious report, so the confirm path was exercised and the hold-back path was not. It is now in our daily kernel.drivers/input/misc/macsmc-input.obuilds withW=1(LLVM, arm64) onintegration/aurora4114f76; checkpatch--strictclean.Dependencies: none.
Open questions: