Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Intel Trust Domain Extensions (TDX) #228

Draft
wants to merge 36 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
923e3f8
Modify existing Confidential Computing feature flags
jakecorrenti Sep 16, 2024
b1dfbf1
Fix examples/launch-tee.c and examples/Makefile
jakecorrenti Sep 18, 2024
4ce8c6f
Add TDX targets to the Makefile
jakecorrenti Sep 18, 2024
dbcfaa2
Add virtee/tdx, update kvm-{ioctls, bindings}
jakecorrenti Oct 19, 2024
d2a99db
Use `kvm_userspace_memory_region2` and friends
jakecorrenti Sep 17, 2024
f1b37f4
Implement `Vm::new()` for TDX
jakecorrenti Sep 17, 2024
d043370
Implement `tdx_secure_virt_prepare`
jakecorrenti Sep 17, 2024
07897a4
Init TDX vCPU
jakecorrenti Oct 21, 2024
f1c7e53
Add definitions from UEFI spec
jakecorrenti Oct 21, 2024
298554c
Add TDX Ram types
jakecorrenti Oct 21, 2024
9ef2f98
Add `TdxHob` and `TdxFirmwareEntry`
jakecorrenti Oct 21, 2024
173ac7d
Add `IntelTdx::init_ram_entries`
jakecorrenti Oct 21, 2024
8ac8027
Add API to create TD Hob
jakecorrenti Oct 21, 2024
21cd1df
Add `configure_td_memory` method for `IntelTdx`
jakecorrenti Oct 21, 2024
6f2f262
Wire together configuring TD mem regions
jakecorrenti Oct 21, 2024
3a3abd4
Finalize TD VM measurements
jakecorrenti Oct 21, 2024
43c3c76
Add `tdx-config-noattest.json` config file
jakecorrenti Oct 21, 2024
463ab38
TDX disable `KVM_CREATE_IRQCHIP` in-kernel IRQ
jakecorrenti Oct 21, 2024
01e3e39
Disable configuring registers for TDX
jakecorrenti Oct 21, 2024
270574c
Use different arch regions for TDX
jakecorrenti Oct 21, 2024
08cfe55
Link with krunfw-tdx for intel-tdx feature
jakecorrenti Oct 30, 2024
95f8b87
TEST: link with libkrunfw-tdx
jakecorrenti Nov 4, 2024
8655af5
TESTING: using a *custom* firmware that just halts at the reset vecto…
jakecorrenti Nov 6, 2024
5de5c75
TESTING: more stuff with testing the firmware setup and a custom over…
jakecorrenti Nov 7, 2024
d9c91d1
TESTING: revert all changes that coordinate with the TDVf firmware. n…
jakecorrenti Nov 11, 2024
24436bc
TESTING: for TDX we dont need to use qboot, so dont worry about writi…
jakecorrenti Nov 11, 2024
6aaa8e9
TESTING: load TDVF for guest
jakecorrenti Nov 11, 2024
8435cbb
TESTING: mist cmdline flag check from tee to amd-sev
jakecorrenti Nov 11, 2024
85f2feb
TESTING: keep track of e820 ram regions
jakecorrenti Nov 12, 2024
b3e3479
TESTING: add `configure_td_memory` stub
jakecorrenti Nov 12, 2024
e03d3ac
TESTING: keep track of TDVF mem_ptr
jakecorrenti Nov 12, 2024
22b55cb
TESTING: Track RAM entries for TDX
jakecorrenti Nov 21, 2024
fd4adf3
TESTING: Add definitions from UEFI spec && setup the TD HOB list
jakecorrenti Nov 22, 2024
7543a48
misc testing commit
jakecorrenti Dec 13, 2024
ad547c0
TESTING: changes before trying to use qboot
jakecorrenti Dec 19, 2024
2e9bbff
testing: use qboot-krunfw instead of TDVF
jakecorrenti Jan 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ SNP_INIT_SRC = init/tee/snp_attest.c \
init/tee/snp_attest.h \
$(KBS_INIT_SRC) \

TDX_INIT_SRC = $(KBS_INIT_SRC)

