xref: /linux/include/uapi/linux/psp-sev.h (revision 249872f53d64441690927853e9d3af36394802d5)
1 /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
2 /*
3  * Userspace interface for AMD Secure Encrypted Virtualization (SEV)
4  * platform management commands.
5  *
6  * Copyright (C) 2016-2017 Advanced Micro Devices, Inc.
7  *
8  * Author: Brijesh Singh <brijesh.singh@amd.com>
9  *
10  * SEV API specification is available at: https://developer.amd.com/sev/
11  */
12 
13 #ifndef __PSP_SEV_USER_H__
14 #define __PSP_SEV_USER_H__
15 
16 #include <linux/types.h>
17 
18 /**
19  * SEV platform commands
20  */
21 enum {
22 	SEV_FACTORY_RESET = 0,
23 	SEV_PLATFORM_STATUS,
24 	SEV_PEK_GEN,
25 	SEV_PEK_CSR,
26 	SEV_PDH_GEN,
27 	SEV_PDH_CERT_EXPORT,
28 	SEV_PEK_CERT_IMPORT,
29 	SEV_GET_ID,	/* This command is deprecated, use SEV_GET_ID2 */
30 	SEV_GET_ID2,
31 	SNP_PLATFORM_STATUS,
32 	SNP_COMMIT,
33 	SNP_SET_CONFIG,
34 	SNP_VLEK_LOAD,
35 
36 	SEV_MAX,
37 };
38 
39 /**
40  * SEV Firmware status code
41  */
42 typedef enum {
43 	/*
44 	 * This error code is not in the SEV spec. Its purpose is to convey that
45 	 * there was an error that prevented the SEV firmware from being called.
46 	 * The SEV API error codes are 16 bits, so the -1 value will not overlap
47 	 * with possible values from the specification.
48 	 */
49 	SEV_RET_NO_FW_CALL = -1,
50 	SEV_RET_SUCCESS                    = 0,
51 	SEV_RET_INVALID_PLATFORM_STATE     = 0x0001,
52 	SEV_RET_INVALID_GUEST_STATE        = 0x0002,
53 	SEV_RET_INAVLID_CONFIG             = 0x0003,
54 	SEV_RET_INVALID_CONFIG = SEV_RET_INAVLID_CONFIG,
55 	SEV_RET_INVALID_LEN                = 0x0004,
56 	SEV_RET_ALREADY_OWNED              = 0x0005,
57 	SEV_RET_INVALID_CERTIFICATE        = 0x0006,
58 	SEV_RET_POLICY_FAILURE             = 0x0007,
59 	SEV_RET_INACTIVE                   = 0x0008,
60 	SEV_RET_INVALID_ADDRESS            = 0x0009,
61 	SEV_RET_BAD_SIGNATURE              = 0x000A,
62 	SEV_RET_BAD_MEASUREMENT            = 0x000B,
63 	SEV_RET_ASID_OWNED                 = 0x000C,
64 	SEV_RET_INVALID_ASID               = 0x000D,
65 	SEV_RET_WBINVD_REQUIRED            = 0x000E,
66 	SEV_RET_DFFLUSH_REQUIRED           = 0x000F,
67 	SEV_RET_INVALID_GUEST              = 0x0010,
68 	SEV_RET_INVALID_COMMAND            = 0x0011,
69 	SEV_RET_ACTIVE                     = 0x0012,
70 	SEV_RET_HWSEV_RET_PLATFORM         = 0x0013,
71 	SEV_RET_HWSEV_RET_UNSAFE           = 0x0014,
72 	SEV_RET_UNSUPPORTED                = 0x0015,
73 	SEV_RET_INVALID_PARAM              = 0x0016,
74 	SEV_RET_RESOURCE_LIMIT             = 0x0017,
75 	SEV_RET_SECURE_DATA_INVALID        = 0x0018,
76 	SEV_RET_INVALID_PAGE_SIZE          = 0x0019,
77 	SEV_RET_INVALID_PAGE_STATE         = 0x001A,
78 	SEV_RET_INVALID_MDATA_ENTRY        = 0x001B,
79 	SEV_RET_INVALID_PAGE_OWNER         = 0x001C,
80 	SEV_RET_AEAD_OFLOW                 = 0x001D,
81 	SEV_RET_EXIT_RING_BUFFER           = 0x001F,
82 	SEV_RET_RMP_INIT_REQUIRED          = 0x0020,
83 	SEV_RET_BAD_SVN                    = 0x0021,
84 	SEV_RET_BAD_VERSION                = 0x0022,
85 	SEV_RET_SHUTDOWN_REQUIRED          = 0x0023,
86 	SEV_RET_UPDATE_FAILED              = 0x0024,
87 	SEV_RET_RESTORE_REQUIRED           = 0x0025,
88 	SEV_RET_RMP_INITIALIZATION_FAILED  = 0x0026,
89 	SEV_RET_INVALID_KEY                = 0x0027,
90 	SEV_RET_SHUTDOWN_INCOMPLETE        = 0x0028,
91 	SEV_RET_INCORRECT_BUFFER_LENGTH	   = 0x0030,
92 	SEV_RET_EXPAND_BUFFER_LENGTH_REQUEST = 0x0031,
93 	SEV_RET_SPDM_REQUEST               = 0x0032,
94 	SEV_RET_SPDM_ERROR                 = 0x0033,
95 	SEV_RET_SEV_STATUS_ERR_IN_DEV_CONN = 0x0035,
96 	SEV_RET_SEV_STATUS_INVALID_DEV_CTX = 0x0036,
97 	SEV_RET_SEV_STATUS_INVALID_TDI_CTX = 0x0037,
98 	SEV_RET_SEV_STATUS_INVALID_TDI     = 0x0038,
99 	SEV_RET_SEV_STATUS_RECLAIM_REQUIRED = 0x0039,
100 	SEV_RET_IN_USE                     = 0x003A,
101 	SEV_RET_SEV_STATUS_INVALID_DEV_STATE = 0x003B,
102 	SEV_RET_SEV_STATUS_INVALID_TDI_STATE = 0x003C,
103 	SEV_RET_SEV_STATUS_DEV_CERT_CHANGED = 0x003D,
104 	SEV_RET_SEV_STATUS_RESYNC_REQ      = 0x003E,
105 	SEV_RET_SEV_STATUS_RESPONSE_TOO_LARGE = 0x003F,
106 	SEV_RET_MAX,
107 } sev_ret_code;
108 
109 /**
110  * struct sev_user_data_status - PLATFORM_STATUS command parameters
111  *
112  * @major: major API version
113  * @minor: minor API version
114  * @state: platform state
115  * @flags: platform config flags
116  * @build: firmware build id for API version
117  * @guest_count: number of active guests
118  */
119 struct sev_user_data_status {
120 	__u8 api_major;				/* Out */
121 	__u8 api_minor;				/* Out */
122 	__u8 state;				/* Out */
123 	__u32 flags;				/* Out */
124 	__u8 build;				/* Out */
125 	__u32 guest_count;			/* Out */
126 } __packed;
127 
128 #define SEV_STATUS_FLAGS_CONFIG_ES	0x0100
129 
130 /**
131  * struct sev_user_data_pek_csr - PEK_CSR command parameters
132  *
133  * @address: PEK certificate chain
134  * @length: length of certificate
135  */
136 struct sev_user_data_pek_csr {
137 	__u64 address;				/* In */
138 	__u32 length;				/* In/Out */
139 } __packed;
140 
141 /**
142  * struct sev_user_data_cert_import - PEK_CERT_IMPORT command parameters
143  *
144  * @pek_address: PEK certificate chain
145  * @pek_len: length of PEK certificate
146  * @oca_address: OCA certificate chain
147  * @oca_len: length of OCA certificate
148  */
149 struct sev_user_data_pek_cert_import {
150 	__u64 pek_cert_address;			/* In */
151 	__u32 pek_cert_len;			/* In */
152 	__u64 oca_cert_address;			/* In */
153 	__u32 oca_cert_len;			/* In */
154 } __packed;
155 
156 /**
157  * struct sev_user_data_pdh_cert_export - PDH_CERT_EXPORT command parameters
158  *
159  * @pdh_address: PDH certificate address
160  * @pdh_len: length of PDH certificate
161  * @cert_chain_address: PDH certificate chain
162  * @cert_chain_len: length of PDH certificate chain
163  */
164 struct sev_user_data_pdh_cert_export {
165 	__u64 pdh_cert_address;			/* In */
166 	__u32 pdh_cert_len;			/* In/Out */
167 	__u64 cert_chain_address;		/* In */
168 	__u32 cert_chain_len;			/* In/Out */
169 } __packed;
170 
171 /**
172  * struct sev_user_data_get_id - GET_ID command parameters (deprecated)
173  *
174  * @socket1: Buffer to pass unique ID of first socket
175  * @socket2: Buffer to pass unique ID of second socket
176  */
177 struct sev_user_data_get_id {
178 	__u8 socket1[64];			/* Out */
179 	__u8 socket2[64];			/* Out */
180 } __packed;
181 
182 /**
183  * struct sev_user_data_get_id2 - GET_ID command parameters
184  * @address: Buffer to store unique ID
185  * @length: length of the unique ID
186  */
187 struct sev_user_data_get_id2 {
188 	__u64 address;				/* In */
189 	__u32 length;				/* In/Out */
190 } __packed;
191 
192 /**
193  * struct sev_user_data_snp_status - SNP status
194  *
195  * @api_major: API major version
196  * @api_minor: API minor version
197  * @state: current platform state
198  * @is_rmp_initialized: whether RMP is initialized or not
199  * @rsvd: reserved
200  * @build_id: firmware build id for the API version
201  * @mask_chip_id: whether chip id is present in attestation reports or not
202  * @mask_chip_key: whether attestation reports are signed or not
203  * @vlek_en: VLEK (Version Loaded Endorsement Key) hashstick is loaded
204  * @feature_info: whether SNP_FEATURE_INFO command is available
205  * @rapl_dis: whether RAPL is disabled
206  * @ciphertext_hiding_cap: whether platform has ciphertext hiding capability
207  * @ciphertext_hiding_en: whether ciphertext hiding is enabled
208  * @rsvd1: reserved
209  * @guest_count: the number of guest currently managed by the firmware
210  * @current_tcb_version: current TCB version
211  * @reported_tcb_version: reported TCB version
212  */
213 struct sev_user_data_snp_status {
214 	__u8 api_major;			/* Out */
215 	__u8 api_minor;			/* Out */
216 	__u8 state;			/* Out */
217 	__u8 is_rmp_initialized:1;	/* Out */
218 	__u8 rsvd:7;
219 	__u32 build_id;			/* Out */
220 	__u32 mask_chip_id:1;		/* Out */
221 	__u32 mask_chip_key:1;		/* Out */
222 	__u32 vlek_en:1;		/* Out */
223 	__u32 feature_info:1;		/* Out */
224 	__u32 rapl_dis:1;		/* Out */
225 	__u32 ciphertext_hiding_cap:1;	/* Out */
226 	__u32 ciphertext_hiding_en:1;	/* Out */
227 	__u32 rsvd1:25;
228 	__u32 guest_count;		/* Out */
229 	__u64 current_tcb_version;	/* Out */
230 	__u64 reported_tcb_version;	/* Out */
231 } __packed;
232 
233 /**
234  * struct sev_user_data_snp_config - system wide configuration value for SNP.
235  *
236  * @reported_tcb: the TCB version to report in the guest attestation report.
237  * @mask_chip_id: whether chip id is present in attestation reports or not
238  * @mask_chip_key: whether attestation reports are signed or not
239  * @rsvd: reserved
240  * @rsvd1: reserved
241  */
242 struct sev_user_data_snp_config {
243 	__u64 reported_tcb  ;   /* In */
244 	__u32 mask_chip_id:1;   /* In */
245 	__u32 mask_chip_key:1;  /* In */
246 	__u32 rsvd:30;          /* In */
247 	__u8 rsvd1[52];
248 } __packed;
249 
250 /**
251  * struct sev_data_snp_vlek_load - SNP_VLEK_LOAD structure
252  *
253  * @len: length of the command buffer read by the PSP
254  * @vlek_wrapped_version: version of wrapped VLEK hashstick (Must be 0h)
255  * @rsvd: reserved
256  * @vlek_wrapped_address: address of a wrapped VLEK hashstick
257  *                        (struct sev_user_data_snp_wrapped_vlek_hashstick)
258  */
259 struct sev_user_data_snp_vlek_load {
260 	__u32 len;				/* In */
261 	__u8 vlek_wrapped_version;		/* In */
262 	__u8 rsvd[3];				/* In */
263 	__u64 vlek_wrapped_address;		/* In */
264 } __packed;
265 
266 /**
267  * struct sev_user_data_snp_vlek_wrapped_vlek_hashstick - Wrapped VLEK data
268  *
269  * @data: Opaque data provided by AMD KDS (as described in SEV-SNP Firmware ABI
270  *        1.54, SNP_VLEK_LOAD)
271  */
272 struct sev_user_data_snp_wrapped_vlek_hashstick {
273 	__u8 data[432];				/* In */
274 } __packed;
275 
276 /**
277  * struct sev_issue_cmd - SEV ioctl parameters
278  *
279  * @cmd: SEV commands to execute
280  * @opaque: pointer to the command structure
281  * @error: SEV FW return code on failure
282  */
283 struct sev_issue_cmd {
284 	__u32 cmd;				/* In */
285 	__u64 data;				/* In */
286 	__u32 error;				/* Out */
287 } __packed;
288 
289 #define SEV_IOC_TYPE		'S'
290 #define SEV_ISSUE_CMD	_IOWR(SEV_IOC_TYPE, 0x0, struct sev_issue_cmd)
291 
292 #endif /* __PSP_USER_SEV_H */
293