-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
feat(virtualization): 内核虚拟化支持 #900
base: master
Are you sure you want to change the base?
Conversation
可以先merge一下主线,然后review之后,剩余的功能分多个pr提交 |
use crate::{ | ||
arch::mm::barrier, | ||
kdebug, kerror, | ||
mm::{phys_2_virt, PhysAddr}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不应该依赖这个接口,应改为MMArch::phys_2_virt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为何,这都已经在x86下了吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是旧版的接口,在主线已经被移除了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
然后,对于一些体积较大的结构体,建议在堆上分配,以免爆栈。
} | ||
|
||
pub fn vmcs_load(phys_addr: PhysAddr) { | ||
match unsafe { x86::bits64::vmx::vmptrld(phys_addr.data() as u64) } { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
所有类似这种的,都要使用if let Err(e) = xxxx
use crate::{ | ||
arch::mm::barrier, | ||
kdebug, kerror, | ||
mm::{phys_2_virt, PhysAddr}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是旧版的接口,在主线已经被移除了。
kernel/src/arch/x86_64/vm/mmu.rs
Outdated
|
||
static mut TDP_ENABLED: bool = false; | ||
static mut TDP_MMU_ENABLED: bool = true; | ||
static mut TDP_MMU_ALLOWED: bool = unsafe { TDP_MMU_ENABLED }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个值得在kvm x86 mmu初始化之后再设置吧?不然的话他一直都是true了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个值目前只是先给个默认值,后面需要动态调整的时候再调整
VmxAsm::vmx_vmwrite(control::CR4_READ_SHADOW, cr4_flags.bits() as u64); | ||
VmxAsm::vmx_vmwrite(guest::CR4, hw_cr4.bits() as u64); | ||
|
||
if (cr4_flags ^ old_cr4).contains(Cr4::CR4_ENABLE_OS_XSAVE | Cr4::CR4_ENABLE_PROTECTION_KEY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里有问题,你想表达的意思应该是,(cr4_flags ^ old_cr4)
的结果,包含Cr4::CR4_ENABLE_OS_XSAVE 或者 Cr4::CR4_ENABLE_PROTECTION_KEY
但是这种写法,指的是,(cr4_flags ^ old_cr4)
的结果同时具有Cr4::CR4_ENABLE_OS_XSAVE
和Cr4::CR4_ENABLE_PROTECTION_KEY
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
基于linux源码,原有语意是正确的
} | ||
} | ||
|
||
pub struct Pte { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
#[allow(dead_code)] | ||
pub mod kvm_exit { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个写到单独的模块文件好些
主要完成整体框架的搭建以及CPU虚拟化模块。目前能够成功
vmlaunch
,后续会在这个pr下继续开发。下列为完成进度以及后续TODO: