Skip to contentSkip to conversation

x86/sgx: Use ENCLS mnemonic in <kernel/cpu/sgx/encls.h>

PATCH Applied Uros Bizjak 4 participants 7 messages Jun 16, 2025 – Aug 27, 2025

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

PATCH 1/1 x86/sgx: Use ENCLS mnemonic in <kernel/cpu/sgx/encls.h>

Current minimum required version of binutils is 2.30, which supports ENCLS instruction mnemonic.

Replace the byte-wise specification of ENCLS with
this proper mnemonic.

No functional change intended.

Cc Jarkko Sakkinen <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/cpu/sgx/encls.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/sgx/encls.h +3 -3
index 99004b02e2ed..42a088a337c5 100644
@@ -68,7 +68,7 @@ static inline bool encls_failed(int ret)
 	({							\
 	int ret;						\
 	asm volatile(						\
-	"1: .byte 0x0f, 0x01, 0xcf;\n\t"			\
+	"1: encls\n"						\
 	"2:\n"							\
 	_ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_FAULT_SGX)		\
 	: "=a"(ret)						\
@@ -111,8 +111,8 @@ static inline bool encls_failed(int ret)
 	({							\
 	int ret;						\
 	asm volatile(						\
-	"1: .byte 0x0f, 0x01, 0xcf;\n\t"			\
-	"   xor %%eax,%%eax;\n"					\
+	"1: encls\n\t"						\
+	"xor %%eax,%%eax\n"					\
 	"2:\n"							\
 	_ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_FAULT_SGX)		\
 	: "=a"(ret), "=b"(rbx_out)				\
Signature · 1 line
2.49.0
maintainer
#1 lore raw
Quoted 46 lines · Uros Bizjak

Current minimum required version of binutils is 2.30, which supports ENCLS instruction mnemonic.

Replace the byte-wise specification of ENCLS with
this proper mnemonic.

No functional change intended.

Cc Jarkko Sakkinen <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/cpu/sgx/encls.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/sgx/encls.h +3 -3
index 99004b02e2ed..42a088a337c5 100644
@@ -68,7 +68,7 @@ static inline bool encls_failed(int ret)
 	({							\
 	int ret;						\
 	asm volatile(						\
-	"1: .byte 0x0f, 0x01, 0xcf;\n\t"			\
+	"1: encls\n"						\
 	"2:\n"							\
 	_ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_FAULT_SGX)		\
 	: "=a"(ret)						\
@@ -111,8 +111,8 @@ static inline bool encls_failed(int ret)
 	({							\
 	int ret;						\
 	asm volatile(						\
-	"1: .byte 0x0f, 0x01, 0xcf;\n\t"			\
-	"   xor %%eax,%%eax;\n"					\
+	"1: encls\n\t"						\
+	"xor %%eax,%%eax\n"					\
 	"2:\n"							\
 	_ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_FAULT_SGX)		\
 	: "=a"(ret), "=b"(rbx_out)				\
Signature · 1 line
2.49.0

I don't really see how this is that useful. That said, f a bug fix or feature used encls mnemonic, I'd had no problems with acking it.

BR, Jarkko

#2 lore raw
Quoted 2 lines · Jarkko Sakkinen

I don't really see how this is that useful. That said, f a bug fix or feature used encls mnemonic, I'd had no problems with acking it.

It's not _that_ useful.

But old assemblers that we still want to use *NEVER* have support for newfanlged instructions, so we always add new instructions with ".byte". Then, a few years down the road when we've moved to just old assemblers instead of super old assemblers, we move to the real instruction names.

This is all business as usual.

#3 lore raw
Quoted 11 lines · Dave Hansen
Quoted 2 lines · Jarkko Sakkinen

I don't really see how this is that useful. That said, f a bug fix or feature used encls mnemonic, I'd had no problems with acking it.

It's not _that_ useful.

But old assemblers that we still want to use *NEVER* have support for newfanlged instructions, so we always add new instructions with ".byte". Then, a few years down the road when we've moved to just old assemblers instead of super old assemblers, we move to the real instruction names.

That, and the code becomes self-documenting. You don't have to scratch your head what the .byte stream represents when reading assembly.

Uros.

maintainer
#4 lore raw
Quoted 8 lines · Uros Bizjak
Quoted 7 lines · Dave Hansen
Quoted 2 lines · Jarkko Sakkinen

I don't really see how this is that useful. That said, f a bug fix or feature used encls mnemonic, I'd had no problems with acking it.

It's not _that_ useful.

Quoted 7 lines
Quoted 4 lines

But old assemblers that we still want to use *NEVER* have support for newfanlged instructions, so we always add new instructions with ".byte". Then, a few years down the road when we've moved to just old assemblers instead of super old assemblers, we move to the real instruction names.

That, and the code becomes self-documenting. You don't have to scratch your head what the .byte stream represents when reading assembly.

I hear you but I doubt that here looking into the code in detail and not being aware of ENCLS opcode would be unlikely :-)

That said, I'm cool with applying the patch to tip.

Quoted 2 lines

Uros.

BR, Jarkko

maintainer Reviewed-by
#5 lore raw
In reply to Dave Hansen
Quoted 4 lines · Dave Hansen
Quoted 2 lines · Jarkko Sakkinen

I don't really see how this is that useful. That said, f a bug fix or feature used encls mnemonic, I'd had no problems with acking it.

Quoted 8 lines

It's not _that_ useful.

But old assemblers that we still want to use *NEVER* have support for newfanlged instructions, so we always add new instructions with ".byte". Then, a few years down the road when we've moved to just old assemblers instead of super old assemblers, we move to the real instruction names.

This is all business as usual.

OK, I'm fine with this reasoning as it is neither by any means distruptive change either:

BR, Jarkko

merge bot Applied
#6 lore raw
In reply to Uros Bizjak
The following commit has been merged into the x86/cleanups branch of tip:

The following commit has been merged into the x86/cleanups branch of tip:

Commit-ID:     13bdfb53aa04eeb8022af87288c5bc0a5d13a834
Gitweb:        https://git.kernel.org/tip/13bdfb53aa04eeb8022af87288c5bc0a5d13a834
Author:        Uros Bizjak <[email protected]>
AuthorDate:    Mon, 16 Jun 2025 10:56:30 +02:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Mon, 25 Aug 2025 17:28:43 +02:00

x86/sgx: Use ENCLS mnemonic in <kernel/cpu/sgx/encls.h>

Current minimum required version of binutils is 2.30, which supports ENCLS instruction mnemonic.

Replace the byte-wise specification of ENCLS with this proper mnemonic.

No functional change intended.

---
 arch/x86/kernel/cpu/sgx/encls.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/sgx/encls.h +3 -3
index 99004b0..42a088a 100644
@@ -68,7 +68,7 @@ static inline bool encls_failed(int ret)
 	({							\
 	int ret;						\
 	asm volatile(						\
-	"1: .byte 0x0f, 0x01, 0xcf;\n\t"			\
+	"1: encls\n"						\
 	"2:\n"							\
 	_ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_FAULT_SGX)		\
 	: "=a"(ret)						\
@@ -111,8 +111,8 @@ static inline bool encls_failed(int ret)
 	({							\
 	int ret;						\
 	asm volatile(						\
-	"1: .byte 0x0f, 0x01, 0xcf;\n\t"			\
-	"   xor %%eax,%%eax;\n"					\
+	"1: encls\n\t"						\
+	"xor %%eax,%%eax\n"					\
 	"2:\n"							\
 	_ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_FAULT_SGX)		\
 	: "=a"(ret), "=b"(rbx_out)				\