Repository navigation
drm: retain VM resources until queued jobs retire #472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-only OR MIT | ||
| #![allow(clippy::unusual_byte_groupings)] | ||
|
|
||
|
|
@@ -70,7 +70,6 @@ | |
| vm: mmu::Vm, | ||
| user_range: Range<u64>, | ||
| kernel_range: Range<u64>, | ||
| _dummy_mapping: mmu::KernelMapping, | ||
| gpu: Arc<dyn gpu::Gpu>, | ||
| } | ||
|
|
||
|
|
@@ -83,41 +82,15 @@ | |
| // object must not outlive the client's VM handle. | ||
| status.release_mirror(); | ||
| } | ||
| if self.vm.status().is_some() { | ||
| // Tracked jobs can outlive their file's VM handle. Their last guard performs | ||
| // these unmaps once no accepted work can still dereference the mappings. | ||
| if let Err(error) = self | ||
| .vm | ||
| .unmap_user_ranges(self.user_range.clone(), self.kernel_range.clone()) | ||
| { | ||
| pr_err!("Vm::Drop: deferred user unmap failed: {:?}\n", error); | ||
| } | ||
| self.vm.bo_deferred_cleanup(); | ||
| self.gpu.vm_closed(&self.vm); | ||
| return; | ||
| } | ||
| // When the user Vm is dropped, verify that no user mappings exists. | ||
| let left_range = self.user_range.start..self.kernel_range.start; | ||
| let right_range = self.kernel_range.end..self.user_range.end; | ||
|
|
||
| if !left_range.is_empty() | ||
| && self | ||
| .vm | ||
| .unmap_range(None, left_range.start, left_range.range()) | ||
| .is_err() | ||
| { | ||
| pr_err!("Vm::Drop: vm.unmap_range() failed\n"); | ||
| } | ||
| if !right_range.is_empty() | ||
| && self | ||
| .vm | ||
| .unmap_range(None, right_range.start, right_range.range()) | ||
| .is_err() | ||
| // Accepted jobs retain mappings until firmware completion or GPU stop. | ||
| if let Err(error) = self | ||
| .vm | ||
| .unmap_user_ranges(self.user_range.clone(), self.kernel_range.clone()) | ||
| { | ||
| pr_err!("Vm::Drop: vm.unmap_range() failed\n"); | ||
| pr_err!("Vm::Drop: deferred user unmap failed: {:?}\n", error); | ||
| } | ||
|
|
||
| self.vm.bo_deferred_cleanup(); | ||
| self.gpu.vm_closed(&self.vm); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -555,13 +528,15 @@ | |
|
|
||
| let gpu = ®_data.gpu; | ||
| let file_id = file.inner().id; | ||
| let vm = gpu.new_vm_for_file(kernel_range.clone(), file_id)?; | ||
| let vm = gpu | ||
| .new_vm_for_file(kernel_range.clone(), file_id)? | ||
| .with_job_lifetime()?; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On G13/G14 this switches on deferred GEM cleanup. Closed objects are then held until the VM fully idles ( — Marcelo's agent
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is real, and I did not change it in this push. Objects closed while the VM has accepted jobs wait in Unmapping an object as soon as the jobs accepted before its close retire would bound it. That needs a per-job sequence and a partial drain, and it breaks the drain loop's rule that only one drainer runs and only at zero active jobs. I will not change that state machine without a stress run on G13 hardware. Would you rather have that here, or as a follow-up PR with the stress result?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On your question: the scope is wider than closed objects on one VM. — Marcelo's agent |
||
| // G16 registers a retained backend owner before returning this VM. Any later | ||
| // allocation can fail before file::Vm exists to run its normal close path. | ||
| let failed_vm = ScopeGuard::new_with_data( | ||
| (vm.clone(), user_range.clone(), kernel_range.clone()), | ||
| |(vm, user_range, kernel_range)| { | ||
| if gpu.tracked_submission() && vm.status().is_some() && !vm.is_closed() { | ||
| if !vm.is_closed() { | ||
| vm.close_idle_reclaim(); | ||
| if let Err(error) = vm.unmap_user_ranges(user_range, kernel_range) { | ||
| pr_err!("VM create: closing unpublished VM failed: {:?}\n", error); | ||
|
|
@@ -631,6 +606,7 @@ | |
| mmu::PROT_GPU_SHARED_RW, | ||
| true, | ||
| )?; | ||
| vm.retain_mapping(dummy_mapping)?; | ||
|
|
||
| mod_dev_dbg!(device, "[File {} VM {}]: VM created\n", file_id, id); | ||
| resv.fill(KBox::new( | ||
|
|
@@ -645,7 +621,6 @@ | |
| vm, | ||
| user_range, | ||
| kernel_range, | ||
| _dummy_mapping: dummy_mapping, | ||
| gpu: gpu.clone(), | ||
| }, | ||
| GFP_KERNEL, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed: this keeps the queue, and with it
QueueInfo, the ring, notifier list and GPU context (fw/workqueue.rs:176-182), for as long as the pinned commands. Please make the body say "until reboot" to match.— Marcelo's agent