Skip to content

Qemu SGX virtualization

Yang Zhong qemu-devel 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest33 patches 27 repliesIn review
  2. v333 patches 4 repliesSuperseded
  3. v232 patches 0 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v1 posting 2/232 patches20 repliesSuperseded
v1 posting 1/232 patches2 repliesSuperseded

Changelog from the cover letter

=========

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/33memory: Add RAM_PROTECTED flag to skip IOMMU mappingshw/vfio/common.c include/exec/memory.h softmmu/memory.c +1 more+22 -20 replies
2/33hostmem: Add hostmem-epc as a backend for SGX EPCbackends/hostmem-epc.c backends/meson.build+93 -00 replies
3/33qom: Add memory-backend-epc ObjectOptions supportqapi/qom.json+19 -00 replies
4/33i386: Add 'sgx-epc' device to expose EPC sections to guesthw/i386/meson.build hw/i386/sgx-epc.c include/hw/i386/sgx-epc.h+206 -02 replies
5/33vl: Add sgx compound properties to expose SGX EPC sections to guesthw/i386/meson.build hw/i386/sgx-epc.c hw/i386/sgx.c +6 more+166 -80 replies
6/33i386: Add primary SGX CPUID and MSR definestarget/i386/cpu.c target/i386/cpu.h+14 -20 replies
7/33i386: Add SGX CPUID leaf FEAT_SGX_12_0_EAXtarget/i386/cpu.c target/i386/cpu.h+21 -00 replies
8/33i386: Add SGX CPUID leaf FEAT_SGX_12_0_EBXtarget/i386/cpu.c target/i386/cpu.h+22 -00 replies
9/33i386: Add SGX CPUID leaf FEAT_SGX_12_1_EAXtarget/i386/cpu.c target/i386/cpu.h+22 -00 replies
10/33i386: Add get/set/migrate support for SGX_LEPUBKEYHASH MSRstarget/i386/cpu.c target/i386/cpu.h target/i386/kvm/kvm.c +1 more+59 -13 replies
11/33i386: Add feature control MSR dependency when SGX is enabledtarget/i386/kvm/kvm.c+5 -00 replies
12/33i386: Update SGX CPUID info according to hardware/KVM/user inputhw/i386/sgx.c include/hw/i386/sgx-epc.h target/i386/cpu.c+96 -00 replies
13/33i386: kvm: Add support for exposing PROVISIONKEY to guesttarget/i386/cpu.c target/i386/kvm/kvm.c target/i386/kvm/kvm_i386.h+35 -10 replies
14/33i386: Propagate SGX CPUID sub-leafs to KVMtarget/i386/kvm/kvm.c+19 -00 replies
15/33Adjust min CPUID level to 0x12 when SGX is enabledtarget/i386/cpu.c+5 -00 replies
16/33hw/i386/fw_cfg: Set SGX bits in feature control fw_cfg accordinglyhw/i386/fw_cfg.c+9 -10 replies
17/33hw/i386/pc: Account for SGX EPC sections when calculating device memoryhw/i386/pc.c include/hw/i386/sgx-epc.h+17 -10 replies
18/33i386/pc: Add e820 entry for SGX EPC section(s)hw/i386/pc.c+4 -00 replies
19/33i386: acpi: Add SGX EPC entry to ACPI tableshw/i386/acpi-build.c+22 -00 replies
20/33q35: Add support for SGX EPChw/i386/pc_q35.c+3 -00 replies
21/33i440fx: Add support for SGX EPChw/i386/pc_piix.c+4 -00 replies
22/33hostmem-epc: Add the reset interface for EPC backend resetbackends/hostmem-epc.c include/hw/i386/pc.h+18 -010 replies
23/33sgx-epc: Add the reset interface for sgx-epc virt devicehw/i386/sgx-epc.c+81 -133 replies
24/33sgx-epc: Avoid bios reset during sgx epc initializationhw/i386/sgx-epc.c+19 -00 replies
25/33hostmem-epc: Make prealloc consistent with qemu cmdline during resetbackends/hostmem-epc.c+10 -00 replies
26/33qmp: Add query-sgx commandmonitor/qmp-cmds.c qapi/misc.json tests/qtest/qmp-cmd-test.c+49 -00 replies
27/33hmp: Add 'info sgx' commandhmp-commands-info.hx include/monitor/hmp.h monitor/hmp-cmds.c+22 -00 replies
28/33i386: Add sgx_get_info() interfacehw/i386/sgx.c include/hw/i386/pc.h include/hw/i386/sgx-epc.h +4 more+58 -40 replies
29/33bitops: Support 32 and 64 bit mask macroinclude/qemu/bitops.h+7 -00 replies
30/33qmp: Add the qmp_query_sgx_capabilities()hw/i386/sgx.c include/hw/i386/pc.h monitor/qmp-cmds.c +3 more+97 -00 replies
31/33Kconfig: Add CONFIG_SGX supportbackends/meson.build configs/devices/i386-softmmu/default.mak hw/i386/Kconfig +2 more+22 -30 replies
32/33sgx-epc: Add the fill_device_info() callback supporthw/i386/sgx-epc.c monitor/hmp-cmds.c qapi/machine.json+45 -20 replies
33/33doc: Add the SGX docdocs/intel-sgx.txt+167 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH v4 00/33] Qemu SGX virtualization

