From patchwork Wed Sep 21 17:32:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 9344005 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 739E26077A for ; Wed, 21 Sep 2016 17:35:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 611232A83E for ; Wed, 21 Sep 2016 17:35:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 524492A84D; Wed, 21 Sep 2016 17:35:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 59C5C2A84A for ; Wed, 21 Sep 2016 17:35:29 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bmlOa-00040b-V1; Wed, 21 Sep 2016 17:33:20 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bmlOa-0003zO-5b for xen-devel@lists.xenproject.org; Wed, 21 Sep 2016 17:33:20 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id D6/54-27233-F54C2E75; Wed, 21 Sep 2016 17:33:19 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsXSO6nOVTfuyKN wg9X/LSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oy3/9ayFszQqDjdfJylgfGfQhcjF4eQwEQm ie7XS9ghnN+MEvN2PGGBcDYyStz9/pm5i5ETyJnFKLHigloXIwcHm4CJxJtVjiA1IgJ9jBIbr /5mA6lhBnH2nQarFxZwkvjWsJ0dxGYRUJW4uL6VBcTmFXCX6Hn2lQlkjoSAvMSz2/UgYU6g8J 1HR6BWuUnc7X/ICmJLCBhKfN64lHkCI98CRoZVjBrFqUVlqUW6RhZ6SUWZ6RkluYmZObqGBsZ 6uanFxYnpqTmJScV6yfm5mxiBgVLPwMC4g7H9hN8hRkkOJiVR3u4tj8KF+JLyUyozEosz4otK c1KLDzHKcHAoSfCuOQSUEyxKTU+tSMvMAYYsTFqCg0dJhFfhMFCat7ggMbc4Mx0idYpRUUqc9 w1InwBIIqM0D64NFieXGGWlhHkZGRgYhHgKUotyM0tQ5V8xinMwKgnzrgCZwpOZVwI3/RXQYi agxVt+PgBZXJKIkJJqYNw+RerVb9+I9zf/Jn5T21wRl//u7bG/gcsvWEkUL9MxWjLRNWVPnWG 2p5hrH6u53Rpeoc78WV1qVUy3fA61s7Dzi82KaduT/rQt4Yn7v5MLHNh2n/Gv2e9ra98XrBFT YCD6Y91x70fPEntz9W66LCqbZRD1momlKm+7x2eR4zxzTy/dqHeCVYmlOCPRUIu5qDgRAC0/Y ReOAgAA X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1474479197!45188053!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30004 invoked from network); 21 Sep 2016 17:33:18 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-12.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 21 Sep 2016 17:33:18 -0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u8LHXAiU024338 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Sep 2016 17:33:11 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u8LHXA4a017353 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Sep 2016 17:33:10 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u8LHX9kQ005092; Wed, 21 Sep 2016 17:33:09 GMT Received: from localhost.localdomain.localdomain (/172.58.216.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 21 Sep 2016 10:33:09 -0700 From: Konrad Rzeszutek Wilk To: konrad@kernel.org, xen-devel@lists.xenproject.org, ross.lagerwall@citrix.com, sstabellini@kernel.org, julien.grall@arm.com Date: Wed, 21 Sep 2016 13:32:34 -0400 Message-Id: <1474479154-20991-17-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.4.11 In-Reply-To: <1474479154-20991-1-git-send-email-konrad.wilk@oracle.com> References: <1474479154-20991-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: Andrew Cooper , Jan Beulich , Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v5 16/16] livepatch: arm[32, 64], x86: NOP test-case X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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} 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. 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 --- Cc: Julien Grall Cc: Stefano Stabellini Cc: Jan Beulich Cc: Andrew Cooper v3: New submission. --- xen/test/livepatch/Makefile | 15 +++++++++++++- xen/test/livepatch/xen_nop.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 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 4d66a40..d7a4735 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 @@ -92,5 +99,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..3827979 --- /dev/null +++ b/xen/test/livepatch/xen_nop.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. + * + */ + +#include "config.h" +#include + +#include + +/* + * 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 + /* Skip the first instruction: "push {fp}". */ + .old_addr = (void *)(MINOR_VERSION_ADDR + 4), + /* And replace the next three instructions. */ + .new_size = 3 * 4, +#endif +}; + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */