From 337f19f0b2dd5eb429beccb1620baaa12be1abd1 Mon Sep 17 00:00:00 2001 From: Chao Wu Date: Tue, 14 Feb 2023 17:04:02 +0800 Subject: [PATCH] Dragonball: add is_tdx_enabled to identify tdx VM type In order to disable or enable some features when running tdx vms, we need to add is_tdx_enabled() function to identify whether the VM confidiential type is TDX. fixes: #6276 Signed-off-by: fengshifang Signed-off-by: Chao Wu --- src/dragonball/src/api/v1/instance_info.rs | 5 +++++ src/dragonball/src/vm/mod.rs | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/dragonball/src/api/v1/instance_info.rs b/src/dragonball/src/api/v1/instance_info.rs index 9d89c488f3..5b99e6a680 100644 --- a/src/dragonball/src/api/v1/instance_info.rs +++ b/src/dragonball/src/api/v1/instance_info.rs @@ -83,6 +83,11 @@ impl InstanceInfo { confidential_vm_type: None, } } + + /// return true if VM confidential type is TDX + pub fn is_tdx_enabled(&self) -> bool { + matches!(self.confidential_vm_type, Some(ConfidentialVmType::TDX)) + } } impl Default for InstanceInfo { diff --git a/src/dragonball/src/vm/mod.rs b/src/dragonball/src/vm/mod.rs index 51262c92fd..c8a6a39e19 100644 --- a/src/dragonball/src/vm/mod.rs +++ b/src/dragonball/src/vm/mod.rs @@ -350,6 +350,15 @@ impl Vm { instance_state == InstanceState::Running } + /// return true if VM confidential type is TDX + pub fn is_tdx_enabled(&self) -> bool { + let shared_info = self + .shared_info() + .read() + .expect("failed to get instance state, because shared info is poisoned lock"); + shared_info.is_tdx_enabled() + } + /// Save VM instance exit state pub fn vm_exit(&self, exit_code: i32) { if let Ok(mut info) = self.shared_info.write() {