#include <asm/system.h>
#include <asm/traps.h>
#include <asm/nmi.h>
+#include <xen/xsplice.h>
#define MAX_PATCH_LEN (255-1)
extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
#ifdef K8_NOP1
-static const unsigned char k8nops[] __initconst = {
+static const unsigned char k8nops[] init_or_xsplice_const = {
K8_NOP1,
K8_NOP2,
K8_NOP3,
K8_NOP7,
K8_NOP8
};
-static const unsigned char * const k8_nops[ASM_NOP_MAX+1] __initconstrel = {
+static const unsigned char * const k8_nops[ASM_NOP_MAX+1] init_or_xsplice_constrel = {
NULL,
k8nops,
k8nops + 1,
#endif
#ifdef P6_NOP1
-static const unsigned char p6nops[] __initconst = {
+static const unsigned char p6nops[] init_or_xsplice_const = {
P6_NOP1,
P6_NOP2,
P6_NOP3,
P6_NOP7,
P6_NOP8
};
-static const unsigned char * const p6_nops[ASM_NOP_MAX+1] __initconstrel = {
+static const unsigned char * const p6_nops[ASM_NOP_MAX+1] init_or_xsplice_constrel = {
NULL,
p6nops,
p6nops + 1,
};
#endif
-static const unsigned char * const *ideal_nops __initdata = k8_nops;
+static const unsigned char * const *ideal_nops init_or_xsplice_data = k8_nops;
static int __init mask_nmi_callback(const struct cpu_user_regs *regs, int cpu)
{
}
/* 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 init_or_xsplice add_nops(void *insns, unsigned int len)
{
while ( len > 0 )
{
}
/*
- * text_poke_early - Update instructions on a live kernel at boot time
+ * text_poke - Update instructions on a live kernel or non-executed code.
* @addr: address to modify
* @opcode: source of the copy
* @len: length to copy
* instructions. And on the local CPU you need to be protected again NMI or MCE
* handlers seeing an inconsistent instruction while you patch.
*
- * This routine is called with local interrupt disabled.
+ * You should run this with interrupts disabled or on code that is not
+ * executing.
*/
-static void *__init text_poke_early(void *addr, const void *opcode, size_t len)
+static void *init_or_xsplice text_poke(void *addr, const void *opcode, size_t len)
{
memcpy(addr, opcode, len);
sync_core();
* 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 init_or_xsplice apply_alternatives_nocheck(struct alt_instr *start, struct alt_instr *end)
{
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.
add_nops(insnbuf + a->replacementlen,
a->instrlen - a->replacementlen);
- text_poke_early(instr, insnbuf, a->instrlen);
+ text_poke(instr, insnbuf, a->instrlen);
}
+}
+
+/*
+ * This routine is called with local interrupt disabled and used during
+ * bootup.
+ */
+void __init apply_alternatives(struct alt_instr *start, struct alt_instr *end)
+{
+ unsigned long cr0 = read_cr0();
+
+ ASSERT(!local_irq_is_enabled());
+
+ /* Disable WP to allow application of alternatives to read-only pages. */
+ write_cr0(cr0 & ~X86_CR0_WP);
+
+ apply_alternatives_nocheck(start, end);
/* Reinstate WP. */
write_cr0(cr0);
}
#ifndef CONFIG_ARM
+ sec = xsplice_elf_sec_by_name(elf, ".altinstructions");
+ if ( sec )
+ {
+ struct alt_instr *a, *start, *end;
+
+ if ( sec->sec->sh_size % sizeof(*a) )
+ {
+ dprintk(XENLOG_ERR, XSPLICE "%s: Size of .alt_instr is not multiple of %zu!\n",
+ elf->name, sizeof(*a));
+ return -EINVAL;
+ }
+
+ start = sec->load_addr;
+ end = sec->load_addr + sec->sec->sh_size;
+
+ for ( a = start; a < end; a++ )
+ {
+ const void *instr = &a->instr_offset + a->instr_offset;
+ const void *replacement = &a->repl_offset + a->repl_offset;
+
+ if ( (instr < region->start && instr >= region->end) ||
+ (replacement < region->start && replacement >= region->end) )
+ {
+ dprintk(XENLOG_ERR, XSPLICE "%s Alt patching outside payload: %p!\n",
+ elf->name, instr);
+ return -EINVAL;
+ }
+ }
+ apply_alternatives_nocheck(start, end);
+ }
+
sec = xsplice_elf_sec_by_name(elf, ".ex_table");
if ( sec )
{