diff --git a/drivers/gpu/drm/asahi/g17/context.rs b/drivers/gpu/drm/asahi/g17/context.rs index cebeb73c78d9a..6836b6c333d9c 100644 --- a/drivers/gpu/drm/asahi/g17/context.rs +++ b/drivers/gpu/drm/asahi/g17/context.rs @@ -293,13 +293,15 @@ impl Context { mmu::PROT_GPU_FW_SHARED_RW }; let exposure = Arc::new(Exposure::new(), GFP_KERNEL)?; + // The scheduler page sits in the upper half, which every execution context includes, + // and only the firmware reads and writes it: it is firmware-only. let mut scheduler = if alloc.uat.is_m5() { let mut object = pool.allocate( alloc, Family::Scheduler, UAT_PGSZ, 0, - kernel_prot, + mmu::PROT_FW_SHARED_RW, CpuMap::WriteCombined, )?; object.defer_once_exposed(&exposure); @@ -308,7 +310,7 @@ impl Context { SchedulerStorage::Ordinary(alloc.kernel( UAT_PGSZ, UAT_PGSZ as u64, - mmu::PROT_GPU_FW_SHARED_RW, + mmu::PROT_FW_SHARED_RW, CpuMap::WriteCombined, )?) }; diff --git a/drivers/gpu/drm/asahi/g17/initdata.rs b/drivers/gpu/drm/asahi/g17/initdata.rs index 56d654e7712f6..1c4a917aa6127 100644 --- a/drivers/gpu/drm/asahi/g17/initdata.rs +++ b/drivers/gpu/drm/asahi/g17/initdata.rs @@ -113,7 +113,9 @@ impl ComputeShared { } /// A device-global scheduler, retained independently of whichever physical queue first -/// needed it. Its generation reservation precedes later graph allocation failures. +/// needed it. Its generation reservation precedes later graph allocation failures. Only the +/// firmware reads and writes it, and it sits in the upper half every execution context +/// includes, so it is firmware-only. pub(super) struct ComputeScheduler { object: KernelObject, } @@ -123,7 +125,7 @@ impl ComputeScheduler { let mut object = alloc.kernel( mmu::UAT_PGSZ, mmu::UAT_PGSZ as u64, - mmu::PROT_GPU_FW_SHARED_RW, + mmu::PROT_FW_SHARED_RW, CpuMap::WriteCombined, )?; object.initialize::(0, |state| { diff --git a/drivers/gpu/drm/asahi/g17/kick.rs b/drivers/gpu/drm/asahi/g17/kick.rs index 43e1115f221f0..7f365425f5d78 100644 --- a/drivers/gpu/drm/asahi/g17/kick.rs +++ b/drivers/gpu/drm/asahi/g17/kick.rs @@ -690,18 +690,13 @@ impl Queue { } } let (vm, status) = (client.id(), client.status().cloned()); - // The firmware's mapping sits in the upper half, which every execution context includes. - // On M5 it is firmware-only, as a compute ring's is; the GPU reads the ring at its lower + // The firmware's mapping sits in the upper half, which every execution context includes, + // so it is firmware-only, as a compute ring's is: the GPU reads the ring at its lower // address. - let firmware_prot = if alloc.uat.is_m5() { - mmu::PROT_FW_SHARED_RW - } else { - mmu::PROT_GPU_FW_SHARED_RW - }; let high = alloc.kernel( KICK_RING_SIZE, mmu::UAT_PGSZ as u64, - firmware_prot, + mmu::PROT_FW_SHARED_RW, CpuMap::WriteCombined, )?; let mut range = alloc.uat.kernel_lower_dynamic_range(); diff --git a/drivers/gpu/drm/asahi/g17/queue/compute.rs b/drivers/gpu/drm/asahi/g17/queue/compute.rs index 968ca6a9bf012..06bd738c22831 100644 --- a/drivers/gpu/drm/asahi/g17/queue/compute.rs +++ b/drivers/gpu/drm/asahi/g17/queue/compute.rs @@ -114,8 +114,8 @@ impl DescriptorRing { /// does render descriptors: the host rewrites a slot only after the kick /// that last used it retired (at most `DESCRIPTORS` kicks are in flight), /// by when that kick's accounting store is in memory. The hardware reads - /// the same pages through an uncached canonical low alias; on M5 the - /// kernel mapping, in the upper half every execution context includes, is + /// the same pages through an uncached canonical low alias; the kernel + /// mapping, in the upper half every execution context includes, is /// firmware-only. pub(crate) fn new(alloc: &Allocator<'_>, objects: &Arc) -> Result { let size = DESCRIPTORS * COMPUTE_DESCRIPTOR_SIZE; @@ -124,7 +124,7 @@ impl DescriptorRing { Family::Descriptor, size, if alloc.uat.is_m5() { 0 } else { size }, - if alloc.uat.is_m5() { mmu::PROT_FW_SHARED_RW } else { mmu::PROT_GPU_FW_SHARED_RW }, + mmu::PROT_FW_SHARED_RW, CpuMap::WriteCombined, )?; let low = object.alias_in( @@ -181,14 +181,19 @@ impl Graph { mcache: bool, ) -> Result { let page = mmu::UAT_PGSZ as u64; - let prot = mmu::PROT_GPU_FW_SHARED_RW; + // The kernel's mappings of the queue's records sit in the upper half, which every + // execution context includes: only the firmware reaches them there. The GPU reaches the + // preemption buffer and usage page through the aliases a binding maps into its VM. + let prot = mmu::PROT_FW_SHARED_RW; + // The kernel lower VM is context 0's alone. + let lower = mmu::PROT_GPU_FW_SHARED_RW; let cpu = CpuMap::WriteCombined; let ring = DescriptorRing::new(alloc, objects)?; let preempt = alloc.kernel(0x4000, page, prot, cpu)?; let usage = alloc.kernel(mmu::UAT_PGSZ, page, prot, cpu)?; - let operand = alloc.lower(operand_state.size, page, prot, cpu)?; + let operand = alloc.lower(operand_state.size, page, lower, cpu)?; // The M5 support page is firmware-only; the GPU has no access to it. - let support_prot = if m5 { mmu::PROT_FW_SHARED_RW } else { prot }; + let support_prot = if m5 { mmu::PROT_FW_SHARED_RW } else { mmu::PROT_GPU_FW_SHARED_RW }; let mut support = alloc.kernel(if m5 { mmu::UAT_PGSZ } else { 0xc000 }, page, support_prot, cpu)?; if !m5 { let support_va = support.gpu_va(); @@ -231,12 +236,13 @@ impl Graph { graph.write(0, QueueRecord::new(&record))?; } let (context_low, context_high) = if m5 { (None, None) } else { - (Some(alloc.lower(CONTEXT_SIZE, page, prot, cpu)?), + (Some(alloc.lower(CONTEXT_SIZE, page, lower, cpu)?), Some(alloc.kernel(CONTEXT_SIZE, page, prot, cpu)?)) }; let records = alloc.kernel(RECORD_SLOTS * RECORD_STRIDE, page, prot, cpu)?; let m5_timestamps = if m5 { - Some(Arc::new(alloc.kernel(RECORD_SLOTS * 16, page, prot, cpu)?, GFP_KERNEL)?) + Some(Arc::new(alloc.kernel(RECORD_SLOTS * 16, page, mmu::PROT_GPU_FW_SHARED_RW, cpu)?, + GFP_KERNEL)?) } else { None }; let cached_records = objects.allocate( alloc, diff --git a/drivers/gpu/drm/asahi/g17/queue/render/memory.rs b/drivers/gpu/drm/asahi/g17/queue/render/memory.rs index ee973609ad3d3..cfbccd57f52be 100644 --- a/drivers/gpu/drm/asahi/g17/queue/render/memory.rs +++ b/drivers/gpu/drm/asahi/g17/queue/render/memory.rs @@ -120,21 +120,22 @@ impl Graph { qids: [u8; 2], pointers: fw::variant::PointerLayout, ) -> Result { - let prot = mmu::PROT_GPU_FW_SHARED_RW; + // The kernel's mappings of a pair's command storage and queue records sit in the upper + // half, which every execution context includes: only the firmware reaches them there. + // The GPU reads command storage only through the read-only aliases below. + let prot = mmu::PROT_FW_SHARED_RW; let m5 = alloc.uat.is_m5(); // M5 selects cached firmware attributes at initial mapping creation; // write-combined CPU stores also support the uncached capacity fallback. let cpu = if m5 { CpuMap::WriteCombined } else { CpuMap::WriteBack }; let bytes = if m5 { RECORDS * fw::m5::render_assembly::COMMAND_STORAGE_BYTES } else { TA_BYTES + FRAGMENT_BYTES }; - // The GPU reads command storage only through the read-only aliases below. On M5 the - // kernel mapping, in the upper half every execution context includes, is firmware-only. let descriptors = pool.allocate( alloc, Family::Descriptor, bytes, bytes, - if m5 { mmu::PROT_FW_SHARED_RW } else { prot }, + prot, cpu, )?; let ta = Aliases::new(&descriptors, alloc, context.vm(),