linux/arch/sh/include/asm
Steven Rostedt 17666f02b1 ftrace: nmi safe code modification
Impact: fix crashes that can occur in NMI handlers, if their code is modified

Modifying code is something that needs special care. On SMP boxes,
if code that is being modified is also being executed on another CPU,
that CPU will have undefined results.

The dynamic ftrace uses kstop_machine to make the system act like a
uniprocessor system. But this does not address NMIs, that can still
run on other CPUs.

One approach to handle this is to make all code that are used by NMIs
not be traced. But NMIs can call notifiers that spread throughout the
kernel and this will be very hard to maintain, and the chance of missing
a function is very high.

The approach that this patch takes is to have the NMIs modify the code
if the modification is taking place. The way this works is that just
writing to code executing on another CPU is not harmful if what is
written is the same as what exists.

Two buffers are used: an IP buffer and a "code" buffer.

The steps that the patcher takes are:

 1) Put in the instruction pointer into the IP buffer
    and the new code into the "code" buffer.
 2) Set a flag that says we are modifying code
 3) Wait for any running NMIs to finish.
 4) Write the code
 5) clear the flag.
 6) Wait for any running NMIs to finish.

If an NMI is executed, it will also write the pending code.
Multiple writes are OK, because what is being written is the same.
Then the patcher must wait for all running NMIs to finish before
going to the next line that must be patched.

This is basically the RCU approach to code modification.

