oscourse-tsinghua / rcore_plus

Rust version of THU uCore OS. Linux compatible.
MIT License
172 stars 26 forks source link

Refactor paging from recursive mapping to linear mapping #50

Closed wangrunji0408 closed 5 years ago

wangrunji0408 commented 5 years ago

Motivation

The current page table use recursive mapping to access itself and do not have a linear mapping to all physical memory.

This mechanism follows BlogOS. It worked well at the beginning.

But we found several limitations as our OS grows:

  1. It's a really complicated concept that hard to understand for beginners.
  2. For some architectures, recursive mapping can not be implemented normally. For example, RISC-V and MIPS.
  3. It's not easy to access page table and data of other processes. So forking process and coping the memory can not be implemented both simply and efficiently.
  4. All access to an inactive page table needs to modify the active one, which causes unnecessary data race on multi-thread and multi-core.
  5. It discourages us to access physical memory directly, which is unfriendly to driver and DMA.

Almost everyone agrees that linear mapping is a better choice.

Changes

  1. Merge InactivePageTable and PageTable trait.
  2. Add phys_to_virt function.
  3. Remove all DMA mappings in drivers.
  4. ...

Progress

Arch Status Note
x86_64
RISC-V
AArch64
MIPS
jiegec commented 5 years ago

Still one problem remains: #[repr(align(64)]] does not work with rv64.

jiegec commented 5 years ago

RV32+64 is ready now.

Harry-Chen commented 5 years ago

I believe it is now feasible to merge these commits

wangrunji0408 commented 5 years ago

Then aarch64 is broken. 😂 @equation314 Could you help fix linear mapping on aarch64?

equation314 commented 5 years ago

OK, I will try to work in it this week...