[PATCH v2 09/32] gpu: nova-core: mm: borrow BarUser for temporary BAR1 access
From: Zhi Wang
Date: Mon Sep 14 2026 - 04:11:58 EST
Temporary BAR1 access needs a borrow of the GPU-owned BarUser. Store
BarUser inline in Gpu and borrow it in BarUserAccess, avoiding a separate
allocation and reference counting for these accesses. Update the existing
self-test entry points to accept the borrowed interface.
No functional change is intended.
Cc: Alistair Popple <apopple@xxxxxxxxxx>
Signed-off-by: Zhi Wang <zhiw@xxxxxxxxxx>
---
drivers/gpu/nova-core/gpu.rs | 21 +++++++++------------
drivers/gpu/nova-core/mm.rs | 5 ++---
drivers/gpu/nova-core/mm/bar_user.rs | 27 ++++++++++++---------------
3 files changed, 23 insertions(+), 30 deletions(-)
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index 227531b28541..ebf29b06a8e1 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -16,7 +16,6 @@
SizeConstants,
SZ_4K, //
},
- sync::Arc,
};
use crate::{
@@ -327,7 +326,8 @@ pub(crate) struct Gpu<'gpu> {
/// the GSP is still operational.
mm: GpuMm<'gpu>,
/// BAR1 user interface for CPU access to GPU virtual memory.
- bar_user: Arc<BarUser<'gpu>>,
+ #[pin]
+ bar_user: BarUser<'gpu>,
/// GSP and its resources.
#[pin]
gsp_resources: GspResources<'gpu>,
@@ -523,19 +523,16 @@ pub(crate) fn new<'a>(
},
// Create BAR1 user interface for CPU access to GPU virtual memory.
- bar_user: {
+ bar_user <- {
let pdb_addr =
VramAddress::from_raw(gsp_resources.boot_result.static_info.bar1_pde_base);
let bar1_idx = crate::driver::bar1_resource_index(pdev)?;
let bar1_size = pdev.resource_len(bar1_idx)?;
- Arc::pin_init(
- BarUser::new(
- pdb_addr,
- gsp_resources.spec.chipset,
- bar1_size,
- bar1,
- )?,
- GFP_KERNEL,
+ BarUser::new(
+ pdb_addr,
+ gsp_resources.spec.chipset,
+ bar1_size,
+ bar1,
)?
},
})
@@ -552,7 +549,7 @@ pub(crate) fn run_selftests(self: Pin<&mut Self>, pdev: &pci::Device<device::Bou
dev,
this.mm,
regions,
- this.bar_user,
+ this.bar_user.as_ref().get_ref(),
this.gsp_resources.boot_result.static_info.bar1_pde_base,
this.gsp_resources.spec.chipset,
) {
diff --git a/drivers/gpu/nova-core/mm.rs b/drivers/gpu/nova-core/mm.rs
index a5bc4042577b..8a934c55169f 100644
--- a/drivers/gpu/nova-core/mm.rs
+++ b/drivers/gpu/nova-core/mm.rs
@@ -298,8 +298,7 @@ pub(crate) mod selftest {
use kernel::{
device,
- sizes::SizeConstants,
- sync::Arc, //
+ sizes::SizeConstants, //
};
use super::*;
@@ -309,7 +308,7 @@ pub(crate) fn run(
dev: &device::Device<device::Bound>,
mm: &mut GpuMm<'_>,
usable_fb_regions: &[Range<u64>],
- bar_user: &Arc<bar_user::BarUser<'_>>,
+ bar_user: &bar_user::BarUser<'_>,
bar1_pdb: u64,
chipset: Chipset,
) -> Result {
diff --git a/drivers/gpu/nova-core/mm/bar_user.rs b/drivers/gpu/nova-core/mm/bar_user.rs
index 1bef01d147ad..2e6d229b1a23 100644
--- a/drivers/gpu/nova-core/mm/bar_user.rs
+++ b/drivers/gpu/nova-core/mm/bar_user.rs
@@ -7,10 +7,7 @@
io::Io,
new_mutex,
prelude::*,
- sync::{
- Arc,
- Mutex, //
- },
+ sync::Mutex, //
};
use crate::{
@@ -60,12 +57,12 @@ pub(crate) fn new(
}
/// Map physical pages to a contiguous BAR1 virtual range.
- pub(crate) fn map(
- self: &Arc<Self>,
+ pub(crate) fn map<'access>(
+ &'access self,
mm: &mut GpuMm<'_>,
pfns: &[Pfn],
writable: bool,
- ) -> Result<BarUserAccess<'gpu>> {
+ ) -> Result<BarUserAccess<'access, 'gpu>> {
if pfns.is_empty() {
return Err(EINVAL);
}
@@ -73,22 +70,22 @@ pub(crate) fn map(
let mapped = vmm.map_pages(mm, pfns, None, writable)?;
Ok(BarUserAccess {
- bar_user: self.clone(),
+ bar_user: self,
mapped: Some(mapped),
})
}
}
/// Access object for a mapped BAR1 region.
-pub(crate) struct BarUserAccess<'gpu> {
- bar_user: Arc<BarUser<'gpu>>,
+pub(crate) struct BarUserAccess<'access, 'gpu> {
+ bar_user: &'access BarUser<'gpu>,
/// [`BarUserAccess::release`] [`Option::take`]s this; `Some` at
/// drop time means `release()` was never called.
mapped: Option<MappedRange>,
}
#[expect(dead_code)]
-impl BarUserAccess<'_> {
+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)?;
@@ -162,7 +159,7 @@ pub(crate) fn try_write64(&self, value: u64, offset: usize) -> Result {
}
}
-impl Drop for BarUserAccess<'_> {
+impl Drop for BarUserAccess<'_, '_> {
fn drop(&mut self) {
if self.mapped.is_some() {
kernel::pr_warn!(
@@ -180,10 +177,10 @@ fn drop(&mut self) {
/// address space. Uses the `GpuMm`'s buddy allocator to allocate page tables
/// and test pages as needed.
#[cfg(CONFIG_NOVA_CORE_SELFTESTS)]
-pub(crate) fn run_self_test(
+pub(super) fn run_self_test(
dev: &device::Device<device::Bound>,
mm: &mut GpuMm<'_>,
- bar_user: &Arc<BarUser<'_>>,
+ bar_user: &BarUser<'_>,
bar1_pdb: u64,
chipset: Chipset,
) -> Result {
@@ -386,7 +383,7 @@ pub(crate) fn run_self_test(
drop(vmm);
// Test 4: Exercise `BarUser::map()` end-to-end.
- let bar_user = Arc::pin_init(
+ let bar_user = KBox::pin_init(
BarUser::new(pdb_addr, chipset, SZ_64K.into_safe_cast(), bar1)?,
GFP_KERNEL,
)?;