Skip to content

Commit 9e2f402

Browse files
committed
Merge tag 'x86_sgx_for_v6.0-2022-08-03.1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 SGX updates from Dave Hansen: "A set of x86/sgx changes focused on implementing the "SGX2" features, plus a minor cleanup: - SGX2 ISA support which makes enclave memory management much more dynamic. For instance, enclaves can now change enclave page permissions on the fly. - Removal of an unused structure member" * tag 'x86_sgx_for_v6.0-2022-08-03.1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (32 commits) x86/sgx: Drop 'page_index' from sgx_backing selftests/sgx: Page removal stress test selftests/sgx: Test reclaiming of untouched page selftests/sgx: Test invalid access to removed enclave page selftests/sgx: Test faulty enclave behavior selftests/sgx: Test complete changing of page type flow selftests/sgx: Introduce TCS initialization enclave operation selftests/sgx: Introduce dynamic entry point selftests/sgx: Test two different SGX2 EAUG flows selftests/sgx: Add test for TCS page permission changes selftests/sgx: Add test for EPCM permission changes Documentation/x86: Introduce enclave runtime management section x86/sgx: Free up EPC pages directly to support large page ranges x86/sgx: Support complete page removal x86/sgx: Support modifying SGX page type x86/sgx: Tighten accessible memory range after enclave initialization x86/sgx: Support adding of pages to an initialized enclave x86/sgx: Support restricting of enclave page permissions x86/sgx: Support VA page allocation without reclaiming x86/sgx: Export sgx_encl_page_alloc() ...
2 parents 3bd6e58 + e0a5915 commit 9e2f402

File tree

15 files changed

+2627
-130
lines changed

15 files changed

+2627
-130
lines changed

Documentation/x86/sgx.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@ pages and establish enclave page permissions.
100100
sgx_ioc_enclave_init
101101
sgx_ioc_enclave_provision
102102

103+
Enclave runtime management
104+
--------------------------
105+
106+
Systems supporting SGX2 additionally support changes to initialized
107+
enclaves: modifying enclave page permissions and type, and dynamically
108+
adding and removing of enclave pages. When an enclave accesses an address
109+
within its address range that does not have a backing page then a new
110+
regular page will be dynamically added to the enclave. The enclave is
111+
still required to run EACCEPT on the new page before it can be used.
112+
113+
.. kernel-doc:: arch/x86/kernel/cpu/sgx/ioctl.c
114+
:functions: sgx_ioc_enclave_restrict_permissions
115+
sgx_ioc_enclave_modify_types
116+
sgx_ioc_enclave_remove_pages
117+
103118
Enclave vDSO
104119
------------
105120

