livepatch: tests: Make them compile under ARM64
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Mon, 19 Sep 2016 20:04:55 +0000 (16:04 -0400)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Wed, 28 Sep 2016 02:06:59 +0000 (22:06 -0400)
We need to two things:
1) Wrap the platform-specific objcopy parameters in defines
   The input and output parameters for $(OBJCOPY) are different
   based on the platforms. As such provide them in the
   OBJCOPY_MAGIC define and use that.

2) The alternative is a bit different (exists only under ARM64
   and x86), while and there are no exceptions under ARM at all.
   We use the LIVEPATCH_FEATURE CPU id feature for ARM similar to
   how it is done on x86.

We are not yet attempting to build them under ARM32 so
that is still ifdefed out.

Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
xen/test/Makefile
xen/test/livepatch/Makefile
xen/test/livepatch/xen_hello_world_func.c

index 8c530409652fd9808b6486ba7b1b629ad2e72dd2..95c175539ee6406a3ebea2e27f53c09e8ea43bd2 100644 (file)
@@ -1,6 +1,6 @@
 .PHONY: tests
 tests:
-ifeq ($(XEN_TARGET_ARCH),x86_64)
+ifneq $(XEN_TARGET_ARCH),arm32)
        $(MAKE) -f $(BASEDIR)/Rules.mk -C livepatch livepatch
 endif
 
index 48ff84300f1f49eb3b22817b270372d30ec835a3..d844ad4424fdfd0a0ab5342e232415e30667b123 100644 (file)
@@ -1,5 +1,12 @@
 include $(XEN_ROOT)/Config.mk
 
+ifeq ($(XEN_TARGET_ARCH),x86_64)
+OBJCOPY_MAGIC := -I binary -O elf64-x86-64 -B i386:x86-64
+endif
+ifeq ($(XEN_TARGET_ARCH),arm64)
+OBJCOPY_MAGIC := -I binary -O elf64-littleaarch64 -B aarch64
+endif
+
 CODE_ADDR=$(shell nm --defined $(1) | grep $(2) | awk '{print "0x"$$1}')
 CODE_SZ=$(shell nm --defined -S $(1) | grep $(2) | awk '{ print "0x"$$2}')
 
@@ -54,7 +61,7 @@ $(LIVEPATCH): xen_hello_world_func.o xen_hello_world.o note.o
 .PHONY: note.o
 note.o:
        $(OBJCOPY) -O binary --only-section=.note.gnu.build-id $(BASEDIR)/xen-syms $@.bin
-       $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 \
+       $(OBJCOPY) $(OBJCOPY_MAGIC) \
                   --rename-section=.data=.livepatch.depends,alloc,load,readonly,data,contents -S $@.bin $@
        rm -f $@.bin
 
@@ -65,7 +72,7 @@ note.o:
 .PHONY: hello_world_note.o
 hello_world_note.o: $(LIVEPATCH)
        $(OBJCOPY) -O binary --only-section=.note.gnu.build-id $(LIVEPATCH) $@.bin
-       $(OBJCOPY)  -I binary -O elf64-x86-64 -B i386:x86-64 \
+       $(OBJCOPY) $(OBJCOPY_MAGIC) \
                   --rename-section=.data=.livepatch.depends,alloc,load,readonly,data,contents -S $@.bin $@
        rm -f $@.bin
 
index 0321f3ece2edce8922a9378e5d74af142cf4fda4..1518f71e3ee8600596d9ffaaf9b64b770581357b 100644 (file)
@@ -7,14 +7,17 @@
 
 #include <asm/alternative.h>
 #include <asm/livepatch.h>
+#ifdef CONFIG_X86
 #include <asm/nops.h>
 #include <asm/uaccess.h>
 
 static unsigned long *non_canonical_addr = (unsigned long *)0xdead000000000000ULL;
+#endif
 
 /* Our replacement function for xen_extra_version. */
 const char *xen_hello_world(void)
 {
+#ifdef CONFIG_X86
     unsigned long tmp;
     int rc;
 
@@ -25,6 +28,10 @@ const char *xen_hello_world(void)
      */
     rc = __get_user(tmp, non_canonical_addr);
     BUG_ON(rc != -EFAULT);
+#endif
+#if defined(CONFIG_ARM) && defined(CONFIG_HAS_ALTERNATIVE)
+    asm(ALTERNATIVE("nop", "nop", LIVEPATCH_FEATURE));
+#endif
 
     return "Hello World";
 }