Skip to content

Commit

Permalink
Merge tag 'x86_sgx_for_v6.0-2022-08-03.1' of git://git.kernel.org/pub…
Browse files Browse the repository at this point in the history
…/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()
  ...
  • Loading branch information
torvalds committed Aug 5, 2022
2 parents 3bd6e58 + e0a5915 commit 9e2f402
Show file tree
Hide file tree
Showing 15 changed files with 2,627 additions and 130 deletions.
15 changes: 15 additions & 0 deletions Documentation/x86/sgx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ pages and establish enclave page permissions.
sgx_ioc_enclave_init
sgx_ioc_enclave_provision

Enclave runtime management
--------------------------

Systems supporting SGX2 additionally support changes to initialized
enclaves: modifying enclave page permissions and type, and dynamically
adding and removing of enclave pages. When an enclave accesses an address
within its address range that does not have a backing page then a new
regular page will be dynamically added to the enclave. The enclave is
still required to run EACCEPT on the new page before it can be used.

.. kernel-doc:: arch/x86/kernel/cpu/sgx/ioctl.c
:functions: sgx_ioc_enclave_restrict_permissions
sgx_ioc_enclave_modify_types
sgx_ioc_enclave_remove_pages

Enclave vDSO
------------

Expand Down
8 changes: 8 additions & 0 deletions arch/x86/include/asm/sgx.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,22 @@ enum sgx_encls_function {

/**
* enum sgx_return_code - The return code type for ENCLS, ENCLU and ENCLV
* %SGX_EPC_PAGE_CONFLICT: Page is being written by other ENCLS function.
* %SGX_NOT_TRACKED: Previous ETRACK's shootdown sequence has not
* been completed yet.
* %SGX_CHILD_PRESENT SECS has child pages present in the EPC.
* %SGX_INVALID_EINITTOKEN: EINITTOKEN is invalid and enclave signer's
* public key does not match IA32_SGXLEPUBKEYHASH.
* %SGX_PAGE_NOT_MODIFIABLE: The EPC page cannot be modified because it
* is in the PENDING or MODIFIED state.
* %SGX_UNMASKED_EVENT: An unmasked event, e.g. INTR, was received
*/
enum sgx_return_code {
SGX_EPC_PAGE_CONFLICT = 7,
SGX_NOT_TRACKED = 11,
SGX_CHILD_PRESENT = 13,
SGX_INVALID_EINITTOKEN = 16,
SGX_PAGE_NOT_MODIFIABLE = 20,
SGX_UNMASKED_EVENT = 128,
};

Expand Down Expand Up @@ -234,6 +239,9 @@ struct sgx_pageinfo {
* %SGX_PAGE_TYPE_REG: a regular page
* %SGX_PAGE_TYPE_VA: a VA page
* %SGX_PAGE_TYPE_TRIM: a page in trimmed state
*
* Make sure when making changes to this enum that its values can still fit
* in the bitfield within &struct sgx_encl_page
*/
enum sgx_page_type {
SGX_PAGE_TYPE_SECS,
Expand Down
62 changes: 62 additions & 0 deletions arch/x86/include/uapi/asm/sgx.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ enum sgx_page_flags {
_IOW(SGX_MAGIC, 0x03, struct sgx_enclave_provision)
#define SGX_IOC_VEPC_REMOVE_ALL \
_IO(SGX_MAGIC, 0x04)
#define SGX_IOC_ENCLAVE_RESTRICT_PERMISSIONS \
_IOWR(SGX_MAGIC, 0x05, struct sgx_enclave_restrict_permissions)
#define SGX_IOC_ENCLAVE_MODIFY_TYPES \
_IOWR(SGX_MAGIC, 0x06, struct sgx_enclave_modify_types)
#define SGX_IOC_ENCLAVE_REMOVE_PAGES \
_IOWR(SGX_MAGIC, 0x07, struct sgx_enclave_remove_pages)

/**
* struct sgx_enclave_create - parameter structure for the
Expand Down Expand Up @@ -76,6 +82,62 @@ struct sgx_enclave_provision {
__u64 fd;
};

/**
* struct sgx_enclave_restrict_permissions - parameters for ioctl
* %SGX_IOC_ENCLAVE_RESTRICT_PERMISSIONS
* @offset: starting page offset (page aligned relative to enclave base
* address defined in SECS)
* @length: length of memory (multiple of the page size)
* @permissions:new permission bits for pages in range described by @offset
* and @length
* @result: (output) SGX result code of ENCLS[EMODPR] function
* @count: (output) bytes successfully changed (multiple of page size)
*/
struct sgx_enclave_restrict_permissions {
__u64 offset;
__u64 length;
__u64 permissions;
__u64 result;
__u64 count;
};

/**
* struct sgx_enclave_modify_types - parameters for ioctl
* %SGX_IOC_ENCLAVE_MODIFY_TYPES
* @offset: starting page offset (page aligned relative to enclave base
* address defined in SECS)
* @length: length of memory (multiple of the page size)
* @page_type: new type for pages in range described by @offset and @length
* @result: (output) SGX result code of ENCLS[EMODT] function
* @count: (output) bytes successfully changed (multiple of page size)
*/
struct sgx_enclave_modify_types {
__u64 offset;
__u64 length;
__u64 page_type;
__u64 result;
__u64 count;
};

/**
* struct sgx_enclave_remove_pages - %SGX_IOC_ENCLAVE_REMOVE_PAGES parameters
* @offset: starting page offset (page aligned relative to enclave base
* address defined in SECS)
* @length: length of memory (multiple of the page size)
* @count: (output) bytes successfully changed (multiple of page size)
*
* Regular (PT_REG) or TCS (PT_TCS) can be removed from an initialized
* enclave if the system supports SGX2. First, the %SGX_IOC_ENCLAVE_MODIFY_TYPES
* ioctl() should be used to change the page type to PT_TRIM. After that
* succeeds ENCLU[EACCEPT] should be run from within the enclave and then
* %SGX_IOC_ENCLAVE_REMOVE_PAGES can be used to complete the page removal.
*/
struct sgx_enclave_remove_pages {
__u64 offset;
__u64 length;
__u64 count;
};

struct sgx_enclave_run;

/**
Expand Down
Loading

0 comments on commit 9e2f402

Please sign in to comment.