xref: /cloud-hypervisor/docs/intel_tdx.md (revision ea4693a09123234951ae1516f112c5cfce5032ca)
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/tools/trust-domain-extensions/overview.html):
8  more 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 Linux](https://github.com/intel/tdx-linux): 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 Linux](https://github.com/intel/tdx-linux).
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 Linux](https://github.com/intel/tdx-linux).
37
38### TDVF
39
40> **Note**
41> The latest version of TDVF being tested is [_13b9773_](https://github.com/tianocore/edk2/commit/13b97736c876919b9786055829caaa4fa46984b7).
42
43The firmware can be built as follows:
44
45```bash
46sudo apt-get update
47sudo apt-get install uuid-dev nasm iasl build-essential python3-distutils git
48
49git clone https://github.com/tianocore/edk2.git
50cd edk2
51git checkout 13b97736c876919b9786055829caaa4fa46984b7
52source ./edksetup.sh
53git submodule update --init --recursive
54make -C BaseTools -j `nproc`
55build -p OvmfPkg/IntelTdx/IntelTdxX64.dsc -a X64 -t GCC5 -b RELEASE
56```
57
58If debug logs are needed, here is the alternative command:
59
60```bash
61build -p OvmfPkg/IntelTdx/IntelTdxX64.dsc -a X64 -t GCC5 -D DEBUG_ON_SERIAL_PORT=TRUE
62```
63
64On the Cloud Hypervisor side, all you need is to build the project with the
65`tdx` feature enabled:
66
67```bash
68cargo build --features tdx
69```
70
71And run a TDX VM by providing the firmware previously built, along with the
72guest image containing the TDX enlightened kernel. The latest image
73`td-guest-rhel8.5.raw` contains `console=hvc0` on the kernel boot parameters,
74meaning it will be printing guest kernel logs to the `virtio-console` device.
75
76```bash
77./cloud-hypervisor \
78    --platform tdx=on
79    --firmware edk2/Build/IntelTdx/RELEASE_GCC5/FV/OVMF.fd \
80    --cpus boot=1 \
81    --memory size=1G \
82    --disk path=tdx_guest_img
83```
84
85And here is the alternative command when looking for debug logs from the
86firmware:
87
88```bash
89./cloud-hypervisor \
90    --platform tdx=on
91    --firmware edk2/Build/IntelTdx/DEBUG_GCC5/FV/OVMF.fd \
92    --cpus boot=1 \
93    --memory size=1G \
94    --disk path=tdx_guest_img \
95    --serial file=/tmp/ch_serial \
96    --console tty
97```
98
99### TDShim
100
101> **Note**
102> The latest version of TDShim being tested is [_v0.8.0_](https://github.com/confidential-containers/td-shim/releases/tag/v0.8.0).
103
104This is a lightweight version of the TDVF, written in Rust and designed for
105direct kernel boot, which is useful for containers use cases.
106
107To build TDShim from source, it is required to install `Rust`, `NASM`,
108and `LLVM` first. The TDshim can be build as follows:
109
110```bash
111git clone https://github.com/confidential-containers/td-shim
112cd td-shim
113git checkout v0.8.0
114cargo install cargo-xbuild
115export CC=clang
116export AR=llvm-ar
117export CC_x86_64_unknown_none=clang
118export AR_x86_64_unknown_none=llvm-ar
119git submodule update --init --recursive
120./sh_script/preparation.sh
121cargo image --release
122```
123
124If debug logs from the TDShim is needed, here are the alternative
125commands:
126
127```bash
128cargo image
129```
130
131And run a TDX VM by providing the firmware previously built, along with a guest
132kernel built from the [Guest TDX tree](https://github.com/intel/tdx/tree/guest)
133or the [TDX Linux](https://github.com/intel/tdx-linux).
134The appropriate kernel boot options must be provided through the `--cmdline`
135option as well.
136
137```bash
138./cloud-hypervisor \
139    --platform tdx=on
140    --firmware td-shim/target/release/final.bin \
141    --kernel bzImage \
142    --cmdline "root=/dev/vda3 console=hvc0 rw"
143    --cpus boot=1 \
144    --memory size=1G \
145    --disk path=tdx_guest_img
146```
147
148And here is the alternative command when looking for debug logs from the
149TDShim:
150
151```bash
152./cloud-hypervisor \
153    --platform tdx=on
154    --firmware td-shim/target/debug/final.bin \
155    --kernel bzImage \
156    --cmdline "root=/dev/vda3 console=hvc0 rw"
157    --cpus boot=1 \
158    --memory size=1G \
159    --disk path=tdx_guest_img
160```
161
162### Guest kernel limitations
163
164#### Serial ports disabled
165
166The latest guest kernel that can be found in the latest image
167`td-guest-rhel8.5.raw` disabled the support for serial ports. This means adding
168`console=ttyS0` will have no effect and will not print any log from the guest.
169
170#### PCI hotplug through ACPI
171
172Unless you run the guest kernel with the parameter `tdx_disable_filter`, ACPI
173devices responsible for handling PCI hotplug (PCI hotplug controller, PCI
174Express Bus and Generic Event Device) will not be allowed, therefore the
175corresponding drivers will not be loaded and the PCI hotplug feature will not
176be supported.
177