sev-guest.rst 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ===================================================================
  3. The Definitive SEV Guest API Documentation
  4. ===================================================================
  5. 1. General description
  6. ======================
  7. The SEV API is a set of ioctls that are used by the guest or hypervisor
  8. to get or set a certain aspect of the SEV virtual machine. The ioctls belong
  9. to the following classes:
  10. - Hypervisor ioctls: These query and set global attributes which affect the
  11. whole SEV firmware. These ioctl are used by platform provisioning tools.
  12. - Guest ioctls: These query and set attributes of the SEV virtual machine.
  13. 2. API description
  14. ==================
  15. This section describes ioctls that is used for querying the SEV guest report
  16. from the SEV firmware. For each ioctl, the following information is provided
  17. along with a description:
  18. Technology:
  19. which SEV technology provides this ioctl. SEV, SEV-ES, SEV-SNP or all.
  20. Type:
  21. hypervisor or guest. The ioctl can be used inside the guest or the
  22. hypervisor.
  23. Parameters:
  24. what parameters are accepted by the ioctl.
  25. Returns:
  26. the return value. General error numbers (-ENOMEM, -EINVAL)
  27. are not detailed, but errors with specific meanings are.
  28. The guest ioctl should be issued on a file descriptor of the /dev/sev-guest
  29. device. The ioctl accepts struct snp_user_guest_request. The input and
  30. output structure is specified through the req_data and resp_data field
  31. respectively. If the ioctl fails to execute due to a firmware error, then
  32. the fw_error code will be set, otherwise fw_error will be set to -1.
  33. The firmware checks that the message sequence counter is one greater than
  34. the guests message sequence counter. If guest driver fails to increment message
  35. counter (e.g. counter overflow), then -EIO will be returned.
  36. ::
  37. struct snp_guest_request_ioctl {
  38. /* Message version number */
  39. __u32 msg_version;
  40. /* Request and response structure address */
  41. __u64 req_data;
  42. __u64 resp_data;
  43. /* bits[63:32]: VMM error code, bits[31:0] firmware error code (see psp-sev.h) */
  44. union {
  45. __u64 exitinfo2;
  46. struct {
  47. __u32 fw_error;
  48. __u32 vmm_error;
  49. };
  50. };
  51. };
  52. The host ioctls are issued to a file descriptor of the /dev/sev device.
  53. The ioctl accepts the command ID/input structure documented below.
  54. ::
  55. struct sev_issue_cmd {
  56. /* Command ID */
  57. __u32 cmd;
  58. /* Command request structure */
  59. __u64 data;
  60. /* Firmware error code on failure (see psp-sev.h) */
  61. __u32 error;
  62. };
  63. 2.1 SNP_GET_REPORT
  64. ------------------
  65. :Technology: sev-snp
  66. :Type: guest ioctl
  67. :Parameters (in): struct snp_report_req
  68. :Returns (out): struct snp_report_resp on success, -negative on error
  69. The SNP_GET_REPORT ioctl can be used to query the attestation report from the
  70. SEV-SNP firmware. The ioctl uses the SNP_GUEST_REQUEST (MSG_REPORT_REQ) command
  71. provided by the SEV-SNP firmware to query the attestation report.
  72. On success, the snp_report_resp.data will contains the report. The report
  73. contain the format described in the SEV-SNP specification. See the SEV-SNP
  74. specification for further details.
  75. 2.2 SNP_GET_DERIVED_KEY
  76. -----------------------
  77. :Technology: sev-snp
  78. :Type: guest ioctl
  79. :Parameters (in): struct snp_derived_key_req
  80. :Returns (out): struct snp_derived_key_resp on success, -negative on error
  81. The SNP_GET_DERIVED_KEY ioctl can be used to get a key derive from a root key.
  82. The derived key can be used by the guest for any purpose, such as sealing keys
  83. or communicating with external entities.
  84. The ioctl uses the SNP_GUEST_REQUEST (MSG_KEY_REQ) command provided by the
  85. SEV-SNP firmware to derive the key. See SEV-SNP specification for further details
  86. on the various fields passed in the key derivation request.
  87. On success, the snp_derived_key_resp.data contains the derived key value. See
  88. the SEV-SNP specification for further details.
  89. 2.3 SNP_GET_EXT_REPORT
  90. ----------------------
  91. :Technology: sev-snp
  92. :Type: guest ioctl
  93. :Parameters (in/out): struct snp_ext_report_req
  94. :Returns (out): struct snp_report_resp on success, -negative on error
  95. The SNP_GET_EXT_REPORT ioctl is similar to the SNP_GET_REPORT. The difference is
  96. related to the additional certificate data that is returned with the report.
  97. The certificate data returned is being provided by the hypervisor through the
  98. SNP_SET_EXT_CONFIG.
  99. The ioctl uses the SNP_GUEST_REQUEST (MSG_REPORT_REQ) command provided by the SEV-SNP
  100. firmware to get the attestation report.
  101. On success, the snp_ext_report_resp.data will contain the attestation report
  102. and snp_ext_report_req.certs_address will contain the certificate blob. If the
  103. length of the blob is smaller than expected then snp_ext_report_req.certs_len will
  104. be updated with the expected value.
  105. See GHCB specification for further detail on how to parse the certificate blob.
  106. 2.4 SNP_PLATFORM_STATUS
  107. -----------------------
  108. :Technology: sev-snp
  109. :Type: hypervisor ioctl cmd
  110. :Parameters (out): struct sev_user_data_snp_status
  111. :Returns (out): 0 on success, -negative on error
  112. The SNP_PLATFORM_STATUS command is used to query the SNP platform status. The
  113. status includes API major, minor version and more. See the SEV-SNP
  114. specification for further details.
  115. 2.5 SNP_COMMIT
  116. --------------
  117. :Technology: sev-snp
  118. :Type: hypervisor ioctl cmd
  119. :Returns (out): 0 on success, -negative on error
  120. SNP_COMMIT is used to commit the currently installed firmware using the
  121. SEV-SNP firmware SNP_COMMIT command. This prevents roll-back to a previously
  122. committed firmware version. This will also update the reported TCB to match
  123. that of the currently installed firmware.
  124. 2.6 SNP_SET_CONFIG
  125. ------------------
  126. :Technology: sev-snp
  127. :Type: hypervisor ioctl cmd
  128. :Parameters (in): struct sev_user_data_snp_config
  129. :Returns (out): 0 on success, -negative on error
  130. SNP_SET_CONFIG is used to set the system-wide configuration such as
  131. reported TCB version in the attestation report. The command is similar
  132. to SNP_CONFIG command defined in the SEV-SNP spec. The current values of
  133. the firmware parameters affected by this command can be queried via
  134. SNP_PLATFORM_STATUS.
  135. 2.7 SNP_VLEK_LOAD
  136. -----------------
  137. :Technology: sev-snp
  138. :Type: hypervisor ioctl cmd
  139. :Parameters (in): struct sev_user_data_snp_vlek_load
  140. :Returns (out): 0 on success, -negative on error
  141. When requesting an attestation report a guest is able to specify whether
  142. it wants SNP firmware to sign the report using either a Versioned Chip
  143. Endorsement Key (VCEK), which is derived from chip-unique secrets, or a
  144. Versioned Loaded Endorsement Key (VLEK) which is obtained from an AMD
  145. Key Derivation Service (KDS) and derived from seeds allocated to
  146. enrolled cloud service providers.
  147. In the case of VLEK keys, the SNP_VLEK_LOAD SNP command is used to load
  148. them into the system after obtaining them from the KDS, and corresponds
  149. closely to the SNP_VLEK_LOAD firmware command specified in the SEV-SNP
  150. spec.
  151. 3. SEV-SNP CPUID Enforcement
  152. ============================
  153. SEV-SNP guests can access a special page that contains a table of CPUID values
  154. that have been validated by the PSP as part of the SNP_LAUNCH_UPDATE firmware
  155. command. It provides the following assurances regarding the validity of CPUID
  156. values:
  157. - Its address is obtained via bootloader/firmware (via CC blob), and those
  158. binaries will be measured as part of the SEV-SNP attestation report.
  159. - Its initial state will be encrypted/pvalidated, so attempts to modify
  160. it during run-time will result in garbage being written, or #VC exceptions
  161. being generated due to changes in validation state if the hypervisor tries
  162. to swap the backing page.
  163. - Attempts to bypass PSP checks by the hypervisor by using a normal page, or
  164. a non-CPUID encrypted page will change the measurement provided by the
  165. SEV-SNP attestation report.
  166. - The CPUID page contents are *not* measured, but attempts to modify the
  167. expected contents of a CPUID page as part of guest initialization will be
  168. gated by the PSP CPUID enforcement policy checks performed on the page
  169. during SNP_LAUNCH_UPDATE, and noticeable later if the guest owner
  170. implements their own checks of the CPUID values.
  171. It is important to note that this last assurance is only useful if the kernel
  172. has taken care to make use of the SEV-SNP CPUID throughout all stages of boot.
  173. Otherwise, guest owner attestation provides no assurance that the kernel wasn't
  174. fed incorrect values at some point during boot.
  175. 4. SEV Guest Driver Communication Key
  176. =====================================
  177. Communication between an SEV guest and the SEV firmware in the AMD Secure
  178. Processor (ASP, aka PSP) is protected by a VM Platform Communication Key
  179. (VMPCK). By default, the sev-guest driver uses the VMPCK associated with the
  180. VM Privilege Level (VMPL) at which the guest is running. Should this key be
  181. wiped by the sev-guest driver (see the driver for reasons why a VMPCK can be
  182. wiped), a different key can be used by reloading the sev-guest driver and
  183. specifying the desired key using the vmpck_id module parameter.
  184. Reference
  185. ---------
  186. SEV-SNP and GHCB specification: developer.amd.com/sev
  187. The driver is based on SEV-SNP firmware spec 0.9 and GHCB spec version 2.0.