The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/3] x86/sgx: Remove unused definitions and reuse launch token size
@ 2026-07-11 10:00 Thorsten Blum
  2026-07-11 10:00 ` [PATCH 1/3] x86/sgx: Remove unused TCS definitions Thorsten Blum
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Thorsten Blum @ 2026-07-11 10:00 UTC (permalink / raw)
  To: Jarkko Sakkinen, Dave Hansen, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, H. Peter Anvin
  Cc: x86, linux-sgx, linux-kernel, 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().

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] x86/sgx: Remove unused TCS definitions
  2026-07-11 10:00 [PATCH 0/3] x86/sgx: Remove unused definitions and reuse launch token size Thorsten Blum
@ 2026-07-11 10:00 ` Thorsten Blum
  2026-07-11 18:22   ` Jarkko Sakkinen
  2026-07-11 10:00 ` [PATCH 2/3] x86/sgx: Remove unused size and count definitions Thorsten Blum
  2026-07-11 10:00 ` [PATCH 3/3] x86/sgx: Use SGX_LAUNCH_TOKEN_SIZE in __sgx_virt_einit() Thorsten Blum
  2 siblings, 1 reply; 7+ messages in thread
From: Thorsten Blum @ 2026-07-11 10:00 UTC (permalink / raw)
  To: Jarkko Sakkinen, Dave Hansen, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, H. Peter Anvin, x86
  Cc: linux-sgx, linux-kernel, Thorsten Blum

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.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/x86/include/asm/sgx.h | 50 --------------------------------------
 1 file changed, 50 deletions(-)

diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h
index 04958459a7ca..fe106c55a593 100644
--- a/arch/x86/include/asm/sgx.h
+++ b/arch/x86/include/asm/sgx.h
@@ -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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] x86/sgx: Remove unused size and count definitions
  2026-07-11 10:00 [PATCH 0/3] x86/sgx: Remove unused definitions and reuse launch token size Thorsten Blum
  2026-07-11 10:00 ` [PATCH 1/3] x86/sgx: Remove unused TCS definitions Thorsten Blum
@ 2026-07-11 10:00 ` Thorsten Blum
  2026-07-11 18:22   ` Jarkko Sakkinen
  2026-07-11 10:00 ` [PATCH 3/3] x86/sgx: Use SGX_LAUNCH_TOKEN_SIZE in __sgx_virt_einit() Thorsten Blum
  2 siblings, 1 reply; 7+ messages in thread
From: Thorsten Blum @ 2026-07-11 10:00 UTC (permalink / raw)
  To: Jarkko Sakkinen, Dave Hansen, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, H. Peter Anvin, x86
  Cc: linux-sgx, linux-kernel, 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.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/x86/include/asm/sgx.h | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h
index fe106c55a593..af5cd6ce9010 100644
--- a/arch/x86/include/asm/sgx.h
+++ b/arch/x86/include/asm/sgx.h
@@ -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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] x86/sgx: Use SGX_LAUNCH_TOKEN_SIZE in __sgx_virt_einit()
  2026-07-11 10:00 [PATCH 0/3] x86/sgx: Remove unused definitions and reuse launch token size Thorsten Blum
  2026-07-11 10:00 ` [PATCH 1/3] x86/sgx: Remove unused TCS definitions Thorsten Blum
  2026-07-11 10:00 ` [PATCH 2/3] x86/sgx: Remove unused size and count definitions Thorsten Blum
@ 2026-07-11 10:00 ` Thorsten Blum
  2026-07-11 18:23   ` Jarkko Sakkinen
  2 siblings, 1 reply; 7+ messages in thread
From: Thorsten Blum @ 2026-07-11 10:00 UTC (permalink / raw)
  To: Jarkko Sakkinen, Dave Hansen, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, H. Peter Anvin, x86
  Cc: linux-sgx, linux-kernel, 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, ensuring the token initialization
and validation paths use the same size.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/x86/kernel/cpu/sgx/virt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/sgx/virt.c b/arch/x86/kernel/cpu/sgx/virt.c
index db6806c40483..fa9173a9384a 100644
--- a/arch/x86/kernel/cpu/sgx/virt.c
+++ b/arch/x86/kernel/cpu/sgx/virt.c
@@ -394,9 +394,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;
 

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] x86/sgx: Remove unused TCS definitions
  2026-07-11 10:00 ` [PATCH 1/3] x86/sgx: Remove unused TCS definitions Thorsten Blum
