Skip to content
Draft
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
16 changes: 12 additions & 4 deletions drivers/gpu/drm/asahi/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,12 @@ impl SyncItem {
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 picks the count, and the array is one kmalloc() buffer, which warns past
// KMALLOC_MAX_SIZE. Refuse a larger one first. Charge it to the caller's memcg.
if count as usize > bindings::KMALLOC_MAX_SIZE as usize / core::mem::size_of::<SyncItem>() {
return Err(E2BIG);
}
let mut vec = KVec::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 @@ -425,11 +430,13 @@ impl TableQueue {
}
}

/// Copies the command stream. `max_cmdbuf_size()` has bounded `size`. The buffer is charged
/// to the caller's memcg, as userspace picks its size.
fn copy_cmdbuf_from_user(buf: &mut KVec<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 @@ -1220,7 +1227,8 @@ impl File {
.checked_mul(usize::try_from(data.num_binds)?)
.ok_or(EOVERFLOW)?;
let reader = UserSlice::new(UserPtr::from_addr(data.userptr as usize), size).reader();
reader.read_all(&mut vec, GFP_KERNEL)?;
// Without a GPU batch limit, userspace picks the size: fail, do not warn.
reader.read_all(&mut vec, GFP_KERNEL | __GFP_NOWARN)?;
let mut reader = Reader::new(&vec);

for _i in 0..data.num_binds {
Expand All @@ -1239,7 +1247,7 @@ impl File {
let mut bytes = KVec::new();
UserSlice::new(UserPtr::from_addr(data.userptr as usize), size)
.reader()
.read_all(&mut bytes, GFP_KERNEL)?;
.read_all(&mut bytes, GFP_KERNEL | __GFP_NOWARN)?;
let (vm, user_range, kernel_range) = {
let vms = file.inner().vms();
let guard = vms.lock();
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
6 changes: 5 additions & 1 deletion drivers/gpu/drm/asahi/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,12 @@ impl WorkItem for GpuManager::ver {
/// Operations the DRM driver performs on a GPU, independent of its firmware interface.
pub(crate) trait Gpu: Send + Sync {
/// Admission bound checked before copying the userspace command stream.
///
/// The copy is a kmalloc() buffer, which warns past `KMALLOC_MAX_SIZE`, so that is the
/// default. A GPU whose parser accepts less returns its own limit (G15 and G16: 4 MiB;
/// G17: see `g17::command::MAX_STREAM`).
fn max_cmdbuf_size(&self) -> usize {
usize::MAX
kernel::bindings::KMALLOC_MAX_SIZE as usize
}

/// The firmware statistics snapshot of this GPU, if its firmware reports any.
Expand Down
Loading