Files
android_kernel_xiaomi_sm8450/arch/x86/kernel
Quentin Barnes b506a9d08b x86: code clarification patch to Kprobes arch code
When developing the Kprobes arch code for ARM, I ran across some code
found in x86 and s390 Kprobes arch code which I didn't consider as
good as it could be.

Once I figured out what the code was doing, I changed the code
for ARM Kprobes to work the way I felt was more appropriate.
I've tested the code this way in ARM for about a year and would
like to push the same change to the other affected architectures.

The code in question is in kprobe_exceptions_notify() which
does:
====
          /* kprobe_running() needs smp_processor_id() */
          preempt_disable();
          if (kprobe_running() &&
              kprobe_fault_handler(args->regs, args->trapnr))
                  ret = NOTIFY_STOP;
          preempt_enable();
====

For the moment, ignore the code having the preempt_disable()/
preempt_enable() pair in it.

The problem is that kprobe_running() needs to call smp_processor_id()
which will assert if preemption is enabled.  That sanity check by
smp_processor_id() makes perfect sense since calling it with preemption
enabled would return an unreliable result.

But the function kprobe_exceptions_notify() can be called from a
context where preemption could be enabled.  If that happens, the
assertion in smp_processor_id() happens and we're dead.  So what
the original author did (speculation on my part!) is put in the
preempt_disable()/preempt_enable() pair to simply defeat the check.

Once I figured out what was going on, I considered this an
inappropriate approach.  If kprobe_exceptions_notify() is called
from a preemptible context, we can't be in a kprobe processing
context at that time anyways since kprobes requires preemption to
already be disabled, so just check for preemption enabled, and if
so, blow out before ever calling kprobe_running().  I wrote the ARM
kprobe code like this:
====
          /* To be potentially processing a kprobe fault and to
           * trust the result from kprobe_running(), we have
           * be non-preemptible. */
          if (!preemptible() && kprobe_running() &&
              kprobe_fault_handler(args->regs, args->trapnr))
                  ret = NOTIFY_STOP;
====

The above code has been working fine for ARM Kprobes for a year.
So I changed the x86 code (2.6.24-rc6) to be the same way and ran
the Systemtap tests on that kernel.  As on ARM, Systemtap on x86
comes up with the same test results either way, so it's a neutral
external functional change (as expected).

This issue has been discussed previously on linux-arm-kernel and the
Systemtap mailing lists.  Pointers to the by base for the two
discussions:
http://lists.arm.linux.org.uk/lurker/message/20071219.223225.1f5c2a5e.en.html
http://sourceware.org/ml/systemtap/2007-q1/msg00251.html

Signed-off-by: Quentin Barnes <qbarnes@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Ananth N Mavinakayahanalli <ananth@in.ibm.com>
Acked-by: Ananth N Mavinakayahanalli <ananth@in.ibm.com>
2008-01-30 13:32:32 +01:00
..
2008-01-30 13:31:16 +01:00
2007-10-17 21:19:04 +02:00
2008-01-30 13:31:42 +01:00
2008-01-30 13:31:12 +01:00
2008-01-30 13:31:31 +01:00
2007-10-11 11:17:01 +02:00
2007-10-11 11:17:24 +02:00
2007-10-13 10:01:23 -07:00
2008-01-24 20:40:04 -08:00
2007-10-19 11:53:33 -07:00
2007-10-13 10:01:23 -07:00
2008-01-30 13:31:31 +01:00
2007-10-11 11:17:01 +02:00
2008-01-30 13:31:19 +01:00
2008-01-30 13:31:23 +01:00
2008-01-01 11:30:35 -08:00
2008-01-30 13:30:32 +01:00
2008-01-30 13:31:55 +01:00
2008-01-30 13:31:23 +01:00
2008-01-30 13:30:28 +01:00
2007-10-11 11:17:24 +02:00
2008-01-30 13:31:13 +01:00
2008-01-30 13:31:12 +01:00
2007-10-13 10:01:23 -07:00
2007-10-11 11:17:01 +02:00
2007-10-11 11:17:24 +02:00
2008-01-30 13:31:42 +01:00
2007-10-19 20:35:03 +02:00
2008-01-24 20:40:04 -08:00
2008-01-30 13:30:33 +01:00
2008-01-30 13:30:33 +01:00
2007-10-11 11:17:01 +02:00
2008-01-30 13:30:31 +01:00
2007-10-11 11:17:01 +02:00
2008-01-30 13:31:55 +01:00
2008-01-30 13:31:55 +01:00
2008-01-30 13:32:03 +01:00
2008-01-30 13:31:12 +01:00
2007-10-11 11:17:01 +02:00
2007-10-11 11:17:24 +02:00
2008-01-30 13:30:27 +01:00
2008-01-30 13:31:31 +01:00
2007-10-11 11:17:01 +02:00
2008-01-30 13:31:27 +01:00
2007-10-11 11:17:01 +02:00
2008-01-30 13:30:28 +01:00
2007-10-20 01:13:56 +02:00
2007-10-17 08:42:55 -07:00
2007-10-11 11:17:01 +02:00
2008-01-30 13:31:52 +01:00
2008-01-30 13:31:52 +01:00
2007-10-17 20:16:08 +02:00
2007-10-17 20:16:08 +02:00
2008-01-30 13:31:27 +01:00
2008-01-30 13:31:03 +01:00
2007-10-11 11:17:24 +02:00
2008-01-30 13:31:42 +01:00
2008-01-30 13:31:13 +01:00
2007-10-11 11:17:01 +02:00
2008-01-30 13:31:10 +01:00