KBS_LD_FLAGS = -lcurl -lidn2 -lssl -lcrypto -lzstd -lz -lbrotlidec-static \
-lbrotlicommon-static

Expand All @@ -27,6 +29,14 @@ ifeq ($(SEV),1)
INIT_SRC += $(SNP_INIT_SRC)
BUILD_INIT = 0
endif
ifeq ($(TDX),1)
VARIANT = -tdx
FEATURE_FLAGS := --features intel-tdx,tee,blk,kbs-types,serde,serde_json,curl
INIT_DEFS += -DTDX=1
INIT_DEFS += $(KBS_LD_FLAGS)
INIT_SRC += $(KBS_INIT_SRC)
BUILD_INIT = 0
endif
ifeq ($(GPU),1)
FEATURE_FLAGS += --features gpu
endif
Expand Down Expand Up @@ -91,6 +101,9 @@ $(LIBRARY_RELEASE_$(OS)): $(INIT_BINARY)
ifeq ($(SEV),1)
mv target/release/libkrun.so target/release/$(KRUN_BASE_$(OS))
endif
ifeq ($(TDX),1)
mv target/release/libkrun.so target/release/$(KRUN_BASE_$(OS))
endif
ifeq ($(OS),Linux)
patchelf --set-soname $(KRUN_SONAME_$(OS)) --output $(LIBRARY_RELEASE_$(OS)) target/release/$(KRUN_BASE_$(OS))
else
Expand All @@ -108,6 +121,9 @@ $(LIBRARY_DEBUG_$(OS)): $(INIT_BINARY)
ifeq ($(SEV),1)
mv target/debug/libkrun.so target/debug/$(KRUN_BASE_$(OS))
endif
ifeq ($(TDX),1)
mv target/debug/libkrun.so target/debug/$(KRUN_BASE_$(OS))
endif
ifeq ($(OS),Linux)
patchelf --set-soname $(KRUN_SONAME_$(OS)) --output $(LIBRARY_DEBUG_$(OS)) target/debug/$(KRUN_BASE_$(OS))
else
Expand Down
9 changes: 9 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ LDFLAGS_x86_64_Linux = -lkrun
LDFLAGS_aarch64_Linux = -lkrun
LDFLAGS_arm64_Darwin = -L/opt/homebrew/lib -lkrun
LDFLAGS_sev = -lkrun-sev
LDFLAGS_tdx = -lkrun-tdx
LDFLAGS_efi = -L/opt/homebrew/lib -lkrun-efi
CFLAGS = -O2 -g -I../include
ROOTFS_DISTRO := fedora
Expand All @@ -15,6 +16,9 @@ EXAMPLES := chroot_vm
ifeq ($(SEV),1)
EXAMPLES := launch-tee
endif
ifeq ($(TDX),1)
EXAMPLES := launch-tee
endif
ifeq ($(EFI),1)
EXAMPLES := boot_efi
endif
Expand All @@ -28,7 +32,12 @@ ifeq ($(OS),Darwin)
endif

launch-tee: launch-tee.c
ifeq ($(SEV),1)
gcc -o $@ $< $(CFLAGS) $(LDFLAGS_sev)
endif
ifeq ($(TDX),1)
gcc -o $@ $< $(CFLAGS) $(LDFLAGS_tdx)
endif

boot_efi: boot_efi.c
gcc -o $@ $< $(CFLAGS) $(LDFLAGS_efi)
Expand Down
4 changes: 2 additions & 2 deletions examples/launch-tee.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

int main(int argc, char *const argv[])
{
char *const port_map[] =
const char *const port_map[] =
{
"18000:8000",
0
};
char *const rlimits[] =
const char *const rlimits[] =
{
// RLIMIT_NPROC = 6
"6=4096:8192",
Expand Down
8 changes: 8 additions & 0 deletions examples/tdx-config-noattest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"workload_id": "tdxtest",
"cpus": 1,
"ram_mib": 2048,
"tee": "tdx",
"tee_data": "{\"vendor_chain\": \"\", \"attestation_server_pubkey\": \"\"}",
"attestation_url": ""
}
6 changes: 4 additions & 2 deletions src/arch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"

[features]
tee = []
intel-tdx = [ "tee", "tdx" ]
amd-sev = [ "tee" ]
efi = []

Expand All @@ -18,8 +19,9 @@ smbios = { path = "../smbios" }
utils = { path = "../utils" }

[target.'cfg(target_os = "linux")'.dependencies]
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] }
kvm-ioctls = ">=0.17"
kvm-bindings = { version = "0.9.1", features = ["fam-wrappers"] }
kvm-ioctls = "0.18"
tdx = { path = "../../../tdx", optional = true }

