From e3e303261dd51ce9aeb6488c5fff7bad2bd2c9fb Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Fri, 27 Nov 2026 02:55:02 -0500 Subject: [PATCH 1/4] drm/asahi: g16: wait for the compute service stamp before a render reads A render pass that depends on compute work waits for it with a firmware barrier on the compute pipe's stamp. That barrier waited on fw_stamp, which the firmware stores at FINALIZE. The kernel only retires compute work at the pipe's later service stamp, after the firmware has finished servicing the record. A render on another queue of the same VM could therefore start while the compute writes it reads were not yet visible to it. In dEQP-VK.synchronization.op.multi_queue.timeline_semaphore. write_image_tess_control_read_blit_image.*, a tessellation-control compute pass writes an image on one queue and a blit reads it on another; under CPU load about one full parallel run in three failed with "Memory contents don't match" (linux#3349). Wait on the service stamp instead, at both the TA and the FS barrier. The wait stays in firmware. Closes: https://github.com/aurora-silicon/linux/issues/3349 Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g16/engine.rs | 19 ++++++++++--------- drivers/gpu/drm/asahi/g16/graph.rs | 9 +++++++++ .../drivers/gpu/asahi-m4/test-publication.py | 8 ++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/engine.rs b/drivers/gpu/drm/asahi/g16/engine.rs index d96e24b6d851a..c773f465ebde9 100644 --- a/drivers/gpu/drm/asahi/g16/engine.rs +++ b/drivers/gpu/drm/asahi/g16/engine.rs @@ -148,13 +148,12 @@ struct WaitTarget { /// /// Unlike G15 (`g15/hw.rs: CROSS_ENGINE_HOLD` — "Never both type 0"), G16 (M4 25G83/26B123) /// does not require a software-job hold on one cross-engine direction when neither side -/// carries `InitBM`. On G16, every stage (CDM, TA, FS) executes its `FINALIZE` -/// micro-sequence — flushing stage caches to the shared coherent fabric — before firmware -/// advances `fw_stamp`, so waiting on `fw_stamp` with `BarrierType::Stamp` (type 0) in both -/// directions (`fs2c` and `c2ta`/`c2fs`) avoids hold bubbles within one VM (same ASID and -/// UAT page tables). Zero-fault M4 J773g runs (13,873 `fs2c` and 20,506 `c2ta` type-0 -/// handoffs) confirm no GPU wedge or hang, while CTS synchronization / pipeline-barrier -/// coverage validates producer-to-consumer memory visibility. +/// carries `InitBM`: `BarrierType::Stamp` (type 0) in both directions (`fs2c` and +/// `c2ta`/`c2fs`) avoids hold bubbles within one VM (same ASID and UAT page tables). +/// Zero-fault M4 J773g runs (13,873 `fs2c` and 20,506 `c2ta` type-0 handoffs) confirm no GPU +/// wedge or hang. Which stamp a wait uses is chosen at its site: a producer's `fw_stamp`, +/// stored at `FINALIZE`, does not yet make its writes visible to work on another firmware +/// queue, so waits on compute use `ComputeGraph::service_stamp_va` (linux#3349). /// /// Keep `BarrierType::Hold` (type 1) whenever either producer or consumer carries `InitBM` /// (checked against both the waited target and any live `InitBM` flight). Cross-VM switches, @@ -3914,9 +3913,11 @@ impl Firmware { } for p_idx in 0..sizes::COMPUTE_PIPES { let off = p_idx * work::barrier::SIZE; + // A render reads what compute wrote: wait for the producer pipe's service stamp, not + // its FINALIZE fw_stamp (see `ComputeGraph::service_stamp_va`). if let Some(wait_c) = plan.ta_compute_wait[p_idx] { let cbar = encode::barrier( - self.graph.compute[p_idx].fw_stamp.va, + self.graph.compute[p_idx].service_stamp_va(), wait_c, work::compute::EVENTS[p_idx], target, @@ -3932,7 +3933,7 @@ impl Firmware { } if let Some(wait_c) = plan.fs_compute_wait[p_idx] { let fcbar = encode::barrier( - self.graph.compute[p_idx].fw_stamp.va, + self.graph.compute[p_idx].service_stamp_va(), wait_c, work::compute::EVENTS[p_idx], target, diff --git a/drivers/gpu/drm/asahi/g16/graph.rs b/drivers/gpu/drm/asahi/g16/graph.rs index b3eaa19d7ee44..fee591770bbb4 100644 --- a/drivers/gpu/drm/asahi/g16/graph.rs +++ b/drivers/gpu/drm/asahi/g16/graph.rs @@ -263,6 +263,15 @@ impl ComputeGraph { )?; self.threshold.w64(0, 1) } + + /// The pipe's terminal service-stamp cell. The firmware stores a work item's stamp here after + /// it has finished servicing the item's record, later than [`Self::fw_stamp`], which it stores + /// at FINALIZE. Work on another firmware queue that reads what this pipe's work wrote waits on + /// this cell: at FINALIZE those writes are not yet visible there (linux#3349). Retirement + /// waits for the same cell. + pub(crate) fn service_stamp_va(&self) -> u64 { + self.notifier.va + notifier_page::COMPUTE_STAMP as u64 + } } pub(crate) struct RenderGraph { diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py index 50611556c8718..5dc6321213168 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -69,6 +69,14 @@ def item(declaration): assert 'work::compute::EVENTS[pipe]' in prefix_compute_fn assert 'work::compute::EVENTS[p_idx]' in c2ta_slice assert 'work::compute::EVENTS[p_idx]' in c2fs_slice +# linux#3349: a render's barriers on a compute pipe wait on that pipe's service stamp, not FINALIZE. +assert 'self.graph.compute[p_idx].service_stamp_va(),' in c2ta_slice, c2ta_slice +assert 'self.graph.compute[p_idx].service_stamp_va(),' in c2fs_slice, c2fs_slice +assert 'fw_stamp' not in c2ta_slice and 'fw_stamp' not in c2fs_slice +graph_src = (production.parent / 'graph.rs').read_text() +service_fn = graph_src[graph_src.index('pub(crate) fn service_stamp_va(&self) -> u64 {'):] +service_fn = service_fn[:service_fn.index('\n }\n') + 6] +assert 'self.notifier.va + notifier_page::COMPUTE_STAMP as u64' in service_fn, service_fn assert 'render_bar,' in c2ta_slice and 'BarrierType::Hold' not in c2ta_slice assert 'render_bar,' in c2fs_slice and 'BarrierType::Hold' not in c2fs_slice assert 'BarrierType::Stamp,' in prefix_render_fn[prefix_render_fn.index('let own = encode::barrier'):prefix_render_fn.index('p.own_barrier.write')] From d64356f5264e88cdc9107c7d81ad90106374f378 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Fri, 27 Nov 2026 02:55:51 -0500 Subject: [PATCH 2/4] drm/asahi: g16: wait for the compute service stamp across compute pipes Compute on one pipe that depends on compute on the other pipe waits with a firmware barrier on the producer pipe's stamp. Like the render barriers before the previous commit, it waited on fw_stamp, which the firmware stores at FINALIZE, earlier than the service stamp the kernel retires on. No failing case shows this on its own: the measured failure in linux#3349 is a render reading compute output. The dependency is the same kind, though, and FINALIZE has not been a point at which writes are visible to another queue anywhere we measured. So wait on the producer pipe's service stamp here too. This commit stands alone so it can be reviewed and reverted separately. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g16/engine.rs | 4 +++- .../selftests/drivers/gpu/asahi-m4/test-publication.py | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/asahi/g16/engine.rs b/drivers/gpu/drm/asahi/g16/engine.rs index c773f465ebde9..4d37ef43c3ab2 100644 --- a/drivers/gpu/drm/asahi/g16/engine.rs +++ b/drivers/gpu/drm/asahi/g16/engine.rs @@ -3564,8 +3564,10 @@ impl Firmware { let producer_initbm = wait_c.initbm || self.engine.flights.iter().any(|fl| fl.initbm); let bar_type = cross_engine_barrier_type(producer_initbm, false); + // Compute on another pipe may read what the producer wrote: wait for the + // producer pipe's service stamp, not its FINALIZE fw_stamp. let bar = encode::barrier( - self.graph.compute[p_idx].fw_stamp.va, + self.graph.compute[p_idx].service_stamp_va(), wait_c.stamp, work::compute::EVENTS[p_idx], target, diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py index 5dc6321213168..d20e4c832fcfc 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -77,6 +77,13 @@ def item(declaration): service_fn = graph_src[graph_src.index('pub(crate) fn service_stamp_va(&self) -> u64 {'):] service_fn = service_fn[:service_fn.index('\n }\n') + 6] assert 'self.notifier.va + notifier_page::COMPUTE_STAMP as u64' in service_fn, service_fn +# Cross-pipe compute->compute barriers wait on the producer pipe's service stamp as well. +c2c_slice = prefix_compute_fn[ + prefix_compute_fn.index('for (p_idx, wait_opt) in c_waits.iter().enumerate()'): + prefix_compute_fn.index('s.barrier.write(off, &bar)?;') +] +assert 'self.graph.compute[p_idx].service_stamp_va(),' in c2c_slice, c2c_slice +assert 'fw_stamp.va' not in c2c_slice, c2c_slice assert 'render_bar,' in c2ta_slice and 'BarrierType::Hold' not in c2ta_slice assert 'render_bar,' in c2fs_slice and 'BarrierType::Hold' not in c2fs_slice assert 'BarrierType::Stamp,' in prefix_render_fn[prefix_render_fn.index('let own = encode::barrier'):prefix_render_fn.index('p.own_barrier.write')] From ab9d85f2bf177314df81d03eae8544f4c298a028 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Fri, 27 Nov 2026 03:01:47 -0500 Subject: [PATCH 3/4] drm/asahi: g16: wait for the render service stamp before compute reads Compute that depends on a render pass waits for it with a firmware barrier on the render FS stamp. It waited on fw_stamp[1], which the firmware stores at FINALIZE, earlier than the FS service stamp that render retirement waits for. No single failing case isolates this direction. The evidence that FS FINALIZE is not a point at which a render's writes are visible to another queue is direct, though: signalling render job fences at FINALIZE instead of the service stamps made the multi_queue sync list fail hundreds of "write on one queue, read on another" cases on the J773g. The compute-to-render direction of the same wait is linux#3349. So wait on the FS service stamp here too. This commit stands alone so it can be reviewed and reverted separately. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g16/engine.rs | 9 +++++---- drivers/gpu/drm/asahi/g16/graph.rs | 8 ++++++++ .../selftests/drivers/gpu/asahi-m4/test-publication.py | 9 +++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/engine.rs b/drivers/gpu/drm/asahi/g16/engine.rs index 4d37ef43c3ab2..bf5a6c73a418b 100644 --- a/drivers/gpu/drm/asahi/g16/engine.rs +++ b/drivers/gpu/drm/asahi/g16/engine.rs @@ -153,7 +153,8 @@ struct WaitTarget { /// Zero-fault M4 J773g runs (13,873 `fs2c` and 20,506 `c2ta` type-0 handoffs) confirm no GPU /// wedge or hang. Which stamp a wait uses is chosen at its site: a producer's `fw_stamp`, /// stored at `FINALIZE`, does not yet make its writes visible to work on another firmware -/// queue, so waits on compute use `ComputeGraph::service_stamp_va` (linux#3349). +/// queue, so waits on compute use `ComputeGraph::service_stamp_va` (linux#3349) and waits on +/// a render's FS use `RenderGraph::fs_service_stamp_va`. /// /// Keep `BarrierType::Hold` (type 1) whenever either producer or consumer carries `InitBM` /// (checked against both the waited target and any live `InitBM` flight). Cross-VM switches, @@ -3536,14 +3537,14 @@ impl Firmware { // Check producer InitBM explicitly in addition to the scheduler drain guard so // FS -> CDM handoff: downgrade to `BarrierType::Stamp` (type 0) only when neither // the waited render nor any live flight carries `InitBM` and the GPU does not need - // G15's cross-engine hold; G16 FS `FINALIZE` flushes caches before advancing - // `fw_stamp[1]` (see `cross_engine_barrier_type`). + // G15's cross-engine hold (see `cross_engine_barrier_type`). Compute may read what + // the render wrote: wait for the FS service stamp, not its FINALIZE `fw_stamp[1]`. let producer_initbm = self.cfg.cross_engine_hold || wait_fs.initbm || self.engine.flights.iter().any(|fl| fl.initbm); let bar_type = cross_engine_barrier_type(producer_initbm, false); let bar = encode::barrier( - self.graph.render.fw_stamp[1].va, + self.graph.render.fs_service_stamp_va(), wait_fs.stamp, 0x71, target, diff --git a/drivers/gpu/drm/asahi/g16/graph.rs b/drivers/gpu/drm/asahi/g16/graph.rs index fee591770bbb4..7acf3e3d396c9 100644 --- a/drivers/gpu/drm/asahi/g16/graph.rs +++ b/drivers/gpu/drm/asahi/g16/graph.rs @@ -364,6 +364,14 @@ impl RenderGraph { } Ok(()) } + + /// The FS queue's terminal service-stamp cell, stored after the firmware has serviced a + /// pass's FS record, later than `fw_stamp[1]` (`FINALIZE`). Work on another firmware queue + /// that reads what a render wrote waits on this cell, as it does for compute + /// ([`ComputeGraph::service_stamp_va`]). Retirement waits for the same cell. + pub(crate) fn fs_service_stamp_va(&self) -> u64 { + self.notifier.va + notifier_page::FS_STAMP as u64 + } } /// Session-side queue graph allocations before sealing the session allocator and attaching diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py index d20e4c832fcfc..19cb607540842 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -88,6 +88,15 @@ def item(declaration): assert 'render_bar,' in c2fs_slice and 'BarrierType::Hold' not in c2fs_slice assert 'BarrierType::Stamp,' in prefix_render_fn[prefix_render_fn.index('let own = encode::barrier'):prefix_render_fn.index('p.own_barrier.write')] assert 'cross_engine_barrier_type(producer_initbm, false)' in fs2c_slice +# Render->compute (fs2c) waits on the render FS service stamp, not FINALIZE fw_stamp[1]. +fs2c_bar = prefix_compute_fn[ + prefix_compute_fn.index('let fs2c_bar ='):prefix_compute_fn.index('s.barrier.write(0, &bar)?;') +] +assert 'self.graph.render.fs_service_stamp_va(),' in fs2c_bar, fs2c_bar +assert 'fw_stamp[1].va' not in fs2c_bar, fs2c_bar +render_service_fn = graph_src[graph_src.index('pub(crate) fn fs_service_stamp_va(&self) -> u64 {'):] +render_service_fn = render_service_fn[:render_service_fn.index('\n }\n') + 6] +assert 'self.notifier.va + notifier_page::FS_STAMP as u64' in render_service_fn, render_service_fn assert 'bar_type,' in fs2c_slice and 'BarrierType::Hold' not in fs2c_slice assert 'let waits_for_timestamps = c.query_access' in can_queue_behind_fn assert 'DRM_ASAHI_FEATURE_RENDER_STAGE_PREFIXES_V2' in params_src From f84a141fb06eb94b87e981002eb0a16f8f8d6c5c Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Fri, 27 Nov 2026 03:41:57 -0500 Subject: [PATCH 4/4] drm/asahi: g16: name each service-stamp cell through one accessor Three places name a pipe's service-stamp cell: the work item that tells the firmware where to store the stamp, retirement that reads it, and the cross-engine barriers that now wait on it. They named it separately. If one of them moved the cell, for example by mapping the notifier page differently, a barrier would wait on a cell the firmware no longer writes, and its queue would hang. Give each cell one accessor, ComputeGraph::service_stamp() and RenderGraph::{ta,fs}_service_stamp(), returning a StampCell with its VA and a read. Work items, retirement and barriers all go through them, and the selftests check that no other code names the cells. No functional change: every address and read is the same as before. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g16/engine.rs | 26 ++++----- drivers/gpu/drm/asahi/g16/graph.rs | 54 ++++++++++++++----- drivers/gpu/drm/asahi/g16/poll.rs | 12 ++--- .../drivers/gpu/asahi-m4/test-publication.py | 33 ++++++++---- .../drivers/gpu/asahi-m4/test-resources.py | 2 + .../drivers/gpu/asahi-m4/test-stamp-wrap.py | 19 +++++++ 6 files changed, 102 insertions(+), 44 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/engine.rs b/drivers/gpu/drm/asahi/g16/engine.rs index bf5a6c73a418b..4575308b4533b 100644 --- a/drivers/gpu/drm/asahi/g16/engine.rs +++ b/drivers/gpu/drm/asahi/g16/engine.rs @@ -153,8 +153,8 @@ struct WaitTarget { /// Zero-fault M4 J773g runs (13,873 `fs2c` and 20,506 `c2ta` type-0 handoffs) confirm no GPU /// wedge or hang. Which stamp a wait uses is chosen at its site: a producer's `fw_stamp`, /// stored at `FINALIZE`, does not yet make its writes visible to work on another firmware -/// queue, so waits on compute use `ComputeGraph::service_stamp_va` (linux#3349) and waits on -/// a render's FS use `RenderGraph::fs_service_stamp_va`. +/// queue, so waits on compute use `ComputeGraph::service_stamp` (linux#3349) and waits on a +/// render's FS use `RenderGraph::fs_service_stamp`. /// /// Keep `BarrierType::Hold` (type 1) whenever either producer or consumer carries `InitBM` /// (checked against both the waited target and any live `InitBM` flight). Cross-VM switches, @@ -2458,10 +2458,7 @@ impl Firmware { notifier: r.notifier.va, legacy_empty: r.legacy_empty.va, qinfo: [r.qinfo[0].va, r.qinfo[1].va], - user_stamp: [ - r.notifier.va + notifier_page::TA_STAMP as u64, - r.notifier.va + notifier_page::FS_STAMP as u64, - ], + user_stamp: [r.ta_service_stamp().va(), r.fs_service_stamp().va()], fw_stamp: [r.fw_stamp[0].va, r.fw_stamp[1].va], uma_mgr: a.uma_mgr, uma_aux: a.uma_aux, @@ -2502,10 +2499,7 @@ impl Firmware { notifier: r.notifier.va, legacy_empty: r.legacy_empty.va, qinfo: [r.qinfo[0].va, r.qinfo[1].va], - user_stamp: [ - r.notifier.va + notifier_page::TA_STAMP as u64, - r.notifier.va + notifier_page::FS_STAMP as u64, - ], + user_stamp: [r.ta_service_stamp().va(), r.fs_service_stamp().va()], fw_stamp: [r.fw_stamp[0].va, r.fw_stamp[1].va], uma_mgr: a.uma_mgr, uma_aux: a.uma_aux, @@ -3450,7 +3444,7 @@ impl Firmware { let refs = ComputeRefs { notifier: g.notifier.va + notifier_page::COMPUTE_RECORD as u64, qinfo: g.qinfo.va, - user_stamp: g.notifier.va + notifier_page::COMPUTE_STAMP as u64, + user_stamp: g.service_stamp().va(), fw_stamp: g.fw_stamp.va, work: s.work.va, work_gva: s.work.lower_gva.ok_or(EINVAL)?, @@ -3544,7 +3538,7 @@ impl Firmware { || self.engine.flights.iter().any(|fl| fl.initbm); let bar_type = cross_engine_barrier_type(producer_initbm, false); let bar = encode::barrier( - self.graph.render.fs_service_stamp_va(), + self.graph.render.fs_service_stamp().va(), wait_fs.stamp, 0x71, target, @@ -3568,7 +3562,7 @@ impl Firmware { // Compute on another pipe may read what the producer wrote: wait for the // producer pipe's service stamp, not its FINALIZE fw_stamp. let bar = encode::barrier( - self.graph.compute[p_idx].service_stamp_va(), + self.graph.compute[p_idx].service_stamp().va(), wait_c.stamp, work::compute::EVENTS[p_idx], target, @@ -3917,10 +3911,10 @@ impl Firmware { for p_idx in 0..sizes::COMPUTE_PIPES { let off = p_idx * work::barrier::SIZE; // A render reads what compute wrote: wait for the producer pipe's service stamp, not - // its FINALIZE fw_stamp (see `ComputeGraph::service_stamp_va`). + // its FINALIZE fw_stamp (see `ComputeGraph::service_stamp`). if let Some(wait_c) = plan.ta_compute_wait[p_idx] { let cbar = encode::barrier( - self.graph.compute[p_idx].service_stamp_va(), + self.graph.compute[p_idx].service_stamp().va(), wait_c, work::compute::EVENTS[p_idx], target, @@ -3936,7 +3930,7 @@ impl Firmware { } if let Some(wait_c) = plan.fs_compute_wait[p_idx] { let fcbar = encode::barrier( - self.graph.compute[p_idx].service_stamp_va(), + self.graph.compute[p_idx].service_stamp().va(), wait_c, work::compute::EVENTS[p_idx], target, diff --git a/drivers/gpu/drm/asahi/g16/graph.rs b/drivers/gpu/drm/asahi/g16/graph.rs index 7acf3e3d396c9..1317645063212 100644 --- a/drivers/gpu/drm/asahi/g16/graph.rs +++ b/drivers/gpu/drm/asahi/g16/graph.rs @@ -110,6 +110,29 @@ pub(crate) fn alloc_work( }) } +/// A 32-bit stamp cell the firmware stores into: an object and a byte offset in it. +#[derive(Clone, Copy)] +pub(crate) struct StampCell<'a> { + obj: &'a FwObject, + off: usize, +} + +impl<'a> StampCell<'a> { + fn new(obj: &'a FwObject, off: usize) -> Self { + Self { obj, off } + } + + /// The cell's firmware VA, as work items and barriers name it. + pub(crate) fn va(&self) -> u64 { + self.obj.va + self.off as u64 + } + + /// Reads the cell. + pub(crate) fn read(&self) -> Result { + self.obj.r32(self.off) + } +} + pub(crate) struct ComputeGraph { pub(crate) sched_ctx: Arc, /// Whole 0x1000 page; compute's record is +0x400, service stamps +0x640/+0x648. @@ -264,13 +287,14 @@ impl ComputeGraph { self.threshold.w64(0, 1) } - /// The pipe's terminal service-stamp cell. The firmware stores a work item's stamp here after - /// it has finished servicing the item's record, later than [`Self::fw_stamp`], which it stores - /// at FINALIZE. Work on another firmware queue that reads what this pipe's work wrote waits on - /// this cell: at FINALIZE those writes are not yet visible there (linux#3349). Retirement - /// waits for the same cell. - pub(crate) fn service_stamp_va(&self) -> u64 { - self.notifier.va + notifier_page::COMPUTE_STAMP as u64 + /// The pipe's terminal service-stamp cell. Each compute work item names this cell as the one + /// the firmware stores its stamp into after it has finished servicing the item's record, later + /// than [`Self::fw_stamp`], which it stores at FINALIZE. Retirement reads its completion from + /// this cell, and work on another firmware queue that reads what this pipe wrote waits on it: + /// at FINALIZE those writes are not yet visible there (linux#3349). All three go through this + /// accessor so that they can never name different cells. + pub(crate) fn service_stamp(&self) -> StampCell<'_> { + StampCell::new(&self.notifier, notifier_page::COMPUTE_STAMP) } } @@ -365,12 +389,18 @@ impl RenderGraph { Ok(()) } + /// The TA queue's terminal service-stamp cell, as named by every render's TA work item and + /// read by retirement. + pub(crate) fn ta_service_stamp(&self) -> StampCell<'_> { + StampCell::new(&self.notifier, notifier_page::TA_STAMP) + } + /// The FS queue's terminal service-stamp cell, stored after the firmware has serviced a - /// pass's FS record, later than `fw_stamp[1]` (`FINALIZE`). Work on another firmware queue - /// that reads what a render wrote waits on this cell, as it does for compute - /// ([`ComputeGraph::service_stamp_va`]). Retirement waits for the same cell. - pub(crate) fn fs_service_stamp_va(&self) -> u64 { - self.notifier.va + notifier_page::FS_STAMP as u64 + /// pass's FS record, later than `fw_stamp[1]` (`FINALIZE`). Every render's FS work item names + /// it, retirement reads it, and work on another firmware queue that reads what a render wrote + /// waits on it, as for compute ([`ComputeGraph::service_stamp`]). + pub(crate) fn fs_service_stamp(&self) -> StampCell<'_> { + StampCell::new(&self.notifier, notifier_page::FS_STAMP) } } diff --git a/drivers/gpu/drm/asahi/g16/poll.rs b/drivers/gpu/drm/asahi/g16/poll.rs index dbd1e6a18325d..02df461b3cd3d 100644 --- a/drivers/gpu/drm/asahi/g16/poll.rs +++ b/drivers/gpu/drm/asahi/g16/poll.rs @@ -1283,7 +1283,7 @@ impl Firmware { return Ok(Retirement::Pending); } rmb(); - let stamp = g.notifier.r32(notifier_page::COMPUTE_STAMP)?; + let stamp = g.service_stamp().read()?; full &= stamp_reached(stamp, f.target, tail) && (stamp != f.target || g.notifier.r32(notifier_page::COMPUTE_CONTEXT)? == f.job.vm.slot); @@ -1296,7 +1296,7 @@ impl Firmware { return Ok(Retirement::Pending); } rmb(); - full &= g.notifier.r32(notifier_page::COMPUTE_STAMP)? == f.target + full &= g.service_stamp().read()? == f.target && g.notifier.r32(notifier_page::COMPUTE_CONTEXT)? == f.job.vm.slot; } let count = f.claims.slot_count as usize; @@ -1346,8 +1346,8 @@ impl Firmware { return Ok(Retirement::Pending); } rmb(); - let fs_stamp = g.notifier.r32(notifier_page::FS_STAMP)?; - let ta_stamp = g.notifier.r32(notifier_page::TA_STAMP)?; + let fs_stamp = g.fs_service_stamp().read()?; + let ta_stamp = g.ta_service_stamp().read()?; full &= stamp_reached(fs_stamp, f.fs_target, e.fs_target) && (fs_stamp != f.fs_target || g.notifier @@ -1381,8 +1381,8 @@ impl Firmware { return Ok(Retirement::Pending); } rmb(); - full &= g.notifier.r32(notifier_page::FS_STAMP)? == f.fs_target - && g.notifier.r32(notifier_page::TA_STAMP)? == f.ta_target + full &= g.fs_service_stamp().read()? == f.fs_target + && g.ta_service_stamp().read()? == f.ta_target && g.notifier.r32(notifier::CONTEXT)? == f.job.vm.slot && g.notifier .r32(notifier_page::FS_RECORD + notifier::CONTEXT)? diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py index 19cb607540842..5e4a0b4898a78 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -70,19 +70,34 @@ def item(declaration): assert 'work::compute::EVENTS[p_idx]' in c2ta_slice assert 'work::compute::EVENTS[p_idx]' in c2fs_slice # linux#3349: a render's barriers on a compute pipe wait on that pipe's service stamp, not FINALIZE. -assert 'self.graph.compute[p_idx].service_stamp_va(),' in c2ta_slice, c2ta_slice -assert 'self.graph.compute[p_idx].service_stamp_va(),' in c2fs_slice, c2fs_slice +assert 'self.graph.compute[p_idx].service_stamp().va(),' in c2ta_slice, c2ta_slice +assert 'self.graph.compute[p_idx].service_stamp().va(),' in c2fs_slice, c2fs_slice assert 'fw_stamp' not in c2ta_slice and 'fw_stamp' not in c2fs_slice graph_src = (production.parent / 'graph.rs').read_text() -service_fn = graph_src[graph_src.index('pub(crate) fn service_stamp_va(&self) -> u64 {'):] -service_fn = service_fn[:service_fn.index('\n }\n') + 6] -assert 'self.notifier.va + notifier_page::COMPUTE_STAMP as u64' in service_fn, service_fn +# One accessor per service-stamp cell: the work item names it (where the firmware stores), retirement +# reads it, and cross-engine barriers wait on it. Nothing else may name the cell, so the three can +# never diverge (a barrier on a cell no longer written would hang the queue). +poll_src = (production.parent / 'poll.rs').read_text() +for cell, accessor in (('COMPUTE_STAMP', 'fn service_stamp(&self) -> StampCell'), + ('TA_STAMP', 'fn ta_service_stamp(&self) -> StampCell'), + ('FS_STAMP', 'fn fs_service_stamp(&self) -> StampCell')): + assert graph_src.count('notifier_page::' + cell) == 1, cell + body = graph_src[graph_src.index(accessor):] + body = body[:body.index('\n }\n')] + assert 'notifier_page::' + cell in body, (cell, body) + assert 'notifier_page::' + cell not in source, cell + assert 'notifier_page::' + cell not in poll_src, cell +assert source.count('user_stamp: g.service_stamp().va(),') == 1 +assert source.count('user_stamp: [r.ta_service_stamp().va(), r.fs_service_stamp().va()],') == 2 +assert poll_src.count('g.service_stamp().read()?') == 2 +assert poll_src.count('g.fs_service_stamp().read()?') == 2 +assert poll_src.count('g.ta_service_stamp().read()?') == 2 # Cross-pipe compute->compute barriers wait on the producer pipe's service stamp as well. c2c_slice = prefix_compute_fn[ prefix_compute_fn.index('for (p_idx, wait_opt) in c_waits.iter().enumerate()'): prefix_compute_fn.index('s.barrier.write(off, &bar)?;') ] -assert 'self.graph.compute[p_idx].service_stamp_va(),' in c2c_slice, c2c_slice +assert 'self.graph.compute[p_idx].service_stamp().va(),' in c2c_slice, c2c_slice assert 'fw_stamp.va' not in c2c_slice, c2c_slice assert 'render_bar,' in c2ta_slice and 'BarrierType::Hold' not in c2ta_slice assert 'render_bar,' in c2fs_slice and 'BarrierType::Hold' not in c2fs_slice @@ -92,11 +107,9 @@ def item(declaration): fs2c_bar = prefix_compute_fn[ prefix_compute_fn.index('let fs2c_bar ='):prefix_compute_fn.index('s.barrier.write(0, &bar)?;') ] -assert 'self.graph.render.fs_service_stamp_va(),' in fs2c_bar, fs2c_bar +assert 'self.graph.render.fs_service_stamp().va(),' in fs2c_bar, fs2c_bar assert 'fw_stamp[1].va' not in fs2c_bar, fs2c_bar -render_service_fn = graph_src[graph_src.index('pub(crate) fn fs_service_stamp_va(&self) -> u64 {'):] -render_service_fn = render_service_fn[:render_service_fn.index('\n }\n') + 6] -assert 'self.notifier.va + notifier_page::FS_STAMP as u64' in render_service_fn, render_service_fn + assert 'bar_type,' in fs2c_slice and 'BarrierType::Hold' not in fs2c_slice assert 'let waits_for_timestamps = c.query_access' in can_queue_behind_fn assert 'DRM_ASAHI_FEATURE_RENDER_STAGE_PREFIXES_V2' in params_src diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-resources.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-resources.py index cb84603adc556..c28dfa21c9304 100755 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-resources.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-resources.py @@ -3554,6 +3554,8 @@ def module(text, name): graph_types = '\n'.join( item(graph_source, decl) for decl in ( + "pub(crate) struct StampCell<'a> {", + "impl<'a> StampCell<'a> {", 'pub(crate) struct ComputeGraph {', 'struct QueueSession {', 'impl QueueSession {', diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-stamp-wrap.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-stamp-wrap.py index a06beb782943b..6eb89fdf75a4a 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-stamp-wrap.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-stamp-wrap.py @@ -43,6 +43,12 @@ def function(text, name): mod manager {pub const COUNTER:usize=0x4c;pub const COMPLETED:usize=0x54;} #[derive(Default)]struct CGraph{fw_stamp:Object,qstate:Object,qinfo:Object,notifier:Object} struct RGraph{fw_stamp:[Object;2],qstate:[Object;2],qinfo:[Object;2],notifier:Object} +// Production service-stamp accessors (graph.rs) over the mock objects: retirement reads the cells +// through exactly the accessors that work items and cross-engine barriers name them by. +type FwObject=Object; +__STAMP_CELL__ +impl CGraph{__COMPUTE_SERVICE_STAMP__} +impl RGraph{__TA_SERVICE_STAMP__ __FS_SERVICE_STAMP__} struct Graph{compute:[CGraph;hw::sizes::COMPUTE_PIPES],render:RGraph} struct Vm{slot:u32}struct Job{vm:Vm,resources:Resources} struct Resources{compute:Vec,passes:Vec,pools:Pools} @@ -680,6 +686,19 @@ def function(text, name): if token in ('__RETIRED_FLIGHT__', '__RETIRED_FLIGHT_CLASSES__', '__RETIRED_SNAPSHOT_AT__'): body = body.replace('super::hw::', 'hw::') harness=harness.replace(token, body) +graph_text=(backend/'graph.rs').read_text() +cell_start=graph_text.index('/// A 32-bit stamp cell') +cell_impl=graph_text.index("impl<'a> StampCell<'a> {") +cell_at=graph_text.index('{',cell_impl) +depth,cell_end=1,cell_at+1 +while depth: + depth+=(graph_text[cell_end]=='{')-(graph_text[cell_end]=='}') + cell_end+=1 +harness=(harness + .replace('__STAMP_CELL__',graph_text[cell_start:cell_end]) + .replace('__COMPUTE_SERVICE_STAMP__',function(graph_text,'service_stamp')) + .replace('__TA_SERVICE_STAMP__',function(graph_text,'ta_service_stamp')) + .replace('__FS_SERVICE_STAMP__',function(graph_text,'fs_service_stamp'))) hw_text=(backend/'hw.rs').read_text() def mod_block(text, name): start=text.index('pub(crate) mod '+name+' {')