From patchwork Tue Feb 23 16:31:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 8394271 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A3B04C0553 for ; Tue, 23 Feb 2016 16:34:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D4E84202EC for ; Tue, 23 Feb 2016 16:34:07 +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 F2428202F8 for ; Tue, 23 Feb 2016 16:34:06 +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 1aYFsI-0002I1-Qm; Tue, 23 Feb 2016 16:31:46 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aYFsH-0002HR-3C for xen-devel@lists.xen.org; Tue, 23 Feb 2016 16:31:45 +0000 Received: from [193.109.254.147] by server-8.bemta-14.messagelabs.com id BA/81-24450-0798CC65; Tue, 23 Feb 2016 16:31:44 +0000 X-Env-Sender: prvs=8544ffb4f=Andrew.Cooper3@citrix.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1456245102!26083253!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 16971 invoked from network); 23 Feb 2016 16:31:43 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-7.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 23 Feb 2016 16:31:43 -0000 X-IronPort-AV: E=Sophos;i="5.22,490,1449532800"; d="scan'208";a="333705412" From: Andrew Cooper To: Xen-devel Date: Tue, 23 Feb 2016 16:31:22 +0000 Message-ID: <1456245085-2302-6-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1456245085-2302-1-git-send-email-andrew.cooper3@citrix.com> References: <1456245085-2302-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Andrew Cooper , Jan Beulich Subject: [Xen-devel] [PATCH v2 5/8] xen/x86: Disable CR0.WP while applying 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: , 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 In preparation for marking .text as read-only, care needs to be taken not to fault while applying alternatives. Swapping back to RW mappings is a possibility, but would require additional TLB management. A temporary disabling of CR0.WP is cleaner. Signed-off-by: Andrew Cooper --- CC: Jan Beulich New in v2. (The one downside of my very-quick-to-reboot test box is that it is sufficiently old to not have any alternatives needing patching.) --- xen/arch/x86/alternative.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c index 46ac0fd..d123fa7 100644 --- a/xen/arch/x86/alternative.c +++ b/xen/arch/x86/alternative.c @@ -147,11 +147,15 @@ static void __init apply_alternatives(struct alt_instr *start, struct alt_instr struct alt_instr *a; u8 *instr, *replacement; u8 insnbuf[MAX_PATCH_LEN]; + unsigned long cr0 = read_cr0(); ASSERT(!local_irq_is_enabled()); printk(KERN_INFO "alt table %p -> %p\n", start, end); + /* Disable WP to allow application of alternatives to read-only pages. */ + write_cr0(cr0 & ~X86_CR0_WP); + /* * The scan order should be from start to end. A later scanned * alternative code can overwrite a previous scanned alternative code. @@ -181,6 +185,9 @@ static void __init apply_alternatives(struct alt_instr *start, struct alt_instr a->instrlen - a->replacementlen); text_poke_early(instr, insnbuf, a->instrlen); } + + /* Reinstate WP. */ + write_cr0(cr0); } void __init alternative_instructions(void)