[PATCH] [43/50] x86: multi-byte single instruction NOPs

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <jbeulich@...>, <patches@...>, <linux-kernel@...>
Date: Friday, September 21, 2007 - 6:32 pm

From: "Jan Beulich" <jbeulich@novell.com>
Add support for and use the multi-byte NOPs recently documented to be
available on all PentiumPro and later processors.

This patch only applies cleanly on top of the "x86: misc.
constifications" patch sent earlier.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Andi Kleen <ak@suse.de>

 arch/i386/kernel/alternative.c |   23 ++++++++++++++++++++++-
 include/asm-i386/processor.h   |   22 ++++++++++++++++++++++
 include/asm-x86_64/processor.h |   22 ++++++++++++++++++++++
 3 files changed, 66 insertions(+), 1 deletion(-)

Index: linux/arch/i386/kernel/alternative.c
===================================================================
--- linux.orig/arch/i386/kernel/alternative.c
+++ linux/arch/i386/kernel/alternative.c
@@ -115,12 +115,31 @@ static const unsigned char *const k7_nop
 };
 #endif
 
+#ifdef P6_NOP1
+asm("\t.section .rodata, \"a\"\np6nops: "
+	P6_NOP1 P6_NOP2 P6_NOP3 P6_NOP4 P6_NOP5 P6_NOP6
+	P6_NOP7 P6_NOP8);
+extern const unsigned char p6nops[];
+static const unsigned char *const p6_nops[ASM_NOP_MAX+1] = {
+	NULL,
+	p6nops,
+	p6nops + 1,
+	p6nops + 1 + 2,
+	p6nops + 1 + 2 + 3,
+	p6nops + 1 + 2 + 3 + 4,
+	p6nops + 1 + 2 + 3 + 4 + 5,
+	p6nops + 1 + 2 + 3 + 4 + 5 + 6,
+	p6nops + 1 + 2 + 3 + 4 + 5 + 6 + 7,
+};
+#endif
+
 #ifdef CONFIG_X86_64
 
 extern char __vsyscall_0;
 static inline const unsigned char*const * find_nop_table(void)
 {
-	return k8_nops;
+	return boot_cpu_data.x86_vendor != X86_VENDOR_INTEL ||
+	       boot_cpu_data.x86 < 6 ? k8_nops : p6_nops;
 }
 
 #else /* CONFIG_X86_64 */
@@ -131,6 +150,8 @@ static const struct nop {
 } noptypes[] = {
 	{ X86_FEATURE_K8, k8_nops },
 	{ X86_FEATURE_K7, k7_nops },
+	{ X86_FEATURE_P4, p6_nops },
+	{ X86_FEATURE_P3, p6_nops },
 	{ -1, NULL }
 };
 
Index: linux/include/asm-i386/processor.h
===================================================================
--- linux.orig/include/asm-i386/processor.h
+++ linux/include/asm-i386/processor.h
@@ -681,6 +681,17 @@ void ler_enable(void);
 #define K7_NOP7        ".byte 0x8D,0x04,0x05,0,0,0,0\n"
 #define K7_NOP8        K7_NOP7 ASM_NOP1
 
+/* P6 nops */
+/* uses eax dependencies (Intel-recommended choice) */
+#define P6_NOP1	GENERIC_NOP1
+#define P6_NOP2	".byte 0x66,0x90\n"
+#define P6_NOP3	".byte 0x0f,0x1f,0x00\n"
+#define P6_NOP4	".byte 0x0f,0x1f,0x40,0\n"
+#define P6_NOP5	".byte 0x0f,0x1f,0x44,0x00,0\n"
+#define P6_NOP6	".byte 0x66,0x0f,0x1f,0x44,0x00,0\n"
+#define P6_NOP7	".byte 0x0f,0x1f,0x80,0,0,0,0\n"
+#define P6_NOP8	".byte 0x0f,0x1f,0x84,0x00,0,0,0,0\n"
+
 #ifdef CONFIG_MK8
 #define ASM_NOP1 K8_NOP1
 #define ASM_NOP2 K8_NOP2
@@ -699,6 +710,17 @@ void ler_enable(void);
 #define ASM_NOP6 K7_NOP6
 #define ASM_NOP7 K7_NOP7
 #define ASM_NOP8 K7_NOP8
