Skip to content

Commit 7454cb5

Browse files
hoshinolinajannau
authored andcommitted
drm/asahi: queue/render,compute: Plumb through timestamps extension
Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent 1ed45ba commit 7454cb5

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

drivers/gpu/drm/asahi/queue/compute.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,55 @@ impl super::QueueInner::ver {
8080

8181
let mut user_timestamps: fw::job::UserTimestamps = Default::default();
8282

83+
let mut ext_ptr = cmdbuf.extensions;
84+
while ext_ptr != 0 {
85+
// SAFETY: There is a double read from userspace here, but there is no TOCTOU
86+
// issue since at worst the extension parse below will read garbage, and
87+
// we do not trust any fields anyway.
88+
let ext_type = UserSlice::new(ext_ptr as UserPtr, 4)
89+
.reader()
90+
.read::<u32>()?;
91+
92+
match ext_type {
93+
uapi::ASAHI_COMPUTE_EXT_TIMESTAMPS => {
94+
let mut ext_user_timestamps: uapi::drm_asahi_cmd_compute_user_timestamps =
95+
Default::default();
96+
97+
// SAFETY: See above
98+
let mut ext_reader = UserSlice::new(
99+
ext_ptr as UserPtr,
100+
core::mem::size_of::<uapi::drm_asahi_cmd_compute_user_timestamps>(),
101+
)
102+
.reader();
103+
// SAFETY: The output buffer is valid and of the correct size, and all bit
104+
// patterns are valid.
105+
ext_reader.read_raw(unsafe {
106+
core::slice::from_raw_parts_mut(
107+
&mut ext_user_timestamps as *mut _ as *mut MaybeUninit<u8>,
108+
core::mem::size_of::<uapi::drm_asahi_cmd_compute_user_timestamps>(),
109+
)
110+
})?;
111+
112+
user_timestamps.start = common::get_timestamp_object(
113+
objects,
114+
ext_user_timestamps.start_handle,
115+
ext_user_timestamps.start_offset,
116+
)?;
117+
user_timestamps.end = common::get_timestamp_object(
118+
objects,
119+
ext_user_timestamps.end_handle,
120+
ext_user_timestamps.end_offset,
121+
)?;
122+
123+
ext_ptr = ext_user_timestamps.next;
124+
}
125+
_ => {
126+
cls_pr_debug!(Errors, "Unknown extension {}\n", ext_type);
127+
return Err(EINVAL);
128+
}
129+
}
130+
}
131+
83132
// This sequence number increases per new client/VM? assigned to some slot,
84133
// but it's unclear *which* slot...
85134
let slot_client_seq: u8 = (self.id & 0xff) as u8;

drivers/gpu/drm/asahi/queue/render.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,48 @@ impl super::QueueInner::ver {
311311

312312
ext_ptr = unks.next;
313313
}
314+
uapi::ASAHI_RENDER_EXT_TIMESTAMPS => {
315+
let mut ext_user_timestamps: uapi::drm_asahi_cmd_render_user_timestamps =
316+
Default::default();
317+
318+
// SAFETY: See above
319+
let mut ext_reader = UserSlice::new(
320+
ext_ptr as UserPtr,
321+
core::mem::size_of::<uapi::drm_asahi_cmd_render_user_timestamps>(),
322+
)
323+
.reader();
324+
// SAFETY: The output buffer is valid and of the correct size, and all bit
325+
// patterns are valid.
326+
ext_reader.read_raw(unsafe {
327+
core::slice::from_raw_parts_mut(
328+
&mut ext_user_timestamps as *mut _ as *mut MaybeUninit<u8>,
329+
core::mem::size_of::<uapi::drm_asahi_cmd_render_user_timestamps>(),
330+
)
331+
})?;
332+
333+
vtx_user_timestamps.start = common::get_timestamp_object(
334+
objects,
335+
ext_user_timestamps.vtx_start_handle,
336+
ext_user_timestamps.vtx_start_offset,
337+
)?;
338+
vtx_user_timestamps.end = common::get_timestamp_object(
339+
objects,
340+
ext_user_timestamps.vtx_end_handle,
341+
ext_user_timestamps.vtx_end_offset,
342+
)?;
343+
frg_user_timestamps.start = common::get_timestamp_object(
344+
objects,
345+
ext_user_timestamps.frg_start_handle,
346+
ext_user_timestamps.frg_start_offset,
347+
)?;
348+
frg_user_timestamps.end = common::get_timestamp_object(
349+
objects,
350+
ext_user_timestamps.frg_end_handle,
351+
ext_user_timestamps.frg_end_offset,
352+
)?;
353+
354+
ext_ptr = ext_user_timestamps.next;
355+
}
314356
_ => {
315357
cls_pr_debug!(Errors, "Unknown extension {}\n", ext_type);
316358
return Err(EINVAL);

0 commit comments

Comments
 (0)