From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Julien Grall <julien.grall@arm.com>
Cc: sstabellini@kernel.org, ross.lagerwall@citrix.com,
Andrew Cooper <andrew.cooper3@citrix.com>,
Jan Beulich <jbeulich@suse.com>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH v5 16/16] livepatch: arm[32, 64], x86: NOP test-case
Date: Thu, 22 Sep 2016 21:35:03 -0400 [thread overview]
Message-ID: <20160923013502.GC29985@localhost.localdomain> (raw)
In-Reply-To: <b86db145-5164-1ec9-1a63-231dbf303e68@arm.com>
.snip..
> > While on ARM32 there are 24 bytes:
> >
> > e52db004 push {fp}
> > e28db000 add fp, sp, #0 <- NOP
> > e3a00008 mov r0, #8 <- NOP
> > e24bd000 sub sp, fp, #0 <- NOP
> > e49db004 pop {fp}
> > e12fff1e bx lr
> >
> > And we can NOP instruction 2,3, and 4.
>
> Why don't you NOP push {fp} and pop {fp}? At first glance, I am a bit
> surprised that the compiler is generating them (maybe it is because you have
> debug enabled?) and would have expect to have:
>
> mov r0, #8
> bx lr
>
> NOPing all the instructions but the last one would simplify at lot the test
> case below.
>
> [...]
..snip..
> With my suggestion above, the two ARM code could become:
>
> #ifdef CONFIG_ARM
> .old_addr = (void *)MINOR_VERSION_ADDR,
> .new_size = MINOR_VERSION_SIZE - 4,
> #endif
>
> The "- 4" is to avoid replacing the return.
Done!
From 8ade51e1866b86c7660277bb19100db337d432b4 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Date: Sat, 10 Sep 2016 20:41:24 -0400
Subject: [PATCH v6] livepatch: arm[32,64],x86: NOP test-case
The test-case is quite simple - we NOP the 'xen_minor_version'.
The amount of NOPs depends on the architecture.
On x86 the function is 11 bytes long:
55 push %rbp <- NOP
48 89 e5 mov %rsp,%rbp <- NOP
b8 04 00 00 00 mov $0x4,%eax <- NOP
5d pop %rbp <- NOP
c3 retq
We can NOP everything but the last instruction (so 10 bytes).
On ARM64 its 8 bytes:
52800100 mov w0, #0x8 <- NOP
d65f03c0 ret
We can NOP the first instruction.
While on ARM32 there are 24 bytes:
e52db004 push {fp} <- NOP
e28db000 add fp, sp, #0 <- NOP
e3a00008 mov r0, #8 <- NOP
e24bd000 sub sp, fp, #0 <- NOP
e49db004 pop {fp} <- NOP
e12fff1e bx lr
And we can NOP instructions 1 through 5.
Granted this code may be different per compiler!
Hence if anybody does run this test-case - they should
verify that the assumptions made here are correct.
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
Cc: Julien Grall <julien.grall@arm.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
v3: New submission.
v4: Redo the ARM code to NOP over push/pop as well.
---
xen/test/livepatch/Makefile | 15 +++++++++++++-
xen/test/livepatch/xen_nop.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+), 1 deletion(-)
create mode 100644 xen/test/livepatch/xen_nop.c
diff --git a/xen/test/livepatch/Makefile b/xen/test/livepatch/Makefile
index 9439f62..76a779a 100644
--- a/xen/test/livepatch/Makefile
+++ b/xen/test/livepatch/Makefile
@@ -18,6 +18,7 @@ CODE_SZ=$(shell nm --defined -S $(1) | grep $(2) | awk '{ print "0x"$$2}')
LIVEPATCH := xen_hello_world.livepatch
LIVEPATCH_BYE := xen_bye_world.livepatch
LIVEPATCH_REPLACE := xen_replace_world.livepatch
+LIVEPATCH_NOP := xen_nop.livepatch
default: livepatch
@@ -25,10 +26,12 @@ install: livepatch
$(INSTALL_DATA) $(LIVEPATCH) $(DESTDIR)$(DEBUG_DIR)/$(LIVEPATCH)
$(INSTALL_DATA) $(LIVEPATCH_BYE) $(DESTDIR)$(DEBUG_DIR)/$(LIVEPATCH_BYE)
$(INSTALL_DATA) $(LIVEPATCH_REPLACE) $(DESTDIR)$(DEBUG_DIR)/$(LIVEPATCH_REPLACE)
+ $(INSTALL_DATA) $(LIVEPATCH_NOP) $(DESTDIR)$(DEBUG_DIR)/$(LIVEPATCH_NOP)
uninstall:
rm -f $(DESTDIR)$(DEBUG_DIR)/$(LIVEPATCH)
rm -f $(DESTDIR)$(DEBUG_DIR)/$(LIVEPATCH_BYE)
rm -f $(DESTDIR)$(DEBUG_DIR)/$(LIVEPATCH_REPLACE)
+ rm -f $(DESTDIR)$(DEBUG_DIR)/$(LIVEPATCH_NOP)
.PHONY: clean
clean::
@@ -41,9 +44,13 @@ clean::
.PHONY: config.h
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: MINOR_VERSION_SZ=$(call CODE_SZ,$(BASEDIR)/xen-syms,xen_minor_version)
+config.h: MINOR_VERSION_ADDR=$(call CODE_ADDR,$(BASEDIR)/xen-syms,xen_minor_version)
config.h: xen_hello_world_func.o
(set -e; \
echo "#define NEW_CODE_SZ $(NEW_CODE_SZ)"; \
+ echo "#define MINOR_VERSION_SZ $(MINOR_VERSION_SZ)"; \
+ echo "#define MINOR_VERSION_ADDR $(MINOR_VERSION_ADDR)"; \
echo "#define OLD_CODE_SZ $(OLD_CODE_SZ)") > $@
xen_hello_world.o: config.h
@@ -91,5 +98,11 @@ xen_replace_world.o: config.h
$(LIVEPATCH_REPLACE): xen_replace_world_func.o xen_replace_world.o note.o
$(LD) $(LDFLAGS) $(build_id_linker) -r -o $(LIVEPATCH_REPLACE) $^
+xen_nop.o: config.h
+
+.PHONY: $(LIVEPATCH_NOP)
+$(LIVEPATCH_NOP): xen_nop.o note.o
+ $(LD) $(LDFLAGS) $(build_id_linker) -r -o $(LIVEPATCH_NOP) $^
+
.PHONY: livepatch
-livepatch: $(LIVEPATCH) $(LIVEPATCH_BYE) $(LIVEPATCH_REPLACE)
+livepatch: $(LIVEPATCH) $(LIVEPATCH_BYE) $(LIVEPATCH_REPLACE) $(LIVEPATCH_NOP)
diff --git a/xen/test/livepatch/xen_nop.c b/xen/test/livepatch/xen_nop.c
new file mode 100644
index 0000000..69dcbca
--- /dev/null
+++ b/xen/test/livepatch/xen_nop.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
+ *
+ */
+
+#include "config.h"
+#include <xen/types.h>
+
+#include <public/sysctl.h>
+
+/*
+ * All of the .new_size and .old_addr are based on assumptions that the
+ * code for 'xen_minor_version' is compiled in specific way. Before
+ * running this test-case you MUST verify that the assumptions are
+ * correct (Hint: make debug and look in xen.s).
+ */
+struct livepatch_func __section(".livepatch.funcs") livepatch_nop = {
+ .version = LIVEPATCH_PAYLOAD_VERSION,
+ .old_size = MINOR_VERSION_SZ,
+
+#ifdef CONFIG_X86
+ .old_addr = (void *)MINOR_VERSION_ADDR,
+ /* Everything but the last instruction: "req". */
+ .new_size = MINOR_VERSION_SZ-1,
+#endif
+
+#ifdef CONFIG_ARM_64
+ .old_addr = (void *)MINOR_VERSION_ADDR,
+ /* Replace the first one: "mov w0, #0x8". */
+ .new_size = 4,
+#endif
+
+#ifdef CONFIG_ARM_32
+ .old_addr = (void *)MINOR_VERSION_ADDR,
+ /* And replace all but the return instruction. */
+ .new_size = MINOR_VERSION_SZ-4,
+#endif
+};
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
2.4.11
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-09-23 1:35 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-21 17:32 [PATCH v5] Livepatch for ARM 64 and 32 Konrad Rzeszutek Wilk
2016-09-21 17:32 ` [PATCH v5 01/16] arm64: s/ALTERNATIVE/HAS_ALTERNATIVE/ Konrad Rzeszutek Wilk
2016-09-22 12:21 ` Julien Grall
2016-09-21 17:32 ` [PATCH v5 02/16] arm/x86/common: Add HAS_[ALTERNATIVE|EX_TABLE] Konrad Rzeszutek Wilk
2016-09-22 12:23 ` Julien Grall
2016-09-22 15:30 ` Ross Lagerwall
2016-09-21 17:32 ` [PATCH v5 03/16] livepatch: Reject payloads with .alternative or .ex_table if support is not built-in Konrad Rzeszutek Wilk
2016-09-23 12:47 ` Ross Lagerwall
2016-09-21 17:32 ` [PATCH v5 04/16] arm: poison initmem when it is freed Konrad Rzeszutek Wilk
2016-09-22 12:28 ` Julien Grall
2016-09-21 17:32 ` [PATCH v5 05/16] livepatch: Initial ARM64 support Konrad Rzeszutek Wilk
2016-09-22 12:49 ` Julien Grall
2016-09-23 13:38 ` Ross Lagerwall
2016-09-23 15:44 ` Konrad Rzeszutek Wilk
2016-09-27 16:42 ` Julien Grall
2016-09-21 17:32 ` [PATCH v5 06/16] livepatch: ARM/x86: Check displacement of old_addr and new_addr Konrad Rzeszutek Wilk
2016-09-22 12:55 ` Julien Grall
2016-09-23 14:36 ` Ross Lagerwall
2016-09-23 15:37 ` Konrad Rzeszutek Wilk
2016-09-23 15:59 ` Konrad Rzeszutek Wilk
2016-09-28 10:21 ` Ross Lagerwall
2016-09-21 17:32 ` [PATCH v5 07/16] livepatch: ARM 32|64: Ignore mapping symbols: $[d, a, x] Konrad Rzeszutek Wilk
2016-09-22 12:56 ` Julien Grall
2016-09-23 14:44 ` Ross Lagerwall
2016-09-23 16:13 ` Konrad Rzeszutek Wilk
2016-09-21 17:32 ` [PATCH v5 08/16] livepatch/arm/x86: Check payload for for unwelcomed symbols Konrad Rzeszutek Wilk
2016-09-22 13:00 ` Julien Grall
2016-09-23 1:29 ` Konrad Rzeszutek Wilk
2016-09-27 8:49 ` Ross Lagerwall
2016-09-23 14:49 ` Ross Lagerwall
2016-09-23 16:15 ` Konrad Rzeszutek Wilk
2016-09-21 17:32 ` [PATCH v5 09/16] livepatch: Move test-cases to their own sub-directory in test Konrad Rzeszutek Wilk
2016-09-22 13:01 ` Julien Grall
2016-09-23 14:51 ` Ross Lagerwall
2016-09-21 17:32 ` [PATCH v5 10/16] livepatch: x86, ARM, alternative: Expose FEATURE_LIVEPATCH Konrad Rzeszutek Wilk
2016-09-22 13:03 ` Julien Grall
2016-09-27 9:49 ` Ross Lagerwall
2016-09-21 17:32 ` [PATCH v5 11/16] livepatch: tests: Make them compile under ARM64 Konrad Rzeszutek Wilk
2016-09-22 13:10 ` Julien Grall
2016-09-22 19:26 ` Konrad Rzeszutek Wilk
2016-09-23 1:33 ` Konrad Rzeszutek Wilk
2016-09-23 9:50 ` Julien Grall
2016-09-27 9:49 ` Ross Lagerwall
2016-09-21 17:32 ` [PATCH v5 12/16] xen/arm32: Add an helper to invalidate all instruction caches Konrad Rzeszutek Wilk
2016-09-22 13:17 ` Julien Grall
2016-09-21 17:32 ` [PATCH v5 13/16] bug/x86/arm: Align bug_frames sections Konrad Rzeszutek Wilk
2016-09-21 17:32 ` [PATCH v5 14/16] livepatch: Initial ARM32 support Konrad Rzeszutek Wilk
2016-09-27 16:39 ` Julien Grall
2016-09-27 17:50 ` Konrad Rzeszutek Wilk
2016-09-27 23:13 ` Julien Grall
2016-09-21 17:32 ` [PATCH v5 15/16] livepatch, arm[32|64]: Share arch_livepatch_revert Konrad Rzeszutek Wilk
2016-09-23 14:59 ` Ross Lagerwall
2016-09-23 16:15 ` Konrad Rzeszutek Wilk
2016-09-21 17:32 ` [PATCH v5 16/16] livepatch: arm[32, 64], x86: NOP test-case Konrad Rzeszutek Wilk
2016-09-22 13:23 ` Julien Grall
2016-09-23 1:35 ` Konrad Rzeszutek Wilk [this message]
2016-09-23 9:53 ` Julien Grall
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=20160923013502.GC29985@localhost.localdomain \
--to=konrad.wilk@oracle.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=julien.grall@arm.com \
--cc=ross.lagerwall@citrix.com \
--cc=sstabellini@kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.