From 6a4d8d113fbe0edc178fa812ee32d76a51caf4f9 Mon Sep 17 00:00:00 2001 From: Zhang Junyang Date: Sat, 19 Jul 2025 17:01:56 +0800 Subject: [PATCH] Fix missing updates of page table `Entry::pte` Co-authored-by: Xungan2 <2100012996@stu.pku.edu.cn> --- ostd/src/mm/page_table/node/entry.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/ostd/src/mm/page_table/node/entry.rs b/ostd/src/mm/page_table/node/entry.rs index b80425e71..ba659f60b 100644 --- a/ostd/src/mm/page_table/node/entry.rs +++ b/ostd/src/mm/page_table/node/entry.rs @@ -111,15 +111,13 @@ impl<'a, 'rcu, C: PageTableConfig> Entry<'a, 'rcu, C> { *self.node.nr_children_mut() -= 1; } - let new_pte = new_child.into_pte(); + self.pte = new_child.into_pte(); // SAFETY: // 1. The index is within the bounds. // 2. The new PTE is a child in `C` and at the correct paging level. // 3. The ownership of the child is passed to the page table node. - unsafe { self.node.write_pte(self.idx, new_pte) }; - - self.pte = new_pte; + unsafe { self.node.write_pte(self.idx, self.pte) }; old_child } @@ -147,14 +145,13 @@ impl<'a, 'rcu, C: PageTableConfig> Entry<'a, 'rcu, C> { // Lock before writing the PTE, so no one else can operate on it. let pt_lock_guard = pt_ref.lock(guard); + self.pte = Child::PageTable(new_page).into_pte(); + // SAFETY: // 1. The index is within the bounds. // 2. The new PTE is a child in `C` and at the correct paging level. // 3. The ownership of the child is passed to the page table node. - unsafe { - self.node - .write_pte(self.idx, Child::PageTable(new_page).into_pte()) - }; + unsafe { self.node.write_pte(self.idx, self.pte) }; *self.node.nr_children_mut() += 1; @@ -199,14 +196,13 @@ impl<'a, 'rcu, C: PageTableConfig> Entry<'a, 'rcu, C> { debug_assert!(old.is_none()); } + self.pte = Child::PageTable(new_page).into_pte(); + // SAFETY: // 1. The index is within the bounds. // 2. The new PTE is a child in `C` and at the correct paging level. // 3. The ownership of the child is passed to the page table node. - unsafe { - self.node - .write_pte(self.idx, Child::PageTable(new_page).into_pte()) - }; + unsafe { self.node.write_pte(self.idx, self.pte) }; Some(pt_lock_guard) }