From 1b3f06b5eda642e7f4be4778b70ed70d25f18dd2 Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Mon, 30 Nov 2026 14:10:56 -0300 Subject: [PATCH 1/4] drm/asahi: g17: install a submission's outputs only once it is queued A G17 SUBMIT stores its aggregate fence in the output sync objects when it creates it, before the loop that queues its commands. Every failure of that loop therefore comes after the outputs changed. Under DRM_ASAHI_FEATURE_SUBMIT_REFUSAL_UNTOUCHED, those failures cannot be refusals (ENOMEM, ENOSPC), and they become EIO. The loop allocates each command's completion state, including the compute timestamp page, its dependency vectors, its packet and its scheduler job. A lack of memory there cost the client its device. Install the outputs after the loop instead: - **Creating the submission** builds the aggregate fence and allocates the cumulative signal's scope (now `asahi_g17_signals_prepare()`), but stores nothing. - **Outputs::install()** stores it in every output (`asahi_g17_signals_commit()`). It cannot fail. - **When it runs:** - after the loop, unless the ioctl was refused before its first command was queued; - otherwise when the outputs are dropped, as before. - **Queued means armed:** a command counts as queued once its scheduler job is armed. The two pushes after that, into room reserved before the first command, now return EIO if they ever fail, so ENOMEM never follows a queued command. A refusal while preparing the first command now leaves the outputs untouched too. This covers every refusal of a one-command submission. A refusal of a later command still returns EIO, because earlier commands of the same ioctl are already queued. Early publication can now complete a command before its outputs carry the fence. They then get a fence that is already signalled. The cumulative scope is still taken over the anchor's fence before the loop, under the queue's lock. G16 keeps `SignalBundle::publish()`, now prepare plus commit, built only with CONFIG_DRM_ASAHI_G16 (G17 no longer calls it). The host test g17-submit-refusal-untouched-tests.py also checks three things: creating the submission stores nothing, the outputs are installed after the loop and gated on queued commands, and post-queue failures are EIO. Three more injected faults are caught. Signed-off-by: Jonathan Goyvaerts --- drivers/gpu/drm/asahi/g17/fence.rs | 44 +++++++++++++++---- drivers/gpu/drm/asahi/g17/queue/mod.rs | 16 ++++++- drivers/gpu/drm/asahi/g17/sync_output.c | 36 ++++++++++----- drivers/gpu/drm/asahi/g17/sync_output.h | 3 +- drivers/gpu/drm/asahi/g17/sync_output.rs | 25 +++++++++-- .../g17-submit-refusal-untouched-tests.py | 34 ++++++++++++-- tools/asahi/run-host-tests.py | 2 +- 7 files changed, 131 insertions(+), 29 deletions(-) diff --git a/drivers/gpu/drm/asahi/g17/fence.rs b/drivers/gpu/drm/asahi/g17/fence.rs index fa837f01003a1..100f513169989 100644 --- a/drivers/gpu/drm/asahi/g17/fence.rs +++ b/drivers/gpu/drm/asahi/g17/fence.rs @@ -734,6 +734,8 @@ pub(crate) struct Outputs { chunks: KVec>, result: Result, cumulative: Option, + /// The submission's fence is in the outputs ([`Self::install`]). + installed: bool, } impl Outputs { pub(crate) fn new( @@ -768,11 +770,29 @@ impl Outputs { chunks: KVec::new(), result: Err(ECANCELED), cumulative, + installed: false, }) } /// Whether the outputs carry this submission's fence already. pub(crate) fn published(&self) -> bool { - self.submission.is_some() + self.installed + } + /// Stores the submission's fence, created by [`Self::publish`] or + /// [`Self::publish_with_status`], in every output. Cannot fail. + pub(crate) fn install(&mut self) { + let Some(submission) = &self.submission else { + return; + }; + if self.installed { + return; + } + self.installed = true; + if let Some(bundle) = &mut self.cumulative { + bundle.commit(); + self.syncs.truncate(self.input_count); + } else { + install(self.syncs.drain(self.input_count..), &submission.fence()); + } } pub(crate) fn inputs(&self) -> &[SyncItem] { &self.syncs[..self.input_count] @@ -810,11 +830,9 @@ impl Outputs { fence.compute_only = compute_only; let submission = Aggregate(fence.into()); self.submission = Some(submission.clone()); + // Outputs get the fence only at `install()`, once the commands are queued. if let Some(bundle) = &mut self.cumulative { - bundle.publish(&submission.fence(), compute_only)?; - self.syncs.truncate(self.input_count); - } else { - install(self.syncs.drain(self.input_count..), &submission.fence()); + bundle.prepare(&submission.fence(), compute_only)?; } Ok(submission) } @@ -828,9 +846,19 @@ impl Drop for Outputs { for chunk in &self.chunks { chunk.finish_enqueue(self.result); } - if let Some(submission) = self.submission.take() { - if let Some(bundle) = &mut self.cumulative { - bundle.fail(&submission.fence()); + if self.submission.is_some() { + if !self.installed && !untouched_refusal(false, &self.result) { + self.install(); + } + let Some(submission) = self.submission.take() else { + return; + }; + // A prepared cumulative signal that could not be committed falls back to the + // submission's own fence; this does nothing once committed. + if self.installed { + if let Some(bundle) = &mut self.cumulative { + bundle.fail(&submission.fence()); + } } submission.finish_enqueue(self.result); return; diff --git a/drivers/gpu/drm/asahi/g17/queue/mod.rs b/drivers/gpu/drm/asahi/g17/queue/mod.rs index 934e223e807e8..9a0fbf7a7aad5 100644 --- a/drivers/gpu/drm/asahi/g17/queue/mod.rs +++ b/drivers/gpu/drm/asahi/g17/queue/mod.rs @@ -453,10 +453,14 @@ impl Queue { .enqueue(packet, dependencies, early, publication)?; fences.timestamp_waits = inherited_timestamp_waits; self.sequence[index] = order.sequence; + // The command is queued: from here on no failure may read as a refusal (the room was + // reserved before the first command, so these cannot fail). if fences.publishes() { - self.publishers[index].push_within_capacity(order.sequence, fences.clone())?; + self.publishers[index] + .push_within_capacity(order.sequence, fences.clone()) + .map_err(|_| EIO)?; } - self.frontiers[index].push_within_capacity(order.sequence, fences)?; + self.frontiers[index].push_within_capacity(order.sequence, fences).map_err(|_| EIO)?; Ok(()) } /// Finish parsing, validation and VM pinning before entering publication, into the @@ -602,6 +606,8 @@ impl crate::queue::Queue for Queue { } }; let mut scratch = core::mem::take(&mut self.scratch); + // Commands queued so far; until the first is, nothing of the submission is visible. + let mut enqueued = 0usize; let result = (|| { if !self.backend.supports_submission() { return Err(ENOTSUPP); @@ -709,9 +715,15 @@ impl crate::queue::Queue for Queue { outputs.inputs(), destinations, )?; + enqueued += 1; } Ok(()) })(); + // Queued commands need their outputs to carry the submission's fence. A refusal before + // the first one was queued leaves them untouched. + if !super::fence::untouched_refusal(enqueued != 0, &result) { + outputs.install(); + } // What an error left unsubmitted is released here, as before the scratch was kept. scratch.pending.clear(); scratch.guards.clear(); diff --git a/drivers/gpu/drm/asahi/g17/sync_output.c b/drivers/gpu/drm/asahi/g17/sync_output.c index 191ebdfc04cdb..48fc958e12dd3 100644 --- a/drivers/gpu/drm/asahi/g17/sync_output.c +++ b/drivers/gpu/drm/asahi/g17/sync_output.c @@ -16,6 +16,8 @@ struct asahi_g17_signal_bundle { size_t count; size_t anchor; bool published; + /* The anchor's scope, prepared and not committed yet. */ + struct dma_fence *scope; struct asahi_g17_signal_target targets[]; }; @@ -25,6 +27,7 @@ void asahi_g17_signals_free(struct asahi_g17_signal_bundle *bundle) if (!bundle) return; + dma_fence_put(bundle->scope); for (i = 0; i < bundle->count; ++i) { struct asahi_g17_signal_target *target = &bundle->targets[i]; if (target->chain) @@ -97,21 +100,35 @@ static void asahi_g17_signal_install(struct asahi_g17_signal_target *target, } } -int asahi_g17_signals_publish(struct asahi_g17_signal_bundle *bundle, +/* + * Allocate the anchor's scope over its current fence and @submitted. Nothing is + * stored in a sync object until asahi_g17_signals_commit(), so a failure here, or a + * bundle freed after it, leaves every output as it was. + */ +int asahi_g17_signals_prepare(struct asahi_g17_signal_bundle *bundle, struct dma_fence *submitted, bool compute_only) { - struct dma_fence *previous, *scope; - size_t i; + struct dma_fence *previous; - if (bundle->published) + if (bundle->published || bundle->scope) return -EINVAL; previous = drm_syncobj_fence_get(bundle->targets[bundle->anchor].syncobj); - scope = asahi_g17_scope_create(previous, submitted, - bundle->targets[bundle->anchor].point, - compute_only); + bundle->scope = asahi_g17_scope_create(previous, submitted, + bundle->targets[bundle->anchor].point, + compute_only); dma_fence_put(previous); - if (!scope) - return -ENOMEM; + return bundle->scope ? 0 : -ENOMEM; +} + +/* Install the prepared scope in every output. Cannot fail. */ +void asahi_g17_signals_commit(struct asahi_g17_signal_bundle *bundle) +{ + struct dma_fence *previous, *scope = bundle->scope; + size_t i; + + if (bundle->published || !scope) + return; + bundle->scope = NULL; /* Only exported completion includes earlier work. GPU execution gets no new wait. */ asahi_g17_signal_install(&bundle->targets[bundle->anchor], scope); previous = drm_syncobj_fence_get(bundle->targets[bundle->anchor].syncobj); @@ -122,7 +139,6 @@ int asahi_g17_signals_publish(struct asahi_g17_signal_bundle *bundle, asahi_g17_signal_install(&bundle->targets[i], scope); bundle->published = true; dma_fence_put(scope); - return 0; } /* Allocation or validation failed before enqueue: install an error promise without allocating. */ diff --git a/drivers/gpu/drm/asahi/g17/sync_output.h b/drivers/gpu/drm/asahi/g17/sync_output.h index cee1146372fc6..1264ebd57aa19 100644 --- a/drivers/gpu/drm/asahi/g17/sync_output.h +++ b/drivers/gpu/drm/asahi/g17/sync_output.h @@ -16,8 +16,9 @@ struct asahi_g17_signal_bundle * asahi_g17_signals_new(const struct asahi_g17_signal_spec *specs, size_t count, size_t anchor, int *error); void asahi_g17_signals_free(struct asahi_g17_signal_bundle *bundle); -int asahi_g17_signals_publish(struct asahi_g17_signal_bundle *bundle, +int asahi_g17_signals_prepare(struct asahi_g17_signal_bundle *bundle, struct dma_fence *submitted, bool compute_only); +void asahi_g17_signals_commit(struct asahi_g17_signal_bundle *bundle); void asahi_g17_signals_fail(struct asahi_g17_signal_bundle *bundle, struct dma_fence *failure); #endif diff --git a/drivers/gpu/drm/asahi/g17/sync_output.rs b/drivers/gpu/drm/asahi/g17/sync_output.rs index 5bbc3467a4000..f12126d217274 100644 --- a/drivers/gpu/drm/asahi/g17/sync_output.rs +++ b/drivers/gpu/drm/asahi/g17/sync_output.rs @@ -12,8 +12,9 @@ unsafe extern "C" { fn asahi_g17_signals_new(syncs: *const SignalSpec, count: usize, anchor: usize, error: *mut i32) -> *mut core::ffi::c_void; fn asahi_g17_signals_free(bundle: *mut core::ffi::c_void); - fn asahi_g17_signals_publish(bundle: *mut core::ffi::c_void, + fn asahi_g17_signals_prepare(bundle: *mut core::ffi::c_void, current: *mut bindings::dma_fence, compute_only: bool) -> i32; + fn asahi_g17_signals_commit(bundle: *mut core::ffi::c_void); fn asahi_g17_signals_fail(bundle: *mut core::ffi::c_void, failure: *mut bindings::dma_fence); } @@ -48,13 +49,29 @@ impl SignalBundle { Ok(Self(raw)) } - pub(crate) fn publish(&mut self, current: &Fence, compute_only: bool) -> Result { + /// Allocates what publishing `current` needs, storing nothing in an output yet. + pub(crate) fn prepare(&mut self, current: &Fence, compute_only: bool) -> Result { // SAFETY: The bundle and current fence are owned for this call; C takes - // its own references on publication and reports failure before any store. - let error = unsafe { asahi_g17_signals_publish(self.0, current.raw(), compute_only) }; + // its own references and reports failure before any store. + let error = unsafe { asahi_g17_signals_prepare(self.0, current.raw(), compute_only) }; if error == 0 { Ok(()) } else { Err(Error::from_errno(error)) } } + /// [`Self::prepare`] and [`Self::commit`] at once: fails before any store. G16 publishes + /// this way; G17 commits only once its commands are queued. + #[cfg(CONFIG_DRM_ASAHI_G16)] + pub(crate) fn publish(&mut self, current: &Fence, compute_only: bool) -> Result { + self.prepare(current, compute_only)?; + self.commit(); + Ok(()) + } + + /// Publishes what [`Self::prepare`] allocated in every output. + pub(crate) fn commit(&mut self) { + // SAFETY: The bundle is owned; C stores only what prepare allocated. + unsafe { asahi_g17_signals_commit(self.0) }; + } + pub(crate) fn fail(&mut self, failure: &Fence) { // SAFETY: Live owned arguments; this only consumes uninstalled chain nodes. unsafe { asahi_g17_signals_fail(self.0, failure.raw()) }; diff --git a/tools/asahi/g17-submit-refusal-untouched-tests.py b/tools/asahi/g17-submit-refusal-untouched-tests.py index dfef7c9841390..aa7e920c59d26 100644 --- a/tools/asahi/g17-submit-refusal-untouched-tests.py +++ b/tools/asahi/g17-submit-refusal-untouched-tests.py @@ -12,10 +12,16 @@ - G17's submit reports no allocation_failure on a refusal, and passes its result through submit_result, so a late ENOMEM/ENOSPC is EIO; - drm_asahi_submit::flags stays MBZ; -- only G17 reports DRM_ASAHI_FEATURE_SUBMIT_REFUSAL_UNTOUCHED. +- only G17 reports DRM_ASAHI_FEATURE_SUBMIT_REFUSAL_UNTOUCHED; +- the submission's fence reaches the outputs only after the enqueue loop + (Outputs::install), and is left out only while no command was queued; +- creating the submission stores nothing in an output: the cumulative signal + is prepared there and committed by install; +- a failure after a command was queued is never ENOMEM. --mutation new-installs / drop-installs / no-errno-map / flags-accepted / -not-reported inject each fault and must be caught. +not-reported / install-early / ignore-queued / queued-enomem inject each fault +and must be caught. """ import argparse import sys @@ -47,6 +53,17 @@ def sources(mutation): 'let result = super::fence::submit_result(outputs.published(), result);', '', 1) elif mutation == 'flags-accepted': files['file.rs'] = files['file.rs'].replace('if data.flags != 0 || data.pad != 0 {', 'if data.pad != 0 {', 1) + elif mutation == 'install-early': + files['g17/fence.rs'] = files['g17/fence.rs'].replace( + 'bundle.prepare(&submission.fence(), compute_only)?;\n }\n Ok(submission)', + 'bundle.prepare(&submission.fence(), compute_only)?;\n }\n self.install();\n Ok(submission)', 1) + elif mutation == 'ignore-queued': + files['g17/queue/mod.rs'] = files['g17/queue/mod.rs'].replace( + 'untouched_refusal(enqueued != 0, &result)', 'untouched_refusal(false, &result)', 1) + elif mutation == 'queued-enomem': + files['g17/queue/mod.rs'] = files['g17/queue/mod.rs'].replace( + '.push_within_capacity(order.sequence, fences).map_err(|_| EIO)?;', + '.push_within_capacity(order.sequence, fences)?;', 1) elif mutation == 'not-reported': files['g17/mod.rs'] = files['g17/mod.rs'].replace( '| uapi::DRM_ASAHI_FEATURE_SUBMIT_REFUSAL_UNTOUCHED as u64\n', '', 1) @@ -74,13 +91,24 @@ def check(files): failures.append('FAIL line 5: drm_asahi_submit::flags is not MBZ') if 'DRM_ASAHI_FEATURE_SUBMIT_REFUSAL_UNTOUCHED' not in item(files['g17/mod.rs'], 'fn get_params('): failures.append('FAIL line 6: G17 does not report the feature') + publish = '\n'.join(l.split('//')[0] for l in item(fence, 'fn publish_source(').split('\n')) + if 'install(' in publish or 'commit(' in publish: + failures.append('FAIL line 7: creating the submission stores it in the outputs') + loop_end = submit.find('enqueued += 1;') + gate = submit.find('if !super::fence::untouched_refusal(enqueued != 0, &result) {\n outputs.install();') + if loop_end < 0 or gate < loop_end: + failures.append('FAIL line 8: the outputs are not installed after the loop, gated on queued commands') + enqueue = item(queue, 'fn enqueue(') + if enqueue.count('.map_err(|_| EIO)?;') < 2: + failures.append('FAIL line 9: a failure after a command was queued can read as ENOMEM') return failures def main(): parser = argparse.ArgumentParser() parser.add_argument('--mutation', choices=['new-installs', 'drop-installs', 'no-errno-map', - 'flags-accepted', 'not-reported']) + 'flags-accepted', 'not-reported', 'install-early', + 'ignore-queued', 'queued-enomem']) args = parser.parse_args() failures = check(sources(args.mutation)) for f in failures: diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 9d7594f089d6d..a09c416e7fe90 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -447,7 +447,7 @@ def mutations(flag, names, base, expect=KILL): 'g17-shared-pool-tests.py': [([], PASS)], 'g17-submit-refusal-untouched-tests.py': [([], PASS)] + mutations( '--mutation', ['new-installs', 'drop-installs', 'no-errno-map', 'flags-accepted', - 'not-reported'], []), + 'not-reported', 'install-early', 'ignore-queued', 'queued-enomem'], []), 'g17-t6041-initdata-tests.py': [([], PASS)], 'g17-uninstalled-cleanup-tests.py': [([], PASS)], 'g17-unpublished-tests.py': [([], PASS)], From ffcbd9447a7a6c5567d75c3bbf89109e788f0929 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 30 Nov 2026 16:15:47 -0500 Subject: [PATCH 2/4] drm/asahi: arm cumulative scope callbacks only at commit Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g17/sync_output.c | 1 + drivers/gpu/drm/asahi/g17/sync_scope.c | 11 +++++++++-- drivers/gpu/drm/asahi/g17/sync_scope.h | 1 + tools/asahi/g17-submit-refusal-untouched-tests.py | 11 ++++++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/asahi/g17/sync_output.c b/drivers/gpu/drm/asahi/g17/sync_output.c index 48fc958e12dd3..4e74adbab367d 100644 --- a/drivers/gpu/drm/asahi/g17/sync_output.c +++ b/drivers/gpu/drm/asahi/g17/sync_output.c @@ -129,6 +129,7 @@ void asahi_g17_signals_commit(struct asahi_g17_signal_bundle *bundle) if (bundle->published || !scope) return; bundle->scope = NULL; + asahi_g17_scope_arm(scope); /* Only exported completion includes earlier work. GPU execution gets no new wait. */ asahi_g17_signal_install(&bundle->targets[bundle->anchor], scope); previous = drm_syncobj_fence_get(bundle->targets[bundle->anchor].syncobj); diff --git a/drivers/gpu/drm/asahi/g17/sync_scope.c b/drivers/gpu/drm/asahi/g17/sync_scope.c index bf2f6282e642b..a7ed11d3a1be6 100644 --- a/drivers/gpu/drm/asahi/g17/sync_scope.c +++ b/drivers/gpu/drm/asahi/g17/sync_scope.c @@ -331,7 +331,6 @@ struct dma_fence *asahi_g17_scope_create(struct dma_fence *previous, struct dma_fence *parent = NULL; struct asahi_g17_scope *scope, *prior = NULL; u64 context; - unsigned int i; if (asahi_g17_is_scope(contained)) { prior = to_scope(contained); @@ -367,6 +366,15 @@ struct dma_fence *asahi_g17_scope_create(struct dma_fence *previous, /* The constructor guard prevents completion while callbacks are being installed. */ atomic_set(&scope->pending, 3); scope->base.error = 1; + return &scope->base; +} + +/* The bundle owns the only reference until commit. */ +void asahi_g17_scope_arm(struct dma_fence *fence) +{ + struct asahi_g17_scope *scope = to_scope(fence); + unsigned int i; + for (i = 0; i < ARRAY_SIZE(scope->children); ++i) { struct dma_fence *child = scope->children[i]; int err; @@ -389,5 +397,4 @@ struct dma_fence *asahi_g17_scope_create(struct dma_fence *previous, } } scope_arrived(scope, 0); - return &scope->base; } diff --git a/drivers/gpu/drm/asahi/g17/sync_scope.h b/drivers/gpu/drm/asahi/g17/sync_scope.h index 25b9acb8d7148..a442af0d25a22 100644 --- a/drivers/gpu/drm/asahi/g17/sync_scope.h +++ b/drivers/gpu/drm/asahi/g17/sync_scope.h @@ -15,6 +15,7 @@ int asahi_g17_completion_fence_status(struct dma_fence *fence); struct dma_fence *asahi_g17_scope_create(struct dma_fence *previous, struct dma_fence *submitted, u64 point, bool compute_only); +void asahi_g17_scope_arm(struct dma_fence *scope); void asahi_g17_scope_bind(struct dma_fence *scope, struct dma_fence *root); bool asahi_g17_is_scope(struct dma_fence *fence); /* Returns owned child references, or zero once the scope is signalled. */ diff --git a/tools/asahi/g17-submit-refusal-untouched-tests.py b/tools/asahi/g17-submit-refusal-untouched-tests.py index 706505cc2cd6e..2d5e33800a4ed 100644 --- a/tools/asahi/g17-submit-refusal-untouched-tests.py +++ b/tools/asahi/g17-submit-refusal-untouched-tests.py @@ -41,7 +41,7 @@ def item(source, signature): def sources(mutation): - files = {n: (ASAHI / n).read_text() for n in ('g17/fence.rs', 'g17/queue/mod.rs', 'file.rs', 'g17/mod.rs')} + files = {n: (ASAHI / n).read_text() for n in ('g17/fence.rs', 'g17/queue/mod.rs', 'file.rs', 'g17/mod.rs', 'g17/sync_scope.c', 'g17/sync_output.c')} if mutation == 'new-installs': files['g17/fence.rs'] = files['g17/fence.rs'].replace( 'if untouched_refusal(false, &Err(error)) {', 'if false {', 1) @@ -94,6 +94,15 @@ def check(files): failures.append('FAIL: cumulative allocation failure publishes the private aggregate') if 'if super::fence::untouched_refusal(outputs.published(), &result)' not in submit: failures.append('FAIL: refusal trace exposes a private fence') + scope = files['g17/sync_scope.c'] + create = item(scope, 'struct dma_fence *asahi_g17_scope_create(') + signals = files['g17/sync_output.c'] + commit = item(signals, 'void asahi_g17_signals_commit(') + free = item(signals, 'void asahi_g17_signals_free(') + if ('dma_fence_add_callback' in create or 'asahi_g17_scope_arm(' in create + or not 0 <= commit.find('asahi_g17_scope_arm(scope)') < commit.find('asahi_g17_signal_install') + or 'dma_fence_put(bundle->scope)' not in free): + failures.append('FAIL: an abandoned scope keeps callback or child references') ioctl = item(files['file.rs'], 'pub(crate) fn submit(\n device: &AsahiDrmDevice,') if 'if data.flags != 0 || data.pad != 0 {' not in ioctl: failures.append('FAIL line 5: drm_asahi_submit::flags is not MBZ') From 6d560c76c23cab97598fcabc5668de368a13d50e Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 30 Nov 2026 16:57:37 -0500 Subject: [PATCH 3/4] drm/asahi: trace output installation after enqueue A first-command refusal leaves the prepared aggregate private. Emit the install event when the output syncobjs have actually been updated so a refused ioctl cannot report a transient installation. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g17/queue/mod.rs | 22 ++++++++++--------- .../g17-submit-refusal-untouched-tests.py | 7 ++++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/asahi/g17/queue/mod.rs b/drivers/gpu/drm/asahi/g17/queue/mod.rs index 3cc760e1268ea..acc4dbb8e79fe 100644 --- a/drivers/gpu/drm/asahi/g17/queue/mod.rs +++ b/drivers/gpu/drm/asahi/g17/queue/mod.rs @@ -692,16 +692,6 @@ impl crate::queue::Queue for Queue { && !self.has_pending_publication(&pending[0].1); outputs.publish(self.context.clone(), firmware_source, compute_only)? }; - let output_fence = aggregate.fence(); - super::trace::submit( - 1, - id, - self.context.id(), - input_count, - output_count, - 0, - Some(&output_fence), - ); let mut work_states = work_states.into_iter(); for (command, order, destinations) in pending.drain_all() { let guard = guards.next().ok_or(EIO)?; @@ -723,6 +713,18 @@ impl crate::queue::Queue for Queue { // the first one was queued leaves them untouched. if !super::fence::untouched_refusal(enqueued != 0, &result) { outputs.install(); + if outputs.published() { + let output_fence = outputs.output_fence(); + super::trace::submit( + 1, + id, + self.context.id(), + input_count, + output_count, + 0, + output_fence.as_ref(), + ); + } } // What an error left unsubmitted is released here, as before the scratch was kept. scratch.pending.clear(); diff --git a/tools/asahi/g17-submit-refusal-untouched-tests.py b/tools/asahi/g17-submit-refusal-untouched-tests.py index 2d5e33800a4ed..d6b8f8deca47c 100644 --- a/tools/asahi/g17-submit-refusal-untouched-tests.py +++ b/tools/asahi/g17-submit-refusal-untouched-tests.py @@ -24,6 +24,7 @@ and must be caught. """ import argparse +import re import sys from pathlib import Path @@ -115,6 +116,12 @@ def check(files): gate = submit.find('if !super::fence::untouched_refusal(enqueued != 0, &result) {\n outputs.install();') if loop_end < 0 or gate < loop_end: failures.append('FAIL line 8: the outputs are not installed after the loop, gated on queued commands') + install_trace = re.compile(r'super::trace::submit\(\s*1,') + trace_sites = list(install_trace.finditer(submit)) + published = 'if outputs.published() {' + if (len(trace_sites) != 1 or gate < 0 or published not in submit[gate:] + or not install_trace.search(item(submit[gate:], published))): + failures.append('FAIL: the installation trace must follow publication') enqueue = item(queue, 'fn enqueue(') if enqueue.count('.map_err(|_| EIO)?;') < 2: failures.append('FAIL line 9: a failure after a command was queued can read as ENOMEM') From b6ad82398efd66fcfb99cdd6736876970a25c22c Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Sat, 5 Dec 2026 04:03:16 -0300 Subject: [PATCH 4/4] drm/asahi: g17: publish the prior-scope test's bundles as G17 does The KUnit test cumulative_scope_skips_signaled_healthy_prior_but_retains_failed_prior, which came with main's 6b5d9264a7a5, publishes its signal bundles with SignalBundle::publish(). On this branch that is G16's one-call form and exists only with CONFIG_DRM_ASAHI_G16, so a KUnit build without G16 (the m4 kernel's configuration) fails to compile the test. Prepare and commit each bundle instead, as G17's Outputs::install() does; the test checks the same scopes. Signed-off-by: Jonathan Goyvaerts --- drivers/gpu/drm/asahi/g17/fence.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/asahi/g17/fence.rs b/drivers/gpu/drm/asahi/g17/fence.rs index 3fa300952e0d4..ce39b39c0d390 100644 --- a/drivers/gpu/drm/asahi/g17/fence.rs +++ b/drivers/gpu/drm/asahi/g17/fence.rs @@ -1073,7 +1073,8 @@ mod tests { let s1 = independent(&contexts)?; let items1 = [cumulative_item(anchor.clone(), 1), binary_item(out.clone())]; let mut b1 = super::super::sync_output::SignalBundle::new(&items1, 0)?; - b1.publish(&Fence::from_fence(&s1), true)?; + b1.prepare(&Fence::from_fence(&s1), true)?; + b1.commit(); let scope1 = out.fence_get().unwrap(); // SAFETY: `scope1` owns a live dma_fence reference. assert!(unsafe { asahi_g17_is_scope(scope1.raw()) }); @@ -1087,7 +1088,8 @@ mod tests { let s2 = independent(&contexts)?; let items2 = [cumulative_item(anchor.clone(), 2), binary_item(out.clone())]; let mut b2 = super::super::sync_output::SignalBundle::new(&items2, 0)?; - b2.publish(&Fence::from_fence(&s2), true)?; + b2.prepare(&Fence::from_fence(&s2), true)?; + b2.commit(); let scope2 = out.fence_get().unwrap(); // SAFETY: `scope2` owns a live dma_fence reference. assert!(unsafe { asahi_g17_is_scope(scope2.raw()) }); @@ -1111,7 +1113,8 @@ mod tests { let s3 = independent(&contexts)?; let items3 = [cumulative_item(anchor.clone(), 3), binary_item(out.clone())]; let mut b3 = super::super::sync_output::SignalBundle::new(&items3, 0)?; - b3.publish(&Fence::from_fence(&s3), true)?; + b3.prepare(&Fence::from_fence(&s3), true)?; + b3.commit(); let scope3 = out.fence_get().unwrap(); // SAFETY: `scope3` owns a live dma_fence reference. assert!(unsafe { asahi_g17_is_scope(scope3.raw()) });