linux/arch/sparc
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>
2008-10-30 21:30:08 +01:00
..
boot sparc: Add target for a stripped kernel 2008-08-24 20:35:47 -07:00
include/asm ftrace: nmi safe code modification 2008-10-30 21:30:08 +01:00
kernel sparc: correct section of current_pc() 2008-10-22 21:53:47 -07:00
lib sparc: remove CVS keywords 2008-05-20 00:33:44 -07:00
math-emu sparc: remove CVS keywords 2008-05-20 00:33:44 -07:00
mm sparc32: add init memory poisoning 2008-09-03 16:29:42 -07:00
oprofile oprofile: more whitespace fixes 2008-10-15 20:55:51 +02:00
prom sparc: remove CONFIG_SUN4 2008-08-31 20:59:37 -07:00
defconfig sparc: Add kgdb support. 2008-04-29 02:38:50 -07:00
Kconfig container freezer: implement freezer cgroup subsystem 2008-10-20 08:52:34 -07:00
Kconfig.debug [SPARC32]: Add irqflags.h to sparc32 and use it from generic code. 2007-10-13 21:53:11 -07:00
Makefile sparc: Add target for a stripped kernel 2008-08-24 20:35:47 -07:00