Repository navigation
Conversation
A PCI_Config operation region first used during a bridge's ACPI power-up can be initialized before the PCI core restores that bridge's bus-number registers. AcpiHwGetPciDeviceInfo() has already located the bridge using its parent's secondary bus. Reading a zero Primary Bus Number and assigning it to PciId->Bus then misdirects the following secondary-bus read and caches the wrong region address. On MacBookPro14,1, first-resume tracing records UPSB at 04:00.0 with header type 1 and primary bus 0. Region derivation returns 00:00.0 successfully. The H530 region then directs 150,120 mailbox polls to the host bridge; three exhausted firmware retry sequences cost about seven seconds. Two downstream-bridge regions show the same address loss. Keep the address already derived from the parent and remove the unnecessary primary-bus read. The secondary-bus read then uses that same correct bridge address. This changes neither the PCI power sequence nor firmware retry limits. Hardware validation on MacBookPro14,1 confirms correct PCI region addresses and successful mailbox access: the three firmware retry sequences fell from 6.939 seconds to 1.836 milliseconds. A replay of the actual C helper also corrects two captured reset-primary cases and preserves six comparison cases. A separate Thunderbolt controller power-transition failure still occurs with this correction. This change fixes PCI region address derivation. Fixes: 08fd524 ("Obsolete the AcpiOsDerivePciId OSL interface.") Assisted-by: LLM Signed-off-by: clowdyffs <alex@clowdydev.com>
…d of ~23 s ACPICA derives a PCI_Config region address once, on first access, from the bridge Primary Bus Number. The UPSB regions of both Titan Ridge controllers were first touched inside the first resume, while Primary Bus was still 0, so they stayed cached at the host bridge 00:00.0 and the firmware _PS0 mailbox polls timed out (~20 s per resume). ws-tb-acpi-seed.service reads one field of every region via the ACPI debugger after boot, before the first suspend (open-acpica/acpica#1235). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Additional hardware evidence from MacBookPro13,3 (2016 15-inch, Alpine Ridge) using a built kernel with this correction. I applied the Linux-form carry from omarchy-pkgs #544 at Before: an entry kprobe/histogram observed 200,160 matching 32-bit ACPI PCI reads at segment 0, register After: three attended lid-sleep recoveries passed across two boots of the patched kernel. I observed about one second to illumination in the first, and nearly immediate wake in the second; the third passed without a numerical timing. The last two included 15 minutes asleep on battery. Touch Bar/Fn and controller bindings recovered. I have not captured corrected PCI addresses or new per-bridge timing, so the before/after latency comparison is an owner observation, not an instrumented benchmark. These are undocked Public evidence and test boundaries. Thank you for the fix; this adds a tested 13,3 to the hardware evidence. |
|
Additional hardware evidence for this correction from a MacBookPro14,3 (2017 15-inch, two Alpine Ridge domains), using the Linux-form carry in omacom/omarchy-pkgs#544 built into a separate A read-only inspection of selected initialized ACPICA PCI operation-region contexts before/after the platform transition found:
Comparable serialized The parent-derived-bus correction was carried unchanged from omacom/omarchy-pkgs#544 at Both sides retained the necessary Thunderbolt host protection from omacom/omarchy-pkgs#596. Separate EC/T1 issues are required for actual lid sleep on this machine, so this does not claim a complete suspend fix or universal compatibility. The fuller comparison and its limitations are recorded in the accompanying hardware comment on omacom/omarchy-pkgs#544. Prepared with AI assistance from local test records. This is Linux hardware-validation evidence, not a new test of the native ACPICA tools or this PR's packaging. |
A MacBookPro16,1 takes 28.5 seconds to wake from deep sleep, the median of 10 on the charger. Its two Thunderbolt bridges spend 6.6 seconds each in resume. ACPICA builds the bridges' PCI config address from the primary bus register. That register reads 0 before the PCI core restores it, so the firmware's mailbox polls go to the host bridge and time out. Carry the ACPICA fix from open-acpica/acpica#1235, which keeps the bus found from the parent. Each bridge then resumes in 0.44 seconds, the mean of 10, and the wake takes 10.5 seconds, the median of 10 on battery. Co-authored-by: clowdyffs <alex@clowdydev.com>
A MacBookPro16,1 takes 28.5 seconds to wake from deep sleep, the median of 10 sleeps on the charger. In the 9 of those wakes that logged it, its two Thunderbolt bridges took a median 6.66 and 6.61 seconds each to resume. ACPICA builds the bridges' PCI config address from the primary bus register. That register reads 0 before the PCI core restores it, so the firmware's mailbox polls go to the host bridge and time out. Carry the ACPICA fix from open-acpica/acpica#1235, which keeps the bus found from the parent. In 10 sleeps on battery, each bridge then resumes in a median 0.44 seconds, and the wake takes 10.5 seconds. Co-authored-by: clowdyffs <alex@clowdydev.com>
Found this bug while diagnosing various resume/firmware issues on my 2017 Macbook Pro. Some addresses can be overwritten with the incorrect address on resume. Fixing this issue speeds up resume by 3,779× on this hardware, since it tries to recover for ~7 seconds when given the "bad" address.
Below this line is ai-written
A PCI_Config operation region first used while a PCI bridge is powering up can be initialized before the bridge's bus-number registers have been restored.
AcpiHwGetPciDeviceInfo()has already derived the bridge's bus from its parent, but overwrites that bus with the bridge's Primary Bus Number. When that register still contains zero, subsequent accesses target the wrong PCI device and the wrong address is retained in the operation-region context.This patch preserves the parent-derived bus and removes the redundant primary-bus read. It fixes a traced resume failure on Apple MacBookPro14,1 and removes approximately 6.94 seconds of firmware retry time in the measured comparison.
Observed failure and why it needs fixing
The affected hardware is a 2017 13-inch MacBook Pro, two Thunderbolt 3 ports, no Touch Bar (DMI
MacBookPro14,1), Intel x86-64, with firmware451.120.7.0.0and the Intel Alpine Ridge Thunderbolt hierarchy. The instrumented hardware comparison used Linux 7.2.3-arch1-3, with an otherwise matching local kernel carrying the equivalent ACPICA change. The machine now runs Omarchy's packagedlinux-omarchy 7.2.5-3; the new package name is not the kernel used for those earlier timing measurements.During the first affected resume-path region initialization, the PCI reads were:
UPSB.A1E0andUPSB.H530consequently retained00:00.0instead of04:00.0. Two DSB0 regions,A1E2andA1E1, exhibited the same overwrite, losing the already-derived bus 5. Later regions could derive correctly after their ancestors had been restored, so inspecting only the final PCI topology misses the problem.The H530 mailbox reads then went to the host bridge at
00:00.0. The capture recorded 150,120 command-register reads at offset0x530, returning all ones; mailbox data accesses at0x538also used the wrong device. The traced accessor calls include writes to those unintended mailbox offsets as well. No resulting host-bridge corruption or exploit has been established.Leaving this unchanged retains a demonstrated incorrect PCI address, including misdirected configuration accesses and exhausted firmware retries. The region initialization reports success, so ordinary error handling does not discard that wrong context. Fixing the derivation lets the original firmware operations complete against their intended bridge.
Why removing the read is sufficient
The helper already knows the current bridge's bus from the parent's secondary-bus number (or the initial root-bus value). It uses that address to read the bridge's header before it reaches the deleted code. On a normally configured hierarchy, the bridge's primary-bus value agrees with the address already derived; assigning it again provides no additional location information.
During this resume sequence, Linux can enter ACPI power-up before PCI state restoration. The primary register can therefore still hold its reset value while configuration reads already reach the bridge. Keeping the derived address also makes the following secondary-bus read use the correct bridge.
The change preserves bridge-type detection, secondary-bus reads, and their error handling. It adds no waits, allocations, model-specific bus numbers or changes to firmware retry limits. It removes one configuration read per bridge during derivation. There is no new performance work in this path; the compatibility question is whether some other platform depends on the overwritten value despite already having derived an address.
This code entered shared ACPICA in
08fd52445bf4, replacing OS-specificAcpiOsDerivePciIdimplementations, and entered Linux in95abccb576c4. The history does not document a special reason to overwrite the parent-derived bus. Please flag any historical platform dependency that should be considered.Measured result
00:00.004:00.000:00.005:00.0That is 6.937 seconds saved, approximately 99.97% less time (about 3,779× shorter duration) for those three firmware sequences. These are timings from the captured comparison, not a statistical benchmark or a claim that the entire system resumes 3,779× faster.
The timing comparison used automatic-return
pm_test=platform, with the same temporary Thunderbolt LC-sleep-skip diagnostic in both baseline and corrected runs to keep a separate controller-loss problem from obscuring the measurement. This comparison did not enter actual sleep. The full diagnostic transition included its intentional five-second pause; the table reports only the measured firmware sequences. Subsequent combined real-sleep tests also completed, but they are not used to calculate the speedup above.A same-boot control with the corrected kernel and original Thunderbolt driver still reproduced controller loss and its long recovery timeout, while the corrected firmware operations stayed fast. Thus this patch fixes the address/retry defect; it does not claim to solve that separate controller fault, intermittent Wi-Fi loss, lid-wake delivery or sleep power consumption.
Validation and universality limits
98bbab7dbae0ff7941c4cf08d46f5d30978f809e; onlysource/components/hardware/hwpci.cchanges (6 insertions, 11 deletions).acpiexecandacpisrc, including the modified hardware component, without compiler warnings or errors. The code is byte-identical to the native correction corresponding to the earlier hardware-validated Linux patch.-std=c11 -O2 -Wall -Wextra -Werror. 15 topology fixtures pass in both native ACPICA and current Linux form: the original two captured reset-primary failures, six original comparison cases, and seven additional nonzero-root-bus/CardBus cases. Four fixtures exercise the correction; eleven retain their original results.518e5b794c06c0f0eb40df3e202274a66202c137and passes strict checkpatch (the separate Linux-form draft was checked with--no-signoff; the submitted ACPICA commit carries the human submitter's sign-off). The introducing commit IDs/titles were verified against their respective repositories.Hardware evidence is limited to this one MacBookPro14,1. The extra root-bus/CardBus cases are simulations, not tests on those physical devices. ACPICA serves other platforms and operating systems, and this is a generic helper change, so the local results cannot establish universal compatibility. No full ACPICA test-suite pass, cross-OS testing, or hardware validation of a newly built current-mainline Linux kernel is claimed. Maintainer review and wider testing are requested, particularly for any platform relying on the old overwrite. The patch also cannot reconstruct a downstream bus number if the ancestor's secondary-bus register itself is unavailable or incorrect.
Assistance and reproducer
OpenAI Codex assisted with source/history analysis, preparation of the patch and replay harness, and interpretation of local hardware traces during investigation of slow resume on this Mac. The human submitter has added the DCO sign-off;
Assisted-by: LLMis included. No maintainer endorsement is implied.The standalone reproducer below extracts the actual helper from each supplied C source. It stubs only the ACPI/PCI interfaces and performs no live hardware access. The reset-secondary values in leaf fixtures are assumptions; the observed defect is the captured primary-zero overwrite. The nonzero-root-bus and CardBus fixtures are synthetic regression checks.
From a checkout of the PR branch, save the script below as
/tmp/replay-pci-expanded.py, then run:git show 98bbab7dbae0ff7941c4cf08d46f5d30978f809e:source/components/hardware/hwpci.c > /tmp/hwpci-before.c python3 /tmp/replay-pci-expanded.py /tmp/hwpci-before.c source/components/hardware/hwpci.cExpected:
"passed": true,"case_count": 15, and no compiler warnings. The output includes source hashes and the before/after address/status for every fixture.Standalone 15-case actual-C replay (Python 3 and a C compiler)