Skip to content

Commit

Permalink
修正大页映射错误
Browse files Browse the repository at this point in the history
  • Loading branch information
MemoryShore committed Apr 15, 2024
1 parent 23b06e2 commit ec50c99
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
10 changes: 6 additions & 4 deletions kernel/src/arch/riscv64/mm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -251,10 +257,6 @@ impl MemoryManagementArch for RiscV64MMArch {
) -> bool {
true
}

const PKEY_MASK: usize = 0;

const VM_PKEY_SHIFT: usize = 0;
}

impl VirtAddr {
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/arch/x86_64/mm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// 物理地址与虚拟地址的偏移量
Expand Down
4 changes: 0 additions & 4 deletions kernel/src/mm/fault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/mm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions kernel/src/mm/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ impl<Arch: MemoryManagementArch> PageFlags<Arch> {
/// - 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内存的页表项标志
Expand Down Expand Up @@ -925,8 +925,8 @@ impl<Arch: MemoryManagementArch, F: FrameAllocator> PageMapper<Arch, F> {
}
}

// 支持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;
}

Expand Down

0 comments on commit ec50c99

Please sign in to comment.