From ed6f57f8f6e54425e655dc978aba645424b2591d Mon Sep 17 00:00:00 2001 From: Ruoqing He Date: Thu, 6 Mar 2025 11:06:36 +0800 Subject: [PATCH] runtime-rs: Restrict cloud-hypervisor feature Cloud-Hypervisor currently only supports `x86_64` and `aarch64`, this features should not be avaiable even if other architectures explicitly requires it. Restrict `cloud-hypervisor` feature to only `x86_64` and `aarch64`. Signed-off-by: Ruoqing He --- src/runtime-rs/crates/hypervisor/src/lib.rs | 5 ++++- .../crates/runtimes/virt_container/src/lib.rs | 20 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/runtime-rs/crates/hypervisor/src/lib.rs b/src/runtime-rs/crates/hypervisor/src/lib.rs index a28d0a608..6185fa802 100644 --- a/src/runtime-rs/crates/hypervisor/src/lib.rs +++ b/src/runtime-rs/crates/hypervisor/src/lib.rs @@ -23,7 +23,10 @@ pub use kernel_param::Param; pub mod utils; use std::collections::HashMap; -#[cfg(feature = "cloud-hypervisor")] +#[cfg(all( + feature = "cloud-hypervisor", + any(target_arch = "x86_64", target_arch = "aarch64") +))] pub mod ch; use anyhow::Result; diff --git a/src/runtime-rs/crates/runtimes/virt_container/src/lib.rs b/src/runtime-rs/crates/runtimes/virt_container/src/lib.rs index 1654cfde7..20ab06960 100644 --- a/src/runtime-rs/crates/runtimes/virt_container/src/lib.rs +++ b/src/runtime-rs/crates/runtimes/virt_container/src/lib.rs @@ -32,9 +32,15 @@ use kata_types::config::FirecrackerConfig; use kata_types::config::RemoteConfig; use kata_types::config::{hypervisor::register_hypervisor_plugin, QemuConfig, TomlConfig}; -#[cfg(feature = "cloud-hypervisor")] +#[cfg(all( + feature = "cloud-hypervisor", + any(target_arch = "x86_64", target_arch = "aarch64") +))] use hypervisor::ch::CloudHypervisor; -#[cfg(feature = "cloud-hypervisor")] +#[cfg(all( + feature = "cloud-hypervisor", + any(target_arch = "x86_64", target_arch = "aarch64") +))] use kata_types::config::{hypervisor::HYPERVISOR_NAME_CH, CloudHypervisorConfig}; use resource::cpu_mem::initial_size::InitialSizeManager; @@ -66,7 +72,10 @@ impl RuntimeHandler for VirtContainer { let qemu_config = Arc::new(QemuConfig::new()); register_hypervisor_plugin("qemu", qemu_config); - #[cfg(feature = "cloud-hypervisor")] + #[cfg(all( + feature = "cloud-hypervisor", + any(target_arch = "x86_64", target_arch = "aarch64") + ))] { let ch_config = Arc::new(CloudHypervisorConfig::new()); register_hypervisor_plugin(HYPERVISOR_NAME_CH, ch_config); @@ -178,7 +187,10 @@ async fn new_hypervisor(toml_config: &TomlConfig) -> Result> .await; Ok(Arc::new(hypervisor)) } - #[cfg(feature = "cloud-hypervisor")] + #[cfg(all( + feature = "cloud-hypervisor", + any(target_arch = "x86_64", target_arch = "aarch64") + ))] HYPERVISOR_NAME_CH => { let hypervisor = CloudHypervisor::new(); hypervisor