Skip to content

linux-omarchy: carry ACPICA PCI bus fix for resume delays - #544

Open
Clowdyffs wants to merge 1 commit into
omacom:masterfrom
Clowdyffs:fix/acpica-parent-derived-pci-bus
Open

Clowdyffs wants to merge 1 commit into
omacom:masterfrom
Clowdyffs:fix/acpica-parent-derived-pci-bus

Conversation

@Clowdyffs

@Clowdyffs Clowdyffs commented Sep 20, 2026 •

Copy link
Copy Markdown

Submitting this directly in the omarchy repo since omarchy seems to have a lot of old macbooks in its userbase. For it to change upstream it has to go through the acpica review process, the linux kernel release candidates, then the arch linux kernel has to be released after that, which could make this change take a couple months or longer (if ever). If and when it gets merged, I'll keep track of it and submit a follow up PR to remove this patch from this repo since it will be directly inherited.

-----------everything below this line is written by ai------------

Carry the PCI operation-region address correction proposed in open-acpica/acpica#1235 in linux-omarchy and linux-omarchy-bore. On a MacBookPro14,1, this fixes incorrectly cached PCI addresses during resume and reduces three affected firmware sequences from 6.939 seconds to 1.836 milliseconds.

Upstream status: ACPICA #1235 is open for review, not accepted or merged. This is a proposed downstream carry of its current source change, not an already accepted upstream backport. The upstream PR contains the full diagnosis, trace excerpts, historical rationale and standalone reproducer. Please keep this carry aligned with upstream review and remove it when the packaged base kernel includes the correction. Merge timing can follow that review.

What changes

  • Add the same 0771-acpica-preserve-parent-derived-pci-bus.patch to the standard and BORE recipes, following this repository's practice of keeping shared kernel fixes in both variants.
  • Update SHA-256 and BLAKE2 checksums and bump both recipes from 7.2.5-6 to 7.2.5-7.
  • The kernel diff changes only drivers/acpi/acpica/hwpci.c: six insertions and eleven deletions. Existing prepare() applies it with --fuzz=0; no new build logic, kernel configuration, power hook, DMI quirk or sleep-policy change is needed.

The patch links to the upstream PR and identifies its human-signed source commit, 615f1b568156. Its existing author sign-off and AI-assistance disclosure are preserved. Paths, identifiers and the Fixes: reference are translated to Linux form; the functional correction is unchanged.

Root cause and why it should be corrected

acpi_hw_get_pci_device_info() locates each bridge using the bus derived from its parent. It then reads that bridge's Primary Bus Number register and overwrites the already established address before reading the Secondary Bus Number.

During this machine's ACPI power-up, the bridge header is accessible before the PCI core has restored the bridge's bus-number registers. The primary register can still contain its reset value, zero. The captured upstream bridge is at 04:00.0, but its primary register reads zero; the overwrite redirects the next configuration read to host bridge 00:00.0. Derivation nevertheless returns AE_OK, and the operation region retains the wrong address. The downstream bridge shows the same mechanism.

Consequently, the firmware mailbox region at offset 0x530 directs 150,120 polling reads to the host bridge, instead of the intended Thunderbolt bridge. Associated accesses at 0x538 and writes are likewise misdirected. Three firmware retry sequences exhaust their counters. Leaving this unchanged retains incorrect address derivation and misdirected configuration accesses, as well as the visible delay. No host-bridge corruption, exploit or security-boundary crossing was demonstrated.

The correction retains the parent-derived address and removes the redundant primary-register read. It preserves device/header checks and secondary-bus reads/error handling. It changes neither firmware retry limits nor PCI power sequencing, and removes one configuration read per inspected bridge rather than adding polling or delays.

The code originated in ACPICA 08fd52445bf4, imported into Linux as 95abccb576c4. The patch uses the Linux commit in its Fixes: tag.

Hardware evidence and performance

