From patchwork Fri Sep 23 16:13:24 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: 9348443 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 57035607F2 for ; Fri, 23 Sep 2016 16:16:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48B0F2AC2D for ; Fri, 23 Sep 2016 16:16:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3CD422AC59; Fri, 23 Sep 2016 16:16:09 +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 17D342AC2D for ; Fri, 23 Sep 2016 16:16:07 +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 1bnT6Y-0002lx-Qf; Fri, 23 Sep 2016 16:13:38 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bnT6X-0002lr-Dr for xen-devel@lists.xenproject.org; Fri, 23 Sep 2016 16:13:37 +0000 Received: from [85.158.137.68] by server-8.bemta-3.messagelabs.com id F2/15-10540-0B455E75; Fri, 23 Sep 2016 16:13:36 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrLIsWRWlGSWpSXmKPExsXSO6nOVXdDyNN wg58cFt+3TGZyYPQ4/OEKSwBjFGtmXlJ+RQJrxqIfPgVXdSv+NX5mbmD8rtTFyMUhJNDBJNGy qJcJwvnGKHH++3wWCGcjo8TWJd+ZIZxuIGfrM9YuRk4gp0ji3bSpzCA2i4CqRE9zD3sXIwcHm 4CJxJtVjiBhEQE9ia41zWC9zAL7GSVmPpnNCFIjLBAq8fAbWA2vgLlE8+tOqGVbGSU27ZnCBp EQlDg58wkLiM0soCVx499LJpBeZgFpieX/OEDCnAJ2EvcOvQI7R1RAWWJxfw9Yq4SAsUTfrD6 WCYxCs5BMmoVk0iyESQsYmVcxahSnFpWlFukameklFWWmZ5TkJmbm6BoaGOvlphYXJ6an5iQm Fesl5+duYgQGcz0DA+MOxoa9focYJTmYlER5ldyehgvxJeWnVGYkFmfEF5XmpBYfYpTh4FCS4 HUwAMoJFqWmp1akZeYA4womLcHBoyTCezAYKM1bXJCYW5yZDpE6xagoJc67HCQhAJLIKM2Da4 PF8iVGWSlhXkYGBgYhnoLUotzMElT5V4ziHIxKwrxPQKbwZOaVwE1/BbSYCWjxtztPQBaXJCK kpBoY04Juzt+ld/Ld1Zu7bJltuB3/KyqsNfxlF7vyz/QKi7mrYg9lfd1n8CJyDv+kag25jtMF 3ZeDqv88PaAQFyp26g/f1qWWJo4dXDPX35tq4Bt/qrhvyzaX+VNLa6JtIwTqL3O9sl1wTfR62 J5zx0SfrxNuNft0wp/juHTfjT2L/yQf3VR9MmRzuxJLcUaioRZzUXEiAMpnqEHgAgAA X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-10.tower-31.messagelabs.com!1474647214!61691309!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 27730 invoked from network); 23 Sep 2016 16:13:35 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-10.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 23 Sep 2016 16:13:35 -0000 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u8NGDRDB017656 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 23 Sep 2016 16:13:27 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u8NGDQYm026070 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 23 Sep 2016 16:13:26 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u8NGDQPw027060; Fri, 23 Sep 2016 16:13:26 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 23 Sep 2016 09:13:26 -0700 Received: by char.us.oracle.com (Postfix, from userid 1000) id 079B56A0DEF; Fri, 23 Sep 2016 12:13:24 -0400 (EDT) Date: Fri, 23 Sep 2016 12:13:24 -0400 From: Konrad Rzeszutek Wilk To: Ross Lagerwall Message-ID: <20160923161324.GF25028@char.us.oracle.com> References: <1474479154-20991-1-git-send-email-konrad.wilk@oracle.com> <1474479154-20991-8-git-send-email-konrad.wilk@oracle.com> <08c3bd1d-c18e-43ae-a670-6196ef963a68@citrix.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <08c3bd1d-c18e-43ae-a670-6196ef963a68@citrix.com> User-Agent: Mutt/1.6.2 (2016-07-01) X-Source-IP: aserv0021.oracle.com [141.146.126.233] Cc: sstabellini@kernel.org, Andrew Cooper , julien.grall@arm.com, Jan Beulich , xen-devel@lists.xenproject.org Subject: Re: [Xen-devel] [PATCH v5 07/16] livepatch: ARM 32|64: Ignore mapping symbols: $[d, a, x] 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP > > +bool arch_livepatch_symbol_ok(const struct livepatch_elf *elf, > > + const struct livepatch_elf_sym *sym) > > +{ > > + /* > > + * - Mapping symbols - denote the "start of a sequence of bytes of the > > + * appropriate type" to mark certain features - such as start of region > > + * containing data ($d); ARM ($a), or A64 ($x) instructions. > > + * We ignore Thumb instructions ($t) as we shouldn't have them. > > + * > > + * The format is either short: '$x' or long: '$x.'. We do not > > + * need this and more importantly - each payload will contain this > > + * resulting in symbol collisions. > > + */ > > + if ( *sym->name == '$' && sym->name[1] != '\0' ) > > This would be clear (IMO) as sym->name[0]. > > Either way, > > Reviewed-by: Ross Lagerwall Updated it to be: From e6cafccb4a869e3e649c2295c5003435299fb7df Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Wilk Date: Fri, 12 Aug 2016 23:08:32 -0400 Subject: [PATCH v6] livepatch: ARM 32|64: Ignore mapping symbols: $[d,a,x] Those symbols are used to help final linkers to replace insn. The ARM ELF specification mandates that they are present to denote the start of certain CPU features. There are two variants of it - short and long format. Either way - we can ignore these symbols. Reviewed-by: Ross Lagerwall Acked-by: Julien Grall Reviewed-by: Andrew Cooper [x86 bits] Signed-off-by: Konrad Rzeszutek Wilk --- Cc: Konrad Rzeszutek Wilk Cc: Ross Lagerwall Cc: Stefano Stabellini Cc: Julien Grall Cc: Andrew Cooper v1: First submission v2: Update the order of symbols, fix title Add {} in after the first if - per Jan's recommendation. v3: Add Andrew's Review tag Make the function return an bool_t. Skip check for '$t' Fix spelling of comments. s/arch_is_payload_symbol/arch_livepatch_symbol_ok/ v4: s/bool_t/bool/ v5: Removed an extra space in the conditional. v6: Added Julien's Acked-by. s/*sym-name/sym-name[0]/ on the NULL check. Added Julien's Reviewed-by --- xen/arch/arm/livepatch.c | 33 +++++++++++++++++++++++++++++++++ xen/arch/x86/livepatch.c | 7 +++++++ xen/common/livepatch.c | 2 +- xen/include/xen/livepatch.h | 2 ++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c index 679abf1..f467d9d 100644 --- a/xen/arch/arm/livepatch.c +++ b/xen/arch/arm/livepatch.c @@ -84,6 +84,39 @@ void arch_livepatch_unmask(void) local_abort_enable(); } +bool arch_livepatch_symbol_ok(const struct livepatch_elf *elf, + const struct livepatch_elf_sym *sym) +{ + /* + * - Mapping symbols - denote the "start of a sequence of bytes of the + * appropriate type" to mark certain features - such as start of region + * containing data ($d); ARM ($a), or A64 ($x) instructions. + * We ignore Thumb instructions ($t) as we shouldn't have them. + * + * The format is either short: '$x' or long: '$x.'. We do not + * need this and more importantly - each payload will contain this + * resulting in symbol collisions. + */ + if ( sym->name[0] == '$' && sym->name[1] != '\0' ) + { + char p = sym->name[1]; + size_t len = strlen(sym->name); + + if ( (len >= 3 && (sym->name[2] == '.' )) || (len == 2) ) + { + if ( p == 'd' || +#ifdef CONFIG_ARM_32 + p == 'a' +#else + p == 'x' +#endif + ) + return false; + } + } + return true; +} + int arch_livepatch_perform_rel(struct livepatch_elf *elf, const struct livepatch_elf_sec *base, const struct livepatch_elf_sec *rela) diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c index b0d81d7..7a369a0 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -124,6 +124,13 @@ int arch_livepatch_verify_elf(const struct livepatch_elf *elf) return 0; } +bool arch_livepatch_symbol_ok(const struct livepatch_elf *elf, + const struct livepatch_elf_sym *sym) +{ + /* No special checks on x86. */ + return true; +} + int arch_livepatch_perform_rel(struct livepatch_elf *elf, const struct livepatch_elf_sec *base, const struct livepatch_elf_sec *rela) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 2d08c9a..fc8ef99 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -747,7 +747,7 @@ static bool_t is_payload_symbol(const struct livepatch_elf *elf, !strncmp(sym->name, ".L", 2) ) return 0; - return 1; + return arch_livepatch_symbol_ok(elf, sym); } static int build_symbol_table(struct payload *payload, diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h index b7b84e7..e8c67d6 100644 --- a/xen/include/xen/livepatch.h +++ b/xen/include/xen/livepatch.h @@ -48,6 +48,8 @@ bool_t is_patch(const void *addr); /* Arch hooks. */ int arch_livepatch_verify_elf(const struct livepatch_elf *elf); +bool arch_livepatch_symbol_ok(const struct livepatch_elf *elf, + const struct livepatch_elf_sym *sym); int arch_livepatch_perform_rel(struct livepatch_elf *elf, const struct livepatch_elf_sec *base, const struct livepatch_elf_sec *rela);