Skip to content

pinctrl: apple: do not arm a masked interrupt in set_type - #233

Closed
ryzensnyper wants to merge 1 commit into
OrchardLinux:mainfrom
ryzensnyper:pr/apple-gpio-masked-irq
Closed

ryzensnyper wants to merge 1 commit into
OrchardLinux:mainfrom
ryzensnyper:pr/apple-gpio-masked-irq

Conversation

@ryzensnyper

@ryzensnyper ryzensnyper commented Nov 24, 2026 •

Copy link
Copy Markdown

Problem

apple_gpio_irq_set_type() writes the trigger mode into the pin's MODE field unconditionally. On Apple GPIO that field is also the interrupt mask (IN_IRQ_OFF = masked). So a type change on an interrupt the IRQ core holds masked or disabled arms the pin in hardware anyway. That happens on request_irq() with IRQF_NO_AUTOEN, or on irq_set_irq_type() while the line is disabled.

When that level line asserts, handle_level_irq() calls mask_ack_irq(). There is no irq_mask_ack, and mask_irq() skips the hardware because irqd_irq_masked() is already set, so only the ack happens. The interrupt re-fires forever and wedges the CPU servicing the bank (RCU stall, no backtrace from that CPU).

Fix

Write MODE in set_type only when the interrupt is unmasked. apple_gpio_irq_unmask() already applies the stored trigger type. The patch is kernel/patches/drivers/pinctrl/0006-pinctrl-apple-Do-not-arm-a-masked-interrupt-in-set_t.patch.

How it was found and tested

On the iPhone 8 Plus (D21), reloading apple_z2 hung the phone 5 of 8 times (plus 1 of 1 with the mailbox IRQ moved to CPU3). First boots never hung.

A logging build read the pin register around power-on:

  • Reload: before the touch rail came on the pin was GRP 0 (routed to CPU0), MODE 3 (level-low armed) and irqd_irq_masked=1. The hang followed within about 5 ms of the controller pulling the line low.
  • First boot: the pin is still GRP 7 (unrouted) until the first irq_startup, which is why first boots never hung.
  • With this patch: MODE 7 while masked, the line goes low with no storm, and 20 of 20 reloads were clean with default IRQ affinities (10 with the logging build, 10 with the final series). Touch worked after every reload.

Test procedure: orchard build <project> --device d21, boot over checkm8/PongoOS, then on the device rmmod apple_z2; modprobe apple_z2 ten times, reading /dev/input/event1 after each reload.

Other devices

This is the pinctrl driver for every Apple SoC Orchard supports, so any board whose driver changes an IRQ type while the line is masked is affected. I have tested only D21.

Tests

python -m unittest discover -s tests: 930 tests. The 4 test_ram CLI errors also fail on unmodified main on my host, because the free-disk check fails there. Nothing else fails.

The device testing was on a build from eab974c. main has moved since, but not in drivers/pinctrl.

Related: #234 (D21 touch) uses this fix for its reload numbers.

🤖 Generated with Claude Code

apple_gpio_irq_set_type() wrote the trigger mode into the pin while the
IRQ core had the interrupt masked. The mode field is also the hardware
mask, so the masked level interrupt was live, mask_irq() then skipped the
hardware, and an asserted line re-fired forever on CPU0. On the iPhone 8
Plus this hung touchscreen module reloads (5 of 8); with the fix 20 of 20
reloads were clean. Every board with Apple GPIO pinctrl uses this driver.

Assisted-by: LLM
Signed-off-by: Dugs <dugahol@protonmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ryzensnyper

Copy link
Copy Markdown
Author

Retest on the exact submitted revisions: #234 head e3827d8 with #233 60fd37c on top, on current main (9cb4066).

  • Build: orchard build <project> --device d21, payload sha256 075b48e6bdf746a7…. I checked in the built source tree and DTB that all four patches are present (touchclk 0x8000, the set_type mask check, P2, the d9 retry), and that no debug patches are.
  • Fresh boot: touch GOOD (69,864 bytes from /dev/input/event1).
  • 3 reloads (rmmod apple_z2; modprobe apple_z2), default IRQ affinities: all clean, and touch GOOD after each (50,568 / 63,648 / 93,912 bytes). The descriptor stored on attempt 1 every time.
  • Kernel log: no RCU stalls, BUG/WARNING, recovery restarts or "touch packet without surface descriptor".

This matches the earlier runs on eab974c (5/5 boots, 10/10 + 10/10 reloads).

@henrikklee

Copy link
Copy Markdown
Contributor

Thanks @ryzensnyper! This is on main unchanged, with you as author, in 06e093e (tag contrib/ryzensnyper-d21-touch), so I'm closing the PR as you suggested. The GPIO fix helps every board with Apple's GPIO controller, not just the 8 Plus.

@henrikklee henrikklee closed this Nov 24, 2026
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.

3 participants