Skip to content

Strongly typed RISC-V Page Table & Hypervisor Extension #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

gjz010
Copy link

@gjz010 gjz010 commented Mar 8, 2021

  • 调整页表机制
    • 重构页表部分代码。
    • 目前的页表假设Sv39是Sv48的“子集”(即p3_index长度为9),而这一点对Sv39x4和Sv48x4并不成立,去除这一假设。
    • 将Sv32所支持的物理地址提升到34位。
    • 目前的API设计严重依赖usize(以及条件编译),我们将其分离出来并且拆分出“平台相关接口”和“平台无关接口”。
    • 尽可能保证已有对外接口的不变性,但是仍然会导致一些接口被破坏
      • 例如,riscv crate默认RISCV64用Sv48页表,但是rCore使用了Sv39页表。
      • 由于我们的强类型约束下二者的VirtAddr和PhysAddr是不同的类型,需要改写rCore相关代码以兼容。
    • 此外,加入了对Sv32x4、Sv39x4、Sv48x4的支持。
  • 加入对RISC-V Hypervisor扩展的支持(CSR和新指令)
    • 由于LLVM不认得H扩展新加的指令,使用硬编码指令。
    • 使用feature="hypervisor"开启支持。

@gjz010 gjz010 changed the title Hypervisor Extension (and much more) Strongly typed RISC-V Page Table & Hypervisor Extension Apr 25, 2021
@wangrunji0408 wangrunji0408 self-requested a review May 12, 2021 02:46
@wangrunji0408 wangrunji0408 added the enhancement New feature or request label May 12, 2021
Copy link
Member

@wangrunji0408 wangrunji0408 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yyds!

@wangrunji0408 wangrunji0408 merged commit 4e58457 into rcore-os:master May 22, 2021
Copy link
Member

@wangrunji0408 wangrunji0408 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait. I found some bugs.

self.0.try_into().unwrap()
}
fn page_number(&self) -> usize {
self.0.get_bits(12..64).try_into().unwrap()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be 12..39?

Comment on lines +51 to +53
assert!(p3_index.get_bits(12..) == 0, "p3_index exceeding 11 bits");
assert!(p2_index.get_bits(10..) == 0, "p2_index exceeding 9 bits");
assert!(p1_index.get_bits(10..) == 0, "p1_index exceeding 9 bits");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be 9..?

let mut addr =
(p3_index << 12 << 9 << 9) | (p2_index << 12 << 9) | (p1_index << 12) | offset;
if addr.get_bit(38) {
addr.set_bits(39..64, 0xFFFF);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be (1 << (64 - 39)) - 1?

impl AddressX64 for VirtAddrSv39 {
fn new_u64(addr: u64) -> Self {
if addr.get_bit(38) {
assert!(addr.get_bits(39..64) == 0xFFFF, "va 39..64 is not sext");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be (1 << (64 - 39)) - 1?

Comment on lines +57 to +60
assert!(p4_index.get_bits(10..) == 0, "p4_index exceeding 9 bits");
assert!(p3_index.get_bits(10..) == 0, "p3_index exceeding 9 bits");
assert!(p2_index.get_bits(10..) == 0, "p2_index exceeding 9 bits");
assert!(p1_index.get_bits(10..) == 0, "p1_index exceeding 9 bits");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be 9..?

self.0.try_into().unwrap()
}
fn page_number(&self) -> usize {
self.0.get_bits(12..64).try_into().unwrap()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be 12..48?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants