Skip to contentSkip to conversation

x86/sgx: Remove unused definitions and reuse launch token size

PATCH In review Thorsten Blum 1 participant 5 messages Jul 29 – Aug 31

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover x86/sgx: Remove unused definitions and reuse launch token size

Remove SGX definitions that have never had in-tree users and reuse SGX_LAUNCH_TOKEN_SIZE when validating the launch token in __sgx_virt_einit().

Changes in v2:
- Adjust commit message 3/3 as suggested by Kai
- v1: https://lore.kernel.org/r/[email protected]/

Thorsten Blum (3):
x86/sgx: Remove unused TCS definitions
x86/sgx: Remove unused size and count definitions x86/sgx: Use SGX_LAUNCH_TOKEN_SIZE in __sgx_virt_einit()

 arch/x86/include/asm/sgx.h     | 59 ----------------------------------
 arch/x86/kernel/cpu/sgx/virt.c |  3 +-
 2 files changed, 1 insertion(+), 61 deletions(-)

base-commit: 2d3090a8aeb596a26935db0955d46c9a5db5c6ce

#1 lore raw

PATCH v2 1/3 x86/sgx: Remove unused TCS definitions

The TCS structure was added with commit 70d3b8ddcd20 ("x86/sgx: Add SGX architectural data structures"), but has never had an in-tree user. Remove the unused TCS structure and its corresponding definitions.

---
 arch/x86/include/asm/sgx.h | 50 --------------------------------------
 1 file changed, 50 deletions(-)
arch/x86/include/asm/sgx.h +0 -50
index 04958459a7ca..fe106c55a593 100644
@@ -193,56 +193,6 @@ struct sgx_secs {
 	u8  reserved4[3834];
 } __packed;
 
