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>
Acked-by: Jan Beulich <jbeulich@suse.com>
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.
a->instrlen - a->replacementlen);
text_poke_early(instr, insnbuf, a->instrlen);
}
+
+ /* Reinstate WP. */
+ write_cr0(cr0);
}
void __init alternative_instructions(void)