linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "tip-bot2 for Peter Zijlstra" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Borislav Petkov <bp@suse.de>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: x86/cpu] objtool/x86: Use asm/nops.h
Date: Mon, 15 Mar 2021 18:00:12 -0000	[thread overview]
Message-ID: <161583121208.398.8769751653293178203.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20210312115749.136357911@infradead.org>

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

Commit-ID:     301cddc21a157a3072d789a3097857202e550a24
Gitweb:        https://git.kernel.org/tip/301cddc21a157a3072d789a3097857202e550a24
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Fri, 12 Mar 2021 12:32:55 +01:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Mon, 15 Mar 2021 16:37:37 +01:00

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) <peterz@infradead.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210312115749.136357911@infradead.org
---
 tools/arch/x86/include/asm/nops.h | 81 ++++++++++++++++++++++++++++++-
 tools/objtool/arch/x86/decode.c   | 13 +++--
 tools/objtool/sync-check.sh       |  1 +-
 3 files changed, 90 insertions(+), 5 deletions(-)
 create mode 100644 tools/arch/x86/include/asm/nops.h

diff --git a/tools/arch/x86/include/asm/nops.h b/tools/arch/x86/include/asm/nops.h
new file mode 100644
index 0000000..c1e5e81
--- /dev/null
+++ b/tools/arch/x86/include/asm/nops.h
@@ -0,0 +1,81 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_NOPS_H
+#define _ASM_X86_NOPS_H
+
+/*
+ * Define nops for use with alternative() and for tracing.
+ */
+
+#ifndef CONFIG_64BIT
+
+/*
+ * Generic 32bit nops from GAS:
+ *
+ * 1: nop
+ * 2: movl %esi,%esi
+ * 3: leal 0x0(%esi),%esi
+ * 4: leal 0x0(%esi,%eiz,1),%esi
+ * 5: leal %ds:0x0(%esi,%eiz,1),%esi
+ * 6: leal 0x0(%esi),%esi
+ * 7: leal 0x0(%esi,%eiz,1),%esi
+ * 8: leal %ds:0x0(%esi,%eiz,1),%esi
+ *
+ * Except 5 and 8, which are DS prefixed 4 and 7 resp, where GAS would emit 2
+ * nop instructions.
+ */
+#define BYTES_NOP1	0x90
+#define BYTES_NOP2	0x89,0xf6
+#define BYTES_NOP3	0x8d,0x76,0x00
+#define BYTES_NOP4	0x8d,0x74,0x26,0x00
+#define BYTES_NOP5	0x3e,BYTES_NOP4
+#define BYTES_NOP6	0x8d,0xb6,0x00,0x00,0x00,0x00
+#define BYTES_NOP7	0x8d,0xb4,0x26,0x00,0x00,0x00,0x00
+#define BYTES_NOP8	0x3e,BYTES_NOP7
+
+#else
+
+/*
+ * 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
+
+#endif /* CONFIG_64BIT */
+
+#ifdef __ASSEMBLY__
+#define _ASM_MK_NOP(x) .byte x
+#else
+#define _ASM_MK_NOP(x) ".byte " __stringify(x) "\n"
+#endif
+
+#define ASM_NOP1 _ASM_MK_NOP(BYTES_NOP1)
+#define ASM_NOP2 _ASM_MK_NOP(BYTES_NOP2)
+#define ASM_NOP3 _ASM_MK_NOP(BYTES_NOP3)
+#define ASM_NOP4 _ASM_MK_NOP(BYTES_NOP4)
+#define ASM_NOP5 _ASM_MK_NOP(BYTES_NOP5)
+#define ASM_NOP6 _ASM_MK_NOP(BYTES_NOP6)
+#define ASM_NOP7 _ASM_MK_NOP(BYTES_NOP7)
+#define ASM_NOP8 _ASM_MK_NOP(BYTES_NOP8)
+
+#define ASM_NOP_MAX 8
+
+#ifndef __ASSEMBLY__
+extern const unsigned char * const x86_nops[];
+#endif
+
+#endif /* _ASM_X86_NOPS_H */
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index 549813c..c117bfc 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -11,6 +11,9 @@
 #include "../../../arch/x86/lib/inat.c"
 #include "../../../arch/x86/lib/insn.c"
 
+#define CONFIG_64BIT 1
+#include <asm/nops.h>
+
 #include <asm/orc_types.h>
 #include <objtool/check.h>
 #include <objtool/elf.h>
