Skip to content

Commit e258041

Browse files
Danilo KrummrichGnurou
authored andcommitted
gpu: nova-core: take advantage of pci::Device::unbind()
Now that we have pci::Device::unbind() we can unregister the sysmem flush page with a direct access the I/O resource, i.e. without RCU read side critical section. Signed-off-by: Danilo Krummrich <dakr@kernel.org> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Link: https://lore.kernel.org/r/20250901150207.63094-1-dakr@kernel.org Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
1 parent c58466b commit e258041

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

drivers/gpu/nova-core/driver.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,8 @@ impl pci::Driver for NovaCore {
5454

5555
Ok(this)
5656
}
57+
58+
fn unbind(pdev: &pci::Device<Core>, this: Pin<&Self>) {
59+
this.gpu.unbind(pdev.as_ref());
60+
}
5761
}

drivers/gpu/nova-core/gpu.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl Spec {
163163
}
164164

165165
/// Structure holding the resources required to operate the GPU.
166-
#[pin_data(PinnedDrop)]
166+
#[pin_data]
167167
pub(crate) struct Gpu {
168168
spec: Spec,
169169
/// MMIO mapping of PCI BAR 0
@@ -174,15 +174,6 @@ pub(crate) struct Gpu {
174174
sysmem_flush: SysmemFlush,
175175
}
176176

177-
#[pinned_drop]
178-
impl PinnedDrop for Gpu {
179-
fn drop(self: Pin<&mut Self>) {
180-
// Unregister the sysmem flush page before we release it.
181-
self.bar
182-
.try_access_with(|b| self.sysmem_flush.unregister(b));
183-
}
184-
}
185-
186177
impl Gpu {
187178
/// Helper function to load and run the FWSEC-FRTS firmware and confirm that it has properly
188179
/// created the WPR2 region.
@@ -309,4 +300,15 @@ impl Gpu {
309300
sysmem_flush,
310301
}))
311302
}
303+
304+
/// Called when the corresponding [`Device`](device::Device) is unbound.
305+
///
306+
/// Note: This method must only be called from `Driver::unbind`.
307+
pub(crate) fn unbind(&self, dev: &device::Device<device::Core>) {
308+
kernel::warn_on!(self
309+
.bar
310+
.access(dev)
311+
.inspect(|bar| self.sysmem_flush.unregister(bar))
312+
.is_err());
313+
}
312314
}

0 commit comments

Comments
 (0)