[target.'cfg(target_arch = "aarch64")'.dependencies]
vm-fdt = ">= 0.2.0"
Expand Down
26 changes: 25 additions & 1 deletion src/arch/src/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ pub enum Error {

// Where BIOS/VGA magic would live on a real PC.
const EBDA_START: u64 = 0x9fc00;
#[cfg(not(feature = "intel-tdx"))]
pub const RESET_VECTOR: u64 = 0xfff0;
#[cfg(feature = "intel-tdx")]
pub const RESET_VECTOR: u64 = 0xffff_fff0;
pub const RESET_VECTOR_SEV_AP: u64 = 0xfff3;
pub const BIOS_START: u64 = 0xffff_0000;
pub const BIOS_SIZE: usize = 65536;
Expand Down Expand Up @@ -119,6 +122,15 @@ pub fn arch_memory_regions(
(info, regions)
}

#[cfg(feature = "intel-tdx")]
fn get_tdvf_image_size() -> usize {
use std::io::{Seek, SeekFrom};
let mut fs = std::fs::File::open("/home/jcorrent/edk2/Build/IntelTdx/DEBUG_GCC5/FV/OVMF.fd").unwrap();
// let mut fs = std::fs::File::open("/home/jcorrent/edk2/Build/IntelTdx/RELEASE_GCC5/FV/OVMF.fd").unwrap();
// TODO(jakecorrenti): do proper error handling here
fs.seek(SeekFrom::End(0)).unwrap() as usize
}

/// Returns a Vec of the valid memory addresses.
/// These should be used to configure the GuestMemoryMmap structure for the platform.
/// For SEV, don't make a hole for the kernel, as it needs to be copied instead of injected,
Expand All @@ -132,6 +144,11 @@ pub fn arch_memory_regions(
) -> (ArchMemoryInfo, Vec<(GuestAddress, usize)>) {
let page_size: usize = unsafe { libc::sysconf(libc::_SC_PAGESIZE).try_into().unwrap() };

#[cfg(feature = "intel-tdx")]
let tdvf_image_size = get_tdvf_image_size();
#[cfg(feature = "intel-tdx")]
let tdvf_image_start_addr = 0x1_0000_0000 - tdvf_image_size;

let size = round_up(size, page_size);
if size < (kernel_load_addr + kernel_size as u64) as usize {
panic!("Kernel doesn't fit in RAM");
Expand Down Expand Up @@ -214,6 +231,8 @@ pub fn configure_system(
cmdline_size: usize,
initrd: &Option<InitrdConfig>,
num_cpus: u8,
ram_entries: &mut Vec<arch_gen::x86::bootparam::e820entry>,
nr_ram_entries: &mut u8,
) -> super::Result<()> {
const KERNEL_BOOT_FLAG_MAGIC: u16 = 0xaa55;
const KERNEL_HDR_MAGIC: u32 = 0x5372_6448;
Expand Down Expand Up @@ -244,7 +263,9 @@ pub fn configure_system(

#[cfg(feature = "tee")]
{
params.0.hdr.syssize = num_cpus as u32;
// params.0.hdr.syssize = num_cpus as u32;
params.0.hdr.syssize = (arch_memory_info.ram_last_addr / 4096) as u32;
params.0.hdr.root_flags = num_cpus as u16;
}

add_e820_entry(&mut params.0, 0, EBDA_START, E820_RAM)?;
Expand Down Expand Up @@ -286,6 +307,9 @@ pub fn configure_system(
.write_obj(params, zero_page_addr)
.map_err(|_| Error::ZeroPageSetup)?;

*ram_entries = params.0.e820_map.to_vec();
*nr_ram_entries = params.0.e820_entries;

Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions src/arch/src/x86_64/mptable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ pub fn setup_mptable(mem: &GuestMemoryMmap, num_cpus: u8) -> Result<()> {
let mut mpc_bus = MpcBusWrapper(mpspec::mpc_bus::default());
mpc_bus.0.type_ = mpspec::MP_BUS as u8;
mpc_bus.0.busid = 0;
panic!("hi");
mpc_bus.0.bustype = BUS_TYPE_ISA;
mem.write_obj(mpc_bus, base_mp)
.map_err(|_| Error::WriteMpcBus)?;
Expand Down
4 changes: 2 additions & 2 deletions src/cpuid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ edition = "2021"
vmm-sys-util = ">=0.11"

[target.'cfg(target_os = "linux")'.dependencies]
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] }
kvm-ioctls = ">=0.17"
kvm-bindings = { version = "0.9.1", features = ["fam-wrappers"] }
kvm-ioctls = "0.18"
4 changes: 3 additions & 1 deletion src/libkrun/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ fn main() {
println!("cargo:rustc-link-search=/opt/homebrew/lib");
#[cfg(all(not(feature = "tee"), not(feature = "efi")))]
println!("cargo:rustc-link-lib=krunfw");
#[cfg(feature = "tee")]
#[cfg(feature = "amd-sev")]
println!("cargo:rustc-link-lib=krunfw-sev");
#[cfg(feature = "intel-tdx")]
println!("cargo:rustc-link-lib=krunfw-tdx");
}
16 changes: 15 additions & 1 deletion src/libkrun/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ extern "C" {
fn krunfw_get_version() -> u32;
}

#[cfg(feature = "tee")]
#[cfg(feature = "amd-sev")]
#[link(name = "krunfw-sev")]
extern "C" {
fn krunfw_get_qboot(size: *mut size_t) -> *mut c_char;
Expand All @@ -264,6 +264,20 @@ extern "C" {
fn krunfw_get_version() -> u32;
}

// #[cfg(all(feature = "intel-tdx", feature = "tee"))]
#[cfg(feature = "tee")]
#[link(name = "krunfw-tdx")]
extern "C" {
fn krunfw_get_qboot(size: *mut size_t) -> *mut c_char;
fn krunfw_get_initrd(size: *mut size_t) -> *mut c_char;
fn krunfw_get_kernel(
load_addr: *mut u64,
entry_addr: *mut u64,
size: *mut size_t,
) -> *mut c_char;
fn krunfw_get_version() -> u32;
}

#[no_mangle]
pub extern "C" fn krun_set_log_level(level: u32) -> i32 {
let log_level = match level {
Expand Down
8 changes: 6 additions & 2 deletions src/vmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
[features]
tee = []
amd-sev = [ "blk", "tee", "codicon", "kbs-types", "procfs", "serde", "serde_json", "sev", "curl" ]
intel-tdx = [ "blk", "tee", "kbs-types", "serde", "serde_json", "curl", "tdx" ]
net = []
blk = []
efi = [ "blk", "net" ]
Expand All @@ -21,6 +22,7 @@ log = "0.4.0"
vm-memory = { version = ">=0.13", features = ["backend-mmap"] }

arch = { path = "../arch" }
arch_gen = { path = "../arch_gen" }
devices = { path = "../devices" }
kernel = { path = "../kernel" }
utils = { path = "../utils"}
Expand All @@ -36,12 +38,14 @@ sev = { version = "3.2.0", features = ["openssl"], optional = true }
curl = { version = "0.4", optional = true }
nix = "0.24.1"

tdx = { path = "../../../tdx", optional = true }

[target.'cfg(target_arch = "x86_64")'.dependencies]
cpuid = { path = "../cpuid" }

[target.'cfg(target_os = "linux")'.dependencies]
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] }
kvm-ioctls = ">=0.17"
kvm-bindings = { version = "0.9.1", features = ["fam-wrappers"] }
kvm-ioctls = "0.18"

[target.'cfg(target_os = "macos")'.dependencies]
hvf = { path = "../hvf" }
Expand Down
Loading