Repository navigation
drm/asahi: drain deferred BO cleanup after immediate GEM close - #1838
Conversation
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]>
|
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. 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. 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.
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. |
|
[Joshua's agent] Follow-up to my baseline comment: the kernel source is now known. The builder of Source. Top commit The nine commits, oldest first.
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. |
|
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 Host tests ( GPU / Vulkan CTS (deqp-vk, aurora-wip Mesa HEAD), targeting the buffer/memory/GEM-lifetime paths this change affects:
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. |
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
f8a53798bbfdb5804542e2a0e13514f4a9be9bd8passed 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-ARCHis reported asb43d20295a73(w88/lab4-73), baseintegration/aurora@50e5f040ba07plus the nine listed lab commits. Image SHA256292e10ea50334495d6fcb3ac858d541edb40fa5cd41b93ff7e1c98572bede37ecomes 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 off8a53798relies on timestamps, not an ancestry check.Mesa
1:26.2.4-1/Honeykrisp. The pinned reporter source isad36ede0274ba20cb11787d2e88e04fb3390ec20, SHA2565273f6acc23584151ee3e677de9b90266f08983a6eb8679e463e27460dfb6785; binary SHA256a0583b77aef9b2067a2c0b99688e4ce8fc690580c32d2520d6aceeb565ab6dbd. 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,-p1stayed3/3 and-p21/1 across both rounds; both reached0/0 aftervkDestroyDeviceand 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.