Skip to content

Commit 301cddc

Browse files
Peter Zijlstrasuryasaimadhu
authored andcommitted
objtool/x86: Use asm/nops.h
Since the kernel will rely on a single canonical set of NOPs, make sure objtool uses the exact same ones. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent a89dfde commit 301cddc

File tree

3 files changed

+90
-5
lines changed

3 files changed

+90
-5
lines changed

tools/arch/x86/include/asm/nops.h

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _ASM_X86_NOPS_H
3+
#define _ASM_X86_NOPS_H
4+
5+
/*
6+
* Define nops for use with alternative() and for tracing.
7+
*/
8+
9+
#ifndef CONFIG_64BIT
10+
11+
/*
12+
* Generic 32bit nops from GAS:
13+
*
14+
* 1: nop
15+
* 2: movl %esi,%esi
16+
* 3: leal 0x0(%esi),%esi
17+
* 4: leal 0x0(%esi,%eiz,1),%esi
18+
* 5: leal %ds:0x0(%esi,%eiz,1),%esi
19+
* 6: leal 0x0(%esi),%esi
20+
* 7: leal 0x0(%esi,%eiz,1),%esi
21+
* 8: leal %ds:0x0(%esi,%eiz,1),%esi
22+
*
23+
* Except 5 and 8, which are DS prefixed 4 and 7 resp, where GAS would emit 2
24+
* nop instructions.
25+
*/
26+
#define BYTES_NOP1 0x90
27+
#define BYTES_NOP2 0x89,0xf6
28+
#define BYTES_NOP3 0x8d,0x76,0x00
29+
#define BYTES_NOP4 0x8d,0x74,0x26,0x00
30+
#define BYTES_NOP5 0x3e,BYTES_NOP4
31+
#define BYTES_NOP6 0x8d,0xb6,0x00,0x00,0x00,0x00
32+
#define BYTES_NOP7 0x8d,0xb4,0x26,0x00,0x00,0x00,0x00
33+
#define BYTES_NOP8 0x3e,BYTES_NOP7
34+
35+
#else
36+
37+
/*
38+
* Generic 64bit nops from GAS:
39+
*
40+
* 1: nop
41+
* 2: osp nop
42+
* 3: nopl (%eax)
43+
* 4: nopl 0x00(%eax)
44+
* 5: nopl 0x00(%eax,%eax,1)
45+
* 6: osp nopl 0x00(%eax,%eax,1)
46+
* 7: nopl 0x00000000(%eax)
47+
* 8: nopl 0x00000000(%eax,%eax,1)
48+
*/
49+
#define BYTES_NOP1 0x90
50+
#define BYTES_NOP2 0x66,BYTES_NOP1
51+
#define BYTES_NOP3 0x0f,0x1f,0x00
52+
#define BYTES_NOP4 0x0f,0x1f,0x40,0x00
53+
#define BYTES_NOP5 0x0f,0x1f,0x44,0x00,0x00
54+
#define BYTES_NOP6 0x66,BYTES_NOP5
55+
#define BYTES_NOP7 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00
56+
#define BYTES_NOP8 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00
57+
58+
#endif /* CONFIG_64BIT */
59+
60+
#ifdef __ASSEMBLY__
61+
#define _ASM_MK_NOP(x) .byte x
62+
#else
63+
#define _ASM_MK_NOP(x) ".byte " __stringify(x) "\n"
64+
#endif
65+
66+
#define ASM_NOP1 _ASM_MK_NOP(BYTES_NOP1)
67+
#define ASM_NOP2 _ASM_MK_NOP(BYTES_NOP2)
68+
#define ASM_NOP3 _ASM_MK_NOP(BYTES_NOP3)
69+
#define ASM_NOP4 _ASM_MK_NOP(BYTES_NOP4)
70+
#define ASM_NOP5 _ASM_MK_NOP(BYTES_NOP5)
71+
#define ASM_NOP6 _ASM_MK_NOP(BYTES_NOP6)
72+
#define ASM_NOP7 _ASM_MK_NOP(BYTES_NOP7)
73+
#define ASM_NOP8 _ASM_MK_NOP(BYTES_NOP8)
74+
75+
#define ASM_NOP_MAX 8
76+
77+
#ifndef __ASSEMBLY__
78+
extern const unsigned char * const x86_nops[];
79+
#endif
80+
81+
#endif /* _ASM_X86_NOPS_H */

tools/objtool/arch/x86/decode.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include "../../../arch/x86/lib/inat.c"
1212
#include "../../../arch/x86/lib/insn.c"
1313

14+
#define CONFIG_64BIT 1
15+
#include <asm/nops.h>
16+
1417
#include <asm/orc_types.h>
1518
#include <objtool/check.h>
1619
#include <objtool/elf.h>
@@ -596,11 +599,11 @@ void arch_initial_func_cfi_state(struct cfi_init_state *state)
596599
const char *arch_nop_insn(int len)
597600
{
598601
static const char nops[5][5] = {
599-
/* 1 */ { 0x90 },
600-
/* 2 */ { 0x66, 0x90 },
601-
/* 3 */ { 0x0f, 0x1f, 0x00 },
602-
/* 4 */ { 0x0f, 0x1f, 0x40, 0x00 },
603-
/* 5 */ { 0x0f, 0x1f, 0x44, 0x00, 0x00 },
602+
{ BYTES_NOP1 },
603+
{ BYTES_NOP2 },
604+
{ BYTES_NOP3 },
605+
{ BYTES_NOP4 },
606+
{ BYTES_NOP5 },
604607
};
605608

606609
if (len < 1 || len > 5) {

tools/objtool/sync-check.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ FILES="include/linux/objtool.h"
1010

1111
if [ "$SRCARCH" = "x86" ]; then
1212
FILES="$FILES
13+
arch/x86/include/asm/nops.h
1314
arch/x86/include/asm/inat_types.h
1415
arch/x86/include/asm/orc_types.h
1516
arch/x86/include/asm/emulate_prefix.h

0 commit comments

Comments
 (0)