xref: /cloud-hypervisor/docs/intel_sgx.md (revision 100c6d81426a538dc27f9b7b477d8d765d069dd3)
1# Intel SGX
2
3Intel® Software Guard Extensions (Intel® SGX) is an Intel technology designed
4to increase the security of application code and data. Cloud Hypervisor supports
5SGX virtualization through KVM. Because SGX is built on hardware features that
6cannot be emulated in software, virtualizing SGX requires support in KVM and in
7the host kernel. The required Linux and KVM changes can be found in Linux 5.13+.
8
9Utilizing SGX in the guest requires a kernel/OS with SGX support, e.g. a kernel
10since release 5.11, see
11[here](https://www.intel.com/content/www/us/en/developer/tools/software-guard-extensions/linux-overview.html).
12Running Linux 5.13+ as the guest kernel allows nested virtualization of SGX.
13
14For more information about SGX, please refer to the [SGX Homepage](https://www.intel.com/content/www/us/en/developer/tools/software-guard-extensions/linux-overview.html).
15
16For more information about SGX SDK and how to test SGX, please refer to the
17following [instructions](https://github.com/intel/linux-sgx).
18
19## Cloud Hypervisor support
20
21Assuming the host exposes `/dev/sgx_vepc`, we can pass SGX enclaves through
22the guest.
23
24In order to use SGX enclaves within a Cloud Hypervisor VM, we must define one
25or several Enclave Page Cache (EPC) sections. Here is an example of a VM being
26created with 2 EPC sections, the first one being 64MiB with pre-allocated
27memory, the second one being 32MiB with no pre-allocated memory.
28
29```bash
30./cloud-hypervisor \
31    --cpus boot=1 \
32    --memory size=1G \
33    --disk path=focal-server-cloudimg-amd64.raw \
34    --kernel vmlinux \
35    --cmdline "console=ttyS0 console=hvc0 root=/dev/vda1 rw" \
36    --sgx-epc id=epc0,size=64M,prefault=on id=epc1,size=32M,prefault=off
37```
38
39Once booted, and assuming your guest kernel contains the patches from the
40[KVM SGX Tree](https://github.com/intel/kvm-sgx), you can validate SGX devices
41have been correctly created under `/dev/sgx`:
42
43```bash
44ls /dev/sgx*
45/dev/sgx_enclave  /dev/sgx_provision  /dev/sgx_vepc
46```
47
48From this point, it is possible to run any SGX application from the guest, as
49it will access `/dev/sgx_enclave` device to create dedicated SGX enclaves.
50
51Note: There is only one contiguous SGX EPC region, which contains all SGX EPC
52sections. This region is exposed through ACPI and marked as reserved through
53the e820 table. It is treated as yet another device, which means it should
54appear at the end of the guest address space.
55