Skip to content

drm/asahi: drain deferred BO cleanup after immediate GEM close - #1838

Merged
RyanTheTide merged 1 commit into
integration/aurorafrom
fix/dmabuf-gem-close-cleanup-458
Nov 13, 2026
Merged

RyanTheTide merged 1 commit into
integration/aurorafrom
fix/dmabuf-gem-close-cleanup-458

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

REVERTED by #1885, merged as 5b36eff41af74dc4bb6a297d0832c11140466701. Do not reapply this synchronous GEM-close drain.

The M1 Pro/G13S sustained-CTS A/B reported intermittent firmware crashes with this commit present, versus three full consecutive passes (4,412,154 cases) without it, with the unrelated stamp-lifecycle fix retained. The lab described those three clean passes as suggestive, not conclusive; the rollback is the containment action, not proof of every mechanism or platform.

My extracted-method test checked reservation/put/drain ordering but did not model accepted firmware work. It therefore did not establish that GEM close was a safe reclamation point. Any replacement needs explicit firmware-retirement/quiescence ownership and appropriate hardware validation; this PR's host results are insufficient for that decision. The reported import/callback issue and delayed reclamation need to retain their distinct scope, and the older bounded M1 baseline did not reproduce buffers surviving device destruction or exit.

The original report/reproducer remains credited to Anees Iqbal (@steelbrain). The unsafe cleanup placement was my implementation; the reporter did not supply this kernel patch.

Original proposal and validation history, retained for traceability (superseded by rollback)

A freed dma-buf import can remain allocated while an M1/M2 Vulkan device is still alive. The G13/G14 GEM-close path removes its mappings and drops the temporary VM-BO reference, but that final put only queues deferred destruction. Nothing in that close path drains the queue.

Drain it immediately after releasing the VM reservation and the temporary BO reference, before returning an unmap error or taking the ENOMEM fallback. Remaining GPUVA references continue to retain backing after partial-unmap failures.

Credit for the finding, analysis and Vulkan/udmabuf reproducer goes to Anees Iqbal (@steelbrain) in omacom/linux-aurora#458. I found no contributed kernel patch in that report or its reproducer directory; this patch is new. The commit includes Reported-by and links to the report and pinned reproducer.

Scope: Aurora already addresses the imported-object callback/allocation bug through #240, and already drains normal VM/kernel-mapping teardown. This PR fixes the remaining immediate GEM-close retention; it does not claim the old-kernel leak after process exit has been reproduced on current Aurora. This is separate from omacom issue69's DMA-heap copy_to_user error leak.

Validation:

  • The host test extracts and compiles the actual drop_mappings_now() method with instrumented reservation and BO lifetimes, covering success, partial error, ENOMEM fallback and absent BO.

  • Positive run passes. All three registered negative controls compile and fail at runtime: missing drain, drain before final BO put, and drain while reservation held. Registered with tools/asahi/run-host-tests.py.

  • rustc1.99.0, edition2021, -Dwarnings. checkpatch: 0 errors, 1 generic new-file MAINTAINERS reminder.

  • Independent source review confirms the drain placement and remaining-mapping ownership.

  • Hosted CI on exact head f8a53798bbfdb5804542e2a0e13514f4a9be9bd8 passed all 306/306 registered host runs, including the new positive GEM-close test and all three runtime-negative controls (job log). This is host-test coverage, not a full kernel build or hardware reclamation result.

  • Public M1 baseline report, with builder-supplied source follow-up: kernel 7.3.0-2-20261110.1-lab-ARCH is reported as b43d20295a73 (w88/lab4-73), base integration/aurora@50e5f040ba07 plus the nine listed lab commits. Image SHA256 292e10ea50334495d6fcb3ac858d541edb40fa5cd41b93ff7e1c98572bede37e comes from the builder, not a new hash by the tester. The lab top is not resolvable through the Aurora GitHub API, so its complete source delta was not independently checked here; commit titles alone do not establish free-path equivalence. It predates this PR; the report's exclusion of f8a53798 relies on timestamps, not an ancestry check.

    Mesa 1:26.2.4-1/Honeykrisp. The pinned reporter source is ad36ede0274ba20cb11787d2e88e04fb3390ec20, SHA256 5273f6acc23584151ee3e677de9b90266f08983a6eb8679e463e27460dfb6785; binary SHA256 a0583b77aef9b2067a2c0b99688e4ce8fc690580c32d2520d6aceeb565ab6dbd. One run per mode (-t1 -w2 -n8 -r2 -m16 -M1 -f16 -p1 -c1 -S, then -p2). Live control observed1 buffer/1 attachment, still1 after freeing the control: it validates live visibility, not immediate reclamation. Before device destruction, -p1 stayed3/3 and -p21/1 across both rounds; both reached0/0 after vkDestroyDevice and process exit, with0 new kernel-log lines. This bounded run did not reproduce an after-device/exit leak. The flat live-device references remain unexplained and are not established to be leaks. No larger stress run was requested; this is not a test of the patched kernel.

  • No full kernel build or fixed-kernel reclamation comparison yet.

