Repository navigation
drm/asahi: g17: keep firmware-mutable pooled state uncached - #3170
Conversation
On G17, Pool::allocate() converts the requested prefix of pooled firmware objects from MEMATTR_UNCACHED to MEMATTR_CACHED via set_fw_cached_prefix(), while the host accesses them through write-combined mappings. G17 firmware has no cache-flush protocol, and host CPU stores neither snoop nor invalidate dirty lines in the firmware coprocessor's private cache. When the firmware writes runtime state into a firmware-cached page and the host later overwrites fields on the same cache line, the firmware can read stale data from its cache and later evict the dirty line back to DRAM, reverting the host's update. On J716c (T6050), rebinding an idle compute queue to a new context through Graph::set_owner() left the firmware's dirty QueueRecord line intact: on subsequent mixed render/compute work, QueueRecord.job_list_va in DRAM reverted to the previous context's WorkHead, stranding shared WorkNodes with completed == submitted and a non-empty job list until the 2 s watchdog failed the client with VK_ERROR_DEVICE_LOST and quarantined the queues. The same dirty-line hazard applies to every pooled G17 object that both the firmware and the host write: - Compute queue graphs (QueueRecord rewritten on rebind, items ring rewritten on wrap). Because installed compute graphs live until firmware stop, allocate them directly as uncached KernelObjects, freeing Family::QueueState pool slots for render pairs. - Compute descriptor rings (M5 common firmware clears the accounting counter at +0xfac, and the host rewrites each slot every 32 kicks). - Render queue-state objects (QueueRecord rewritten on G17P rebind and work-slot bind, and zeroed on pool reuse everywhere). - Context work-state objects (WorkNode slots rewritten every 63 submissions and zeroed on pool reuse). - M5 context scheduler pages (zeroed and reinitialized on pool reuse). Allow Pool::allocate() with prefix == 0 to retain and fence an uncached mapping without calling set_fw_cached_prefix(), preserving control-ring fencing, A18 Pro ReturnMark tracking, retain_until_stop(), and O(1) VA reuse. Pass prefix == 0 for compute DescriptorRing, render QueueState, WorkState, and M5 Scheduler allocations, leave firmware-read-only render descriptors (which already fall back to uncached on M5 due to the 32-page conversion limit) and QueueConfig pools unchanged, add release barriers after QueueRecord owner rebinds, and cover prefix == 0 pool retention in tools/asahi/g17-object-fence-tests.py. Signed-off-by: Erik Bourget <[email protected]>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Audited full 307-line diff across all 5 files at 3025a8dcbf66: keeping firmware-mutable pooled G17 objects (Scheduler, WorkState, DescriptorRing, render QueueState) uncached via prefix == 0 in Pool::allocate() while preserving pool leasing/fencing/reuse zeroing/retention, allocating compute::Graph uncached directly, adding Ordering::Release fences after in-place owner/queue-record updates, and covering prefix == 0 in tools/asahi/g17-object-fence-tests.py cleanly addresses the non-coherent firmware writeback hazard. DCO, J716c 5,454/5,454 multi_queue.* + 8-way stress, and 93/93 host tests look solid.
Holding merge until CI completes and a second-generation G17 regression row (M4 Pro or Neo) lands.
|
3025a8d J616s (MacBook Pro 16" M4 Pro, T6040,
|
|
Tested (
|
What: Keep G17 pooled firmware objects that both the firmware and host write (
compute::Graph, computeDescriptorRing, renderQueueState, contextWorkState, and M5Scheduler) mappedMEMATTR_UNCACHEDinstead of converting them to non-coherentMEMATTR_CACHED, fixing dirty firmware cache-line evictions that revertedQueueRecord.job_list_vaon compute rebinds and causedVK_ERROR_DEVICE_LOSTwatchdog timeouts and quarantined queues.Tested: J716c M5 Max (T6050) at
3025a8dcbf66(identical tree0607db4616e9tested on trial kernel7.3.0-ewb313+ #8): two 4-way passes ofdEQP-VK.synchronization2.op.multi_queue.*(6,000 cases each) passed 5,454/5,454 (546 unsupported, 0 failures, 0DeviceLost, 0 GPU kernel errors), 8-way stress hit 0DeviceLostand 0 quarantined slots, Hyprland desktop ran cleanly with 0 new kernel errors;tools/asahi/run-host-tests.py --only g1793/93 passed.Risk: two-way door · M4 Pro, M4 Max, M5 Pro, M5 Max, Neo (G17 GPUs)
Not yet: M4 Pro (T6040) / A18 Pro (T8140 / Neo) hardware regression row (hardware not in this lab).
Details
Root cause
Pool::allocate()converts[0..prefix)of pooled G17 firmware objects fromMEMATTR_UNCACHEDtoMEMATTR_CACHEDviaset_fw_cached_prefix(), while the host accesses them through write-combined mappings. G17 has no firmware cache-flush protocol, and host CPU stores neither snoop nor invalidate dirty lines in the firmware coprocessor's private cache.When firmware writes runtime state into a firmware-cached page and the host later overwrites fields on the same cache line, the firmware can read stale data from its cache and later evict the dirty line back to DRAM, reverting the host's update:
drivers/gpu/drm/asahi/g17/queue/compute.rs): On J716c, rebinding an idle compute queue to a new context throughGraph::set_owner()left the firmware's dirtyQueueRecordcache line intact. On subsequent mixed render/compute work sharing aWorkNode,QueueRecord.job_list_vain DRAM reverted to the previous context'sWorkHead(observed on 4/4 compute timeouts:qid=37,qid=15,qid=14,qid=4). Render linked theWorkNodeonto the current context'sWorkHeadwhile compute targeted the previous context'sWorkHead, leavingcompleted == submittedwith a non-empty job list until the 2 s watchdog failed the client withVK_ERROR_DEVICE_LOSTand quarantined the queues. Computeitems[1280]also lived inside the cached prefix and wraps every 1,280 entries.drivers/gpu/drm/asahi/g17/queue/compute.rs): Common M5 firmware clears the accounting counter at+0xfac, and the host rewrites each slot every 32 kicks.drivers/gpu/drm/asahi/g17/queue/render/memory.rs): Both firmware and host writeQueueRecord(in-placeset_owner()andbind_work_slot()on G17P, and zeroing on pool reuse on all G17 GPUs).drivers/gpu/drm/asahi/g17/context.rs): Both firmware and host writeWorkNode[0..62](reused every 63 submissions viaWorkStorage::initialize()and zeroed on pool reuse).drivers/gpu/drm/asahi/g17/context.rs): Written by firmware and zeroed/reinitialized on pool reuse.Changes
drivers/gpu/drm/asahi/g17/object.rs: AllowPool::allocate()withprefix == 0to keep the mappingMEMATTR_UNCACHED(skippingset_fw_cached_prefix()and itstlbi_all()) while preserving pool reservation,control_fence(), A18 ProReturnMarktracking,retain_until_stop(), and O(1) VA reuse. Theif prefix == 0early return is placed afterif !reservedso pending pool-fencing work stays cleanly ordered.drivers/gpu/drm/asahi/g17/queue/compute.rs: Allocate installed compute graphs directly as uncachedKernelObjects (they live until firmware stop and no longer consumeFamily::QueueStatepool slots needed by render pairs), passprefix = 0for computeDescriptorRing, and addOrdering::Releasebarriers afterGraph::set_owner().drivers/gpu/drm/asahi/g17/queue/render/memory.rs: Passprefix = 0forFamily::QueueStateand addOrdering::Releasebarriers afterMemory::set_owner().drivers/gpu/drm/asahi/g17/context.rs: Passprefix = 0forFamily::WorkStateand M5Family::Scheduler. Leave firmware-read-only render descriptors (which already fall back to uncached on M5 due to the 32-page conversion limit) andQueueConfigpools unchanged.tools/asahi/g17-object-fence-tests.py: Assertset_fw_cached_prefixis never called forprefix == 0and adduncached_pooledcovering pool leases,ReturnMark,control_fence(), reuse zeroing,retain_until_stop(), andstop_after_firmware().Evidence
J716c (T6050, M5 Max) hardware row
3025a8dcbf6625b2a98edf4faa8cadf4262efd6f(tree0607db4616e98a5e75b5649935d0ee6098a550a7, identical built kernel tof2fc7fd815da; only commit message wording updated).7.3.0-ewb313+ #8 SMP PREEMPT(one-shotaura-trytrial boot, default kernel command line).asahi_icd.aarch64.json),deqp-vk(synchronization2.txt, first 6,000 cases ofdEQP-VK.synchronization2.op.multi_queue.*).DeviceLostResourceErrororigin/main)LogicalQueuescap)vkCmdFillBuffer, single queue, 2,000d1/ 8,000d64submissions):d1 = 128.4 us/submit,d64 = 15.4 us/submit.m5-gpu.lua),crashed=0,online=1,physical_qids used=124/128 (tiling=49 fragment=49 compute=26),render_slots quarantined=0,cached_objects_fenced overruns=0,firmware_linked_objects kept=0, 0 new kernel errors (pre-existingaurora-peripherals.servicefailure unchanged from default boot).Host tests & checks
python3 tools/asahi/run-host-tests.py --only g17: 93/93 passed (2 s), includingg17-object-fence-testsand all 5 mutations../scripts/checkpatch.pl --strict --git origin/main..HEAD:total: 0 errors, 0 warnings, 0 checks, 269 lines checked.git diff --check origin/main..HEAD: clean.