Skip to content

irqchip/apple-aic: Keep a concurrent smp_affinity write on a CPU set change - #2870

Open
jgoyvaerts wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
jgoyvaerts:m4pro/aic-affinity-locked-mask
Open

jgoyvaerts wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
jgoyvaerts:m4pro/aic-affinity-locked-mask

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #2222, from RyanTheTide's merge-train review (nit 1).

aic_irq_cpus_update() copied each IRQ's affinity mask into a static cpumask and passed the copy to irq_set_affinity(). It took the copy without the descriptor lock. A /proc/irq/N/smp_affinity write (irqbalance, for example) that lands between the copy and irq_set_affinity() was then overwritten with the stale mask, and the user's setting was lost.

Now irq_get_affinity_mask(virq) goes straight to irq_set_affinity(), so the mask is read under the descriptor lock and the CPU set change applies whatever affinity is current. genirq does the same when it restores a managed IRQ's affinity on CPU online (irq_restore_affinity_of_irq() passes the descriptor's own mask to irq_set_affinity_locked()). The static cpumask goes with it.

If the IRQ's descriptor is gone by the time its mask is looked up, irq_get_affinity_mask() returns NULL; that IRQ is now skipped instead of passing NULL on to irq_set_affinity() (DjDeveloperr's nit).

Scope: aic_irq_cpus_update() runs only on AICv2 and AICv3 at EL2, where aic2_routed_chip is used. It changes the stored and effective affinity that is reported, not AICv1 or how the hardware delivers IRQs (SIQ_CFG decides that). One commit, drivers/irqchip/irq-apple-aic.c only.

Tested

  • Head ed5c57ef2c58: drivers/irqchip/irq-apple-aic.o builds for arm64 (defconfig, LLVM=1, W=1) with no warnings; checkpatch 0 errors, 0 warnings.
  • J616s (T6040) boot with the previous head bfd106d44798 in our combined kernel (7.3.0-m4.179, AIC at EL2 with VHE): irqchip/apple-aic:siq-cfg is registered (hotplug state 191). 52 routed (AIC2) IRQs report effective affinity 0, the one CPU whose SIQ_CFG accepts IRQs. 23 other requested AIC2 IRQs, which have never fired (mailbox lines and ane-h16), report an empty effective affinity. 0 error-level kernel messages, 0 failed system or user units. The new head differs only by the NULL check and has not been booted.
  • Not run: the CPU offline/online race. The J616s secondaries are spin-table (enable-method = "spin-table", no PSCI node), so there is no cpuN/online and the set of accepting CPUs never changes after boot. This needs an AICv2/v3 Mac whose CPUs can go offline.

Not done

Ryan's nits 2-6 on #2222 are not part of this PR. They are cosmetic or predate it.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Review at bfd106d.

