fix(boot): won't fail to boot when kvm not available (#1152)

* fix(boot): won't fail to boot when kvm not available

* feat(kvm): add additional debug message on kvm init fail
This commit is contained in:
Samuel Dai 2025-05-07 23:23:10 +08:00 committed by GitHub
parent 5e87c41d96
commit f3bfe77712
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View File

@ -3743,8 +3743,12 @@ pub static L1TF_VMX_MITIGATION: RwLock<VmxL1dFlushState> = RwLock::new(VmxL1dFlu
pub fn vmx_init() -> Result<(), SystemError> {
let cpuid = CpuId::new();
let cpu_feat = cpuid.get_feature_info().ok_or(SystemError::ENOSYS)?;
let cpu_feat = cpuid.get_feature_info().ok_or_else(|| {
log::warn!("Failed to get CPU feature info, perhaps not AMD or Intel CPU");
SystemError::ENOSYS
})?;
if !cpu_feat.has_vmx() {
log::warn!("VMX not supported or enabled");
return Err(SystemError::ENOSYS);
}

View File

@ -93,10 +93,10 @@ fn do_start_kernel() {
crate::bpf::init_bpf_system();
crate::debug::jump_label::static_keys_init();
// #[cfg(all(target_arch = "x86_64", feature = "kvm"))]
// crate::virt::kvm::kvm_init();
#[cfg(all(target_arch = "x86_64", feature = "kvm"))]
crate::arch::vm::vmx::vmx_init().unwrap();
if crate::arch::vm::vmx::vmx_init().is_err() {
log::warn!("vmx init failed, will not be enabled");
}
}
/// 在内存管理初始化之前,执行的初始化