From: Alexandre Courbot <[email protected]> Use the `pin_init_scope` feature to create the debugfs entry for loginit.
`pin_init_scope` solves the lifetime issue over the `DEBUGFS_ROOT` reference by delaying its acquisition until the time the entry is actually initialized. Signed-off-by: Alexandre Courbot <[email protected]> Signed-off-by: Timur Tabi <[email protected]> --- drivers/gpu/nova-core/gsp.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs index 860674dac31e..ba4f789d8ac1 100644 --- a/drivers/gpu/nova-core/gsp.rs +++ b/drivers/gpu/nova-core/gsp.rs @@ -107,7 +107,8 @@ pub(crate) struct Gsp { /// Libos arguments. pub(crate) libos: CoherentAllocation<LibosMemoryRegionInitArgument>, /// Init log buffer. - loginit: LogBuffer, + #[pin] + pub loginit: debugfs::File<LogBuffer>, /// Interrupts log buffer. logintr: LogBuffer, /// RM log buffer. @@ -143,7 +144,9 @@ unsafe impl Sync for LogBuffer {} impl Gsp { // Creates an in-place initializer for a `Gsp` manager for `pdev`. - pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> Result<impl PinInit<Self, Error>> { + pub(crate) fn new<'a>( + pdev: &'a pci::Device<device::Bound>, + ) -> Result<impl PinInit<Self, Error> + 'a> { let dev = pdev.as_ref(); let libos = CoherentAllocation::<LibosMemoryRegionInitArgument>::alloc_coherent( dev, @@ -173,9 +176,17 @@ pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> Result<impl PinInit<Self dma_write!(rmargs[0] = fw::GspArgumentsCached::new(&cmdq))?; dma_write!(libos[3] = LibosMemoryRegionInitArgument::new("RMARGS", &rmargs))?; + #[allow(static_mut_refs)] + let debugfs_dir = + // SAFETY: `DEBUGFS_ROOT` is never modified after initialization, so it is safe to + // create a shared reference to it. + unsafe { crate::DEBUGFS_ROOT.as_ref() } + .map(|root| root.subdir(pdev.name())) + .ok_or(ENOENT)?; + Ok(try_pin_init!(Self { libos, - loginit, + loginit <- debugfs_dir.read_binary_file(kernel::c_str!("loginit"), loginit), logintr, logrm, rmargs, -- 2.52.0
