08 Sep, 2005

2 commits

  • This patch fixes a race condition where in system used to hang or sometime
    crash within minutes when kprobes are inserted on ISR routine and a task
    routine.

    The fix has been stress tested on i386, ia64, pp64 and on x86_64. To
    reproduce the problem insert kprobes on schedule() and do_IRQ() functions
    and you should see hang or system crash.

    Signed-off-by: Anil S Keshavamurthy
    Signed-off-by: Ananth N Mavinakayanahalli
    Acked-by: Prasanna S Panchamukhi
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Keshavamurthy Anil S
     
  • There are possible race conditions if probes are placed on routines within the
    kprobes files and routines used by the kprobes. For example if you put probe
    on get_kprobe() routines, the system can hang while inserting probes on any
    routine such as do_fork(). Because while inserting probes on do_fork(),
    register_kprobes() routine grabs the kprobes spin lock and executes
    get_kprobe() routine and to handle probe of get_kprobe(), kprobes_handler()
    gets executed and tries to grab kprobes spin lock, and spins forever. This
    patch avoids such possible race conditions by preventing probes on routines
    within the kprobes file and routines used by kprobes.

    I have modified the patches as per Andi Kleen's suggestion to move kprobes
    routines and other routines used by kprobes to a seperate section
    .kprobes.text.

    Also moved page fault and exception handlers, general protection fault to
    .kprobes.text section.

    These patches have been tested on i386, x86_64 and ppc64 architectures, also
    compiled on ia64 and sparc64 architectures.

    Signed-off-by: Prasanna S Panchamukhi
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Prasanna S Panchamukhi
     

06 Jul, 2005

1 commit

  • The following renames arch_init, a kprobes function for performing any
    architecture specific initialization, to arch_init_kprobes in order to
    cleanup the namespace.

    Also, this patch adds arch_init_kprobes to sparc64 to fix the sparc64 kprobes
    build from the last return probe patch.

    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rusty Lynch
     

28 Jun, 2005

2 commits

  • The following is the second version of the function return probe patches
    I sent out earlier this week. Changes since my last submission include:

    * Fix in ppc64 code removing an unneeded call to re-enable preemption
    * Fix a build problem in ia64 when kprobes was turned off
    * Added another BUG_ON check to each of the architecture trampoline
    handlers

    My initial patch description ==>

    From my experiences with adding return probes to x86_64 and ia64, and the
    feedback on LKML to those patches, I think we can simplify the design
    for return probes.

    The following patch tweaks the original design such that:

    * Instead of storing the stack address in the return probe instance, the
    task pointer is stored. This gives us all we need in order to:
    - find the correct return probe instance when we enter the trampoline
    (even if we are recursing)
    - find all left-over return probe instances when the task is going away

    This has the side effect of simplifying the implementation since more
    work can be done in kernel/kprobes.c since architecture specific knowledge
    of the stack layout is no longer required. Specifically, we no longer have:
    - arch_get_kprobe_task()
    - arch_kprobe_flush_task()
    - get_rp_inst_tsk()
    - get_rp_inst()
    - trampoline_post_handler()

    * Instead of splitting the return probe handling and cleanup logic across
    the pre and post trampoline handlers, all the work is pushed into the
    pre function (trampoline_probe_handler), and then we skip single stepping
    the original function. In this case the original instruction to be single
    stepped was just a NOP, and we can do without the extra interruption.

    The new flow of events to having a return probe handler execute when a target
    function exits is:

    * At system initialization time, a kprobe is inserted at the beginning of
    kretprobe_trampoline. kernel/kprobes.c use to handle this on it's own,
    but ia64 needed to do this a little differently (i.e. a function pointer
    is really a pointer to a structure containing the instruction pointer and
    a global pointer), so I added the notion of arch_init(), so that
    kernel/kprobes.c:init_kprobes() now allows architecture specific
    initialization by calling arch_init() before exiting. Each architecture
    now registers a kprobe on it's own trampoline function.

    * register_kretprobe() will insert a kprobe at the beginning of the targeted
    function with the kprobe pre_handler set to arch_prepare_kretprobe
    (still no change)

    * When the target function is entered, the kprobe is fired, calling
    arch_prepare_kretprobe (still no change)

    * In arch_prepare_kretprobe() we try to get a free instance and if one is
    available then we fill out the instance with a pointer to the return probe,
    the original return address, and a pointer to the task structure (instead
    of the stack address.) Just like before we change the return address
    to the trampoline function and mark the instance as used.

    If multiple return probes are registered for a given target function,
    then arch_prepare_kretprobe() will get called multiple times for the same
    task (since our kprobe implementation is able to handle multiple kprobes
    at the same address.) Past the first call to arch_prepare_kretprobe,
    we end up with the original address stored in the return probe instance
    pointing to our trampoline function. (This is a significant difference
    from the original arch_prepare_kretprobe design.)

    * Target function executes like normal and then returns to kretprobe_trampoline.

    * kprobe inserted on the first instruction of kretprobe_trampoline is fired
    and calls trampoline_probe_handler() (no change here)

    * trampoline_probe_handler() consumes each of the instances associated with
    the current task by calling the registered handler function and marking
    the instance as unused until an instance is found that has a return address
    different then the trampoline function.

    (change similar to my previous ia64 RFC)

    * If the task is killed with some left-over return probe instances (meaning
    that a target function was entered, but never returned), then we just
    free any instances associated with the task. (Not much different other
    then we can handle this without calling architecture specific functions.)

    There is a known problem that this patch does not yet solve where
    registering a return probe flush_old_exec or flush_thread will put us
    in a bad state. Most likely the best way to handle this is to not allow
    registering return probes on these two functions.

    (Significant change)

    This patch series applies to the 2.6.12-rc6-mm1 kernel, and provides:
    * kernel/kprobes.c changes
    * i386 patch of existing return probes implementation
    * x86_64 patch of existing return probe implementation
    * ia64 implementation
    * ppc64 implementation (provided by Ananth)

    This patch implements the architecture independant changes for a reworking
    of the kprobes based function return probes design. Changes include:

    * Removing functions for querying a return probe instance off a stack address
    * Removing the stack_addr field from the kretprobe_instance definition,
    and adding a task pointer
    * Adding architecture specific initialization via arch_init()
    * Removing extern definitions for the architecture trampoline functions
    (this isn't needed anymore since the architecture handles the
    initialization of the kprobe in the return probe trampoline function.)

    Signed-off-by: Rusty Lynch
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rusty Lynch
     
  • Now that PPC64 has no-execute support, here is a second try to fix the
    single step out of line during kprobe execution. Kprobes on x86_64 already
    solved this problem by allocating an executable page and using it as the
    scratch area for stepping out of line. Reuse that.

    Signed-off-by: Ananth N Mavinakayanahalli
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ananth N Mavinakayanahalli
     