@ 2026-07-11 18:22   ` Jarkko Sakkinen
  0 siblings, 0 replies; 7+ messages in thread
From: Jarkko Sakkinen @ 2026-07-11 18:22 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Dave Hansen, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, x86, linux-sgx, linux-kernel

On Sat, Jul 11, 2026 at 12:00:55PM +0200, Thorsten Blum wrote:
> 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.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  arch/x86/include/asm/sgx.h | 50 --------------------------------------
>  1 file changed, 50 deletions(-)
> 
> diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h
> index 04958459a7ca..fe106c55a593 100644
> --- a/arch/x86/include/asm/sgx.h
> +++ b/arch/x86/include/asm/sgx.h
> @@ -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


Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] x86/sgx: Remove unused size and count definitions
  2026-07-11 10:00 ` [PATCH 2/3] x86/sgx: Remove unused size and count definitions Thorsten Blum
@ 2026-07-11 18:22   ` Jarkko Sakkinen
  0 siblings, 0 replies; 7+ messages in thread
From: Jarkko Sakkinen @ 2026-07-11 18:22 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Dave Hansen, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, x86, linux-sgx, linux-kernel

On Sat, Jul 11, 2026 at 12:00:56PM +0200, Thorsten Blum wrote:
> 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.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  arch/x86/include/asm/sgx.h | 9 ---------
>  1 file changed, 9 deletions(-)
> 
> diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h
> index fe106c55a593..af5cd6ce9010 100644
> --- a/arch/x86/include/asm/sgx.h
> +++ b/arch/x86/include/asm/sgx.h
> @@ -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


Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] x86/sgx: Use SGX_LAUNCH_TOKEN_SIZE in __sgx_virt_einit()
  2026-07-11 10:00 ` [PATCH 3/3] x86/sgx: Use SGX_LAUNCH_TOKEN_SIZE in __sgx_virt_einit() Thorsten Blum
@ 2026-07-11 18:23   ` Jarkko Sakkinen
  0 siblings, 0 replies; 7+ messages in thread
From: Jarkko Sakkinen @ 2026-07-11 18:23 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Dave Hansen, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, x86, linux-sgx, linux-kernel

On Sat, Jul 11, 2026 at 12:00:57PM +0200, Thorsten Blum wrote:
> 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, ensuring the token initialization
> and validation paths use the same size.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  arch/x86/kernel/cpu/sgx/virt.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/sgx/virt.c b/arch/x86/kernel/cpu/sgx/virt.c
> index db6806c40483..fa9173a9384a 100644
> --- a/arch/x86/kernel/cpu/sgx/virt.c
> +++ b/arch/x86/kernel/cpu/sgx/virt.c
> @@ -394,9 +394,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;
>  

true:

❯ git grep LAUNCH_TOKEN_SIZE
arch/x86/include/asm/sgx.h:#define SGX_LAUNCH_TOKEN_SIZE 304
arch/x86/kernel/cpu/sgx/ioctl.c:        memset(token, 0, SGX_LAUNCH_TOKEN_SIZE);

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-07-11 18:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-11 10:00 [PATCH 0/3] x86/sgx: Remove unused definitions and reuse launch token size Thorsten Blum
2026-07-11 10:00 ` [PATCH 1/3] x86/sgx: Remove unused TCS definitions Thorsten Blum
2026-07-11 18:22   ` Jarkko Sakkinen
2026-07-11 10:00 ` [PATCH 2/3] x86/sgx: Remove unused size and count definitions Thorsten Blum
2026-07-11 18:22   ` Jarkko Sakkinen
2026-07-11 10:00 ` [PATCH 3/3] x86/sgx: Use SGX_LAUNCH_TOKEN_SIZE in __sgx_virt_einit() Thorsten Blum
2026-07-11 18:23   ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox