From: Zhi Wang <[email protected]>

The BAR1 self-test creates temporary Vmm and BarUser instances on the
live BAR1 page directory. Dropping them releases their page-table pages
while parent PDEs still point to those pages. Reusing a freed page for
another leaf table can make disjoint BAR mappings alias: unmapping one
vGPU then invalidates its sibling's mapping.

Use the supplied persistent BarUser for all tests so the installed page
tables remain owned until GPU teardown. Borrow its Vmm for the direct
mapping tests and release the mutex guard before testing BarUser::map().

Fixes: d669686f8170 ("gpu: nova-core: mm: Add BAR1 memory management 
self-tests")
Signed-off-by: Zhi Wang <[email protected]>
Signed-off-by: Alok Kumar <[email protected]>
---
 drivers/gpu/nova-core/mm/bar_user.rs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/nova-core/mm/bar_user.rs 
b/drivers/gpu/nova-core/mm/bar_user.rs
index 64802ccec37b..7bf5f71b51fb 100644
--- a/drivers/gpu/nova-core/mm/bar_user.rs
+++ b/drivers/gpu/nova-core/mm/bar_user.rs
@@ -329,8 +329,8 @@ pub(super) fn run_self_test(
     let test_vram = VramAddress::from_raw(test_vram_offset);
     let test_pfn = Pfn::from(test_vram);
 
-    // Create a VMM of size 64K to track virtual memory mappings.
-    let mut vmm = Vmm::new(pdb_addr, chipset.mmu_version(), 
SZ_64K.into_safe_cast())?;
+    // Page tables installed in the live BAR1 PDB must keep their owner until 
GPU teardown.
+    let mut vmm = bar_user.vmm.lock();
 
     // Create a test mapping.
     let mapped = vmm.map_pages(mm, &[test_pfn], None, true)?;
@@ -490,7 +490,7 @@ pub(super) fn run_self_test(
         test3_passed = false;
     }
 
-    // Release Tests 1-3's Vmm before Test 4 uses the GPU's BarUser on the 
same PDB.
+    // Release the lock before `BarUser::map()` acquires it again.
     drop(vmm);
 
     // Test 4: Exercise `BarUser::map()` end-to-end.

Reply via email to