From patchwork Thu Aug 25 13:37:19 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: 9299381 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 8AAC860459 for ; Thu, 25 Aug 2016 13:40:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B71729332 for ; Thu, 25 Aug 2016 13:40:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 703D929337; Thu, 25 Aug 2016 13:40:34 +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 DC74329332 for ; Thu, 25 Aug 2016 13:40:33 +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 1bcur3-0000sa-JZ; Thu, 25 Aug 2016 13:38:01 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bcur2-0000s4-BG for xen-devel@lists.xenproject.org; Thu, 25 Aug 2016 13:38:00 +0000 Received: from [85.158.137.68] by server-3.bemta-3.messagelabs.com id 4A/EF-23620-7B4FEB75; Thu, 25 Aug 2016 13:37:59 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsUyZ7p8oO72L/v CDU4+Zbf4vmUykwOjx+EPV1gCGKNYM/OS8isSWDMWT7vFXtCoXbHh8zPmBsZe5S5GLg4hgclM EvO/d7JBOL8ZJd6++coM4WxklFj4+S0ThDONUeLZz8ssXYwcHGwCJhJvVjmCxEUE+hglDh/dB NbBDOJcOXAbyOHkEBbwlzh0YCkLiM0ioCpxfP8zVhCbV8BNouvkESaQQRIC8hLPbteDhDkF3C V+N2xmA7GFgEq+X+oAa5UQMJZof3uRbQIj3wJGhlWM6sWpRWWpRbqGeklFmekZJbmJmTm6hgb GermpxcWJ6ak5iUnFesn5uZsYgaHCAAQ7GJd/dDrEKMnBpCTKq71iX7gQX1J+SmVGYnFGfFFp TmrxIUYZDg4lCV7Vz0A5waLU9NSKtMwcYNDCpCU4eJREeM1A0rzFBYm5xZnpEKlTjIpS4rxVI AkBkERGaR5cGyxSLjHKSgnzMgIdIsRTkFqUm1mCKv+KUZyDUUmYdx/IFJ7MvBK46a+AFjMBLW 65vxtkcUkiQkqqgdH5jstfZW/TbQLn/Y+1Pp6dsb4wy1xKsVwqT2XBhAmcMUdsdz90zdRhi0r 8X7nWhcP/ffLrx9UKEX/inOsbAjf96jTZcd5ebn3yLInXhoIKt2qCyouWBP6Tc53cE5gz7cP5 bd3Sk/07dk6oSZRe0aKy5dFNj4j9V3a5LFSxSmp689P9tZMdgxJLcUaioRZzUXEiADnmCkqPA gAA X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1472132277!40576022!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 63482 invoked from network); 25 Aug 2016 13:37:58 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-12.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 25 Aug 2016 13:37:58 -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 u7PDbnDd030513 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Aug 2016 13:37:49 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id u7PDbmFU009157 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 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 userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u7PDbmLs017595; 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:19 -0400 Message-Id: <1472132255-23470-5-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: aserv0022.oracle.com [141.146.126.234] Cc: Andrew Cooper , Jan Beulich , Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v2 04/20] alternatives: x86 rename and change parameters on ARM 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 On x86 we squash 'apply_alternatives' in to 'alternative_instructions' (who was its sole user) and 'apply_alternatives_nocheck' to 'apply_alternatives'. On ARM we change the parameters for 'apply_alternatives' to be of 'const struct alt_instr *' instead of void pointer and size length. We also add 'const' and make the arguments be on the proper offset. Signed-off-by: Konrad Rzeszutek Wilk Reviewed-by: Andrew Cooper Reviewed-by: Julien Grall --- Cc: Stefano Stabellini Cc: Julien Grall Cc: Andrew Cooper Cc: Jan Beulich v1: First submission. v2: Squash apply_alternatives(old) in alternative_instructions. Add const on x86. --- xen/arch/arm/alternative.c | 4 ++-- xen/arch/x86/alternative.c | 29 ++++++++++++----------------- xen/common/livepatch.c | 2 +- xen/include/asm-arm/alternative.h | 2 +- xen/include/asm-x86/alternative.h | 7 +++---- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c index bf4101c..aba06db 100644 --- a/xen/arch/arm/alternative.c +++ b/xen/arch/arm/alternative.c @@ -200,11 +200,11 @@ void __init apply_alternatives_all(void) BUG_ON(ret); } -int apply_alternatives(void *start, size_t length) +int apply_alternatives(const struct alt_instr *start, const struct alt_instr *end) { const struct alt_region region = { .begin = start, - .end = start + length, + .end = end, }; return __apply_alternatives(®ion); diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c index fd8528e..6eaa10f 100644 --- a/xen/arch/x86/alternative.c +++ b/xen/arch/x86/alternative.c @@ -144,9 +144,10 @@ static void *init_or_livepatch text_poke(void *addr, const void *opcode, size_t * APs have less capabilities than the boot processor are not handled. * Tough. Make sure you disable such features by hand. */ -void init_or_livepatch apply_alternatives_nocheck(struct alt_instr *start, struct alt_instr *end) +void init_or_livepatch apply_alternatives(const struct alt_instr *start, + const struct alt_instr *end) { - struct alt_instr *a; + const struct alt_instr *a; u8 *instr, *replacement; u8 insnbuf[MAX_PATCH_LEN]; @@ -187,24 +188,10 @@ void init_or_livepatch apply_alternatives_nocheck(struct alt_instr *start, struc * This routine is called with local interrupt disabled and used during * bootup. */ -void __init apply_alternatives(struct alt_instr *start, struct alt_instr *end) -{ - unsigned long cr0 = read_cr0(); - - ASSERT(!local_irq_is_enabled()); - - /* Disable WP to allow application of alternatives to read-only pages. */ - write_cr0(cr0 & ~X86_CR0_WP); - - apply_alternatives_nocheck(start, end); - - /* Reinstate WP. */ - write_cr0(cr0); -} - void __init alternative_instructions(void) { nmi_callback_t *saved_nmi_callback; + unsigned long cr0 = read_cr0(); arch_init_ideal_nops(); @@ -225,7 +212,15 @@ void __init alternative_instructions(void) * expect a machine check to cause undue problems during to code * patching. */ + ASSERT(!local_irq_is_enabled()); + + /* Disable WP to allow application of alternatives to read-only pages. */ + write_cr0(cr0 & ~X86_CR0_WP); + apply_alternatives(__alt_instructions, __alt_instructions_end); + /* Reinstate WP. */ + write_cr0(cr0); + set_nmi_callback(saved_nmi_callback); } diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 774a51d..b771c7d 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -713,7 +713,7 @@ static int prepare_payload(struct payload *payload, return -EINVAL; } } - apply_alternatives_nocheck(start, end); + apply_alternatives(start, end); } sec = livepatch_elf_sec_by_name(elf, ".ex_table"); diff --git a/xen/include/asm-arm/alternative.h b/xen/include/asm-arm/alternative.h index f25d3a7..9f88fd9 100644 --- a/xen/include/asm-arm/alternative.h +++ b/xen/include/asm-arm/alternative.h @@ -27,7 +27,7 @@ struct alt_instr { #define ALT_REPL_PTR(a) __ALT_PTR(a, alt_offset) void __init apply_alternatives_all(void); -int apply_alternatives(void *start, size_t length); +int apply_alternatives(const struct alt_instr *start, const struct alt_instr *end); #define ALTINSTR_ENTRY(feature) \ " .word 661b - .\n" /* label */ \ diff --git a/xen/include/asm-x86/alternative.h b/xen/include/asm-x86/alternative.h index de807c8..db4f08e 100644 --- a/xen/include/asm-x86/alternative.h +++ b/xen/include/asm-x86/alternative.h @@ -28,10 +28,9 @@ struct alt_instr { #define ALT_REPL_PTR(a) __ALT_PTR(a, repl_offset) extern void add_nops(void *insns, unsigned int len); -/* Similar to apply_alternatives except it can be run with IRQs enabled. */ -extern void apply_alternatives_nocheck(struct alt_instr *start, - struct alt_instr *end); -extern void apply_alternatives(struct alt_instr *start, struct alt_instr *end); +/* Similar to alternative_instructions except it can be run with IRQs enabled. */ +extern void apply_alternatives(const struct alt_instr *start, + const struct alt_instr *end); extern void alternative_instructions(void); #define OLDINSTR(oldinstr) "661:\n\t" oldinstr "\n662:\n"