On Fri, 25 Apr 2008, Andi Kleen wrote: > > So all these checks can be just removed. Quite frankly, I'd rather tighten them up. All the callers actually seem to do just a single-byte one. So I'd suggest really tightening it up to require total natural alignment (rather than the weaker version that required that it fit in an aligned unsigned long or whatever). And I'd suggest using FIXMAP's instead of vmap. Maybe something like the appended (TOTALLY UNTESTED!) Linus --- arch/x86/kernel/alternative.c | 32 ++++++++++++++++---------------- include/asm-x86/fixmap_32.h | 1 + include/asm-x86/fixmap_64.h | 1 + 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index df4099d..6172e40 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -508,24 +508,24 @@ void *text_poke_early(void *addr, const void *opcode, size_t len) */ void *__kprobes text_poke(void *addr, const void *opcode, size_t len) { - unsigned long flags; - char *vaddr; - int nr_pages = 2; + static DEFINE_SPINLOCK(poke_lock); + unsigned long flags, bits; + bits = (unsigned long) addr; BUG_ON(len > sizeof(long)); - BUG_ON((((long)addr + len - 1) & ~(sizeof(long) - 1)) - - ((long)addr & ~(sizeof(long) - 1))); - if (kernel_text_address((unsigned long)addr)) { - struct page *pages[2] = { virt_to_page(addr), - virt_to_page(addr + PAGE_SIZE) }; - if (!pages[1]) - nr_pages = 1; - vaddr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL); - BUG_ON(!vaddr); - local_irq_save(flags); - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len); - local_irq_restore(flags); - vunmap(vaddr); + BUG_ON(len & (len-1)); + BUG_ON(bits & (len-1)); + + if (core_kernel_text(bits)) { + unsigned long phys = __pa(addr); + unsigned long offset = phys & ~PAGE_MASK; + unsigned long virt = fix_to_virt(FIX_POKE); + phys &= PAGE_MASK; + + spin_lock_irqsave(&poke_lock, flags); + set_fixmap(FIX_POKE, phys); + memcpy((void *)(virt + offset), opcode, len); + spin_unlock_irqrestore(&poke_lock, flags); } else { /* * modules are in vmalloc'ed memory, always writable. diff --git a/include/asm-x86/fixmap_32.h b/include/asm-x86/fixmap_32.h index eb16651..1f6df95 100644 --- a/include/asm-x86/fixmap_32.h +++ b/include/asm-x86/fixmap_32.h @@ -55,6 +55,7 @@ enum fixed_addresses { FIX_HOLE, FIX_VDSO, FIX_DBGP_BASE, + FIX_POKE, FIX_EARLYCON_MEM_BASE, #ifdef CONFIG_X86_LOCAL_APIC FIX_APIC_BASE, /* local (CPU) APIC) -- required for SMP or not */ diff --git a/include/asm-x86/fixmap_64.h b/include/asm-x86/fixmap_64.h index f3d7685..75e6004 100644 --- a/include/asm-x86/fixmap_64.h +++ b/include/asm-x86/fixmap_64.h @@ -37,6 +37,7 @@ enum fixed_addresses { VSYSCALL_FIRST_PAGE = VSYSCALL_LAST_PAGE + ((VSYSCALL_END-VSYSCALL_START) >> PAGE_SHIFT) - 1, VSYSCALL_HPET, + FIX_POKE, FIX_DBGP_BASE, FIX_EARLYCON_MEM_BASE, FIX_HPET_BASE, -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html