From patchwork Thu Jan 14 21:47:11 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: 8035681 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 747769F1C0 for ; Thu, 14 Jan 2016 21:49:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7196320251 for ; Thu, 14 Jan 2016 21:49:56 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5CFC320357 for ; Thu, 14 Jan 2016 21:49:55 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aJpjs-0006RS-6P; Thu, 14 Jan 2016 21:47:28 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aJpjq-0006Qu-9r for xen-devel@lists.xenproject.org; Thu, 14 Jan 2016 21:47:26 +0000 Received: from [85.158.139.211] by server-6.bemta-5.messagelabs.com id 8F/6B-22089-D6718965; Thu, 14 Jan 2016 21:47:25 +0000 X-Env-Sender: konrad@char.us.oracle.com X-Msg-Ref: server-13.tower-206.messagelabs.com!1452808043!15701647!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: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26804 invoked from network); 14 Jan 2016 21:47:24 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-13.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 14 Jan 2016 21:47:24 -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 u0ELlL17014884 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Thu, 14 Jan 2016 21:47:21 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u0ELlKQo016068 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Thu, 14 Jan 2016 21:47:21 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u0ELlKV7003174; Thu, 14 Jan 2016 21:47:20 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 14 Jan 2016 13:47:19 -0800 Received: by char.us.oracle.com (Postfix, from userid 1000) id D26746A4DBE; Thu, 14 Jan 2016 16:47:17 -0500 (EST) From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, ross.lagerwall@citrix.com, mpohlack@amazon.com, andrew.cooper3@citrix.com, stefano.stabellini@citrix.com, jbeulich@suse.com, ian.jackson@eu.citrix.com, ian.campbell@citrix.com, wei.liu2@citrix.com, sasha.levin@oracle.com Date: Thu, 14 Jan 2016 16:47:11 -0500 Message-Id: <1452808031-706-14-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1452808031-706-1-git-send-email-konrad.wilk@oracle.com> References: <1452808031-706-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 13/13] xsplice: Add support for alternatives X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ross Lagerwall Add support for applying alternative sections within xsplice modules. At module load time, apply an alternative sections that are found. Signed-off-by: Ross Lagerwall Signed-off-by: Konrad Rzeszutek Wilk --- xen/arch/x86/Makefile | 2 +- xen/arch/x86/alternative.c | 12 ++++++------ xen/common/xsplice.c | 10 +++++++++- xen/include/asm-x86/alternative.h | 1 + 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile index f7d3e39..60249ab 100644 --- a/xen/arch/x86/Makefile +++ b/xen/arch/x86/Makefile @@ -6,7 +6,7 @@ subdir-y += mm subdir-y += oprofile subdir-y += x86_64 -obj-bin-y += alternative.init.o +obj-bin-y += alternative.o obj-y += apic.o obj-y += bitops.o obj-bin-y += bzimage.init.o diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c index 46ac0fd..8d895ad 100644 --- a/xen/arch/x86/alternative.c +++ b/xen/arch/x86/alternative.c @@ -28,7 +28,7 @@ extern struct alt_instr __alt_instructions[], __alt_instructions_end[]; #ifdef K8_NOP1 -static const unsigned char k8nops[] __initconst = { +static const unsigned char k8nops[] = { K8_NOP1, K8_NOP2, K8_NOP3, @@ -52,7 +52,7 @@ static const unsigned char * const k8_nops[ASM_NOP_MAX+1] = { #endif #ifdef P6_NOP1 -static const unsigned char p6nops[] __initconst = { +static const unsigned char p6nops[] = { P6_NOP1, P6_NOP2, P6_NOP3, @@ -75,7 +75,7 @@ static const unsigned char * const p6_nops[ASM_NOP_MAX+1] = { }; #endif -static const unsigned char * const *ideal_nops __initdata = k8_nops; +static const unsigned char * const *ideal_nops = k8_nops; static int __init mask_nmi_callback(const struct cpu_user_regs *regs, int cpu) { @@ -100,7 +100,7 @@ static void __init arch_init_ideal_nops(void) } /* Use this to add nops to a buffer, then text_poke the whole buffer. */ -static void __init add_nops(void *insns, unsigned int len) +static void add_nops(void *insns, unsigned int len) { while ( len > 0 ) { @@ -127,7 +127,7 @@ static void __init add_nops(void *insns, unsigned int len) * * This routine is called with local interrupt disabled. */ -static void *__init text_poke_early(void *addr, const void *opcode, size_t len) +static void *text_poke_early(void *addr, const void *opcode, size_t len) { memcpy(addr, opcode, len); sync_core(); @@ -142,7 +142,7 @@ static void *__init text_poke_early(void *addr, const void *opcode, size_t len) * APs have less capabilities than the boot processor are not handled. * Tough. Make sure you disable such features by hand. */ -static void __init apply_alternatives(struct alt_instr *start, struct alt_instr *end) +void apply_alternatives(struct alt_instr *start, struct alt_instr *end) { struct alt_instr *a; u8 *instr, *replacement; diff --git a/xen/common/xsplice.c b/xen/common/xsplice.c index 53a67a9..7866162 100644 --- a/xen/common/xsplice.c +++ b/xen/common/xsplice.c @@ -677,7 +677,7 @@ static int find_special_sections(struct payload *payload, if ( sec ) { if ( ( !sec->sec->sh_size ) || - ( sec->sec->sh_size % sizeof *sec->load_addr ) ) + ( sec->sec->sh_size % sizeof (struct exception_table_entry) ) ) return -EINVAL; payload->start_ex_table = (struct exception_table_entry *)sec->load_addr; @@ -685,6 +685,14 @@ static int find_special_sections(struct payload *payload, sort_exception_table(payload->start_ex_table, payload->stop_ex_table); } + sec = xsplice_elf_sec_by_name(elf, ".altinstructions"); + if ( sec ) + { + local_irq_disable(); + apply_alternatives((struct alt_instr *)sec->load_addr, + (struct alt_instr *)(sec->load_addr + sec->sec->sh_size)); + local_irq_enable(); + } #endif return 0; } diff --git a/xen/include/asm-x86/alternative.h b/xen/include/asm-x86/alternative.h index 7d11354..95c2f7e 100644 --- a/xen/include/asm-x86/alternative.h +++ b/xen/include/asm-x86/alternative.h @@ -23,6 +23,7 @@ struct alt_instr { u8 replacementlen; /* length of new instruction, <= instrlen */ }; +extern void apply_alternatives(struct alt_instr *start, struct alt_instr *end); extern void alternative_instructions(void); #define OLDINSTR(oldinstr) "661:\n\t" oldinstr "\n662:\n"