From patchwork Thu Aug 25 13:37:20 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: 9299375 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 5199B60459 for ; Thu, 25 Aug 2016 13:40:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 438C429332 for ; Thu, 25 Aug 2016 13:40:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3858029335; Thu, 25 Aug 2016 13:40:29 +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 3A78929332 for ; Thu, 25 Aug 2016 13:40:28 +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 1bcur4-0000tg-Vw; Thu, 25 Aug 2016 13:38:02 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bcur3-0000sF-BU for xen-devel@lists.xenproject.org; Thu, 25 Aug 2016 13:38:01 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id C8/E7-05661-8B4FEB75; Thu, 25 Aug 2016 13:38:00 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsXSO6nOVXfHl33 hBrseiFl83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBm/5/xmLLgoXtH35QdzA+M+wS5GLg4hgQ4m if61F5ghnG+MEmv/rIJyNjJKzL52mA3CmcYo8eznZZYuRg4ONgETiTerHEHiIgJ9jBKHj24C6 uDkYBYwkpjc+I4FxBYWiJPo6Z7HDmKzCKhKnG3fzwRi8wq4SfS/WQo2R0JAXuLZ7XqQMKeAu8 Tvhs1sILYQUMn3Sx1gYyQEjCX6ZvWxTGDkW8DIsIpRvTi1qCy1SNdEL6koMz2jJDcxM0fX0MB MLze1uDgxPTUnMalYLzk/dxMjMFAYgGAHY/dl/0OMkhxMSqK82iv2hQvxJeWnVGYkFmfEF5Xm pBYfYpTh4FCS4J3yGSgnWJSanlqRlpkDDFmYtAQHj5IIrxlImre4IDG3ODMdInWKUVFKnLcKJ CEAksgozYNrg8XJJUZZKWFeRqBDhHgKUotyM0tQ5V8xinMwKgnzVoNM4cnMK4Gb/gpoMRPQ4p b7u0EWlyQipKQaGEXKY2O1PfcxL/uQI9Yluir4YUiXVYOT29qEBSejz/b2y3C2pc9v/XHxg/F PJv+YY943LBPnlcnvmnjhkWb1f4vUfZbdqvJrO7WfzfiX98nxz4EzrxNf31I+Wtu933PRujet j1s+PprqrTk71U5p5+zr+2Q3NeW8u+bB4DDvQu31vDsNK6RbbZRYijMSDbWYi4oTAeMfC7+OA gAA X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-8.tower-21.messagelabs.com!1472132278!30036990!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 29025 invoked from network); 25 Aug 2016 13:38:00 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-8.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 25 Aug 2016 13:38:00 -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 u7PDbnXd006092 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 25 Aug 2016 13:37:49 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 u7PDbnPm021829 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 25 Aug 2016 13:37:49 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u7PDbmvU020683; Thu, 25 Aug 2016 13:37:48 GMT Received: from localhost.event.rightround.com (/75.98.193.200) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 25 Aug 2016 06:37:48 -0700 From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, konrad@kernel.org, ross.lagerwall@citrix.com, sstabellini@kernel.org, julien.grall@arm.com Date: Thu, 25 Aug 2016 09:37:20 -0400 Message-Id: <1472132255-23470-6-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.4.11 In-Reply-To: <1472132255-23470-1-git-send-email-konrad.wilk@oracle.com> References: <1472132255-23470-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: aserv0021.oracle.com [141.146.126.233] Cc: Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v2 05/20] arm64/alternatives: Make it possible to patch outside of hypervisor. 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 With livepatching the alternatives that should be patched are outside the Xen hypervisor _start -> _end. As such having to use an alternative VA is not neccessary. In fact we can use the ones that the caller provided us with. Signed-off-by: Konrad Rzeszutek Wilk --- Cc: Stefano Stabellini Cc: Julien Grall v2: First version --- xen/arch/arm/alternative.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c index aba06db..90a857a 100644 --- a/xen/arch/arm/alternative.c +++ b/xen/arch/arm/alternative.c @@ -94,24 +94,30 @@ static int __apply_alternatives(const struct alt_region *region) { const struct alt_instr *alt; const u32 *origptr, *replptr; - u32 *writeptr, *writemap; + u32 *writeptr, *writemap = NULL; mfn_t text_mfn = _mfn(virt_to_mfn(_stext)); unsigned int text_order = get_order_from_bytes(_end - _start); - printk(XENLOG_INFO "alternatives: Patching kernel code\n"); - - /* - * The text section is read-only. So re-map Xen to be able to patch - * the code. - */ - writemap = __vmap(&text_mfn, 1 << text_order, 1, 1, PAGE_HYPERVISOR, - VMAP_DEFAULT); - if ( !writemap ) + if ( region->begin >= __alt_instructions && + region->end <= __alt_instructions_end ) { - printk(XENLOG_ERR "alternatives: Unable to map the text section (size %u)\n", - 1 << text_order); - return -ENOMEM; + printk(XENLOG_INFO "alternatives: Patching kernel code\n"); + /* + * The text section is read-only. So re-map Xen to be able to patch + * the code. + */ + writemap = __vmap(&text_mfn, 1 << text_order, 1, 1, PAGE_HYPERVISOR, + VMAP_DEFAULT); + if ( !writemap ) + { + printk(XENLOG_ERR "alternatives: Unable to map the text section (size %u)\n", + 1 << text_order); + return -ENOMEM; + } } + else + printk(XENLOG_INFO "alternatives: Patching %p -> %p\n", + region->begin, region->end); for ( alt = region->begin; alt < region->end; alt++ ) { @@ -124,8 +130,11 @@ static int __apply_alternatives(const struct alt_region *region) BUG_ON(alt->alt_len != alt->orig_len); origptr = ALT_ORIG_PTR(alt); - writeptr = origptr - (u32 *)_start + writemap; replptr = ALT_REPL_PTR(alt); + if ( writemap ) + writeptr = origptr - (u32 *)_start + writemap; + else + writeptr = (u32 *)origptr; nr_inst = alt->alt_len / sizeof(insn); @@ -143,7 +152,8 @@ static int __apply_alternatives(const struct alt_region *region) /* Nuke the instruction cache */ invalidate_icache(); - vunmap(writemap); + if ( writemap ) + vunmap(writemap); return 0; }