Repository navigation
drm/asahi: enable HIGH priority GPU queues across G14 v27.2, G15-G17 and split-KMS compositors - #4080
RyanTheTide wants to merge 4 commits into
Conversation
On split KMS/render platforms (such as Apple Silicon with apple-drm + aurora/asahi), Wayland compositors hold DRM master on the display card while opening the render-only GPU node where drm_is_current_master() is always false. Without CAP_SYS_NICE (which GNOME Shell and Hyprland do not carry), compositors cannot obtain high-priority GPU queues and log 'Failed to obtain high priority context'. Add drm_current_is_kms_master() to check under current->files->file_lock whether the calling task currently holds active DRM master on any live DRIVER_MODESET primary node, and expose it to Rust DRM drivers via File::current_is_kms_master(). Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…KMS masters Every Apple Silicon GPU backend from G13 through G17 already implements priority ordering for queues created with DRM_ASAHI_PRIORITY_HIGH: - G13/G14 v12.3/v13.5 submit through per-priority firmware pipes and raw::PRIORITY[1]. - G14 firmware 27.2 uses a 4-priority drm_sched scheduler; order its unpublished pending queue by packet urgency as well so HIGH work jumps ahead of queued MEDIUM/LOW work without disturbing partially published packets. - G15 (M3 Pro/Max) and G16 (M4) engines pick pending jobs by smallest QueueState::priority first (HIGH=1 < MEDIUM=2 < LOW=3). - M3 T8122 Extended and G17 (M5) already supported HIGH. Move HIGH-priority capability discovery onto Gpu::supports_high_priority() (defaulting to false for backends without priority scheduling), enable it on G13/G14, G14 v27.2, G15, G16, G17, and M3 T8122 Extended, and admit callers that hold CAP_SYS_NICE, DRM master on this device, or active DRM master on a KMS display card (File::current_is_kms_master()) so Wayland compositors such as GNOME Shell and Hyprland obtain high-priority contexts on split KMS/render Apple Silicon setups while unprivileged clients still receive -EACCES. Update tools/asahi/queue-priority-tests.py to cover the trait predicate and split-KMS master credential gate. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Exact-head hardware verification on J473 (Apple M2 Mac mini, T8112, G14G B0 firmware 27.2, Fedora 45,
|
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Exact-head hardware verification on J473 (Apple M2 Mac mini, T8112, G14G B0 firmware 27.2, Fedora 45,
|
…nding queue
Add Packet::urgency and KVec::{reserve, insert_within_capacity,
Index<RangeFrom>} to the standalone g14-v27-2-try-bind-tests.py mock
harness so it matches drivers/gpu/drm/asahi/g14_v27_2.rs's urgency-ordered
state.pending insertion.
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at d757eee16f8852205e4fea3f908f94173bfd56ab
Blockers:
drivers/gpu/drm/asahi/g14_v27_2.rs:963-976: on G14 27.2, work can now run before the work it waits for.- All queues share one DRM scheduler (
g14_v27_2.rs:2401). For a dependency on another queue of the same scheduler, drm_sched only waits until that job was handed torun_job, not until it finished (scheduler/sched_entity.c:496,DRM_SCHED_FENCE_DONT_PIPELINEnot set). That was safe whilependingwas first in, first out. Now a more urgent job is put in front of its own producer. - Case: a client's MEDIUM render A is waiting in
pending(index 0) because another render is in flight. The compositor's HIGH job B waits for A through a binary syncobj, which is what Mesa builds from an imported sync file (agx_batch.c:1889). A'sscheduledfence has signalled, so B goes straight tosubmitand is inserted before A. The compositor samples an unfinished buffer, and B's fence signals before A's. - I compiled the insertion code from the head against a host model with that rule: MEDIUM producer, HIGH consumer is published as
[consumer, producer]; the same for LOW producer and MEDIUM consumer, which needs no privilege.maingives[producer, consumer]for both. - Fix: set
DRM_SCHED_FENCE_DONT_PIPELINEon the job'sfinishedfence betweenjob.arm()andjob.push()(m3/m3_submit.rs:457), with a small helper inrust/kernel/drm/sched.rs. Jobs of one queue still pipeline, because the same-entity check comes first. This also covers the T8122, wherem3_runtime.rs:1500andm3_drm.rs:197already have the same problem onmain. Please add the LOW to MEDIUM case to a host test.
- All queues share one DRM scheduler (
- Rows: the only Mac so far is J473 (G14G 27.2), and that row tests who may create a queue, not the order or whether lower priorities still finish. The PR also turns HIGH on for the first time on G15, on G16 and on G13/G14 firmware 12.3/13.5. Please add a row at the new head for G14 27.2 that covers the order in point 1, and one on a newly enabled backend (G15 or G16). For firmware 12.3/13.5, add a row too or leave
GpuManager::veratfalseuntil there is one: nothing has runPRIORITY[1]there yet, and compute on those GPUs without preemption always takes fields of the top entry (workqueue.rs:991), so HIGH render cannot get ahead of MEDIUM compute. Rows on J516s (G15S), J773g (G16G), J700 (G17P) and J714s (G17S) are wanted as well; J414s (G14S 27.2) has to be stacked with #3998, which merges cleanly with this.
Checked: every changed line at this head, no Apple material, no new parameters, no new chip or board gates (the type checks became a backend capability), human sign-off on all commits, lifetimes and locks of the new DRM helper, priority use per GPU generation, host tests on the merge with current main. host-tests failed at 5dc26996; the last commit fixes g14-v27-2-try-bind-tests.py (11/11 here).
Evidence, questions and nits (none of these blocks)
drm_current_is_kms_master(): sound. An fd in the table holds its file, so drm_release cannot run while file_lock is held, and a file is only installed after drm_open set private_data. The major, f_op->open and primary-node checks keep other files and O_PATH fds out. drm_is_current_master() takes only the master_lookup_lock spinlock, drm_dev_is_unplugged() is an SRCU section, and I found no path that takes file_lock under master_lookup_lock. Threads sharing a files table get one answer, a passed or inherited KMS fd carries master with it, and a lessee counts as master; amdgpu's check behaves the same way.
- A queue keeps HIGH after a VT switch or
DROP_MASTER, because only creation is checked. Same as amdgpu; worth one sentence in the comment. - Any
DRIVER_MODESETcard counts. On a card nobody has claimed (Touch Bar, vkms, a USB display), the first opener becomes master, so the seat user can get HIGH that way. Say that this is intended, or narrow it. - The walk holds
file_lockfor the whole table and an unprivileged caller can trigger it. With the usual 524288 fd limit that is a long section without a reschedule. current_is_kms_master(&self)does not useself;iterate_fd()already handles a NULLfiles; the debug message atfile.rs:1800and theDRM_ASAHI_PRIORITY_HIGHtext inasahi_drm.hshould mention the KMS card; the second commit message has broken wrapping.
Starvation: G15 and G16 pick by host priority with no aging (g15/engine.rs and g16/engine.rs, pick()), and G14 27.2 now does the same, so a HIGH queue that is always backlogged holds MEDIUM and LOW back for as long as it stays backlogged. Their scheduler timeouts report no hang, so waiting work is late, not failed. G17 keeps its existing classes; a waiting job there is renewed for up to 30 s and then fails (g17/timeout.rs). G15, G16 and G14 27.2 use no firmware priority value. G13/G14 12.3/13.5 use PRIORITY[1] from the existing table; I found no trace of that entry in the repository.
G14 27.2 reorder apart from point 1: each queue stays in order, a partly published packet and one waiting for a context slot stay in front, stamps and slots are assigned at publication and stay consistent, and withdraw and recovery find packets by identity.
Tests, with mutations on the merge:
queue-priority-tests.pypasses (288 cases). It catches dropping the KMS check, droppingCAP_SYS_NICE, inverting the support check and widening the M3 check. It does not see which backends returntrue,drm_auth.c, or the G14 order.g14-v27-2-try-bind-tests.pypasses with<changed to<=, with the partly-published check removed and with the context-wait check removed: every mock packet has urgency 1. Mixed urgencies would cover all three.
Address review feedback on HIGH-priority queue enablement: - Expose DRM_SCHED_FENCE_DONT_PIPELINE via JobFences::set_dont_pipeline() in rust/kernel/drm/sched.rs and set it between job.arm() and job.push() in m3/m3_submit.rs so cross-entity dependencies on shared-scheduler backends (G14 27.2 and T8122 M3) wait for the producer's finished fence instead of pipelining ahead of it when pending is urgency-ordered. Same-entity dependencies still pipeline. - Leave G13/G14 firmware 12.3/13.5 (GpuManager::ver) at supports_high_priority() == false until tested on hardware. - Polish drm_current_is_kms_master() (drop redundant NULL check handled by iterate_fd(), document VT-switch/DROP_MASTER and DRIVER_MODESET scope), make drm::file::current_is_kms_master() a free function without unused &self, and mention KMS master in asahi_drm.h and file.rs debug logs. - Expand g14-v27-2-try-bind-tests.py with mixed-urgency FIFO ordering, partly-published and waiting_bind head-preservation, and LOW->MEDIUM / MEDIUM->HIGH cross-entity DONT_PIPELINE tests (14 cases + 9 mutations). Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
The fix for point 1 of the review is in #4163 against One correction to the review: on |
|
Addressed both blockers and the review nits in Blocker 1 — shared-scheduler cross-entity pipelining (
|
| Target | gnome-shell (Uid=1000, CapEff=0) |
QUEUE_CREATE auth |
2-proc SCM_RIGHTS SYNC_FD ordering (2048x2048 saturation) |
2-proc preemption + lower-prio completion (16x heavy LOW + 1x HIGH) |
Concurrent 6xLOW+6xMED+6xHIGH |
dmesg GPU errors |
|---|---|---|---|---|---|---|
J473 (Apple M2, T8112, G14G B0 fw 27.2, Fedora 45, Enforcing) |
Obtained a high priority EGL context |
unpriv HIGH -> -EACCES (LOW/MEDIUM OK); CAP_SYS_NICE LOW/MEDIUM/HIGH OK |
LOW->MEDIUM: 15/15 (0 inv, prod 51.8 ms, +0.28 ms); MEDIUM->HIGH: 15/15 (0 inv, prod 51.4 ms, +0.31 ms); LOW->HIGH: 15/15 (0 inv, prod 51.4 ms, +0.27 ms); Vulkan render+compute LOW->MEDIUM: 15/15 each (0 inv) |
5/5 preempted (HIGH 7.8–13.1 ms vs LOW 163.5–170.9 ms; all LOW completed) |
PASS (hi=34.3ms, med=23.8ms, lo=13.5ms) |
0 |
J616s (Apple M4 Pro, T6040, G16S B1, Fedora 45, Enforcing) |
Obtained a high priority EGL context |
unpriv uid=1000 HIGH -> -EACCES (LOW/MEDIUM OK); CAP_SYS_NICE LOW/MEDIUM/HIGH OK |
LOW->MEDIUM: 15/15 (0 inv, prod 17.1 ms, +0.82 ms); MEDIUM->HIGH: 15/15 (0 inv, prod 16.5 ms, +0.68 ms); LOW->HIGH: 15/15 (0 inv, prod 16.4 ms, +0.57 ms); Vulkan render+compute LOW->MEDIUM: 15/15 each (0 inv) |
5/5 preempted (HIGH 1.4–12.7 ms, steady 1.4–1.9 ms vs LOW 50.8–70.2 ms; all LOW completed) |
PASS (hi=43.8ms, med=30.8ms, lo=16.4ms) |
0 |
(Note: Vulkan VK_QUEUE_GLOBAL_PRIORITY_HIGH_KHR on non-G17 GPUs currently returns VK_ERROR_NOT_PERMITTED_EXT inside Mesa hk_queue.c:2175 before issuing DRM_IOCTL_ASAHI_QUEUE_CREATE, so the MEDIUM->HIGH / LOW->HIGH / preemption rows exercised the real EGL_IMG_context_priority + EGL_SYNC_NATIVE_FENCE_ANDROID gallium/asahi path used by compositors.)
Nits addressed
- Dropped the redundant
current->filesNULL check indrm_current_is_kms_master()(handled byiterate_fd()), documented VT-switch/DROP_MASTERlifetime andDRIVER_MODESETscope indrivers/gpu/drm/drm_auth.c, madedrm::file::current_is_kms_master()a free function without unused&self, and updatedinclude/uapi/drm/asahi_drm.hand thefile.rsdebug log to mention active KMS DRM master. checkpatch.pl --stricton5c50caa34196: 0 errors, 0 warnings, 0 checks.- Regarding the
file_lockwalk initerate_fd(): it iterates up tofdt->max_fds(typically 64–1024 for normal processes), matching standard kerneliterate_fd()users; happy to switch to an RCU walk in a follow-up if you'd prefer it bounded against pathological fd tables.
Summary
Enables
DRM_ASAHI_PRIORITY_HIGHGPU queues for Wayland compositors (gnome-shell,Hyprland,sway,kwin_wayland) andCAP_SYS_NICEcallers across Apple Silicon G14 v27.2 and G15–G17 (leaving legacy G13/G14 firmware 12.3/13.5 atfalseuntil tested on hardware):drm: add drm_current_is_kms_master() for split KMS/render compositors(include/drm/drm_auth.h,drivers/gpu/drm/drm_auth.c,rust/kernel/drm/file.rs):On split KMS/render platforms (
apple-drm+aurora/asahi), Wayland compositors hold DRM master on the KMS display card while opening the render-only GPU node wheredrm_is_current_master()is always false. Addsdrm_current_is_kms_master()(anddrm::file::current_is_kms_master()) to check undercurrent->files->file_lockwhether the calling task currently holds active DRM master on any liveDRIVER_MODESETprimary node.drm/asahi: enable authorized HIGH priority queues across G14 v27.2, G15–G17 and KMS masters(drivers/gpu/drm/asahi/*,rust/bindings/bindings_helper.h,rust/kernel/drm/sched.rs,tools/asahi/queue-priority-tests.py,tools/asahi/g14-v27-2-try-bind-tests.py):G17/ T8122 M3 check infile.rswithGpu::supports_high_priority(), enabled on G14v27.2, G15, G16, G17, and M3 T8122 Extended (legacy G13/G14 firmware 12.3/13.5 left atfalse).v27.2unpublishedstate.pendingwork by packet urgency soHIGHwork jumps ahead of queuedMEDIUM/LOWpackets without disturbing partially published or context-wait packets.DRM_SCHED_FENCE_DONT_PIPELINEviaJobFences::set_dont_pipeline()betweenjob.arm()andjob.push()inm3/m3_submit.rsso cross-entity dependencies on shared-scheduler backends (G14v27.2and T8122 M3) wait for the producer's finished fence instead of pipelining ahead of it while same-entity pipelining is preserved.DRM_ASAHI_PRIORITY_HIGHwhen the caller hasCAP_SYS_NICE, DRM master on the GPU node, or active KMS master (drm::file::current_is_kms_master()), while continuing to reject unprivileged apps with-EACCES.Risk
Low, two-way:
drm_current_is_kms_master()is read-only underfile_lockand only unlocksDRM_ASAHI_PRIORITY_HIGHfor callers that already hold active KMS DRM master (orCAP_SYS_NICE). Unprivileged clients remain rejected with-EACCES.Testing
Tested: exact head
5c50caa34196(7.3.0-b6qprio2-b6qprio2,Image133d5557d3de,aurora.ko79844321f57fstripped) on J473 (Apple M2, T8112, G14G B0 fw 27.2, Fedora 45,Enforcing) and J616s (Apple M4 Pro, T6040, G16S B1, Fedora 45,Enforcing): on both Macs,gnome-shell(Uid=1000,CapEff=0) loggedObtained a high priority EGL context;DRM_IOCTL_ASAHI_QUEUE_CREATErejected unprivilegedHIGHwith-EACCES(LOW/MEDIUMOK) and allowedCAP_SYS_NICEHIGH; 2-processSCM_RIGHTSEGL_SYNC_NATIVE_FENCE_ANDROIDcross-entity ordering under heavy2048x2048saturation passed 15/15 with 0 inversions forLOW->MEDIUM,MEDIUM->HIGH, andLOW->HIGH(plus VulkanRENDER/COMPUTELOW->MEDIUM15/15 0 inversions); 2-process preemption passed 5/5 withHIGHfinishing ahead of a 16-jobLOWbacklog while allLOWjobs completed (J473: HIGH 7.8–13.1 ms vs LOW 163.5–170.9 ms;J616s: HIGH 1.4–12.7 ms vs LOW 50.8–70.2 ms), and concurrent6xLOW + 6xMEDIUM + 6xHIGHall completed cleanly with 0 dmesg GPU errors.checkpatch.pl --strict: 0/0/0 on5c50caa34196;tools/asahi/queue-priority-tests.py: 288/288 + M3 enabled/disabled compilation +set_dont_pipeline()check PASS;tools/asahi/g14-v27-2-try-bind-tests.py: 14/14 cases + 9/9 mutations PASS.