xref: /openbmc/linux/arch/x86/include/asm/sgx.h (revision 5ce8e39f)
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 /**
49*5ce8e39fSPeter Zijlstra  * SGX_ENCLS_FAULT_FLAG - flag signifying an ENCLS return code is a trapnr
50*5ce8e39fSPeter Zijlstra  *
51*5ce8e39fSPeter Zijlstra  * ENCLS has its own (positive value) error codes and also generates
52*5ce8e39fSPeter Zijlstra  * ENCLS specific #GP and #PF faults.  And the ENCLS values get munged
53*5ce8e39fSPeter Zijlstra  * with system error codes as everything percolates back up the stack.
54*5ce8e39fSPeter Zijlstra  * Unfortunately (for us), we need to precisely identify each unique
55*5ce8e39fSPeter Zijlstra  * error code, e.g. the action taken if EWB fails varies based on the
56*5ce8e39fSPeter Zijlstra  * type of fault and on the exact SGX error code, i.e. we can't simply
57*5ce8e39fSPeter Zijlstra  * convert all faults to -EFAULT.
58*5ce8e39fSPeter Zijlstra  *
59*5ce8e39fSPeter Zijlstra  * To make all three error types coexist, we set bit 30 to identify an
60*5ce8e39fSPeter Zijlstra  * ENCLS fault.  Bit 31 (technically bits N:31) is used to differentiate
61*5ce8e39fSPeter Zijlstra  * between positive (faults and SGX error codes) and negative (system
62*5ce8e39fSPeter Zijlstra  * error codes) values.
63*5ce8e39fSPeter Zijlstra  */
64*5ce8e39fSPeter Zijlstra #define SGX_ENCLS_FAULT_FLAG 0x40000000
65*5ce8e39fSPeter Zijlstra 
66*5ce8e39fSPeter Zijlstra /**
678ca52cc3SSean Christopherson  * enum sgx_return_code - The return code type for ENCLS, ENCLU and ENCLV
688ca52cc3SSean Christopherson  * %SGX_NOT_TRACKED:		Previous ETRACK's shootdown sequence has not
698ca52cc3SSean Christopherson  *				been completed yet.
708ca52cc3SSean Christopherson  * %SGX_CHILD_PRESENT		SECS has child pages present in the EPC.
718ca52cc3SSean Christopherson  * %SGX_INVALID_EINITTOKEN:	EINITTOKEN is invalid and enclave signer's
728ca52cc3SSean Christopherson  *				public key does not match IA32_SGXLEPUBKEYHASH.
738ca52cc3SSean Christopherson  * %SGX_UNMASKED_EVENT:		An unmasked event, e.g. INTR, was received
748ca52cc3SSean Christopherson  */
758ca52cc3SSean Christopherson enum sgx_return_code {
768ca52cc3SSean Christopherson 	SGX_NOT_TRACKED			= 11,
778ca52cc3SSean Christopherson 	SGX_CHILD_PRESENT		= 13,
788ca52cc3SSean Christopherson 	SGX_INVALID_EINITTOKEN		= 16,
798ca52cc3SSean Christopherson 	SGX_UNMASKED_EVENT		= 128,
808ca52cc3SSean Christopherson };
818ca52cc3SSean Christopherson 
828ca52cc3SSean Christopherson /* The modulus size for 3072-bit RSA keys. */
838ca52cc3SSean Christopherson #define SGX_MODULUS_SIZE 384
848ca52cc3SSean Christopherson 
858ca52cc3SSean Christopherson /**
868ca52cc3SSean Christopherson  * enum sgx_miscselect - additional information to an SSA frame
878ca52cc3SSean Christopherson  * %SGX_MISC_EXINFO:	Report #PF or #GP to the SSA frame.
888ca52cc3SSean Christopherson  *
898ca52cc3SSean Christopherson  * Save State Area (SSA) is a stack inside the enclave used to store processor
908ca52cc3SSean Christopherson  * state when an exception or interrupt occurs. This enum defines additional
918ca52cc3SSean Christopherson  * information stored to an SSA frame.
928ca52cc3SSean Christopherson  */
938ca52cc3SSean Christopherson enum sgx_miscselect {
948ca52cc3SSean Christopherson 	SGX_MISC_EXINFO		= BIT(0),
958ca52cc3SSean Christopherson };
968ca52cc3SSean Christopherson 
978ca52cc3SSean Christopherson #define SGX_MISC_RESERVED_MASK	GENMASK_ULL(63, 1)
988ca52cc3SSean Christopherson 
998ca52cc3SSean Christopherson #define SGX_SSA_GPRS_SIZE		184
1008ca52cc3SSean Christopherson #define SGX_SSA_MISC_EXINFO_SIZE	16
1018ca52cc3SSean Christopherson 
1028ca52cc3SSean Christopherson /**
1038ca52cc3SSean Christopherson  * enum sgx_attributes - the attributes field in &struct sgx_secs
1048ca52cc3SSean Christopherson  * %SGX_ATTR_INIT:		Enclave can be entered (is initialized).
1058ca52cc3SSean Christopherson  * %SGX_ATTR_DEBUG:		Allow ENCLS(EDBGRD) and ENCLS(EDBGWR).
1068ca52cc3SSean Christopherson  * %SGX_ATTR_MODE64BIT:		Tell that this a 64-bit enclave.
1078ca52cc3SSean Christopherson  * %SGX_ATTR_PROVISIONKEY:      Allow to use provisioning keys for remote
1088ca52cc3SSean Christopherson  *				attestation.
1098ca52cc3SSean Christopherson  * %SGX_ATTR_KSS:		Allow to use key separation and sharing (KSS).
1108ca52cc3SSean Christopherson  * %SGX_ATTR_EINITTOKENKEY:	Allow to use token signing key that is used to
1118ca52cc3SSean Christopherson  *				sign cryptographic tokens that can be passed to
1128ca52cc3SSean Christopherson  *				EINIT as an authorization to run an enclave.
1138ca52cc3SSean Christopherson  */
1148ca52cc3SSean Christopherson enum sgx_attribute {
1158ca52cc3SSean Christopherson 	SGX_ATTR_INIT		= BIT(0),
1168ca52cc3SSean Christopherson 	SGX_ATTR_DEBUG		= BIT(1),
1178ca52cc3SSean Christopherson 	SGX_ATTR_MODE64BIT	= BIT(2),
1188ca52cc3SSean Christopherson 	SGX_ATTR_PROVISIONKEY	= BIT(4),
1198ca52cc3SSean Christopherson 	SGX_ATTR_EINITTOKENKEY	= BIT(5),
1208ca52cc3SSean Christopherson 	SGX_ATTR_KSS		= BIT(7),
1218ca52cc3SSean Christopherson };
1228ca52cc3SSean Christopherson 
1238ca52cc3SSean Christopherson #define SGX_ATTR_RESERVED_MASK	(BIT_ULL(3) | BIT_ULL(6) | GENMASK_ULL(63, 8))
1248ca52cc3SSean Christopherson 
1258ca52cc3SSean Christopherson /**
1268ca52cc3SSean Christopherson  * struct sgx_secs - SGX Enclave Control Structure (SECS)
1278ca52cc3SSean Christopherson  * @size:		size of the address space
1288ca52cc3SSean Christopherson  * @base:		base address of the  address space
1298ca52cc3SSean Christopherson  * @ssa_frame_size:	size of an SSA frame
1308ca52cc3SSean Christopherson  * @miscselect:		additional information stored to an SSA frame
1318ca52cc3SSean Christopherson  * @attributes:		attributes for enclave
1328ca52cc3SSean Christopherson  * @xfrm:		XSave-Feature Request Mask (subset of XCR0)
1338ca52cc3SSean Christopherson  * @mrenclave:		SHA256-hash of the enclave contents
1348ca52cc3SSean Christopherson  * @mrsigner:		SHA256-hash of the public key used to sign the SIGSTRUCT
1358ca52cc3SSean Christopherson  * @config_id:		a user-defined value that is used in key derivation
1368ca52cc3SSean Christopherson  * @isv_prod_id:	a user-defined value that is used in key derivation
1378ca52cc3SSean Christopherson  * @isv_svn:		a user-defined value that is used in key derivation
1388ca52cc3SSean Christopherson  * @config_svn:		a user-defined value that is used in key derivation
1398ca52cc3SSean Christopherson  *
1408ca52cc3SSean Christopherson  * SGX Enclave Control Structure (SECS) is a special enclave page that is not
1418ca52cc3SSean Christopherson  * visible in the address space. In fact, this structure defines the address
1428ca52cc3SSean Christopherson  * range and other global attributes for the enclave and it is the first EPC
1438ca52cc3SSean Christopherson  * page created for any enclave. It is moved from a temporary buffer to an EPC
1448ca52cc3SSean Christopherson  * by the means of ENCLS[ECREATE] function.
1458ca52cc3SSean Christopherson  */
1468ca52cc3SSean Christopherson struct sgx_secs {
1478ca52cc3SSean Christopherson 	u64 size;
1488ca52cc3SSean Christopherson 	u64 base;
1498ca52cc3SSean Christopherson 	u32 ssa_frame_size;
1508ca52cc3SSean Christopherson 	u32 miscselect;
1518ca52cc3SSean Christopherson 	u8  reserved1[24];
1528ca52cc3SSean Christopherson 	u64 attributes;
1538ca52cc3SSean Christopherson 	u64 xfrm;
1548ca52cc3SSean Christopherson 	u32 mrenclave[8];
1558ca52cc3SSean Christopherson 	u8  reserved2[32];
1568ca52cc3SSean Christopherson 	u32 mrsigner[8];
1578ca52cc3SSean Christopherson 	u8  reserved3[32];
1588ca52cc3SSean Christopherson 	u32 config_id[16];
1598ca52cc3SSean Christopherson 	u16 isv_prod_id;
1608ca52cc3SSean Christopherson 	u16 isv_svn;
1618ca52cc3SSean Christopherson 	u16 config_svn;
1628ca52cc3SSean Christopherson 	u8  reserved4[3834];
1638ca52cc3SSean Christopherson } __packed;
1648ca52cc3SSean Christopherson 
1658ca52cc3SSean Christopherson /**
1668ca52cc3SSean Christopherson  * enum sgx_tcs_flags - execution flags for TCS
1678ca52cc3SSean Christopherson  * %SGX_TCS_DBGOPTIN:	If enabled allows single-stepping and breakpoints
1688ca52cc3SSean Christopherson  *			inside an enclave. It is cleared by EADD but can
1698ca52cc3SSean Christopherson  *			be set later with EDBGWR.
1708ca52cc3SSean Christopherson  */
1718ca52cc3SSean Christopherson enum sgx_tcs_flags {
1728ca52cc3SSean Christopherson 	SGX_TCS_DBGOPTIN	= 0x01,
1738ca52cc3SSean Christopherson };
1748ca52cc3SSean Christopherson 
1758ca52cc3SSean Christopherson #define SGX_TCS_RESERVED_MASK	GENMASK_ULL(63, 1)
1768ca52cc3SSean Christopherson #define SGX_TCS_RESERVED_SIZE	4024
1778ca52cc3SSean Christopherson 
1788ca52cc3SSean Christopherson /**
1798ca52cc3SSean Christopherson  * struct sgx_tcs - Thread Control Structure (TCS)
1808ca52cc3SSean Christopherson  * @state:		used to mark an entered TCS
1818ca52cc3SSean Christopherson  * @flags:		execution flags (cleared by EADD)
1828ca52cc3SSean Christopherson  * @ssa_offset:		SSA stack offset relative to the enclave base
1838ca52cc3SSean Christopherson  * @ssa_index:		the current SSA frame index (cleard by EADD)
1848ca52cc3SSean Christopherson  * @nr_ssa_frames:	the number of frame in the SSA stack
1858ca52cc3SSean Christopherson  * @entry_offset:	entry point offset relative to the enclave base
1868ca52cc3SSean Christopherson  * @exit_addr:		address outside the enclave to exit on an exception or
1878ca52cc3SSean Christopherson  *			interrupt
1888ca52cc3SSean Christopherson  * @fs_offset:		offset relative to the enclave base to become FS
1898ca52cc3SSean Christopherson  *			segment inside the enclave
1908ca52cc3SSean Christopherson  * @gs_offset:		offset relative to the enclave base to become GS
1918ca52cc3SSean Christopherson  *			segment inside the enclave
1928ca52cc3SSean Christopherson  * @fs_limit:		size to become a new FS-limit (only 32-bit enclaves)
1938ca52cc3SSean Christopherson  * @gs_limit:		size to become a new GS-limit (only 32-bit enclaves)
1948ca52cc3SSean Christopherson  *
1958ca52cc3SSean Christopherson  * Thread Control Structure (TCS) is an enclave page visible in its address
1968ca52cc3SSean Christopherson  * space that defines an entry point inside the enclave. A thread enters inside
1978ca52cc3SSean Christopherson  * an enclave by supplying address of TCS to ENCLU(EENTER). A TCS can be entered
1988ca52cc3SSean Christopherson  * by only one thread at a time.
1998ca52cc3SSean Christopherson  */
2008ca52cc3SSean Christopherson struct sgx_tcs {
2018ca52cc3SSean Christopherson 	u64 state;
2028ca52cc3SSean Christopherson 	u64 flags;
2038ca52cc3SSean Christopherson 	u64 ssa_offset;
2048ca52cc3SSean Christopherson 	u32 ssa_index;
2058ca52cc3SSean Christopherson 	u32 nr_ssa_frames;
2068ca52cc3SSean Christopherson 	u64 entry_offset;
2078ca52cc3SSean Christopherson 	u64 exit_addr;
2088ca52cc3SSean Christopherson 	u64 fs_offset;
2098ca52cc3SSean Christopherson 	u64 gs_offset;
2108ca52cc3SSean Christopherson 	u32 fs_limit;
2118ca52cc3SSean Christopherson 	u32 gs_limit;
2128ca52cc3SSean Christopherson 	u8  reserved[SGX_TCS_RESERVED_SIZE];
2138ca52cc3SSean Christopherson } __packed;
2148ca52cc3SSean Christopherson 
2158ca52cc3SSean Christopherson /**
2168ca52cc3SSean Christopherson  * struct sgx_pageinfo - an enclave page descriptor
2178ca52cc3SSean Christopherson  * @addr:	address of the enclave page
2188ca52cc3SSean Christopherson  * @contents:	pointer to the page contents
2198ca52cc3SSean Christopherson  * @metadata:	pointer either to a SECINFO or PCMD instance
2208ca52cc3SSean Christopherson  * @secs:	address of the SECS page
2218ca52cc3SSean Christopherson  */
2228ca52cc3SSean Christopherson struct sgx_pageinfo {
2238ca52cc3SSean Christopherson 	u64 addr;
2248ca52cc3SSean Christopherson 	u64 contents;
2258ca52cc3SSean Christopherson 	u64 metadata;
2268ca52cc3SSean Christopherson 	u64 secs;
2278ca52cc3SSean Christopherson } __packed __aligned(32);
2288ca52cc3SSean Christopherson 
2298ca52cc3SSean Christopherson 
2308ca52cc3SSean Christopherson /**
2318ca52cc3SSean Christopherson  * enum sgx_page_type - bits in the SECINFO flags defining the page type
2328ca52cc3SSean Christopherson  * %SGX_PAGE_TYPE_SECS:	a SECS page
2338ca52cc3SSean Christopherson  * %SGX_PAGE_TYPE_TCS:	a TCS page
2348ca52cc3SSean Christopherson  * %SGX_PAGE_TYPE_REG:	a regular page
2358ca52cc3SSean Christopherson  * %SGX_PAGE_TYPE_VA:	a VA page
2368ca52cc3SSean Christopherson  * %SGX_PAGE_TYPE_TRIM:	a page in trimmed state
2378ca52cc3SSean Christopherson  */
2388ca52cc3SSean Christopherson enum sgx_page_type {
2398ca52cc3SSean Christopherson 	SGX_PAGE_TYPE_SECS,
2408ca52cc3SSean Christopherson 	SGX_PAGE_TYPE_TCS,
2418ca52cc3SSean Christopherson 	SGX_PAGE_TYPE_REG,
2428ca52cc3SSean Christopherson 	SGX_PAGE_TYPE_VA,
2438ca52cc3SSean Christopherson 	SGX_PAGE_TYPE_TRIM,
2448ca52cc3SSean Christopherson };
2458ca52cc3SSean Christopherson 
2468ca52cc3SSean Christopherson #define SGX_NR_PAGE_TYPES	5
2478ca52cc3SSean Christopherson #define SGX_PAGE_TYPE_MASK	GENMASK(7, 0)
2488ca52cc3SSean Christopherson 
2498ca52cc3SSean Christopherson /**
2508ca52cc3SSean Christopherson  * enum sgx_secinfo_flags - the flags field in &struct sgx_secinfo
2518ca52cc3SSean Christopherson  * %SGX_SECINFO_R:	allow read
2528ca52cc3SSean Christopherson  * %SGX_SECINFO_W:	allow write
2538ca52cc3SSean Christopherson  * %SGX_SECINFO_X:	allow execution
2548ca52cc3SSean Christopherson  * %SGX_SECINFO_SECS:	a SECS page
2558ca52cc3SSean Christopherson  * %SGX_SECINFO_TCS:	a TCS page
2568ca52cc3SSean Christopherson  * %SGX_SECINFO_REG:	a regular page
2578ca52cc3SSean Christopherson  * %SGX_SECINFO_VA:	a VA page
2588ca52cc3SSean Christopherson  * %SGX_SECINFO_TRIM:	a page in trimmed state
2598ca52cc3SSean Christopherson  */
2608ca52cc3SSean Christopherson enum sgx_secinfo_flags {
2618ca52cc3SSean Christopherson 	SGX_SECINFO_R			= BIT(0),
2628ca52cc3SSean Christopherson 	SGX_SECINFO_W			= BIT(1),
2638ca52cc3SSean Christopherson 	SGX_SECINFO_X			= BIT(2),
2648ca52cc3SSean Christopherson 	SGX_SECINFO_SECS		= (SGX_PAGE_TYPE_SECS << 8),
2658ca52cc3SSean Christopherson 	SGX_SECINFO_TCS			= (SGX_PAGE_TYPE_TCS << 8),
2668ca52cc3SSean Christopherson 	SGX_SECINFO_REG			= (SGX_PAGE_TYPE_REG << 8),
2678ca52cc3SSean Christopherson 	SGX_SECINFO_VA			= (SGX_PAGE_TYPE_VA << 8),
2688ca52cc3SSean Christopherson 	SGX_SECINFO_TRIM		= (SGX_PAGE_TYPE_TRIM << 8),
2698ca52cc3SSean Christopherson };
2708ca52cc3SSean Christopherson 
2718ca52cc3SSean Christopherson #define SGX_SECINFO_PERMISSION_MASK	GENMASK_ULL(2, 0)
2728ca52cc3SSean Christopherson #define SGX_SECINFO_PAGE_TYPE_MASK	(SGX_PAGE_TYPE_MASK << 8)
2738ca52cc3SSean Christopherson #define SGX_SECINFO_RESERVED_MASK	~(SGX_SECINFO_PERMISSION_MASK | \
2748ca52cc3SSean Christopherson 					  SGX_SECINFO_PAGE_TYPE_MASK)
2758ca52cc3SSean Christopherson 
2768ca52cc3SSean Christopherson /**
2778ca52cc3SSean Christopherson  * struct sgx_secinfo - describes attributes of an EPC page
2788ca52cc3SSean Christopherson  * @flags:	permissions and type
2798ca52cc3SSean Christopherson  *
2808ca52cc3SSean Christopherson  * Used together with ENCLS leaves that add or modify an EPC page to an
2818ca52cc3SSean Christopherson  * enclave to define page permissions and type.
2828ca52cc3SSean Christopherson  */
2838ca52cc3SSean Christopherson struct sgx_secinfo {
2848ca52cc3SSean Christopherson 	u64 flags;
2858ca52cc3SSean Christopherson 	u8  reserved[56];
2868ca52cc3SSean Christopherson } __packed __aligned(64);
2878ca52cc3SSean Christopherson 
2888ca52cc3SSean Christopherson #define SGX_PCMD_RESERVED_SIZE 40
2898ca52cc3SSean Christopherson 
2908ca52cc3SSean Christopherson /**
2918ca52cc3SSean Christopherson  * struct sgx_pcmd - Paging Crypto Metadata (PCMD)
2928ca52cc3SSean Christopherson  * @enclave_id:	enclave identifier
2938ca52cc3SSean Christopherson  * @mac:	MAC over PCMD, page contents and isvsvn
2948ca52cc3SSean Christopherson  *
2958ca52cc3SSean Christopherson  * PCMD is stored for every swapped page to the regular memory. When ELDU loads
2968ca52cc3SSean Christopherson  * the page back it recalculates the MAC by using a isvsvn number stored in a
2978ca52cc3SSean Christopherson  * VA page. Together these two structures bring integrity and rollback
2988ca52cc3SSean Christopherson  * protection.
2998ca52cc3SSean Christopherson  */
3008ca52cc3SSean Christopherson struct sgx_pcmd {
3018ca52cc3SSean Christopherson 	struct sgx_secinfo secinfo;
3028ca52cc3SSean Christopherson 	u64 enclave_id;
3038ca52cc3SSean Christopherson 	u8  reserved[SGX_PCMD_RESERVED_SIZE];
3048ca52cc3SSean Christopherson 	u8  mac[16];
3058ca52cc3SSean Christopherson } __packed __aligned(128);
3068ca52cc3SSean Christopherson 
3078ca52cc3SSean Christopherson #define SGX_SIGSTRUCT_RESERVED1_SIZE 84
3088ca52cc3SSean Christopherson #define SGX_SIGSTRUCT_RESERVED2_SIZE 20
3098ca52cc3SSean Christopherson #define SGX_SIGSTRUCT_RESERVED3_SIZE 32
3108ca52cc3SSean Christopherson #define SGX_SIGSTRUCT_RESERVED4_SIZE 12
3118ca52cc3SSean Christopherson 
3128ca52cc3SSean Christopherson /**
3138ca52cc3SSean Christopherson  * struct sgx_sigstruct_header -  defines author of the enclave
3148ca52cc3SSean Christopherson  * @header1:		constant byte string
3158ca52cc3SSean Christopherson  * @vendor:		must be either 0x0000 or 0x8086
3168ca52cc3SSean Christopherson  * @date:		YYYYMMDD in BCD
317ea5bc7b9SLinus Torvalds  * @header2:		constant byte string
3188ca52cc3SSean Christopherson  * @swdefined:		software defined value
3198ca52cc3SSean Christopherson  */
3208ca52cc3SSean Christopherson struct sgx_sigstruct_header {
3218ca52cc3SSean Christopherson 	u64 header1[2];
3228ca52cc3SSean Christopherson 	u32 vendor;
3238ca52cc3SSean Christopherson 	u32 date;
3248ca52cc3SSean Christopherson 	u64 header2[2];
3258ca52cc3SSean Christopherson 	u32 swdefined;
3268ca52cc3SSean Christopherson 	u8  reserved1[84];
3278ca52cc3SSean Christopherson } __packed;
3288ca52cc3SSean Christopherson 
3298ca52cc3SSean Christopherson /**
3308ca52cc3SSean Christopherson  * struct sgx_sigstruct_body - defines contents of the enclave
3318ca52cc3SSean Christopherson  * @miscselect:		additional information stored to an SSA frame
3328ca52cc3SSean Christopherson  * @misc_mask:		required miscselect in SECS
3338ca52cc3SSean Christopherson  * @attributes:		attributes for enclave
3348ca52cc3SSean Christopherson  * @xfrm:		XSave-Feature Request Mask (subset of XCR0)
3358ca52cc3SSean Christopherson  * @attributes_mask:	required attributes in SECS
3368ca52cc3SSean Christopherson  * @xfrm_mask:		required XFRM in SECS
3378ca52cc3SSean Christopherson  * @mrenclave:		SHA256-hash of the enclave contents
3388ca52cc3SSean Christopherson  * @isvprodid:		a user-defined value that is used in key derivation
3398ca52cc3SSean Christopherson  * @isvsvn:		a user-defined value that is used in key derivation
3408ca52cc3SSean Christopherson  */
3418ca52cc3SSean Christopherson struct sgx_sigstruct_body {
3428ca52cc3SSean Christopherson 	u32 miscselect;
3438ca52cc3SSean Christopherson 	u32 misc_mask;
3448ca52cc3SSean Christopherson 	u8  reserved2[20];
3458ca52cc3SSean Christopherson 	u64 attributes;
3468ca52cc3SSean Christopherson 	u64 xfrm;
3478ca52cc3SSean Christopherson 	u64 attributes_mask;
3488ca52cc3SSean Christopherson 	u64 xfrm_mask;
3498ca52cc3SSean Christopherson 	u8  mrenclave[32];
3508ca52cc3SSean Christopherson 	u8  reserved3[32];
3518ca52cc3SSean Christopherson 	u16 isvprodid;
3528ca52cc3SSean Christopherson 	u16 isvsvn;
3538ca52cc3SSean Christopherson } __packed;
3548ca52cc3SSean Christopherson 
3558ca52cc3SSean Christopherson /**
3568ca52cc3SSean Christopherson  * struct sgx_sigstruct - an enclave signature
3578ca52cc3SSean Christopherson  * @header:		defines author of the enclave
3588ca52cc3SSean Christopherson  * @modulus:		the modulus of the public key
3598ca52cc3SSean Christopherson  * @exponent:		the exponent of the public key
3608ca52cc3SSean Christopherson  * @signature:		the signature calculated over the fields except modulus,
3618ca52cc3SSean Christopherson  * @body:		defines contents of the enclave
3628ca52cc3SSean Christopherson  * @q1:			a value used in RSA signature verification
3638ca52cc3SSean Christopherson  * @q2:			a value used in RSA signature verification
3648ca52cc3SSean Christopherson  *
3658ca52cc3SSean Christopherson  * Header and body are the parts that are actual signed. The remaining fields
3668ca52cc3SSean Christopherson  * define the signature of the enclave.
3678ca52cc3SSean Christopherson  */
3688ca52cc3SSean Christopherson struct sgx_sigstruct {
3698ca52cc3SSean Christopherson 	struct sgx_sigstruct_header header;
3708ca52cc3SSean Christopherson 	u8  modulus[SGX_MODULUS_SIZE];
3718ca52cc3SSean Christopherson 	u32 exponent;
3728ca52cc3SSean Christopherson 	u8  signature[SGX_MODULUS_SIZE];
3738ca52cc3SSean Christopherson 	struct sgx_sigstruct_body body;
3748ca52cc3SSean Christopherson 	u8  reserved4[12];
3758ca52cc3SSean Christopherson 	u8  q1[SGX_MODULUS_SIZE];
3768ca52cc3SSean Christopherson 	u8  q2[SGX_MODULUS_SIZE];
3778ca52cc3SSean Christopherson } __packed;
3788ca52cc3SSean Christopherson 
3798ca52cc3SSean Christopherson #define SGX_LAUNCH_TOKEN_SIZE 304
3808ca52cc3SSean Christopherson 
3818ca52cc3SSean Christopherson /*
3828ca52cc3SSean Christopherson  * Do not put any hardware-defined SGX structure representations below this
3838ca52cc3SSean Christopherson  * comment!
3848ca52cc3SSean Christopherson  */
3858ca52cc3SSean Christopherson 
386d155030bSSean Christopherson #ifdef CONFIG_X86_SGX_KVM
387d155030bSSean Christopherson int sgx_virt_ecreate(struct sgx_pageinfo *pageinfo, void __user *secs,
388d155030bSSean Christopherson 		     int *trapnr);
389d155030bSSean Christopherson int sgx_virt_einit(void __user *sigstruct, void __user *token,
390d155030bSSean Christopherson 		   void __user *secs, u64 *lepubkeyhash, int *trapnr);
391d155030bSSean Christopherson #endif
392d155030bSSean Christopherson 
393b3754e5dSSean Christopherson int sgx_set_attribute(unsigned long *allowed_attributes,
394b3754e5dSSean Christopherson 		      unsigned int attribute_fd);
395b3754e5dSSean Christopherson 
3968ca52cc3SSean Christopherson #endif /* _ASM_X86_SGX_H */
397