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 <fengshifang@linux.alibaba.com>
Signed-off-by: Chao Wu <chaowu@linux.alibaba.com>
This commit is contained in:
Chao Wu 2023-02-14 17:04:02 +08:00
parent b74e84e123
commit 337f19f0b2
2 changed files with 14 additions and 0 deletions

View File

@ -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 {

View File

@ -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() {