On Tue, 2025-12-16 at 19:04 +0900, John Hubbard wrote:
> > If I do that, then how do I access it from gsp.rs (the last patch in this
> > series)?
>
> Given that the current PCI .probe() doesn't pass in module data,
> I looked around and saw that Binder is using global_lock!()
> instead of passing around module data. It seems like this area
> is still new in Rust for Linux.
>
> I wonder if global_lock!() is what Gary had in mind? That is still
> effectively global access, but at least it's synchronized,
> unlike static mut.
It's only 'mut' in that it needs to be initialized when the driver loads.
After that, it's only
referenced as non-mut:
#[allow(static_mut_refs)]
// SAFETY: `DEBUGFS_ROOT` is never modified after initialization, so it
is safe to
// create a shared reference to it.
let novacore_dir = unsafe { crate::DEBUGFS_ROOT.as_ref()
}.ok_or(ENOENT)?;
The first internal version of this code did have global_lock!, but it caused
problems. That's why
Alex recommended to drop the lock and just have an unsafe initialization:
https://github.com/Gnurou/linux/commit/d5435f662b8677545a93373b4c4c80d8b4be40c9
It would be nice if Rust had a concept of a variable that was initialized at
runtime once (before
any concurrent access could occur), and was then read-only everywhere else.