Skip to content

soc: apple: sep: recover a failed Touch ID sensor registration at boot (CLEAR_STATE retry, stale-frame and stale-reply handling) - #325

Merged
RyanTheTide merged 5 commits into
aurora-wipfrom
j700/sep-boot-registration-20261016
Oct 16, 2026
Merged

RyanTheTide merged 5 commits into
aurora-wipfrom
j700/sep-boot-registration-20261016

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

This fixes the MacBook Neo (J700) Touch ID boot-registration failure. On the unmodified release7 kernel, 7 of 16 boots ended without Touch ID until the next reboot. With this series, every one of 104 cold boots registers Touch ID.

Root cause of the permanent failure (ours). A failed first sensor registration was retried without CLEAR_STATE, so the enclave kept the half-done registration and every retry failed. One boot made 42 retries over 800 s. The first-attempt glitch itself is a sensor frame exchange getting out of step, which happens about 1 boot in 8 and correlates with boot-time load. A retry now clears the partial registration and re-registers in about 60 ms.

Commits:

  1. Name the failed step of a Touch ID sensor registration, with status, time since power-on and a post-mortem of the sensor's state.
  2. Clear a partial sensor registration before retrying it (KUnit).
  3. Re-read a sensor frame that is still on offer: check the reply CRC, re-read at most twice, and drain stale frames before a command. A drain that can't empty the queue fails the step.
  4. Retry a failed attach-time sensor bring-up, up to 3 times. A failed power cycle ends the attempt.
  5. Drop an SBIO reply that belongs to an earlier exchange: exchanges are numbered (KUnit).

Testing on the Neo (cold boots, one-shot test kernels)

Build Boots Ended without Touch ID First attempt failed, then recovered
Unmodified release7 16 7 n/a
Fixed builds, traced (4 variants) 64 0 2
This series, untraced 16 0 2
This series + spi-apple CS timing 24 0 3
  • Tests: KUnit 7/7 on arm64, host tests 14/14 at every commit, and W=1 clean at each commit. checkpatch --strict shows only the house Assisted-by and MAINTAINERS notes.
  • Reviews: an independent review and a Sashiko review; all findings are folded in.
  • Ruled out on hardware: rails/SPI readiness, module load order, SPI corruption, fprintd/gdm, the split CS read, realtime SPI scheduling and the CS setup/hold timing.
  • M1/M2: unaffected. This Touch ID SEP path is J700-only.

🤖 Generated with Claude Code

When the enclave did not register the sensor, the log said so and
nothing else. Eight steps can fail on the way: an enclave refusal of
REGISTER_SENSOR, REGISTER_SENSOR_SERIAL, the session share or its
commit, and a failed serial read, nonce read or session exchange on the
sensor side. Most of them returned false without a word, so a failure
could not be told apart from any other.

Name the step that failed with the enclave status or the error, and how
long after the sensor was powered on. Then report what the sensor shows
afterwards: its state, the patch acknowledgment, whether it presents
an identifier and how long a frame it holds. The sensor data itself is
never logged.

The sensor_trace parameter also logs each step as it completes, with
its time since power-on. The host test that runs wake_sensor() gets
the new fields in its mock.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
On a profile with a nonce session, every registration identifies the
sensor first: PLATFORM_IDENTITY, then REGISTER_SENSOR. The enclave state
is only cleared once the bring-up stage reads ESTABLISHED. If a
registration fails after REGISTER_SENSOR was accepted, the stage stays
FRESH while the enclave holds the partial registration. Each retry then
identified the sensor again without clearing it.

On boot d1962b3a, all 42 retries over 800 s failed that way, and Touch
ID stayed unusable until a reboot.

Count the enclave as holding the sensor once REGISTER_SENSOR has been
submitted, answered or not, since a lost or late reply does not mean the
enclave did not act on it. Clear its sensor state before registering
again whenever it may hold one.
Restarting the bring-up from FRESH does not change that, because only
CLEAR_STATE empties the enclave. Profiles without a nonce session keep
their flow.

The decision is a plain function, with KUnit tests for the first
registration, the retry after a partial one, re-registration and the
other profiles.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
A read of a sensor frame can fail on the bus in two ways. The bytes come
back garbled, or the sensor does not take the frame. Either way it keeps
offering the frame at the same length.

Boot 0874c215 showed both: the nonce read failed its CRC, and afterwards
the sensor still offered the complete 43-byte nonce frame with a valid
CRC. On boot 7f0c01be the serial read succeeded but the serial frame was
not taken. The nonce command that followed then waited behind it until
it timed out.

Check the CRC of the serial, nonce, session and challenge replies. The
session and challenge replies were relayed unchecked, but they carry the
same CRC; it held on every boot measured. The calibration module reply
keeps its own handling. When a reply fails its CRC and the sensor still
offers a frame of that length, read it again, at most twice. Before a
command that expects a reply, take any stale frame the sensor still
offers, so the reply is not queued behind it. Two such frames at most:
if one is still on offer after that, fail the step rather than send the
command, because a read does not prove the sensor took the frame.
Report both, since either means an exchange went wrong on the bus.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
When the bring-up at attach failed, nothing retried it until the first
verify, minutes later. That verify was then refused before it touched
the sensor, and gdm offered no fingerprint at login.

A bring-up that fails on the bus leaves nothing a new attempt cannot
undo. Each attempt power-cycles the sensor and, after a failed one,
clears the enclave partial registration first. That is the same path
every verify takes, and it has never failed on an idle machine. Try up
to three times at attach, logging each failed attempt. A power cycle that
fails ends the attempt before registration: a sensor that was not reset
may still hold the session of the attempt before.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
An SBIO reply is matched to the waiting exchange by opcode alone, and an
error marker is matched before the opcode is checked. The receive work
reads a reply before it takes the reassembly lock. If the requester
times out in between and a retry begins the same opcode, the late reply
completes the retry with the earlier attempt result. Bring-up now
retries the registration, so the window is real.

Number the exchanges. The receive work samples the number before it
reads a reply and passes it with the chunk; a chunk sampled before the
current exchange began is dropped. Replies to the current exchange can
only arrive after it began, since its request is sent after that.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant