diff --git a/drivers/gpu/drm/asahi/file.rs b/drivers/gpu/drm/asahi/file.rs index fc2d2dd6cedaf..68dfb87fb293b 100644 --- a/drivers/gpu/drm/asahi/file.rs +++ b/drivers/gpu/drm/asahi/file.rs @@ -295,13 +295,15 @@ impl SyncItem { in_count: u32, out_count: u32, allow_cumulative: bool, - ) -> Result> { + ) -> Result> { let count = in_count.checked_add(out_count).ok_or(EOVERFLOW)?; const STRIDE: usize = core::mem::size_of::(); const CHUNK: usize = 8; let size = STRIDE.checked_mul(count as usize).ok_or(EOVERFLOW)?; - let mut vec = KVec::with_capacity(count as usize, GFP_KERNEL)?; + // Userspace sets the count. Charge the allocation to the caller and + // allow noncontiguous backing pages. + let mut vec = KVVec::with_capacity(count as usize, GFP_KERNEL_ACCOUNT)?; let mut anchor = None; // Read each record once in small stack chunks so validation and use see the @@ -334,7 +336,7 @@ impl SyncItem { } vec.push( Self::parse_one(file, sync, i >= in_count, allow_cumulative)?, - GFP_KERNEL, + GFP_KERNEL_ACCOUNT, )?; } base += chunk as u32; @@ -398,7 +400,7 @@ pub(crate) struct TableQueue { queue: KBox, /// Reusable staging buffer for `SUBMIT` command buffers, avoiding per-submit heap /// allocations and keeping large command buffers off the kernel stack. - cmdbuf: KVec, + cmdbuf: KVVec, _share: Option, } @@ -408,13 +410,13 @@ impl TableQueue { /// Takes the cached command-buffer staging allocation so userspace copies run outside the /// queue mutex (preventing `queue.lock()` -> `mmap_lock` lock-order inversion). - fn take_cmdbuf(&mut self) -> KVec { + fn take_cmdbuf(&mut self) -> KVVec { core::mem::take(&mut self.cmdbuf) } /// Returns a cleared command-buffer allocation to the per-queue cache when within the /// reuse capacity cap; oversized buffers are dropped. - fn return_cmdbuf(&mut self, mut buf: KVec) { + fn return_cmdbuf(&mut self, mut buf: KVVec) { buf.clear(); if buf.capacity() > 0 && buf.capacity() <= Self::REUSE_CMDBUF_CAP @@ -425,11 +427,11 @@ impl TableQueue { } } -fn copy_cmdbuf_from_user(buf: &mut KVec, addr: u64, size: usize) -> Result { +fn copy_cmdbuf_from_user(buf: &mut KVVec, addr: u64, size: usize) -> Result { buf.clear(); UserSlice::new(UserPtr::from_addr(addr as usize), size) .reader() - .read_all(buf, GFP_KERNEL) + .read_all(buf, GFP_KERNEL_ACCOUNT) } impl Deref for TableQueue { @@ -1855,7 +1857,7 @@ impl File { resv.fill(Arc::pin_init( new_mutex!(TableQueue { queue, - cmdbuf: KVec::new(), + cmdbuf: KVVec::new(), _share: share, }), GFP_KERNEL, diff --git a/drivers/gpu/drm/asahi/g15/fence.rs b/drivers/gpu/drm/asahi/g15/fence.rs index bb85764228070..55a85472a794d 100644 --- a/drivers/gpu/drm/asahi/g15/fence.rs +++ b/drivers/gpu/drm/asahi/g15/fence.rs @@ -179,12 +179,12 @@ fn install(outputs: impl Iterator, fence: &Fence) { /// accepted, a signalled error fence when the submission is refused (the shared `file.rs` /// contract of `tracked_submission`). pub(crate) struct Syncs { - syncs: KVec, + syncs: KVVec, input_count: usize, } impl Syncs { - pub(crate) fn new(syncs: KVec, input_count: usize) -> Self { + pub(crate) fn new(syncs: KVVec, input_count: usize) -> Self { Self { syncs, input_count } } diff --git a/drivers/gpu/drm/asahi/g15/mod.rs b/drivers/gpu/drm/asahi/g15/mod.rs index 6d5ca934a0ff2..f59cd893bf9e5 100644 --- a/drivers/gpu/drm/asahi/g15/mod.rs +++ b/drivers/gpu/drm/asahi/g15/mod.rs @@ -589,6 +589,10 @@ impl Firmware { } impl gpu::Gpu for Gpu { + fn max_cmdbuf_size(&self) -> usize { + command::MAX_CMDBUF + } + fn stats_snapshot(&self) -> Option> { None } diff --git a/drivers/gpu/drm/asahi/g15/queue.rs b/drivers/gpu/drm/asahi/g15/queue.rs index 03a8f46c8a0fc..3bdebb7995e44 100644 --- a/drivers/gpu/drm/asahi/g15/queue.rs +++ b/drivers/gpu/drm/asahi/g15/queue.rs @@ -212,7 +212,7 @@ impl crate::queue::Queue for Queue { &mut self, _reg_data: &crate::driver::AsahiRegData<'_>, id: u64, - syncs: KVec, + syncs: KVVec, in_sync_count: usize, cmdbuf_raw: &[u8], objects: Pin<&xarray::XArray>>, diff --git a/drivers/gpu/drm/asahi/g16/fence.rs b/drivers/gpu/drm/asahi/g16/fence.rs index e223c74f9c853..60d7662352318 100644 --- a/drivers/gpu/drm/asahi/g16/fence.rs +++ b/drivers/gpu/drm/asahi/g16/fence.rs @@ -562,13 +562,13 @@ fn install(outputs: impl Iterator, fence: &Fence) { /// contract of `tracked_submission`). Cumulative output bundles reuse the shared /// `g17::sync_output::SignalBundle` scope chain. pub(crate) struct Syncs { - syncs: KVec, + syncs: KVVec, input_count: usize, cumulative: Option, } impl Syncs { - pub(crate) fn new(mut syncs: KVec, input_count: usize) -> Self { + pub(crate) fn new(mut syncs: KVVec, input_count: usize) -> Self { let cumulative = syncs.iter_mut().find_map(|sync| sync.cumulative.take()); Self { syncs, diff --git a/drivers/gpu/drm/asahi/g16/queue.rs b/drivers/gpu/drm/asahi/g16/queue.rs index 7fadc1a3af5d7..900af17ebe8cb 100644 --- a/drivers/gpu/drm/asahi/g16/queue.rs +++ b/drivers/gpu/drm/asahi/g16/queue.rs @@ -390,7 +390,7 @@ impl crate::queue::Queue for Queue { &mut self, _reg_data: &crate::driver::AsahiRegData<'_>, id: u64, - syncs: KVec, + syncs: KVVec, in_sync_count: usize, cmdbuf_raw: &[u8], objects: Pin<&xarray::XArray>>, diff --git a/drivers/gpu/drm/asahi/g17/fence.rs b/drivers/gpu/drm/asahi/g17/fence.rs index d47b4f2f88fd8..f31cd4164f05e 100644 --- a/drivers/gpu/drm/asahi/g17/fence.rs +++ b/drivers/gpu/drm/asahi/g17/fence.rs @@ -607,7 +607,7 @@ fn install(outputs: impl Iterator, fence: &Fence) { pub(crate) struct Outputs { fallback: Option>, - syncs: KVec, + syncs: KVVec, input_count: usize, submission: Option, result: Result, @@ -616,7 +616,7 @@ pub(crate) struct Outputs { impl Outputs { pub(crate) fn new( contexts: &FenceContexts, - mut syncs: KVec, + mut syncs: KVVec, input_count: usize, allocation_failure: &Fence, ) -> Result { diff --git a/drivers/gpu/drm/asahi/g17/queue/mod.rs b/drivers/gpu/drm/asahi/g17/queue/mod.rs index f480b7cda3dec..2bb536c65a68a 100644 --- a/drivers/gpu/drm/asahi/g17/queue/mod.rs +++ b/drivers/gpu/drm/asahi/g17/queue/mod.rs @@ -525,7 +525,7 @@ impl crate::queue::Queue for Queue { &mut self, _reg_data: &crate::driver::AsahiRegData<'_>, id: u64, - syncs: KVec, + syncs: KVVec, input_count: usize, bytes: &[u8], objects: Pin<&xarray::XArray>>, diff --git a/drivers/gpu/drm/asahi/g18/drm.rs b/drivers/gpu/drm/asahi/g18/drm.rs index 650b8e8e94111..102465bb006f4 100644 --- a/drivers/gpu/drm/asahi/g18/drm.rs +++ b/drivers/gpu/drm/asahi/g18/drm.rs @@ -286,7 +286,7 @@ impl FenceOps for G18SubmissionFence { /// Dropped unaccepted, it signals the fence with `result` and installs it. struct OutputPublication { fence: Option>, - syncs: KVec, + syncs: KVVec, input_count: usize, result: Result, } @@ -707,7 +707,7 @@ impl queue::Queue for G18Queue { /// userspace nothing to wait on (Mesa's G18G split compute prepass reads /// GPU results after such submissions). fn submit(&mut self, _reg_data: &AsahiRegData<'_>, submission_id: u64, - syncs: KVec, + syncs: KVVec, in_sync_count: usize, cmdbuf_raw: &[u8], objects: Pin<&xarray::XArray>>) -> Result { if in_sync_count > syncs.len() { return Err(EINVAL); } diff --git a/drivers/gpu/drm/asahi/m3/m3_submit.rs b/drivers/gpu/drm/asahi/m3/m3_submit.rs index e56d4755e58ce..314e9da622c33 100644 --- a/drivers/gpu/drm/asahi/m3/m3_submit.rs +++ b/drivers/gpu/drm/asahi/m3/m3_submit.rs @@ -365,8 +365,15 @@ impl Queue { } } impl queue::Queue for Queue { - fn submit(&mut self,_reg_data:&crate::driver::AsahiRegData<'_>,_id:u64,mut syncs:KVec,in_sync_count:usize, - raw:&[u8],objects:Pin<&xarray::XArray>>)->Result { + fn submit( + &mut self, + _reg_data: &crate::driver::AsahiRegData<'_>, + _id: u64, + mut syncs: KVVec, + in_sync_count: usize, + raw: &[u8], + objects: Pin<&xarray::XArray>>, + ) -> Result { let vm_job=self.vm.retain_job()?; let mut parser=agx_uapi::UapiCommandParser::new(raw);let mut commands=KVec::new();let mut timestamps=KVec::new();let mut flushes=KVec::new();let mut visibility=KVec::new();let mut render_attachments=KVec::new(); while let Some(command)=parser.next_hardware().map_err(|_|EINVAL)? { diff --git a/drivers/gpu/drm/asahi/m5/drm.rs b/drivers/gpu/drm/asahi/m5/drm.rs index 97e1ba90002d4..4ee01fced0310 100644 --- a/drivers/gpu/drm/asahi/m5/drm.rs +++ b/drivers/gpu/drm/asahi/m5/drm.rs @@ -196,7 +196,7 @@ impl FenceOps for M5SubmissionFence { /// allocation failure after userspace has already supplied its wait targets. struct OutputPublication { fence: UserFence, - syncs: KVec, + syncs: KVVec, input_count: usize, result: Result, } @@ -237,7 +237,7 @@ struct M5Queue { impl queue::Queue for M5Queue { fn submit(&mut self, _reg_data: &AsahiRegData<'_>, _submission_id: u64, - syncs: KVec, + syncs: KVVec, in_sync_count: usize, cmdbuf_raw: &[u8], _objects: Pin<&xarray::XArray>>) -> Result { if in_sync_count > syncs.len() { return Err(EINVAL); } diff --git a/drivers/gpu/drm/asahi/queue/mod.rs b/drivers/gpu/drm/asahi/queue/mod.rs index 6a730f8af2d4a..d8621b2b36761 100644 --- a/drivers/gpu/drm/asahi/queue/mod.rs +++ b/drivers/gpu/drm/asahi/queue/mod.rs @@ -197,7 +197,7 @@ pub(crate) trait Queue: Send + Sync { &mut self, reg_data: &AsahiRegData<'_>, id: u64, - syncs: KVec, + syncs: KVVec, in_sync_count: usize, cmdbuf_raw: &[u8], objects: Pin<&xarray::XArray>>, @@ -1010,7 +1010,7 @@ impl Queue for Queue::ver { &mut self, reg_data: &AsahiRegData<'drm>, id: u64, - mut syncs: KVec, + mut syncs: KVVec, in_sync_count: usize, cmdbuf_raw: &[u8], objects: Pin<&xarray::XArray>>, diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-fence-signalling.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-fence-signalling.py index ffc523fa9f5e3..b985dad1a9ed5 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-fence-signalling.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-fence-signalling.py @@ -382,7 +382,7 @@ def extract_function(text, name): pub(crate) cumulative: Option, } - pub(crate) type KVec = Vec; + pub(crate) type KVVec = Vec; fn install(outputs: impl Iterator, fence: &Fence) { for sync in outputs { diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-submit-restart.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-submit-restart.py index adbbf7cdaa39f..8bbd90ad88e2f 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-submit-restart.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-submit-restart.py @@ -11,7 +11,7 @@ #![allow(dead_code,unused_variables)] use std::pin::Pin;use std::sync::atomic::{AtomicU32,Ordering}; type Result = std::result::Result;const ERESTARTSYS:i32=512;const EBUSY:i32=16; -type KVec=Vec;type KBox=Box; +type KVec=Vec;type KVVec=Vec;type KBox=Box; mod xarray{pub struct XArray(pub T);} mod file{pub struct SyncItem;pub struct Object;} mod driver{pub struct AsahiRegData<'a>(pub &'a ());}