gpu: nova-core: take advantage of pci::Device::unbind()
Subsystems (3)
Danilo Krummrich
maintainerPATCH 1/1 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.
--- drivers/gpu/nova-core/driver.rs | 4 ++++ drivers/gpu/nova-core/gpu.rs | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-)
drivers/gpu/nova-core/driver.rs +4 -0
@@ -54,4 +54,8 @@ fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<SelfOk (this) } + +fn unbind (pdev: &pci::Device <Core >, this:Pin <&Self >) { + this.gpu.unbind (pdev); + } }
drivers/gpu/nova-core/gpu.rs +10 -10
@@ -163,7 +163,7 @@ fn new(bar: &Bar0) -> Result<Spec> { }/// Structure holding the resources required to operate the GPU. -#[pin_data( PinnedDrop )] +#[pin_data] pub (crate )struct Gpu { spec:Spec ,/// MMIO mapping of PCI BAR 0
@@ -174,15 +174,6 @@ pub(crate) struct Gpu { sysmem_flush: SysmemFlush, } -#[pinned_drop] -impl PinnedDrop for Gpu { -fn drop (self:Pin <&mut Self >) { -// Unregister the sysmem flush page before we release it. - self.bar - .try_access_with (|b| self.sysmem_flush.unregister (b)); - } -} -impl Gpu {/// Helper function to load and run the FWSEC-FRTS firmware and confirm that it has properly /// created the WPR2 region.
@@ -309,4 +300,13 @@ pub(crate) fn new( sysmem_flush, })) } + +pub (crate )fn unbind (&self, pdev: &pci::Device <device::Bound >) { +// Unregister the sysmem flush page before we release it. + kernel::warn_on!(self.bar.access (pdev.as_ref ()).map_or (true , |bar| { + self.sysmem_flush.unregister (bar); + +false + })); + } }
base-commit: 09f90256e8902793f594517ef440698585eb3595
Signature · 1 line
2.51.0
Danilo Krummrich
maintainerReview
Quoted 9 lines · Danilo Krummrich
(quoted diff) +8
-0+ pub(crate) fn unbind(&self, pdev: &pci::Device<device::Bound>) { + // Unregister the sysmem flush page before we release it. + kernel::warn_on!(self.bar.access(pdev.as_ref()).map_or(true, |bar| { + self.sysmem_flush.unregister(bar); + + false + })); + } }
Actually, inspect() + is_err() is much nicer:
drivers/gpu/nova-core/gpu.rs +5 -5
@@ -303,10 +303,10 @@ pub(crate) fn new(pub (crate )fn unbind (&self, pdev: &pci::Device <device::Bound >) {// Unregister the sysmem flush page before we release it. - kernel::warn_on!(self.bar.access (pdev.as_ref ()).map_or (true , |bar| { - self.sysmem_flush.unregister (bar); - -false - })); + kernel::warn_on!(self + .bar + .access (pdev.as_ref ()) + .inspect (|bar| self.sysmem_flush.unregister (bar)) + .is_err ()); } }
Alexandre Courbot
maintainerQuoted 55 lines · Danilo Krummrich
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 <[email protected]>--- drivers/gpu/nova-core/driver.rs | 4 ++++ drivers/gpu/nova-core/gpu.rs | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-)drivers/gpu/nova-core/driver.rs +4
-0@@ -54,4 +54,8 @@ fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<SelfOk (this) } + +fn unbind (pdev: &pci::Device <Core >, this:Pin <&Self >) { + this.gpu.unbind (pdev); + } }drivers/gpu/nova-core/gpu.rs +1
-10@@ -163,7 +163,7 @@ fn new(bar: &Bar0) -> Result<Spec> { }/// Structure holding the resources required to operate the GPU. -#[pin_data( PinnedDrop )] +#[pin_data] pub (crate )struct Gpu { spec:Spec ,/// MMIO mapping of PCI BAR 0 @@ -174,15 +174,6 @@ pub(crate) struct Gpu { sysmem_flush: SysmemFlush, } -#[pinned_drop] -impl PinnedDrop for Gpu { -fn drop (self:Pin <&mut Self >) { -// Unregister the sysmem flush page before we release it. - self.bar - .try_access_with (|b| self.sysmem_flush.unregister (b)); - } -} -impl Gpu {/// Helper function to load and run the FWSEC-FRTS firmware and confirm that it has properly /// created the WPR2 region. @@ -309,4 +300,13 @@ pub(crate) fn new( sysmem_flush, }))
drivers/gpu/nova-core/gpu.rs pub(crate) fn new( · line 311
Quoted 10 lines
drivers/gpu/nova-core/gpu.rs +9
-0} + +pub (crate )fn unbind (&self, pdev: &pci::Device <device::Bound >) { +// Unregister the sysmem flush page before we release it. + kernel::warn_on!(self.bar.access (pdev.as_ref ()).map_or (true , |bar| { + self.sysmem_flush.unregister (bar); + +false + })); + }
Maybe I'm overtly cautious, but this method can be called from a large part of the driver, leaving the Gpu device in a half-unbound state. The PinnedDrop approach had the benefit of not allowing this.
One way to solve the problem would be to make this method pub(in crate::driver), so other modules cannot call it.
Danilo Krummrich
maintainerQuoted 9 lines · Alexandre Courbot
drivers/gpu/nova-core/gpu.rs pub(crate) fn new( · line 311
Quoted 8 lines
drivers/gpu/nova-core/gpu.rs +8
-0+pub (crate )fn unbind (&self, pdev: &pci::Device <device::Bound >) { +// Unregister the sysmem flush page before we release it. + kernel::warn_on!(self.bar.access (pdev.as_ref ()).map_or (true , |bar| { + self.sysmem_flush.unregister (bar); + +false + })); + }
Quoted 6 lines
Maybe I'm overtly cautious, but this method can be called from a large part of the driver, leaving the Gpu device in a half-unbound state. The
PinnedDropapproach had the benefit of not allowing this.One way to solve the problem would be to make this method
pub(in crate::driver), so other modules cannot call it.
pub(in crate::driver) doesn't work, since hierarchically it's a sibling. :(
However, I can add a doc-comment to make it a bit more obvious.
Alexandre Courbot
maintainerQuoted 10 lines · Danilo Krummrich
Quoted 9 lines · Alexandre Courbot
Quoted 8 lines
drivers/gpu/nova-core/gpu.rs +8
-0+pub (crate )fn unbind (&self, pdev: &pci::Device <device::Bound >) { +// Unregister the sysmem flush page before we release it. + kernel::warn_on!(self.bar.access (pdev.as_ref ()).map_or (true , |bar| { + self.sysmem_flush.unregister (bar); + +false + })); + }
Quoted 8 lines
Quoted 6 lines
Maybe I'm overtly cautious, but this method can be called from a large part of the driver, leaving the Gpu device in a half-unbound state. The
PinnedDropapproach had the benefit of not allowing this.One way to solve the problem would be to make this method
pub(in crate::driver), so other modules cannot call it.pub(in
crate::driver) doesn't work, since hierarchically it's a sibling. :(
Argh. TIL.
Quoted 2 lines
However, I can add a doc-comment to make it a bit more obvious.
Would it also help if we made Gpu::unbind take a pci::Device<device::Core>? That way, driver functions that only have a bound device could not invoke it.
(also, should we make the argument a device::Device instead of a pci::Device?)
Danilo Krummrich
maintainerQuoted 20 lines · Alexandre Courbot
Quoted 10 lines · Danilo Krummrich
Quoted 9 lines · Alexandre Courbot
Quoted 8 lines
drivers/gpu/nova-core/gpu.rs +8
-0+pub (crate )fn unbind (&self, pdev: &pci::Device <device::Bound >) { +// Unregister the sysmem flush page before we release it. + kernel::warn_on!(self.bar.access (pdev.as_ref ()).map_or (true , |bar| { + self.sysmem_flush.unregister (bar); + +false + })); + }Quoted 8 lines
Quoted 6 lines
Maybe I'm overtly cautious, but this method can be called from a large part of the driver, leaving the Gpu device in a half-unbound state. The
PinnedDropapproach had the benefit of not allowing this.One way to solve the problem would be to make this method
pub(in crate::driver), so other modules cannot call it.pub(in
crate::driver) doesn't work, since hierarchically it's a sibling. :(
Quoted 8 lines
Argh. TIL.
Quoted 2 lines
However, I can add a doc-comment to make it a bit more obvious.
Would it also help if we made
Gpu::unbindtake apci::Device<device::Core>? That way, driver functions that only have a bound device could not invoke it.
This was my intention, but somehow I typed Bound.
Quoted 2 lines
(also, should we make the argument a
device::Deviceinstead of apci::Device?)
I think it makes sense to abstract the specific bus device, since long term we also want to support tegra.