-/**
- * enum sgx_tcs_flags - execution flags for TCS
- * @SGX_TCS_DBGOPTIN:	If enabled allows single-stepping and breakpoints
- *			inside an enclave. It is cleared by EADD but can
- *			be set later with EDBGWR.
- */
-enum sgx_tcs_flags {
-	SGX_TCS_DBGOPTIN	= 0x01,
-};
-
-#define SGX_TCS_RESERVED_MASK	GENMASK_ULL(63, 1)
-#define SGX_TCS_RESERVED_SIZE	4024
-
-/**
- * struct sgx_tcs - Thread Control Structure (TCS)
- * @state:		used to mark an entered TCS
- * @flags:		execution flags (cleared by EADD)
- * @ssa_offset:		SSA stack offset relative to the enclave base
- * @ssa_index:		the current SSA frame index (cleard by EADD)
- * @nr_ssa_frames:	the number of frame in the SSA stack
- * @entry_offset:	entry point offset relative to the enclave base
- * @exit_addr:		address outside the enclave to exit on an exception or
- *			interrupt
- * @fs_offset:		offset relative to the enclave base to become FS
- *			segment inside the enclave
- * @gs_offset:		offset relative to the enclave base to become GS
- *			segment inside the enclave
- * @fs_limit:		size to become a new FS-limit (only 32-bit enclaves)
- * @gs_limit:		size to become a new GS-limit (only 32-bit enclaves)
- *
- * Thread Control Structure (TCS) is an enclave page visible in its address
- * space that defines an entry point inside the enclave. A thread enters inside
- * an enclave by supplying address of TCS to ENCLU(EENTER). A TCS can be entered
- * by only one thread at a time.
- */
-struct sgx_tcs {
-	u64 state;
-	u64 flags;
-	u64 ssa_offset;
-	u32 ssa_index;
-	u32 nr_ssa_frames;
-	u64 entry_offset;
-	u64 exit_addr;
-	u64 fs_offset;
-	u64 gs_offset;
-	u32 fs_limit;
-	u32 gs_limit;
-	u8  reserved[SGX_TCS_RESERVED_SIZE];
-} __packed;
-
 /**
  * struct sgx_pageinfo - an enclave page descriptor
  * @addr:	address of the enclave page
#2 lore raw

PATCH v2 2/3 x86/sgx: Remove unused size and count definitions

In reply to Thorsten Blum

The definitions were added with commit 70d3b8ddcd20 ("x86/sgx: Add SGX architectural data structures"), but have never been used. The SIGSTRUCT reserved field sizes are also redundant because the structure uses literal sizes instead. Remove them.

---
 arch/x86/include/asm/sgx.h | 9 ---------
 1 file changed, 9 deletions(-)
arch/x86/include/asm/sgx.h +0 -9
index fe106c55a593..af5cd6ce9010 100644
@@ -108,9 +108,6 @@ enum sgx_miscselect {
 
 #define SGX_MISC_RESERVED_MASK	GENMASK_ULL(63, 1)
 
-#define SGX_SSA_GPRS_SIZE		184
-#define SGX_SSA_MISC_EXINFO_SIZE	16
-
 /**
  * enum sgx_attribute - the attributes field in &struct sgx_secs
  * @SGX_ATTR_INIT:		Enclave can be entered (is initialized).
@@ -227,7 +224,6 @@ enum sgx_page_type {
 	SGX_PAGE_TYPE_TRIM,
 };
 
-#define SGX_NR_PAGE_TYPES	5
 #define SGX_PAGE_TYPE_MASK	GENMASK(7, 0)
 
 /**
@@ -288,11 +284,6 @@ struct sgx_pcmd {
 	u8  mac[16];
 } __packed __aligned(128);
 
-#define SGX_SIGSTRUCT_RESERVED1_SIZE 84
-#define SGX_SIGSTRUCT_RESERVED2_SIZE 20
-#define SGX_SIGSTRUCT_RESERVED3_SIZE 32
-#define SGX_SIGSTRUCT_RESERVED4_SIZE 12
-
 /**
  * struct sgx_sigstruct_header -  defines author of the enclave
  * @header1:		constant byte string
#3 lore raw

PATCH v2 3/3 x86/sgx: Use SGX_LAUNCH_TOKEN_SIZE in __sgx_virt_einit()

In reply to Thorsten Blum

Both sgx_ioc_enclave_init() and __sgx_virt_einit() use the same 304-byte launch token. Use SGX_LAUNCH_TOKEN_SIZE in __sgx_virt_einit() instead of maintaining a second local definition.

---
 arch/x86/kernel/cpu/sgx/virt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kernel/cpu/sgx/virt.c +1 -2
index 6a1933ddc6fc..7c5ac5d38ee1 100644
@@ -395,9 +395,8 @@ static int __sgx_virt_einit(void __user *sigstruct, void __user *token,
 	 * All other checks deferred to ENCLS itself.  Also see comment
 	 * for @secs in sgx_virt_ecreate().
 	 */
-#define SGX_EINITTOKEN_SIZE	304
 	if (WARN_ON_ONCE(!access_ok(sigstruct, sizeof(struct sgx_sigstruct)) ||
-			 !access_ok(token, SGX_EINITTOKEN_SIZE) ||
+			 !access_ok(token, SGX_LAUNCH_TOKEN_SIZE) ||
 			 !access_ok(secs, PAGE_SIZE)))
 		return -EINVAL;
 
#4 lore raw
In reply to Thorsten Blum
Quoted 13 lines · Thorsten Blum

Remove SGX definitions that have never had in-tree users and reuse SGX_LAUNCH_TOKEN_SIZE when validating the launch token in __sgx_virt_einit().

Changes in v2:
- Adjust commit message 3/3 as suggested by Kai
- v1: https://lore.kernel.org/r/[email protected]/

Thorsten Blum (3):
x86/sgx: Remove unused TCS definitions
x86/sgx: Remove unused size and count definitions x86/sgx: Use SGX_LAUNCH_TOKEN_SIZE in __sgx_virt_einit()

Quoted 6 lines
 arch/x86/include/asm/sgx.h     | 59 ----------------------------------
 arch/x86/kernel/cpu/sgx/virt.c |  3 +-
 2 files changed, 1 insertion(+), 61 deletions(-)

base-commit: 2d3090a8aeb596a26935db0955d46c9a5db5c6ce

Gentle ping - all 3 patches have had Reviewed-by: and/or Acked-by: tags since mid-July. Is there anything missing or can these be applied?

Thanks,
Thorsten