From e11accde9300e4d18dbc31a267214c3c81fb7c29 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 25 Nov 2026 00:45:31 +1100 Subject: [PATCH 1/6] drm/asahi: hand G14 firmware 27.2 its user timestamp pairs by pointer The Timestamp operation of a firmware command stream carries one word for the user timestamps. In the 13.5 command layout and in the M3 27.2 runtime that word names the command's pair of user start and end destinations; the firmware reads the destination from that pair. The G14 27.2 render streams instead stored the start destination in the start operation and the end destination in the end operation, so the firmware would have read the user buffer's contents as the pair and written its stamps wherever they pointed. The compute stream left the word and the pair empty, so compute commands never got user timestamps. No user timestamps reach this runtime yet, since it refuses to bind timestamp buffers, so neither has been seen. Make the word name the pair the render commands already carry, or zero without user timestamps, as the M3 27.2 render and compute encoders do. Give the compute command its pair after the internal timestamp pointers, where the 13.5 compute command and the 27.2 render commands keep it, and pass the packet's compute destinations to it. The pair placement and the operation word are host-tested. Signed-off-by: Ryan Murray --- drivers/gpu/drm/asahi/g14_v27_2.rs | 6 +- drivers/gpu/drm/asahi/g14_v27_2_abi.rs | 69 +++++++++++++++++++++++ drivers/gpu/drm/asahi/g14_v27_2_render.rs | 17 +++--- drivers/gpu/drm/asahi/gpu/v27_2.rs | 6 +- 4 files changed, 88 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/asahi/g14_v27_2.rs b/drivers/gpu/drm/asahi/g14_v27_2.rs index e9edc12813ab4..80698d66f8e6d 100644 --- a/drivers/gpu/drm/asahi/g14_v27_2.rs +++ b/drivers/gpu/drm/asahi/g14_v27_2.rs @@ -670,7 +670,8 @@ impl Runtime { }; let last = index + 1 == packet.commands.len(); let result = match command { - Command::Compute(control) => self.publish_compute(state, &packet, control, last, slots[0]), + Command::Compute(control) => + self.publish_compute(state, &packet, index, control, last, slots[0]), Command::Render { command, usc } => self.publish_render(state, &packet, index, &command, usc, last, slots), }; @@ -687,7 +688,7 @@ impl Runtime { } fn publish_compute( - &self, state: &mut State, packet: &Arc, + &self, state: &mut State, packet: &Arc, index: usize, control: crate::m3::agx_compute::Control, last: bool, slot: usize, ) -> Result { let bind = self.graph.kernel_uat().bind(&packet.vm)?; @@ -700,6 +701,7 @@ impl Runtime { cdm_end: control.end, usc_base: control.usc_base, preempt, + timestamps: packet.timestamp_addresses(index), }; let command = state.pool.encode(slot, &state.queue, stamp.raw(), &job)?; let submission = state.root.stage_compute(command)?; diff --git a/drivers/gpu/drm/asahi/g14_v27_2_abi.rs b/drivers/gpu/drm/asahi/g14_v27_2_abi.rs index 20f172fdb52e9..1544c851b6dc3 100644 --- a/drivers/gpu/drm/asahi/g14_v27_2_abi.rs +++ b/drivers/gpu/drm/asahi/g14_v27_2_abi.rs @@ -99,6 +99,34 @@ pub(crate) const GLOBALS_BYTES: usize = 0xe48; /// clock below what the firmware's power and thermal controller would allow. pub(crate) const GLOBALS_PSTATE_SELECTORS: [usize; 3] = [0x88, 0x8c, 0x98]; +/// Where the 27.2 compute command (type 3, 0x358 bytes) keeps the user timestamp pair: right +/// after the command time (+0x2c4) and the internal start/end pointers (+0x2cc), the order of +/// the 13.5 compute command and of the 27.2 render commands (vertex +0x5e4, fragment +0x948). +pub(crate) const COMPUTE_USER_TIMESTAMPS: usize = 0x2dc; + +/// The value of a 27.2 Timestamp operation's user word: like the 13.5 and the M3 27.2 +/// operations it names the command's start/end pair of user destinations, not a destination. +/// Zero when the command has no user timestamps. +pub(crate) fn user_timestamp_pointer(pair_va: u64, pair: [u64; 2]) -> u64 { + if pair == [0; 2] { + 0 + } else { + pair_va + } +} + +fn put64(b: &mut [u8], at: usize, v: u64) { + b[at..at + 8].copy_from_slice(&v.to_le_bytes()); +} + +/// Writes the user timestamp pair of a zeroed 27.2 compute command at `cmd_va` and returns the +/// Timestamp operations' user word ([`user_timestamp_pointer`]). +pub(crate) fn encode_compute_timestamps(cmd: &mut [u8], cmd_va: u64, timestamps: [u64; 2]) -> u64 { + put64(cmd, COMPUTE_USER_TIMESTAMPS, timestamps[0]); + put64(cmd, COMPUTE_USER_TIMESTAMPS + 8, timestamps[1]); + user_timestamp_pointer(cmd_va + COMPUTE_USER_TIMESTAMPS as u64, timestamps) +} + #[cfg_attr(not(test), kunit_tests(asahi_g14_fw_queues))] #[cfg_attr(test, allow(dead_code))] mod tests { @@ -201,4 +229,45 @@ mod tests { assert!(GLOBALS_PSTATE_SELECTORS[i + 1..].iter().all(|&o| o + 4 <= at || at + 4 <= o)); } } + + /// Size of the 27.2 compute command. + const COMPUTE_COMMAND_BYTES: usize = 0x358; + + /// Byte ranges `encode_compute` (gpu/v27_2.rs) writes in the 27.2 compute command, and + /// the words its stream hands the firmware to write (+0x264, +0x2c4, +0x304, +0x314, + /// +0x340). + const COMPUTE_WRITES: &[(usize, usize)] = &[ + (0, 4), (4, 8), (0xc, 4), (0x10, 8), + (0x68, 8), (0x70, 8), (0x78, 8), (0x80, 8), (0x88, 8), (0x90, 8), (0x98, 8), (0xa0, 8), + (0xc0, 8), + (0x1e8, 8), (0x1f0, 4), (0x220, 8), (0x228, 8), (0x264, 8), (0x270, 4), + (0x298, 0x1c), (0x2c4, 0x18), (0x304, 8), (0x314, 8), (0x334, 0x14), + ]; + + /// Whether `len` bytes at `at` fit the command and are none the compute encoder uses. + fn free(at: usize, len: usize) -> bool { + at + len <= COMPUTE_COMMAND_BYTES + && COMPUTE_WRITES.iter().all(|&(o, l)| o + l <= at || at + len <= o) + } + + #[test] + fn a_timestamp_operation_names_the_pair_only_when_there_is_one() { + assert_eq!(user_timestamp_pointer(0x1000, [0, 0]), 0); + assert_eq!(user_timestamp_pointer(0x1000, [0x40, 0]), 0x1000); + assert_eq!(user_timestamp_pointer(0x1000, [0, 0x48]), 0x1000); + } + + #[test] + fn the_compute_user_pair_lands_in_a_free_place() { + let mut cmd = [0u8; COMPUTE_COMMAND_BYTES]; + let pair = [0xffff_ffa1_8140_0010, 0xffff_ffa1_8140_0018]; + assert_eq!(encode_compute_timestamps(&mut cmd, 0x8000, pair), 0x8000 + 0x2dc); + let read64 = |at: usize| u64::from_le_bytes(cmd[at..at + 8].try_into().unwrap()); + assert_eq!([read64(0x2dc), read64(0x2e4)], pair); + assert!(free(0x2dc, 16)); + // No timestamps leave the command as it was. + let mut empty = [0u8; COMPUTE_COMMAND_BYTES]; + assert_eq!(encode_compute_timestamps(&mut empty, 0x8000, [0; 2]), 0); + assert!(empty.iter().all(|&b| b == 0)); + } } diff --git a/drivers/gpu/drm/asahi/g14_v27_2_render.rs b/drivers/gpu/drm/asahi/g14_v27_2_render.rs index 10ce122708dbd..cbbbd7febb8e5 100644 --- a/drivers/gpu/drm/asahi/g14_v27_2_render.rs +++ b/drivers/gpu/drm/asahi/g14_v27_2_render.rs @@ -224,7 +224,8 @@ fn header(b: &mut [u8], kind: u32, c: &Common) { put64(b, 0x10, c.tracking); } -/// Write the destinations used by both internal timestamp paths. +/// Write the destinations used by both internal timestamp paths. `user` names the command's +/// pair of user destinations, or is 0 ([`crate::g14_v27_2_abi::user_timestamp_pointer`]). fn timestamp_op( s: &mut [u8], at: usize, @@ -234,7 +235,7 @@ fn timestamp_op( ts_pointers: u64, internal0: u64, internal1: u64, - user: [u64; 2], + user: u64, ) { put32(s, at, if start { 0x8000_0003 } else { 3 }); put64(s, at + 0x04, command_time); @@ -245,7 +246,7 @@ fn timestamp_op( if start { ts_pointers } else { ts_pointers + 8 }, ); put64(s, at + 0x1c, q.queue); - put64(s, at + 0x24, user[usize::from(!start)]); + put64(s, at + 0x24, user); put64(s, at + 0x2c, internal0); put64(s, at + 0x34, internal1); } @@ -430,6 +431,7 @@ pub(crate) fn encode_vertex( put64(cmd, 0x5dc, c.timestamps + 8); put64(cmd, 0x5e4, timestamps[0]); put64(cmd, 0x5ec, timestamps[1]); + let user = crate::g14_v27_2_abi::user_timestamp_pointer(c.cmd_va + 0x5e4, timestamps); let internal0 = c.cmd_va + 0x61c; let internal1 = c.cmd_va + 0x538; let flag = c.cmd_va + 0x568; @@ -469,7 +471,7 @@ pub(crate) fn encode_vertex( ts, internal0, internal1, - timestamps, + user, ); put32(s, 0x1e8, 0x0000_0100); timestamp_op( @@ -481,7 +483,7 @@ pub(crate) fn encode_vertex( ts, internal0, internal1, - timestamps, + user, ); let fin = 0x238; put32(s, fin, 6); @@ -933,6 +935,7 @@ pub(crate) fn encode_fragment( let ts = va(frag_at(offset_of!(Rf, timestamp_pointers))); put64(cmd, 0x948, timestamps[0]); put64(cmd, 0x950, timestamps[1]); + let user = crate::g14_v27_2_abi::user_timestamp_pointer(va(0x948), timestamps); let internal0 = va(0x980); let internal1 = va(0x89c); let (jp1, jp2) = (va(0x80), va(0x3c8)); @@ -989,7 +992,7 @@ pub(crate) fn encode_fragment( ts, internal0, internal1, - timestamps, + user, ); put32(s, 0x200, 0x0001_0000); // wait for the fragment pipe timestamp_op( @@ -1001,7 +1004,7 @@ pub(crate) fn encode_fragment( ts, internal0, internal1, - timestamps, + user, ); // op 8 FinalizeFragment (0xbc). let fin = 0x250; diff --git a/drivers/gpu/drm/asahi/gpu/v27_2.rs b/drivers/gpu/drm/asahi/gpu/v27_2.rs index 70e9207001035..12efdfff44584 100644 --- a/drivers/gpu/drm/asahi/gpu/v27_2.rs +++ b/drivers/gpu/drm/asahi/gpu/v27_2.rs @@ -76,6 +76,8 @@ pub(crate) struct ComputeJob { /// VA of the preemption buffer in the same context (13.5 layout: buffer 1 at +0, /// buffers 2 to 5 at +compute_preempt1_size + 8n). pub(crate) preempt: u64, + /// Firmware VAs of the user start and end timestamps, or 0. + pub(crate) timestamps: [u64; 2], } fn put32(b: &mut [u8], at: usize, v: u32) { @@ -119,6 +121,7 @@ fn encode_compute( // through the pointer at +0x334. put32(cmd, 0x33c, 1); put64(cmd, 0x334, timestamps + 0x20); + let user = g14_v27_2_abi::encode_compute_timestamps(cmd, cmd_va, job.timestamps); put32(stream, 0, 11); // 13.5 StartCompute.unk_28, at the same place in this layout (the 13.5 G14 path writes 1). @@ -138,6 +141,7 @@ fn encode_compute( put64(stream, at + 0x0c, cmd_va + 0x2cc); put64(stream, at + 0x14, cmd_va + selected); put64(stream, at + 0x1c, q.queue); + put64(stream, at + 0x24, user); put64(stream, at + 0x2c, cmd_va + 0x314); put64(stream, at + 0x34, cmd_va + 0x264); } @@ -354,7 +358,7 @@ impl BootJob { let cdm = self.client_va + self.preempt1 + 0x2000; let job = ComputeJob { context: 0, sequence: 0, cdm_base: cdm, cdm_end: cdm + 8, - usc_base: 0x11_0000_0000, preempt: self.client_va, + usc_base: 0x11_0000_0000, preempt: self.client_va, timestamps: [0; 2], }; let (cmd_va, stream_va) = (self.command.gpu_va().get(), self.stream.gpu_va().get()); encode_compute(self.command.as_mut_slice(), cmd_va, self.stream.as_mut_slice(), stream_va, From 9bc8fcc626484f5ac43757a3faff44fbb6c29299 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 25 Nov 2026 00:46:35 +1100 Subject: [PATCH 2/6] drm/asahi: bind timestamp buffers on G14 firmware 27.2 GEM_BIND_OBJECT with USAGE_TIMESTAMPS returned ENOTSUPP on the G14 firmware 27.2 runtime, so Vulkan could not create timestamp query pools and OpenCL profiling failed. That firmware reaches the kernel window through its own copy of the window's second-level entries, made once before it starts (FirmwareWindow::mirror), so a leaf table created later for a timestamp buffer would never be seen by it. The graph already keeps its private allocations below the 64 MiB timestamp aperture that the 27.2 root hands to the firmware. Link the aperture's leaf tables, with no mappings, before the window is mirrored, the way the kernel lower tables are prepared for a firmware that samples its root only at start (Uat::prepare_lower_tables, now sharing one helper with the new prepare_kernel_tables). Page tables are only freed with their VM, so the mirrored entries stay valid; leaf entries written later are cleaned to the point of coherency by the adopted UAT's page table as for every other firmware mapping. The graph records its profile's timestamp aperture, and the common GpuManager::map_timestamp_buffer maps into it: the native aperture as before, the 27.2 one for the 27.2 profile. The 27.2 backend delegates to it as it does for its parameters and clock, so timestamp buffers are bound, retained by the commands that name them and unmapped exactly as on the 13.5 path. Signed-off-by: Ryan Murray --- drivers/gpu/drm/asahi/g14_v27_2.rs | 9 ++++++--- drivers/gpu/drm/asahi/gpu.rs | 16 +++++++++++----- drivers/gpu/drm/asahi/gpu/v27_2.rs | 5 +++++ drivers/gpu/drm/asahi/mmu.rs | 15 ++++++++++++++- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/asahi/g14_v27_2.rs b/drivers/gpu/drm/asahi/g14_v27_2.rs index 80698d66f8e6d..dc150e8b99d76 100644 --- a/drivers/gpu/drm/asahi/g14_v27_2.rs +++ b/drivers/gpu/drm/asahi/g14_v27_2.rs @@ -340,6 +340,9 @@ pub(crate) fn start<'a>( gpu::GraphProfile::G14V27_2)?; let root = RootV27_2::build(&graph, &board)?; let pool = CommandPool::new(&mut gpu::GpuManager::alloc(&*graph), cfg)?; + // Timestamp buffers are bound in the timestamp aperture while the firmware runs, and the + // window only carries the tables that exist now: link the aperture's tables first. + graph.kernel_uat().prepare_kernel_tables(&[graph.timestamp_range()])?; window.mirror(graph.kernel_uat())?; window.install()?; window.announce(); @@ -1212,8 +1215,8 @@ impl gpu::Gpu for Backend { Ok(KBox::new(crate::m3::m3_submit::Queue::new_g14_v27_2(self.runtime.clone(), self.scheduler.clone(), vm, priority, usc_exec_base, ualloc_priv, self.preempt_bytes, render)?, GFP_KERNEL)?) } - fn map_timestamp_buffer(&self, _bo: gem::ObjectRef, _range: Range) -> Result { - // Timestamp buffers would need new tables in the firmware window after boot. - Err(ENOTSUPP) + fn map_timestamp_buffer(&self, bo: gem::ObjectRef, range: Range) -> Result { + // The aperture's tables were linked before the firmware window was mirrored (start()). + ::map_timestamp_buffer(&self.graph, bo, range) } } diff --git a/drivers/gpu/drm/asahi/gpu.rs b/drivers/gpu/drm/asahi/gpu.rs index 9fed9e62ec383..e153fc7490445 100644 --- a/drivers/gpu/drm/asahi/gpu.rs +++ b/drivers/gpu/drm/asahi/gpu.rs @@ -326,6 +326,8 @@ pub(crate) struct GpuManager { dyncfg: hw::DynConfig, pub(crate) initdata: fw::types::GpuObject, uat: mmu::Uat, + /// The firmware's timestamp aperture in the kernel VM, where timestamp buffers are bound. + timestamp_range: Range, crashed: AtomicBool, /// Set once the over-limit firmware-private garbage was reported as held. garbage_held: AtomicBool, @@ -746,10 +748,10 @@ impl GpuManager::ver { profile: GraphProfile, ) -> Result> { let dyncfg = Self::make_dyncfg(dev, res, cfg, &uat)?; - let private_end = match profile { - GraphProfile::Native => IOVA_KERN_PRIV_RANGE.end, + let (private_end, timestamp_range) = match profile { + GraphProfile::Native => (IOVA_KERN_PRIV_RANGE.end, IOVA_KERN_TIMESTAMP_RANGE), #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] - GraphProfile::G14V27_2 => IOVA_G14_V27_2_TIMESTAMP_RANGE.start, + GraphProfile::G14V27_2 => (IOVA_G14_V27_2_TIMESTAMP_RANGE.start, IOVA_G14_V27_2_TIMESTAMP_RANGE), }; let mut alloc = KernelAllocators { @@ -828,7 +830,8 @@ impl GpuManager::ver { false, )?); - let mut mgr = Self::make_mgr(dev, cfg, dyncfg, uat, alloc, event_manager, initdata)?; + let mut mgr = Self::make_mgr(dev, cfg, dyncfg, uat, alloc, event_manager, initdata, + timestamp_range)?; { let fwctl = mgr.fwctl_channel.lock(); @@ -1005,6 +1008,7 @@ impl GpuManager::ver { /// /// Force disable inlining to avoid blowing up the stack. #[inline(never)] + #[allow(clippy::too_many_arguments)] fn make_mgr( dev: &AsahiDrmDevice, cfg: &'static hw::HwConfig, @@ -1013,6 +1017,7 @@ impl GpuManager::ver { mut alloc: KernelAllocators, event_manager: Arc, initdata: KBox>, + timestamp_range: Range, ) -> Result>> { let mut pipes = PipeChannels::ver { vtx: KVec::new(), @@ -1113,6 +1118,7 @@ impl GpuManager::ver { dyncfg: KBox::::into_inner(dyncfg), initdata: KBox::>::into_inner(initdata), uat: KBox::::into_inner(uat), + timestamp_range, io_mappings: KVec::new(), next_mmio_iova: IOVA_KERN_MMIO_RANGE.start, rtkit <- new_mutex!(None, "rtkit"), @@ -1787,7 +1793,7 @@ impl Gpu for GpuManager::ver { crate::timestamp::Buffer::firmware(bo.map_range_into_range( self.uat.kernel_vm(), range, - IOVA_KERN_TIMESTAMP_RANGE, + self.timestamp_range.clone(), mmu::UAT_PGSZ as u64, mmu::PROT_FW_SHARED_RW, false, diff --git a/drivers/gpu/drm/asahi/gpu/v27_2.rs b/drivers/gpu/drm/asahi/gpu/v27_2.rs index 12efdfff44584..d4dcaa705c5b2 100644 --- a/drivers/gpu/drm/asahi/gpu/v27_2.rs +++ b/drivers/gpu/drm/asahi/gpu/v27_2.rs @@ -530,6 +530,11 @@ impl GpuManagerG14V13_5 { pub(crate) fn kernel_uat(&self) -> &mmu::Uat { &self.uat } + + /// The firmware timestamp aperture that timestamp buffers are bound in. + pub(crate) fn timestamp_range(&self) -> Range { + self.timestamp_range.clone() + } } impl RootV27_2 { diff --git a/drivers/gpu/drm/asahi/mmu.rs b/drivers/gpu/drm/asahi/mmu.rs index 3cca4f5a37fe6..3930365aa4814 100644 --- a/drivers/gpu/drm/asahi/mmu.rs +++ b/drivers/gpu/drm/asahi/mmu.rs @@ -3748,7 +3748,20 @@ impl Uat { /// Links the kernel lower root's tables for each range, with no mappings. A published-roots /// firmware samples that root's top-level entries only when it starts. pub(crate) fn prepare_lower_tables(&self, ranges: &[Range]) -> Result { - let mut inner = lock_vm(&self.kernel_lower_vm.gpuvm, None, false)?; + Self::prepare_tables(&self.kernel_lower_vm, ranges) + } + + /// Links the kernel window's tables for each range, with no mappings, for a firmware that + /// copies the window's second-level entries only when it starts + /// ([`FirmwareWindow::mirror`]). Page tables are only freed with their VM, so the leaf + /// tables stay where that copy names them. + #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] + pub(crate) fn prepare_kernel_tables(&self, ranges: &[Range]) -> Result { + Self::prepare_tables(&self.kernel_vm, ranges) + } + + fn prepare_tables(vm: &Vm, ranges: &[Range]) -> Result { + let mut inner = lock_vm(&vm.gpuvm, None, false)?; for range in ranges { inner.page_table.alloc_pages(range.clone())?; } From 7521672bcdc30572e3f42d2a71e7c3f86d567cae Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 25 Nov 2026 00:49:04 +1100 Subject: [PATCH 3/6] drm/asahi: admit sampler heaps and helper programs on G14 firmware 27.2 The G14 firmware 27.2 runtime takes its client commands through the front end shared with the M3 runtime, whose 26.x commands stream their sampler state and carry no helper program, so that front end refuses both. On the M2 this refused every render command that names a sampler heap with ENOTSUPP: Zink renders through Borealis, which always names its heap, so Zink applications lost the device on their first such pass. Compute commands with a helper program, which Mesa uses for scratch and stack setup, were refused with EINVAL by the common compute translator. The G14 27.2 render builders already write the sampler heap and both helper programs where the 13.5 render commands keep them, and the 27.2 compute command carries the 13.5 compute JobParameters1, which holds the helper. Let a queue say that its builders encode these, as it already says which depth and stencil compression layouts it encodes, and set it for the G14 27.2 queues. Their render admission then checks the sampler heap like the compute translator does instead of refusing it, and their compute commands take the helper from the client and write it to the JobParameters1 places the 13.5 compute path fills. The vertex helper's configuration goes to the tiling parameters, as on 13.5. The M3 queues refuse both as before. The 27.2 compute command's sampler placement is not known, so compute commands with a sampler heap are still refused. Signed-off-by: Ryan Murray --- drivers/gpu/drm/asahi/g14_v27_2.rs | 1 + drivers/gpu/drm/asahi/g14_v27_2_abi.rs | 27 +++++++++++++++++++++++ drivers/gpu/drm/asahi/g14_v27_2_render.rs | 2 ++ drivers/gpu/drm/asahi/gpu/v27_2.rs | 4 ++++ drivers/gpu/drm/asahi/m3/agx_compute.rs | 4 ++++ drivers/gpu/drm/asahi/m3/agx_uapi.rs | 2 +- drivers/gpu/drm/asahi/m3/m3_submit.rs | 24 +++++++++++++++----- 7 files changed, 57 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/asahi/g14_v27_2.rs b/drivers/gpu/drm/asahi/g14_v27_2.rs index dc150e8b99d76..5f18d886413dd 100644 --- a/drivers/gpu/drm/asahi/g14_v27_2.rs +++ b/drivers/gpu/drm/asahi/g14_v27_2.rs @@ -705,6 +705,7 @@ impl Runtime { usc_base: control.usc_base, preempt, timestamps: packet.timestamp_addresses(index), + helper: control.helper, }; let command = state.pool.encode(slot, &state.queue, stamp.raw(), &job)?; let submission = state.root.stage_compute(command)?; diff --git a/drivers/gpu/drm/asahi/g14_v27_2_abi.rs b/drivers/gpu/drm/asahi/g14_v27_2_abi.rs index 1544c851b6dc3..dcd5392c0c146 100644 --- a/drivers/gpu/drm/asahi/g14_v27_2_abi.rs +++ b/drivers/gpu/drm/asahi/g14_v27_2_abi.rs @@ -103,6 +103,8 @@ pub(crate) const GLOBALS_PSTATE_SELECTORS: [usize; 3] = [0x88, 0x8c, 0x98]; /// after the command time (+0x2c4) and the internal start/end pointers (+0x2cc), the order of /// the 13.5 compute command and of the 27.2 render commands (vertex +0x5e4, fragment +0x948). pub(crate) const COMPUTE_USER_TIMESTAMPS: usize = 0x2dc; +/// The 13.5 compute JobParameters1 inside the 27.2 compute command. +pub(crate) const COMPUTE_JOB_PARAMETERS1: usize = 0x68; /// The value of a 27.2 Timestamp operation's user word: like the 13.5 and the M3 27.2 /// operations it names the command's start/end pair of user destinations, not a destination. @@ -119,6 +121,19 @@ fn put64(b: &mut [u8], at: usize, v: u64) { b[at..at + 8].copy_from_slice(&v.to_le_bytes()); } +fn put32(b: &mut [u8], at: usize, v: u32) { + b[at..at + 4].copy_from_slice(&v.to_le_bytes()); +} + +/// Writes a compute helper program (binary: USC offset | 1, data, configuration) into the +/// 13.5 JobParameters1 of a 27.2 compute command, at the places the 13.5 G14 compute path +/// fills: program +0x40, argument +0x48, configuration +0x50. +pub(crate) fn encode_compute_helper(cmd: &mut [u8], binary: u32, data: u64, config: u32) { + put32(cmd, COMPUTE_JOB_PARAMETERS1 + 0x40, binary); + put64(cmd, COMPUTE_JOB_PARAMETERS1 + 0x48, data); + put32(cmd, COMPUTE_JOB_PARAMETERS1 + 0x50, config); +} + /// Writes the user timestamp pair of a zeroed 27.2 compute command at `cmd_va` and returns the /// Timestamp operations' user word ([`user_timestamp_pointer`]). pub(crate) fn encode_compute_timestamps(cmd: &mut [u8], cmd_va: u64, timestamps: [u64; 2]) -> u64 { @@ -250,6 +265,18 @@ mod tests { && COMPUTE_WRITES.iter().all(|&(o, l)| o + l <= at || at + len <= o) } + #[test] + fn the_compute_helper_lands_in_free_job_parameters() { + let mut cmd = [0u8; COMPUTE_COMMAND_BYTES]; + encode_compute_helper(&mut cmd, 0x1235, 0x11_2233_4400, 0x7_0000); + let read64 = |at: usize| u64::from_le_bytes(cmd[at..at + 8].try_into().unwrap()); + let read32 = |at: usize| u32::from_le_bytes(cmd[at..at + 4].try_into().unwrap()); + assert_eq!((read32(0xa8), read64(0xb0), read32(0xb8)), (0x1235, 0x11_2233_4400, 0x7_0000)); + for (at, len) in [(0xa8, 4), (0xb0, 8), (0xb8, 4)] { + assert!(free(at, len)); + } + } + #[test] fn a_timestamp_operation_names_the_pair_only_when_there_is_one() { assert_eq!(user_timestamp_pointer(0x1000, [0, 0]), 0); diff --git a/drivers/gpu/drm/asahi/g14_v27_2_render.rs b/drivers/gpu/drm/asahi/g14_v27_2_render.rs index cbbbd7febb8e5..ecf9e43bc9d86 100644 --- a/drivers/gpu/drm/asahi/g14_v27_2_render.rs +++ b/drivers/gpu/drm/asahi/g14_v27_2_render.rs @@ -92,6 +92,8 @@ fn to_cmdbuf(r: &UapiRenderCommand) -> kernel::uapi::drm_asahi_cmd_render { c.sample_size_B = r.sample_size; c.ppp_ctrl = r.ppp_control; c.ppp_multisamplectl = r.multisample_control; + // The tiling parameters carry the vertex helper's configuration, as in the 13.5 command. + c.vertex_helper.cfg = r.vertex_helper.config; c } diff --git a/drivers/gpu/drm/asahi/gpu/v27_2.rs b/drivers/gpu/drm/asahi/gpu/v27_2.rs index d4dcaa705c5b2..32f606d5066fd 100644 --- a/drivers/gpu/drm/asahi/gpu/v27_2.rs +++ b/drivers/gpu/drm/asahi/gpu/v27_2.rs @@ -78,6 +78,8 @@ pub(crate) struct ComputeJob { pub(crate) preempt: u64, /// Firmware VAs of the user start and end timestamps, or 0. pub(crate) timestamps: [u64; 2], + /// The helper program (scratch and stack setup), or zero. + pub(crate) helper: crate::m3::agx_uapi::UapiHelperProgram, } fn put32(b: &mut [u8], at: usize, v: u32) { @@ -122,6 +124,7 @@ fn encode_compute( put32(cmd, 0x33c, 1); put64(cmd, 0x334, timestamps + 0x20); let user = g14_v27_2_abi::encode_compute_timestamps(cmd, cmd_va, job.timestamps); + g14_v27_2_abi::encode_compute_helper(cmd, job.helper.binary, job.helper.data, job.helper.config); put32(stream, 0, 11); // 13.5 StartCompute.unk_28, at the same place in this layout (the 13.5 G14 path writes 1). @@ -359,6 +362,7 @@ impl BootJob { let job = ComputeJob { context: 0, sequence: 0, cdm_base: cdm, cdm_end: cdm + 8, usc_base: 0x11_0000_0000, preempt: self.client_va, timestamps: [0; 2], + helper: crate::m3::agx_uapi::UapiHelperProgram { binary: 0, config: 0, data: 0 }, }; let (cmd_va, stream_va) = (self.command.gpu_va().get(), self.stream.gpu_va().get()); encode_compute(self.command.as_mut_slice(), cmd_va, self.stream.as_mut_slice(), stream_va, diff --git a/drivers/gpu/drm/asahi/m3/agx_compute.rs b/drivers/gpu/drm/asahi/m3/agx_compute.rs index d58005c504f7a..01c5354748a21 100644 --- a/drivers/gpu/drm/asahi/m3/agx_compute.rs +++ b/drivers/gpu/drm/asahi/m3/agx_compute.rs @@ -6,4 +6,8 @@ pub(crate) struct Control { pub base: u64, pub end: u64, pub usc_base: u64, + /// The helper program, zero unless the queue's command builder encodes it + /// (`m3_submit::Queue::samplers_and_helpers`). + #[cfg_attr(not(CONFIG_DRM_ASAHI_G14_V27_2), allow(dead_code))] + pub helper: crate::m3::agx_uapi::UapiHelperProgram, } diff --git a/drivers/gpu/drm/asahi/m3/agx_uapi.rs b/drivers/gpu/drm/asahi/m3/agx_uapi.rs index 60107f8833edc..028ac81193fbb 100644 --- a/drivers/gpu/drm/asahi/m3/agx_uapi.rs +++ b/drivers/gpu/drm/asahi/m3/agx_uapi.rs @@ -574,7 +574,7 @@ impl QueueUscWindow { } } -fn validate_sampler( +pub(crate) fn validate_sampler( address_space: &A, heap: u64, count: u32, diff --git a/drivers/gpu/drm/asahi/m3/m3_submit.rs b/drivers/gpu/drm/asahi/m3/m3_submit.rs index 5ba1f36879876..3ec3e7c00dbb3 100644 --- a/drivers/gpu/drm/asahi/m3/m3_submit.rs +++ b/drivers/gpu/drm/asahi/m3/m3_submit.rs @@ -318,6 +318,10 @@ pub(crate) struct Queue { /// for every sample count and layer count. Otherwise only the single-sample, /// single-layer compressed depth layout is admitted. zls_compression_all_layouts:bool, + /// Whether this queue's command builders encode the render sampler heap and the render and + /// compute helper programs, in the 13.5 places. Otherwise they are refused: the M3 26.x + /// commands stream their sampler state and carry no helper. + samplers_and_helpers:bool, urgency:u8, } impl Queue { @@ -331,7 +335,7 @@ impl Queue { 1=>sched::Priority::High,0=>sched::Priority::Kernel,_=>return Err(EINVAL)}; Ok(Self {entity:sched::Entity::new(&scheduler,priority)?,_scheduler:scheduler, shared:Sink::M3(shared),vm,usc,fences:FenceContexts::new(1,c_str!("asahi_m3_queue"),kernel::static_lock_class!())?, - early_tiling,wide_visibility,zls_compression_all_layouts:false,urgency,preempt_alloc:None, + early_tiling,wide_visibility,zls_compression_all_layouts:false,samplers_and_helpers:false,urgency,preempt_alloc:None, #[cfg(CONFIG_DRM_ASAHI_G14_V27_2)] render_queue: None}) } @@ -350,6 +354,10 @@ impl Queue { // The G14 render command carries the depth and stencil load, store and partial // compression words in every layout (g14_v27_2_render.rs). zls_compression_all_layouts:true, + // Its render commands carry the sampler heap and both helper programs, and its + // compute command the 13.5 compute JobParameters1 with the helper + // (g14_v27_2_render.rs, gpu/v27_2.rs). + samplers_and_helpers:true, urgency,preempt_alloc:Some((ualloc_priv,preempt_bytes)), render_queue: Some(render_queue)}) } @@ -362,7 +370,7 @@ impl queue::Queue for Queue { while let Some(command)=parser.next_hardware().map_err(|_|EINVAL)? { if let agx_uapi::ParsedHardwareCommand::Render{payload,vertex_attachments,fragment_attachments,..}=command { if let Err(e)=validate_render(payload,self.usc,&AddressSpace(&self.vm),self.early_tiling, - self.zls_compression_all_layouts) { + self.zls_compression_all_layouts,self.samplers_and_helpers) { pr_err!("M3 render rejected {:?}: flags={:#x} size={}x{} layers={} samples={} utile={}x{} sample_size={} depth={:#x} stencil={:#x} zls={:#x} samplers={} heap={:#x}\n",e,payload.flags,payload.width,payload.height,payload.layers,payload.samples,payload.utile_width,payload.utile_height,payload.sample_size,payload.depth.base,payload.stencil.base,payload.zls_control,payload.sampler_count,payload.sampler_heap); return Err(e); } @@ -390,6 +398,9 @@ impl queue::Queue for Queue { // The common translator validates the original command/attachment // addresses; this M3 scheduling hint changes none of them. payload.flags &= !wide; + // The common translator refuses helpers; a queue that encodes one takes it here. + let empty=agx_uapi::UapiHelperProgram{binary:0,config:0,data:0}; + let helper=if self.samplers_and_helpers {core::mem::replace(&mut payload.helper,empty)} else {empty}; render_attachments.push([crate::m3::agx_attachments::Attachments::EMPTY;2],GFP_KERNEL)?; flushes.push(encode_attachments(&self.vm,&attachments)?,GFP_KERNEL)?; let c=agx_uapi::translate_compute_command(payload,attachments, @@ -405,7 +416,7 @@ impl queue::Queue for Queue { } timestamps.push([Destination::resolve(objects,payload.timestamps.start)?, Destination::resolve(objects,payload.timestamps.end)?,None,None],GFP_KERNEL)?; - commands.push(Command::Compute(crate::m3::agx_compute::Control{base:c.control_stream_base,end:c.control_stream_end,usc_base:self.usc}),GFP_KERNEL)?; + commands.push(Command::Compute(crate::m3::agx_compute::Control{base:c.control_stream_base,end:c.control_stream_end,usc_base:self.usc,helper}),GFP_KERNEL)?; } parser.finish().map_err(|_|EINVAL)?; let preempt=match &self.preempt_alloc { @@ -449,7 +460,7 @@ fn encode_attachments(vm: &mmu::Vm, list: &agx_uapi::UapiAttachmentList) } fn validate_render(r: agx_uapi::UapiRenderCommand, usc: u64, space: &AddressSpace<'_>, - early_tiling: bool, zls_compression_all_layouts: bool) -> Result { + early_tiling: bool, zls_compression_all_layouts: bool, samplers_and_helpers: bool) -> Result { use agx_uapi::{GpuAddressSpace, GpuAccess}; if r.sample_size % 8 != 0 {return Err(ENOTSUPP);} let empty = agx_uapi::UapiHelperProgram { binary:0, config:0, data:0 }; @@ -459,8 +470,8 @@ fn validate_render(r: agx_uapi::UapiRenderCommand, usc: u64, space: &AddressSpac #[cfg(not(CONFIG_DRM_ASAHI_M3_T8122))] let stage_scope = { let _ = early_tiling; 0 }; if r.flags & !(2|16|(1<<18)|stage_scope) != 0 || !matches!(r.samples, 1 | 2 | 4) - || r.sampler_count != 0 || r.sampler_heap != 0 - || r.vertex_helper != empty || r.fragment_helper != empty + || (!samplers_and_helpers && (r.sampler_count != 0 || r.sampler_heap != 0 + || r.vertex_helper != empty || r.fragment_helper != empty)) || (!zls_compression_all_layouts && (r.stencil.compression_base != 0 || r.stencil.compression_stride != 0)) || r.ppp_control & !0x203 != 0 { return Err(ENOTSUPP); } @@ -475,6 +486,7 @@ fn validate_render(r: agx_uapi::UapiRenderCommand, usc: u64, space: &AddressSpac || u32::from(r.sample_size)*u32::from(r.utile_width)*u32::from(r.utile_height)*u32::from(r.samples)>32768 { return Err(EINVAL); } + agx_uapi::validate_sampler(space, r.sampler_heap, r.sampler_count.into()).map_err(|_| EINVAL)?; crate::m3::agx_render_state::compact(r.vdm_base).map_err(|_| EINVAL)?; if r.vdm_base & 3 != 0 || !space.covers(r.vdm_base,4,GpuAccess::Read) || r.scissor_base == 0 || r.scissor_base & 7 != 0 || !space.covers(r.scissor_base,8,GpuAccess::Read) { From 9579e14b493ba179ce2820807d662c83483e0b12 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 25 Nov 2026 03:40:54 +1100 Subject: [PATCH 4/6] drm/asahi: validate helper programs before G14 27.2 queues take them The G14 firmware 27.2 queues take render and compute helper programs from the client and write them into the firmware commands, but nothing checked them first. The common compute translator refuses any helper, so the compute path removed the helper before translation, and the render admission only checked that queues without helper support saw none. Check each helper descriptor before a queue takes it. It must either be empty, or name a tagged program offset that the queue's USC window maps readable, plus an 8-byte-aligned argument block that the submitting VM maps read-write. A configuration word or argument block without a program is refused. The render vertex and fragment helpers and the compute helper all go through the same check, which sits next to the sampler validation in the shared UAPI module. Queues that do not encode helpers refuse them as before. The m3-uapi host test covers empty, valid, stray, unmapped, misaligned and read-only descriptors. Signed-off-by: Ryan Murray --- drivers/gpu/drm/asahi/m3/agx_uapi.rs | 25 ++++++++++++ drivers/gpu/drm/asahi/m3/m3_submit.rs | 16 +++++++- tools/asahi/m3-uapi-tests.rs | 57 +++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/asahi/m3/agx_uapi.rs b/drivers/gpu/drm/asahi/m3/agx_uapi.rs index 028ac81193fbb..64912fffadb99 100644 --- a/drivers/gpu/drm/asahi/m3/agx_uapi.rs +++ b/drivers/gpu/drm/asahi/m3/agx_uapi.rs @@ -599,6 +599,31 @@ pub(crate) fn validate_sampler( Ok(()) } +/// Validates a helper program descriptor for a queue whose commands encode helpers: either no +/// helper (all fields zero), or a tagged program offset that names a readable program in the +/// queue's USC window and an 8-byte-aligned argument block that the submitting VM maps +/// read-write. The configuration word is only accepted together with a program. +pub(crate) fn validate_helper( + queue: QueueUscWindow, + address_space: &A, + helper: UapiHelperProgram, +) -> Result<(), UapiTranslateError> { + if helper + == (UapiHelperProgram { + binary: 0, + config: 0, + data: 0, + }) + { + return Ok(()); + } + queue.full_program(address_space, helper.binary)?; + if helper.data & 7 != 0 { + return Err(UapiTranslateError::AddressAlignment); + } + require_range(address_space, helper.data, 8, GpuAccess::ReadWrite) +} + pub(crate) fn validate_attachments( address_space: &A, attachments: &UapiAttachmentList, diff --git a/drivers/gpu/drm/asahi/m3/m3_submit.rs b/drivers/gpu/drm/asahi/m3/m3_submit.rs index 3ec3e7c00dbb3..92b82e1c8097b 100644 --- a/drivers/gpu/drm/asahi/m3/m3_submit.rs +++ b/drivers/gpu/drm/asahi/m3/m3_submit.rs @@ -398,9 +398,17 @@ impl queue::Queue for Queue { // The common translator validates the original command/attachment // addresses; this M3 scheduling hint changes none of them. payload.flags &= !wide; - // The common translator refuses helpers; a queue that encodes one takes it here. + // The common translator refuses helpers; a queue that encodes one validates and + // takes it here. let empty=agx_uapi::UapiHelperProgram{binary:0,config:0,data:0}; - let helper=if self.samplers_and_helpers {core::mem::replace(&mut payload.helper,empty)} else {empty}; + let helper=if self.samplers_and_helpers { + agx_uapi::validate_helper(agx_uapi::QueueUscWindow{base:self.usc,user_start:0x4000,user_end:(1u64<<42)-0x8000}, + &AddressSpace(&self.vm),payload.helper).map_err(|e| { + pr_err!("M3 compute helper rejected {:?}: helper={:?}\n",e,payload.helper); + EINVAL + })?; + core::mem::replace(&mut payload.helper,empty) + } else {empty}; render_attachments.push([crate::m3::agx_attachments::Attachments::EMPTY;2],GFP_KERNEL)?; flushes.push(encode_attachments(&self.vm,&attachments)?,GFP_KERNEL)?; let c=agx_uapi::translate_compute_command(payload,attachments, @@ -501,5 +509,9 @@ fn validate_render(r: agx_uapi::UapiRenderCommand, usc: u64, space: &AddressSpac window.full_program(space,p.usc).map_err(|_| EINVAL)?; if !space.covers(usc+u64::from(p.usc & !63),64,GpuAccess::Read) { return Err(EINVAL); } } + // Only a queue that encodes helpers gets here with one (refused above otherwise). + for helper in [r.vertex_helper,r.fragment_helper] { + agx_uapi::validate_helper(window,space,helper).map_err(|_| EINVAL)?; + } Ok(()) } diff --git a/tools/asahi/m3-uapi-tests.rs b/tools/asahi/m3-uapi-tests.rs index 4dc6012f5213e..dfbbdfe1c82ac 100644 --- a/tools/asahi/m3-uapi-tests.rs +++ b/tools/asahi/m3-uapi-tests.rs @@ -750,6 +750,63 @@ fn attachment_validation_rejects_readonly_zero_and_wrapped_ranges() { } } +#[test] +fn helpers_are_empty_or_a_mapped_program_with_a_writable_argument_block() { + let queue = QueueUscWindow { + base: USC_WINDOW_SIZE, + user_start: 0x4000, + user_end: 2 * USC_WINDOW_SIZE, + }; + let mut region = Region { + start: queue.base + 8, + end: queue.base + 0x100, + writable: true, + }; + let none = UapiHelperProgram { + binary: 0, + config: 0, + data: 0, + }; + let helper = UapiHelperProgram { + binary: 9, + config: 0x40, + data: queue.base + 0x40, + }; + assert_eq!(validate_helper(queue, ®ion, none), Ok(())); + assert_eq!(validate_helper(queue, ®ion, helper), Ok(())); + // A configuration or argument block without a program. + for stray in [ + UapiHelperProgram { config: 0x40, ..none }, + UapiHelperProgram { data: helper.data, ..none }, + ] { + assert_eq!( + validate_helper(queue, ®ion, stray), + Err(UapiTranslateError::ProgramOffset) + ); + } + // A program outside the mapping, a misaligned, unmapped or missing argument block. + assert_eq!( + validate_helper(queue, ®ion, UapiHelperProgram { binary: 0x200, ..helper }), + Err(UapiTranslateError::AddressRange) + ); + assert_eq!( + validate_helper(queue, ®ion, UapiHelperProgram { data: helper.data + 4, ..helper }), + Err(UapiTranslateError::AddressAlignment) + ); + for data in [0, queue.base + 0x100, u64::MAX & !7] { + assert_eq!( + validate_helper(queue, ®ion, UapiHelperProgram { data, ..helper }), + Err(UapiTranslateError::AddressRange) + ); + } + // The argument block must be writable. + region.writable = false; + assert_eq!( + validate_helper(queue, ®ion, helper), + Err(UapiTranslateError::AddressRange) + ); +} + #[test] fn usc_windows_reject_misalignment_overflow_and_unmapped_programs() { let queue = QueueUscWindow { From 4a0eae2e3f44b4272628787f038d067a1356fc17 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 25 Nov 2026 04:57:26 +1100 Subject: [PATCH 5/6] drm/asahi: flush compute stamps on G14 firmware 27.2 The G14 firmware 27.2 compute command left its JobMeta flush_stamps word clear. That did not matter while compute commands carried no user timestamps. Once they do, a queue of them stops retiring: on the M2 mini, gpubench compute.light at queue depth 16 timed out within one or two runs. The firmware had fetched the commands but never retired them, no MMU fault was pending and no firmware timeout event came. Set flush_stamps, as the 27.2 render commands already do for their JobMeta and as the M3 27.2 compute command does when it does not coalesce. With it, the same loop ran eight times with every case passing and no timeout. Signed-off-by: Ryan Murray --- drivers/gpu/drm/asahi/g14_v27_2_abi.rs | 17 ++++++++++++++++- drivers/gpu/drm/asahi/gpu/v27_2.rs | 3 +++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/asahi/g14_v27_2_abi.rs b/drivers/gpu/drm/asahi/g14_v27_2_abi.rs index dcd5392c0c146..4f7bcd5db970f 100644 --- a/drivers/gpu/drm/asahi/g14_v27_2_abi.rs +++ b/drivers/gpu/drm/asahi/g14_v27_2_abi.rs @@ -103,6 +103,13 @@ pub(crate) const GLOBALS_PSTATE_SELECTORS: [usize; 3] = [0x88, 0x8c, 0x98]; /// after the command time (+0x2c4) and the internal start/end pointers (+0x2cc), the order of /// the 13.5 compute command and of the 27.2 render commands (vertex +0x5e4, fragment +0x948). pub(crate) const COMPUTE_USER_TIMESTAMPS: usize = 0x2dc; + +/// The 27.2 compute command's JobMeta flush_stamps word, after the completion stamp, firmware +/// stamp, stamp value and slot (+0x298..+0x2b4); the render commands keep it at the same place +/// of their JobMeta (vertex +0x5a0, fragment +0x904). Set, the firmware flushes the command's +/// stamps when it completes; left clear, a compute queue whose commands write user timestamps +/// stalls with commands fetched but never retired. +pub(crate) const COMPUTE_FLUSH_STAMPS: usize = 0x2b4; /// The 13.5 compute JobParameters1 inside the 27.2 compute command. pub(crate) const COMPUTE_JOB_PARAMETERS1: usize = 0x68; @@ -256,7 +263,7 @@ mod tests { (0x68, 8), (0x70, 8), (0x78, 8), (0x80, 8), (0x88, 8), (0x90, 8), (0x98, 8), (0xa0, 8), (0xc0, 8), (0x1e8, 8), (0x1f0, 4), (0x220, 8), (0x228, 8), (0x264, 8), (0x270, 4), - (0x298, 0x1c), (0x2c4, 0x18), (0x304, 8), (0x314, 8), (0x334, 0x14), + (0x298, 0x20), (0x2c4, 0x18), (0x304, 8), (0x314, 8), (0x334, 0x14), ]; /// Whether `len` bytes at `at` fit the command and are none the compute encoder uses. @@ -277,6 +284,14 @@ mod tests { } } + #[test] + fn flush_stamps_follows_the_compute_job_meta_and_misses_the_user_pair() { + // The JobMeta words the encoder writes end right before it: slot at +0x2b0. + assert_eq!(COMPUTE_FLUSH_STAMPS, 0x2b0 + 4); + assert!(COMPUTE_FLUSH_STAMPS + 4 <= COMPUTE_USER_TIMESTAMPS); + assert_eq!(COMPUTE_FLUSH_STAMPS % 4, 0); + } + #[test] fn a_timestamp_operation_names_the_pair_only_when_there_is_one() { assert_eq!(user_timestamp_pointer(0x1000, [0, 0]), 0); diff --git a/drivers/gpu/drm/asahi/gpu/v27_2.rs b/drivers/gpu/drm/asahi/gpu/v27_2.rs index 32f606d5066fd..fbb48e706eee5 100644 --- a/drivers/gpu/drm/asahi/gpu/v27_2.rs +++ b/drivers/gpu/drm/asahi/gpu/v27_2.rs @@ -117,6 +117,9 @@ fn encode_compute( put64(cmd, 0x2a0, q.fw_stamp); put32(cmd, 0x2a8, stamp_value); put32(cmd, 0x2b0, q.slot); + // flush_stamps, as the render commands set it: without it a queue of compute commands + // with user timestamps stops retiring. + put32(cmd, g14_v27_2_abi::COMPUTE_FLUSH_STAMPS, 1); put64(cmd, 0x2cc, timestamps); put64(cmd, 0x2d4, timestamps + 8); // Command-local dependency latch, enabled with seed 0; the firmware clears 0x10 bytes From b77cd1686972b877eee326eaaad09df0634578e2 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 25 Nov 2026 10:08:03 +1100 Subject: [PATCH 6/6] drm/asahi: correct the G14 27.2 compute flush_stamps comments The comments added with the compute flush_stamps word said that a clear word stalls a compute queue that writes user timestamps. A later A/B on the M2 mini showed that those hangs came from the raised GPU performance-state cap (reverted in #3091). With the cap restored, the same compute loop ran 24 times clean. Say only why the word is set: the 27.2 render commands and the M3 27.2 compute command set it. Comment-only change. Signed-off-by: Ryan Murray --- drivers/gpu/drm/asahi/g14_v27_2_abi.rs | 5 ++--- drivers/gpu/drm/asahi/gpu/v27_2.rs | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/asahi/g14_v27_2_abi.rs b/drivers/gpu/drm/asahi/g14_v27_2_abi.rs index 0d5823fcd2527..ab5c322a27a7b 100644 --- a/drivers/gpu/drm/asahi/g14_v27_2_abi.rs +++ b/drivers/gpu/drm/asahi/g14_v27_2_abi.rs @@ -100,9 +100,8 @@ pub(crate) const COMPUTE_USER_TIMESTAMPS: usize = 0x2dc; /// The 27.2 compute command's JobMeta flush_stamps word, after the completion stamp, firmware /// stamp, stamp value and slot (+0x298..+0x2b4); the render commands keep it at the same place -/// of their JobMeta (vertex +0x5a0, fragment +0x904). Set, the firmware flushes the command's -/// stamps when it completes; left clear, a compute queue whose commands write user timestamps -/// stalls with commands fetched but never retired. +/// of their JobMeta (vertex +0x5a0, fragment +0x904), and the M3 27.2 compute command sets it +/// when it does not coalesce. Set, the firmware flushes the command's stamps when it completes. pub(crate) const COMPUTE_FLUSH_STAMPS: usize = 0x2b4; /// The 13.5 compute JobParameters1 inside the 27.2 compute command. pub(crate) const COMPUTE_JOB_PARAMETERS1: usize = 0x68; diff --git a/drivers/gpu/drm/asahi/gpu/v27_2.rs b/drivers/gpu/drm/asahi/gpu/v27_2.rs index 1094ae6e308ff..6c141adf21807 100644 --- a/drivers/gpu/drm/asahi/gpu/v27_2.rs +++ b/drivers/gpu/drm/asahi/gpu/v27_2.rs @@ -120,8 +120,7 @@ fn encode_compute( put64(cmd, 0x2a0, q.fw_stamp); put32(cmd, 0x2a8, stamp_value); put32(cmd, 0x2b0, q.slot); - // flush_stamps, as the render commands set it: without it a queue of compute commands - // with user timestamps stops retiring. + // flush_stamps, as the render commands and the M3 27.2 compute command set it. put32(cmd, g14_v27_2_abi::COMPUTE_FLUSH_STAMPS, 1); put64(cmd, 0x2cc, timestamps); put64(cmd, 0x2d4, timestamps + 8);