Tested hardware: MacBookPro14,1, 2017 13-inch Intel MacBook Pro, two Thunderbolt 3 ports, no Touch Bar; firmware 451.120.7.0.0, Alpine Ridge controller 8086:1578.

The controlled stock/corrected comparison used Linux 7.2.3-arch1-3 with the same temporary Thunderbolt LC-skip protection and pm_test=platform. These automatic-return diagnostic transitions include a deliberate five-second pause and do not enter actual sleep.

Measurement Before After
Three affected CRMW firmware sequences combined 6.939 s 1.836 ms
Complete diagnostic transition, including the five-second pause 15.550 s 8.106 s

The affected firmware sequences save approximately 6.937 seconds (99.97% shorter). This percentage is not a total-system wake speedup. All six mailbox CIOR calls succeeded after correction, and traced operation-region addresses matched the actual bridge addresses. Later combined real-sleep tests also succeeded, but included separate controller protection and therefore do not establish that this patch alone fixes suspend.

The machine currently runs the official linux-omarchy 7.2.5-3; the source recipe targeted here is 7.2.5-6. The corrected 7.2.3 kernel was built and booted earlier. These are distinct from a new build or hardware test of this packaging PR.

Scope and compatibility limits

This is a generic ACPICA correctness change, not a Mac-specific workaround. ACPICA serves other hardware and operating systems, so one MacBook cannot establish universal safety. Restored bridges should retain the same addresses because the primary register normally agrees with the parent-derived bus. Other firmware/topology behavior still needs upstream review and broader testing.

The expanded reproducer compiles the actual C helper and passes 15 cases: four corrected failures and eleven unchanged comparisons. Coverage includes ordinary bridges/endpoints, namespace scopes, nonzero root buses and CardBus headers. The nonzero-root/CardBus additions are simulated fixtures, not physical-device coverage; the patch does not reconstruct an unavailable ancestor secondary-bus value. No universal no-regression claim is made, and BORE has not been boot-tested here.

The separate Thunderbolt power-transition/controller-loss fault can still produce the xHCI 65,535 ms timeout with this address fix present. A corrected-kernel stock-driver control reproduced that fault while the three firmware sequences remained fast (2.675 ms). This PR therefore does not claim to resolve the full minute-long wake, lid wake delivery, sleep power consumption, or intermittent BCM4350 Wi-Fi failure.

Related controller work: omacom/omarchy#10593, omacom/omarchy#10758 and #349. This carry is separate from those driver/state-restoration changes and should not close their reports.

Validation

  • Both PKGBUILDs pass bash -n and makepkg --printsrcinfo; source/checksum array lengths and all checked-in hashed sources, including architecture configs, match.
  • The two patch copies are byte-identical. No other patch in either recipe touches drivers/acpi/acpica/hwpci.c.
  • The carry applies to the exact Linux v7.2.5 helper with zero fuzz and zero offset. The resulting file is byte-identical to the previously validated Linux-form correction.
  • The actual-C 15-case replay passes against that v7.2.5 result, compiled with -Wall -Wextra -Werror. The complete reproducible harness is in ACPICA bitwarden: add for aarch64 #1235.
  • Strict Linux checkpatch.pl: zero errors, warnings or checks. git diff --check passes for both recipes and for the resulting kernel-source diff (the outer diff of a new .patch file naturally contains unified-diff context markers).
  • bin/build-matrix linux-omarchy linux-omarchy-bore selects both x86_64 edge builds.
  • Previously completed validation: native ACPICA acpiexec/acpisrc build, the equivalent corrected Linux 7.2.3 kernel build/boot, and the hardware comparison above.

A full build of the new 7.2.5 package recipes, full patch-stack application and new hardware/BORE boot testing have not been performed locally. Existing remote archive/signature inputs are unchanged and were not downloaded/reverified for these targeted checks. The repository's normal package build/review remains necessary before shipping.

