From patchwork Wed Sep 21 17:32:25 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: 9343995 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 127D16077A for ; Wed, 21 Sep 2016 17:35:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F41302A83D for ; Wed, 21 Sep 2016 17:35:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E88FE2A846; Wed, 21 Sep 2016 17:35:21 +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 A472D2A83D for ; Wed, 21 Sep 2016 17:35:20 +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 1bmlOP-0003lc-H6; Wed, 21 Sep 2016 17:33:09 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bmlOO-0003kO-Ih for xen-devel@lists.xenproject.org; Wed, 21 Sep 2016 17:33:08 +0000 Received: from [193.109.254.147] by server-8.bemta-6.messagelabs.com id 71/15-05361-354C2E75; Wed, 21 Sep 2016 17:33:07 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRWlGSWpSXmKPExsUyZ7p8oG7wkUf hBtcauCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1owXR9ULpipX7J/9i62B8YVUFyMXh5DAZCaJ ibfXMnUxcgI5fxkl7v3NhEhsZJSY+301C4Qzi1Hi6qqnjF2MHBxsAiYSb1Y5gsRFBPoYJTZe/ c0G0s0M4uw7zQxiCwsESPxqa2UHsVkEVCWOf3vNAmLzCrhJrLl+nRVkjoSAvMSz2/UgYU4Bd4 k7j44wQxzhJnG3/yEriC0hYCzR/vYi2wRGvgWMDKsY1YtTi8pSi3SN9JKKMtMzSnITM3N0DQ3 M9HJTi4sT01NzEpOK9ZLzczcxAoOEAQh2MC7763SIUZKDSUmUt3vLo3AhvqT8lMqMxOKM+KLS nNTiQ4wyHBxKErw6h4FygkWp6akVaZk5wHCFSUtw8CiJ8EaCpHmLCxJzizPTIVKnGBWlxHk9Q BICIImM0jy4NliMXGKUlRLmZQQ6RIinILUoN7MEVf4VozgHo5IwbyzIFJ7MvBK46a+AFjMBLd 7y8wHI4pJEhJRUA2PjtdsyRhZPeJXffH86V8iW213XIq3yyPepEg8bFM78meMZc/5DNX/Rhnn 7n/N47xe6LpH8IaHpn5PHhp+JvcKT/S59u+5oFlXkLPFhY+nLlVHe++N8dj1ld1/x601Wyp2N T5Msvmm3icUf1H31wONlG29R/x89l/cSq5Ru//rp6iTjrKMtpanEUpyRaKjFXFScCABolgOuj AIAAA== X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-4.tower-27.messagelabs.com!1474479185!59686361!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: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30139 invoked from network); 21 Sep 2016 17:33:06 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-4.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 21 Sep 2016 17:33:06 -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 u8LHWwhw021402 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Sep 2016 17:32:58 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 u8LHWvQU028719 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Sep 2016 17:32:57 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u8LHWvLb015042; Wed, 21 Sep 2016 17:32:57 GMT Received: from localhost.localdomain.localdomain (/172.58.216.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 21 Sep 2016 10:32:57 -0700 From: Konrad Rzeszutek Wilk To: konrad@kernel.org, xen-devel@lists.xenproject.org, ross.lagerwall@citrix.com, sstabellini@kernel.org, julien.grall@arm.com Date: Wed, 21 Sep 2016 13:32:25 -0400 Message-Id: <1474479154-20991-8-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.4.11 In-Reply-To: <1474479154-20991-1-git-send-email-konrad.wilk@oracle.com> References: <1474479154-20991-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] Cc: Andrew Cooper , Jan Beulich , Konrad Rzeszutek Wilk Subject: [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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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: Andrew Cooper [x86 bits] Signed-off-by: Konrad Rzeszutek Wilk Acked-by: Julien Grall Reviewed-by: Ross Lagerwall --- 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. --- 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 9284766..9959315 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 == '$' && 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 f2f866c..082f553 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -749,7 +749,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);