Repository navigation
drm/asahi: g17: bound submit syncs, install repeated timeline outputs once, return closed queues' identities at close - #3200
DjDeveloperr wants to merge 10 commits into
Conversation
A SUBMIT names its input and output syncs by count and pointer, and the ioctl parses every one of them before the queue sees the submission: each becomes a parsed record holding a syncobj and fence reference, and each timeline output a chain node its syncobj keeps once installed. G17 put no bound on their number. G15 and G16 refuse more than 4096 in total, but only in their queues, after parsing. Move that bound to file.rs as MAX_SYNCS_PER_SUBMISSION, which G15 and G16 now name, and give the GPU trait a max_syncs() admission bound that the ioctl checks next to max_cmdbuf_size(), before anything is copied or allocated. G17 returns the shared bound, so userspace that submits on G15 and G16 submits the same way on G17. Other generations keep their current behaviour. Signed-off-by: Dj <[email protected]>
Every output of a submission receives the same fence. Installing a timeline point, drm_syncobj_add_point() walks the syncobj's chain for garbage collection, one node per step while the fence it holds is unsignalled, and each installation adds a node. N outputs that name one timeline syncobj therefore cost N(N+1)/2 chain steps under the queue lock, and keep N chain nodes on the syncobj. G17 installs its outputs both when it accepts a submission and when it refuses one after resolving them, so an empty command stream is enough. Such submissions are not only malformed ones: the Vulkan runtime merges a signal-only batch into the batch before it, so one submission can signal a timeline at two rising points. Merge those outputs before any chain node is allocated: keep the last output of each timeline syncobj, at the highest of its points. Waits are unchanged: dma_fence_chain_find_seqno() resolves any of the merged points to the one node, whose fence is the submission's, and the syncobj's last submitted point is the same. Binary outputs are left as they are, and the cumulative anchor never merges, so an output aliasing it is still refused. The merge sorts the outputs that can merge, and allocates only when a submission has two or more of them. KUnit: asahi_submit_outputs. Signed-off-by: Dj <[email protected]>
A queue's context holds an execution identity, a QoS ID and, on some variants, a render identity, all from small device-wide pools. If the firmware saw the context, closing the queue arms a scheduler release, and the identities return when the firmware has consumed it. If it never saw the context, teardown::Pending::close() keeps nothing, and the identities return only with the context's last reference. That reference can outlive the queue by as long as userspace likes. When a client exits, its scheduler entities cancel the jobs still waiting for an input fence, but drm_sched frees such a job only once every one of its dependencies has signalled (drm_sched_entity_kill_jobs_work()), and the job holds the queue's backend and so its context. Meanwhile the queue's admission slot and its process's queue share are returned at close. Each exiting client with such a job then leaves an execution identity in use that no open queue accounts for. On M5, where every queue has its own, enough of them leave a new queue waiting for contexts that are not closing, and it fails with ENOSPC. Once both schedulers are torn down nothing of the queue can be published any more, so the firmware can never see that context: return its execution identity, QoS ID and unused render identity at close, next to the queue's admission. The cancelled jobs keep only memory, and still signal their outputs after their inputs, as drm_sched requires. QosLease now gives its ID back once, early or on drop. KUnit: asahi_g17_qos_capacity (an_id_given_back_early_is_given_back_once). Signed-off-by: Dj <[email protected]>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Verdict at Blockers: none At Checked:
Evidence
|
|
Update, J773g (M4 Mac mini, G16G) at How it was run: two guarded one-shots on the default cmdline, the same day on the same Mac.
CTS:
All four fails are different cases from the same
None of them fails on its own: all four ran 25 times each on the stock kernel, 100/100 pass, with no kernel lines. I read them as the same flaky family on both arms, not something this PR adds. I didn't repeat them on the candidate kernel. Other checks: Not run: the Both boots returned to the stock kernel, and the kits were removed from the Mac. Earlier run, at J773g (M4 Mac mini, G16G) at How it was run: two guarded one-shots on the default cmdline.
CTS:
Both boots lost the device on the same early case,
So these faults come from the base, the cross-instance external-semaphore tests, as in #3201. Whether this PR makes them escalate can't be told from one run per arm. Other checks:
Not yet: the same subset on both kernels with one worker and without the |
…d the sync bound Two host tests compile driver files against stand-ins that lacked what this branch's earlier commits use. g17-admission-order-tests.py builds release_queue(), which now calls Context::release_unpublished(); its stand-in Context gets it as a no-op, since the fixture models slot holds, not identities. test-command-stream.py builds g16/command.rs, whose MAX_SYNCS now names file::MAX_SYNCS_PER_SUBMISSION; its stand-in file module gets the constant. No runtime code changes. Signed-off-by: DjDeveloperr <[email protected]>
There was a problem hiding this comment.
Verdict: FINISH, then merge at ccdf52ab
Blockers:
- Merge conflict (
CONFLICTING) againstmain; rebase onto currentmainand re-run CI (14 checks were cancelled atccdf52ab).
Checked:
- Verified mergeability (
CONFLICTING) and existingJ714sM5 Pro A/B PASS row in the PR comments. - Deferred final diff approval until the conflict against
mainis resolved and CI finishes green.
Evidence
- Head
ccdf52abvsmain:CONFLICTING; CI 5 passed, 14 cancelled.
Forward-merge main. Main made release_queue() close the context only once (is_closed()/note_closed(), as Firmware::close_failed_owners may have closed it already); this branch returns an unpublished context's identities after the close unless teardown retained a scheduler. backend.rs keeps main's single close and takes "retained" from it, false when the queue was closed earlier: release_unpublished() itself does nothing for a published context, which every context close_failed_owners closes is. The admission-order test stand-in keeps the no-op release_unpublished() next to main's note_closed/is_closed. Signed-off-by: Ryan Murray <[email protected]>
There was a problem hiding this comment.
Verdict: MERGE at 13b8b42d9b67
Blockers: None (wait for queued CI to finish green).
Checked:
- Forward merge
13b8b42d9b67ofmain(MERGEABLE):g17/runtime/backend.rspreservesmain's!self.context.is_closed()single-close guard and callsself.context.release_unpublished()whenever!retained(teardown.close()returnsOk(true)if tracked or published,Ok(false)otherwise). - Full audit of all three fixes across
file.rs,gpu.rs,g15/command.rs,g16/command.rs,g17/{context,mod,teardown,runtime/backend}.rs, and host/KUnit tests:MAX_SYNCS_PER_SUBMISSION(4096) viaGpu::max_syncs()checked inFile::submit()before copying or allocating sync arrays (in_sync_count as usize + out_sync_count as usizecannot overflow 64-bitusize).SyncItem::coalesce_outputs()/coalesce_timeline_outputs(): excludes the cumulativeanchorso aliasing outputs stay refused, keeps the last timeline output per syncobj raised tomaxpoint, accurately shiftsanchorby removed indices< anchor, and drops merged entries inO(N)beforeSignalBundle::new()or chain node allocation.Context::release_unpublished(): guarded byif self.is_published() { return; }and backed by idempotentrelease_execution(),QosLease::give_back()(returned.swap(true, Ordering::AcqRel)), andrelease_render_id()(take()), returning finite pool IDs at close rather than waiting for cancelleddrm_schedjobs.
- Prior J773g (G16G, 11,834 sync CTS cases) and J714s (M5 Pro G17S, 146,489 sync/fence/semaphore CTS cases) A/B PASS rows stand with unchanged core logic; KUnit (
asahi_submit_outputs,an_id_given_back_early_is_given_back_once) and host tests pass.
Evidence
- Verified
teardown::Pending::close()returnsOk(true)for both existing teardown entries and newly inserted published contexts, andOk(false)only for never-published contexts. - 20 CI checks at
13b8b42d9b67are queued at review time (0failures); approve now so merge can proceed once CI goes green.
|
Forward-merged main into this branch (merge commit 13b8b42, no force push). In g17/runtime/backend.rs, main now closes a context only once ( |
|
code-owner ping <@422957901716652033>: merge train at |
Signed-off-by: Ryan Murray <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
|
I merged current |
|
@DjDeveloperr code-owner notice: the review app approved this head, which only merges |
main (#3021) made the parsed sync list a KVVec, and this branch's coalesce_outputs() still took a KVec, so the forward merge no longer builds (E0308 at file.rs:332). Take &mut KVVec<SyncItem>; the body only uses Vec methods. Signed-off-by: Ryan Murray <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
There was a problem hiding this comment.
Verdict: HOLD at 7121f2eb
Blockers:
- Pending CI at head
7121f2eb: All18build and test checks (apple-build,host-tests, and all16KUnit suites includingKUnit asahi) are currentlyQUEUED(pr-textandreadinesspassed). Code and theKVVecfix are clean; ready to approve as soon as CI completes green.
Checked:
- Commit
ff6b9485(drivers/gpu/drm/asahi/file.rs): updatesSyncItem::coalesce_outputs()from&mut KVec<SyncItem>to&mut KVVec<SyncItem>to matchmain's#3021parsed sync list type (Vec<T, KVmalloc>), preserving.iter(), indexing, and.retain()semantics identically. - Merge
7121f2eboforigin/main(42169a04): clean merge withMERGEABLEstatus; all previously reviewed changes (MAX_SYNCS_PER_SUBMISSION,coalesce_timeline_outputs()+ KUnit tests,QosLease::give_back()/Context::release_unpublished(),g17/runtime/backend.rs!self.context.is_closed()single-close +!retainedrelease,g17/teardown.rsResult<bool>, and host/selftest fixtures) remain intact.
Evidence
- Diff reviewed:
linux#3200at7121f2ebd2f895683ab7de53e9e1ebb7fec8056a(+213/-10, 10 files,MERGEABLEonmain), delta since previously approvedcdbf1626isff6b9485(+1/-1indrivers/gpu/drm/asahi/file.rs) plus clean merge ofmain42169a04. - CI snapshot at review time:
pr-text(SUCCESS),readiness(SUCCESS),18build/KUnit/host-tests jobsQUEUED.
|
CI caught a build break in my forward merge ( |
|
J700 (MacBook Neo, A18 Pro, G17P) at
|
There was a problem hiding this comment.
Verdict: MERGE at 7121f2e once current hosted checks pass.
Checked: The merge-up type fix accepts the same KVVec that main now uses for parsed syncs. It changes the parameter type without changing coalescing order or the close path. The current-head J700 result matches stock on the sync CTS subset and passes duplicate outputs and kill/teardown stress.
What: Three fixes on the G17 submit and queue-close paths. A SUBMIT's syncs get the bound G15 and G16 already apply, checked before they are parsed. Timeline outputs of one submission that name the same syncobj are installed once, at their highest point, instead of once each. A closed queue whose context the firmware never saw returns that context's execution identity, QoS ID and unused render identity at close, instead of when its last cancelled job is freed.
Tested: host build of
drivers/gpu/drm/asahi(asahi.config, LLVM, Rust) at43f3740cfbd05: builds, no new warnings; checkpatch --strict 0 errors, 0 warnings, 0 checks on each commit.b04ba72e86eeonly adds the new API to two host-test stand-ins, with no runtime change. At it,g17-admission-order-tests(25/25, mutations included) and theasahi-m4suite pass locally. Hardware rows on J714s (the M5 combined candidate) and J700 are in progress; they cover the runtime code, whichb04ba72e86eedoesn't touch.Risk: two-way door · every Mac for the output merge (shared
file.rssync parsing); A18 Pro and M5 for the sync bound and the close path.Not yet: J700 (A18 Pro) and J714s (M5 Pro) rows: the Vulkan sync CTS subset against base, both tests below, and a kill/teardown stress. CI.
Details
1.
drm/asahi: g17: bound a submission's syncs before parsing themThe ioctl parses every input and output sync before the queue sees the submission. Each becomes a parsed record holding a syncobj and fence reference, and each timeline output also gets a chain node that its syncobj keeps once the output is installed. G17 had no bound on how many. G15 and G16 refuse more than 4096 in total, but only in their queues, after parsing.
The bound moves to
file.rsasMAX_SYNCS_PER_SUBMISSION, which G15 and G16 now name; their behaviour is unchanged. A newGpu::max_syncs()admission bound is checked next tomax_cmdbuf_size(), before anything is copied or allocated. G17 returns the shared bound, so userspace that submits on G15 and G16 submits the same way on G17. Other generations keep returning no bound.2.
drm/asahi: install a submission's timeline outputs on one syncobj onceEvery output of a submission gets the same fence.
drm_syncobj_add_point()walks the syncobj's chain after each installation, one node per step while the fence it holds is unsignalled, and each installation adds a node. N outputs naming one timeline syncobj therefore cost N(N+1)/2 chain steps under the queue lock. G17 installs outputs both when it accepts a submission and when it refuses one after resolving its outputs, so an empty command stream is enough.This isn't only a malformed-input case. Mesa's Vulkan runtime merges a signal-only batch into the batch before it, so one submission can signal a timeline at two rising points.
The parser now merges them before any chain node is allocated. It keeps the last output of each timeline syncobj, raised to the highest of that syncobj's points. Waits don't change:
dma_fence_chain_find_seqno()resolves any of the merged points to that one node, whose fence is the submission's, and the syncobj's last submitted point is the same. Binary outputs are left alone. The cumulative anchor never merges, so an output aliasing it is still refused. The merge sorts only the outputs that can merge, and allocates only when there are at least two of them.This sits in shared
file.rs, so every generation's submissions get it. It changes nothing a waiter can observe.3.
drm/asahi: g17: return a closed queue's unpublished identities at closeA context holds an execution identity, a QoS ID and, on some variants, a render identity, all from small device-wide pools. If the firmware saw the context, closing the queue arms a scheduler release, and the identities return once the firmware has consumed it. If it never saw the context,
teardown::Pending::close()keeps nothing, and the identities return only with the context's last reference.That reference can outlive the queue for as long as userspace likes. When a client exits, its scheduler entities cancel the jobs still waiting for an input fence. drm_sched frees such a job only after every one of its dependencies has signalled (
drm_sched_entity_kill_jobs_work()), and the job holds the queue's backend, and through it the context. The queue's admission slot and its process's queue share, though, are returned at close. So each exiting client with such a job leaves an execution identity in use that no open queue accounts for. On M5, where every queue has its own, enough of them leave a new queue waiting for contexts that aren't actually closing, until it fails with ENOSPC.Once both schedulers are torn down, nothing of the queue can be published, so the firmware can never see that context.
release_queue()now returns its execution identity (through the shared-context bookkeeping on A18 Pro), its QoS ID and its unused render identity right there, next to the queue's admission. The cancelled jobs keep only memory, and still signal their outputs after their inputs, as drm_sched requires.QosLeasegives its ID back exactly once, either early or on drop. A published context is unchanged: its identities still wait for the consumed release.Merging with #3021
#3021 turns the sync list into a
KVVec. Whichever of the two lands second needscoalesce_outputs()to take the other's vector type; the logic doesn't change.Evidence
./linux-build/build kernel --profile asahi <tree> -- drivers/gpu/drm/asahi/at43f3740cfbd05, exit 0. No warning in a changed line.--strict: 0/0/0 on all three commits.asahi_submit_outputs(distinct syncobjs untouched; rising and falling points keep the last output at the highest point; 4096 repeats of one point leave one output) andasahi_g17_qos_capacity::an_id_given_back_early_is_given_back_once.dup-outputs: raw ioctls with no GPU work. It names one timeline syncobj from 1024, 2048 and 4096 outputs, then rising points 1 to 4096, then 4097 syncs. It expects time to grow about linearly, every point to be waitable, and 4097 to be refused with nothing installed.killed-jobs: twelve clients each submit a fill behind a chain of bounded compute dispatches (8 × ~0.8 s, each inside the 2 s watchdog) and are SIGKILLed while the chain runs. It compares/sys/kernel/debug/aurora-g17/capacityafter the kills against after the chain finished. Expected: no execution contexts or QoS IDs held by the killed jobs.killed-jobsrounds, then a kernel log check.