cloud-hypervisor/docs/intel_tdx.md
Bo Chen bc59ca72f3 docs: Update the intel_tdx documentation
Updates include:
- Add references to 'TDX Tools'
- Expand instructions on buidling and using TDShim
- Add version information of guest/host kernel, TDVF, TDShim being tested

Signed-off-by: Bo Chen <chen.bo@intel.com>
2023-02-07 06:30:38 -08:00

6.4 KiB

Intel TDX

Intel® Trust Domain Extensions (Intel® TDX) is an Intel technology designed to isolate virtual machines from the VMM, hypervisor and any other software on the host platform. Here are some useful links:

  • TDX Homepage: more information about TDX technical aspects, design and specification

  • KVM TDX tree: the required Linux kernel changes for the host side

  • Guest TDX tree: the Linux kernel changes for the guest side

  • EDK2 project: the TDVF firmware

  • Confidential Containers project: the TDShim firmware

  • TDX Tools: a collection of tools and scripts to setup TDX environment for testing purpose (such as installing required packages on the host, creating guest images, and building the custom Linux kernel for TDX host and guest)

Cloud Hypervisor support

It is required to use a machine with TDX enabled in hardware and with the host OS compiled from the KVM TDX tree. The host environment can also be setup with the TDX Tools.

Cloud Hypervisor can run TDX VM (Trust Domain) by loading a TD firmware (TDVF), which will then load the guest kernel from the image. The image must be custom as it must include a kernel built from the Guest TDX tree. Cloud Hypervisor can also boot a TDX VM with direct kernel boot using TDshim. The custom Linux kernel for the guest can be built with the TDX Tools.

Note

The latest version of custom host and guest kernel being tested is from TDX Tools - 2023ww01.

TDVF

Note

The latest version of TDVF being tested is 13b9773.

The firmware can be built as follows:

git clone https://github.com/tianocore/edk2.git
cd edk2
git checkout 13b97736c876919b9786055829caaa4fa46984b7
git submodule update --init --recursive
make -C BaseTools
source ./edksetup.sh
build -p OvmfPkg/IntelTdx/IntelTdxX64.dsc -a X64 -t GCC5 -b RELEASE

If debug logs are needed, here is the alternative command:

build -p OvmfPkg/IntelTdx/IntelTdxX64.dsc -a X64 -t GCC5 -D DEBUG_ON_SERIAL_PORT=TRUE

On the Cloud Hypervisor side, all you need is to build the project with the tdx feature enabled:

cargo build --features tdx

And run a TDX VM by providing the firmware previously built, along with the guest image containing the TDX enlightened kernel. The latest image td-guest-rhel8.5.raw contains console=hvc0 on the kernel boot parameters, meaning it will be printing guest kernel logs to the virtio-console device.

./cloud-hypervisor \
    --platform tdx=on
    --firmware edk2/Build/IntelTdx/RELEASE_GCC5/FV/OVMF.fd \
    --cpus boot=1 \
    --memory size=1G \
    --disk path=tdx_guest_img

And here is the alternative command when looking for debug logs from the firmware:

./cloud-hypervisor \
    --platform tdx=on
    --firmware edk2/Build/IntelTdx/DEBUG_GCC5/FV/OVMF.fd \
    --cpus boot=1 \
    --memory size=1G \
    --disk path=tdx_guest_img \
    --serial file=/tmp/ch_serial \
    --console tty

TDShim

Note

The latest version of TDShim being tested is 66bb334.

This is a lightweight version of the TDVF, written in Rust and designed for direct kernel boot, which is useful for containers use cases.

To build TDShim from source, it is required to install Rust, NASM, and LLVM first. The TDshim can be build as follows:

git clone https://github.com/confidential-containers/td-shim
cd td-shim
git checkout 66bb33451befbf1291abe3cfea7ee9e99d922b0d
cargo install cargo-xbuild
export CC=clang
export AR=llvm-ar
export CC_x86_64_unknown_none=clang
export AR_x86_64_unknown_none=llvm-ar
git submodule update --init --recursive
./sh_script/preparation.sh
cargo xbuild -p td-shim --target x86_64-unknown-none --release --features=main,tdx
cargo run -p td-shim-tools --bin td-shim-ld --features=linker -- target/x86_64-unknown-none/release/ResetVector.bin target/x86_64-unknown-none/release/td-shim -o target/release/final.bin

If debug logs from the TDShim is needed, here are the alternative commands:

cargo xbuild -p td-shim --target x86_64-unknown-none --features=main,tdx
cargo run -p td-shim-tools --bin td-shim-ld --features=linker -- target/x86_64-unknown-none/debug/ResetVector.bin target/x86_64-unknown-none/debug/td-shim -o target/debug/final.bin

And run a TDX VM by providing the firmware previously built, along with a guest kernel built from the Guest TDX tree or the TDX Tools. The appropriate kernel boot options must be provided through the --cmdline option as well.

./cloud-hypervisor \
    --platform tdx=on
    --firmware td-shim/target/release/final.bin \
    --kernel bzImage \
    --cmdline "root=/dev/vda3 console=hvc0 rw"
    --cpus boot=1 \
    --memory size=1G \
    --disk path=tdx_guest_img

And here is the alternative command when looking for debug logs from the TDShim:

./cloud-hypervisor \
    --platform tdx=on
    --firmware td-shim/target/debug/final.bin \
    --kernel bzImage \
    --cmdline "root=/dev/vda3 console=hvc0 rw"
    --cpus boot=1 \
    --memory size=1G \
    --disk path=tdx_guest_img

Guest kernel limitations

Serial ports disabled

The latest guest kernel that can be found in the latest image td-guest-rhel8.5.raw disabled the support for serial ports. This means adding console=ttyS0 will have no effect and will not print any log from the guest.

PCI hotplug through ACPI

Unless you run the guest kernel with the parameter tdx_disable_filter, ACPI devices responsible for handling PCI hotplug (PCI hotplug controller, PCI Express Bus and Generic Event Device) will not be allowed, therefore the corresponding drivers will not be loaded and the PCI hotplug feature will not be supported.