]> xenbits.xensource.com Git - people/dwmw2/xen.git/commitdiff
x86/alternatives: allow using assembler macros in favor of C ones
authorJan Beulich <jbeulich@suse.com>
Thu, 30 Aug 2018 09:03:47 +0000 (11:03 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 30 Aug 2018 09:03:47 +0000 (11:03 +0200)
As was validly pointed out as motivation for similar Linux side changes
(https://lkml.org/lkml/2018/6/22/677), using long sequences of
directives and auxiliary instructions, like is commonly the case when
setting up an alternative patch site, gcc can be mislead into believing
an asm() to be more heavy weight than it really is. By presenting it
with an assembler macro invocation instead, this can be avoided.

Initially I wanted to outright change the C macros ALTERNATIVE() and
ALTERNATIVE_2() to invoke the respective assembler ones, but doing so
would require quite a bit of cleanup of some use sites, because of the
exra necessary quoting combined with the need that each assembler macro
argument must consist of just a single string literal. We can consider
working towards that subsequently.

For now, set the stage of using the assembler macros here by providing a
new generated header, being the slightly massaged pre-processor output
of (for now just) alternative-asm.h. The massaging is primarily to be
able to properly track the build dependency: For this, we need the C
compiler to see the inclusion, which means we shouldn't directly use an
asm(". include ...") directive.

The dependency added to asm-offsets.s is not a true one; it's just the
easiest approach I could think of to make sure the new header gets
generated early on, without having to fiddle with xen/Makefile (and
introducing some x86-specific construct there).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
.gitignore
xen/arch/x86/Makefile
xen/arch/x86/asm-macros.c [new file with mode: 0644]
xen/include/asm-x86/alternative.h

index 1625a8f0e7f4a38315fd9455dd52f587dda69305..a7cc3f36ceacd9b2ad3028824779714bd8a6433f 100644 (file)
@@ -293,6 +293,7 @@ xen/.config.old
 xen/System.map
 xen/arch/arm/asm-offsets.s
 xen/arch/arm/xen.lds
+xen/arch/x86/asm-macros.i
 xen/arch/x86/asm-offsets.s
 xen/arch/x86/boot/mkelf32
 xen/arch/x86/xen.lds
index 9b9b63ac63bb97b9491399e9854331b49ab7ddc1..261c598ff3bf3b0ef3cd18a1ee79905c20694d8f 100644 (file)
@@ -215,9 +215,22 @@ $(TARGET).efi: prelink-efi.o $(note_file) efi.lds efi/relocs-dummy.o $(BASEDIR)/
 efi/boot.init.o efi/runtime.o efi/compat.o efi/buildid.o: $(BASEDIR)/arch/x86/efi/built_in.o
 efi/boot.init.o efi/runtime.o efi/compat.o efi/buildid.o: ;
 
-asm-offsets.s: $(TARGET_SUBARCH)/asm-offsets.c
+asm-offsets.s: $(TARGET_SUBARCH)/asm-offsets.c $(BASEDIR)/include/asm-x86/asm-macros.h
        $(CC) $(filter-out -Wa$(comma)% -flto,$(CFLAGS)) -S -o $@ $<
 
+asm-macros.i: CFLAGS += -D__ASSEMBLY__ -P
+
+$(BASEDIR)/include/asm-x86/asm-macros.h: asm-macros.i Makefile
+       echo '#if 0' >$@.new
+       echo '.if 0' >>$@.new
+       echo '#endif' >>$@.new
+       echo 'asm ( ".include \"$@\"" );' >>$@.new
+       echo '#if 0' >>$@.new
+       echo '.endif' >>$@.new
+       cat $< >>$@.new
+       echo '#endif' >>$@.new
+       $(call move-if-changed,$@.new,$@)
+
 xen.lds: xen.lds.S
        $(CC) -P -E -Ui386 $(filter-out -Wa$(comma)%,$(AFLAGS)) -o $@ $<
        sed -e 's/xen\.lds\.o:/xen\.lds:/g' <.xen.lds.d >.xen.lds.d.new
@@ -237,6 +250,7 @@ efi/mkreloc: efi/mkreloc.c
 .PHONY: clean
 clean::
        rm -f asm-offsets.s *.lds boot/*.o boot/*~ boot/core boot/mkelf32
+       rm -f asm-macros.i $(BASEDIR)/include/asm-x86/asm-macros.*
        rm -f $(BASEDIR)/.xen-syms.[0-9]* boot/.*.d
        rm -f $(BASEDIR)/.xen.efi.[0-9]* efi/*.efi efi/mkreloc
        rm -f boot/cmdline.S boot/reloc.S boot/*.lnk boot/*.bin
diff --git a/xen/arch/x86/asm-macros.c b/xen/arch/x86/asm-macros.c
new file mode 100644 (file)
index 0000000..b963d56
--- /dev/null
@@ -0,0 +1 @@
+#include <asm/alternative-asm.h>
index 66fe791818589982adce588eb95374ef04d315fc..d96411f0f38e98989b2897d8b01953fa4d18482f 100644 (file)
@@ -1,11 +1,12 @@
 #ifndef __X86_ALTERNATIVE_H__
 #define __X86_ALTERNATIVE_H__
 
+#ifdef __ASSEMBLY__
 #include <asm/alternative-asm.h>
-
-#ifndef __ASSEMBLY__
+#else
 #include <xen/stringify.h>
 #include <xen/types.h>
+#include <asm/asm-macros.h>
 
 struct __packed alt_instr {
     int32_t  orig_offset;   /* original instruction */
@@ -26,14 +27,6 @@ extern void add_nops(void *insns, unsigned int len);
 extern void apply_alternatives(struct alt_instr *start, struct alt_instr *end);
 extern void alternative_instructions(void);
 
-asm ( ".macro mknops nr_bytes\n\t"
-#ifdef HAVE_AS_NOPS_DIRECTIVE
-      ".nops \\nr_bytes, " __stringify(ASM_NOP_MAX) "\n\t"
-#else
-      ".skip \\nr_bytes, 0x90\n\t"
-#endif
-      ".endm\n\t" );
-
 #define alt_orig_len       "(.LXEN%=_orig_e - .LXEN%=_orig_s)"
 #define alt_pad_len        "(.LXEN%=_orig_p - .LXEN%=_orig_e)"
 #define alt_total_len      "(.LXEN%=_orig_p - .LXEN%=_orig_s)"