[PATCH] gpu: nova-core: mm: keep a page table page before installing its PDE

From: Vladislav Zaharov

Date: Fri Nov 13 2026 - 04:44:21 EST


install_mappings() writes the PDE of a new page table page before moving
the page into page_table_allocs. If push_within_capacity() then fails,
the page is dropped and its VRAM freed while the PDE still points at it.

Move the page into page_table_allocs first, so that a failure leaves no
PDE pointing at freed memory.

The problem was found by an LLM-assisted code review.

Fixes: 4e4182282d4e ("gpu: nova-core: mm: Add multi-page mapping API to VMM")
Signed-off-by: Vladislav Zaharov <vladazaharova2018@xxxxxxxxx>
---
I could not reproduce the failure, as it needs push_within_capacity() to
fail. With the change, the MM self-tests still pass on a GB203.

drivers/gpu/nova-core/mm/pagetable/map.rs | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/nova-core/mm/pagetable/map.rs b/drivers/gpu/nova-core/mm/pagetable/map.rs
index f7774b9cc972..e678197ec009 100644
--- a/drivers/gpu/nova-core/mm/pagetable/map.rs
+++ b/drivers/gpu/nova-core/mm/pagetable/map.rs
@@ -209,8 +209,15 @@ pub(super) fn install_mappings(
let (install_addr, page) = node.to_key_value();
let page_vram =
VramAddress::from_raw(page.alloc.iter().next().ok_or(ENOMEM)?.offset());
+ let level = page.level;

- if page.level == M::DUAL_PDE_LEVEL {
+ // Keep the page before pointing a PDE at it, so that a failure here cannot leave a
+ // PDE pointing at freed VRAM.
+ page_table_allocs
+ .push_within_capacity(page.alloc)
+ .map_err(|_| ENOMEM)?;
+
+ if level == M::DUAL_PDE_LEVEL {
let new_dpde = M::DualPde::new_small(Pfn::from(page_vram));
new_dpde.write(pramin, install_addr)?;
} else {
@@ -218,10 +225,6 @@ pub(super) fn install_mappings(
new_pde.write(pramin, install_addr)?;
}

- page_table_allocs
- .push_within_capacity(page.alloc)
- .map_err(|_| ENOMEM)?;
-
cursor = next;
}


base-commit: 0ff9e5b9ff6736c37593cd7db89f4593ec4f8e86
--
2.56.0