Since Sean Christopherson has left Intel and i am responsible for Qemu SGX upstream work. His @intel.com address will be bouncing and his new email( [email protected]) is also in CC lists.

This series is Qemu SGX virtualization implementation rebased on latest Qemu release. The numa support for SGX will be sent in another patchset once this basic SGX patchset are merged.

You can find Qemu repo here:

https://github.com/intel/qemu-sgx.git upstream

If you want to try SGX, you can directly install the linux release(at least 5.13.0-rc1+) since kvm SGX has been merged into linux release.

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

To simplify, you'd better install linux on host and guest, which can support SGX on host and guest kernel. And to me, use below reference command to boot SGX guest:

    #qemu-system-x86_64 \
        ...... \
        -cpu host,+sgx-provisionkey \
        -object memory-backend-epc,id=mem1,size=64M,prealloc=on \
        -object memory-backend-epc,id=mem2,size=28M \
        -M sgx-epc.0.memdev=mem1,sgx-epc.1.memdev=mem2

Overview
========

Intel Software Guard eXtensions (SGX) is a set of instructions and mechanisms for memory accesses in order to provide security accesses for sensitive applications and data. SGX allows an application to use it's pariticular address space as an *enclave*, which is a protected area provides confidentiality and integrity even in the presence of privileged malware. Accesses to the enclave memory area from any software not resident in the enclave are prevented, including those from privileged software.

SGX virtaulization
==================

The KVM SGX creates one new misc device, sgx_vepc, and Qemu will open '/dev/sgx_vepc' device node to mmap() host EPC memory to guest. The Qemu also adds 'sgx-epc' device to expose EPC sections to guest through CPUID and ACPI table. The Qemu SGX also supports multiple virtual EPC sections to guest, we just put them together physically contiguous for the sake of simplicity. The kernel SGX NUMA has been merged into Linux tip tree, we will support this function in the next phase.

Although the current host SGX subsystem can not support SGX2 feature, the KVM/Qemu implementation still expose this feature to guest. Guest SGX2 support doesn't have interaction with host kernel SGX driver, the SGX guest can normally use those new instructions.

As for SGX virtualization detailed infomation, please reference docs/intel-sgx.txt docuement(patch 33).

Changelog:
=========