Carry the Linux form of open-acpica/acpica#1235 in the base and BORE
kernels, keeping their shared fixes aligned. Bump both package releases
and add SHA-256/BLAKE2 checksums for the checked-in patch.

During ACPI power-up a bridge's Primary Bus Number can still be zero.
ACPICA must retain the address derived from the parent instead of using
that reset value and caching an operation region at the host bridge.
The equivalent correction reduced three firmware sequences from 6.939 s
to 1.836 ms on MacBookPro14,1; controller-loss and Wi-Fi faults remain
separate. Broader hardware coverage and upstream review are still needed.

The patch records its pending upstream status and removal condition,
preserving the source submission's existing human author sign-off.
Validate both recipe manifests/checksums, apply to the exact 7.2.5 helper
without fuzz/offset, and pass the 15-case actual-C replay and checkpatch.
The full new package builds and BORE boot test have not been performed.

Upstream: open-acpica/acpica#1235
Assisted-by: LLM
@angellindo

Copy link
Copy Markdown

Tested the equivalent of this change on a MacBookPro14,3 (JHL6540, two Alpine Ridge host routers), linux-omarchy 7.2.5-3, s2idle. It fixes the resume delay here.

Before. The first resume after boot sets up the PCI_Config regions H530, A1E0, A1E1 and A1E2 under \_SB.PCI0.PEG1.UPSB, PEG2.UPSB and their DSB0. At that point the bridges read Primary Bus 0, so all eight regions get cached at 00:00.0. A kprobe trace over one resume showed 300,240 reads of 00:00.0 offset 0x530, the CIOR/CRMW mailbox from UPSB._PS0. noirq resume took 17.8 s: 04:00.0 12.5 s, 7a:00.0 12.0 s, and each NHI about 5.5 s.

After. I applied the same logic as a local kretprobe module, which keeps the parent-derived bus when the 0x18 read comes from acpi_hw_derive_pci_id. The first resume after a fresh boot then took 0.53 s: 04:00.0 0.45 s, 7a:00.0 0.46 s, NHI 0.06 s. During that resume, eight primary-bus reads returned 0, on the bridges of buses 04, 05, 7a and 7b, and kept the derived bus. Two later sleeps that day gave 0.524 s and 0.530 s. In the first sleep after another boot, the upstream bridges took 0.45 s again. Both Thunderbolt domains came back with no errors every time.

Dependencies and limits.

  • It was measured together with 0664 from #596, which skips the Thunderbolt LC sleep in s2idle, the same setup as your measurement. Without 0664 the chip is gone after the first sleep, so resume time can't be measured.
  • On this machine the wrong address is cached during the first resume, not at boot. A fix that only ran at boot would miss it.
  • This was not your patch built into a kernel; it was a module that emulates it on the stock kernel.

The full list of suspend fixes for this machine and how they depend on each other is in #596.

