From 56aef3741d0cd067581476fc1c90b4bfafab73a7 Mon Sep 17 00:00:00 2001 From: Hyounggyu Choi Date: Wed, 31 Jan 2024 13:46:16 +0100 Subject: [PATCH 1/3] runtime-rs: Exclude hypervisors plugins except QEMU for s390x Dragonball and cloud-hypervisor are not supported on s390x. We need to exclude the plugins for these hypervisors from compilation. Signed-off-by: Hyounggyu Choi --- src/runtime-rs/crates/hypervisor/Cargo.toml | 7 ++--- src/runtime-rs/crates/hypervisor/src/lib.rs | 7 ++++- .../crates/runtimes/virt_container/src/lib.rs | 26 ++++++++++++------- .../runtimes/virt_container/src/sandbox.rs | 5 +++- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/runtime-rs/crates/hypervisor/Cargo.toml b/src/runtime-rs/crates/hypervisor/Cargo.toml index ef47fe1910..93743c4943 100644 --- a/src/runtime-rs/crates/hypervisor/Cargo.toml +++ b/src/runtime-rs/crates/hypervisor/Cargo.toml @@ -11,7 +11,6 @@ license = "Apache-2.0" actix-rt = "2.7.0" anyhow = "^1.0" async-trait = "0.1.48" -dbs-utils = { path = "../../../dragonball/src/dbs_utils" } go-flag = "0.1.0" libc = ">=0.2.39" nix = "0.24.2" @@ -35,8 +34,6 @@ kata-types = { path = "../../../libs/kata-types" } logging = { path = "../../../libs/logging" } shim-interface = { path = "../../../libs/shim-interface" } -dragonball = { path = "../../../dragonball", features = ["atomic-guest-memory", "virtio-vsock", "hotplug", "virtio-blk", "virtio-net", "virtio-fs", "vhost-net", "dbs-upcall", "virtio-mem", "virtio-balloon", "vhost-user-net", "host-device"] } - ch-config = { path = "ch-config", optional = true } tests_utils = { path = "../../tests/utils" } @@ -44,6 +41,10 @@ futures = "0.3.25" safe-path = "0.1.0" crossbeam-channel = "0.5.6" +[target.'cfg(not(target_arch = "s390x"))'.dependencies] +dragonball = { path = "../../../dragonball", features = ["atomic-guest-memory", "virtio-vsock", "hotplug", "virtio-blk", "virtio-net", "virtio-fs", "vhost-net", "dbs-upcall", "virtio-mem", "virtio-balloon", "vhost-user-net", "host-device"] } +dbs-utils = { path = "../../../dragonball/src/dbs_utils" } + [features] default = [] diff --git a/src/runtime-rs/crates/hypervisor/src/lib.rs b/src/runtime-rs/crates/hypervisor/src/lib.rs index 24987447d2..b40001af22 100644 --- a/src/runtime-rs/crates/hypervisor/src/lib.rs +++ b/src/runtime-rs/crates/hypervisor/src/lib.rs @@ -13,6 +13,7 @@ pub mod device; pub mod hypervisor_persist; pub use device::driver::*; use device::DeviceType; +#[cfg(not(target_arch = "s390x"))] pub mod dragonball; mod kernel_param; pub mod qemu; @@ -20,7 +21,7 @@ pub use kernel_param::Param; pub mod utils; use std::collections::HashMap; -#[cfg(feature = "cloud-hypervisor")] +#[cfg(all(feature = "cloud-hypervisor", not(target_arch = "s390x")))] pub mod ch; use anyhow::Result; @@ -49,9 +50,12 @@ const VM_ROOTFS_FILESYSTEM_EROFS: &str = "erofs"; // /dev/hugepages will be the mount point // mkdir -p /dev/hugepages // mount -t hugetlbfs none /dev/hugepages +#[cfg(not(target_arch = "s390x"))] const DEV_HUGEPAGES: &str = "/dev/hugepages"; pub const HUGETLBFS: &str = "hugetlbfs"; +#[cfg(not(target_arch = "s390x"))] const SHMEM: &str = "shmem"; +#[cfg(not(target_arch = "s390x"))] const HUGE_SHMEM: &str = "hugeshmem"; pub const HYPERVISOR_DRAGONBALL: &str = "dragonball"; @@ -60,6 +64,7 @@ pub const HYPERVISOR_QEMU: &str = "qemu"; pub const DEFAULT_HYBRID_VSOCK_NAME: &str = "kata.hvsock"; pub const JAILER_ROOT: &str = "root"; +#[cfg(not(target_arch = "s390x"))] #[derive(PartialEq, Debug, Clone)] pub(crate) enum VmmState { NotReady, 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 60a3a6eb0e..1bc05b0480 100644 --- a/src/runtime-rs/crates/runtimes/virt_container/src/lib.rs +++ b/src/runtime-rs/crates/runtimes/virt_container/src/lib.rs @@ -20,15 +20,17 @@ use agent::{kata::KataAgent, AGENT_KATA}; use anyhow::{anyhow, Context, Result}; use async_trait::async_trait; use common::{message::Message, RuntimeHandler, RuntimeInstance}; -use hypervisor::{dragonball::Dragonball, Hypervisor, HYPERVISOR_DRAGONBALL}; +use hypervisor::Hypervisor; +#[cfg(not(target_arch = "s390x"))] +use hypervisor::{dragonball::Dragonball, HYPERVISOR_DRAGONBALL}; use hypervisor::{qemu::Qemu, HYPERVISOR_QEMU}; -use kata_types::config::{ - hypervisor::register_hypervisor_plugin, DragonballConfig, QemuConfig, TomlConfig, -}; +#[cfg(not(target_arch = "s390x"))] +use kata_types::config::DragonballConfig; +use kata_types::config::{hypervisor::register_hypervisor_plugin, QemuConfig, TomlConfig}; -#[cfg(feature = "cloud-hypervisor")] +#[cfg(all(feature = "cloud-hypervisor", not(target_arch = "s390x")))] use hypervisor::ch::CloudHypervisor; -#[cfg(feature = "cloud-hypervisor")] +#[cfg(all(feature = "cloud-hypervisor", not(target_arch = "s390x")))] use kata_types::config::{hypervisor::HYPERVISOR_NAME_CH, CloudHypervisorConfig}; use resource::cpu_mem::initial_size::InitialSizeManager; @@ -49,13 +51,16 @@ impl RuntimeHandler for VirtContainer { logging::register_subsystem_logger("runtimes", "virt-container"); // register - let dragonball_config = Arc::new(DragonballConfig::new()); - register_hypervisor_plugin("dragonball", dragonball_config); + #[cfg(not(target_arch = "s390x"))] + { + let dragonball_config = Arc::new(DragonballConfig::new()); + register_hypervisor_plugin("dragonball", dragonball_config); + } let qemu_config = Arc::new(QemuConfig::new()); register_hypervisor_plugin("qemu", qemu_config); - #[cfg(feature = "cloud-hypervisor")] + #[cfg(all(feature = "cloud-hypervisor", not(target_arch = "s390x")))] { let ch_config = Arc::new(CloudHypervisorConfig::new()); register_hypervisor_plugin(HYPERVISOR_NAME_CH, ch_config); @@ -135,6 +140,7 @@ async fn new_hypervisor(toml_config: &TomlConfig) -> Result> // TODO: support other hypervisor // issue: https://github.com/kata-containers/kata-containers/issues/4634 match hypervisor_name.as_str() { + #[cfg(not(target_arch = "s390x"))] HYPERVISOR_DRAGONBALL => { let mut hypervisor = Dragonball::new(); hypervisor @@ -150,7 +156,7 @@ async fn new_hypervisor(toml_config: &TomlConfig) -> Result> Ok(Arc::new(hypervisor)) } - #[cfg(feature = "cloud-hypervisor")] + #[cfg(all(feature = "cloud-hypervisor", not(target_arch = "s390x")))] HYPERVISOR_NAME_CH => { let mut hypervisor = CloudHypervisor::new(); diff --git a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs index 59ad1c08b7..3d8926018a 100644 --- a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs +++ b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs @@ -17,7 +17,9 @@ use common::message::{Action, Message}; use common::{Sandbox, SandboxNetworkEnv}; use containerd_shim_protos::events::task::TaskOOM; use hypervisor::VsockConfig; -use hypervisor::{dragonball::Dragonball, BlockConfig, Hypervisor, HYPERVISOR_DRAGONBALL}; +use hypervisor::{BlockConfig, Hypervisor}; +#[cfg(not(target_arch = "s390x"))] +use hypervisor::{dragonball::Dragonball, HYPERVISOR_DRAGONBALL}; use hypervisor::{utils::get_hvsock_path, HybridVsockConfig, DEFAULT_GUEST_VSOCK_CID}; use kata_sys_util::hooks::HookStates; use kata_types::capabilities::CapabilityBits; @@ -585,6 +587,7 @@ impl Persist for VirtSandbox { let h = sandbox_state.hypervisor.unwrap_or_default(); let hypervisor = match h.hypervisor_type.as_str() { // TODO support other hypervisors + #[cfg(not(target_arch = "s390x"))] HYPERVISOR_DRAGONBALL => Ok(Arc::new(Dragonball::restore((), h).await?)), _ => Err(anyhow!("Unsupported hypervisor {}", &h.hypervisor_type)), }?; From 8fcee6e6ec06e9958b3ad323b3d1b67e8ceb3be9 Mon Sep 17 00:00:00 2001 From: Hyounggyu Choi Date: Wed, 31 Jan 2024 15:24:34 +0100 Subject: [PATCH 2/3] runtime-rs: Use Persist::restore() of QEMU for VirtSandbox It fails to compile virt_container because Dragonball is only used in the implementation of the trait method Persist::restore(). As the hypervisor is not compiled on s390x and QEMU implements the trait method, this commit is to let the method use QEMUi's. Signed-off-by: Hyounggyu Choi --- .../crates/runtimes/virt_container/src/sandbox.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs index 3d8926018a..6f572083a6 100644 --- a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs +++ b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs @@ -17,10 +17,11 @@ use common::message::{Action, Message}; use common::{Sandbox, SandboxNetworkEnv}; use containerd_shim_protos::events::task::TaskOOM; use hypervisor::VsockConfig; -use hypervisor::{BlockConfig, Hypervisor}; #[cfg(not(target_arch = "s390x"))] use hypervisor::{dragonball::Dragonball, HYPERVISOR_DRAGONBALL}; +use hypervisor::{qemu::Qemu, HYPERVISOR_QEMU}; use hypervisor::{utils::get_hvsock_path, HybridVsockConfig, DEFAULT_GUEST_VSOCK_CID}; +use hypervisor::{BlockConfig, Hypervisor}; use kata_sys_util::hooks::HookStates; use kata_types::capabilities::CapabilityBits; use kata_types::config::TomlConfig; @@ -588,7 +589,14 @@ impl Persist for VirtSandbox { let hypervisor = match h.hypervisor_type.as_str() { // TODO support other hypervisors #[cfg(not(target_arch = "s390x"))] - HYPERVISOR_DRAGONBALL => Ok(Arc::new(Dragonball::restore((), h).await?)), + HYPERVISOR_DRAGONBALL => { + let hypervisor = Arc::new(Dragonball::restore((), h).await?) as Arc; + Ok(hypervisor) + } + HYPERVISOR_QEMU => { + let hypervisor = Arc::new(Qemu::restore((), h).await?) as Arc; + Ok(hypervisor) + } _ => Err(anyhow!("Unsupported hypervisor {}", &h.hypervisor_type)), }?; let agent = Arc::new(KataAgent::new(kata_types::config::Agent::default())); From bb6f5073aa42b3e3ea2796c496b13e2e79bdc06a Mon Sep 17 00:00:00 2001 From: Hyounggyu Choi Date: Wed, 31 Jan 2024 13:20:35 +0100 Subject: [PATCH 3/3] runtime-rs: Allow compilation for s390x Until now, runtime-rs couldn't be compiled on s390x. We need to lift those restrictions in Makefile first. Fixes: #8446 Signed-off-by: Hyounggyu Choi --- src/runtime-rs/Makefile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/runtime-rs/Makefile b/src/runtime-rs/Makefile index 66d32c1fc0..eee60818a3 100644 --- a/src/runtime-rs/Makefile +++ b/src/runtime-rs/Makefile @@ -26,15 +26,11 @@ ARCH_FILE_SUFFIX = -options.mk ARCH_FILE = $(ARCH_DIR)/$(ARCH)$(ARCH_FILE_SUFFIX) ifeq ($(ARCH), s390x) -default: - @echo "s390x is not currently supported" - exit 0 +default: runtime show-header test: @echo "s390x is not currently supported" exit 0 -install: - @echo "s390x is not currently supported" - exit 0 +install: install-runtime install-configs else ifeq ($(ARCH), powerpc64le) default: @echo "PowerPC 64 LE is not currently supported"