24 Jun, 2005

5 commits

  • Presently either multiple kprobes or only one jprobe could be inserted.
    This patch removes the above limitation and allows one jprobe and multiple
    kprobes to coexist at the same address. However multiple jprobes cannot
    coexist with multiple kprobes. Currently I am working on the prototype to
    allow multiple jprobes coexist with multiple kprobes.

    Signed-off-by: Ananth N Mavinakayanhalli
    Signed-off-by: Prasanna S Panchamukhi
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Prasanna S Panchamukhi
     
  • In situations where a kprobes handler calls a routine which has a probe on it,
    then kprobes_handler() disarms the new probe forever. This patch removes the
    above limitation by temporarily disarming the new probe. When the another
    probe hits while handling the old probe, the kprobes_handler() saves previous
    kprobes state and handles the new probe without calling the new kprobes
    registered handlers. kprobe_post_handler() restores back the previous kprobes
    state and the normal execution continues.

    However on x86_64 architecture, re-rentrancy is provided only through
    pre_handler(). If a routine having probe is referenced through
    post_handler(), then the probes on that routine are disarmed forever, since
    the exception stack is gets changed after the processor single steps the
    instruction of the new probe.

    This patch includes generic changes to support temporary disarming on
    reentrancy of probes.

    Signed-of-by: Prasanna S Panchamukhi

    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Prasanna S Panchamukhi
     
  • This patch moves the lock/unlock of the arch specific kprobe_flush_task()
    to the non-arch specific kprobe_flusk_task().

    Signed-off-by: Hien Nguyen
    Acked-by: Prasanna S Panchamukhi
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Hien Nguyen
     
  • The architecture independent code of the current kprobes implementation is
    arming and disarming kprobes at registration time. The problem is that the
    code is assuming that arming and disarming is a just done by a simple write
    of some magic value to an address. This is problematic for ia64 where our
    instructions look more like structures, and we can not insert break points
    by just doing something like:

    *p->addr = BREAKPOINT_INSTRUCTION;

    The following patch to 2.6.12-rc4-mm2 adds two new architecture dependent
    functions:

    * void arch_arm_kprobe(struct kprobe *p)
    * void arch_disarm_kprobe(struct kprobe *p)

    and then adds the new functions for each of the architectures that already
    implement kprobes (spar64/ppc64/i386/x86_64).

    I thought arch_[dis]arm_kprobe was the most descriptive of what was really
    happening, but each of the architectures already had a disarm_kprobe()
    function that was really a "disarm and do some other clean-up items as
    needed when you stumble across a recursive kprobe." So... I took the
    liberty of changing the code that was calling disarm_kprobe() to call
    arch_disarm_kprobe(), and then do the cleanup in the block of code dealing
    with the recursive kprobe case.

    So far this patch as been tested on i386, x86_64, and ppc64, but still
    needs to be tested in sparc64.

    Signed-off-by: Rusty Lynch
    Signed-off-by: Anil S Keshavamurthy
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rusty Lynch
     
  • This patch adds function-return probes to kprobes for the i386
    architecture. This enables you to establish a handler to be run when a
    function returns.

    1. API

    Two new functions are added to kprobes:

    int register_kretprobe(struct kretprobe *rp);
    void unregister_kretprobe(struct kretprobe *rp);

    2. Registration and unregistration

    2.1 Register

    To register a function-return probe, the user populates the following
    fields in a kretprobe object and calls register_kretprobe() with the
    kretprobe address as an argument:

    kp.addr - the function's address

    handler - this function is run after the ret instruction executes, but
    before control returns to the return address in the caller.

    maxactive - The maximum number of instances of the probed function that
    can be active concurrently. For example, if the function is non-
    recursive and is called with a spinlock or mutex held, maxactive = 1
    should be enough. If the function is non-recursive and can never
    relinquish the CPU (e.g., via a semaphore or preemption), NR_CPUS should
    be enough. maxactive is used to determine how many kretprobe_instance
    objects to allocate for this particular probed function. If maxactive
    Signed-off-by: Prasanna S Panchamukhi
    Signed-off-by: Frederik Deweerdt
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Hien Nguyen
     

06 May, 2005

2 commits


17 Apr, 2005

1 commit

  • Initial git repository build. I'm not bothering with the full history,
    even though we have it. We can create a separate "historical" git
    archive of that later if we want to, and in the meantime it's about
    3.2GB when imported into git - space that would just make the early
    git days unnecessarily complicated, when we don't have a lot of good
    infrastructure for it.

    Let it rip!

    Linus Torvalds