maralcbr added a commit that referenced this pull request Sep 25, 2026
Moves the pin from the boot-set integration commit to quattro-upstream,
which now has #541 with its review fixes (first boot hands off only for a
failed step, and the retry waits for NetworkManager), #543's update-verify
entrypoint, #545's provision entrypoints and #549's keyslot-only LUKS check.
#544 is not in it, so the Plymouth fragment still ships and no HOOKS baseline
dependency applies.
APS6 pushed a commit to APS6/omarchy-pkgs that referenced this pull request Sep 26, 2026
Moves the pin from f7ea7ecc to the head of quattro-upstream, which adds
omacom#552's reset-prepare, reset-verify, reset-commit and reset-rollback
entrypoints, omacom#553's luks-slots entrypoint and recovery key handling,
omacom#556's encrypt unit output to kmsg at notice, and omacom#560's snapshot restore
check with its limine-snapper-sync pre and post hooks. The pin's UTC date is
still 20260925, so pkgrel goes to 4. omacom#544 is not in it, so the Plymouth
fragment still ships and no HOOKS baseline dependency applies.
maralcbr added a commit that referenced this pull request Oct 4, 2026
The engine enabled omarchy-mac-migrate-verify.service with systemctl; with the unit gone the link would dangle. Also correct which omarchy-mac pull requests every omarchy-mac-pkgs pin includes (#544 has not merged).
@Clowdyffs

Copy link
Copy Markdown
Author

Thanks for reproducing this on MacBookPro14,3. The first-resume primary-bus reset values and preserved parent-derived buses support the diagnosis on a second Mac model.

Your equivalent probe-module correction used separate Thunderbolt LC protection from #596. It supports the ACPICA fix, but isn't a test of this exact package or proof that this carry alone fixes controller loss/suspend.

ACPICA #1235 remains open, unchanged and signed, without review comments. This carry still targets 7.2.5-6 standard/BORE recipes; the 15-case replay and source/recipe checks stand. Full builds and maintainer review remain pending. The carry will track upstream revisions and be removed once inherited.

— GPT-6.1 Sol high

@aldervale

Copy link
Copy Markdown

Adding MacBookPro13,3 results from a kernel built with this carry at 4d81f4f8ad65b14f94a1f7e21d98b52a21e2e184.

On the original 7.2.5-3-omarchy kernel, all 200,160 traced mailbox reads at 0x530 targeted 00:00.0; the two upstream bridge callbacks took 17.65 seconds combined, in a 17.86-second noirq resume. Visible wake was 17–18 seconds.

With the correction built into 7.2.5-3-omarchy-acpi-trial, three attended recoveries passed across two boots. The first two woke in about one second / nearly immediately; the third passed without a numerical timing. The last two included 15-minute battery sleeps. Touch Bar/Fn and both NHI/USB-C binding pairs recovered.

Scope: I rebuilt the existing 7.2.5-3 recipe with this patch, not this PR's exact newer standard/BORE recipes. Kernel, headers, installed DKMS modules and the 15-case C reproducer passed their build/test checks. The existing EC lid-wake and guarded Thunderbolt unload/reload workaround remained in place, as did T1Bridge #47; this is not a test of #596 or a claim that this carry alone fixes controller loss. No corrected-address/per-bridge trace has been captured yet. Battery retention remains broken.

I've also reported the hardware evidence directly on ACPICA #1235. Full chronology and limitations.

@angellindo

Copy link
Copy Markdown

Tested on a MacBookPro14,3 (15" 2017, two Alpine Ridge controllers behind PEG1 and PEG2), S3 (deep).

Rebase. I rebased the patch onto 7.2.8 and renamed it to 0778-acpica-preserve-parent-derived-pci-bus.patch. On current master 0771 is taken by 0771-gpiolib-acpi-quirk-irq-active-low-dell-xps.patch; the ACPI block runs 0770–0777, so 0778 is the next free slot in the same group. Nothing else in the series touches drivers/acpi/acpica/hwpci.c, so the position does not change the result. The content is unchanged and it applies with --fuzz=0, no offset, both on a clean v7.2.8 tree and on top of the full master series. Also note that linux-omarchy-bore no longer carries patches.

Method. kprobes on acpi_ds_begin_method_execution and acpi_ds_terminate_control_method, filtered to CRMW, PCED and _PS0 of PEGx.UPSB. Suspend and resume by closing and opening the lid, first sleep after a cold boot.

without fix (stock 7.2.8) with 0778, run 1 with 0778, run 2
CRMW, per call 3616.2 / 3859.4 / 3804.7 ms 1.2–2.4 ms (n=5, total 9.1 ms) 1.2–2.5 ms (n=5, total 9.0 ms)
UPSB._PS0, link up normally PEG2: 7913.8 ms (PCED 437.8 + 2× CRMW) PEG1: 442.7 ms (PCED 438.1) PEG2: 443.0 ms (PCED 438.3)

Separate issue, not caused by this patch. On some resumes PCED (the link-training wait) on one UPSB takes ~26.7 s (26699.1 ms on PEG2 in run 1, 26694.6 ms on PEG1 in run 2). I also see it on the stock kernel with an equivalent out-of-tree module, and without any fix (there PCED hits AE_AML_LOOP_TIMEOUT at 31.7 s). With the fix, CRMW still runs right after PCED and finishes in a few ms.

Caveat. The test kernel also carried the patches from #596 and #815. Level-0 runs (resume timings only, no method kprobes) showed the same UPSB pattern.

Conclusion. On this machine the patch does what it says: the mailbox waits drop from seconds to milliseconds. I would suggest renaming it to 0778 when you rebase. Thanks for tracking this down!

@patattzel

Copy link
Copy Markdown

Additional built-kernel evidence from MacBookPro14,3 (15-inch 2017, i7-7820HQ, Radeon Pro 560, two Alpine Ridge Thunderbolt domains), tested November 5–6.

I carried this PR's Linux-form correction at 4d81f4f8ad65b14f94a1f7e21d98b52a21e2e184 into the existing 7.2.15-2 Omarchy recipe, installed separately as 7.2.15-2-macbook143. The kernel feature configuration was retained. The additional host patches were 0609 (Thunderbolt) and 0682 (BCM43602) from #596; the reference stock-kernel measurement already used equivalent separately built host modules. This is not a build/test of this PR's exact older package recipes or other scheduler variants, and no live function redirection was used for these measurements.

Direct PCI-context check

Of 14 selected operation regions, eight became initialized during each platform test:

Operation regions Before correction, cached BDF After correction, cached BDF
PEG1.UPSB.H530, A1E0 0000:00:00.0 0000:04:00.0
PEG1.UPSB.DSB0.A1E1, A1E2 0000:00:00.0 0000:05:00.0
PEG2.UPSB.H530, A1E0 0000:00:00.0 0000:7a:00.0
PEG2.UPSB.DSB0.A1E1, A1E2 0000:00:00.0 0000:7b:00.0

All eight corrected contexts match the actual PCI/ACPI topology. The other six selected regions remained uninitialized, not verified as either correctly or incorrectly addressed. These were read-only, running-BTF-validated metadata checks with explicit model/kernel/boot guards; no AML was evaluated by the reader. No kernel-memory dump is attached. This check does not establish per-access polling counts.

Comparable serialized pm_test=platform measurements

Kernel-reported phase Before With correction
noirq device resume 18449.478 ms 1143.967 ms
normal device resume 509.023 ms 455.371 ms

That is 17.306 s / 93.8% less time in the noirq phase, not a 93.8% total-system wake improvement. Both measurements were serialized (pm_async=0) without compiler load. The corrected trace retained all 4984/4984 entries and recorded no nonzero PM callback results.

Important timing qualification: the corrected run advertised the usual five-second debug pause but skipped it because a wakeup was already pending. Therefore I am comparing the separately delimited resume phases and PCI contexts, not total transition duration or equal debug pauses. These platform tests did not enter real sleep.

The patch also applied to the exact source with zero fuzz/offset; the actual-C 15-case replay passed with compiler warnings treated as errors and ASan/UBSan.

A later, separately controlled real s2idle lid cycle slept 26.563 s, accepted EC/LID wake before device resume, and returned visibly in approximately one second. That cycle additionally required an EC wake-capability workaround, T1 USB remote-wake disabled, and T1Bridge #49; it is not evidence that this ACPICA correction alone fixes suspend. Repeated/long sleeps and battery retention remain unvalidated on this machine.

Thanks for the correction. These results add built-kernel address verification on 7.2.15 to the existing evidence, without claiming new authorship of the patch.

Prepared with AI assistance from local test records and the machine owner's separate visual confirmation. No additional hardware test was run for this comment.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants