From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Jan Beulich <JBeulich@suse.com>
Subject: [PATCH] xen/x86: Disable CR0.WP while applying alternatives
Date: Wed, 24 Feb 2016 19:07:33 +0000 [thread overview]
Message-ID: <1456340856-3065-6-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1456340856-3065-1-git-send-email-andrew.cooper3@citrix.com>
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 <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
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)
--
2.1.4
next prev parent reply other threads:[~2016-02-24 19:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-24 19:07 [PATCH] Map Xen code/data/bss with superpages Andrew Cooper
2016-02-24 19:07 ` [PATCH] xen/lockprof: Move .lockprofile.data into .rodata Andrew Cooper
2016-02-25 11:02 ` Stefano Stabellini
2016-02-25 11:12 ` Stefano Stabellini
2016-02-24 19:07 ` [PATCH] xen/x86: Improvements to build-time pagetable generation Andrew Cooper
2016-02-24 19:07 ` [PATCH] xen/x86: Construct the {l2, l3}_bootmap at compile time Andrew Cooper
2016-02-24 19:07 ` [PATCH] xen/memguard: Drop memguard_init() entirely Andrew Cooper
2016-02-24 19:07 ` Andrew Cooper [this message]
2016-02-24 19:07 ` [PATCH] xen/x86: Reorder .data and .init when linking Andrew Cooper
2016-02-24 19:07 ` [PATCH] xen/x86: Use 2M superpages for text/data/bss mappings Andrew Cooper
2016-02-24 19:07 ` [PATCH] xen/x86: Unilaterally remove .init mappings Andrew Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1456340856-3065-6-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).