Explorar o código

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
Samuel Dai hai 1 día
pai
achega
f3bfe77712
Modificáronse 2 ficheiros con 8 adicións e 4 borrados
  1. 5 1
      kernel/src/arch/x86_64/vm/vmx/mod.rs
  2. 3 3
      kernel/src/init/init.rs

+ 5 - 1
kernel/src/arch/x86_64/vm/vmx/mod.rs

@@ -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);
     }
 

+ 3 - 3
kernel/src/init/init.rs

@@ -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");
+    }
 }
 
 /// 在内存管理初始化之前,执行的初始化