From patchwork Tue Jun 20 02:47:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 9798417 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 97A3460381 for ; Tue, 20 Jun 2017 02:51:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95B15274A3 for ; Tue, 20 Jun 2017 02:51:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CA9027DCD; Tue, 20 Jun 2017 02:51:51 +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 DCFA6274D2 for ; Tue, 20 Jun 2017 02:51:50 +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 1dN9DX-0005FM-E4; Tue, 20 Jun 2017 02:48:35 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dN9DW-0005Ey-7R for xen-devel@lists.xenproject.org; Tue, 20 Jun 2017 02:48:34 +0000 Received: from [85.158.143.35] by server-7.bemta-6.messagelabs.com id 79/13-03620-10D88495; Tue, 20 Jun 2017 02:48:33 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpnkeJIrShJLcpLzFFi42LpnVTnqsvQ6xF pcHSXhcX3LZOZHBg9Dn+4whLAGMWamZeUX5HAmnG8ay1zwU6FimMTXjA2MM6V6WLk4hASmMgk 8XT6MTYI5zejxM87zxkhnI2MErf3T2CGcPoYJX7dXwWU4eBgEzCReLPKsYuRk0NEIFbiw869L CA2s0CGxMN9X8FsYQEniV/XVjCC2CwCqhLTps8Ei/MKWEu8/PqJDcSWEJCTWLr9OjOIzSlgI7 Ht1wywGiGgmvnHVrFC1BhKfN64lHkCI98CRoZVjOrFqUVlqUW6ZnpJRZnpGSW5iZk5uoYGZnq 5qcXFiempOYlJxXrJ+bmbGIGBwgAEOxjnnfA/xCjJwaQkypuc4REpxJeUn1KZkVicEV9UmpNa fIhRhoNDSYJXrwcoJ1iUmp5akZaZAwxZmLQEB4+SCO+2QqA0b3FBYm5xZjpE6hSjLseG1eu/M Amx5OXnpUqJ837uBioSACnKKM2DGwGLn0uMslLCvIxARwnxFKQW5WaWoMq/YhTnYFQS5k1rBZ rCk5lXArfpFdARTEBHMJ9xATmiJBEhJdXAeLW0NMJWZlUp28XD4h67YqtazxfvSqgtt294cqn 2scVhredTVYLV01eGRyiGuio4hjf0T3ndV+cQ17JzYtW0iK2Prc7l/+5Q+823RNXwzTORI8wf Sws87WZvfrnFvl744k63zPq6nVKiBavixHUTzbZuYpfaHvguu82gO0bgm+5hkxoewUwlluKMR EMt5qLiRADqD3bXmgIAAA== X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-7.tower-21.messagelabs.com!1497926911!74699494!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: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 48073 invoked from network); 20 Jun 2017 02:48:32 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-7.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 20 Jun 2017 02:48:32 -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 v5K2mP3w025493 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Jun 2017 02:48:26 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v5K2mP9i030394 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Jun 2017 02:48:25 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v5K2mP7Z022351; Tue, 20 Jun 2017 02:48:25 GMT Received: from x230.dumpdata.com.com (/10.154.148.136) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 19 Jun 2017 19:48:24 -0700 From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, ian.jackson@citrix.com, ross.lagerwall@citrix.com Date: Mon, 19 Jun 2017 22:47:58 -0400 Message-Id: <20170620024759.32562-3-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170620024759.32562-1-konrad.wilk@oracle.com> References: <20170620024759.32562-1-konrad.wilk@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: andrew.cooper3@citrix.com, jbeulich@suse.com, Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v1 2/3] livepatch: Add xen_local_symbols 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 To exercise the local/global visibility. With "livepatch: Add local and global symbol resolution." we can load both xen_hello_world and xen_local_symbols without having to worry about: -bash-4.1# xen-livepatch load xen_hello_world.livepatch Uploading xen_hello_world.livepatch... completed Applying xen_hello_world... completed -bash-4.1# xen-livepatch list ID | status ----------------------------------------+------------ xen_hello_world | APPLIED -bash-4.1# xen-livepatch upload xen_local_symbols xen_local_symbols.livepatch Uploading xen_local_symbols.livepatch... failed (XEN) livepatch.c:819: livepatch: xen_local_symbols: duplicate new symbol: revert_hook In fact you will see: livepatch: xen_hello_world: new local symbol revert_hook livepatch: xen_hello_world: new local symbol apply_hook livepatch: xen_hello_world: new local symbol check_fnc livepatch: xen_hello_world: new local symbol hello_world_patch_this_fnc ... livepatch: xen_local_symbols: new local symbol revert_hook livepatch: xen_local_symbols: new local symbol apply_hook livepatch: xen_local_symbols: new local symbol hello_world_patch_this_fnc .. Signed-off-by: Konrad Rzeszutek Wilk --- xen/test/livepatch/Makefile | 10 ++++++- xen/test/livepatch/xen_local_symbols.c | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 xen/test/livepatch/xen_local_symbols.c diff --git a/xen/test/livepatch/Makefile b/xen/test/livepatch/Makefile index 6831383d..b9ad291 100644 --- a/xen/test/livepatch/Makefile +++ b/xen/test/livepatch/Makefile @@ -19,11 +19,13 @@ LIVEPATCH := xen_hello_world.livepatch LIVEPATCH_BYE := xen_bye_world.livepatch LIVEPATCH_REPLACE := xen_replace_world.livepatch LIVEPATCH_NOP := xen_nop.livepatch +LIVEPATCH_LOCAL := xen_local_symbols.livepatch LIVEPATCHES += $(LIVEPATCH) LIVEPATCHES += $(LIVEPATCH_BYE) LIVEPATCHES += $(LIVEPATCH_REPLACE) LIVEPATCHES += $(LIVEPATCH_NOP) +LIVEPATCHES += $(LIVEPATCH_LOCAL) LIVEPATCH_DEBUG_DIR ?= $(DEBUG_DIR)/xen-livepatch @@ -107,5 +109,11 @@ xen_nop.o: config.h $(LIVEPATCH_NOP): xen_nop.o note.o $(LD) $(LDFLAGS) $(build_id_linker) -r -o $(LIVEPATCH_NOP) $^ +xen_local_symbols.o: config.h + +.PHONY: $(LIVEPATCH_LOCAL) +$(LIVEPATCH_LOCAL): xen_hello_world_func.o xen_local_symbols.o note.o + $(LD) $(LDFLAGS) $(build_id_linker) -r -o $(LIVEPATCH_LOCAL) $^ + .PHONY: livepatch -livepatch: $(LIVEPATCH) $(LIVEPATCH_BYE) $(LIVEPATCH_REPLACE) $(LIVEPATCH_NOP) +livepatch: $(LIVEPATCH) $(LIVEPATCH_BYE) $(LIVEPATCH_REPLACE) $(LIVEPATCH_NOP) $(LIVEPATCH_LOCAL) diff --git a/xen/test/livepatch/xen_local_symbols.c b/xen/test/livepatch/xen_local_symbols.c new file mode 100644 index 0000000..eb01b69 --- /dev/null +++ b/xen/test/livepatch/xen_local_symbols.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. + */ + +#include "config.h" +#include +#include +#include +#include +#include + +#include + +/* Same name as in xen_hello_world */ +static const char hello_world_patch_this_fnc[] = "xen_extra_version"; +extern const char *xen_hello_world(void); + +/* + * The hooks are static here (LOCAL) and also in xen_hello_world.c + * and their name is exactly the same. + */ +static void apply_hook(void) +{ + printk(KERN_DEBUG "local_symbols: Hook executing.\n"); +} + +static void revert_hook(void) +{ + printk(KERN_DEBUG "local_symbols: Hook unloaded.\n"); +} + +LIVEPATCH_LOAD_HOOK(apply_hook); +LIVEPATCH_UNLOAD_HOOK(revert_hook); + +struct livepatch_func __section(".livepatch.funcs") livepatch_xen_local_symbols = { + .version = LIVEPATCH_PAYLOAD_VERSION, + .name = hello_world_patch_this_fnc, + .new_addr = xen_hello_world, + .old_addr = xen_extra_version, + .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: + */