Skip to contentSkip to conversation

objtool: Few x86 decoder updates

PATCH Applied Peter Zijlstra 4 participants 19 messages Sep 24, 2025 – Oct 14, 2025

Subsystems (2)
lore
Share & tools
lore

Peter Zijlstra

author maintainer
#0 lore raw

cover objtool: Few x86 decoder updates

Hi,

few patches that update the 0xea/udb situation and fix up the x86_64 NOP decoding.

author maintainer
#1 lore raw

PATCH 1/3 objtool/x86: Remove 0xea hack

Was properly fixed in the decoder with commit 4b626015e1bf ("x86/insn:
Stop decoding i64 instructions in x86-64 mode at opcode")

---
 tools/objtool/arch/x86/decode.c |    9 ---------
 1 file changed, 9 deletions(-)
tools/objtool/arch/x86/decode.c +0 -9
@@ -189,15 +189,6 @@ int arch_decode_instruction(struct objto
 	op2 = ins.opcode.bytes[1];
 	op3 = ins.opcode.bytes[2];
 
-	/*
-	 * XXX hack, decoder is buggered and thinks 0xea is 7 bytes long.
-	 */
-	if (op1 == 0xea) {
-		insn->len = 1;
-		insn->type = INSN_BUG;
-		return 0;
-	}
-
 	if (ins.rex_prefix.nbytes) {
 		rex = ins.rex_prefix.bytes[0];
 		rex_w = X86_REX_W(rex) >> 3;
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] objtool/x86: Remove 0xea hack

Quoted 18 lines · Peter Zijlstra

Was properly fixed in the decoder with commit 4b626015e1bf ("x86/insn:
Stop decoding i64 instructions in x86-64 mode at opcode")

---
  tools/objtool/arch/x86/decode.c |    9 ---------
  1 file changed, 9 deletions(-)
tools/objtool/arch/x86/decode.c +0 -2
@@ -189,15 +189,6 @@ int arch_decode_instruction(struct objto
  	op2 = ins.opcode.bytes[1];
  	op3 = ins.opcode.bytes[2];
 
-	/*
-	 * XXX hack, decoder is buggered and thinks 0xea is 7 bytes long.

tools/objtool/arch/x86/decode.c int arch_decode_instruction(struct objto · line 194

Quoted 10 lines
tools/objtool/arch/x86/decode.c +0 -7
-	 */
-	if (op1 == 0xea) {
-		insn->len = 1;
-		insn->type = INSN_BUG;
-		return 0;
-	}
-
  	if (ins.rex_prefix.nbytes) {
  		rex = ins.rex_prefix.bytes[0];
  		rex_w = X86_REX_W(rex) >> 3;

alex.

merge bot Applied
#3 lore raw

[tip: objtool/core] objtool/x86: Remove 0xea hack

In reply to Peter Zijlstra
The following commit has been merged into the objtool/core branch of tip:

The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     c5df4e1ab8c00c4dc13094fa44e219bc48d910f4
Gitweb:        https://git.kernel.org/tip/c5df4e1ab8c00c4dc13094fa44e219bc48d910f4
Author:        Peter Zijlstra <[email protected]>
AuthorDate:    Wed, 24 Sep 2025 15:22:46 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 14 Oct 2025 13:43:10 +02:00

objtool/x86: Remove 0xea hack

Was properly fixed in the decoder with commit 4b626015e1bf ("x86/insn:
Stop decoding i64 instructions in x86-64 mode at opcode")

---
 tools/objtool/arch/x86/decode.c |  9 ---------
 1 file changed, 9 deletions(-)
tools/objtool/arch/x86/decode.c +0 -9
index 0ad5cc7..ce16fb2 100644
@@ -189,15 +189,6 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 	op2 = ins.opcode.bytes[1];
 	op3 = ins.opcode.bytes[2];
 
-	/*
-	 * XXX hack, decoder is buggered and thinks 0xea is 7 bytes long.
-	 */
-	if (op1 == 0xea) {
-		insn->len = 1;
-		insn->type = INSN_BUG;
-		return 0;
-	}
-
 	if (ins.rex_prefix.nbytes) {
 		rex = ins.rex_prefix.bytes[0];
 		rex_w = X86_REX_W(rex) >> 3;
author maintainer
#4 lore raw

PATCH 2/3 objtool/x86: Add UDB support

In reply to Peter Zijlstra

Per commit 85a2d4a890dc ("x86,ibt: Use UDB instead of 0xEA"), make sure objtool also recognises UDB as a #UD instruction.

---
 tools/objtool/arch/x86/decode.c |    4 ++++
 1 file changed, 4 insertions(+)
tools/objtool/arch/x86/decode.c +4 -0
@@ -683,6 +683,10 @@ int arch_decode_instruction(struct objto
 		insn->type = INSN_SYSRET;
 		break;
 
+	case 0xd6: /* udb */
+		insn->type = INSN_BUG;
+		break;
+
 	case 0xe0: /* loopne */
 	case 0xe1: /* loope */
 	case 0xe2: /* loop */
Reviewed-by on v1 2/3
#5 lore raw

Re: [PATCH 2/3] objtool/x86: Add UDB support

Quoted 13 lines · Peter Zijlstra

Per commit 85a2d4a890dc ("x86,ibt: Use UDB instead of 0xEA"), make sure objtool also recognises UDB as a #UD instruction.

---
  tools/objtool/arch/x86/decode.c |    4 ++++
  1 file changed, 4 insertions(+)

tools/objtool/arch/x86/decode.c int arch_decode_instruction(struct objto · line 692

Quoted 10 lines
tools/objtool/arch/x86/decode.c +4 -0
@@ -683,6 +683,10 @@ int arch_decode_instruction(struct objto
  		insn->type = INSN_SYSRET;
  		break;
 
+	case 0xd6: /* udb */
+		insn->type = INSN_BUG;
+		break;
+
  	case 0xe0: /* loopne */
  	case 0xe1: /* loope */
  	case 0xe2: /* loop */

alex.

merge bot Applied
#6 lore raw

[tip: objtool/core] objtool/x86: Add UDB support

In reply to Peter Zijlstra
The following commit has been merged into the objtool/core branch of tip:

The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     76e1851a1bc28e760d6acc7a54ec9dce05717028
Gitweb:        https://git.kernel.org/tip/76e1851a1bc28e760d6acc7a54ec9dce05717028
Author:        Peter Zijlstra <[email protected]>
AuthorDate:    Wed, 24 Sep 2025 15:25:27 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 14 Oct 2025 13:43:11 +02:00

objtool/x86: Add UDB support

Per commit 85a2d4a890dc ("x86,ibt: Use UDB instead of 0xEA"), make sure objtool also recognises UDB as a #UD instruction.

---
 tools/objtool/arch/x86/decode.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/objtool/arch/x86/decode.c +4 -0
index ce16fb2..ef6e96d 100644
@@ -683,6 +683,10 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 		insn->type = INSN_SYSRET;
 		break;
 
+	case 0xd6: /* udb */
+		insn->type = INSN_BUG;
+		break;
+
 	case 0xe0: /* loopne */
 	case 0xe1: /* loope */
 	case 0xe2: /* loop */
author maintainer
#7 lore raw

PATCH 3/3 objtool/x86: Fix NOP decode

In reply to Peter Zijlstra

For x86_64 the kernel consistently uses 2 instructions for all NOPs:

90 - NOP
0f 1f /0 - NOPL

Notably:

- REP NOP is PAUSE, not a NOP instruction.

- 0f {0c...0f} is reserved space,
except for 0f 0d /1, which is PREFETCHW, not a NOP.

- 0f {19,1c...1f} is reserved space,
except for 0f 1f /0, which is NOPL.

---
 tools/objtool/arch/x86/decode.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tools/objtool/arch/x86/decode.c +7 -5
@@ -494,7 +494,8 @@ int arch_decode_instruction(struct objto
 		break;
 
 	case 0x90:
-		insn->type = INSN_NOP;
+		if (prefix != 0xf3) /* REP NOP := PAUSE */
+			insn->type = INSN_NOP;
 		break;
 
 	case 0x9c:
@@ -547,13 +548,14 @@ int arch_decode_instruction(struct objto
 
 		} else if (op2 == 0x0b || op2 == 0xb9) {
 
-			/* ud2 */
+			/* ud2, ud1 */
 			insn->type = INSN_BUG;
 
-		} else if (op2 == 0x0d || op2 == 0x1f) {
+		} else if (op2 == 0x1f) {
 
-			/* nopl/nopw */
-			insn->type = INSN_NOP;
+			/* 0f 1f /0 := NOPL */
+			if (modrm_reg == 0)
+				insn->type = INSN_NOP;
 
 		} else if (op2 == 0x1e) {
 
#8 lore raw

Re: [PATCH 3/3] objtool/x86: Fix NOP decode

Quoted 24 lines · Peter Zijlstra

For x86_64 the kernel consistently uses 2 instructions for all NOPs:

90 - NOP
0f 1f /0 - NOPL

Notably:

- REP NOP is PAUSE, not a NOP instruction.

- 0f {0c...0f} is reserved space,
except for 0f 0d /1, which is PREFETCHW, not a NOP.

- 0f {19,1c...1f} is reserved space,
except for 0f 1f /0, which is NOPL.

---
  tools/objtool/arch/x86/decode.c |   12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)

tools/objtool/arch/x86/decode.c int arch_decode_instruction(struct objto · line 499

Quoted 7 lines
tools/objtool/arch/x86/decode.c +2 -1
@@ -494,7 +494,8 @@ int arch_decode_instruction(struct objto
  		break;
 
  	case 0x90:
-		insn->type = INSN_NOP;
+		if (prefix != 0xf3) /* REP NOP := PAUSE */
+			insn->type = INSN_NOP;
  		break;

So this covers NOP1 (0x90) and NOP2 (0x66 0x90), right?

Quoted 11 lines
tools/objtool/arch/x86/decode.c +1 -2
  	case 0x9c:
@@ -547,13 +548,14 @@ int arch_decode_instruction(struct objto
 
  		} else if (op2 == 0x0b || op2 == 0xb9) {
 
-			/* ud2 */
+			/* ud2, ud1 */
  			insn->type = INSN_BUG;
 
-		} else if (op2 == 0x0d || op2 == 0x1f) {

tools/objtool/arch/x86/decode.c int arch_decode_instruction(struct objto · line 561

Quoted 10 lines
tools/objtool/arch/x86/decode.c +4 -2
+		} else if (op2 == 0x1f) {
 
-			/* nopl/nopw */
-			insn->type = INSN_NOP;
+			/* 0f 1f /0 := NOPL */
+			if (modrm_reg == 0)
+				insn->type = INSN_NOP;
 
  		} else if (op2 == 0x1e) {
 

And this covers all other NOPs (0x0f 0x1f ...), including NOP6 which has a 0x66 preifx (0x66 0xf 0x1f ...) ?

From arch/x86/include/asm/nops.h we have:

/*
* Generic 64bit nops from GAS:
*
* 1: nop
* 2: osp nop
* 3: nopl (%eax)
* 4: nopl 0x00(%eax)
* 5: nopl 0x00(%eax,%eax,1)
* 6: osp nopl 0x00(%eax,%eax,1)
* 7: nopl 0x00000000(%eax)
* 8: nopl 0x00000000(%eax,%eax,1)
*/

#define BYTES_NOP1      0x90
#define BYTES_NOP2      0x66,BYTES_NOP1
#define BYTES_NOP3      0x0f,0x1f,0x00
#define BYTES_NOP4      0x0f,0x1f,0x40,0x00
#define BYTES_NOP5      0x0f,0x1f,0x44,0x00,0x00
#define BYTES_NOP6      0x66,BYTES_NOP5
#define BYTES_NOP7      0x0f,0x1f,0x80,0x00,0x00,0x00,0x00
#define BYTES_NOP8      0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00

alex.

author maintainer
#9 lore raw

Re: [PATCH 3/3] objtool/x86: Fix NOP decode

Quoted 23 lines · Alexandre Chartre
Quoted 21 lines · Peter Zijlstra

For x86_64 the kernel consistently uses 2 instructions for all NOPs:

90 - NOP
0f 1f /0 - NOPL

Notably:

- REP NOP is PAUSE, not a NOP instruction.

- 0f {0c...0f} is reserved space,
except for 0f 0d /1, which is PREFETCHW, not a NOP.

- 0f {19,1c...1f} is reserved space,
except for 0f 1f /0, which is NOPL.

---
  tools/objtool/arch/x86/decode.c |   12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
Quoted 10 lines

tools/objtool/arch/x86/decode.c int arch_decode_instruction(struct objto · line 498

Quoted 8 lines
tools/objtool/arch/x86/decode.c +2 -0
@@ -494,7 +494,8 @@ int arch_decode_instruction(struct objto
  		break;
  	case 0x90:
+		if (prefix != 0xf3) /* REP NOP := PAUSE */
+			insn->type = INSN_NOP;
  		break;

So this covers NOP1 (0x90) and NOP2 (0x66 0x90), right?

Yes. Everything with opcode 0x90, except 0xf3 0x90, which as stated is PAUSE.

Quoted 5 lines
Quoted 5 lines
tools/objtool/arch/x86/decode.c +1 -0
  	case 0x9c:
@@ -547,13 +548,14 @@ int arch_decode_instruction(struct objto
  		} else if (op2 == 0x0b || op2 == 0xb9) {
+			/* ud2, ud1 */
  			insn->type = INSN_BUG;
Quoted 8 lines

tools/objtool/arch/x86/decode.c int arch_decode_instruction(struct objto · line 560

Quoted 5 lines
tools/objtool/arch/x86/decode.c +4 -0
+		} else if (op2 == 0x1f) {
+			/* 0f 1f /0 := NOPL */
+			if (modrm_reg == 0)
+				insn->type = INSN_NOP;
  		} else if (op2 == 0x1e) {

And this covers all other NOPs (0x0f 0x1f ...), including NOP6 which has a 0x66 preifx (0x66 0xf 0x1f ...) ?

Sorta, it accepts everything with opcode 0f 1f and modrm_reg==0, which is how NOPL is encoded.

Both: 66 66 66 66 66 66 66 66 66 66 66 66 66 66 90 (NOP15)
And:  66 66 66 66 66 66 66 0f 1f 84 00 00 00 00 00 (NOP15)

will be accepted here as max length instructions. The kernel will not actually use those, since a bunch of micro archs have decode penalties for too many prefixes.

Quoted 1 line

From arch/x86/include/asm/nops.h we have:

You're looking at old code :-)

Quoted 11 lines

/*
* Generic 64bit nops from GAS:
*
* 1: nop
* 2: osp nop
* 3: nopl (%eax)
* 4: nopl 0x00(%eax)
* 5: nopl 0x00(%eax,%eax,1)
* 6: osp nopl 0x00(%eax,%eax,1)
* 7: nopl 0x00000000(%eax)
* 8: nopl 0x00000000(%eax,%eax,1)

* 9: cs nopl 0x00000000(%eax,%eax,1)
* 10: osp cs nopl 0x00000000(%eax,%eax,1)
* 11: osp osp cs nopl 0x00000000(%eax,%eax,1)

Quoted 9 lines

*/

#define BYTES_NOP1      0x90
#define BYTES_NOP2      0x66,BYTES_NOP1
#define BYTES_NOP3      0x0f,0x1f,0x00
#define BYTES_NOP4      0x0f,0x1f,0x40,0x00
#define BYTES_NOP5      0x0f,0x1f,0x44,0x00,0x00
#define BYTES_NOP6      0x66,BYTES_NOP5
#define BYTES_NOP7      0x0f,0x1f,0x80,0x00,0x00,0x00,0x00
#define BYTES_NOP8      0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00
#define BYTES_NOP9      0x2e,BYTES_NOP8
#define BYTES_NOP10     0x66,BYTES_NOP9
#define BYTES_NOP11     0x66,BYTES_NOP10

But yes, first two are NOP and then it switches to NOPL for 3 bytes and longer (2 opcode, 1 modrm). Where for 11 bytes we have:

- 3 prefixes
- 2 opcode
- 1 modrm
- 1 sib
- 4 displacement

#10 lore raw

Re: [PATCH 3/3] objtool/x86: Fix NOP decode

Quoted 35 lines · Peter Zijlstra
Quoted 23 lines · Alexandre Chartre
Quoted 21 lines · Peter Zijlstra

For x86_64 the kernel consistently uses 2 instructions for all NOPs:

90 - NOP
0f 1f /0 - NOPL

Notably:

- REP NOP is PAUSE, not a NOP instruction.

- 0f {0c...0f} is reserved space,
except for 0f 0d /1, which is PREFETCHW, not a NOP.

- 0f {19,1c...1f} is reserved space,
except for 0f 1f /0, which is NOPL.

---
   tools/objtool/arch/x86/decode.c |   12 +++++++-----
   1 file changed, 7 insertions(+), 5 deletions(-)
Quoted 10 lines

tools/objtool/arch/x86/decode.c int arch_decode_instruction(struct objto · line 498

Quoted 8 lines
tools/objtool/arch/x86/decode.c +2 -0
@@ -494,7 +494,8 @@ int arch_decode_instruction(struct objto
   		break;
   	case 0x90:
+		if (prefix != 0xf3) /* REP NOP := PAUSE */
+			insn->type = INSN_NOP;
   		break;

So this covers NOP1 (0x90) and NOP2 (0x66 0x90), right?

Quoted 3 lines

Yes. Everything with opcode 0x90, except 0xf3 0x90, which as stated is PAUSE.

What about 0x49 0x90, which is xchg (XCHG r8,rAX) ?

Quoted 20 lines
Quoted 5 lines
Quoted 5 lines
tools/objtool/arch/x86/decode.c +1 -0
   	case 0x9c:
@@ -547,13 +548,14 @@ int arch_decode_instruction(struct objto
   		} else if (op2 == 0x0b || op2 == 0xb9) {
+			/* ud2, ud1 */
   			insn->type = INSN_BUG;
Quoted 8 lines

tools/objtool/arch/x86/decode.c int arch_decode_instruction(struct objto · line 560

Quoted 5 lines
tools/objtool/arch/x86/decode.c +4 -0
+		} else if (op2 == 0x1f) {
+			/* 0f 1f /0 := NOPL */
+			if (modrm_reg == 0)
+				insn->type = INSN_NOP;
   		} else if (op2 == 0x1e) {

And this covers all other NOPs (0x0f 0x1f ...), including NOP6 which has a 0x66 preifx (0x66 0xf 0x1f ...) ?

Sorta, it accepts everything with opcode 0f 1f and modrm_reg==0, which is how NOPL is encoded.

Both: 66 66 66 66 66 66 66 66 66 66 66 66 66 66 90 (NOP15)
And:  66 66 66 66 66 66 66 0f 1f 84 00 00 00 00 00 (NOP15)
Quoted 8 lines

will be accepted here as max length instructions. The kernel will not actually use those, since a bunch of micro archs have decode penalties for too many prefixes.

Quoted 1 line

From arch/x86/include/asm/nops.h we have:

You're looking at old code :-)

Correct, I was on the 5.15 branch.

alex.

Quoted 39 lines
Quoted 11 lines

/*
* Generic 64bit nops from GAS:
*
* 1: nop
* 2: osp nop
* 3: nopl (%eax)
* 4: nopl 0x00(%eax)
* 5: nopl 0x00(%eax,%eax,1)
* 6: osp nopl 0x00(%eax,%eax,1)
* 7: nopl 0x00000000(%eax)
* 8: nopl 0x00000000(%eax,%eax,1)

* 9: cs nopl 0x00000000(%eax,%eax,1)
* 10: osp cs nopl 0x00000000(%eax,%eax,1)
* 11: osp osp cs nopl 0x00000000(%eax,%eax,1)

Quoted 9 lines

*/

#define BYTES_NOP1      0x90
#define BYTES_NOP2      0x66,BYTES_NOP1
#define BYTES_NOP3      0x0f,0x1f,0x00
#define BYTES_NOP4      0x0f,0x1f,0x40,0x00
#define BYTES_NOP5      0x0f,0x1f,0x44,0x00,0x00
#define BYTES_NOP6      0x66,BYTES_NOP5
#define BYTES_NOP7      0x0f,0x1f,0x80,0x00,0x00,0x00,0x00
#define BYTES_NOP8      0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00
#define BYTES_NOP9      0x2e,BYTES_NOP8
#define BYTES_NOP10     0x66,BYTES_NOP9
#define BYTES_NOP11     0x66,BYTES_NOP10

But yes, first two are NOP and then it switches to NOPL for 3 bytes and longer (2 opcode, 1 modrm). Where for 11 bytes we have:

- 3 prefixes
- 2 opcode
- 1 modrm
- 1 sib
- 4 displacement

author maintainer
#11 lore raw

Re: [PATCH 3/3] objtool/x86: Fix NOP decode

Quoted 37 lines · Alexandre Chartre
Quoted 35 lines · Peter Zijlstra
Quoted 33 lines · Alexandre Chartre
Quoted 24 lines · Peter Zijlstra

For x86_64 the kernel consistently uses 2 instructions for all NOPs:

90 - NOP
0f 1f /0 - NOPL

Notably:

- REP NOP is PAUSE, not a NOP instruction.

- 0f {0c...0f} is reserved space,
except for 0f 0d /1, which is PREFETCHW, not a NOP.

- 0f {19,1c...1f} is reserved space,
except for 0f 1f /0, which is NOPL.

---
   tools/objtool/arch/x86/decode.c |   12 +++++++-----
   1 file changed, 7 insertions(+), 5 deletions(-)

tools/objtool/arch/x86/decode.c int arch_decode_instruction(struct objto · line 498

Quoted 5 lines
tools/objtool/arch/x86/decode.c +2 -0
@@ -494,7 +494,8 @@ int arch_decode_instruction(struct objto
   		break;
   	case 0x90:
+		if (prefix != 0xf3) /* REP NOP := PAUSE */
+			insn->type = INSN_NOP;
   		break;

So this covers NOP1 (0x90) and NOP2 (0x66 0x90), right?

Quoted 5 lines
Quoted 3 lines

Yes. Everything with opcode 0x90, except 0xf3 0x90, which as stated is PAUSE.

What about 0x49 0x90, which is xchg (XCHG r8,rAX) ?

Ooh, that is a nice one. Yes, that needs fixing. Thanks!

author maintainer
#12 lore raw

Re: [PATCH 3/3] objtool/x86: Fix NOP decode

Quoted 6 lines · Peter Zijlstra
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

tools/objtool/arch/x86/decode.c int arch_decode_instruction(struct objto · line 499

Quoted 4 lines
   	case 0x90:
tools/objtool/arch/x86/decode.c +2 -0
+		if (prefix != 0xf3) /* REP NOP := PAUSE */
+			insn->type = INSN_NOP;
   		break;

What about 0x49 0x90, which is xchg (XCHG r8,rAX) ?

I've made that:

	case 0x90:                                                                                                                                                                                                                        
		if (rex_b) /* XCHG %r8, %rax */ 
			break; 

		if (prefix == 0xf3) /* REP NOP := PAUSE */ 
			break; 

		insn->type = INSN_NOP; 
		break;
#13 lore raw

Re: [PATCH 3/3] objtool/x86: Fix NOP decode

Quoted 11 lines

I've made that:

	case 0x90:                                                                                                                                                                                                                        
		if (rex_b) /* XCHG %r8, %rax */ 
			break; 

		if (prefix == 0xf3) /* REP NOP := PAUSE */ 
			break; 

		insn->type = INSN_NOP; 
		break;

Legacy prefixes can come in any order.  What is F3 66 90 ?

Also, VEX/EVEX/REX2 want excluding too, all of which can encode rex_b differently.

Is it really only rex_b which prevents NOP becoming a pause, or is it any REX prefix?  I would have thought it was any REX prefix.

~Andrew

author maintainer
#14 lore raw

Re: [PATCH 3/3] objtool/x86: Fix NOP decode

Quoted 9 lines · Andrew Cooper
Quoted 9 lines

I've made that:

	case 0x90:                                                                                                                                                                                                                        
		if (rex_b) /* XCHG %r8, %rax */ 
			break; 

		if (prefix == 0xf3) /* REP NOP := PAUSE */ 
			break; 
Quoted 7 lines
Quoted 2 lines
		insn->type = INSN_NOP; 
		break;

Legacy prefixes can come in any order.  What is F3 66 90 ?

Also, VEX/EVEX/REX2 want excluding too, all of which can encode rex_b differently.

So luckily objtool only really cares about instructions as found in the kernel text. Neither f3 66 90 nor VEX/EVEX/REX2 prefixes are of much concern.

But yes.. I happen to have an insn_is_nop() function that can be used on userspace, and that certainly wants to be taught about these... x86 is such a pain :/

Quoted 2 lines

Is it really only rex_b which prevents NOP becoming a pause, or is it any REX prefix?  I would have thought it was any REX prefix.

SDM opcode table and instruction reference seems consistent with f3 only.

#15 lore raw

Re: [PATCH 3/3] objtool/x86: Fix NOP decode

Quoted 13 lines · Peter Zijlstra
Quoted 12 lines · Andrew Cooper
Quoted 11 lines

I've made that:

	case 0x90:
		if (rex_b) /* XCHG %r8, %rax */
			break;

		if (prefix == 0xf3) /* REP NOP := PAUSE */
			break;

		insn->type = INSN_NOP;
		break;
Quoted 8 lines
Quoted 4 lines

Legacy prefixes can come in any order.  What is F3 66 90 ?

Also, VEX/EVEX/REX2 want excluding too, all of which can encode rex_b differently.

So luckily objtool only really cares about instructions as found in the kernel text. Neither f3 66 90 nor VEX/EVEX/REX2 prefixes are of much concern.

And it looks like objtool ignores VEX instructions earlier in the same function:

int arch_decode_instruction(struct objtool_file *file, const struct section *sec,
unsigned long offset, unsigned int maxlen, struct instruction *insn)

{
       ...

       if (ins.vex_prefix.nbytes)
                return 0;

       ...
}

vex_prefix is set for VEX/EVEX/VEX3/VEX2.

alex.

Quoted 9 lines

But yes.. I happen to have an insn_is_nop() function that can be used on userspace, and that certainly wants to be taught about these... x86 is such a pain :/

Quoted 2 lines

Is it really only rex_b which prevents NOP becoming a pause, or is it any REX prefix?  I would have thought it was any REX prefix.

SDM opcode table and instruction reference seems consistent with f3 only.

author maintainer
#16 lore raw

Re: [PATCH 3/3] objtool/x86: Fix NOP decode

In reply to Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

But yes.. I happen to have an insn_is_nop() function that can be used on userspace, and that certainly wants to be taught about these... x86 is such a pain :/

This is the delta I ended up with for my insn_is_nop() function to support *VEX*/REX2.

I'll post the whole thing later.

arch/x86/include/asm/insn.h +4 -0
@@ -138,6 +138,10 @@ struct insn {
 #define X86_VEX_V(vex)	(((vex) & 0x78) >> 3)	/* VEX3 Byte2, VEX2 Byte1 */
 #define X86_VEX_P(vex)	((vex) & 0x03)		/* VEX3 Byte2, VEX2 Byte1 */
 #define X86_VEX_M_MAX	0x1f			/* VEX3.M Maximum value */
+/* EVEX bit fields */
+#define X86_EVEX_R4(vex) ((vex) & 0x10)		/* EVEX Byte1 */
+#define X86_EVEX_B4(vex) ((vex) & 0x08)		/* EVEX Byte1 */
+#define X86_EVEX_X4(vex) ((vex) & 0x04)		/* EVEX Byte2 */
 /* XOP bit fields */
 #define X86_XOP_R(xop)	((xop) & 0x80)	/* XOP Byte2 */
 #define X86_XOP_X(xop)	((xop) & 0x40)	/* XOP Byte2 */
arch/x86/lib/insn-eval.c +43 -14

97 lines not on this page · raw message

Reviewed-by
#17 lore raw

Re: [PATCH 3/3] objtool/x86: Fix NOP decode

In reply to Peter Zijlstra
Quoted 11 lines · Peter Zijlstra
Quoted 6 lines · Peter Zijlstra
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

tools/objtool/arch/x86/decode.c int arch_decode_instruction(struct objto · line 499

Quoted 4 lines
    	case 0x90:
tools/objtool/arch/x86/decode.c +2 -0
+		if (prefix != 0xf3) /* REP NOP := PAUSE */
+			insn->type = INSN_NOP;
    		break;

What about 0x49 0x90, which is xchg (XCHG r8,rAX) ?

I've made that:

Quoted 11 lines
	case 0x90:
		if (rex_b) /* XCHG %r8, %rax */
			break;

		if (prefix == 0xf3) /* REP NOP := PAUSE */
			break;

		insn->type = INSN_NOP;
		break;

Sounds good.

alex.

merge bot Applied
#18 lore raw

[tip: objtool/core] objtool/x86: Fix NOP decode

In reply to Peter Zijlstra
The following commit has been merged into the objtool/core branch of tip:

The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     044f721ccd33103349eebbb960825584bc6d8e23
Gitweb:        https://git.kernel.org/tip/044f721ccd33103349eebbb960825584bc6d8e23
Author:        Peter Zijlstra <[email protected]>
AuthorDate:    Wed, 24 Sep 2025 15:27:03 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 14 Oct 2025 13:43:11 +02:00

objtool/x86: Fix NOP decode

For x86_64 the kernel consistently uses 2 instructions for all NOPs:

90 - NOP
0f 1f /0 - NOPL

Notably:

- REP NOP is PAUSE, not a NOP instruction.

- 0f {0c...0f} is reserved space,
except for 0f 0d /1, which is PREFETCHW, not a NOP.

- 0f {19,1c...1f} is reserved space,
except for 0f 1f /0, which is NOPL.

---
 tools/objtool/arch/x86/decode.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
tools/objtool/arch/x86/decode.c +11 -4
index ef6e96d..204e2ad 100644
@@ -494,6 +494,12 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 		break;
 
 	case 0x90:
+		if (rex_b) /* XCHG %r8, %rax */
+			break;
+
+		if (prefix == 0xf3) /* REP NOP := PAUSE */
+			break;
+
 		insn->type = INSN_NOP;
 		break;
 
@@ -547,13 +553,14 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 
 		} else if (op2 == 0x0b || op2 == 0xb9) {
 
-			/* ud2 */
+			/* ud2, ud1 */
 			insn->type = INSN_BUG;
 
-		} else if (op2 == 0x0d || op2 == 0x1f) {
+		} else if (op2 == 0x1f) {
 
-			/* nopl/nopw */
-			insn->type = INSN_NOP;
+			/* 0f 1f /0 := NOPL */
+			if (modrm_reg == 0)
+				insn->type = INSN_NOP;
 
 		} else if (op2 == 0x1e) {