amd-memory-encryption.rst 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. ======================================
  2. Secure Encrypted Virtualization (SEV)
  3. ======================================
  4. Overview
  5. ========
  6. Secure Encrypted Virtualization (SEV) is a feature found on AMD processors.
  7. SEV is an extension to the AMD-V architecture which supports running
  8. virtual machines (VMs) under the control of a hypervisor. When enabled,
  9. the memory contents of a VM will be transparently encrypted with a key
  10. unique to that VM.
  11. The hypervisor can determine the SEV support through the CPUID
  12. instruction. The CPUID function 0x8000001f reports information related
  13. to SEV::
  14. 0x8000001f[eax]:
  15. Bit[1] indicates support for SEV
  16. ...
  17. [ecx]:
  18. Bits[31:0] Number of encrypted guests supported simultaneously
  19. If support for SEV is present, MSR 0xc001_0010 (MSR_K8_SYSCFG) and MSR 0xc001_0015
  20. (MSR_K7_HWCR) can be used to determine if it can be enabled::
  21. 0xc001_0010:
  22. Bit[23] 1 = memory encryption can be enabled
  23. 0 = memory encryption can not be enabled
  24. 0xc001_0015:
  25. Bit[0] 1 = memory encryption can be enabled
  26. 0 = memory encryption can not be enabled
  27. When SEV support is available, it can be enabled in a specific VM by
  28. setting the SEV bit before executing VMRUN.::
  29. VMCB[0x90]:
  30. Bit[1] 1 = SEV is enabled
  31. 0 = SEV is disabled
  32. SEV hardware uses ASIDs to associate a memory encryption key with a VM.
  33. Hence, the ASID for the SEV-enabled guests must be from 1 to a maximum value
  34. defined in the CPUID 0x8000001f[ecx] field.
  35. SEV Key Management
  36. ==================
  37. The SEV guest key management is handled by a separate processor called the AMD
  38. Secure Processor (AMD-SP). Firmware running inside the AMD-SP provides a secure
  39. key management interface to perform common hypervisor activities such as
  40. encrypting bootstrap code, snapshot, migrating and debugging the guest. For more
  41. information, see the SEV Key Management spec [api-spec]_
  42. KVM implements the following commands to support common lifecycle events of SEV
  43. guests, such as launching, running, snapshotting, migrating and decommissioning.
  44. 1. KVM_SEV_INIT
  45. ---------------
  46. The KVM_SEV_INIT command is used by the hypervisor to initialize the SEV platform
  47. context. In a typical workflow, this command should be the first command issued.
  48. Returns: 0 on success, -negative on error
  49. 2. KVM_SEV_LAUNCH_START
  50. -----------------------
  51. The KVM_SEV_LAUNCH_START command is used for creating the memory encryption
  52. context. To create the encryption context, user must provide a guest policy,
  53. the owner's public Diffie-Hellman (PDH) key and session information.
  54. Parameters: struct kvm_sev_launch_start (in/out)
  55. Returns: 0 on success, -negative on error
  56. ::
  57. struct kvm_sev_launch_start {
  58. __u32 handle; /* if zero then firmware creates a new handle */
  59. __u32 policy; /* guest's policy */
  60. __u64 dh_uaddr; /* userspace address pointing to the guest owner's PDH key */
  61. __u32 dh_len;
  62. __u64 session_addr; /* userspace address which points to the guest session information */
  63. __u32 session_len;
  64. };
  65. On success, the 'handle' field contains a new handle and on error, a negative value.
  66. For more details, see SEV spec Section 6.2.
  67. 3. KVM_SEV_LAUNCH_UPDATE_DATA
  68. -----------------------------
  69. The KVM_SEV_LAUNCH_UPDATE_DATA is used for encrypting a memory region. It also
  70. calculates a measurement of the memory contents. The measurement is a signature
  71. of the memory contents that can be sent to the guest owner as an attestation
  72. that the memory was encrypted correctly by the firmware.
  73. Parameters (in): struct kvm_sev_launch_update_data
  74. Returns: 0 on success, -negative on error
  75. ::
  76. struct kvm_sev_launch_update {
  77. __u64 uaddr; /* userspace address to be encrypted (must be 16-byte aligned) */
  78. __u32 len; /* length of the data to be encrypted (must be 16-byte aligned) */
  79. };
  80. For more details, see SEV spec Section 6.3.
  81. 4. KVM_SEV_LAUNCH_MEASURE
  82. -------------------------
  83. The KVM_SEV_LAUNCH_MEASURE command is used to retrieve the measurement of the
  84. data encrypted by the KVM_SEV_LAUNCH_UPDATE_DATA command. The guest owner may
  85. wait to provide the guest with confidential information until it can verify the
  86. measurement. Since the guest owner knows the initial contents of the guest at
  87. boot, the measurement can be verified by comparing it to what the guest owner
  88. expects.
  89. Parameters (in): struct kvm_sev_launch_measure
  90. Returns: 0 on success, -negative on error
  91. ::
  92. struct kvm_sev_launch_measure {
  93. __u64 uaddr; /* where to copy the measurement */
  94. __u32 len; /* length of measurement blob */
  95. };
  96. For more details on the measurement verification flow, see SEV spec Section 6.4.
  97. 5. KVM_SEV_LAUNCH_FINISH
  98. ------------------------
  99. After completion of the launch flow, the KVM_SEV_LAUNCH_FINISH command can be
  100. issued to make the guest ready for the execution.
  101. Returns: 0 on success, -negative on error
  102. 6. KVM_SEV_GUEST_STATUS
  103. -----------------------
  104. The KVM_SEV_GUEST_STATUS command is used to retrieve status information about a
  105. SEV-enabled guest.
  106. Parameters (out): struct kvm_sev_guest_status
  107. Returns: 0 on success, -negative on error
  108. ::
  109. struct kvm_sev_guest_status {
  110. __u32 handle; /* guest handle */
  111. __u32 policy; /* guest policy */
  112. __u8 state; /* guest state (see enum below) */
  113. };
  114. SEV guest state:
  115. ::
  116. enum {
  117. SEV_STATE_INVALID = 0;
  118. SEV_STATE_LAUNCHING, /* guest is currently being launched */
  119. SEV_STATE_SECRET, /* guest is being launched and ready to accept the ciphertext data */
  120. SEV_STATE_RUNNING, /* guest is fully launched and running */
  121. SEV_STATE_RECEIVING, /* guest is being migrated in from another SEV machine */
  122. SEV_STATE_SENDING /* guest is getting migrated out to another SEV machine */
  123. };
  124. 7. KVM_SEV_DBG_DECRYPT
  125. ----------------------
  126. The KVM_SEV_DEBUG_DECRYPT command can be used by the hypervisor to request the
  127. firmware to decrypt the data at the given memory region.
  128. Parameters (in): struct kvm_sev_dbg
  129. Returns: 0 on success, -negative on error
  130. ::
  131. struct kvm_sev_dbg {
  132. __u64 src_uaddr; /* userspace address of data to decrypt */
  133. __u64 dst_uaddr; /* userspace address of destination */
  134. __u32 len; /* length of memory region to decrypt */
  135. };
  136. The command returns an error if the guest policy does not allow debugging.
  137. 8. KVM_SEV_DBG_ENCRYPT
  138. ----------------------
  139. The KVM_SEV_DEBUG_ENCRYPT command can be used by the hypervisor to request the
  140. firmware to encrypt the data at the given memory region.
  141. Parameters (in): struct kvm_sev_dbg
  142. Returns: 0 on success, -negative on error
  143. ::
  144. struct kvm_sev_dbg {
  145. __u64 src_uaddr; /* userspace address of data to encrypt */
  146. __u64 dst_uaddr; /* userspace address of destination */
  147. __u32 len; /* length of memory region to encrypt */
  148. };
  149. The command returns an error if the guest policy does not allow debugging.
  150. 9. KVM_SEV_LAUNCH_SECRET
  151. ------------------------
  152. The KVM_SEV_LAUNCH_SECRET command can be used by the hypervisor to inject secret
  153. data after the measurement has been validated by the guest owner.
  154. Parameters (in): struct kvm_sev_launch_secret
  155. Returns: 0 on success, -negative on error
  156. ::
  157. struct kvm_sev_launch_secret {
  158. __u64 hdr_uaddr; /* userspace address containing the packet header */
  159. __u32 hdr_len;
  160. __u64 guest_uaddr; /* the guest memory region where the secret should be injected */
  161. __u32 guest_len;
  162. __u64 trans_uaddr; /* the hypervisor memory region which contains the secret */
  163. __u32 trans_len;
  164. };
  165. References
  166. ==========
  167. .. [white-paper] http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/12/AMD_Memory_Encryption_Whitepaper_v7-Public.pdf
  168. .. [api-spec] http://support.amd.com/TechDocs/55766_SEV-KM%20API_Specification.pdf
  169. .. [amd-apm] http://support.amd.com/TechDocs/24593.pdf (section 15.34)
  170. .. [kvm-forum] http://www.linux-kvm.org/images/7/74/02x08A-Thomas_Lendacky-AMDs_Virtualizatoin_Memory_Encryption_Technology.pdf