sev-guest.rst 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. 2.1 SNP_GET_REPORT
  53. ------------------
  54. :Technology: sev-snp
  55. :Type: guest ioctl
  56. :Parameters (in): struct snp_report_req
  57. :Returns (out): struct snp_report_resp on success, -negative on error
  58. The SNP_GET_REPORT ioctl can be used to query the attestation report from the
  59. SEV-SNP firmware. The ioctl uses the SNP_GUEST_REQUEST (MSG_REPORT_REQ) command
  60. provided by the SEV-SNP firmware to query the attestation report.
  61. On success, the snp_report_resp.data will contains the report. The report
  62. contain the format described in the SEV-SNP specification. See the SEV-SNP
  63. specification for further details.
  64. 2.2 SNP_GET_DERIVED_KEY
  65. -----------------------
  66. :Technology: sev-snp
  67. :Type: guest ioctl
  68. :Parameters (in): struct snp_derived_key_req
  69. :Returns (out): struct snp_derived_key_resp on success, -negative on error
  70. The SNP_GET_DERIVED_KEY ioctl can be used to get a key derive from a root key.
  71. The derived key can be used by the guest for any purpose, such as sealing keys
  72. or communicating with external entities.
  73. The ioctl uses the SNP_GUEST_REQUEST (MSG_KEY_REQ) command provided by the
  74. SEV-SNP firmware to derive the key. See SEV-SNP specification for further details
  75. on the various fields passed in the key derivation request.
  76. On success, the snp_derived_key_resp.data contains the derived key value. See
  77. the SEV-SNP specification for further details.
  78. 2.3 SNP_GET_EXT_REPORT
  79. ----------------------
  80. :Technology: sev-snp
  81. :Type: guest ioctl
  82. :Parameters (in/out): struct snp_ext_report_req
  83. :Returns (out): struct snp_report_resp on success, -negative on error
  84. The SNP_GET_EXT_REPORT ioctl is similar to the SNP_GET_REPORT. The difference is
  85. related to the additional certificate data that is returned with the report.
  86. The certificate data returned is being provided by the hypervisor through the
  87. SNP_SET_EXT_CONFIG.
  88. The ioctl uses the SNP_GUEST_REQUEST (MSG_REPORT_REQ) command provided by the SEV-SNP
  89. firmware to get the attestation report.
  90. On success, the snp_ext_report_resp.data will contain the attestation report
  91. and snp_ext_report_req.certs_address will contain the certificate blob. If the
  92. length of the blob is smaller than expected then snp_ext_report_req.certs_len will
  93. be updated with the expected value.
  94. See GHCB specification for further detail on how to parse the certificate blob.
  95. 3. SEV-SNP CPUID Enforcement
  96. ============================
  97. SEV-SNP guests can access a special page that contains a table of CPUID values
  98. that have been validated by the PSP as part of the SNP_LAUNCH_UPDATE firmware
  99. command. It provides the following assurances regarding the validity of CPUID
  100. values:
  101. - Its address is obtained via bootloader/firmware (via CC blob), and those
  102. binaries will be measured as part of the SEV-SNP attestation report.
  103. - Its initial state will be encrypted/pvalidated, so attempts to modify
  104. it during run-time will result in garbage being written, or #VC exceptions
  105. being generated due to changes in validation state if the hypervisor tries
  106. to swap the backing page.
  107. - Attempts to bypass PSP checks by the hypervisor by using a normal page, or
  108. a non-CPUID encrypted page will change the measurement provided by the
  109. SEV-SNP attestation report.
  110. - The CPUID page contents are *not* measured, but attempts to modify the
  111. expected contents of a CPUID page as part of guest initialization will be
  112. gated by the PSP CPUID enforcement policy checks performed on the page
  113. during SNP_LAUNCH_UPDATE, and noticeable later if the guest owner
  114. implements their own checks of the CPUID values.
  115. It is important to note that this last assurance is only useful if the kernel
  116. has taken care to make use of the SEV-SNP CPUID throughout all stages of boot.
  117. Otherwise, guest owner attestation provides no assurance that the kernel wasn't
  118. fed incorrect values at some point during boot.
  119. Reference
  120. ---------
  121. SEV-SNP and GHCB specification: developer.amd.com/sev
  122. The driver is based on SEV-SNP firmware spec 0.9 and GHCB spec version 2.0.