|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] x86/alternatives: allow using assembler macros in favor of C ones
commit f8506196920ca66725a9f0d9d05c2ebad3e15376
Author: Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Thu Aug 30 11:03:47 2018 +0200
Commit: Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Thu Aug 30 11:03:47 2018 +0200
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>
Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
.gitignore | 1 +
xen/arch/x86/Makefile | 16 +++++++++++++++-
xen/arch/x86/asm-macros.c | 1 +
xen/include/asm-x86/alternative.h | 13 +++----------
4 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/.gitignore b/.gitignore
index 1625a8f0e7..a7cc3f36ce 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 9b9b63ac63..261c598ff3 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -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
index 0000000000..b963d56a56
--- /dev/null
+++ b/xen/arch/x86/asm-macros.c
@@ -0,0 +1 @@
+#include <asm/alternative-asm.h>
diff --git a/xen/include/asm-x86/alternative.h
b/xen/include/asm-x86/alternative.h
index 66fe791818..d96411f0f3 100644
--- 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__
+#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)"
--
generated by git-patchbot for /home/xen/git/xen.git#master
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |