mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-27 11:23:25 +00:00
Make tracked the metadata and kernel mappings
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
cab348349e
commit
d520360512
@ -48,7 +48,7 @@ use spin::Once;
|
|||||||
use super::{
|
use super::{
|
||||||
nr_subpage_per_huge,
|
nr_subpage_per_huge,
|
||||||
page::{
|
page::{
|
||||||
meta::{mapping, KernelMeta},
|
meta::{mapping, KernelMeta, MetaPageMeta},
|
||||||
Page,
|
Page,
|
||||||
},
|
},
|
||||||
page_prop::{CachePolicy, PageFlags, PageProperty, PrivilegedPageFlags},
|
page_prop::{CachePolicy, PageFlags, PageProperty, PrivilegedPageFlags},
|
||||||
@ -128,7 +128,7 @@ pub(crate) fn init_boot_page_table() {
|
|||||||
///
|
///
|
||||||
/// This function should be called before:
|
/// This function should be called before:
|
||||||
/// - any initializer that modifies the kernel page table.
|
/// - any initializer that modifies the kernel page table.
|
||||||
pub fn init_kernel_page_table(meta_pages: Vec<Range<Paddr>>) {
|
pub fn init_kernel_page_table(meta_pages: Vec<Page<MetaPageMeta>>) {
|
||||||
info!("Initializing the kernel page table");
|
info!("Initializing the kernel page table");
|
||||||
|
|
||||||
let regions = crate::boot::memory_regions();
|
let regions = crate::boot::memory_regions();
|
||||||
@ -168,10 +168,10 @@ pub fn init_kernel_page_table(meta_pages: Vec<Range<Paddr>>) {
|
|||||||
priv_flags: PrivilegedPageFlags::GLOBAL,
|
priv_flags: PrivilegedPageFlags::GLOBAL,
|
||||||
};
|
};
|
||||||
let mut cursor = kpt.cursor_mut(&from).unwrap();
|
let mut cursor = kpt.cursor_mut(&from).unwrap();
|
||||||
for frame in meta_pages {
|
for meta_page in meta_pages {
|
||||||
// SAFETY: we are doing the metadata mappings for the kernel.
|
// SAFETY: we are doing the metadata mappings for the kernel.
|
||||||
unsafe {
|
unsafe {
|
||||||
cursor.map_pa(&frame, prop);
|
cursor.map(meta_page.into(), prop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,10 +212,9 @@ pub fn init_kernel_page_table(meta_pages: Vec<Range<Paddr>>) {
|
|||||||
let mut cursor = kpt.cursor_mut(&from).unwrap();
|
let mut cursor = kpt.cursor_mut(&from).unwrap();
|
||||||
for frame_paddr in to.step_by(PAGE_SIZE) {
|
for frame_paddr in to.step_by(PAGE_SIZE) {
|
||||||
let page = Page::<KernelMeta>::from_unused(frame_paddr);
|
let page = Page::<KernelMeta>::from_unused(frame_paddr);
|
||||||
let paddr = page.into_raw();
|
|
||||||
// SAFETY: we are doing mappings for the kernel.
|
// SAFETY: we are doing mappings for the kernel.
|
||||||
unsafe {
|
unsafe {
|
||||||
cursor.map_pa(&(paddr..paddr + PAGE_SIZE), prop);
|
cursor.map(page.into(), prop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ use alloc::vec::Vec;
|
|||||||
use core::{
|
use core::{
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
mem::{size_of, ManuallyDrop},
|
mem::{size_of, ManuallyDrop},
|
||||||
ops::Range,
|
|
||||||
panic,
|
panic,
|
||||||
sync::atomic::{AtomicU32, AtomicU8, Ordering},
|
sync::atomic::{AtomicU32, AtomicU8, Ordering},
|
||||||
};
|
};
|
||||||
@ -225,7 +224,7 @@ impl PageMeta for KernelMeta {
|
|||||||
/// Initializes the metadata of all physical pages.
|
/// Initializes the metadata of all physical pages.
|
||||||
///
|
///
|
||||||
/// The function returns a list of `Page`s containing the metadata.
|
/// The function returns a list of `Page`s containing the metadata.
|
||||||
pub(crate) fn init() -> Vec<Range<Paddr>> {
|
pub(crate) fn init() -> Vec<Page<MetaPageMeta>> {
|
||||||
let max_paddr = {
|
let max_paddr = {
|
||||||
let regions = crate::boot::memory_regions();
|
let regions = crate::boot::memory_regions();
|
||||||
regions.iter().map(|r| r.base() + r.len()).max().unwrap()
|
regions.iter().map(|r| r.base() + r.len()).max().unwrap()
|
||||||
@ -259,10 +258,7 @@ pub(crate) fn init() -> Vec<Range<Paddr>> {
|
|||||||
// Now the metadata pages are mapped, we can initialize the metadata.
|
// Now the metadata pages are mapped, we can initialize the metadata.
|
||||||
meta_pages
|
meta_pages
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|paddr| {
|
.map(Page::<MetaPageMeta>::from_unused)
|
||||||
let pa = Page::<MetaPageMeta>::from_unused(paddr).into_raw();
|
|
||||||
pa..pa + PAGE_SIZE
|
|
||||||
})
|
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ use align_ext::AlignExt;
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
page_size, pte_index, Child, KernelMode, PageTable, PageTableEntryTrait, PageTableError,
|
page_size, pte_index, Child, KernelMode, PageTable, PageTableEntryTrait, PageTableError,
|
||||||
PageTableMode, PageTableNode, PagingConstsTrait, PagingLevel,
|
PageTableMode, PageTableNode, PagingConstsTrait, PagingLevel, UserMode,
|
||||||
};
|
};
|
||||||
use crate::mm::{page::DynPage, Paddr, PageProperty, Vaddr};
|
use crate::mm::{page::DynPage, Paddr, PageProperty, Vaddr};
|
||||||
|
|
||||||
@ -270,15 +270,19 @@ where
|
|||||||
|
|
||||||
/// Tells if the current virtual range must contain untracked mappings.
|
/// Tells if the current virtual range must contain untracked mappings.
|
||||||
///
|
///
|
||||||
|
/// _Tracked mappings_ means that the mapped physical addresses (in PTEs) points to pages
|
||||||
|
/// tracked by the metadata system. _Tracked mappings_ must be created with page handles.
|
||||||
|
/// While _untracked mappings_ solely maps to plain physical addresses.
|
||||||
|
///
|
||||||
/// In the kernel mode, this is aligned with the definition in [`crate::mm::kspace`].
|
/// In the kernel mode, this is aligned with the definition in [`crate::mm::kspace`].
|
||||||
/// Only linear mappings in the kernel are considered as untracked mappings.
|
/// Only linear mappings in the kernel should be considered as untracked mappings.
|
||||||
///
|
///
|
||||||
/// 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_tracked_range(&self) -> bool {
|
fn in_tracked_range(&self) -> bool {
|
||||||
TypeId::of::<M>() != TypeId::of::<crate::arch::iommu::DeviceMode>()
|
TypeId::of::<M>() == TypeId::of::<UserMode>()
|
||||||
&& (TypeId::of::<M>() != TypeId::of::<KernelMode>()
|
|| TypeId::of::<M>() == TypeId::of::<KernelMode>()
|
||||||
|| crate::mm::kspace::VMALLOC_VADDR_RANGE.contains(&self.va))
|
&& !crate::mm::kspace::LINEAR_MAPPING_VADDR_RANGE.contains(&self.va)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user