(Changelog here is for global changes, please see each patch's changelog for changes made to specific patch.)

v3-->v4:
- Rebased the sgx patches into latest Qemu release.
- Moved sgx compound property setter/getter from MachineState to X86MachineState(Paolo).
- Re-defined struct SgxEPC, removed 'id' property and added struct SgxEPCList for

     sgx-epc.0.{memdev}(Paolo).
   - Removed g_malloc0(), and changed the 'SGXEPCState *sgx_epc' to 'SGXEPCState sgx_epc'
     in struct PCMachineState(Paolo).
   - Changed the SGX compound property cmdline from sgx-epc.{memdev}.0 to
     sgx-epc.0.{memdev}(Paolo).

- Removed the signature from the 'git format-patch' command(Jarkko).

v2-->v3:
- Rebased the sgx patches into latest Qemu release.
- Implemented the compound property for SGX, ref patch5, the command from '-sgx-epc'

     to '-M'(Paolo).

- Moved the sgx common code from sgx-epc.c to sgx.c. The sgx-epc.c is only responsible for virtual epc device.
- Removed the previous patch13(linux-headers: Add placeholder for KVM_CAP_SGX_ATTRIBUTE) because [email protected] updated Linux headers to 5.13-rc4 with commit 278f064e452.
- Updated the patch1 because ram_flags were changed by David Hildenbra.
- Added one patch24, which avoid reset operation caused by bios reset.
- Added one patch25, which make prealloc property consistent with Qemu cmdline during VM reset.

v1-->v2:
- Rebased the sgx patches into latest Qemu release.
- Unified the "share" and "protected" arguments with ram_flags in the memory_region_init_ram_from_fd()(Paolo).
- Added the new MemoryBackendEpcProperties and related documents(Eric Blake).
- Changed the KVM_CAP_SGX_ATTRIBUTE from 195 to 196(Kai).
- Changed the version and some grammar issues(Eric Blake).

Sean Christopherson (21):
memory: Add RAM_PROTECTED flag to skip IOMMU mappings
hostmem: Add hostmem-epc as a backend for SGX EPC
i386: Add 'sgx-epc' device to expose EPC sections to guest
vl: Add sgx compound properties to expose SGX EPC sections to guest
i386: Add primary SGX CPUID and MSR defines
i386: Add SGX CPUID leaf FEAT_SGX_12_0_EAX
i386: Add SGX CPUID leaf FEAT_SGX_12_0_EBX
i386: Add SGX CPUID leaf FEAT_SGX_12_1_EAX
i386: Add get/set/migrate support for SGX_LEPUBKEYHASH MSRs
i386: Add feature control MSR dependency when SGX is enabled
i386: Update SGX CPUID info according to hardware/KVM/user input
i386: kvm: Add support for exposing PROVISIONKEY to guest
i386: Propagate SGX CPUID sub-leafs to KVM
Adjust min CPUID level to 0x12 when SGX is enabled hw/i386/fw_cfg: Set SGX bits in feature control fw_cfg accordingly hw/i386/pc: Account for SGX EPC sections when calculating device
memory
i386/pc: Add e820 entry for SGX EPC section(s)
i386: acpi: Add SGX EPC entry to ACPI tables
q35: Add support for SGX EPC
i440fx: Add support for SGX EPC
doc: Add the SGX doc

Yang Zhong (12):
qom: Add memory-backend-epc ObjectOptions support
hostmem-epc: Add the reset interface for EPC backend reset
sgx-epc: Add the reset interface for sgx-epc virt device
sgx-epc: Avoid bios reset during sgx epc initialization
hostmem-epc: Make prealloc consistent with qemu cmdline during reset
qmp: Add query-sgx command
hmp: Add 'info sgx' command
i386: Add sgx_get_info() interface
bitops: Support 32 and 64 bit mask macro
qmp: Add the qmp_query_sgx_capabilities()
Kconfig: Add CONFIG_SGX support
sgx-epc: Add the fill_device_info() callback support

 backends/hostmem-epc.c                   | 118 ++++++++++
 backends/meson.build                     |   1 +
 configs/devices/i386-softmmu/default.mak |   1 +
 docs/intel-sgx.txt                       | 167 ++++++++++++++
 hmp-commands-info.hx                     |  15 ++
 hw/i386/Kconfig                          |   5 +
 hw/i386/acpi-build.c                     |  22 ++
 hw/i386/fw_cfg.c                         |  10 +-
 hw/i386/meson.build                      |   2 +
 hw/i386/pc.c                             |  15 +-
 hw/i386/pc_piix.c                        |   4 +
 hw/i386/pc_q35.c                         |   3 +
 hw/i386/sgx-epc.c                        | 265 +++++++++++++++++++++++
 hw/i386/sgx-stub.c                       |  13 ++
 hw/i386/sgx.c                            | 170 +++++++++++++++
 hw/i386/x86.c                            |  29 +++
 hw/vfio/common.c                         |   1 +
 include/exec/memory.h                    |  15 +-
 include/hw/i386/pc.h                     |  10 +
 include/hw/i386/sgx-epc.h                |  68 ++++++
 include/hw/i386/x86.h                    |   1 +
 include/monitor/hmp.h                    |   1 +
 include/qemu/bitops.h                    |   7 +
 monitor/hmp-cmds.c                       |  32 +++
 monitor/qmp-cmds.c                       |  19 ++
 qapi/machine.json                        |  52 ++++-
 qapi/misc.json                           |  61 ++++++
 qapi/qom.json                            |  19 ++
 qemu-options.hx                          |  10 +-
 softmmu/memory.c                         |   5 +
 softmmu/physmem.c                        |   3 +-
 stubs/meson.build                        |   1 +
 stubs/sgx-stub.c                         |  12 +
 target/i386/cpu.c                        | 168 +++++++++++++-
 target/i386/cpu.h                        |  16 ++
 target/i386/kvm/kvm.c                    |  75 +++++++
 target/i386/kvm/kvm_i386.h               |   2 +
 target/i386/machine.c                    |  20 ++
 tests/qtest/qmp-cmd-test.c               |   2 +
 39 files changed, 1430 insertions(+), 10 deletions(-)
 create mode 100644 backends/hostmem-epc.c
 create mode 100644 docs/intel-sgx.txt
 create mode 100644 hw/i386/sgx-epc.c
 create mode 100644 hw/i386/sgx-stub.c
 create mode 100644 hw/i386/sgx.c
 create mode 100644 include/hw/i386/sgx-epc.h
 create mode 100644 stubs/sgx-stub.c