Replace in_untracked_range by in_tracked_range

This commit is contained in:
Ruihan Li
2024-06-04 20:04:08 +08:00
committed by Tate, Hongliang Tian
parent 52ee28880d
commit a1f36979d7
2 changed files with 26 additions and 26 deletions

View File

@ -261,7 +261,7 @@ where
fn cur_child(&self) -> Child<E, C> { fn cur_child(&self) -> Child<E, C> {
self.cur_node() self.cur_node()
.child(self.cur_idx(), !self.in_untracked_range()) .child(self.cur_idx(), self.in_tracked_range())
} }
fn read_cur_pte(&self) -> E { fn read_cur_pte(&self) -> E {
@ -275,10 +275,10 @@ where
/// ///
/// All mappings in the user mode are tracked. And all mappings in the IOMMU /// All mappings in the user mode are tracked. And all mappings in the IOMMU
/// page table are untracked. /// page table are untracked.
fn in_untracked_range(&self) -> bool { fn in_tracked_range(&self) -> bool {
TypeId::of::<M>() == TypeId::of::<crate::arch::iommu::DeviceMode>() TypeId::of::<M>() != TypeId::of::<crate::arch::iommu::DeviceMode>()
|| TypeId::of::<M>() == TypeId::of::<KernelMode>() && (TypeId::of::<M>() != TypeId::of::<KernelMode>()
&& !crate::mm::kspace::VMALLOC_VADDR_RANGE.contains(&self.va) || crate::mm::kspace::VMALLOC_VADDR_RANGE.contains(&self.va))
} }
} }
@ -375,7 +375,7 @@ where
pub(crate) unsafe fn map(&mut self, frame: Frame, prop: PageProperty) { pub(crate) unsafe fn map(&mut self, frame: Frame, prop: PageProperty) {
let end = self.0.va + frame.size(); let end = self.0.va + frame.size();
assert!(end <= self.0.barrier_va.end); assert!(end <= self.0.barrier_va.end);
debug_assert!(!self.0.in_untracked_range()); debug_assert!(self.0.in_tracked_range());
// Go down if not applicable. // Go down if not applicable.
while self.0.level > C::HIGHEST_TRANSLATION_LEVEL while self.0.level > C::HIGHEST_TRANSLATION_LEVEL
@ -457,7 +457,7 @@ where
} }
// Map the current page. // Map the current page.
debug_assert!(self.0.in_untracked_range()); debug_assert!(!self.0.in_tracked_range());
let idx = self.0.cur_idx(); let idx = self.0.cur_idx();
self.cur_node_mut().set_child_untracked(idx, pa, prop); self.cur_node_mut().set_child_untracked(idx, pa, prop);
@ -485,7 +485,7 @@ where
while self.0.va < end { while self.0.va < end {
let cur_pte = self.0.read_cur_pte(); let cur_pte = self.0.read_cur_pte();
let untracked = self.0.in_untracked_range(); let is_tracked = self.0.in_tracked_range();
// Skip if it is already invalid. // Skip if it is already invalid.
if !cur_pte.is_present() { if !cur_pte.is_present() {
@ -506,7 +506,7 @@ where
{ {
if cur_pte.is_present() && !cur_pte.is_last(self.0.level) { if cur_pte.is_present() && !cur_pte.is_last(self.0.level) {
self.0.level_down(); self.0.level_down();
} else if untracked { } else if !is_tracked {
self.level_down_split(); self.level_down_split();
} else { } else {
unreachable!(); unreachable!();
@ -516,7 +516,7 @@ where
// Unmap the current page. // Unmap the current page.
let idx = self.0.cur_idx(); let idx = self.0.cur_idx();
self.cur_node_mut().unset_child(idx, untracked); self.cur_node_mut().unset_child(idx, is_tracked);
self.0.move_forward(); self.0.move_forward();
} }
@ -564,7 +564,7 @@ where
// of untracked huge pages. // of untracked huge pages.
let vaddr_not_fit = self.0.va % page_size::<C>(self.0.level) != 0 let vaddr_not_fit = self.0.va % page_size::<C>(self.0.level) != 0
|| self.0.va + page_size::<C>(self.0.level) > end; || self.0.va + page_size::<C>(self.0.level) > end;
if self.0.in_untracked_range() && vaddr_not_fit { if !self.0.in_tracked_range() && vaddr_not_fit {
self.level_down_split(); self.level_down_split();
continue; continue;
} else if vaddr_not_fit { } else if vaddr_not_fit {
@ -608,9 +608,9 @@ where
let new_frame = PageTableNode::<E, C>::alloc(self.0.level - 1); let new_frame = PageTableNode::<E, C>::alloc(self.0.level - 1);
let idx = self.0.cur_idx(); let idx = self.0.cur_idx();
let untracked = self.0.in_untracked_range(); let is_tracked = self.0.in_tracked_range();
self.cur_node_mut() self.cur_node_mut()
.set_child_pt(idx, new_frame.clone_raw(), untracked); .set_child_pt(idx, new_frame.clone_raw(), is_tracked);
self.0.level -= 1; self.0.level -= 1;
self.0.guards[(C::NR_LEVELS - self.0.level) as usize] = Some(new_frame); self.0.guards[(C::NR_LEVELS - self.0.level) as usize] = Some(new_frame);
} }
@ -620,7 +620,7 @@ where
/// This method will split the huge page and go down to the next level. /// This method will split the huge page and go down to the next level.
fn level_down_split(&mut self) { fn level_down_split(&mut self) {
debug_assert!(self.0.level > 1); debug_assert!(self.0.level > 1);
debug_assert!(self.0.in_untracked_range()); debug_assert!(!self.0.in_tracked_range());
let idx = self.0.cur_idx(); let idx = self.0.cur_idx();
self.cur_node_mut().split_untracked_huge(idx); self.cur_node_mut().split_untracked_huge(idx);

View File

@ -266,7 +266,7 @@ where
} }
/// Gets an extra reference of the child at the given index. /// Gets an extra reference of the child at the given index.
pub(super) fn child(&self, idx: usize, tracked: bool) -> Child<E, C> { pub(super) fn child(&self, idx: usize, in_tracked_range: bool) -> Child<E, C> {
debug_assert!(idx < nr_subpage_per_huge::<C>()); debug_assert!(idx < nr_subpage_per_huge::<C>());
let pte = self.read_pte(idx); let pte = self.read_pte(idx);
@ -287,7 +287,7 @@ where
level: self.level() - 1, level: self.level() - 1,
_phantom: PhantomData, _phantom: PhantomData,
}) })
} else if tracked { } else if in_tracked_range {
// SAFETY: The physical address is recorded in a valid PTE // SAFETY: The physical address is recorded in a valid PTE
// which would be casted from a handle. We are incrementing // which would be casted from a handle. We are incrementing
// the reference count so we restore and forget a cloned one. // the reference count so we restore and forget a cloned one.
@ -320,7 +320,7 @@ where
let mut new_frame = Self::alloc(self.level()); let mut new_frame = Self::alloc(self.level());
for i in deep { for i in deep {
match self.child(i, /*meaningless*/ true) { match self.child(i, true) {
Child::PageTable(pt) => { Child::PageTable(pt) => {
let guard = pt.clone_shallow().lock(); let guard = pt.clone_shallow().lock();
let new_child = guard.make_copy(0..nr_subpage_per_huge::<C>(), 0..0); let new_child = guard.make_copy(0..nr_subpage_per_huge::<C>(), 0..0);
@ -354,10 +354,10 @@ where
} }
/// Removes a child if the child at the given index is present. /// Removes a child if the child at the given index is present.
pub(super) fn unset_child(&mut self, idx: usize, in_untracked_range: bool) { pub(super) fn unset_child(&mut self, idx: usize, in_tracked_range: bool) {
debug_assert!(idx < nr_subpage_per_huge::<C>()); debug_assert!(idx < nr_subpage_per_huge::<C>());
self.overwrite_pte(idx, None, in_untracked_range); self.overwrite_pte(idx, None, in_tracked_range);
} }
/// Sets a child page table at a given index. /// Sets a child page table at a given index.
@ -365,14 +365,14 @@ where
&mut self, &mut self,
idx: usize, idx: usize,
pt: RawPageTableNode<E, C>, pt: RawPageTableNode<E, C>,
in_untracked_range: bool, in_tracked_range: bool,
) { ) {
// They should be ensured by the cursor. // They should be ensured by the cursor.
debug_assert!(idx < nr_subpage_per_huge::<C>()); debug_assert!(idx < nr_subpage_per_huge::<C>());
debug_assert_eq!(pt.level, self.level() - 1); debug_assert_eq!(pt.level, self.level() - 1);
let pte = Some(E::new_pt(pt.paddr())); let pte = Some(E::new_pt(pt.paddr()));
self.overwrite_pte(idx, pte, in_untracked_range); self.overwrite_pte(idx, pte, in_tracked_range);
// The ownership is transferred to a raw PTE. Don't drop the handle. // The ownership is transferred to a raw PTE. Don't drop the handle.
let _ = ManuallyDrop::new(pt); let _ = ManuallyDrop::new(pt);
} }
@ -384,7 +384,7 @@ where
debug_assert_eq!(frame.level(), self.level()); debug_assert_eq!(frame.level(), self.level());
let pte = Some(E::new_frame(frame.start_paddr(), self.level(), prop)); let pte = Some(E::new_frame(frame.start_paddr(), self.level(), prop));
self.overwrite_pte(idx, pte, false); self.overwrite_pte(idx, pte, true);
// The ownership is transferred to a raw PTE. Don't drop the handle. // The ownership is transferred to a raw PTE. Don't drop the handle.
let _ = ManuallyDrop::new(frame); let _ = ManuallyDrop::new(frame);
} }
@ -399,7 +399,7 @@ where
debug_assert!(idx < nr_subpage_per_huge::<C>()); debug_assert!(idx < nr_subpage_per_huge::<C>());
let pte = Some(E::new_frame(pa, self.level(), prop)); let pte = Some(E::new_frame(pa, self.level(), prop));
self.overwrite_pte(idx, pte, true); self.overwrite_pte(idx, pte, false);
} }
/// Reads the info from a page table entry at a given index. /// Reads the info from a page table entry at a given index.
@ -426,7 +426,7 @@ where
unsafe { new_frame.set_child_untracked(i, small_pa, prop) }; unsafe { new_frame.set_child_untracked(i, small_pa, prop) };
} }
self.set_child_pt(idx, new_frame.into_raw(), true); self.set_child_pt(idx, new_frame.into_raw(), false);
} }
/// Protects an already mapped child at a given index. /// Protects an already mapped child at a given index.
@ -461,7 +461,7 @@ where
/// ///
/// The caller in this module will ensure that the PTE points to initialized /// The caller in this module will ensure that the PTE points to initialized
/// memory if the child is a page table. /// memory if the child is a page table.
fn overwrite_pte(&mut self, idx: usize, pte: Option<E>, in_untracked_range: bool) { fn overwrite_pte(&mut self, idx: usize, pte: Option<E>, in_tracked_range: bool) {
let existing_pte = self.read_pte(idx); let existing_pte = self.read_pte(idx);
if existing_pte.is_present() { if existing_pte.is_present() {
@ -484,7 +484,7 @@ where
if !existing_pte.is_last(self.level()) { if !existing_pte.is_last(self.level()) {
// This is a page table. // This is a page table.
drop(Page::<PageTablePageMeta<E, C>>::from_raw(paddr)); drop(Page::<PageTablePageMeta<E, C>>::from_raw(paddr));
} else if !in_untracked_range { } else if in_tracked_range {
// This is a frame. // This is a frame.
drop(Page::<FrameMeta>::from_raw(paddr)); drop(Page::<FrameMeta>::from_raw(paddr));
} }