Re: [PATCH 15/16] gpu: nova-core: mm: Add BAR1 user interface
From: Danilo Krummrich
Date: Wed Sep 09 2026 - 16:13:39 EST
On Wed Sep 9, 2026 at 5:59 AM CEST, Eliot Courtney wrote:
> +/// Access object for a mapped BAR1 region.
> +pub(crate) struct BarUserAccess<'gpu> {
> + bar_user: Arc<BarUser<'gpu>>,
This shouldn't be an Arc, we can just borrow from BarUser.
> + /// [`BarUserAccess::release`] [`Option::take`]s this; `Some` at
> + /// drop time means `release()` was never called.
> + mapped: Option<MappedRange>,
This Option, the panic in mapped() and the odd warning in drop() should go away
with using proper RAII types as suggested in a previous reply. I.e.
unmap_pages() doesn't need to call free_vfn() anymore, but MappedRange's drop()
does it.
> +}
> +
> +impl BarUserAccess<'_> {
> + /// Tear down the BAR1 mapping.
> + pub(crate) fn release(mut self, mm: &mut GpuMm<'_>) -> Result {
> + let mapped = self.mapped.take().ok_or(EINVAL)?;
> + let mut vmm = self.bar_user.vmm.lock();
> + vmm.unmap_pages(mm, mapped)?;
> + Ok(())
> + }
> +
> + /// Returns the active mapping.
> + fn mapped(&self) -> &MappedRange {
> + // `mapped` is only `None` after `take()` in `release`; hence unwrap()
> + // cannot panic here.
> + self.mapped.as_ref().unwrap()
> + }
[...]
> +impl Drop for BarUserAccess<'_> {
> + fn drop(&mut self) {
> + if self.mapped.is_some() {
> + kernel::pr_warn!(
> + "BarUserAccess dropped without calling release(). BarUser address space will leak.\n"
> + );
> + }
> + // The inner `MappedRange`'s own `MustUnmapGuard` will also fire,
> + // identifying the leaked VA range.
> + }
> +}