Skip to contentSkip to conversation

x86/asm: Use RDPKRU and WRPKRU mnemonics in <asm/special_insns.h>

PATCH Applied Uros Bizjak 3 participants 5 messages Jun 16, 2025 – Aug 22, 2025 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/asm: Use RDPKRU and WRPKRU mnemonics in <asm/special_insns.h>

Current minimum required version of binutils is 2.30, which supports RDPKRU and WRPKRU instruction mnemonics.

Replace the byte-wise specification of RDPKRU and
WRPKRU with these proper mnemonics.

No functional change intended.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/include/asm/special_insns.h | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
arch/x86/include/asm/special_insns.h +2 -5
index ecda17efa042..13e272e1a53f 100644
@@ -75,9 +75,7 @@ static inline u32 rdpkru(void)
 	 * "rdpkru" instruction.  Places PKRU contents in to EAX,
 	 * clears EDX and requires that ecx=0.
 	 */
-	asm volatile(".byte 0x0f,0x01,0xee\n\t"
-		     : "=a" (pkru), "=d" (edx)
-		     : "c" (ecx));
+	asm volatile("rdpkru" : "=a" (pkru), "=d" (edx) : "c" (ecx));
 	return pkru;
 }
 
@@ -89,8 +87,7 @@ static inline void wrpkru(u32 pkru)
 	 * "wrpkru" instruction.  Loads contents in EAX to PKRU,
 	 * requires that ecx = edx = 0.
 	 */
-	asm volatile(".byte 0x0f,0x01,0xef\n\t"
-		     : : "a" (pkru), "c"(ecx), "d"(edx));
+	asm volatile("wrpkru" : : "a" (pkru), "c"(ecx), "d"(edx));
 }
 
 #else
Signature · 1 line
2.49.0
#1 lore raw
Quoted 5 lines · Uros Bizjak

Current minimum required version of binutils is 2.30, which supports RDPKRU and WRPKRU instruction mnemonics.

Replace the byte-wise specification of RDPKRU and
WRPKRU with these proper mnemonics.

What about the minimal clang version and their integrated assembler?

#2 lore raw
Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · Uros Bizjak

Current minimum required version of binutils is 2.30, which supports RDPKRU and WRPKRU instruction mnemonics.

Replace the byte-wise specification of RDPKRU and
WRPKRU with these proper mnemonics.

What about the minimal clang version and their integrated assembler?

Yes, it works with the minimum required clang version 13.0.1.

Uros.

#3 lore raw
Quoted 6 lines · Uros Bizjak
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Uros Bizjak

Current minimum required version of binutils is 2.30, which supports RDPKRU and WRPKRU instruction mnemonics.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Replace the byte-wise specification of RDPKRU and
WRPKRU with these proper mnemonics.

What about the minimal clang version and their integrated assembler?

Yes, it works with the minimum required clang version 13.0.1.

Excellent!

merge bot Applied
#4 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:     966f504977e3a04fcadbaf199e3302e95e8958b7
Gitweb:        https://git.kernel.org/tip/966f504977e3a04fcadbaf199e3302e95e8958b7
Author:        Uros Bizjak <[email protected]>
AuthorDate:    Mon, 16 Jun 2025 10:35:57 +02:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Fri, 22 Aug 2025 18:54:07 +02:00

x86/asm: Use RDPKRU and WRPKRU mnemonics in <asm/special_insns.h>

Current minimum required version of binutils is 2.30, which supports RDPKRU and WRPKRU instruction mnemonics.

Replace the byte-wise specification of RDPKRU and WRPKRU with these proper mnemonics.

No functional change intended.

---
 arch/x86/include/asm/special_insns.h | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
arch/x86/include/asm/special_insns.h +2 -5
index fde2bd7..c999145 100644
@@ -75,9 +75,7 @@ static inline u32 rdpkru(void)
 	 * "rdpkru" instruction.  Places PKRU contents in to EAX,
 	 * clears EDX and requires that ecx=0.
 	 */
-	asm volatile(".byte 0x0f,0x01,0xee\n\t"
-		     : "=a" (pkru), "=d" (edx)
-		     : "c" (ecx));
+	asm volatile("rdpkru" : "=a" (pkru), "=d" (edx) : "c" (ecx));
 	return pkru;
 }
 
@@ -89,8 +87,7 @@ static inline void wrpkru(u32 pkru)
 	 * "wrpkru" instruction.  Loads contents in EAX to PKRU,
 	 * requires that ecx = edx = 0.
 	 */
-	asm volatile(".byte 0x0f,0x01,0xef\n\t"
-		     : : "a" (pkru), "c"(ecx), "d"(edx));
+	asm volatile("wrpkru" : : "a" (pkru), "c"(ecx), "d"(edx));
 }
 
 #else