+#elif defined(CONFIG_M686) || defined(CONFIG_MPENTIUMII) || \
+      defined(CONFIG_MPENTIUMIII) || defined(CONFIG_MPENTIUMM) || \
+      defined(CONFIG_MCORE2) || defined(CONFIG_PENTIUM4)
+#define ASM_NOP1 P6_NOP1
+#define ASM_NOP2 P6_NOP2
+#define ASM_NOP3 P6_NOP3
+#define ASM_NOP4 P6_NOP4
+#define ASM_NOP5 P6_NOP5
+#define ASM_NOP6 P6_NOP6
+#define ASM_NOP7 P6_NOP7
+#define ASM_NOP8 P6_NOP8
 #else
 #define ASM_NOP1 GENERIC_NOP1
 #define ASM_NOP2 GENERIC_NOP2
Index: linux/include/asm-x86_64/processor.h
===================================================================
--- linux.orig/include/asm-x86_64/processor.h
+++ linux/include/asm-x86_64/processor.h
@@ -338,6 +338,16 @@ DECLARE_PER_CPU(u32, ler_msr);
 extern int ler_enabled;
 void ler_enable(void);
 
+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2)
+#define ASM_NOP1 P6_NOP1
+#define ASM_NOP2 P6_NOP2
+#define ASM_NOP3 P6_NOP3
+#define ASM_NOP4 P6_NOP4
+#define ASM_NOP5 P6_NOP5
+#define ASM_NOP6 P6_NOP6
+#define ASM_NOP7 P6_NOP7
+#define ASM_NOP8 P6_NOP8
+#else
 #define ASM_NOP1 K8_NOP1
 #define ASM_NOP2 K8_NOP2
 #define ASM_NOP3 K8_NOP3
@@ -346,6 +356,7 @@ void ler_enable(void);
 #define ASM_NOP6 K8_NOP6
 #define ASM_NOP7 K8_NOP7
 #define ASM_NOP8 K8_NOP8
+#endif
 
 /* Opteron nops */
 #define K8_NOP1 ".byte 0x90\n"
@@ -357,6 +368,17 @@ void ler_enable(void);
 #define K8_NOP7	K8_NOP4 K8_NOP3
 #define K8_NOP8	K8_NOP4 K8_NOP4
 
+/* P6 nops */
+/* uses eax dependencies (Intel-recommended choice) */
+#define P6_NOP1	".byte 0x90\n"
+#define P6_NOP2	".byte 0x66,0x90\n"
+#define P6_NOP3	".byte 0x0f,0x1f,0x00\n"
+#define P6_NOP4	".byte 0x0f,0x1f,0x40,0\n"
+#define P6_NOP5	".byte 0x0f,0x1f,0x44,0x00,0\n"
+#define P6_NOP6	".byte 0x66,0x0f,0x1f,0x44,0x00,0\n"
+#define P6_NOP7	".byte 0x0f,0x1f,0x80,0,0,0,0\n"
+#define P6_NOP8	".byte 0x0f,0x1f,0x84,0x00,0,0,0,0\n"
+
 #define ASM_NOP_MAX 8
 
 /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] [0/50] x86 2.6.24 patches review II, Andi Kleen, (Fri Sep 21, 6:31 pm)
[PATCH] [50/50] x86_64: Remove fpu io port resource, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [43/50] x86: multi-byte single instruction NOPs, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [42/50] i386: constify wd_ops, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [40/50] i386: Fix section mismatch, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [36/50] x86: Use raw locks during oopses, Andi Kleen, (Fri Sep 21, 6:32 pm)
Re: [PATCH] [34/50] i386: Fix argument signedness warnings, Jan Engelhardt, (Sat Sep 22, 6:01 am)
[PATCH] [30/50] x86_64: remove some dead code, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [28/50] i386: remove stub early_printk.c, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [22/50] i386: Misc cpuinit annotations, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [21/50] i386: Misc cpuinit annotations, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [17/50] x86_64: remove STR() macros, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [6/50] i386: clean up oops/bug reports, Andi Kleen, (Fri Sep 21, 6:32 pm)
Re: [PATCH] [6/50] i386: clean up oops/bug reports, Chuck Ebbert, (Fri Sep 21, 6:41 pm)
Re: [PATCH] [6/50] i386: clean up oops/bug reports, Jan Engelhardt, (Sat Sep 22, 5:47 am)
[PATCH] [8/50] x86_64: remove x86_cpu_to_log_apicid, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [5/50] i386: change order in Kconfig.cpu, Andi Kleen, (Fri Sep 21, 6:32 pm)
Re: [PATCH] [4/50] x86: add cpu codenames for Kconfig.cpu, Thomas Gleixner, (Sat Sep 22, 1:50 pm)
Re: [PATCH] [4/50] x86: add cpu codenames for Kconfig.cpu, Jan Engelhardt, (Sat Sep 22, 5:46 am)
[PATCH] [3/50] x86_64: remove never used apic_mapped, Andi Kleen, (Fri Sep 21, 6:32 pm)