From 360506225808649a8ec71e14af2ccac63df9238b Mon Sep 17 00:00:00 2001 From: Zhongtao Hu Date: Fri, 23 Dec 2022 14:03:45 +0800 Subject: [PATCH 1/2] runtime-rs: add dbs-upcall feature add dbs-upcall feature to dragonball Fixes:#5949 Depends-on: github.com/kata-containers/tests#5355 Signed-off-by: Zhongtao Hu --- src/runtime-rs/Cargo.lock | 15 +++++++++++++++ src/runtime-rs/crates/hypervisor/Cargo.toml | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/runtime-rs/Cargo.lock b/src/runtime-rs/Cargo.lock index 90129b4c5b..a7b3a186e6 100644 --- a/src/runtime-rs/Cargo.lock +++ b/src/runtime-rs/Cargo.lock @@ -651,6 +651,20 @@ dependencies = [ "mio", ] +[[package]] +name = "dbs-upcall" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2fa8b67657cd71779eaceea1b5fa989b62a1be629a07be8498417772e5a8d35" +dependencies = [ + "anyhow", + "dbs-utils", + "dbs-virtio-devices", + "log", + "thiserror", + "timerfd", +] + [[package]] name = "dbs-utils" version = "0.2.1" @@ -743,6 +757,7 @@ dependencies = [ "dbs-device", "dbs-interrupt", "dbs-legacy-devices", + "dbs-upcall", "dbs-utils", "dbs-virtio-devices", "kvm-bindings", diff --git a/src/runtime-rs/crates/hypervisor/Cargo.toml b/src/runtime-rs/crates/hypervisor/Cargo.toml index 7e49850a03..9c70f3914d 100644 --- a/src/runtime-rs/crates/hypervisor/Cargo.toml +++ b/src/runtime-rs/crates/hypervisor/Cargo.toml @@ -30,6 +30,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"] } +dragonball = { path = "../../../dragonball", features = ["atomic-guest-memory", "virtio-vsock", "hotplug", "virtio-blk", "virtio-net", "virtio-fs","dbs-upcall"] } [features] From a2e3715e01bf5f8ecba3818914365ed28a08f6f4 Mon Sep 17 00:00:00 2001 From: Chao Wu Date: Wed, 28 Dec 2022 20:23:39 +0800 Subject: [PATCH 2/2] upcall: remove upcall client when stopping vm In order to avoid resource leak, we need to remove upcall client in vm and vcpu manager when stopping vm. Signed-off-by: Chao Wu --- src/dragonball/src/vm/mod.rs | 7 +++++++ src/dragonball/src/vmm.rs | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/dragonball/src/vm/mod.rs b/src/dragonball/src/vm/mod.rs index 21935faa65..d573080ae8 100644 --- a/src/dragonball/src/vm/mod.rs +++ b/src/dragonball/src/vm/mod.rs @@ -492,6 +492,13 @@ impl Vm { .map_err(StopMicrovmError::DeviceManager) } + /// Remove upcall client when the VM is destoryed. + #[cfg(feature = "dbs-upcall")] + pub fn remove_upcall(&mut self) -> std::result::Result<(), StopMicrovmError> { + self.upcall_client = None; + Ok(()) + } + /// Reset the console into canonical mode. pub fn reset_console(&self) -> std::result::Result<(), DeviceMgrError> { self.device_manager.reset_console() diff --git a/src/dragonball/src/vmm.rs b/src/dragonball/src/vmm.rs index 1cfbfac584..b15e66fef1 100644 --- a/src/dragonball/src/vmm.rs +++ b/src/dragonball/src/vmm.rs @@ -162,6 +162,11 @@ impl Vmm { warn!("failed to remove devices: {:?}", e); } + #[cfg(feature = "dbs-upcall")] + if let Err(e) = vm.remove_upcall() { + warn!("failed to remove upcall: {:?}", e); + } + if let Err(e) = vm.reset_console() { warn!("Cannot set canonical mode for the terminal. {:?}", e); } @@ -174,6 +179,8 @@ impl Vmm { if let Err(e) = mgr.exit_all_vcpus() { warn!("Failed to exit vcpu thread. {:?}", e); } + #[cfg(feature = "dbs-upcall")] + mgr.set_upcall_channel(None); } Err(e) => warn!("Failed to get vcpu manager {:?}", e), }