From patchwork Tue Sep 12 00:37:26 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: 9948231 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 840AB6038F for ; Tue, 12 Sep 2017 00:41:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7608A28D6F for ; Tue, 12 Sep 2017 00:41:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67E8128DA2; Tue, 12 Sep 2017 00:41:10 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID 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 2BCA428D72 for ; Tue, 12 Sep 2017 00:41:04 +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 1drZDM-0000xi-Dx; Tue, 12 Sep 2017 00:38:08 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drZDL-0000u4-9y for xen-devel@lists.xenproject.org; Tue, 12 Sep 2017 00:38:07 +0000 Received: from [85.158.137.68] by server-1.bemta-3.messagelabs.com id E2/37-02048-E6C27B95; Tue, 12 Sep 2017 00:38:06 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrCIsWRWlGSWpSXmKPExsVyMfTOEd1cne2 RBrc6zCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oytHyoLnitVnP8o1MC4Wa6LkYtDSGAGo8SX pleMIA6LwAcWiTebVrKDOBIC01gltp39z9rFyAnkxEnM+PiFBcJOk5i3fzsbhF0h8ff9OWYQW 0hASWLL5MeMEPZBJokPFxRBbGEBPYnJ326DxdkE9CWerr0GVM8B1Osm8ekaF8guEYF2RonZV3 6B7WIWMJRofXuUDaLXRWLr759MIDaLgKrExQs3wGp4BawkFn/YxQRxg7zExN5pYPM5geK/f8x jhbjBUqJjwRWmCYzCCxgZVjFqFKcWlaUW6Rqa6iUVZaZnlOQmZuboGhoY6+WmFhcnpqfmJCYV 6yXn525iBIYnAxDsYFyz3fMQoyQHk5Io72/h7ZFCfEn5KZUZicUZ8UWlOanFhxhlODiUJHjLt IFygkWp6akVaZk5wEiBSUtw8CiJ8GZpAaV5iwsSc4sz0yFSpxjtOS7cufSHiePYpstA8sCeW0 Cy4+bdP0xCLHn5ealS4rxFIFMFQNoySvPghsIi+xKjrJQwLyPQmUI8BalFuZklqPKvGMU5GJW EeZNBpvBk5pXA7X4FdBYT0Fk8l7aAnFWSiJCSamCsWOxWejyswujzr1kvefOOb3ZTdNZbzaZ+ 9dIrzfgFC6359s6x918mYVt05M739btSIubW/uLjv/yqTjx8/Y+1cfy1Brft/kblesTNLGNbr 3br37K3gk1djDvU6/58PRwTuPnomn/7duwLz5fZ//PPtqUi5ZtPZ55/cNa5oofX8Ny1luv7S0 5cUGIpzkg01GIuKk4EAESli3jnAgAA X-Env-Sender: ketuzsezr@gmail.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1505176684!114124551!1 X-Originating-IP: [209.85.220.196] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5664 invoked from network); 12 Sep 2017 00:38:05 -0000 Received: from mail-qk0-f196.google.com (HELO mail-qk0-f196.google.com) (209.85.220.196) by server-14.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 12 Sep 2017 00:38:05 -0000 Received: by mail-qk0-f196.google.com with SMTP id o77so6381088qke.2 for ; Mon, 11 Sep 2017 17:38:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=kxrNpt1JRygA1GMqz/89+dWx2ePtsF/pLXL3YYHcHX4=; b=btINVhQLtstmMIrfEngRYghGKoHYPGXE1phNiDXLzmF6dfIi0opFLO7fYDCJdPgOu5 GQvG0j9EUQ8+Uqhb0qUaC7j6ZNb91qScOhP7H966MZGbauOSRv1JOCumYBpRRrloWg73 S8dCavnjDJ0oJYNlP95ICqbnbMRtPb0SFMxfoTZKEi0yTSDmnAuw+hqsMB9sfGkE2u9o ALqL48V3LWZcfQignwCiR2nGQumJsyLOsmFBwPLFkbckadOS+t2CF5s093PJwUakq8pZ HrLocNIP0M6y61o5NDyBEvWpvXC7DDIhJ8vp7uYNvz/0UXz13lZ3RDv3iPSOzwJNTDJl /ngA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=kxrNpt1JRygA1GMqz/89+dWx2ePtsF/pLXL3YYHcHX4=; b=FEu0hXjcpX9qnxTXb9fROqiOUoOCcM5CTdzAFhcy4/jfdsRBjp1IKkLg23/jhAq/3W /T8Zd5ec7DbN2QkBGd/RWHathqZmIFIBMJ2lZx1k5vqufxncRRLEDuG918kNl9cMOTDr GiRzP4K/22N6wiQlR83Zm0WLVQiRB+ym125Y9NmBVV2VrxbuafZowBHtdn6cH2g3vW8m wurlaTg4LJX/p3ibfS3xFQ8/h1wuB5ETLJUbJTUkd7+nfLgqE5R8juO0o5BJcJBC3s3n pOX0MNH48CA+gUeJKsu7D0RZclhzCwq8QYRjJ1HRofLZUILBr79BcYIpzru3rtJHred/ PLBg== X-Gm-Message-State: AHPjjUiaymrzyAwsM+SMeCrMVzn8DEwDAFn9IT+kYsvSsrBtpCh9O+iB k6gimJrGXcRRnJjr X-Google-Smtp-Source: AOwi7QDHkQmM8IpUpOFZaOH9mAhctvP8SCWcoohDYKLx1+MSrxKzYFj1TFL08KKtvolYL2Iyimldhw== X-Received: by 10.55.110.3 with SMTP id j3mr16924930qkc.195.1505176684332; Mon, 11 Sep 2017 17:38:04 -0700 (PDT) Received: from localhost.localdomain (209-6-200-48.s4398.c3-0.smr-ubr2.sbo-smr.ma.cable.rcncustomer.com. [209.6.200.48]) by smtp.gmail.com with ESMTPSA id z75sm6771034qkb.71.2017.09.11.17.38.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Sep 2017 17:38:03 -0700 (PDT) From: Konrad Rzeszutek Wilk X-Google-Original-From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, ross.lagerwall@citrix.com, konrad.wilk@oracle.com, julien.grall@arm.com, sstabellini@kernel.org Date: Mon, 11 Sep 2017 20:37:26 -0400 Message-Id: <20170912003726.368-18-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170912003726.368-1-konrad.wilk@oracle.com> References: <20170912003726.368-1-konrad.wilk@oracle.com> Cc: andrew.cooper3@citrix.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH v3 17/17] 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 --- v1: First edition v2: Build with mkhex version of build-id from hypervisor. --- xen/test/livepatch/Makefile | 12 +++++++- xen/test/livepatch/xen_local_symbols.c | 53 ++++++++++++++++++++++++++++++++++ 2 files changed, 64 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 6e5b9a3a75..f88c8f9c80 100644 --- a/xen/test/livepatch/Makefile +++ b/xen/test/livepatch/Makefile @@ -11,11 +11,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 @@ -109,5 +111,13 @@ $(LIVEPATCH_NOP): xen_nop.o $(OBJCOPY) --strip-debug --strip-symbol=$(NOTE_SYMBOL) $@ $(OBJCOPY) --set-section-flags .livepatch.funcs=alloc,readonly $@ +xen_local_symbols.o: config.h livepatch_depends.h + +.PHONY: $(LIVEPATCH_LOCAL) +$(LIVEPATCH_LOCAL): xen_hello_world_func.o xen_local_symbols.o + $(LD) $(LDFLAGS) $(build_id_linker) -r -o $(LIVEPATCH_LOCAL) $^ + $(OBJCOPY) --strip-debug --strip-symbol=$(NOTE_SYMBOL) $@ + $(OBJCOPY) --set-section-flags .livepatch.funcs=alloc,readonly $@ + .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 0000000000..448c489818 --- /dev/null +++ b/xen/test/livepatch/xen_local_symbols.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. + */ + +#include "config.h" +#include +#include +#include +#include +#include + +#include +#include "livepatch_depends.h" + +/* 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: + */