Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions drivers/gpu/drm/asahi/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,15 @@ impl SyncItem {
in_count: u32,
out_count: u32,
allow_cumulative: bool,
) -> Result<KVec<SyncItem>> {
) -> Result<KVVec<SyncItem>> {
let count = in_count.checked_add(out_count).ok_or(EOVERFLOW)?;

const STRIDE: usize = core::mem::size_of::<uapi::drm_asahi_sync>();
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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -398,7 +400,7 @@ pub(crate) struct TableQueue {
queue: KBox<dyn queue::Queue>,
/// Reusable staging buffer for `SUBMIT` command buffers, avoiding per-submit heap
/// allocations and keeping large command buffers off the kernel stack.
cmdbuf: KVec<u8>,
cmdbuf: KVVec<u8>,
_share: Option<queue_share::Share>,
}

Expand All @@ -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<u8> {
fn take_cmdbuf(&mut self) -> KVVec<u8> {
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<u8>) {
fn return_cmdbuf(&mut self, mut buf: KVVec<u8>) {
buf.clear();
if buf.capacity() > 0
&& buf.capacity() <= Self::REUSE_CMDBUF_CAP
Expand All @@ -425,11 +427,11 @@ impl TableQueue {
}
}

fn copy_cmdbuf_from_user(buf: &mut KVec<u8>, addr: u64, size: usize) -> Result {
fn copy_cmdbuf_from_user(buf: &mut KVVec<u8>, 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 {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/asahi/g15/fence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ fn install(outputs: impl Iterator<Item = SyncItem>, 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<SyncItem>,
syncs: KVVec<SyncItem>,
input_count: usize,
}

impl Syncs {
pub(crate) fn new(syncs: KVec<SyncItem>, input_count: usize) -> Self {
pub(crate) fn new(syncs: KVVec<SyncItem>, input_count: usize) -> Self {
Self { syncs, input_count }
}

Expand Down
4 changes: 4 additions & 0 deletions drivers/gpu/drm/asahi/g15/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<crate::stats::StatsSnapshot>> {
None
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/asahi/g15/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl crate::queue::Queue for Queue {
&mut self,
_reg_data: &crate::driver::AsahiRegData<'_>,
id: u64,
syncs: KVec<file::SyncItem>,
syncs: KVVec<file::SyncItem>,
in_sync_count: usize,
cmdbuf_raw: &[u8],
objects: Pin<&xarray::XArray<KBox<file::Object>>>,
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/asahi/g16/fence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,13 @@ fn install(outputs: impl Iterator<Item = SyncItem>, fence: &Fence) {
/// contract of `tracked_submission`). Cumulative output bundles reuse the shared
/// `g17::sync_output::SignalBundle` scope chain.
pub(crate) struct Syncs {
syncs: KVec<SyncItem>,
syncs: KVVec<SyncItem>,
input_count: usize,
cumulative: Option<crate::g17::sync_output::SignalBundle>,
}

impl Syncs {
pub(crate) fn new(mut syncs: KVec<SyncItem>, input_count: usize) -> Self {
pub(crate) fn new(mut syncs: KVVec<SyncItem>, input_count: usize) -> Self {
let cumulative = syncs.iter_mut().find_map(|sync| sync.cumulative.take());
Self {
syncs,
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/asahi/g16/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ impl crate::queue::Queue for Queue {
&mut self,
_reg_data: &crate::driver::AsahiRegData<'_>,
id: u64,
syncs: KVec<file::SyncItem>,
syncs: KVVec<file::SyncItem>,
in_sync_count: usize,
cmdbuf_raw: &[u8],
objects: Pin<&xarray::XArray<KBox<file::Object>>>,
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/asahi/g17/fence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ fn install(outputs: impl Iterator<Item = SyncItem>, fence: &Fence) {

pub(crate) struct Outputs {
fallback: Option<UniqueFence<ExportFence>>,
syncs: KVec<SyncItem>,
syncs: KVVec<SyncItem>,
input_count: usize,
submission: Option<Aggregate>,
result: Result,
Expand All @@ -616,7 +616,7 @@ pub(crate) struct Outputs {
impl Outputs {
pub(crate) fn new(
contexts: &FenceContexts,
mut syncs: KVec<SyncItem>,
mut syncs: KVVec<SyncItem>,
input_count: usize,
allocation_failure: &Fence,
) -> Result<Self> {
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/asahi/g17/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ impl<B: Backend> crate::queue::Queue for Queue<B> {
&mut self,
_reg_data: &crate::driver::AsahiRegData<'_>,
id: u64,
syncs: KVec<file::SyncItem>,
syncs: KVVec<file::SyncItem>,
input_count: usize,
bytes: &[u8],
objects: Pin<&xarray::XArray<KBox<file::Object>>>,
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/asahi/g18/drm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl FenceOps for G18SubmissionFence {
/// Dropped unaccepted, it signals the fence with `result` and installs it.
struct OutputPublication {
fence: Option<UserFence<G18SubmissionFence>>,
syncs: KVec<file::SyncItem>,
syncs: KVVec<file::SyncItem>,
input_count: usize,
result: Result,
}
Expand Down Expand Up @@ -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<file::SyncItem>,
syncs: KVVec<file::SyncItem>,
in_sync_count: usize, cmdbuf_raw: &[u8],
objects: Pin<&xarray::XArray<KBox<file::Object>>>) -> Result {
if in_sync_count > syncs.len() { return Err(EINVAL); }
Expand Down
11 changes: 9 additions & 2 deletions drivers/gpu/drm/asahi/m3/m3_submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<file::SyncItem>,in_sync_count:usize,
raw:&[u8],objects:Pin<&xarray::XArray<KBox<file::Object>>>)->Result {
fn submit(
&mut self,
_reg_data: &crate::driver::AsahiRegData<'_>,
_id: u64,
mut syncs: KVVec<file::SyncItem>,
in_sync_count: usize,
raw: &[u8],
objects: Pin<&xarray::XArray<KBox<file::Object>>>,
) -> 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)? {
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/asahi/m5/drm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl FenceOps for M5SubmissionFence {
/// allocation failure after userspace has already supplied its wait targets.
struct OutputPublication {
fence: UserFence<M5SubmissionFence>,
syncs: KVec<file::SyncItem>,
syncs: KVVec<file::SyncItem>,
input_count: usize,
result: Result,
}
Expand Down Expand Up @@ -237,7 +237,7 @@ struct M5Queue {

impl queue::Queue for M5Queue {
fn submit(&mut self, _reg_data: &AsahiRegData<'_>, _submission_id: u64,
syncs: KVec<file::SyncItem>,
syncs: KVVec<file::SyncItem>,
in_sync_count: usize, cmdbuf_raw: &[u8],
_objects: Pin<&xarray::XArray<KBox<file::Object>>>) -> Result {
if in_sync_count > syncs.len() { return Err(EINVAL); }
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/asahi/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub(crate) trait Queue: Send + Sync {
&mut self,
reg_data: &AsahiRegData<'_>,
id: u64,
syncs: KVec<file::SyncItem>,
syncs: KVVec<file::SyncItem>,
in_sync_count: usize,
cmdbuf_raw: &[u8],
objects: Pin<&xarray::XArray<KBox<file::Object>>>,
Expand Down Expand Up @@ -1010,7 +1010,7 @@ impl Queue for Queue::ver {
&mut self,
reg_data: &AsahiRegData<'drm>,
id: u64,
mut syncs: KVec<file::SyncItem>,
mut syncs: KVVec<file::SyncItem>,
in_sync_count: usize,
cmdbuf_raw: &[u8],
objects: Pin<&xarray::XArray<KBox<file::Object>>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def extract_function(text, name):
pub(crate) cumulative: Option<g17::sync_output::SignalBundle>,
}

pub(crate) type KVec<T> = Vec<T>;
pub(crate) type KVVec<T> = Vec<T>;

fn install(outputs: impl Iterator<Item = SyncItem>, fence: &Fence) {
for sync in outputs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#![allow(dead_code,unused_variables)]
use std::pin::Pin;use std::sync::atomic::{AtomicU32,Ordering};
type Result<T=()> = std::result::Result<T,i32>;const ERESTARTSYS:i32=512;const EBUSY:i32=16;
type KVec<T>=Vec<T>;type KBox<T>=Box<T>;
type KVec<T>=Vec<T>;type KVVec<T>=Vec<T>;type KBox<T>=Box<T>;
mod xarray{pub struct XArray<T>(pub T);}
mod file{pub struct SyncItem;pub struct Object;}
mod driver{pub struct AsahiRegData<'a>(pub &'a ());}
Expand Down
Loading