From 93980898ec8967a598b72efe7b5db710d8a81cf7 Mon Sep 17 00:00:00 2001 From: "Ouyang, Hang" Date: Thu, 6 Jun 2024 19:53:19 -0700 Subject: [PATCH] Upstream tdx-tdcall to crates.io Signed-off-by: Ouyang, Hang Signed-off-by: OuyangHang33 --- tdx-tdcall/Cargo.toml | 3 +++ tdx-tdcall/README.md | 16 ++++++++++++++++ tdx-tdcall/src/tdx.rs | 8 ++++---- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 tdx-tdcall/README.md diff --git a/tdx-tdcall/Cargo.toml b/tdx-tdcall/Cargo.toml index 1f0ac907..59b41821 100644 --- a/tdx-tdcall/Cargo.toml +++ b/tdx-tdcall/Cargo.toml @@ -7,6 +7,9 @@ homepage = "https://github.com/confidential-containers" license = "BSD-2-Clause-Patent" edition = "2018" +readme = "README.md" +keywords = ["TDCALL", "TDX", "intel"] + [dependencies] lazy_static = { version = "1.0", features = ["spin_no_std"] } log = "0.4.13" diff --git a/tdx-tdcall/README.md b/tdx-tdcall/README.md new file mode 100644 index 00000000..3c1e2d67 --- /dev/null +++ b/tdx-tdcall/README.md @@ -0,0 +1,16 @@ +[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fconfidential-containers%2Ftd-shim.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fconfidential-containers%2Ftd-shim?ref=badge_shield) +# TDX-tdcall - Trust Domain Extensions tdcall + +## Documents + +* [Intel TDX](https://software.intel.com/content/www/us/en/develop/articles/intel-trust-domain-extensions.html) + +## Introduction + +Intel’s Trust Domain Extensions (TDX) protect confidential guest VMs from the host and physical attacks by isolating the guest register state and by encrypting the guest memory. In TDX, a special module running in a special mode sits between the host and the guest and manages the guest/host separation. + +This tdx-tdcall crate provides constants, stuctures and wrappers to support user access TDCALL services. + + +## License +[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fconfidential-containers%2Ftd-shim.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fconfidential-containers%2Ftd-shim?ref=badge_large) diff --git a/tdx-tdcall/src/tdx.rs b/tdx-tdcall/src/tdx.rs index 4cd246bf..9cab1045 100644 --- a/tdx-tdcall/src/tdx.rs +++ b/tdx-tdcall/src/tdx.rs @@ -234,7 +234,7 @@ pub fn tdvmcall_io_write_32(port: u16, byte: u32) { pub fn tdvmcall_mmio_write(address: *const T, value: T) { let address = address as u64 | *SHARED_MASK; fence(Ordering::SeqCst); - let val = unsafe { *(&value as *const T as *const u64) }; + let val = unsafe { *(core::ptr::addr_of!(value) as *const u64) }; let mut args = TdVmcallArgs { r11: TDVMCALL_MMIO, @@ -273,7 +273,7 @@ pub fn tdvmcall_mmio_read(address: usize) -> T { tdvmcall_halt(); } - unsafe { *(&args.r11 as *const u64 as *const T) } + unsafe { *(core::ptr::addr_of!(args.r11) as *const T) } } /// Used to request the host VMM to map a GPA range as a private or shared memory mappings. @@ -514,8 +514,8 @@ pub fn tdcall_get_td_info() -> Result { /// /// Details can be found in TDX Module ABI spec section 'TDG.VP.INFO Leaf' pub fn tdcall_extend_rtmr(digest: &TdxDigest, mr_index: u32) -> Result<(), TdCallError> { - let buffer: u64 = &digest.data as *const u8 as u64; - + let buffer: u64 = core::ptr::addr_of!(digest.data) as u64; + let mut args = TdcallArgs { rax: TDCALL_TDEXTENDRTMR, rcx: buffer,