From patchwork Tue Sep 12 00:37:25 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: 9948241 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 7AA34603F3 for ; Tue, 12 Sep 2017 00:41:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C96F28D33 for ; Tue, 12 Sep 2017 00:41:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 612EF28D5D; Tue, 12 Sep 2017 00:41:11 +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 2F7B228D77 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 1drZDL-0000uo-5E; Tue, 12 Sep 2017 00:38:07 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drZDK-0000ry-DC for xen-devel@lists.xenproject.org; Tue, 12 Sep 2017 00:38:06 +0000 Received: from [85.158.137.68] by server-3.bemta-3.messagelabs.com id 2E/73-02046-D6C27B95; Tue, 12 Sep 2017 00:38:05 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKIsWRWlGSWpSXmKPExsVyMfTOEd0cne2 RBk1vLSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1owls98yF3zRrHi+bj5TA+NDuS5GTg4hgRmM Ert76roYuThYBD6wSEy/sYURxJEQmMYq8fnwdXaQKgmBOImvZ6YwQ9hpEscbF7BC2OUSl7rvs UFMUpLYMvkxWLOQwEEmiXm7HjOBJIQF9CQmf7vNCGKzCehLPF17DWgQB1Czm8Sna1wg9SIC7Y wSs6/8AhvKLGAo0fr2KBtEr4/EiYufwOawCKhKHDoyiRWkl1fASmLdNwOIG+QlJvZOAxvPCRT +/WMeK8Q9lhIdC64wTWAUXsDIsIpRozi1qCy1SNfYQC+pKDM9oyQ3MTNH19DAWC83tbg4MT01 JzGpWC85P3cTIzBA6xkYGHcwdp7wO8QoycGkJMr7W3h7pBBfUn5KZUZicUZ8UWlOavEhRhkOD iUJXkNtoJxgUWp6akVaZg4wVmDSEhw8SiK8WVpAad7igsTc4sx0iNQpRnuOC3cu/WHiOLbpMp A8sOcWkOy4efcPkxBLXn5eqpQ4bxHIVAGQtozSPLihsNi+xCgrJczLyMDAIMRTkFqUm1mCKv+ KUZyDUUmYVx1kCk9mXgnc7ldAZzEBncVzaQvIWSWJCCmpBkajdYduhHzOuzyr0mRVadW0/2+D mfUWbRNe+qkvusD4uIsxV55Yx5ejCc8/bZ38VaGbx0mnvWbZLJdmd/PoNvtXH9fX2myP4z0T6 L41szjZnD28V87ojsqFzfV2ux/Hc73PbJye/mPxBx932wv3Nr72e6damvPO2Ur2R1yHd/ALts frfUO97iuxFGckGmoxFxUnAgBSDyja6AIAAA== X-Env-Sender: ketuzsezr@gmail.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1505176683!114124548!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 5599 invoked from network); 12 Sep 2017 00:38:04 -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:04 -0000 Received: by mail-qk0-f196.google.com with SMTP id c69so6371834qke.5 for ; Mon, 11 Sep 2017 17:38:04 -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=P7a27S2rFyscDersi1TkS8R2eyEjWQMe+RQC11FTbfk=; b=Spxp8Z/zGgXL3DA7H7zc5WmhgZdZAB2V+JeDepk2AKERDRWbOo8mAOAaYQ8qPCTMt4 J5zf4I3FsUY/wfNmRI7XgiOTE//dxYLADclLj2nFc35lMm7kTX0ud9QQES5ZnsgyKPQU rZunjUmF736A4DaRS2sZYkgO6Zu0kfS9jmTpuRvebHa5e+WullOtmRHWf/nCgJEqkdGU TV7KsyizoTwchGtlCHerhom7/2W2UQ6IcTRqziA3I+QntAHdv6p/tqoLZg9jHkn0Oy2p v3MQKRHrQ5xaQrLXccidG5V0cU2dd5piY1/MVJ+OdIXqxazD51H4nsB9QqQVVCBgQuiS /M/A== 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=P7a27S2rFyscDersi1TkS8R2eyEjWQMe+RQC11FTbfk=; b=NAsymTHURCojDwpr/6clk+pwWOzBvWgKU5px2wM8NApbURHoZ7RfS7/RnnX9P2e9Jl oVXQ6aBqJTssJNcQeR6mX7aYiZQwLwj/Acvmav/sXbUZHdxGuHC1+55DEO9lCkH/N7Sd 56MbqVT8tVSB7p9auRw7PfsB/iylOjRysxWFvmBNXkzHeFBhr2cPVNgElgAKb0SkK4oL ZC61N6qIU57TmqsmRAU4vpgY9dt3NYCRqslYVb3wgyggWp9CjUxoGPtEqSEsYWAXXMov QrYF+34a6wYaTqthXLZGnyD9NTlMbdy/7F8XLRPkqIS4x4nzI4dg1836jI42E8ifjxyM 0LhQ== X-Gm-Message-State: AHPjjUgRRrHqpmJ0rosbkXaguSrxErKa2bHj0HGIlX7JIzKgizAjLDrP DKTT4YS4S6dLj5xa X-Google-Smtp-Source: AOwi7QDJ+GF1N818o6tjFcyWKRRS5+QgBWWqePdx6g2g9NzthEG0dNG8UYug+2hPkUG4ge7gr1vbUA== X-Received: by 10.55.21.5 with SMTP id f5mr13502865qkh.335.1505176683368; Mon, 11 Sep 2017 17:38:03 -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.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Sep 2017 17:38:02 -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:25 -0400 Message-Id: <20170912003726.368-17-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 16/17] 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 --- v1: New version v2: No changes --- 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 2526d3a0ca..5cfce1f2ee 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -187,7 +187,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; } } @@ -804,6 +807,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++; @@ -828,21 +832,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 e529f0e7c3..2f2d3f63e8 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 9ad499ee8b..4d443be1c0 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__ */ /*