Thanks to Ingo Molnar for suggesting the idea, and to Arjan van de Ven
for his guidence on what is safe and what is not.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
History 2008-10-30 21:30:08 +01:00
..
hd64465 sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
.gitignore sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
adc.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
addrspace.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
atomic-grb.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
atomic-irq.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
atomic-llsc.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
atomic.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
auxvec.h sh: Make sure AT_SYSINFO_EHDR is exposed to userspace in asm/auxvec.h. 2008-07-29 23:12:25 +09:00
bitops-grb.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
bitops-irq.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
bitops-llsc.h sh: Provide movli.l/movco.l-based bitops. 2008-09-08 10:35:02 +09:00
bitops.h sh: Provide movli.l/movco.l-based bitops. 2008-09-08 10:35:02 +09:00
bug.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
bugs.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
byteorder.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
cache.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
cacheflush.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
checksum.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
checksum_32.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
checksum_64.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
clock.h sh: fixup many sparse errors. 2008-09-08 10:35:04 +09:00
cmpxchg-grb.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
cmpxchg-irq.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
cmpxchg-llsc.h sh: Provide movli.l/movco.l-based cmpxchg. 2008-09-08 10:35:02 +09:00
cpu-features.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
cputime.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
current.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
delay.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
device.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
div64.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
dma-mapping.h Merge git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6 2008-08-01 10:53:43 -07:00
dma.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
dmabrg.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
elf.h sh: Fix up some merge damage. 2008-10-20 11:37:58 +09:00
emergency-restart.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
entry-macros.S sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
errno.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
fb.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
fcntl.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
fixmap.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
flat.h sh: Provide a FLAT_PLAT_INIT() definition. 2008-08-11 20:17:55 +09:00
fpu.h sh: Add FPU registers to regset interface. 2008-09-21 19:04:55 +09:00
freq.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
ftrace.h ftrace: nmi safe code modification 2008-10-30 21:30:08 +01:00
futex-irq.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
futex.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
gpio.h sh: asm/gpio.h needs linux/kernel.h for might_sleep()/WARN_ON(). 2008-10-23 12:37:20 +09:00
hardirq.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
hd64461.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
heartbeat.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
hugetlb.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
hw_irq.h sh: Move the shared INTC code out to drivers/sh/ 2008-10-01 16:13:54 +09:00
i2c-sh7760.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
ilsel.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
io.h sh: More I/O routine overhauling. 2008-10-04 05:25:52 +09:00
io_generic.h sh: More I/O routine overhauling. 2008-10-04 05:25:52 +09:00
io_trapped.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
ioctl.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
ioctls.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
ipcbuf.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
irq.h sh: fixup many sparse errors. 2008-09-08 10:35:04 +09:00
irq_regs.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
irqflags.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
irqflags_32.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
irqflags_64.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
Kbuild sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
kdebug.h sh: Wire up oops reporting in the die notifier chain. 2008-10-21 18:33:36 +09:00
kexec.h kexec jump: rename KEXEC_CONTROL_CODE_SIZE to KEXEC_CONTROL_PAGE_SIZE 2008-08-15 08:35:42 -07:00
kgdb.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
kmap_types.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
kprobes.h sh: kprobes: Use trapa #0x3a for breakpoint trap. 2008-09-08 18:10:10 +09:00
linkage.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
local.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
machvec.h sh: More I/O routine overhauling. 2008-10-04 05:25:52 +09:00
mc146818rtc.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
mman.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
mmu.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
mmu_context.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
mmu_context_32.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
mmu_context_64.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
mmzone.h sh: Fix up NUMA build error with se7722_defconfig. 2008-09-12 22:41:30 +09:00
module.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
msgbuf.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
mutex.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
page.h sh: ioremap_prot support. 2008-09-12 20:41:05 +09:00
param.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
parport.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
pci.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
percpu.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
pgalloc.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
pgtable.h sh: ioremap_prot support. 2008-09-12 20:41:05 +09:00
pgtable_32.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
pgtable_64.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
pm.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
poll.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
posix_types.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
posix_types_32.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
posix_types_64.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
processor.h sh: Consolidate struct sh_cpuinfo definitions across _32/_64 split. 2008-09-17 23:24:02 +09:00
processor_32.h sh: Consolidate struct sh_cpuinfo definitions across _32/_64 split. 2008-09-17 23:24:02 +09:00
processor_64.h sh: Consolidate struct sh_cpuinfo definitions across _32/_64 split. 2008-09-17 23:24:02 +09:00
ptrace.h sh: Add DSP registers to regset interface. 2008-09-12 22:42:10 +09:00
push-switch.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
resource.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
rtc.h sh: fixup many sparse errors. 2008-09-08 10:35:04 +09:00
rwsem.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
scatterlist.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
seccomp.h sh: seccomp support. 2008-08-02 04:39:32 +09:00
sections.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
segment.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
sembuf.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
serial.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
setup.h sh: Fix up headers_check regression. 2008-09-17 23:24:59 +09:00
sfp-machine.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
sh7760fb.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
sh_bios.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
sh_eth.h [netdrvr] sh_eth: Add SH7619 support 2008-08-07 02:20:57 -04:00
sh_keysc.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
shmbuf.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
shmparam.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
sigcontext.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
siginfo.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
signal.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
sizes.h sh: Add a few more definitions to asm/sizes.h. 2008-09-21 10:31:57 +09:00
smc37c93x.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
smp.h sh: generic clockevent broadcast support. 2008-09-08 10:35:03 +09:00
socket.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
sockios.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
sparsemem.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
spi.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
spinlock.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
spinlock_types.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
stat.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
statfs.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
string.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
string_32.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
string_64.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
syscall.h sh: Provide the asm/syscall.h interface, needed by tracehook. 2008-09-12 22:13:13 +09:00
syscall_32.h sh: Provide the asm/syscall.h interface, needed by tracehook. 2008-09-12 22:13:13 +09:00
syscall_64.h sh: Provide the asm/syscall.h interface, needed by tracehook. 2008-09-12 22:13:13 +09:00
syscalls.h sh: fixup many sparse errors. 2008-09-08 10:35:04 +09:00
syscalls_32.h sh: fixup many sparse errors. 2008-09-08 10:35:04 +09:00
syscalls_64.h sh: fixup many sparse errors. 2008-09-08 10:35:04 +09:00
system.h sh: fixup many sparse errors. 2008-09-08 10:35:04 +09:00
system_32.h sh: Move lookup_exception_vector() out to asm/system_32.h. 2008-09-21 12:00:23 +09:00
system_64.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
termbits.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
termios.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
thread_info.h sh: Support kernel stacks smaller than a page. 2008-09-20 20:21:33 +09:00
timer.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
timex.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
tlb.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
tlb_64.h sh: Fix up broken kerneldoc comments. 2008-08-04 12:51:06 +09:00
tlbflush.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
topology.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
types.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
uaccess.h sh: Proper __put_user_asm() size mismatch fix. 2008-07-29 09:16:33 +09:00
uaccess_32.h sh: Proper __put_user_asm() size mismatch fix. 2008-07-29 09:16:33 +09:00
uaccess_64.h sh: sh_ksyms_64 needs __strncpy_from_user() definition. 2008-09-29 19:45:16 +09:00
ubc.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
ucontext.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
unaligned.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
unistd.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
unistd_32.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
unistd_64.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
user.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
vga.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
watchdog.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00
xor.h sh: migrate to arch/sh/include/ 2008-07-29 08:09:44 +09:00