tdx.rs0.00%
1
// Copyright 2026 Google LLC2
//3
// Licensed under the Apache License, Version 2.0 (the "License");4
// you may not use this file except in compliance with the License.5
// You may obtain a copy of the License at6
//7
// https://www.apache.org/licenses/LICENSE-2.08
//9
// Unless required by applicable law or agreed to in writing, software10
// distributed under the License is distributed on an "AS IS" BASIS,11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12
// See the License for the specific language governing permissions and13
// limitations under the License.14
15
use std::os::fd::OwnedFd;16
17
use snafu::ResultExt;18
19
use crate::hv::{Result, error};20
use crate::sys::kvm::kvm_memory_encrypt_op;21
use crate::sys::tdx::{KvmTdxCmd, KvmTdxCmdId};22
23
pub fn tdx_op<T>(fd: &OwnedFd, cmd: KvmTdxCmdId, flags: u32, data: Option<&mut T>) -> Result<()> {24
let mut req = KvmTdxCmd {25
id: cmd,26
flags,27
data: data.map(|d| d as *mut _ as _).unwrap_or(0),28
hw_error: 0,29
};30
unsafe { kvm_memory_encrypt_op(fd, &mut req) }.context(error::MemEncrypt)?;31
if req.hw_error != 0 {32
return error::TdxErr { code: req.hw_error }.fail();33
}34
Ok(())35
}36