From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: xen-devel@lists.xenproject.org, konrad@kernel.org,
ross.lagerwall@citrix.com, mpohlack@amazon.de,
sasha.levin@oracle.com, andrew.cooper3@citrix.com
Cc: Keir Fraser <keir@xen.org>, Julien Grall <julien.grall@arm.com>,
Stefano Stabellini <stefano.stabellini@citrix.com>,
Jan Beulich <jbeulich@suse.com>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [PATCH v6 11/24] x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version'.
Date: Wed, 6 Apr 2016 23:49:30 -0400 [thread overview]
Message-ID: <1460000983-28170-12-git-send-email-konrad.wilk@oracle.com> (raw)
In-Reply-To: <1460000983-28170-1-git-send-email-konrad.wilk@oracle.com>
This change demonstrates how to generate an xSplice ELF payload.
The idea here is that we want to patch in the hypervisor
the 'xen_version_extra' function with an function that will
return 'Hello World'. The 'xl info | grep extraversion'
will reflect the new value after the patching.
To generate this ELF payload file we need:
- C code of the new code (xen_hello_world_func.c).
- C code generating the .xsplice.funcs structure
(xen_hello_world.c)
- The address of the old code (xen_extra_version). We
retrieve it by using 'nm --defined' on xen-syms.
- The size of the new and old code for which we use
nm --defined -S on our code and xen-syms respectively.
There are two C files and one header files generated
during build. One could make this one C file if the
size of the newly patched function size was known in
advance (or an random value was choosen).
There is also a strict order of compiling:
1) xen_hello_world_func.c
2) config.h - extract the size of the new function,
the old function and the old function address.
3) xen_hello_world.c - which contains the .xsplice.funcs
structure.
4) Link the object files in an xen_hello_world.xsplice file.
The use-case is simple:
$xen-xsplice load /usr/lib/debug/xen_hello_world.xsplice
$xen-xsplice list
ID | status
----------------------------------------+------------
xen_hello_world APPLIED
$xl info | grep extra
xen_extra : Hello World
$xen-xsplice revert xen_hello_world
Performing revert: completed
$xen-xsplice unload xen_hello_world
Performing unload: completed
$xl info | grep extra
xen_extra : -unstable
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
Cc: Stefano Stabellini <stefano.stabellini@citrix.com>
Cc: Julien Grall <julien.grall@arm.com>
Cc: Keir Fraser <keir@xen.org>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
v2: Do it using hypervisor Makefiles
v3: Remove the stale linker file.
Add Copyright and local definition block
s/name/xen_hello_world_name/
v6: Remove the 'install', and 'uninstall' destinations.
Remove xen/config.h from files.
---
---
.gitignore | 2 ++
docs/misc/xsplice.markdown | 35 +++++++++++++++++++++++++
xen/Makefile | 8 ++++--
xen/arch/arm/Makefile | 2 ++
xen/arch/x86/Makefile | 4 +++
xen/arch/x86/test/Makefile | 44 ++++++++++++++++++++++++++++++++
xen/arch/x86/test/xen_hello_world.c | 30 ++++++++++++++++++++++
xen/arch/x86/test/xen_hello_world_func.c | 22 ++++++++++++++++
8 files changed, 145 insertions(+), 2 deletions(-)
create mode 100644 xen/arch/x86/test/Makefile
create mode 100644 xen/arch/x86/test/xen_hello_world.c
create mode 100644 xen/arch/x86/test/xen_hello_world_func.c
diff --git a/.gitignore b/.gitignore
index b9c9550..8dc76b5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -245,6 +245,8 @@ xen/arch/x86/efi.lds
xen/arch/x86/efi/check.efi
xen/arch/x86/efi/disabled
xen/arch/x86/efi/mkreloc
+xen/arch/x86/test/config.h
+xen/arch/x86/test/xen_hello_world.xsplice
xen/arch/*/efi/boot.c
xen/arch/*/efi/compat.c
xen/arch/*/efi/efi.h
diff --git a/docs/misc/xsplice.markdown b/docs/misc/xsplice.markdown
index d4e7d75..8d2d413 100644
--- a/docs/misc/xsplice.markdown
+++ b/docs/misc/xsplice.markdown
@@ -330,6 +330,41 @@ When reverting a patch, the hypervisor iterates over each `xsplice_patch_func`
and the core code copies the data from the undo buffer (private internal copy)
to `old_addr`.
+### Example of .xsplice.funcs
+
+A simple example of what a payload file can be:
+
+<pre>
+/* MUST be in sync with hypervisor. */
+struct xsplice_patch_func {
+ const char *name;
+ uint64_t new_addr;
+ uint64_t old_addr;
+ uint32_t new_size;
+ uint32_t old_size;
+ uint8_t pad[32];
+};
+
+/* Our replacement function for xen_extra_version. */
+const char *xen_hello_world(void)
+{
+ return "Hello World";
+}
+
+static unsigned char name[] = "xen_hello_world";
+
+struct xsplice_patch_func xsplice_hello_world = {
+ .name = name,
+ .new_addr = (unsigned long)(xen_hello_world),
+ .old_addr = 0xffff82d08013963c, /* Extracted from xen-syms. */
+ .new_size = 13, /* To be be computed by scripts. */
+ .old_size = 13, /* -----------""--------------- */
+} __attribute__((__section__(".xsplice.funcs")));
+
+</pre>
+
+Code must be compiled with -fPIC.
+
## Hypercalls
We will employ the sub operations of the system management hypercall (sysctl).
diff --git a/xen/Makefile b/xen/Makefile
index c908544..cabb7b0 100644
--- a/xen/Makefile
+++ b/xen/Makefile
@@ -39,8 +39,8 @@ dist: install
build install:: include/config/auto.conf
-.PHONY: build install uninstall clean distclean cscope TAGS tags MAP gtags
-build install uninstall debug clean distclean cscope TAGS tags MAP gtags::
+.PHONY: build install uninstall clean distclean cscope TAGS tags MAP gtags test
+build install uninstall debug clean distclean cscope TAGS tags MAP gtags test::
ifneq ($(XEN_TARGET_ARCH),x86_32)
$(MAKE) -f Rules.mk _$@
else
@@ -76,6 +76,10 @@ _install: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX)
fi; \
fi
+.PHONY: _test
+_test:
+ $(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) test
+
.PHONY: _uninstall
_uninstall: D=$(DESTDIR)
_uninstall: T=$(notdir $(TARGET))
diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile
index eae5cb3..bbd190e 100644
--- a/xen/arch/arm/Makefile
+++ b/xen/arch/arm/Makefile
@@ -57,6 +57,8 @@ ifeq ($(CONFIG_ARM_64),y)
ln -sf $(notdir $@) ../../$(notdir $@).efi
endif
+test:
+
$(TARGET).axf: $(TARGET)-syms
# XXX: VE model loads by VMA so instead of
# making a proper ELF we link with LMA == VMA and adjust crudely
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 8a6a7d5..cd4abd6 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -76,6 +76,9 @@ $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \
`$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'`
+.PHONY: test
+test:
+ $(MAKE) -f $(BASEDIR)/Rules.mk -C test xsplice
ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)
@@ -179,3 +182,4 @@ clean::
rm -f $(BASEDIR)/.xen-syms.[0-9]* boot/.*.d
rm -f $(BASEDIR)/.xen.efi.[0-9]* efi/*.o efi/.*.d efi/*.efi efi/disabled efi/mkreloc
rm -f boot/reloc.S boot/reloc.lnk boot/reloc.bin
+ $(MAKE) -f $(BASEDIR)/Rules.mk -C test clean
diff --git a/xen/arch/x86/test/Makefile b/xen/arch/x86/test/Makefile
new file mode 100644
index 0000000..b9cf13c
--- /dev/null
+++ b/xen/arch/x86/test/Makefile
@@ -0,0 +1,44 @@
+include $(XEN_ROOT)/Config.mk
+
+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}')
+
+.PHONY: default
+
+XSPLICE := xen_hello_world.xsplice
+
+default: xsplice
+
+install: xsplice
+ $(INSTALL_DATA) $(XSPLICE) $(DESTDIR)$(DEBUG_DIR)/$(XSPLICE)
+uninstall:
+ rm -f $(DESTDIR)$(DEBUG_DIR)/$(XSPLICE)
+
+.PHONY: clean
+clean::
+ rm -f *.o .*.o.d $(XSPLICE) config.h
+
+#
+# To compute these values we need the binary files: xen-syms
+# and xen_hello_world_func.o to be already compiled.
+#
+# We can be assured that xen-syms is already built as we are
+# the last entry in the build target.
+#
+.PHONY: config.h
+config.h: OLD_CODE=$(call CODE_ADDR,$(BASEDIR)/xen-syms,xen_extra_version)
+config.h: OLD_CODE_SZ=$(call CODE_SZ,$(BASEDIR)/xen-syms,xen_extra_version)
+config.h: NEW_CODE_SZ=$(call CODE_SZ,$<,xen_hello_world)
+config.h: xen_hello_world_func.o
+ (set -e; \
+ echo "#define NEW_CODE_SZ $(NEW_CODE_SZ)"; \
+ echo "#define OLD_CODE_SZ $(OLD_CODE_SZ)"; \
+ echo "#define OLD_CODE $(OLD_CODE)") > $@
+
+.PHONY: xsplice
+xsplice: config.h
+ # Need to have these done in sequential order
+ $(MAKE) -f $(BASEDIR)/Rules.mk xen_hello_world_func.o
+ $(MAKE) -f $(BASEDIR)/Rules.mk xen_hello_world.o
+ $(LD) $(LDFLAGS) -r -o $(XSPLICE) xen_hello_world_func.o \
+ xen_hello_world.o
diff --git a/xen/arch/x86/test/xen_hello_world.c b/xen/arch/x86/test/xen_hello_world.c
new file mode 100644
index 0000000..67bbe65
--- /dev/null
+++ b/xen/arch/x86/test/xen_hello_world.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
+ *
+ */
+
+#include <xen/types.h>
+#include <xen/xsplice.h>
+#include "config.h"
+
+static char xen_hello_world_name[] = "xen_hello_world";
+extern const char *xen_hello_world(void);
+
+struct xsplice_patch_func __section(".xsplice.funcs") xsplice_xen_hello_world = {
+ .version = XSPLICE_PAYLOAD_VERSION,
+ .name = xen_hello_world_name,
+ .new_addr = (unsigned long)(xen_hello_world),
+ .old_addr = OLD_CODE,
+ .new_size = NEW_CODE_SZ,
+ .old_size = OLD_CODE_SZ,
+};
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/arch/x86/test/xen_hello_world_func.c b/xen/arch/x86/test/xen_hello_world_func.c
new file mode 100644
index 0000000..1ad002a
--- /dev/null
+++ b/xen/arch/x86/test/xen_hello_world_func.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
+ *
+ */
+
+#include <xen/types.h>
+
+/* Our replacement function for xen_extra_version. */
+const char *xen_hello_world(void)
+{
+ return "Hello World";
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
2.5.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-04-07 3:50 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-07 3:49 [PATCH v6] xSplice v1 design and implementation Konrad Rzeszutek Wilk
2016-04-07 3:49 ` [PATCH v6 01/24] xsplice: Design document Konrad Rzeszutek Wilk
2016-04-07 16:34 ` Ian Jackson
2016-04-07 3:49 ` [PATCH v6 02/24] xen/xsplice: Hypervisor implementation of XEN_XSPLICE_op Konrad Rzeszutek Wilk
2016-04-07 14:47 ` Andrew Cooper
2016-04-08 18:30 ` Konrad Rzeszutek Wilk
2016-04-07 3:49 ` [PATCH v6 03/24] libxc: Implementation of XEN_XSPLICE_op in libxc Konrad Rzeszutek Wilk
2016-04-07 19:53 ` Andrew Cooper
2016-04-07 3:49 ` [PATCH v6 04/24] xen-xsplice: Tool to manipulate xsplice payloads Konrad Rzeszutek Wilk
2016-04-07 3:49 ` [PATCH v6 05/24] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables lookup Konrad Rzeszutek Wilk
2016-04-07 20:12 ` Andrew Cooper
2016-04-08 15:30 ` Julien Grall
2016-04-07 3:49 ` [PATCH v6 06/24] x86: Alter nmi_callback_t typedef Konrad Rzeszutek Wilk
2016-04-07 16:35 ` Ian Jackson
2016-04-07 20:13 ` Andrew Cooper
2016-04-08 20:44 ` Konrad Rzeszutek Wilk
2016-04-07 3:49 ` [PATCH v6 07/24] arm/x86/vmap: Add vmalloc_type and vm_init_type Konrad Rzeszutek Wilk
2016-04-08 14:22 ` Andrew Cooper
2016-04-08 17:19 ` Jan Beulich
2016-04-09 1:10 ` Konrad Rzeszutek Wilk
2016-04-08 15:32 ` Julien Grall
2016-04-07 3:49 ` [PATCH v6 08/24] xsplice: Add helper elf routines Konrad Rzeszutek Wilk
2016-04-07 16:19 ` Ian Jackson
2016-04-07 17:23 ` Jan Beulich
2016-04-07 20:32 ` Andrew Cooper
2016-04-08 13:26 ` Ian Jackson
2016-04-07 20:43 ` Konrad Rzeszutek Wilk
2016-04-08 14:53 ` Andrew Cooper
2016-04-08 21:26 ` Konrad Rzeszutek Wilk
2016-04-08 22:10 ` Andrew Cooper
2016-04-08 22:48 ` Jan Beulich
2016-04-07 3:49 ` [PATCH v6 09/24] xsplice: Implement payload loading Konrad Rzeszutek Wilk
2016-04-08 15:31 ` Andrew Cooper
2016-04-08 21:10 ` Konrad Rzeszutek Wilk
2016-04-08 21:18 ` Jan Beulich
2016-04-08 22:45 ` Konrad Rzeszutek Wilk
2016-04-08 22:50 ` Jan Beulich
2016-04-09 0:37 ` Konrad Rzeszutek Wilk
2016-04-09 11:48 ` Konrad Rzeszutek Wilk
2016-04-11 15:53 ` Jan Beulich
2016-04-11 16:03 ` Konrad Rzeszutek Wilk
2016-04-11 16:34 ` Konrad Rzeszutek Wilk
2016-04-11 16:55 ` Jan Beulich
2016-04-11 17:08 ` Konrad Rzeszutek Wilk
2016-04-11 17:26 ` Jan Beulich
2016-04-11 18:21 ` Konrad Rzeszutek Wilk
2016-04-11 18:57 ` Konrad Rzeszutek Wilk
2016-04-08 15:35 ` Julien Grall
2016-04-07 3:49 ` [PATCH v6 10/24] xsplice: Implement support for applying/reverting/replacing patches Konrad Rzeszutek Wilk
2016-04-08 15:36 ` Julien Grall
2016-04-08 16:33 ` Andrew Cooper
2016-04-07 3:49 ` Konrad Rzeszutek Wilk [this message]
2016-04-08 15:37 ` [PATCH v6 11/24] x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version' Julien Grall
2016-04-08 16:38 ` Andrew Cooper
2016-04-09 0:45 ` Konrad Rzeszutek Wilk
2016-04-07 3:49 ` [PATCH v6 12/24] xsplice, symbols: Implement symbol name resolution on address Konrad Rzeszutek Wilk
2016-04-08 16:55 ` Andrew Cooper
2016-04-07 3:49 ` [PATCH v6 13/24] x86, xsplice: Print payload's symbol name and payload name in backtraces Konrad Rzeszutek Wilk
2016-04-08 17:00 ` Andrew Cooper
2016-04-07 3:49 ` [PATCH v6 14/24] xsplice: Add support for bug frames Konrad Rzeszutek Wilk
2016-04-08 17:03 ` Andrew Cooper
2016-04-07 3:49 ` [PATCH v6 15/24] xsplice: Add support for exception tables Konrad Rzeszutek Wilk
2016-04-08 17:16 ` Andrew Cooper
2016-04-07 3:49 ` [PATCH v6 16/24] xsplice: Add support for alternatives Konrad Rzeszutek Wilk
2016-04-08 17:34 ` Andrew Cooper
2016-04-08 17:57 ` Jan Beulich
2016-04-07 3:49 ` [PATCH v6 17/24] build_id: Provide ld-embedded build-ids Konrad Rzeszutek Wilk
2016-04-08 15:39 ` Julien Grall
2016-04-08 18:07 ` Andrew Cooper
2016-04-08 19:34 ` Konrad Rzeszutek Wilk
2016-04-07 3:49 ` [PATCH v6 18/24] HYPERCALL_version_op: Add VERSION_build_id to retrieve build-id Konrad Rzeszutek Wilk
2016-04-08 18:07 ` Andrew Cooper
2016-04-07 3:49 ` [PATCH v6 19/24] libxl: info: Display build_id of the hypervisor using XEN_VERSION_build_id Konrad Rzeszutek Wilk
2016-04-07 3:49 ` [PATCH v6 20/24] xsplice: Print build_id in keyhandler and on bootup Konrad Rzeszutek Wilk
2016-04-08 18:12 ` Andrew Cooper
2016-04-07 3:49 ` [PATCH v6 21/24] xsplice: Stacking build-id dependency checking Konrad Rzeszutek Wilk
2016-04-08 18:19 ` Andrew Cooper
2016-04-09 1:43 ` Konrad Rzeszutek Wilk
2016-04-07 3:49 ` [PATCH v6 22/24] xsplice/xen_replace_world: Test-case for XSPLICE_ACTION_REPLACE Konrad Rzeszutek Wilk
2016-04-08 18:20 ` Andrew Cooper
2016-04-07 3:49 ` [PATCH v6 23/24] xsplice: Prevent duplicate payloads from being loaded Konrad Rzeszutek Wilk
2016-04-07 16:36 ` Ian Jackson
2016-04-08 18:21 ` Andrew Cooper
2016-04-07 3:49 ` [PATCH v6 24/24] MAINTAINERS/xsplice: Add myself and Ross as the maintainers Konrad Rzeszutek Wilk
2016-04-08 18:21 ` Andrew Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1460000983-28170-12-git-send-email-konrad.wilk@oracle.com \
--to=konrad.wilk@oracle.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=julien.grall@arm.com \
--cc=keir@xen.org \
--cc=konrad@kernel.org \
--cc=mpohlack@amazon.de \
--cc=ross.lagerwall@citrix.com \
--cc=sasha.levin@oracle.com \
--cc=stefano.stabellini@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).