From patchwork Wed Feb 24 19:07:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 8411451 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 58E6BC0553 for ; Wed, 24 Feb 2016 19:10:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6BD902035B for ; Wed, 24 Feb 2016 19:10:47 +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 7B9C0202E6 for ; Wed, 24 Feb 2016 19:10:46 +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 1aYemo-0002Fm-7x; Wed, 24 Feb 2016 19:07:46 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aYeml-0002Ev-DG for xen-devel@lists.xen.org; Wed, 24 Feb 2016 19:07:43 +0000 Received: from [85.158.137.68] by server-4.bemta-3.messagelabs.com id 1A/68-03606-E7FFDC65; Wed, 24 Feb 2016 19:07:42 +0000 X-Env-Sender: prvs=8552da0fd=Andrew.Cooper3@citrix.com X-Msg-Ref: server-5.tower-31.messagelabs.com!1456340859!24834267!3 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 26196 invoked from network); 24 Feb 2016 19:07:42 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-5.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 24 Feb 2016 19:07:42 -0000 X-IronPort-AV: E=Sophos;i="5.22,494,1449532800"; d="scan'208";a="334263052" From: Andrew Cooper To: Xen-devel Date: Wed, 24 Feb 2016 19:07:33 +0000 Message-ID: <1456340856-3065-6-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1456340856-3065-1-git-send-email-andrew.cooper3@citrix.com> References: <1456340856-3065-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Andrew Cooper , Jan Beulich Subject: [Xen-devel] [PATCH] 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)