diff --git a/kernel/src/arch/riscv64/mm/mod.rs b/kernel/src/arch/riscv64/mm/mod.rs index cc1c3ebb8..29f76ff2f 100644 --- a/kernel/src/arch/riscv64/mm/mod.rs +++ b/kernel/src/arch/riscv64/mm/mod.rs @@ -138,6 +138,12 @@ impl MemoryManagementArch for RiscV64MMArch { /// 设置1g的MMIO空间 const MMIO_SIZE: usize = 1 << PAGE_1G_SHIFT; + const PKEY_MASK: usize = 0; + + const VM_PKEY_SHIFT: usize = 0; + + const ENTRY_FLAG_HUGE_PAGE: usize = Self::ENTRY_FLAG_PRESENT | Self::ENTRY_FLAG_READWRITE; + #[inline(never)] unsafe fn init() { riscv_mm_init().expect("init kernel memory management architecture failed"); @@ -251,10 +257,6 @@ impl MemoryManagementArch for RiscV64MMArch { ) -> bool { true } - - const PKEY_MASK: usize = 0; - - const VM_PKEY_SHIFT: usize = 0; } impl VirtAddr { diff --git a/kernel/src/arch/x86_64/mm/mod.rs b/kernel/src/arch/x86_64/mm/mod.rs index 7dd7502dd..1f1b5355e 100644 --- a/kernel/src/arch/x86_64/mm/mod.rs +++ b/kernel/src/arch/x86_64/mm/mod.rs @@ -106,7 +106,7 @@ impl MemoryManagementArch for X86_64MMArch { const ENTRY_FLAG_ACCESSED: usize = 1 << 5; const ENTRY_FLAG_DIRTY: usize = 1 << 6; - const ENTRY_FLAG_PS: usize = 1 << 7; + const ENTRY_FLAG_HUGE_PAGE: usize = 1 << 7; const ENTRY_FLAG_GLOBAL: usize = 1 << 8; /// 物理地址与虚拟地址的偏移量 diff --git a/kernel/src/mm/fault.rs b/kernel/src/mm/fault.rs index 2aeaa151d..9f045ac54 100644 --- a/kernel/src/mm/fault.rs +++ b/kernel/src/mm/fault.rs @@ -181,10 +181,6 @@ impl PageFaultHandler { entry.set_flags(PageFlags::from_data(MMArch::ENTRY_FLAG_DIRTY)); } } - let pte_table = mapper.get_table(address, 0).unwrap(); - let i = pte_table.index_of(address).unwrap(); - entry.set_flags(entry.flags().set_access(true)); - pte_table.set_entry(i, entry); } else if vma.is_anonymous() { return Self::do_anonymous_page(pfm, mapper); } else { diff --git a/kernel/src/mm/mod.rs b/kernel/src/mm/mod.rs index c5ddf8a8d..e56d0d4da 100644 --- a/kernel/src/mm/mod.rs +++ b/kernel/src/mm/mod.rs @@ -462,7 +462,7 @@ pub trait MemoryManagementArch: Clone + Copy + Debug { /// 当该位为1时,代表这个页面被处理器访问过 const ENTRY_FLAG_ACCESSED: usize; /// 标记该页表项指向的页是否为大页 - const ENTRY_FLAG_PS: usize; + const ENTRY_FLAG_HUGE_PAGE: usize; /// 当该位为1时,代表该页表项是全局的 const ENTRY_FLAG_GLOBAL: usize; diff --git a/kernel/src/mm/page.rs b/kernel/src/mm/page.rs index 05844c912..9fb09fb97 100644 --- a/kernel/src/mm/page.rs +++ b/kernel/src/mm/page.rs @@ -710,7 +710,7 @@ impl PageFlags { /// - value: 如果为true,那么将当前页表项的访问标志设置为已访问。 #[inline(always)] pub fn set_huge_page(self, value: bool) -> Self { - return self.update_flags(Arch::ENTRY_FLAG_PS, value); + return self.update_flags(Arch::ENTRY_FLAG_HUGE_PAGE, value); } /// MMIO内存的页表项标志 @@ -925,8 +925,8 @@ impl PageMapper { } } - // 支持2M、1G大页,即页表层级为1、2级的页表可以映射大页,且不能为PGD(顶级页表) - if table.level == Arch::PAGE_LEVELS - 1 || table.level == 0 || table.level > 2 { + // 支持2M、1G大页,即页表层级为1、2级的页表可以映射大页 + if table.level == 0 || table.level > 2 { return None; }