From patchwork Tue Jun 20 02:47:57 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: 9798421 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 4FD0760381 for ; Tue, 20 Jun 2017 02:51:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DA2C274A3 for ; Tue, 20 Jun 2017 02:51:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EEDA274D2; Tue, 20 Jun 2017 02:51:52 +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 C5402274D2 for ; Tue, 20 Jun 2017 02:51:51 +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-0005FX-LO; Tue, 20 Jun 2017 02:48:35 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dN9DW-0005Ez-Co for xen-devel@lists.xenproject.org; Tue, 20 Jun 2017 02:48:34 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 9F/25-26749-10D88495; Tue, 20 Jun 2017 02:48:33 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupgkeJIrShJLcpLzFFi42KZM10+UJex1yP S4M4dJovvWyYzOTB6HP5whSWAMYo1My8pvyKBNePm86PsBbs1K85Mms3ewLhJrouRi0NIYDKT xIPLzawQzl9GiXvNx1kgnI2MEt/WtzFDOH2MErcvvGPvYuTgYBMwkXizyrGLkZNDRCBW4sPOv SwgNrNAhsTDfV/BbGEBL4kPvfPZQWwWAVWJvoOT2UBsXgFria235zCD2BICchJLt18HszkFbC S2/ZoB1isEVDP/2CpWiBpjifa3F9kmMPItYGRYxahRnFpUllqka2ygl1SUmZ5RkpuYmaNraGC sl5taXJyYnpqTmFSsl5yfu4kRGCr1DAyMOxg7T/gdYpTkYFIS5U3O8IgU4kvKT6nMSCzOiC8q zUktPsQow8GhJMG7rRsoJ1iUmp5akZaZAwxamLQEB4+SCO+2QqA0b3FBYm5xZjpE6hSjLseG1 eu/MAmx5OXnpUqJ8yaBzBAAKcoozYMbAYugS4yyUsK8jAwMDEI8BalFuZklqPKvGMU5GJWEed NagabwZOaVwG16BXQEE9ARzGdcQI4oSURISTUwaty/I1Qg0llgwx9h0yc2YVWw4AMFRhdphxr HjmpbPX/Xhe4WZj+LrsQnHblfty37ySRBXQWtKXMFObXZHylfuC8tYXzm/9wK8WlheY5r3VJX uF5Zddb6leFpBefdGQoKX6zv3LBc8uQW8yvH6o57U9byVKbsec03xXba1N0z/WR9L+TkWboos RRnJBpqMRcVJwIAhzxT7JsCAAA= X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-15.tower-31.messagelabs.com!1497926911!102342103!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 38583 invoked from network); 20 Jun 2017 02:48:32 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-15.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 20 Jun 2017 02:48:32 -0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v5K2mO6T020019 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Jun 2017 02:48:25 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v5K2mOZg012502 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Jun 2017 02:48:24 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v5K2mNGJ024470; Tue, 20 Jun 2017 02:48:24 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:23 -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:57 -0400 Message-Id: <20170620024759.32562-2-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: aserv0022.oracle.com [141.146.126.234] Cc: andrew.cooper3@citrix.com, jbeulich@suse.com, Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v1 1/3] livepatch: Add local and global symbol resolution. 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 This way we can load livepatches with symbol names that are the same as long as they are local ('static'). The use case here is to replace an existing livepatch with a newer one - and one which has the same local symbols. Without this patch we get: livepatch.c:819: livepatch: xen_local_symbols: duplicate new symbol: revert_hook when loading the new livepatch (before doing the replace). This due to livepatch assuming that all symbols are all global. With this patch: readelf --symbols xen_hello_world.livepatch File: xen_hello_world.livepatch Symbol table '.symtab' contains 55 entries: Num: Value Size Type Bind Vis Ndx Name ..snip.. 34: 0000000000000000 4 OBJECT LOCAL DEFAULT 25 cnt 35: 000000000000000a 8 OBJECT LOCAL DEFAULT 7 __func__.4654 36: 0000000000000065 23 FUNC LOCAL DEFAULT 2 revert_hook 37: 000000000000007c 23 FUNC LOCAL DEFAULT 2 apply_hook 38: 0000000000000093 54 FUNC LOCAL DEFAULT 2 check_fnc ..snip.. 47: 0000000000000000 54 FUNC GLOBAL HIDDEN 2 xen_hello_world 48: 0000000000000000 0 NOTYPE GLOBAL HIDDEN UND xen_extra_version ..snip.. 52: 0000000000000000 0 NOTYPE GLOBAL HIDDEN UND printk 53: 0000000000000000 64 OBJECT GLOBAL HIDDEN 23 livepatch_xen_hello_world All the 'GLOBAL' have to be unique per livepatch. But the 'LOCAL' can all be the same which means the semantic of 'static' on functions and data variables is the right one. Signed-off-by: Konrad Rzeszutek Wilk --- xen/common/livepatch.c | 21 ++++++++++++++------- xen/include/xen/livepatch.h | 3 ++- xen/include/xen/livepatch_elf.h | 7 +++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index df67a1a..2a86218 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -181,7 +181,10 @@ unsigned long livepatch_symbols_lookup_by_name(const char *symname) if ( !data->symtab[i].new_symbol ) continue; - if ( !strcmp(data->symtab[i].name, symname) ) + if ( strcmp(data->symtab[i].name, symname) ) + continue; + + if ( data->symtab[i].global_symbol ) return data->symtab[i].value; } } @@ -791,6 +794,7 @@ static int build_symbol_table(struct payload *payload, symtab[nsyms].size = elf->sym[i].sym->st_size; symtab[nsyms].value = elf->sym[i].sym->st_value; symtab[nsyms].new_symbol = 0; /* May be overwritten below. */ + symtab[nsyms].global_symbol = livepatch_sym_is_global(elf->sym[i].sym); strtab_len += strlcpy(strtab + strtab_len, elf->sym[i].name, KSYM_NAME_LEN) + 1; nsyms++; @@ -815,21 +819,24 @@ static int build_symbol_table(struct payload *payload, if ( symbols_lookup_by_name(symtab[i].name) || livepatch_symbols_lookup_by_name(symtab[i].name) ) { - dprintk(XENLOG_ERR, LIVEPATCH "%s: duplicate new symbol: %s\n", - elf->name, symtab[i].name); + dprintk(XENLOG_ERR, LIVEPATCH "%s: duplicate new %s symbol: %s\n", + elf->name, symtab[i].global_symbol ? "global" : "local", + symtab[i].name); xfree(symtab); xfree(strtab); return -EEXIST; } symtab[i].new_symbol = 1; - dprintk(XENLOG_DEBUG, LIVEPATCH "%s: new symbol %s\n", - elf->name, symtab[i].name); + dprintk(XENLOG_DEBUG, LIVEPATCH "%s: new %s symbol %s\n", + elf->name, symtab[i].global_symbol ? "global" : "local", + symtab[i].name); } else { /* new_symbol is not set. */ - dprintk(XENLOG_DEBUG, LIVEPATCH "%s: overriding symbol %s\n", - elf->name, symtab[i].name); + dprintk(XENLOG_DEBUG, LIVEPATCH "%s: overriding %s symbol %s\n", + elf->name, symtab[i].global_symbol ? "global" : "local", + symtab[i].name); } } diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h index 98ec012..fccff94 100644 --- a/xen/include/xen/livepatch.h +++ b/xen/include/xen/livepatch.h @@ -38,7 +38,8 @@ struct livepatch_symbol { const char *name; unsigned long value; unsigned int size; - bool_t new_symbol; + unsigned int new_symbol:1; + unsigned int global_symbol:1; }; int livepatch_op(struct xen_sysctl_livepatch_op *); diff --git a/xen/include/xen/livepatch_elf.h b/xen/include/xen/livepatch_elf.h index 9ad499e..870c4bc 100644 --- a/xen/include/xen/livepatch_elf.h +++ b/xen/include/xen/livepatch_elf.h @@ -50,6 +50,13 @@ static inline bool livepatch_elf_ignore_section(const Elf_Shdr *sec) { return !(sec->sh_flags & SHF_ALLOC) || sec->sh_size == 0; } + +static inline bool livepatch_sym_is_global(const Elf_Sym *sym) +{ + return ((ELF_ST_BIND(sym->st_info) & STB_GLOBAL) && + (sym->st_shndx != SHN_UNDEF)); +} + #endif /* __XEN_LIVEPATCH_ELF_H__ */ /*