Thanks, the fix is right and small. Passing the descriptor's own mask lets __irq_set_affinity() read it under desc->lock (kernel/irq/manage.c:463 -> irq_do_set_affinity():283/294), so an smp_affinity write can no longer be lost to a stale copy. cpuhotplug.c:132 and :226 already pass the descriptor's mask the same way. Locking is fine: the callbacks are CPUHP_AP_ONLINE_DYN, run in the hotplug thread with IRQs on, and irq_set_affinity() takes only the raw desc lock, no hotplug lock.

  1. Scope (please put this in the commit message): aic_irq_cpus_update() only runs for AICv2/v3 at EL2 (irq-apple-aic.c:1469-1472), where aic2_routed_irq_set_affinity() ignores the mask and the hardware routes by SIQ_CFG. AICv1 (aic_irq_set_affinity()) is not touched. So this changes only the stored/reported affinity, never where an interrupt is delivered.
  2. Something already there that you may want as a follow-up: the return value at irq-apple-aic.c:1123 is ignored. Say the user pins IRQ N to an accepting CPU X and X goes offline. migrate_one_irq() skips N, because X is no longer in its effective mask, so the affinity stays {X}. When another accepting CPU comes online, irq_do_set_affinity() returns -EINVAL (manage.c:283-289) and N's effective affinity (and its thread's CPU mask) is not refreshed. Not a lost interrupt on v2/v3, but the "set it again on every change" promise breaks there.
  3. Testing: it is not booted, and no test would have failed before the change. It needs a run on an AICv2 or AICv3 Mac where more than one CPU accepts IRQs and secondaries can go offline (PSCI). Loop cpuN/online 0/1 on an accepting CPU while another loop writes /proc/irq/*/smp_affinity, then check that each smp_affinity equals the last value written and effective_affinity_list equals the online accepting set. AICv1 needs only a boot/no-regression check.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formal §1–§6 pre-PR checklist review at live head bfd106d447984be22d48354e9b5b29c1e72e2ad0 (CI green: host-tests).

Concurrency, Locking & Barriers Audit

  • Locking & context: aic_irq_cpus_update() runs only from CPUHP_AP_ONLINE_DYN callbacks (aic_irq_cpu_online/aic_irq_cpu_offline, registered only for AICv2/v3 at EL2 in aic_of_ic_init()). Those callbacks run in process context with IRQs enabled under cpu_hotplug_lock. irq_set_affinity() acquires only desc->lock (raw_spinlock_irqsave) and never takes hotplug locks, so there is no lock-order inversion.
  • Race fix: Replacing the unlocked cpumask_copy(&aff, irq_get_affinity_mask(virq)) with irq_set_affinity(virq, irq_get_affinity_mask(virq)) defers reading the affinity mask until desc->lock is held in __irq_set_affinity() -> irq_do_set_affinity(). Under the Linux Kernel Memory Model, desc->lock release/acquire orders visibility of assign_cpu(cpu, &aic_irq_cpus, accepts) against concurrent /proc/irq/N/smp_affinity writers: any writer that wins desc->lock first is preserved when aic_irq_cpus_update() reads the live mask, and any writer that acquires desc->lock after aic_irq_cpus_update() releases it is guaranteed to observe the updated aic_irq_cpus.
  • Self-copy semantics: irq_do_set_affinity() executes cpumask_copy(desc->irq_common_data.affinity, mask) when aic2_routed_irq_set_affinity() returns IRQ_SET_MASK_OK with mask == desc->irq_common_data.affinity. Core genirq already relies on the exact same pattern in kernel/irq/cpuhotplug.c:132 and :226.

Checklist Summary

  • §1 No model gating: Pass (no chip/board gates; applies cleanly to AICv2/v3 EL2 hotplug path).
  • §2 Production-ready: Pass (removes the static cpumask and unlocked copy cleanly; no delays, retries, or parameters).
  • §3 Safety: Pass.
  • §4 Clean-room & attribution: Pass. Single human commit (Jonathan Goyvaerts), valid Signed-off-by and Fixes:, zero AI trailers in commit.
  • §5 Evidence: Fail (see blocker below).
  • §6 Naming: Pass.

Blocker

  1. §5 Evidence (missing hardware run): This PR has not been booted on any hardware (0 boot rows, 0 regression runs, and the modified aic_irq_cpus_update() path has never executed). Before merge, run at least one verified hardware row at live head on an AICv2/v3 Mac with PSCI CPU hotplug (cpuN/online toggling on an IRQ-accepting CPU concurrently with /proc/irq/*/smp_affinity writes, confirming smp_affinity is preserved and effective_affinity_list tracks the online accepting set), plus the §5 regression check (0 SELinux denials, 0 failed units, 0 new kernel errors).

Non-blocking nits

  • irq_get_affinity_mask(virq) can return NULL if virq is concurrently unmapped between irq_has_action(virq) and the lookup; guarding const struct cpumask *aff = irq_get_affinity_mask(virq); if (!aff) continue; avoids passing NULL into irq_set_affinity() if the virq number were reused before __irq_set_affinity() takes desc->lock (pre-existing code had the same unlocked lookup).
  • Consider noting in the commit message that aic_irq_cpus_update() runs only on AICv2/v3 at EL2 (aic2_routed_chip), affecting stored/effective affinity reporting without touching AICv1 or hardware IRQ delivery.
  • Pre-existing follow-up item: the return value of irq_set_affinity() is ignored; if a user previously pinned an IRQ to a CPU that went offline, irq_do_set_affinity(..., force=false) returns -EINVAL and skips refreshing effective affinity on subsequent online transitions.

Assisted-by: LLM (Gemini 4 Neon)

…change

aic_irq_cpus_update() copied each IRQ's affinity mask into a static
cpumask and then passed the copy to irq_set_affinity(). The copy was
taken without the descriptor lock, so a /proc/irq/N/smp_affinity write
(irqbalance, say) that lands between the copy and irq_set_affinity() was
overwritten with the stale mask, and the user's setting was lost.

Pass irq_get_affinity_mask() to irq_set_affinity() directly. The mask is
then read under the descriptor lock, so the set change applies whatever
affinity is current. genirq does the same when it restores a managed
IRQ's affinity on CPU online (irq_restore_affinity_of_irq()). The static
cpumask goes with it.

If the IRQ's descriptor is gone by the time its mask is looked up,
irq_get_affinity_mask() returns NULL. Skip that IRQ instead of passing
NULL on to irq_set_affinity().

aic_irq_cpus_update() runs only on AICv2 and AICv3 at EL2, where
aic2_routed_chip is used. There it changes the stored and effective
affinity that is reported. It doesn't touch AICv1, or how the hardware
delivers IRQs (SIQ_CFG decides that).

Fixes: d3d404c ("irqchip/apple-aic: Keep the routed IRQ affinity across CPU hotplug")
Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
@jgoyvaerts
jgoyvaerts force-pushed the m4pro/aic-affinity-locked-mask branch from bfd106d to ed5c57e Compare November 23, 2026 20:57
@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

