Repository navigation
HID: spi-hid-apple: stop the IRQ before the device's state goes - #3277
Conversation
The OF glue requests the threaded IRQ before the core allocates its state and buffers, all device-managed, so when probe fails devres frees that state first and the IRQ last. A probe that failed after enabling the IRQ (no boot message, or no device information) returned with the IRQ still enabled and the controller still powered: the handler could run on the freed state and its receive buffer until devres released the IRQ. Remove destroyed the HID devices while the IRQ was still enabled, so a report could be delivered to a device being destroyed, and disabled the IRQ only afterwards. Both now use one stop sequence: refuse transfers, disable the IRQ (which waits for the handler), destroy the HID devices the handler registered, and power the controller off. Probe runs it on every failure after it has enabled the IRQ. The KUnit suite gets three cases. Probe failing at the boot wait, and at the device information wait, must return with the IRQ disabled and the controller off. Remove must disable the IRQ while the HID devices still exist. The previous code fails all three. Signed-off-by: DjDeveloperr <[email protected]>
|
Verdict at Blockers: none Checked
Evidence
|
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
There was a problem hiding this comment.
Verdict: Code approved at 542bbdcd0bb1. Hardware hold remains.
Checked: The OF transport uses synchronous disable_irq(). Both new probe error exits follow IRQ enable, and teardown waits for the threaded handler before destroying HID devices or allowing devres to release their backing state. The logical power gate also rejects HID LED work during destruction. Reviewed the reported 15/15 KUnit results and the three failing controls on the old code.
Before merge: Attach the requested supported SPI-keyboard Mac row with boot, keyboard and trackpad input, sleep/wake, unbind/rebind, and kernel error counts.
|
Merge-train review at |
|
542bbdc J316s (M1 Pro, T6000) PASS: combined guarded one-shot |
|
Row (J316s, M1 Pro, T6000) at exact head 542bbdc in combined candidate 77b87daa (main de965eb + #3277 542bbdc + #3231 c955307 + #3210 69f3a4a), kernel 7.3.0-aurora-crj7+ (fleet edge config), kernel-only one-shot with the saved Stage 2 and the default command line -> PASS.
Evidence: traces/kernel/20261130-closeout-k114s-j316s-combo/m1pro/. Saved kernel 7.3.0-aurora-edge restored and verified. |
|
Merging at |
What: The Apple SPI keyboard/trackpad transport now stops its IRQ before its state goes away, on a failed probe and on remove. The IRQ is requested before the core's device-managed state, so a probe that failed after enabling it returned with the IRQ still live while devres freed the state and buffers. Remove destroyed the HID devices before disabling the IRQ.
Tested: The
spi-hid-appleKUnit suite on arm64 QEMU passes 15/15 at542bbdcd0bb1, including 3 new cases; the previous code fails those 3.spi-hid-apple-core.oandspi-hid-apple-of.obuild with W=1 (arm64, 16K pages). No hardware row yet.Risk: two-way · Macs with the SPI keyboard and trackpad: J293, J313, J314, J316. Only probe failure and remove change.
Not yet: A hardware row on one of the SPI-keyboard Macs: boot, keyboard and trackpad input, a sleep, and an unbind/bind of the transport, with no new kernel errors.
Details
spihid_apple_of_probe()callsdevm_request_threaded_irq()beforespihid_apple_core_probe()makes itsdevm_allocations (state, RX/TX/status buffers, descriptors). Devres releases in reverse order, so on a probe failure the core's state is freed before the IRQ. Probe enables the IRQ, then waits for the boot message and the device information; when either wait failed it returned without disabling the IRQ or powering the controller off. The threaded handler reads intorx_bufwithspi_sync()and works on the driver state.spihid_apple_core_stop()is now the one stop sequence:led_work's fromhid_destroy_device()) are refused;Probe runs it on both failures after the IRQ is enabled. Remove is now just this sequence, so no report reaches a HID device while
hid_destroy_device()runs. Shutdown already disabled the IRQ and powered off, and creates nothing to destroy, so it is unchanged.The KUnit cases use a transport whose ops log each call:
spihid_test_probe_boot_timeout: no boot message;spihid_test_probe_info_timeout: booted, but the device information never comes.In both, probe must return with the IRQ disabled and the controller off: the log is
on irq-on irq-off off, and power was already off when the IRQ was disabled.spihid_test_remove_irq_first: remove must disable the IRQ while the HID devices still exist, then destroy them and power off.HID: spi-hid-apple: bound reassembled reports and refuse a descriptor without a buffer #2986 changes report reassembly in the same file; the two don't overlap.
Evidence
./tools/testing/kunit/kunit.py run --arch=arm64 --make_options LLVM=1 --kunitconfig=drivers/hid/spi-hid/.kunitconfig:Ran 15 tests: passed: 15. The raw log showswaiting for device boot failed: -19in the first new case andwaiting for device info failed: -19in the second.main'sspi-hid-apple-core.cand the new tests:passed: 12, failed: 3.probe_boot_timeoutandprobe_info_timeout:t->log == "on irq-on ",t->irq_enabled == 1.remove_irq_first: "Expected t->hid_at_irq_off to be true, but is false"../linux-build/build kernel … -- -j4 W=1 drivers/hid/spi-hid/spi-hid-apple-core.o drivers/hid/spi-hid/spi-hid-apple-of.o: no warnings. A W=1 compile of the core with the KUnit cases included is also clean.scripts/checkpatch.pl --strict: clean.main859e8a29796c.