From: Danilo Krummrich <dakr@kernel.org>
To: dakr@kernel.org, acourbot@nvidia.com, aliceryhl@google.com,
airlied@gmail.com, simona@ffwll.ch, lossin@kernel.org,
gary@garyguo.net, ecourtney@nvidia.com, jhubbard@nvidia.com
Cc: nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/4] gpu: nova-core: mm: use shared references to GpuMm
Date: Thu, 26 Nov 2026 22:36:03 +0100 [thread overview]
Message-ID: <20261126213652.3716162-3-dakr@kernel.org> (raw)
In-Reply-To: <20261126213652.3716162-1-dakr@kernel.org>
The components owned by GpuMm now provide their own synchronization.
Accept shared references to the memory manager so independent users can
access these resources without requiring a lock around the container.
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
drivers/gpu/nova-core/gpu.rs | 13 ++++++-------
drivers/gpu/nova-core/mm.rs | 2 +-
drivers/gpu/nova-core/mm/bar_user.rs | 6 +++---
drivers/gpu/nova-core/mm/pagetable/map.rs | 16 ++++++++--------
drivers/gpu/nova-core/mm/pagetable/walk.rs | 4 ++--
drivers/gpu/nova-core/mm/vmm.rs | 10 +++++-----
6 files changed, 25 insertions(+), 26 deletions(-)
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index 8ab1687847ff..39e57e724a71 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -613,18 +613,17 @@ pub(crate) fn wait_gfw_boot_completion(
/// Runs self-tests on the constructed [`Gpu`], logging failures without failing probe.
#[cfg(CONFIG_NOVA_CORE_SELFTESTS)]
- pub(crate) fn run_selftests(self: Pin<&mut Self>, pdev: &pci::Device<device::Bound>) {
- let this = self.project();
+ pub(crate) fn run_selftests(&self, pdev: &pci::Device<device::Bound>) {
let dev = pdev.as_ref();
- let regions = &this.gsp_static_info.usable_fb_regions;
+ let regions = &self.gsp_static_info.usable_fb_regions;
if let Err(err) = crate::mm::selftest::run(
dev,
- this.mm,
+ &self.mm,
regions,
- &this.bar_user,
- this.gsp_static_info.bar1_pde_base,
- this.spec.chipset,
+ &self.bar_user,
+ self.gsp_static_info.bar1_pde_base,
+ self.spec.chipset,
) {
dev_err!(dev, "self-tests failed: {:?}\n", err);
}
diff --git a/drivers/gpu/nova-core/mm.rs b/drivers/gpu/nova-core/mm.rs
index bbe23dc6351f..30a394424e12 100644
--- a/drivers/gpu/nova-core/mm.rs
+++ b/drivers/gpu/nova-core/mm.rs
@@ -311,7 +311,7 @@ pub(crate) mod selftest {
/// Run MM subsystem self-tests during probe.
pub(crate) fn run(
dev: &device::Device<device::Bound>,
- mm: &mut GpuMm<'_>,
+ mm: &GpuMm<'_>,
usable_fb_regions: &[Range<u64>],
bar_user: &bar_user::BarUser<'_>,
bar1_pdb: u64,
diff --git a/drivers/gpu/nova-core/mm/bar_user.rs b/drivers/gpu/nova-core/mm/bar_user.rs
index f25ead64bf53..483129d3d0f7 100644
--- a/drivers/gpu/nova-core/mm/bar_user.rs
+++ b/drivers/gpu/nova-core/mm/bar_user.rs
@@ -61,7 +61,7 @@ pub(crate) fn new(
/// Map physical pages to a contiguous BAR1 virtual range.
pub(crate) fn map(
&self,
- mm: &mut GpuMm<'_>,
+ mm: &GpuMm<'_>,
pfns: &[Pfn],
writable: bool,
) -> Result<BarUserAccess<'_>> {
@@ -91,7 +91,7 @@ pub(crate) struct BarUserAccess<'a> {
#[expect(dead_code)]
impl BarUserAccess<'_> {
/// Tear down the BAR1 mapping.
- pub(crate) fn release(mut self, mm: &mut GpuMm<'_>) -> Result {
+ pub(crate) fn release(mut self, mm: &GpuMm<'_>) -> Result {
let mapped = self.mapped.take().ok_or(EINVAL)?;
let mut vmm = self.bar_user.vmm.lock();
vmm.unmap_pages(mm, mapped)?;
@@ -183,7 +183,7 @@ fn drop(&mut self) {
#[cfg(CONFIG_NOVA_CORE_SELFTESTS)]
pub(crate) fn run_self_test(
dev: &device::Device<device::Bound>,
- mm: &mut GpuMm<'_>,
+ mm: &GpuMm<'_>,
bar_user: &BarUser<'_>,
bar1_pdb: u64,
chipset: Chipset,
diff --git a/drivers/gpu/nova-core/mm/pagetable/map.rs b/drivers/gpu/nova-core/mm/pagetable/map.rs
index ba23cd3c2b25..22e44386423f 100644
--- a/drivers/gpu/nova-core/mm/pagetable/map.rs
+++ b/drivers/gpu/nova-core/mm/pagetable/map.rs
@@ -82,7 +82,7 @@ pub(super) fn new(pdb_addr: VramAddress) -> Self {
}
/// Allocate and zero a physical page table page.
- fn alloc_and_zero_page(mm: &mut GpuMm<'_>, level: PageTableLevel) -> Result<PreparedPtPage> {
+ fn alloc_and_zero_page(mm: &GpuMm<'_>, level: PageTableLevel) -> Result<PreparedPtPage> {
let blocks = KBox::pin_init(
mm.buddy().alloc_blocks(
GpuBuddyAllocMode::Simple,
@@ -115,7 +115,7 @@ fn alloc_and_zero_page(mm: &mut GpuMm<'_>, level: PageTableLevel) -> Result<Prep
/// The mutable PRAMIN borrow ends before each allocation.
fn ensure_single_pte_path(
&self,
- mm: &mut GpuMm<'_>,
+ mm: &GpuMm<'_>,
vfn: Vfn,
pt_pages: &mut RBTree<VramAddress, PreparedPtPage>,
) -> Result {
@@ -168,7 +168,7 @@ fn ensure_single_pte_path(
/// per-VFN to prepare pages for all missing PDEs.
pub(super) fn prepare_map(
&self,
- mm: &mut GpuMm<'_>,
+ mm: &GpuMm<'_>,
vfn_start: Vfn,
num_pages: usize,
page_table_allocs: &mut KVec<Pin<KBox<AllocatedBlocks>>>,
@@ -193,7 +193,7 @@ pub(super) fn prepare_map(
/// Drains `pt_pages` and moves allocations into `page_table_allocs`.
pub(super) fn install_mappings(
&self,
- mm: &mut GpuMm<'_>,
+ mm: &GpuMm<'_>,
pt_pages: &mut RBTree<VramAddress, PreparedPtPage>,
page_table_allocs: &mut KVec<Pin<KBox<AllocatedBlocks>>>,
vfn_start: Vfn,
@@ -251,7 +251,7 @@ pub(super) fn install_mappings(
/// Invalidate PTEs for a range and flush TLB.
pub(super) fn invalidate_ptes(
&self,
- mm: &mut GpuMm<'_>,
+ mm: &GpuMm<'_>,
vfn_start: Vfn,
num_pages: usize,
) -> Result {
@@ -308,7 +308,7 @@ pub(in crate::mm) fn new(pdb_addr: VramAddress, version: MmuVersion) -> Self {
/// Prepare page table resources for a mapping.
pub(in crate::mm) fn prepare_map(
&self,
- mm: &mut GpuMm<'_>,
+ mm: &GpuMm<'_>,
vfn_start: Vfn,
num_pages: usize,
page_table_allocs: &mut KVec<Pin<KBox<AllocatedBlocks>>>,
@@ -323,7 +323,7 @@ pub(in crate::mm) fn prepare_map(
/// Install prepared PDEs and write PTEs, then flush TLB.
pub(in crate::mm) fn install_mappings(
&self,
- mm: &mut GpuMm<'_>,
+ mm: &GpuMm<'_>,
pt_pages: &mut RBTree<VramAddress, PreparedPtPage>,
page_table_allocs: &mut KVec<Pin<KBox<AllocatedBlocks>>>,
vfn_start: Vfn,
@@ -339,7 +339,7 @@ pub(in crate::mm) fn install_mappings(
/// Invalidate PTEs for a range and flush TLB.
pub(in crate::mm) fn invalidate_ptes(
&self,
- mm: &mut GpuMm<'_>,
+ mm: &GpuMm<'_>,
vfn_start: Vfn,
num_pages: usize,
) -> Result {
diff --git a/drivers/gpu/nova-core/mm/pagetable/walk.rs b/drivers/gpu/nova-core/mm/pagetable/walk.rs
index 899c61888756..59a011148455 100644
--- a/drivers/gpu/nova-core/mm/pagetable/walk.rs
+++ b/drivers/gpu/nova-core/mm/pagetable/walk.rs
@@ -171,7 +171,7 @@ pub(super) fn walk_pde_levels(
/// Walk to PTE for lookup only (no allocation).
///
/// Returns [`WalkResult::PageTableMissing`] if intermediate tables don't exist.
- pub(super) fn walk_to_pte_lookup(&self, mm: &mut GpuMm<'_>, vfn: Vfn) -> Result<WalkResult> {
+ pub(super) fn walk_to_pte_lookup(&self, mm: &GpuMm<'_>, vfn: Vfn) -> Result<WalkResult> {
mm.with_pramin_locked(|pramin| self.walk_to_pte_lookup_with_window(pramin, vfn))
}
@@ -238,7 +238,7 @@ pub(in crate::mm) fn new(pdb_addr: VramAddress, version: MmuVersion) -> Self {
}
/// Walk to PTE for lookup.
- pub(in crate::mm) fn walk_to_pte(&self, mm: &mut GpuMm<'_>, vfn: Vfn) -> Result<WalkResult> {
+ pub(in crate::mm) fn walk_to_pte(&self, mm: &GpuMm<'_>, vfn: Vfn) -> Result<WalkResult> {
pt_walk_dispatch!(self, walk_to_pte_lookup(mm, vfn))
}
}
diff --git a/drivers/gpu/nova-core/mm/vmm.rs b/drivers/gpu/nova-core/mm/vmm.rs
index 51b500a27233..c8258e579f8b 100644
--- a/drivers/gpu/nova-core/mm/vmm.rs
+++ b/drivers/gpu/nova-core/mm/vmm.rs
@@ -204,7 +204,7 @@ fn free_vfn(&self, vfn: Vfn) {
}
/// Read the [`Pfn`] for a mapped [`Vfn`] if one is mapped.
- pub(super) fn read_mapping(&self, mm: &mut GpuMm<'_>, vfn: Vfn) -> Result<Option<Pfn>> {
+ pub(super) fn read_mapping(&self, mm: &GpuMm<'_>, vfn: Vfn) -> Result<Option<Pfn>> {
match self.pt_walk.walk_to_pte(mm, vfn)? {
WalkResult::Mapped { pfn, .. } => Ok(Some(pfn)),
WalkResult::Unmapped { .. } | WalkResult::PageTableMissing => Ok(None),
@@ -220,7 +220,7 @@ pub(super) fn read_mapping(&self, mm: &mut GpuMm<'_>, vfn: Vfn) -> Result<Option
/// to call outside the fence signalling critical path.
pub(crate) fn prepare_map(
&mut self,
- mm: &mut GpuMm<'_>,
+ mm: &GpuMm<'_>,
num_pages: usize,
va_range: Option<Range<u64>>,
) -> Result<PreparedMapping> {
@@ -254,7 +254,7 @@ pub(crate) fn prepare_map(
/// Installs all prepared PDEs and writes PTEs into the page table, then flushes TLB.
pub(crate) fn execute_map(
&mut self,
- mm: &mut GpuMm<'_>,
+ mm: &GpuMm<'_>,
prepared: PreparedMapping,
pfns: &[Pfn],
writable: bool,
@@ -297,7 +297,7 @@ pub(crate) fn execute_map(
/// [`Vmm::execute_map()`] will be called separately.
pub(crate) fn map_pages(
&mut self,
- mm: &mut GpuMm<'_>,
+ mm: &GpuMm<'_>,
pfns: &[Pfn],
va_range: Option<Range<u64>>,
writable: bool,
@@ -324,7 +324,7 @@ pub(crate) fn map_pages(
}
/// Unmap all pages in a [`MappedRange`] with a single TLB flush.
- pub(crate) fn unmap_pages(&mut self, mm: &mut GpuMm<'_>, range: MappedRange) -> Result {
+ pub(crate) fn unmap_pages(&mut self, mm: &GpuMm<'_>, range: MappedRange) -> Result {
let result = self
.pt_map
.invalidate_ptes(mm, range.vfn_start, range.num_pages);
--
2.56.1
next prev parent reply other threads:[~2026-11-26 21:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 21:36 [PATCH 0/4] gpu: nova-core: prepare GpuMm for shared access Danilo Krummrich
2026-11-26 21:36 ` [PATCH 1/4] gpu: nova-core: mm: serialize PRAMIN access Danilo Krummrich
2026-11-26 21:36 ` Danilo Krummrich [this message]
2026-11-26 21:36 ` [PATCH 3/4] gpu: nova-core: mm: initialize GpuMm in place Danilo Krummrich
2026-11-26 21:36 ` [PATCH 4/4] gpu: nova-core: mm: remove SharedPramin Danilo Krummrich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126213652.3716162-3-dakr@kernel.org \
--to=dakr@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=simona@ffwll.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox