All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpu: nova-core: mm: keep a page table page before installing its PDE
@ 2026-11-13  7:54 Vladislav Zaharov
  2026-11-13  8:07 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Vladislav Zaharov @ 2026-11-13  7:54 UTC (permalink / raw)
  To: dakr, joelagnelf
  Cc: acourbot, aliceryhl, ecourtney, gary, nova-gpu, dri-devel,
	linux-kernel, vladazaharova2018

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@gmail.com>
---
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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-13  8:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13  7:54 [PATCH] gpu: nova-core: mm: keep a page table page before installing its PDE Vladislav Zaharov
2026-11-13  8:07 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.