This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: [PATCH] x86 - Enhance DEBUG_RODATA support - alternatives
- From: pageexec at freemail dot hu
- To: Mathieu Desnoyers <mathieu dot desnoyers at polymtl dot ca>, Ingo Molnar <mingo at elte dot hu>
- Cc: Srinivasa DS <srinivasa at in dot ibm dot com>, Andrew Morton <akpm at linux-foundation dot org>, linux-kernel at vger dot kernel dot org, ananth at in dot ibm dot com, Jim Keniston <jkenisto at us dot ibm dot com>, srikar at linux dot vnet dot ibm dot com, SystemTAP <systemtap at sources dot redhat dot com>, Andi Kleen <andi at firstfloor dot org>, Thomas Gleixner <tglx at linutronix dot de>, Ingo Molnar <mingo at redhat dot com>, "H. Peter Anvin" <hpa at zytor dot com>, Jeremy Fitzhardinge <jeremy at goop dot org>, Arjan van de Ven <arjan at infradead dot org>
- Date: Thu, 06 Mar 2008 15:59:29 +0200
- Subject: Re: [PATCH] x86 - Enhance DEBUG_RODATA support - alternatives
- References: <200803061811.27555.srinivasa@in.ibm.com>, <20080306134849.GA4088@Krystal>, <20080306140105.GC28438@elte.hu>
- Reply-to: pageexec at freemail dot hu
On 6 Mar 2008 at 15:01, Ingo Molnar wrote:
> +/**
> + * text_poke - Update instructions on a live kernel
> + * @addr: address to modify
> + * @opcode: source of the copy
> + * @len: length to copy
> + *
> + * Only atomic text poke/set should be allowed when not doing early patching.
> + * It means the size must be writable atomically and the address must be aligned
> + * in a way that permits an atomic write. It also makes sure we fit on a single
> + * page.
> + */
> +void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
> +{
> + unsigned long flags;
> + char *vaddr;
> + int nr_pages = 2;
> +
> + BUG_ON(len > sizeof(long));
> + BUG_ON((((long)addr + len - 1) & ~(sizeof(long) - 1))
> + - ((long)addr & ~(sizeof(long) - 1)));
> + {
> + 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);
> + WARN_ON(!vaddr);
> + local_irq_save(flags);
> + memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
> + local_irq_restore(flags);
you probably want a BUG_ON instead (or some graceful recovery) else
the NULL deref will trigger with IRQs off...
> + vunmap(vaddr);
> + }
> sync_core();
> /* Could also do a CLFLUSH here to speed up CPU recovery; but
> that causes hangs on some VIA CPUs. */
> + return addr;
> }