@@ -596,11 +599,11 @@ void arch_initial_func_cfi_state(struct cfi_init_state *state)
 const char *arch_nop_insn(int len)
 {
 	static const char nops[5][5] = {
-		/* 1 */ { 0x90 },
-		/* 2 */ { 0x66, 0x90 },
-		/* 3 */ { 0x0f, 0x1f, 0x00 },
-		/* 4 */ { 0x0f, 0x1f, 0x40, 0x00 },
-		/* 5 */ { 0x0f, 0x1f, 0x44, 0x00, 0x00 },
+		{ BYTES_NOP1 },
+		{ BYTES_NOP2 },
+		{ BYTES_NOP3 },
+		{ BYTES_NOP4 },
+		{ BYTES_NOP5 },
 	};
 
 	if (len < 1 || len > 5) {
diff --git a/tools/objtool/sync-check.sh b/tools/objtool/sync-check.sh
index 606a4b5..d232686 100755
--- a/tools/objtool/sync-check.sh
+++ b/tools/objtool/sync-check.sh
@@ -10,6 +10,7 @@ FILES="include/linux/objtool.h"
 
 if [ "$SRCARCH" = "x86" ]; then
 FILES="$FILES
+arch/x86/include/asm/nops.h
 arch/x86/include/asm/inat_types.h
 arch/x86/include/asm/orc_types.h
 arch/x86/include/asm/emulate_prefix.h

  reply	other threads:[~2021-03-15 18:00 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-12 11:32 [PATCH 0/2] x86: Remove ideal_nops[] Peter Zijlstra
2021-03-12 11:32 ` [PATCH 1/2] x86: Remove dynamic NOP selection Peter Zijlstra
2021-03-12 12:09   ` Peter Zijlstra
2021-03-12 20:36     ` Linus Torvalds
2021-03-15 18:00   ` [tip: x86/cpu] " tip-bot2 for Peter Zijlstra
2024-01-20  6:58   ` [PATCH 1/2] " Thorsten Glaser
2024-01-20  8:22     ` H. Peter Anvin
2024-01-20 16:53       ` Thorsten Glaser
2024-01-21 23:21         ` H. Peter Anvin
2024-01-21 23:58           ` Thorsten Glaser
2024-01-22  0:15             ` H. Peter Anvin
2024-01-22  0:56               ` Steven Rostedt
2024-01-22  1:17                 ` Thorsten Glaser
2024-01-22  2:04                   ` H. Peter Anvin
2024-01-22  2:15                 ` H. Peter Anvin
2024-01-22  2:22                   ` Steven Rostedt
2024-01-22  2:31                     ` H. Peter Anvin
2024-01-20 17:00       ` Linus Torvalds
2024-01-20 17:19         ` Thorsten Glaser
2024-01-20 18:21           ` disassemblers (was Re: [PATCH 1/2] x86: Remove dynamic NOP selection) Thorsten Glaser
2024-01-21 22:36         ` [PATCH 1/2] x86: Remove dynamic NOP selection David Laight
2024-01-21 23:10           ` H. Peter Anvin
2021-03-12 11:32 ` [PATCH 2/2] objtool,x86: Use asm/nops.h Peter Zijlstra
2021-03-15 18:00   ` tip-bot2 for Peter Zijlstra [this message]
2021-03-12 14:29 ` [PATCH 0/2] x86: Remove ideal_nops[] Sedat Dilek
2021-03-12 14:47   ` Borislav Petkov
2021-03-12 17:26     ` Steven Rostedt
2021-03-12 17:35       ` Sedat Dilek
2021-03-12 17:46         ` Borislav Petkov
2021-03-12 17:47         ` Steven Rostedt
2021-03-12 18:13           ` Sedat Dilek
2021-03-12 19:03             ` Sedat Dilek
2021-03-12 20:59 ` Borislav Petkov
2021-03-13  5:26   ` Sedat Dilek
2021-03-13  8:49     ` Borislav Petkov
2021-03-13 11:23       ` Borislav Petkov
2021-03-13 12:10       ` Sedat Dilek
2021-03-13 12:15         ` Borislav Petkov
2021-03-13 12:38           ` Sedat Dilek
2021-03-13 12:49             ` Borislav Petkov
2021-03-13 12:58               ` Sedat Dilek
2021-03-13 13:29                 ` Borislav Petkov
2021-03-13 13:47                   ` Sedat Dilek
2021-03-15 17:04                     ` Sedat Dilek
2021-03-15 17:15                       ` Borislav Petkov
2021-03-15 17:19                         ` Sedat Dilek
2021-03-15 17:23                           ` Borislav Petkov
2021-03-15 18:10                       ` Peter Zijlstra
2021-03-15 18:23                         ` Sedat Dilek
2021-03-15 22:14                           ` Peter Zijlstra
2021-03-16  5:56                             ` Sedat Dilek
2021-03-27 12:08                               ` Sedat Dilek
2021-03-27 20:02                                 ` Linus Torvalds
2021-03-30 12:31                                   ` Sedat Dilek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=161583121208.398.8769751653293178203.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=bp@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).