xref: /openbmc/linux/arch/x86/include/asm/sgx.h (revision 8cb7b502)
18ca52cc3SSean Christopherson /* SPDX-License-Identifier: GPL-2.0 */
28ca52cc3SSean Christopherson /**
38ca52cc3SSean Christopherson  * Copyright(c) 2016-20 Intel Corporation.
48ca52cc3SSean Christopherson  *
58ca52cc3SSean Christopherson  * Intel Software Guard Extensions (SGX) support.
68ca52cc3SSean Christopherson  */
78ca52cc3SSean Christopherson #ifndef _ASM_X86_SGX_H
88ca52cc3SSean Christopherson #define _ASM_X86_SGX_H
98ca52cc3SSean Christopherson 
108ca52cc3SSean Christopherson #include <linux/bits.h>
118ca52cc3SSean Christopherson #include <linux/types.h>
128ca52cc3SSean Christopherson 
138ca52cc3SSean Christopherson /*
148ca52cc3SSean Christopherson  * This file contains both data structures defined by SGX architecture and Linux
158ca52cc3SSean Christopherson  * defined software data structures and functions.  The two should not be mixed
16c4342633SIngo Molnar  * together for better readability.  The architectural definitions come first.
178ca52cc3SSean Christopherson  */
188ca52cc3SSean Christopherson 
198ca52cc3SSean Christopherson /* The SGX specific CPUID function. */
208ca52cc3SSean Christopherson #define SGX_CPUID		0x12
218ca52cc3SSean Christopherson /* EPC enumeration. */
228ca52cc3SSean Christopherson #define SGX_CPUID_EPC		2
238ca52cc3SSean Christopherson /* An invalid EPC section, i.e. the end marker. */
248ca52cc3SSean Christopherson #define SGX_CPUID_EPC_INVALID	0x0
258ca52cc3SSean Christopherson /* A valid EPC section. */
268ca52cc3SSean Christopherson #define SGX_CPUID_EPC_SECTION	0x1
278ca52cc3SSean Christopherson /* The bitmask for the EPC section type. */
288ca52cc3SSean Christopherson #define SGX_CPUID_EPC_MASK	GENMASK(3, 0)
298ca52cc3SSean Christopherson 
309c55c78aSSean Christopherson enum sgx_encls_function {
319c55c78aSSean Christopherson 	ECREATE	= 0x00,
329c55c78aSSean Christopherson 	EADD	= 0x01,
339c55c78aSSean Christopherson 	EINIT	= 0x02,
349c55c78aSSean Christopherson 	EREMOVE	= 0x03,
359c55c78aSSean Christopherson 	EDGBRD	= 0x04,
369c55c78aSSean Christopherson 	EDGBWR	= 0x05,
379c55c78aSSean Christopherson 	EEXTEND	= 0x06,
389c55c78aSSean Christopherson 	ELDU	= 0x08,
399c55c78aSSean Christopherson 	EBLOCK	= 0x09,
409c55c78aSSean Christopherson 	EPA	= 0x0A,
419c55c78aSSean Christopherson 	EWB	= 0x0B,
429c55c78aSSean Christopherson 	ETRACK	= 0x0C,
4332ddda8eSSean Christopherson 	EAUG	= 0x0D,
4432ddda8eSSean Christopherson 	EMODPR	= 0x0E,
4532ddda8eSSean Christopherson 	EMODT	= 0x0F,
469c55c78aSSean Christopherson };
479c55c78aSSean Christopherson 
488ca52cc3SSean Christopherson /**
495ce8e39fSPeter Zijlstra  * SGX_ENCLS_FAULT_FLAG - flag signifying an ENCLS return code is a trapnr
505ce8e39fSPeter Zijlstra  *
515ce8e39fSPeter Zijlstra  * ENCLS has its own (positive value) error codes and also generates
525ce8e39fSPeter Zijlstra  * ENCLS specific #GP and #PF faults.  And the ENCLS values get munged
535ce8e39fSPeter Zijlstra  * with system error codes as everything percolates back up the stack.
545ce8e39fSPeter Zijlstra  * Unfortunately (for us), we need to precisely identify each unique
555ce8e39fSPeter Zijlstra  * error code, e.g. the action taken if EWB fails varies based on the
565ce8e39fSPeter Zijlstra  * type of fault and on the exact SGX error code, i.e. we can't simply
575ce8e39fSPeter Zijlstra  * convert all faults to -EFAULT.
585ce8e39fSPeter Zijlstra  *
595ce8e39fSPeter Zijlstra  * To make all three error types coexist, we set bit 30 to identify an
605ce8e39fSPeter Zijlstra  * ENCLS fault.  Bit 31 (technically bits N:31) is used to differentiate
615ce8e39fSPeter Zijlstra  * between positive (faults and SGX error codes) and negative (system
625ce8e39fSPeter Zijlstra  * error codes) values.
635ce8e39fSPeter Zijlstra  */
645ce8e39fSPeter Zijlstra #define SGX_ENCLS_FAULT_FLAG 0x40000000
655ce8e39fSPeter Zijlstra 
665ce8e39fSPeter Zijlstra /**
678ca52cc3SSean Christopherson  * enum sgx_return_code - The return code type for ENCLS, ENCLU and ENCLV
680fb2126dSReinette Chatre  * %SGX_EPC_PAGE_CONFLICT:	Page is being written by other ENCLS function.
698ca52cc3SSean Christopherson  * %SGX_NOT_TRACKED:		Previous ETRACK's shootdown sequence has not
708ca52cc3SSean Christopherson  *				been completed yet.
718ca52cc3SSean Christopherson  * %SGX_CHILD_PRESENT		SECS has child pages present in the EPC.
728ca52cc3SSean Christopherson  * %SGX_INVALID_EINITTOKEN:	EINITTOKEN is invalid and enclave signer's
738ca52cc3SSean Christopherson  *				public key does not match IA32_SGXLEPUBKEYHASH.
740fb2126dSReinette Chatre  * %SGX_PAGE_NOT_MODIFIABLE:	The EPC page cannot be modified because it
750fb2126dSReinette Chatre  *				is in the PENDING or MODIFIED state.
768ca52cc3SSean Christopherson  * %SGX_UNMASKED_EVENT:		An unmasked event, e.g. INTR, was received
778ca52cc3SSean Christopherson  */
788ca52cc3SSean Christopherson enum sgx_return_code {
790fb2126dSReinette Chatre 	SGX_EPC_PAGE_CONFLICT		= 7,
808ca52cc3SSean Christopherson 	SGX_NOT_TRACKED			= 11,
818ca52cc3SSean Christopherson 	SGX_CHILD_PRESENT		= 13,
828ca52cc3SSean Christopherson 	SGX_INVALID_EINITTOKEN		= 16,
830fb2126dSReinette Chatre 	SGX_PAGE_NOT_MODIFIABLE		= 20,
848ca52cc3SSean Christopherson 	SGX_UNMASKED_EVENT		= 128,
858ca52cc3SSean Christopherson };
868ca52cc3SSean Christopherson 
878ca52cc3SSean Christopherson /* The modulus size for 3072-bit RSA keys. */
888ca52cc3SSean Christopherson #define SGX_MODULUS_SIZE 384
898ca52cc3SSean Christopherson 
908ca52cc3SSean Christopherson /**
918ca52cc3SSean Christopherson  * enum sgx_miscselect - additional information to an SSA frame
928ca52cc3SSean Christopherson  * %SGX_MISC_EXINFO:	Report #PF or #GP to the SSA frame.
938ca52cc3SSean Christopherson  *
948ca52cc3SSean Christopherson  * Save State Area (SSA) is a stack inside the enclave used to store processor
958ca52cc3SSean Christopherson  * state when an exception or interrupt occurs. This enum defines additional
968ca52cc3SSean Christopherson  * information stored to an SSA frame.
978ca52cc3SSean Christopherson  */
988ca52cc3SSean Christopherson enum sgx_miscselect {
998ca52cc3SSean Christopherson 	SGX_MISC_EXINFO		= BIT(0),
1008ca52cc3SSean Christopherson };
1018ca52cc3SSean Christopherson 
1028ca52cc3SSean Christopherson #define SGX_MISC_RESERVED_MASK	GENMASK_ULL(63, 1)
1038ca52cc3SSean Christopherson 
1048ca52cc3SSean Christopherson #define SGX_SSA_GPRS_SIZE		184
1058ca52cc3SSean Christopherson #define SGX_SSA_MISC_EXINFO_SIZE	16
1068ca52cc3SSean Christopherson 
1078ca52cc3SSean Christopherson /**
1088ca52cc3SSean Christopherson  * enum sgx_attributes - the attributes field in &struct sgx_secs
1098ca52cc3SSean Christopherson  * %SGX_ATTR_INIT:		Enclave can be entered (is initialized).
1108ca52cc3SSean Christopherson  * %SGX_ATTR_DEBUG:		Allow ENCLS(EDBGRD) and ENCLS(EDBGWR).
1118ca52cc3SSean Christopherson  * %SGX_ATTR_MODE64BIT:		Tell that this a 64-bit enclave.
1128ca52cc3SSean Christopherson  * %SGX_ATTR_PROVISIONKEY:      Allow to use provisioning keys for remote
1138ca52cc3SSean Christopherson  *				attestation.
1148ca52cc3SSean Christopherson  * %SGX_ATTR_KSS:		Allow to use key separation and sharing (KSS).
1158ca52cc3SSean Christopherson  * %SGX_ATTR_EINITTOKENKEY:	Allow to use token signing key that is used to
1168ca52cc3SSean Christopherson  *				sign cryptographic tokens that can be passed to
1178ca52cc3SSean Christopherson  *				EINIT as an authorization to run an enclave.
1188ca52cc3SSean Christopherson  */
1198ca52cc3SSean Christopherson enum sgx_attribute {
1208ca52cc3SSean Christopherson 	SGX_ATTR_INIT		= BIT(0),
1218ca52cc3SSean Christopherson 	SGX_ATTR_DEBUG		= BIT(1),
1228ca52cc3SSean Christopherson 	SGX_ATTR_MODE64BIT	= BIT(2),
1238ca52cc3SSean Christopherson 	SGX_ATTR_PROVISIONKEY	= BIT(4),
1248ca52cc3SSean Christopherson 	SGX_ATTR_EINITTOKENKEY	= BIT(5),
1258ca52cc3SSean Christopherson 	SGX_ATTR_KSS		= BIT(7),
1268ca52cc3SSean Christopherson };
1278ca52cc3SSean Christopherson 
1288ca52cc3SSean Christopherson #define SGX_ATTR_RESERVED_MASK	(BIT_ULL(3) | BIT_ULL(6) | GENMASK_ULL(63, 8))
1298ca52cc3SSean Christopherson 
1308ca52cc3SSean Christopherson /**
1318ca52cc3SSean Christopherson  * struct sgx_secs - SGX Enclave Control Structure (SECS)
1328ca52cc3SSean Christopherson  * @size:		size of the address space
1338ca52cc3SSean Christopherson  * @base:		base address of the  address space
1348ca52cc3SSean Christopherson  * @ssa_frame_size:	size of an SSA frame
1358ca52cc3SSean Christopherson  * @miscselect:		additional information stored to an SSA frame
1368ca52cc3SSean Christopherson  * @attributes:		attributes for enclave
1378ca52cc3SSean Christopherson  * @xfrm:		XSave-Feature Request Mask (subset of XCR0)
1388ca52cc3SSean Christopherson  * @mrenclave:		SHA256-hash of the enclave contents
1398ca52cc3SSean Christopherson  * @mrsigner:		SHA256-hash of the public key used to sign the SIGSTRUCT
1408ca52cc3SSean Christopherson  * @config_id:		a user-defined value that is used in key derivation
1418ca52cc3SSean Christopherson  * @isv_prod_id:	a user-defined value that is used in key derivation
1428ca52cc3SSean Christopherson  * @isv_svn:		a user-defined value that is used in key derivation
1438ca52cc3SSean Christopherson  * @config_svn:		a user-defined value that is used in key derivation
1448ca52cc3SSean Christopherson  *
1458ca52cc3SSean Christopherson  * SGX Enclave Control Structure (SECS) is a special enclave page that is not
1468ca52cc3SSean Christopherson  * visible in the address space. In fact, this structure defines the address
1478ca52cc3SSean Christopherson  * range and other global attributes for the enclave and it is the first EPC
1488ca52cc3SSean Christopherson  * page created for any enclave. It is moved from a temporary buffer to an EPC
1498ca52cc3SSean Christopherson  * by the means of ENCLS[ECREATE] function.
1508ca52cc3SSean Christopherson  */
1518ca52cc3SSean Christopherson struct sgx_secs {
1528ca52cc3SSean Christopherson 	u64 size;
1538ca52cc3SSean Christopherson 	u64 base;
1548ca52cc3SSean Christopherson 	u32 ssa_frame_size;
1558ca52cc3SSean Christopherson 	u32 miscselect;
1568ca52cc3SSean Christopherson 	u8  reserved1[24];
1578ca52cc3SSean Christopherson 	u64 attributes;
1588ca52cc3SSean Christopherson 	u64 xfrm;
1598ca52cc3SSean Christopherson 	u32 mrenclave[8];
1608ca52cc3SSean Christopherson 	u8  reserved2[32];
1618ca52cc3SSean Christopherson 	u32 mrsigner[8];
1628ca52cc3SSean Christopherson 	u8  reserved3[32];
1638ca52cc3SSean Christopherson 	u32 config_id[16];
1648ca52cc3SSean Christopherson 	u16 isv_prod_id;
1658ca52cc3SSean Christopherson 	u16 isv_svn;
1668ca52cc3SSean Christopherson 	u16 config_svn;
1678ca52cc3SSean Christopherson 	u8  reserved4[3834];
1688ca52cc3SSean Christopherson } __packed;
1698ca52cc3SSean Christopherson 
1708ca52cc3SSean Christopherson /**
1718ca52cc3SSean Christopherson  * enum sgx_tcs_flags - execution flags for TCS
1728ca52cc3SSean Christopherson  * %SGX_TCS_DBGOPTIN:	If enabled allows single-stepping and breakpoints
1738ca52cc3SSean Christopherson  *			inside an enclave. It is cleared by EADD but can
1748ca52cc3SSean Christopherson  *			be set later with EDBGWR.
1758ca52cc3SSean Christopherson  */
1768ca52cc3SSean Christopherson enum sgx_tcs_flags {
1778ca52cc3SSean Christopherson 	SGX_TCS_DBGOPTIN	= 0x01,
1788ca52cc3SSean Christopherson };
1798ca52cc3SSean Christopherson 
1808ca52cc3SSean Christopherson #define SGX_TCS_RESERVED_MASK	GENMASK_ULL(63, 1)
1818ca52cc3SSean Christopherson #define SGX_TCS_RESERVED_SIZE	4024
1828ca52cc3SSean Christopherson 
1838ca52cc3SSean Christopherson /**
1848ca52cc3SSean Christopherson  * struct sgx_tcs - Thread Control Structure (TCS)
1858ca52cc3SSean Christopherson  * @state:		used to mark an entered TCS
1868ca52cc3SSean Christopherson  * @flags:		execution flags (cleared by EADD)
1878ca52cc3SSean Christopherson  * @ssa_offset:		SSA stack offset relative to the enclave base
1888ca52cc3SSean Christopherson  * @ssa_index:		the current SSA frame index (cleard by EADD)
1898ca52cc3SSean Christopherson  * @nr_ssa_frames:	the number of frame in the SSA stack
1908ca52cc3SSean Christopherson  * @entry_offset:	entry point offset relative to the enclave base
1918ca52cc3SSean Christopherson  * @exit_addr:		address outside the enclave to exit on an exception or
1928ca52cc3SSean Christopherson  *			interrupt
1938ca52cc3SSean Christopherson  * @fs_offset:		offset relative to the enclave base to become FS
1948ca52cc3SSean Christopherson  *			segment inside the enclave
1958ca52cc3SSean Christopherson  * @gs_offset:		offset relative to the enclave base to become GS
1968ca52cc3SSean Christopherson  *			segment inside the enclave
1978ca52cc3SSean Christopherson  * @fs_limit:		size to become a new FS-limit (only 32-bit enclaves)
1988ca52cc3SSean Christopherson  * @gs_limit:		size to become a new GS-limit (only 32-bit enclaves)
1998ca52cc3SSean Christopherson  *
2008ca52cc3SSean Christopherson  * Thread Control Structure (TCS) is an enclave page visible in its address
2018ca52cc3SSean Christopherson  * space that defines an entry point inside the enclave. A thread enters inside
2028ca52cc3SSean Christopherson  * an enclave by supplying address of TCS to ENCLU(EENTER). A TCS can be entered
2038ca52cc3SSean Christopherson  * by only one thread at a time.
2048ca52cc3SSean Christopherson  */
2058ca52cc3SSean Christopherson struct sgx_tcs {
2068ca52cc3SSean Christopherson 	u64 state;
2078ca52cc3SSean Christopherson 	u64 flags;
2088ca52cc3SSean Christopherson 	u64 ssa_offset;
2098ca52cc3SSean Christopherson 	u32 ssa_index;
2108ca52cc3SSean Christopherson 	u32 nr_ssa_frames;
2118ca52cc3SSean Christopherson 	u64 entry_offset;
2128ca52cc3SSean Christopherson 	u64 exit_addr;
2138ca52cc3SSean Christopherson 	u64 fs_offset;
2148ca52cc3SSean Christopherson 	u64 gs_offset;
2158ca52cc3SSean Christopherson 	u32 fs_limit;
2168ca52cc3SSean Christopherson 	u32 gs_limit;
2178ca52cc3SSean Christopherson 	u8  reserved[SGX_TCS_RESERVED_SIZE];
2188ca52cc3SSean Christopherson } __packed;
2198ca52cc3SSean Christopherson 
2208ca52cc3SSean Christopherson /**
2218ca52cc3SSean Christopherson  * struct sgx_pageinfo - an enclave page descriptor
2228ca52cc3SSean Christopherson  * @addr:	address of the enclave page
2238ca52cc3SSean Christopherson  * @contents:	pointer to the page contents
2248ca52cc3SSean Christopherson  * @metadata:	pointer either to a SECINFO or PCMD instance
2258ca52cc3SSean Christopherson  * @secs:	address of the SECS page
2268ca52cc3SSean Christopherson  */
2278ca52cc3SSean Christopherson struct sgx_pageinfo {
2288ca52cc3SSean Christopherson 	u64 addr;
2298ca52cc3SSean Christopherson 	u64 contents;
2308ca52cc3SSean Christopherson 	u64 metadata;
2318ca52cc3SSean Christopherson 	u64 secs;
2328ca52cc3SSean Christopherson } __packed __aligned(32);
2338ca52cc3SSean Christopherson 
2348ca52cc3SSean Christopherson 
2358ca52cc3SSean Christopherson /**
2368ca52cc3SSean Christopherson  * enum sgx_page_type - bits in the SECINFO flags defining the page type
2378ca52cc3SSean Christopherson  * %SGX_PAGE_TYPE_SECS:	a SECS page
2388ca52cc3SSean Christopherson  * %SGX_PAGE_TYPE_TCS:	a TCS page
2398ca52cc3SSean Christopherson  * %SGX_PAGE_TYPE_REG:	a regular page
2408ca52cc3SSean Christopherson  * %SGX_PAGE_TYPE_VA:	a VA page
2418ca52cc3SSean Christopherson  * %SGX_PAGE_TYPE_TRIM:	a page in trimmed state
242*8cb7b502SReinette Chatre  *
243*8cb7b502SReinette Chatre  * Make sure when making changes to this enum that its values can still fit
244*8cb7b502SReinette Chatre  * in the bitfield within &struct sgx_encl_page
2458ca52cc3SSean Christopherson  */
2468ca52cc3SSean Christopherson enum sgx_page_type {
2478ca52cc3SSean Christopherson 	SGX_PAGE_TYPE_SECS,
2488ca52cc3SSean Christopherson 	SGX_PAGE_TYPE_TCS,
2498ca52cc3SSean Christopherson 	SGX_PAGE_TYPE_REG,
2508ca52cc3SSean Christopherson 	SGX_PAGE_TYPE_VA,
2518ca52cc3SSean Christopherson 	SGX_PAGE_TYPE_TRIM,
2528ca52cc3SSean Christopherson };
2538ca52cc3SSean Christopherson 
2548ca52cc3SSean Christopherson #define SGX_NR_PAGE_TYPES	5
2558ca52cc3SSean Christopherson #define SGX_PAGE_TYPE_MASK	GENMASK(7, 0)
2568ca52cc3SSean Christopherson 
2578ca52cc3SSean Christopherson /**
2588ca52cc3SSean Christopherson  * enum sgx_secinfo_flags - the flags field in &struct sgx_secinfo
2598ca52cc3SSean Christopherson  * %SGX_SECINFO_R:	allow read
2608ca52cc3SSean Christopherson  * %SGX_SECINFO_W:	allow write
2618ca52cc3SSean Christopherson  * %SGX_SECINFO_X:	allow execution
2628ca52cc3SSean Christopherson  * %SGX_SECINFO_SECS:	a SECS page
2638ca52cc3SSean Christopherson  * %SGX_SECINFO_TCS:	a TCS page
2648ca52cc3SSean Christopherson  * %SGX_SECINFO_REG:	a regular page
2658ca52cc3SSean Christopherson  * %SGX_SECINFO_VA:	a VA page
2668ca52cc3SSean Christopherson  * %SGX_SECINFO_TRIM:	a page in trimmed state
2678ca52cc3SSean Christopherson  */
2688ca52cc3SSean Christopherson enum sgx_secinfo_flags {
2698ca52cc3SSean Christopherson 	SGX_SECINFO_R			= BIT(0),
2708ca52cc3SSean Christopherson 	SGX_SECINFO_W			= BIT(1),
2718ca52cc3SSean Christopherson 	SGX_SECINFO_X			= BIT(2),
2728ca52cc3SSean Christopherson 	SGX_SECINFO_SECS		= (SGX_PAGE_TYPE_SECS << 8),
2738ca52cc3SSean Christopherson 	SGX_SECINFO_TCS			= (SGX_PAGE_TYPE_TCS << 8),
2748ca52cc3SSean Christopherson 	SGX_SECINFO_REG			= (SGX_PAGE_TYPE_REG << 8),
2758ca52cc3SSean Christopherson 	SGX_SECINFO_VA			= (SGX_PAGE_TYPE_VA << 8),
2768ca52cc3SSean Christopherson 	SGX_SECINFO_TRIM		= (SGX_PAGE_TYPE_TRIM << 8),
2778ca52cc3SSean Christopherson };
2788ca52cc3SSean Christopherson 
2798ca52cc3SSean Christopherson #define SGX_SECINFO_PERMISSION_MASK	GENMASK_ULL(2, 0)
2808ca52cc3SSean Christopherson #define SGX_SECINFO_PAGE_TYPE_MASK	(SGX_PAGE_TYPE_MASK << 8)
2818ca52cc3SSean Christopherson #define SGX_SECINFO_RESERVED_MASK	~(SGX_SECINFO_PERMISSION_MASK | \
2828ca52cc3SSean Christopherson 					  SGX_SECINFO_PAGE_TYPE_MASK)
2838ca52cc3SSean Christopherson 
2848ca52cc3SSean Christopherson /**
2858ca52cc3SSean Christopherson  * struct sgx_secinfo - describes attributes of an EPC page
2868ca52cc3SSean Christopherson  * @flags:	permissions and type
2878ca52cc3SSean Christopherson  *
2888ca52cc3SSean Christopherson  * Used together with ENCLS leaves that add or modify an EPC page to an
2898ca52cc3SSean Christopherson  * enclave to define page permissions and type.
2908ca52cc3SSean Christopherson  */
2918ca52cc3SSean Christopherson struct sgx_secinfo {
2928ca52cc3SSean Christopherson 	u64 flags;
2938ca52cc3SSean Christopherson 	u8  reserved[56];
2948ca52cc3SSean Christopherson } __packed __aligned(64);
2958ca52cc3SSean Christopherson 
2968ca52cc3SSean Christopherson #define SGX_PCMD_RESERVED_SIZE 40
2978ca52cc3SSean Christopherson 
2988ca52cc3SSean Christopherson /**
2998ca52cc3SSean Christopherson  * struct sgx_pcmd - Paging Crypto Metadata (PCMD)
3008ca52cc3SSean Christopherson  * @enclave_id:	enclave identifier
3018ca52cc3SSean Christopherson  * @mac:	MAC over PCMD, page contents and isvsvn
3028ca52cc3SSean Christopherson  *
3038ca52cc3SSean Christopherson  * PCMD is stored for every swapped page to the regular memory. When ELDU loads
3048ca52cc3SSean Christopherson  * the page back it recalculates the MAC by using a isvsvn number stored in a
3058ca52cc3SSean Christopherson  * VA page. Together these two structures bring integrity and rollback
3068ca52cc3SSean Christopherson  * protection.
3078ca52cc3SSean Christopherson  */
3088ca52cc3SSean Christopherson struct sgx_pcmd {
3098ca52cc3SSean Christopherson 	struct sgx_secinfo secinfo;
3108ca52cc3SSean Christopherson 	u64 enclave_id;
3118ca52cc3SSean Christopherson 	u8  reserved[SGX_PCMD_RESERVED_SIZE];
3128ca52cc3SSean Christopherson 	u8  mac[16];
3138ca52cc3SSean Christopherson } __packed __aligned(128);
3148ca52cc3SSean Christopherson 
3158ca52cc3SSean Christopherson #define SGX_SIGSTRUCT_RESERVED1_SIZE 84
3168ca52cc3SSean Christopherson #define SGX_SIGSTRUCT_RESERVED2_SIZE 20
3178ca52cc3SSean Christopherson #define SGX_SIGSTRUCT_RESERVED3_SIZE 32
3188ca52cc3SSean Christopherson #define SGX_SIGSTRUCT_RESERVED4_SIZE 12
3198ca52cc3SSean Christopherson 
3208ca52cc3SSean Christopherson /**
3218ca52cc3SSean Christopherson  * struct sgx_sigstruct_header -  defines author of the enclave
3228ca52cc3SSean Christopherson  * @header1:		constant byte string
3238ca52cc3SSean Christopherson  * @vendor:		must be either 0x0000 or 0x8086
3248ca52cc3SSean Christopherson  * @date:		YYYYMMDD in BCD
325ea5bc7b9SLinus Torvalds  * @header2:		constant byte string
3268ca52cc3SSean Christopherson  * @swdefined:		software defined value
3278ca52cc3SSean Christopherson  */
3288ca52cc3SSean Christopherson struct sgx_sigstruct_header {
3298ca52cc3SSean Christopherson 	u64 header1[2];
3308ca52cc3SSean Christopherson 	u32 vendor;
3318ca52cc3SSean Christopherson 	u32 date;
3328ca52cc3SSean Christopherson 	u64 header2[2];
3338ca52cc3SSean Christopherson 	u32 swdefined;
3348ca52cc3SSean Christopherson 	u8  reserved1[84];
3358ca52cc3SSean Christopherson } __packed;
3368ca52cc3SSean Christopherson 
3378ca52cc3SSean Christopherson /**
3388ca52cc3SSean Christopherson  * struct sgx_sigstruct_body - defines contents of the enclave
3398ca52cc3SSean Christopherson  * @miscselect:		additional information stored to an SSA frame
3408ca52cc3SSean Christopherson  * @misc_mask:		required miscselect in SECS
3418ca52cc3SSean Christopherson  * @attributes:		attributes for enclave
3428ca52cc3SSean Christopherson  * @xfrm:		XSave-Feature Request Mask (subset of XCR0)
3438ca52cc3SSean Christopherson  * @attributes_mask:	required attributes in SECS
3448ca52cc3SSean Christopherson  * @xfrm_mask:		required XFRM in SECS
3458ca52cc3SSean Christopherson  * @mrenclave:		SHA256-hash of the enclave contents
3468ca52cc3SSean Christopherson  * @isvprodid:		a user-defined value that is used in key derivation
3478ca52cc3SSean Christopherson  * @isvsvn:		a user-defined value that is used in key derivation
3488ca52cc3SSean Christopherson  */
3498ca52cc3SSean Christopherson struct sgx_sigstruct_body {
3508ca52cc3SSean Christopherson 	u32 miscselect;
3518ca52cc3SSean Christopherson 	u32 misc_mask;
3528ca52cc3SSean Christopherson 	u8  reserved2[20];
3538ca52cc3SSean Christopherson 	u64 attributes;
3548ca52cc3SSean Christopherson 	u64 xfrm;
3558ca52cc3SSean Christopherson 	u64 attributes_mask;
3568ca52cc3SSean Christopherson 	u64 xfrm_mask;
3578ca52cc3SSean Christopherson 	u8  mrenclave[32];
3588ca52cc3SSean Christopherson 	u8  reserved3[32];
3598ca52cc3SSean Christopherson 	u16 isvprodid;
3608ca52cc3SSean Christopherson 	u16 isvsvn;
3618ca52cc3SSean Christopherson } __packed;
3628ca52cc3SSean Christopherson 
3638ca52cc3SSean Christopherson /**
3648ca52cc3SSean Christopherson  * struct sgx_sigstruct - an enclave signature
3658ca52cc3SSean Christopherson  * @header:		defines author of the enclave
3668ca52cc3SSean Christopherson  * @modulus:		the modulus of the public key
3678ca52cc3SSean Christopherson  * @exponent:		the exponent of the public key
3688ca52cc3SSean Christopherson  * @signature:		the signature calculated over the fields except modulus,
3698ca52cc3SSean Christopherson  * @body:		defines contents of the enclave
3708ca52cc3SSean Christopherson  * @q1:			a value used in RSA signature verification
3718ca52cc3SSean Christopherson  * @q2:			a value used in RSA signature verification
3728ca52cc3SSean Christopherson  *
3738ca52cc3SSean Christopherson  * Header and body are the parts that are actual signed. The remaining fields
3748ca52cc3SSean Christopherson  * define the signature of the enclave.
3758ca52cc3SSean Christopherson  */
3768ca52cc3SSean Christopherson struct sgx_sigstruct {
3778ca52cc3SSean Christopherson 	struct sgx_sigstruct_header header;
3788ca52cc3SSean Christopherson 	u8  modulus[SGX_MODULUS_SIZE];
3798ca52cc3SSean Christopherson 	u32 exponent;
3808ca52cc3SSean Christopherson 	u8  signature[SGX_MODULUS_SIZE];
3818ca52cc3SSean Christopherson 	struct sgx_sigstruct_body body;
3828ca52cc3SSean Christopherson 	u8  reserved4[12];
3838ca52cc3SSean Christopherson 	u8  q1[SGX_MODULUS_SIZE];
3848ca52cc3SSean Christopherson 	u8  q2[SGX_MODULUS_SIZE];
3858ca52cc3SSean Christopherson } __packed;
3868ca52cc3SSean Christopherson 
3878ca52cc3SSean Christopherson #define SGX_LAUNCH_TOKEN_SIZE 304
3888ca52cc3SSean Christopherson 
3898ca52cc3SSean Christopherson /*
3908ca52cc3SSean Christopherson  * Do not put any hardware-defined SGX structure representations below this
3918ca52cc3SSean Christopherson  * comment!
3928ca52cc3SSean Christopherson  */
3938ca52cc3SSean Christopherson 
394d155030bSSean Christopherson #ifdef CONFIG_X86_SGX_KVM
395d155030bSSean Christopherson int sgx_virt_ecreate(struct sgx_pageinfo *pageinfo, void __user *secs,
396d155030bSSean Christopherson 		     int *trapnr);
397d155030bSSean Christopherson int sgx_virt_einit(void __user *sigstruct, void __user *token,
398d155030bSSean Christopherson 		   void __user *secs, u64 *lepubkeyhash, int *trapnr);
399d155030bSSean Christopherson #endif
400d155030bSSean Christopherson 
401b3754e5dSSean Christopherson int sgx_set_attribute(unsigned long *allowed_attributes,
402b3754e5dSSean Christopherson 		      unsigned int attribute_fd);
403b3754e5dSSean Christopherson 
4048ca52cc3SSean Christopherson #endif /* _ASM_X86_SGX_H */
405