Thanks @DjDeveloperr. New head ed5c57ef2c58 takes both nits:

  • drivers/irqchip/irq-apple-aic.c:1123-1125: a NULL irq_get_affinity_mask() now skips the IRQ instead of being passed on to irq_set_affinity().
  • The commit message now says the function runs only on AICv2/v3 at EL2 (aic2_routed_chip), and that it changes reported affinity, not AICv1 or how the hardware delivers IRQs.
  • Build: irq-apple-aic.o for arm64 (defconfig, LLVM=1, W=1), no warnings. checkpatch clean.

On the hardware row: the CPU offline/online race can't run on the J616s (T6040). Its secondaries are enable-method = "spin-table" with no PSCI node, so there is no cpuN/online, and the set of accepting CPUs never changes after boot.

What I can show is the boot of our combined kernel carrying the previous head bfd106d44798 (7.3.0-m4.179, AIC at EL2):

  • irqchip/apple-aic:siq-cfg is registered.
  • 52 routed IRQs report effective affinity 0, the only CPU whose SIQ_CFG accepts IRQs.
  • 0 error-level kernel messages, 0 failed units.

The new head itself has not been booted. If a fleet Mac with AICv2/v3 and offline-capable CPUs is available, that run would close §5. The test: toggle an accepting CPU's online while writing /proc/irq/N/smp_affinity, then check that the written mask stays and that effective_affinity_list follows the online accepting set.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formal Pre-PR Checklist Re-Review (§1–§6) — REQUEST_CHANGES

Re-reviewed at verified live head ed5c57ef2c58e34c0fab10d2123208efb9a212c0 (jgoyvaerts:m4pro/aic-affinity-locked-mask → aurora-silicon/linux:integration/aurora). Live CI: Host tests (45264648717) = success.

Code & Prior Nits Verification

  • Both non-blocking nits from the prior review are cleanly addressed: irq_get_affinity_mask(virq) is now NULL-checked before irq_set_affinity(virq, aff) (drivers/irqchip/irq-apple-aic.c:1121-1125), and the commit message clearly scopes aic_irq_cpus_update() to AICv2/v3 at EL2 (aic2_routed_chip, stored/reported affinity only).
  • The concurrency fix itself is sound and ready to merge once §5 hardware evidence lands.

Remaining Blocker

  1. §5 Evidence (exact head unbooted; modified path never exercised on hardware):
    • Exact head ed5c57ef2c58 has not been booted on any hardware.
    • The earlier J616s (T6040) boot carried previous head bfd106d44798 in a combined kernel (7.3.0-m4.179), omitted SELinux/AppArmor denial counts, and ran with enable-method = "spin-table" (no PSCI / no cpuN/online). Because aic_of_ic_init() registers CPUHP_AP_ONLINE_DYN in early boot before peripheral IRQs have actions (irq_has_action(virq)), the modified loop body (irq-apple-aic.c:1121-1127) has never actually executed on hardware.
    • Action needed: Post a verified hardware run at live head ed5c57ef2c58 on an AICv2/v3 Mac with PSCI CPU hotplug (cpuN/online toggling on an IRQ-accepting CPU concurrently with /proc/irq/*/smp_affinity writes, confirming written smp_affinity masks are preserved and effective_affinity_list tracks the online accepting set) along with the full §5 regression tuple (0 SELinux denials, 0 failed units, 0 new kernel errors).

Pre-PR Checklist Summary (§1–§6)

  • §1 No model gating: PASS.
  • §2 Production-ready, no hacks: PASS.
  • §3 Safety: PASS.
  • §4 Clean-room & attribution: PASS — single commit ed5c57ef2c58 has human author/committer (Jonathan Goyvaerts), human Signed-off-by: and Fixes: d3d404c0e448, zero AI trailers in commit.
  • §5 Evidence: FAIL — live head unbooted, modified hotplug loop untested on hardware, missing full §5 regression tuple at ed5c57ef2c58.
  • §6 Naming: PASS.

Assisted-by: LLM (Gemini 4 Neon)

@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

J616s (T6040) boot with head ed5c57ef2c58, in our combined kernel 7.3.0-m4.183. The commit there is patch-id equal to this head. AIC at EL2 (VHE), default command line, booted 2026-11-24 01:05 UTC:

  • irqchip/apple-aic:siq-cfg is registered (hotplug state 191).
  • Routed (AIC2) IRQs: 52 report effective affinity 0, the only CPU whose SIQ_CFG accepts IRQs. All have smp_affinity_list 0-13. 23 requested lines that have never been started report an empty effective affinity, the same as on the previous boot.
  • 0 error-level kernel messages, and no WARN, Oops or SError. 0 failed system or user units.
  • The LSMs are capability,landlock,yama. No SELinux or AppArmor is loaded, so there is no denial count to give (0 avc: lines).

This covers boot and health at the exact code only. As @DjDeveloperr notes, the changed loop body still hasn't executed on hardware. On this machine it can't: the CPUs are spin-table, and no peripheral IRQ has an action yet when CPU0's callback runs. The CPU offline/online row still needs an AICv2/v3 Mac with PSCI.

Assisted-by: LLM (Claude:Opus 5.5)

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