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

[Xen-devel] [PATCH 08/16] x86/alternatives: allow using assembler macros in favor of C ones

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@xxxxxxxx>

--- a/.gitignore
+++ b/.gitignore
@@ -293,6 +293,7 @@ xen/.config.old
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -209,9 +209,22 @@ $(TARGET).efi: prelink-efi.o $(note_file
 efi/boot.init.o efi/runtime.o efi/compat.o efi/buildid.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 
        $(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
@@ -231,6 +244,7 @@ efi/mkreloc: efi/mkreloc.c
 .PHONY: 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/disabled efi/mkreloc
        rm -f boot/cmdline.S boot/reloc.S boot/*.lnk boot/*.bin
--- /dev/null
+++ b/xen/arch/x86/asm-macros.c
@@ -0,0 +1 @@
+#include <asm/alternative-asm.h>
--- a/xen/include/asm-x86/alternative.h
+++ b/xen/include/asm-x86/alternative.h
@@ -1,11 +1,12 @@
 #ifndef __X86_ALTERNATIVE_H__
 #define __X86_ALTERNATIVE_H__
+#ifdef __ASSEMBLY__
 #include <asm/alternative-asm.h>
-#ifndef __ASSEMBLY__
 #include <xen/stringify.h>
 #include <xen/types.h>
+#include <asm/asm-macros.h>
 struct __packed alt_instr {
     int32_t  orig_offset;   /* original instruction */

Xen-devel mailing list



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