1# Intel TDX 2 3Intel® Trust Domain Extensions (Intel® TDX) is an Intel technology designed to 4isolate virtual machines from the VMM, hypervisor and any other software on the 5host platform. Here are some useful links: 6 7* [TDX Homepage](https://www.intel.com/content/www/us/en/developer/articles/technical/intel-trust-domain-extensions.html): 8more information about TDX technical aspects, design and specification 9 10* [KVM TDX tree](https://github.com/intel/tdx/tree/kvm): the required 11 Linux kernel changes for the host side 12 13* [Guest TDX tree](https://github.com/intel/tdx/tree/guest): the Linux 14 kernel changes for the guest side 15 16* [EDK2 project](https://github.com/tianocore/edk2): the TDVF firmware 17 18* [Confidential Containers project](https://github.com/confidential-containers/td-shim): 19 the TDShim firmware 20 21* [TDX Tools](https://github.com/intel/tdx-tools): a collection of tools 22 and scripts to setup TDX environment for testing purpose (such as 23 installing required packages on the host, creating guest images, and 24 building the custom Linux kernel for TDX host and guest) 25 26## Cloud Hypervisor support 27 28It is required to use a machine with TDX enabled in hardware and 29with the host OS compiled from the [KVM TDX tree](https://github.com/intel/tdx/tree/kvm). 30The host environment can also be setup with the [TDX Tools](https://github.com/intel/tdx-tools). 31 32Cloud Hypervisor can run TDX VM (Trust Domain) by loading a TD firmware ([TDVF](https://github.com/tianocore/edk2)), 33which will then load the guest kernel from the image. The image must be custom 34as it must include a kernel built from the [Guest TDX tree](https://github.com/intel/tdx/tree/guest). 35Cloud Hypervisor can also boot a TDX VM with direct kernel boot using [TDshim](https://github.com/confidential-containers/td-shim). 36The custom Linux kernel for the guest can be built with the [TDX Tools](https://github.com/intel/tdx-tools). 37 38> **Note** 39> The latest version of custom host and guest kernel being tested is 40> from [TDX Tools - 2023ww01](https://github.com/intel/tdx-tools/commits/2023ww01). 41 42### TDVF 43 44> **Note** 45> The latest version of TDVF being tested is [_13b9773_](https://github.com/tianocore/edk2/commit/13b97736c876919b9786055829caaa4fa46984b7). 46 47The firmware can be built as follows: 48 49```bash 50sudo apt-get update 51sudo apt-get install uuid-dev nasm iasl build-essential python3-distutils git 52 53git clone https://github.com/tianocore/edk2.git 54cd edk2 55git checkout 13b97736c876919b9786055829caaa4fa46984b7 56source ./edksetup.sh 57git submodule update --init --recursive 58make -C BaseTools -j `nproc` 59build -p OvmfPkg/IntelTdx/IntelTdxX64.dsc -a X64 -t GCC5 -b RELEASE 60``` 61 62If debug logs are needed, here is the alternative command: 63 64```bash 65build -p OvmfPkg/IntelTdx/IntelTdxX64.dsc -a X64 -t GCC5 -D DEBUG_ON_SERIAL_PORT=TRUE 66``` 67 68On the Cloud Hypervisor side, all you need is to build the project with the 69`tdx` feature enabled: 70 71```bash 72cargo build --features tdx 73``` 74 75And run a TDX VM by providing the firmware previously built, along with the 76guest image containing the TDX enlightened kernel. The latest image 77`td-guest-rhel8.5.raw` contains `console=hvc0` on the kernel boot parameters, 78meaning it will be printing guest kernel logs to the `virtio-console` device. 79 80```bash 81./cloud-hypervisor \ 82 --platform tdx=on 83 --firmware edk2/Build/IntelTdx/RELEASE_GCC5/FV/OVMF.fd \ 84 --cpus boot=1 \ 85 --memory size=1G \ 86 --disk path=tdx_guest_img 87``` 88 89And here is the alternative command when looking for debug logs from the 90firmware: 91 92```bash 93./cloud-hypervisor \ 94 --platform tdx=on 95 --firmware edk2/Build/IntelTdx/DEBUG_GCC5/FV/OVMF.fd \ 96 --cpus boot=1 \ 97 --memory size=1G \ 98 --disk path=tdx_guest_img \ 99 --serial file=/tmp/ch_serial \ 100 --console tty 101``` 102 103### TDShim 104 105> **Note** 106> The latest version of TDShim being tested is [_v0.8.0_](https://github.com/confidential-containers/td-shim/releases/tag/v0.8.0). 107 108This is a lightweight version of the TDVF, written in Rust and designed for 109direct kernel boot, which is useful for containers use cases. 110 111To build TDShim from source, it is required to install `Rust`, `NASM`, 112and `LLVM` first. The TDshim can be build as follows: 113```bash 114git clone https://github.com/confidential-containers/td-shim 115cd td-shim 116git checkout v0.8.0 117cargo install cargo-xbuild 118export CC=clang 119export AR=llvm-ar 120export CC_x86_64_unknown_none=clang 121export AR_x86_64_unknown_none=llvm-ar 122git submodule update --init --recursive 123./sh_script/preparation.sh 124cargo image --release 125``` 126 127If debug logs from the TDShim is needed, here are the alternative 128commands: 129```bash 130cargo image 131``` 132 133And run a TDX VM by providing the firmware previously built, along with a guest 134kernel built from the [Guest TDX tree](https://github.com/intel/tdx/tree/guest) 135or the [TDX Tools](https://github.com/intel/tdx-tools). 136The appropriate kernel boot options must be provided through the `--cmdline` 137option as well. 138 139```bash 140./cloud-hypervisor \ 141 --platform tdx=on 142 --firmware td-shim/target/release/final.bin \ 143 --kernel bzImage \ 144 --cmdline "root=/dev/vda3 console=hvc0 rw" 145 --cpus boot=1 \ 146 --memory size=1G \ 147 --disk path=tdx_guest_img 148``` 149 150And here is the alternative command when looking for debug logs from the 151TDShim: 152 153```bash 154./cloud-hypervisor \ 155 --platform tdx=on 156 --firmware td-shim/target/debug/final.bin \ 157 --kernel bzImage \ 158 --cmdline "root=/dev/vda3 console=hvc0 rw" 159 --cpus boot=1 \ 160 --memory size=1G \ 161 --disk path=tdx_guest_img 162``` 163 164### Guest kernel limitations 165 166#### Serial ports disabled 167 168The latest guest kernel that can be found in the latest image 169`td-guest-rhel8.5.raw` disabled the support for serial ports. This means adding 170`console=ttyS0` will have no effect and will not print any log from the guest. 171 172#### PCI hotplug through ACPI 173 174Unless you run the guest kernel with the parameter `tdx_disable_filter`, ACPI 175devices responsible for handling PCI hotplug (PCI hotplug controller, PCI 176Express Bus and Generic Event Device) will not be allowed, therefore the 177corresponding drivers will not be loaded and the PCI hotplug feature will not 178be supported. 179