Based on integration/aurora aa9c73f.

Anees Iqbal reported that dma-buf imports can retain their backing after
Vulkan frees them. Aurora already gives imported objects the driver's
close callback, but the G13/G14 immediate close path still leaves a final
VM-BO put on the deferred cleanup list.

drop_mappings_now() holds a temporary BO reference while bo_unmap removes
its GPUVAs. Releasing that reference after unlocking the VM can enqueue
the last BO, retaining its GEM and GPUVM until a later cleanup happens.
Drain after both the reservation and temporary reference are released,
before propagating errors or entering the ENOMEM fallback.

Add a host test that compiles this production method with instrumented
reservation and BO lifetimes. Cover success, partial unmap failure,
ENOMEM fallback and an absent BO; reject omission of the drain and both
unsafe drain orderings. This does not substitute for a hardware dma-buf
reclamation run.

Reported-by: Anees Iqbal <[email protected]>
Link: omacom/linux-aurora#458
Link: https://github.com/steelbrain/metal2vulkan/blob/ad36ede0274ba20cb11787d2e88e04fb3390ec20/scripts/dma-buf-leak/repro.c
Assisted-by: LLM
Signed-off-by: Diljit Singh <[email protected]>
@joshuaswarren

joshuaswarren commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Baseline run of the dma-buf import repro (linux-aurora#458) on a 13-inch M1 MacBook Pro, from before this PR. This is not a test of the fix.

Kernel. 7.3.0-2-20261110.1-lab-ARCH, built 2026-11-10 06:03 UTC (#4 SMP PREEMPT_DYNAMIC, clang 22.1.8). I could not recover the kernel source commit or its exact composition: the build is not a package on the machine, and no commit id is recorded in the kernel image or modules directory. A train/20261110-linux merge branch exists in a local clone, but I cannot tie this kernel to it, so I am not claiming that.

Is f8a5379 in it? No. Commit f8a5379 (this PR head) was committed 2026-11-13 15:05 UTC. The kernel was built three days earlier, so it cannot contain the commit. This comes from the two timestamps, not from a source diff.

Repro. repro.c from steelbrain/metal2vulkan commit ad36ede0274ba20cb11787d2e88e04fb3390ec20, blob 46a40e356f667f7d8a1bb5e134d3704880603563, sha256 5273f6acc23584151ee3e677de9b90266f08983a6eb8679e463e27460dfb6785. Binary sha256 a0583b77aef9b2067a2c0b99688e4ce8fc690580c32d2520d6aceeb565ab6dbd. Mesa 1:26.2.4-1 with the honeykrisp ICD. Arguments: -t1 -w2 -n8 -r2 -m16 -M1 -f16 -p1 -c1 -S, then the same with -p2.

Live control. While the control buffer was alive, the process listed 1 buffer with 1 attachment, so the counter sees a named buffer and its attachment. After the control buffer was freed, it still read 1. I did not explain that reading, so treat the control as a check that the counter works while buffers are live only.

Result.

Point -p1 buffers / attachments -p2 buffers / attachments
Before vkDestroyDevice, both rounds 3 / 3 1 / 1
After vkDestroyDevice 0 / 0 0 / 0
After process exit 0 / 0 0 / 0

The kernel log gained 0 new lines during the run (1676 lines before) and had 0 matching lines.

Limits. One run per mode, 1 thread, imports of 16 KiB to 1 MiB. On this kernel the run did not reproduce a leftover buffer after device destroy. I make no claim that the leak is fixed or absent. A fixed-head comparison needs a kernel that contains f8a5379; I have not installed one.

@joshuaswarren

Copy link
Copy Markdown
Contributor

[Joshua's agent] Follow-up to my baseline comment: the kernel source is now known. The builder of 7.3.0-2-20261110.1-lab-ARCH supplied it, and I checked the commit list in a local clone.

Source. Top commit b43d20295a73, on branch w88/lab4-73. Base is integration/aurora at 50e5f040ba07 (2026-11-09). Nine commits sit on top. Image sha256 (from the builder, not re-hashed by me) 292e10ea50334495d6fcb3ac858d541edb40fa5cd41b93ff7e1c98572bede37e, built 2026-11-10 06:04:12 UTC. The builder says later commits on that branch are not in the image.

The nine commits, oldest first.

  1. 279e5ac9c2ee pci=noiovbars (SR-IOV BAR opt-out)
  2. deda29e70eed xe non-posted VRAM keep for the B60
  3. 70064c47d6e3 xe UAPI header NP_KEEP definitions
  4. a796d1fd6a87 xe stolen manager registers fini before the fallible map
  5. 1ba83ced9ae0 cast the xe np dev_info format args to unsigned long long
  6. c6f959792f41 PCI: apple: cold-init T600x/T602x PCIe-C ports without a DT property
  7. 83a145c43a7c keep the DRM driver name for the Apple GPU driver
  8. 693cc5cc816c ASoC: apple: macaudio: keep the board-table amp gain when the DT has no speaker rows
  9. b43d20295a73 PCI: apple: mirror the root-port prefetchable window into the port block on cold-init tunnels

None of them touches the GPU buffer free path by title. I did not diff them for that.

f8a5379. The conclusion is unchanged: it is dated 2026-11-13 and the base is dated 2026-11-09, so it is not in this kernel. I could not run an ancestry check, because the local clone does not have that commit. A fixed-head comparison still needs a kernel built with it.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Hardware proof on M2 (Apple M2, t8112, G14G) — the G14 analog of the G13 deferred-cleanup path this PR drains.

Build: proof kernel = current fleet base + the just-merged #1828 + this PR cherry-picked on top. The two compose cleanly — this PR touches drivers/gpu/drm/asahi/mmu.rs (bo_deferred_cleanup() drain after an immediate GEM close in drop_mappings), #1828 touches workqueue.rs (command-descriptor retirement); different files, different deferred-cleanup mechanisms. Cherry-pick (f8a5379) onto the #1828 tip applied with no conflicts. SELinux enforcing throughout; one-shot boot on real hardware.

Host tests (run-host-tests.py --only gem-close): 4/4. The control compiles and runs; all three mutations — omit-drain, drain-before-put, drain-under-lock — are correctly killed, confirming the drain is present and correctly ordered.

GPU / Vulkan CTS (deqp-vk, aurora-wip Mesa HEAD), targeting the buffer/memory/GEM-lifetime paths this change affects:

  • api.smoke: 8/8 pass.
  • Lifetime subset, 10,528 cases across 6 chunks: memory.mapping (dedicated + suballocation), memory.zero_initialize_device_memory, memory.binding, memory.pageable/device_group/allocation, api.buffer.suballocation/dedicated_alloc, api.buffer_view.create/access, api.external.memory incl. dma_buf export/import (the leak path), synchronization2.basic, and null_handle object-lifetime. Result: 8,538 Pass + 1,990 NotSupported = 10,528/10,528, 0 Fail, 0 GPU-firmware co-processor crashes across all 6 chunks, 0 GPU timeouts.
  • Firmware co-processor crashes this boot: 0 before, 0 after. SELinux AVC denials: 0.

Clean restore to the production kernel afterward; test kernel removed. No dma-buf / GEM-cleanup regression observed on G14 under the export/import and buffer-lifetime workloads.

@RyanTheTide
RyanTheTide merged commit c638876 into integration/aurora Nov 13, 2026
1 check passed
@RyanTheTide
RyanTheTide deleted the fix/dmabuf-gem-close-cleanup-458 branch November 16, 2026 05:06
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