Re: Re: [PATCH -tip v8 10/26] kprobes/x86: Allow probe on some kprobe preparation functions

From: Masami Hiramatsu
Date: Thu Mar 27 2014 - 01:50:58 EST


(2014/03/25 4:35), Steven Rostedt wrote:
> On Wed, 05 Mar 2014 20:59:53 +0900
> Masami Hiramatsu <masami.hiramatsu.pt@xxxxxxxxxxx> wrote:
>
>> There is no need to prohibit probing on the functions
>> used in preparation phase. Those are safely probed because
>> those are not invoked from breakpoint/fault/debug handlers,
>> there is no chance to cause recursive exceptions.
>>
>> Following functions are now removed from the kprobes blacklist.
>> can_boost
>> can_probe
>> can_optimize
>> is_IF_modifier
>> __copy_instruction
>> copy_optimized_instructions
>> arch_copy_kprobe
>> arch_prepare_kprobe
>> arch_arm_kprobe
>> arch_disarm_kprobe
>> arch_remove_kprobe
>
> Is there any possibility that the arm and disarm could cause issues if
> we have a probe in the middle of setting it?
>
> I guess not, but I just wanted to ask, as your test only tested the
> start of function and not the middle of it.

OK, I've tested it by attached script which adds probes on every address
of the target function and run a testcase(register/unregister other probes),
and found no problem. :)

Thank you,


--
Masami HIRAMATSU
IT Management Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@xxxxxxxxxxx



#!/bin/bash
TARGETS=$1
FTRACE_KPROBE_EVENT=/sys/kernel/debug/tracing/kprobe_events
FTRACE_KPROBE_PROFILE=/sys/kernel/debug/tracing/kprobe_profile
FTRACE_EVENTS=/sys/kernel/debug/tracing/events

if [ ! -f $TARGETS ]; then
echo "Usage: kprobe_test.sh <Targetfile>"
exit 1
fi
if [ `id -u` -ne 0 ]; then
echo "Error: This program requires root privilege"
exit 2
fi

function get_symbol_size() { #symbol
grep $1 -w -m1 -A1 /proc/kallsyms |\
awk 'BEGIN{ s = 0 }; {p = strtonum("0x"substr($1,9,8)); if (s == 0) {s = p;} else { print p - s}}'
}

function setup_probes() { #symbol
size=`get_symbol_size $1`
if [ -z "$size" ]; then
echo "No symbol $1 found"
return 1
fi
i=0
err=0
while [ $i -lt $size ]; do
(echo p $1+$i >> $FTRACE_KPROBE_EVENT) &> /dev/null
[ $? -eq 0 ] || err=$((err+1))
i=$((i+1))
done
probed=`expr $size - $err`
echo "Setup $probed probes on $1"
[ $probed -eq 0 ] && return 1
return 0
}

function enable_probes() {
echo 1 > $FTRACE_EVENTS/kprobes/enable
}

function clear_probes() {
echo 0 > $FTRACE_EVENTS/kprobes/enable
echo > $FTRACE_KPROBE_EVENT
}

function run_test() {
echo p:test1 vfs_symlink >> $FTRACE_KPROBE_EVENT
echo p:test2 vfs_symlink+5 >> $FTRACE_KPROBE_EVENT
echo 1 > $FTRACE_EVENTS/kprobes/test1/enable
echo 1 > $FTRACE_EVENTS/kprobes/test2/enable
sleep 1
echo 0 > $FTRACE_EVENTS/kprobes/test1/enable
echo 0 > $FTRACE_EVENTS/kprobes/test2/enable
echo -:test1 >> $FTRACE_KPROBE_EVENT
echo -:test2 >> $FTRACE_KPROBE_EVENT
}

function save_profile() { # symbol
cat $FTRACE_KPROBE_PROFILE > ${1}.profile
}

function test_on() { # symbol
setup_probes $1
[ $? -ne 0 ] && return
enable_probes
echo "Probe Enabled"
run_test
echo "Test done on $1"
save_profile $1
clear_probes
}

clear_probes
cat $TARGETS | while read sym; do
test_on $sym
done