arch/x86/include/asm/sgx.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,22 @@ enum sgx_encls_function {
6565

6666
/**
6767
* enum sgx_return_code - The return code type for ENCLS, ENCLU and ENCLV
68+
* %SGX_EPC_PAGE_CONFLICT: Page is being written by other ENCLS function.
6869
* %SGX_NOT_TRACKED: Previous ETRACK's shootdown sequence has not
6970
* been completed yet.
7071
* %SGX_CHILD_PRESENT SECS has child pages present in the EPC.
7172
* %SGX_INVALID_EINITTOKEN: EINITTOKEN is invalid and enclave signer's
7273
* public key does not match IA32_SGXLEPUBKEYHASH.
74+
* %SGX_PAGE_NOT_MODIFIABLE: The EPC page cannot be modified because it
75+
* is in the PENDING or MODIFIED state.
7376
* %SGX_UNMASKED_EVENT: An unmasked event, e.g. INTR, was received
7477
*/
7578
enum sgx_return_code {
79+
SGX_EPC_PAGE_CONFLICT = 7,
7680
SGX_NOT_TRACKED = 11,
7781
SGX_CHILD_PRESENT = 13,
7882
SGX_INVALID_EINITTOKEN = 16,
83+
SGX_PAGE_NOT_MODIFIABLE = 20,
7984
SGX_UNMASKED_EVENT = 128,
8085
};
8186

@@ -234,6 +239,9 @@ struct sgx_pageinfo {
234239
* %SGX_PAGE_TYPE_REG: a regular page
235240
* %SGX_PAGE_TYPE_VA: a VA page
236241
* %SGX_PAGE_TYPE_TRIM: a page in trimmed state
242+
*
243+
* Make sure when making changes to this enum that its values can still fit
244+
* in the bitfield within &struct sgx_encl_page
237245
*/
238246
enum sgx_page_type {
239247
SGX_PAGE_TYPE_SECS,

arch/x86/include/uapi/asm/sgx.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ enum sgx_page_flags {
2929
_IOW(SGX_MAGIC, 0x03, struct sgx_enclave_provision)
3030
#define SGX_IOC_VEPC_REMOVE_ALL \
3131
_IO(SGX_MAGIC, 0x04)
32+
#define SGX_IOC_ENCLAVE_RESTRICT_PERMISSIONS \
33+
_IOWR(SGX_MAGIC, 0x05, struct sgx_enclave_restrict_permissions)
34+
#define SGX_IOC_ENCLAVE_MODIFY_TYPES \
35+
_IOWR(SGX_MAGIC, 0x06, struct sgx_enclave_modify_types)
36+
#define SGX_IOC_ENCLAVE_REMOVE_PAGES \
37+
_IOWR(SGX_MAGIC, 0x07, struct sgx_enclave_remove_pages)
3238

3339
/**
3440
* struct sgx_enclave_create - parameter structure for the
@@ -76,6 +82,62 @@ struct sgx_enclave_provision {
7682
__u64 fd;
7783
};
7884

85+
/**
86+
* struct sgx_enclave_restrict_permissions - parameters for ioctl
87+
* %SGX_IOC_ENCLAVE_RESTRICT_PERMISSIONS
88+
* @offset: starting page offset (page aligned relative to enclave base
89+
* address defined in SECS)
90+
* @length: length of memory (multiple of the page size)
91+
* @permissions:new permission bits for pages in range described by @offset
92+
* and @length
93+
* @result: (output) SGX result code of ENCLS[EMODPR] function
94+
* @count: (output) bytes successfully changed (multiple of page size)
95+
*/
96+
struct sgx_enclave_restrict_permissions {
97+
__u64 offset;
98+
__u64 length;
99+
__u64 permissions;
100+
__u64 result;
101+
__u64 count;
102+
};
103+
104+
/**
105+
* struct sgx_enclave_modify_types - parameters for ioctl
106+
* %SGX_IOC_ENCLAVE_MODIFY_TYPES
107+
* @offset: starting page offset (page aligned relative to enclave base
108+
* address defined in SECS)
109+
* @length: length of memory (multiple of the page size)
110+
* @page_type: new type for pages in range described by @offset and @length
111+
* @result: (output) SGX result code of ENCLS[EMODT] function
112+
* @count: (output) bytes successfully changed (multiple of page size)
113+
*/
114+
struct sgx_enclave_modify_types {
115+
__u64 offset;
116+
__u64 length;
117+
__u64 page_type;
118+
__u64 result;
119+
__u64 count;
120+
};
121+
122+
/**
123+
* struct sgx_enclave_remove_pages - %SGX_IOC_ENCLAVE_REMOVE_PAGES parameters
124+
* @offset: starting page offset (page aligned relative to enclave base
125+
* address defined in SECS)
126+
* @length: length of memory (multiple of the page size)
127+
* @count: (output) bytes successfully changed (multiple of page size)
128+
*
129+
* Regular (PT_REG) or TCS (PT_TCS) can be removed from an initialized
130+
* enclave if the system supports SGX2. First, the %SGX_IOC_ENCLAVE_MODIFY_TYPES
131+
* ioctl() should be used to change the page type to PT_TRIM. After that
132+
* succeeds ENCLU[EACCEPT] should be run from within the enclave and then
133+
* %SGX_IOC_ENCLAVE_REMOVE_PAGES can be used to complete the page removal.
134+
*/
135+
struct sgx_enclave_remove_pages {
136+
__u64 offset;
137+
__u64 length;
138+
__u64 count;
139+
};
140+
79141
struct sgx_enclave_run;
80142

81143
/**

0 commit comments

Comments
 (0)