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
12 changes: 10 additions & 2 deletions drivers/gpu/drm/asahi/g18/boot/compute_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ impl G18Session {
translated: &crate::g18::uapi::command::TranslatedComputeCommand)
-> core::result::Result<(), Failure> {
self.poll_idle_faults("application compute prepare")?;
let (command, pool, generation, knobs) = self.memory.as_mut().ok_or(EIO)?
.prepare_application_compute(&self.dev, vm, translated)?;
let memory = self.memory.as_mut().ok_or(EIO)?;
let (command, pool, generation, knobs) =
match memory.prepare_application_compute(&self.dev, vm, translated) {
Ok(prepared) => prepared,
// A refusal that left the owner retired and nothing
// published fails this job only.
Err(error) => return Err(if memory.application_compute_unpublished() {
Failure::Job(JobFailure::Refused(error))
} else { Failure::Fatal(error) }),
};
if generation == 1 {
self.queue_probe.as_mut().ok_or(EIO)?.prepare_initial_context(command.context_id)?;
for phase in 1..=3 {
Expand Down
5 changes: 5 additions & 0 deletions drivers/gpu/drm/asahi/g18/boot/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ pub(super) enum JobFailure {
Released,
/// [`Self::Stranded`] as reported back to the submitting thread.
Retained,
/// Refused while being prepared from the client's own state (its VM
/// closed, an address it names unmapped, an allocation it sized): nothing
/// of the job reached the firmware and its owner is back where the last
/// retirement left it. The session and the path keep serving.
Refused(Error),
}

/// How far a failed task reaches.
Expand Down
16 changes: 15 additions & 1 deletion drivers/gpu/drm/asahi/g18/boot/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl ApplicationOwner {
Err(Failure::Fatal(error))=>error.to_errno(),
Err(Failure::Job(JobFailure::Recovered(_) | JobFailure::Unbound(..) | JobFailure::Released))=>JobOutcome::Recovered as i32,
Err(Failure::Job(JobFailure::Stranded(..) | JobFailure::Retained))=>JobOutcome::Stranded as i32,
Err(Failure::Job(JobFailure::Refused(error)))=>JobOutcome::Refused as i32-error.to_errno(),
}
}

Expand All @@ -114,6 +115,8 @@ impl ApplicationOwner {
0 => Ok(()),
code if code==JobOutcome::Recovered as i32 => Err(Failure::Job(JobFailure::Released)),
code if code==JobOutcome::Stranded as i32 => Err(Failure::Job(JobFailure::Retained)),
code if code>JobOutcome::Refused as i32 =>
Err(Failure::Job(JobFailure::Refused(Error::from_errno(JobOutcome::Refused as i32-code)))),
errno => Err(Failure::Fatal(Error::from_errno(errno))),
}
}
Expand All @@ -125,6 +128,8 @@ impl ApplicationOwner {
match result {
Ok(()) => Ok(()),
Err(Failure::Job(JobFailure::Released)) | Err(Failure::Job(JobFailure::Recovered(_))) => Err(EIO),
// Nothing ran: the client's VM stays usable.
Err(Failure::Job(JobFailure::Refused(error))) => Err(error),
Err(Failure::Job(_)) => {if let Some(status)=vm.status(){status.record(EIO);}Err(EIO)}
Err(Failure::Fatal(error)) => {if let Some(status)=vm.status(){status.record(error);}Err(error)}
}
Expand All @@ -137,6 +142,8 @@ const TICKET_RUNNING: i32 = 1;
enum JobOutcome {
Recovered = 2,
Stranded = 3,
/// Plus the errno: [`JobFailure::Refused`].
Refused = 0x1000,
}

impl G18Runtime for ApplicationOwner {
Expand Down Expand Up @@ -200,6 +207,9 @@ fn log_job_failure(session:&G18Session,failure:&JobFailure) {
JobFailure::Unbound(r,path,unready) => dev_err!(session.device(),
"G18_APP_JOB_FAILED error={:?} recovery epoch={} host={} us={} reason={:#x} slot-mask={:#x} queues=retired unbound={} path={:?} quarantined session=live recoveries={}\n",
EIO,r.epoch,r.host,r.us,r.cause.reason,r.cause.slot_mask,unready,path,recovery::recoveries()),
// The submitter's own error, returned to it: not logged above debug level.
JobFailure::Refused(error) => dev_dbg!(session.device(),
"G18_APP_JOB_REFUSED error={:?} unpublished session=live\n",error),
// Only the submitting thread's summaries; the worker logs the rest.
JobFailure::Released | JobFailure::Retained => {}
}
Expand All @@ -213,7 +223,11 @@ impl G18Session {
self.application_job=Some(ApplicationJob::new(self.render_job.take().ok_or(EIO)?)?);
}
let job=self.application_job.as_mut().ok_or(EIO)?;
job.prepare(&self.dev,&self.uat,vm,render)?;
if let Err(error)=job.prepare(&self.dev,&self.uat,vm,render) {
// Nothing is published before prepare() commits the frame: a
// job it refused leaves the owner retired, the session serves on.
return Err(if job.unpublished() {Failure::Job(JobFailure::Refused(error))} else {Failure::Fatal(error)});
}
if job.pool_aliases.is_empty() {
job.pool_aliases=self.memory.as_mut().ok_or(EIO)?.application_aliases(vm)?;
}
Expand Down
23 changes: 23 additions & 0 deletions drivers/gpu/drm/asahi/g18/buffer/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ pub(crate) struct G18UmaPoolMemory {
low_bias: u64,
hardware_slot: u32,
block_stride: u64,
/// The client VM an application path last aliased the scratch blocks
/// into; None before the first.
client_vm: Option<u64>,
}

impl G18UmaPoolMemory {
Expand All @@ -109,10 +112,29 @@ impl G18UmaPoolMemory {
|| !self.process_aliases.is_empty() {
return Err(EINVAL);
}
self.clear_scratch_for(vm)?;
self.alias_into_process(dev, uat, vm)?;
Ok(core::mem::replace(&mut self.process_aliases, KVec::new()))
}

/// The scratch blocks hold the private memory of the last client VM's
/// threads. Storage released by that VM may still hold its data; clear
/// it before another VM maps it (construction leaves it zero). The
/// directory, block list, state and descriptor are kept: they name the
/// pool's own objects and the hardware owns their allocation cursors.
/// The caller proved the pool's last job retired and dropped the
/// previous VM's aliases. The same VM again clears nothing.
fn clear_scratch_for(&mut self, vm: &mmu::Vm) -> Result {
if self.client_vm.is_some_and(|id| id != vm.id()) {
for block in self.scratch.iter_mut() {
block.with_bytes_mut(|bytes| { bytes.fill(0); Ok(()) })?;
}
fence(Ordering::SeqCst);
}
self.client_vm = Some(vm.id());
Ok(())
}

/// The retained backing plan; application compute bounds its SMA pair by it.
pub(crate) fn scratch_plan(&self) -> Option<g18_uma::G18ComputeScratchPlan> {
self.scratch_plan
Expand Down Expand Up @@ -283,6 +305,7 @@ impl G18UmaPoolMemory {
descriptor_loaded: false,
render: false, low_bias, hardware_slot,
block_stride: if low_bias == 0 { BLOCK_DATA_STRIDE } else { 0x300000 },
client_vm: None,
})
}

Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/asahi/g18/buffer/pool_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl G18UmaPoolMemory {
pub(crate) fn application_aliases(&mut self, uat: &mmu::Uat, vm: &mmu::Vm)
-> Result<KVec<mmu::KernelMapping>> {
if !self.render || self.scratch_plan.is_none() {return Err(EINVAL);}
self.clear_scratch_for(vm)?;
let mut aliases=KVec::new();
for (index,page) in self.directory.iter_mut().enumerate() {
let address=DIRECTORY_BASE+self.layout.page_offset(index as u32).ok_or(EINVAL)?;
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/asahi/g18/buffer/pool_shared_compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ impl G18UmaPoolMemory {
let mut pool = Self::new_layout(dev, uat, high.clone(), 12,
true, false, bias, 1, G18_COMPUTE_BLOCK_BYTES)?;
pool.prepare_shared_compute_retaining(dev, uat, high, plan, Some(self))?;
// The retained scratch objects carry the last client's data along.
pool.client_vm = self.client_vm;
Ok(pool)
}

Expand Down
6 changes: 3 additions & 3 deletions drivers/gpu/drm/asahi/g18/drm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ pub(crate) trait G18DrmRuntime: G18RenderJobSink {
/// Adapter options fixed at registration.
#[derive(Debug, Copy, Clone, Default)]
pub(crate) struct G18DrmConfig {
/// Admit compute commands (module parameter `g18_admit_compute`, default 0).
/// Admit compute commands (module parameter `g18_admit_compute`, default 1).
pub(crate) admit_compute: bool,
/// Admit exactly the native 4x MSAA render set (module parameter
/// `g18_admit_msaa4`, default 0; msaa163). Off refuses every
/// `g18_admit_msaa4`, default 1; msaa163). Off refuses every
/// multisampled render as before.
pub(crate) admit_msaa4: bool,
/// Admit renders carrying `DRM_ASAHI_RENDER_G18_RESOURCES` (module
/// parameter `g18_admit_graphics_scratch`, default 0). Off leaves the
/// parameter `g18_admit_graphics_scratch`, default 1). Off leaves the
/// feature unadvertised and refuses the flag, so Mesa keeps refusing
/// draws whose programs need a thread-private frame.
pub(crate) admit_graphics_scratch: bool,
Expand Down
12 changes: 12 additions & 0 deletions drivers/gpu/drm/asahi/g18/initdata/application_compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,18 @@ impl G18FirmwareMemory {
Ok((prepared, job.binding, generation, knobs))
}

/// Whether the compute owner is as the last retirement left it, with no
/// process, command or context published: a failed preparation that
/// leaves this true changed nothing the firmware uses. Before the owner
/// exists, its scheduler record must not be armed yet.
pub(crate) fn application_compute_unpublished(&self) -> bool {
self.compute.unpublished_idle() && match self.application_compute.as_ref() {
Some(job) => job.retired && job.guard.is_none() && job.aliases.is_empty()
&& job.previous_pool.is_none() && job.previous_binding.is_none(),
None => self.scheduler.binding(0).is_err(),
}
}

/// The binding the firmware must still own before the next tag15.
pub(crate) fn application_compute_previous_binding(&self) -> Result<(G18UmaPoolBinding, u32)> {
let job = self.application_compute.as_ref().ok_or(EIO)?;
Expand Down
23 changes: 23 additions & 0 deletions drivers/gpu/drm/asahi/g18/queue/graphics_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,29 @@ impl G18ParameterBuffer {
Ok(aliases)
}

/// Storage the previous VM's renders wrote (every block, grown ones
/// included, the scene scratch and the discard page) may still hold its
/// data; clear it before another VM maps it. Construction leaves it zero.
/// The page list, block table, scene records, metrics and ring cursors
/// are kept: they name the PB's own objects and the PM owns their
/// progress. The caller proved the render retired and dropped the
/// previous VM's aliases.
pub(crate) fn clear_client_data(&mut self) -> Result {
let clear = |object: &mut MappedObject| {
object.with_bytes_mut(|bytes| {
bytes.fill(0);
Ok(())
})
};
for block in self.blocks.iter_mut() {
clear(block)?;
}
clear(&mut self.scene_scratch)?;
clear(&mut self.discard)?;
fence(Ordering::SeqCst);
Ok(())
}

/// Blocks backed so far: the initial ones plus every growth.
fn backed_blocks(&self) -> Result<u32> {
let bytes: usize = self.blocks.iter().map(|block| block.logical_size).sum();
Expand Down
23 changes: 19 additions & 4 deletions drivers/gpu/drm/asahi/g18/runtime/graphics_job_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ impl ApplicationJob {
if let Some(status)=self.job.vm().status(){status.record(EIO);}
}
pub(crate) fn retired(&mut self) {self.retired=true;self.guard=None;}
/// No frame is committed: the last one retired and none was prepared
/// since, so the firmware holds nothing of this job beyond it.
pub(crate) fn unpublished(&self) -> bool {self.retired && self.guard.is_none()}
/// One of the first frames of its client: logged even when job logging
/// is sparse, so every isolated client leaves a kick/retirement pair.
pub(crate) fn traced(&self) -> bool {self.client_frames<=3}
Expand All @@ -89,8 +92,13 @@ impl ApplicationJob {
if remap {
self.job.program.rebind_retired(&self.storage)?;
self.user_aliases.clear();self.pool_aliases.clear();
// The last frame retired (checked above) and the previous VM's
// views are gone: clear what its renders left before this VM
// maps the PB. The pool scratch is cleared as it is aliased.
if new_client && self.generation!=0 {self.job.parameter_buffer.clear_client_data()?;}
}
if self.generation==0 {
// Once: a first frame refused after this keeps the alias.
if self.generation==0 && self.job.aliases.is_empty() {
let alias=self.job.graph.map_alias_at(uat.kernel_lower_vm(),va::GRAPHICS_JOB_LOW,
mmu::PROT_GPU_SHARED_RW)?;
self.job.aliases.push(alias,GFP_KERNEL)?;
Expand All @@ -110,16 +118,19 @@ impl ApplicationJob {
}
}
if remap {
// The job context only reads the commands' register lists here
// (the RCE addresses encode_into places at GRAPHICS_JOB_LOW);
// firmware uses GRAPHICS_JOB_HIGH. The client view is read-only,
// as g17 maps M5 command storage, so the client's own GPU work
// cannot rewrite commands after the kernel encoded and audited them.
self.user_aliases.push(self.job.graph.map_alias_at(vm,va::GRAPHICS_JOB_LOW,
mmu::PROT_GPU_SHARED_RW)?,GFP_KERNEL)?;
mmu::PROT_GPU_SHARED_RO)?,GFP_KERNEL)?;
let aliases=self.job.parameter_buffer.application_aliases(vm)?;
for alias in aliases {self.user_aliases.push(alias,GFP_KERNEL)?;}
}
// Retract even an unchanged root before publish_h1's fresh lease
// publication. Retain the mappings when the actual VM is unchanged.
self.job.program.rebind_retired(vm)?;
self.guard=Some(guard);self.generation=frame.generation;self.retired=false;
self.client_frames=if new_client {1} else {self.client_frames.saturating_add(1)};
if remap {
crate::g18_kick_info!(dev.as_ref(),"G18_APP_VM frame={} vm={} context={} target={}x{} aliases={}\n",
frame.generation,vm.id(),self.job.context_id(),render.target.width,render.target.height,self.user_aliases.len());
Expand All @@ -144,6 +155,10 @@ impl ApplicationJob {
self.job.signals.with_bytes_mut(|out| {out[0xc000..0xc020].fill(0);Ok(())})?;
self.job.encoded=None;
self.encode_application(dev,frame)?;
// Commit the frame only now: until here an error leaves the job
// retired, and the next prepare() rebuilds whatever this one changed.
self.guard=Some(guard);self.generation=frame.generation;self.retired=false;
self.client_frames=if new_client {1} else {self.client_frames.saturating_add(1)};
Ok(())
}

Expand Down
12 changes: 10 additions & 2 deletions drivers/gpu/drm/asahi/m5/resources/graphics_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::parameter_buffer::{M5ParameterBuffer, BLOCK_BYTES, PAGE_LIST_BYTES, P
use super::target_memory::M5TargetMemory;
use crate::{driver::AsahiDrmDevice, m5::render_desc, m5::render, mmu};
use crate::m5::completion::MAX_GRAPHICS_GENERATION;
use core::sync::atomic::{fence, Ordering};
use kernel::prelude::*;

const HIGH: u64 = 0xffff_fc20_c100_0000;
Expand Down Expand Up @@ -271,8 +272,9 @@ impl M5GraphicsJob {
/// for the new VM and the pools are aliased into it. The previous VM's
/// render targets are not used in the new VM: they stay cached under the
/// previous VM for its next turn, and the next application frame takes or
/// allocates targets in the new VM. The caller publishes the new roots
/// before the next draw.
/// allocates targets in the new VM. Pool data storage is cleared before
/// the new VM maps it; allocator and parameter-manager state is kept. The
/// caller publishes the new roots before the next draw.
pub(super) fn rebind_vm(&mut self, dev: &AsahiDrmDevice, vm: &mmu::Vm) -> Result {
if self.owns_vm(vm) { return Ok(()); }
if self.scheduler_status()? != [2, 0] { return Err(EBUSY); }
Expand All @@ -286,6 +288,12 @@ impl M5GraphicsJob {
for alias in self.parameter_buffer.alias_into(vm)? {
aliases.push(alias, GFP_KERNEL)?;
}
// Compute operands and the preemption page released by the previous
// VM may still hold its data; clear them, and restore the zero
// robustness page, before another VM maps them.
self.compute_storage.with_bytes_mut(|out| { out.fill(0); Ok(()) })?;
// Order the clears before the new roots and the next draw are published.
fence(Ordering::SeqCst);
let storage = self.compute_storage.iova();
if let Some(alias) = self.compute_storage.map_alias_at_with_guards(
vm, storage, mmu::PROT_GPU_SHARED_RW, 2)? {
Expand Down
10 changes: 9 additions & 1 deletion drivers/gpu/drm/asahi/m5/resources/graphics_usc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,17 @@ impl M5GraphicsUsc {
/// addresses, reproducing each allocation's guard reservation, so every
/// firmware record naming the directory, free list or blocks stays valid
/// across a render client handoff. The returned aliases must be kept for
/// as long as that VM may submit.
/// as long as that VM may submit. The caller has verified that all work
/// using the pool has retired.
pub(super) fn alias_into(&mut self, vm: &mmu::Vm) -> Result<KVec<mmu::KernelMapping>> {
let range = crate::m5::vm_layout::auxiliary_range(&vm.kernel_range()).ok_or(EINVAL)?;
// Blocks released by the previous VM may still hold its shader stack
// and spill data; clear them before another VM maps them. The
// directory and free list are allocator state that the firmware's
// cursors refer to, so they are kept (see below).
for block in self.blocks.iter_mut() {
block.with_bytes_mut(|out| { out.fill(0); Ok(()) })?;
}
let mut aliases = KVec::new();
let alias = |object: &mut MappedObject, size: usize, guards: usize,
aliases: &mut KVec<mmu::KernelMapping>| -> Result {
Expand Down
11 changes: 10 additions & 1 deletion drivers/gpu/drm/asahi/m5/resources/parameter_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,18 @@ impl M5ParameterBuffer {
/// Map the retained pool into another application VM at the same compact
/// addresses with the original two-page guard reservations, so the
/// firmware's parameter-manager records keep naming valid pages after a
/// render client handoff.
/// render client handoff. The caller has verified that all work using
/// the pool has retired.
pub(super) fn alias_into(&mut self, vm: &mmu::Vm) -> Result<KVec<mmu::KernelMapping>> {
let range = vm_layout::compact_range(&vm.kernel_range()).ok_or(EINVAL)?;
// Blocks, scene scratch and the discard page released by the previous
// VM may still hold its scene data; clear them before another VM maps
// them. The page list and metrics are parameter-manager state named
// by the retained firmware records and are kept.
for object in Iterator::chain(self.blocks.iter_mut(),
[&mut self.scene_scratch, &mut self.discard]) {
object.with_bytes_mut(|out| { out.fill(0); Ok(()) })?;
}
let mut aliases = KVec::new();
let alias = |object: &mut MappedObject, aliases: &mut KVec<mmu::KernelMapping>| -> Result {
let end = object.iova()
Expand Down
Loading
Loading