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 crate::hv::Result;16
use crate::hv::kvm::tdx::tdx_op;17
use crate::hv::kvm::vcpu::KvmVcpu;18
use crate::sys::tdx::{KvmTdxCmdId, KvmTdxInitMemRegion, KvmTdxInitMemRegionFlag};19
20
impl KvmVcpu {21
pub fn tdx_init_mem_region(&self, data: &[u8], gpa: u64, measure: bool) -> Result<()> {22
let mut region = KvmTdxInitMemRegion {23
source_addr: data.as_ptr() as u64,24
nr_pages: data.len() as u64 >> 12,25
gpa,26
};27
let flag = if measure {28
KvmTdxInitMemRegionFlag::MEASURE_MEMORY_REGION29
} else {30
KvmTdxInitMemRegionFlag::empty()31
};32
tdx_op(33
&self.fd,34
KvmTdxCmdId::INIT_MEM_REGION,35
flag.bits(),36
Some(&mut region),37
)38
}39
40
pub fn tdx_init_vcpu(&self, mut hob: u64) -> Result<()> {41
tdx_op(&self.fd, KvmTdxCmdId::INIT_VCPU, 0, Some(&mut hob))42
}43
}44