[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 7/7] x86/build: Use new .nop directive when available



Newer versions of binutils are capable of emitting an exact number bytes worth
of optimised nops.  Use this in preference to .skip when available.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
CC: Wei Liu <wei.liu2@xxxxxxxxxx>

RFC until support is actually committed to binutils mainline.
---
 xen/arch/x86/Rules.mk                 |  1 +
 xen/include/asm-x86/alternative-asm.h | 16 +++++++++++++---
 xen/include/asm-x86/alternative.h     | 17 ++++++++++++-----
 3 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/xen/arch/x86/Rules.mk b/xen/arch/x86/Rules.mk
index 56b2ea8..c3b726c 100644
--- a/xen/arch/x86/Rules.mk
+++ b/xen/arch/x86/Rules.mk
@@ -20,6 +20,7 @@ $(call as-insn-check,CFLAGS,CC,"invept 
(%rax)$$(comma)%rax",-DHAVE_GAS_EPT)
 $(call as-insn-check,CFLAGS,CC,"rdrand %eax",-DHAVE_GAS_RDRAND)
 $(call as-insn-check,CFLAGS,CC,"rdfsbase %rax",-DHAVE_GAS_FSGSBASE)
 $(call as-insn-check,CFLAGS,CC,"rdseed %eax",-DHAVE_GAS_RDSEED)
+$(call as-insn-check,CFLAGS,CC,".nop 0$$(comma)9",-DHAVE_GAS_LONG_NOPS)
 $(call as-insn-check,CFLAGS,CC,".equ \"x\"$$(comma)1", \
                      -U__OBJECT_LABEL__ -DHAVE_GAS_QUOTED_SYM \
                      '-D__OBJECT_LABEL__=$(subst $(BASEDIR)/,,$(CURDIR))/$$@')
diff --git a/xen/include/asm-x86/alternative-asm.h 
b/xen/include/asm-x86/alternative-asm.h
index f7e37cb..a4893e7 100644
--- a/xen/include/asm-x86/alternative-asm.h
+++ b/xen/include/asm-x86/alternative-asm.h
@@ -1,6 +1,8 @@
 #ifndef _ASM_X86_ALTERNATIVE_ASM_H_
 #define _ASM_X86_ALTERNATIVE_ASM_H_
 
+#include <asm/nops.h>
+
 #ifdef __ASSEMBLY__
 
 /*
@@ -18,6 +20,14 @@
     .byte \pad_len
 .endm
 
+.macro mknops nr_bytes
+#ifdef HAVE_GAS_LONG_NOPS
+    .nop \nr_bytes, ASM_NOP_MAX
+#else
+    .skip \nr_bytes, 0x90
+#endif
+.endm
+
 #define orig_len               (.L\@_orig_e       -     .L\@_orig_s)
 #define pad_len                (.L\@_orig_p       -     .L\@_orig_e)
 #define total_len              (.L\@_orig_p       -     .L\@_orig_s)
@@ -29,7 +39,7 @@
 .L\@_orig_s:
     \oldinstr
 .L\@_orig_e:
-     .skip (-((repl_len(1) - orig_len) > 0) * (repl_len(1) - orig_len)), 0x90
+     mknops (-((repl_len(1) - orig_len) > 0) * (repl_len(1) - orig_len))
 .L\@_orig_p:
 
     .pushsection .altinstructions, "a", @progbits
@@ -56,8 +66,8 @@
 .L\@_orig_s:
     \oldinstr
 .L\@_orig_e:
-    .skip (-((gas_max(repl_len(1), repl_len(2)) - orig_len) > 0) * \
-             (gas_max(repl_len(1), repl_len(2)) - orig_len)), 0x90
+    mknops (-((gas_max(repl_len(1), repl_len(2)) - orig_len) > 0) * \
+              (gas_max(repl_len(1), repl_len(2)) - orig_len))
 .L\@_orig_p:
 
     .pushsection .altinstructions, "a", @progbits
diff --git a/xen/include/asm-x86/alternative.h 
b/xen/include/asm-x86/alternative.h
index 20dea22..076d700 100644
--- a/xen/include/asm-x86/alternative.h
+++ b/xen/include/asm-x86/alternative.h
@@ -2,7 +2,6 @@
 #define __X86_ALTERNATIVE_H__
 
 #include <asm/alternative-asm.h>
-#include <asm/nops.h>
 
 #ifndef __ASSEMBLY__
 #include <xen/stringify.h>
@@ -27,6 +26,14 @@ extern void apply_alternatives(const struct alt_instr *start,
                                const struct alt_instr *end);
 extern void alternative_instructions(void);
 
+asm ( ".macro mknops nr_bytes\n\t"
+#ifdef HAVE_GAS_LONG_NOPS
+      ".nop \\nr_bytes, " __stringify(ASM_NOP_MAX) "\n\t"
+#else
+      ".skip \\nr_bytes, 0x90\n\t"
+#endif
+      ".endm\n\t" );
+
 #define repl_s(num)             ".L%=_repl_s"#num
 #define repl_e(num)             ".L%=_repl_e"#num
 
@@ -39,8 +46,8 @@ extern void alternative_instructions(void);
 
 #define OLDINSTR_1(oldinstr, n1)                              \
     ".L%=_orig_s:\n\t" oldinstr "\n .L%=_orig_e:\n\t"         \
-    ".skip (-(("alt_repl_len(n1)"-"alt_orig_len") > 0) * "    \
-             "("alt_repl_len(n1)"-"alt_orig_len")), 0x90\n\t" \
+    "mknops (-(("alt_repl_len(n1)"-"alt_orig_len") > 0) * "   \
+              "("alt_repl_len(n1)"-"alt_orig_len"))\n\t"      \
     ".L%=_orig_p:\n\t"
 
 #define ALT_PADDING_LEN(n1, n2) \
@@ -48,8 +55,8 @@ extern void alternative_instructions(void);
 
 #define OLDINSTR_2(oldinstr, n1, n2)                          \
     ".L%=_orig_s:\n\t" oldinstr "\n .L%=_orig_e:\n\t"         \
-    ".skip (-(("ALT_PADDING_LEN(n1, n2)") > 0) * "            \
-             "("ALT_PADDING_LEN(n1, n2)")), 0x90\n\t"         \
+    "mknops (-(("ALT_PADDING_LEN(n1, n2)") > 0) * "           \
+              "("ALT_PADDING_LEN(n1, n2)"))\n\t"              \
     ".L%=_orig_p:\n\t"
 
 #define ALTINSTR_ENTRY(feature, num)                                    \
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.