14 Nov, 2018

1 commit

  • [ Upstream commit 819319fc93461c07b9cdb3064f154bd8cfd48172 ]

    Make reuse_unused_kprobe() to return error code if
    it fails to reuse unused kprobe for optprobe instead
    of calling BUG_ON().

    Signed-off-by: Masami Hiramatsu
    Cc: Anil S Keshavamurthy
    Cc: David S . Miller
    Cc: Linus Torvalds
    Cc: Naveen N . Rao
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/153666124040.21306.14150398706331307654.stgit@devbox
    Signed-off-by: Ingo Molnar
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Masami Hiramatsu
     

21 Jun, 2018

6 commits

  • Replace %p with %pS or just remove it if unneeded.
    And use WARN_ONCE() if it is a single bug.

    Signed-off-by: Masami Hiramatsu
    Cc: Ananth N Mavinakayanahalli
    Cc: Anil S Keshavamurthy
    Cc: Arnd Bergmann
    Cc: David Howells
    Cc: David S . Miller
    Cc: Heiko Carstens
    Cc: Jon Medhurst
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Thomas Richter
    Cc: Tobin C . Harding
    Cc: Will Deacon
    Cc: acme@kernel.org
    Cc: akpm@linux-foundation.org
    Cc: brueckner@linux.vnet.ibm.com
    Cc: linux-arch@vger.kernel.org
    Cc: rostedt@goodmis.org
    Cc: schwidefsky@de.ibm.com
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/lkml/152491899284.9916.5350534544808158621.stgit@devbox
    Signed-off-by: Ingo Molnar

    Masami Hiramatsu
     
  • Show probed address in debugfs kprobe list file as same
    as kallsyms does. This information is used for checking
    kprobes are placed in the expected address. So it should
    be able to compared with address in kallsyms.

    Signed-off-by: Masami Hiramatsu
    Cc: Ananth N Mavinakayanahalli
    Cc: Anil S Keshavamurthy
    Cc: Arnd Bergmann
    Cc: David Howells
    Cc: David S . Miller
    Cc: Heiko Carstens
    Cc: Jon Medhurst
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Thomas Richter
    Cc: Tobin C . Harding
    Cc: Will Deacon
    Cc: acme@kernel.org
    Cc: akpm@linux-foundation.org
    Cc: brueckner@linux.vnet.ibm.com
    Cc: linux-arch@vger.kernel.org
    Cc: rostedt@goodmis.org
    Cc: schwidefsky@de.ibm.com
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/lkml/152491896256.9916.1583733714492565296.stgit@devbox
    Signed-off-by: Ingo Molnar

    Masami Hiramatsu
     
  • Show kprobes blacklist addresses under same condition of
    showing kallsyms addresses.

    Since there are several name conflict for local symbols,
    kprobe blacklist needs to show each addresses so that
    user can identify where is on blacklist by comparing
    with kallsyms.

    Signed-off-by: Masami Hiramatsu
    Cc: Ananth N Mavinakayanahalli
    Cc: Anil S Keshavamurthy
    Cc: Arnd Bergmann
    Cc: David Howells
    Cc: David S . Miller
    Cc: Heiko Carstens
    Cc: Jon Medhurst
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Thomas Richter
    Cc: Tobin C . Harding
    Cc: Will Deacon
    Cc: acme@kernel.org
    Cc: akpm@linux-foundation.org
    Cc: brueckner@linux.vnet.ibm.com
    Cc: linux-arch@vger.kernel.org
    Cc: rostedt@goodmis.org
    Cc: schwidefsky@de.ibm.com
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/lkml/152491893217.9916.14760965896164273464.stgit@devbox
    Signed-off-by: Ingo Molnar

    Masami Hiramatsu
     
  • Since the blacklist and list files on debugfs indicates
    a sensitive address information to reader, it should be
    restricted to the root user.

    Suggested-by: Thomas Richter
    Suggested-by: Ingo Molnar
    Signed-off-by: Masami Hiramatsu
    Cc: Ananth N Mavinakayanahalli
    Cc: Anil S Keshavamurthy
    Cc: Arnd Bergmann
    Cc: David Howells
    Cc: David S . Miller
    Cc: Heiko Carstens
    Cc: Jon Medhurst
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Tobin C . Harding
    Cc: Will Deacon
    Cc: acme@kernel.org
    Cc: akpm@linux-foundation.org
    Cc: brueckner@linux.vnet.ibm.com
    Cc: linux-arch@vger.kernel.org
    Cc: rostedt@goodmis.org
    Cc: schwidefsky@de.ibm.com
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/lkml/152491890171.9916.5183693615601334087.stgit@devbox
    Signed-off-by: Ingo Molnar

    Masami Hiramatsu
     
  • Don't check the ->break_handler() from the core kprobes code,
    because it was only used by jprobes which got removed.

    ( In followup patches we'll remove the remaining calls in low level
    arch handlers as well and remove the callback altogether. )

    Signed-off-by: Masami Hiramatsu
    Acked-by: Thomas Gleixner
    Cc: Ananth N Mavinakayanahalli
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: linux-arch@vger.kernel.org
    Link: https://lore.kernel.org/lkml/152942462686.15209.6324404940493598980.stgit@devbox
    Signed-off-by: Ingo Molnar

    Masami Hiramatsu
     
  • Remove functionally empty jprobe API implementations and test cases.

    Signed-off-by: Masami Hiramatsu
    Acked-by: Thomas Gleixner
    Cc: Ananth N Mavinakayanahalli
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: linux-arch@vger.kernel.org
    Link: https://lore.kernel.org/lkml/152942430705.15209.2307050500995264322.stgit@devbox
    Signed-off-by: Ingo Molnar

    Masami Hiramatsu
     

25 Apr, 2018

1 commit

  • File /sys/kernel/debug/kprobes/blacklist displays random addresses:

    [root@s8360046 linux]# cat /sys/kernel/debug/kprobes/blacklist
    0x0000000047149a90-0x00000000bfcb099a print_type_x8
    ....

    This breaks 'perf probe' which uses the blacklist file to prohibit
    probes on certain functions by checking the address range.

    Fix this by printing the correct (unhashed) address.

    The file mode is read all but this is not an issue as the file
    hierarchy points out:
    # ls -ld /sys/ /sys/kernel/ /sys/kernel/debug/ /sys/kernel/debug/kprobes/
    /sys/kernel/debug/kprobes/blacklist
    dr-xr-xr-x 12 root root 0 Apr 19 07:56 /sys/
    drwxr-xr-x 8 root root 0 Apr 19 07:56 /sys/kernel/
    drwx------ 16 root root 0 Apr 19 06:56 /sys/kernel/debug/
    drwxr-xr-x 2 root root 0 Apr 19 06:56 /sys/kernel/debug/kprobes/
    -r--r--r-- 1 root root 0 Apr 19 06:56 /sys/kernel/debug/kprobes/blacklist

    Everything in and below /sys/kernel/debug is rwx to root only,
    no group or others have access.

    Background:
    Directory /sys/kernel/debug/kprobes is created by debugfs_create_dir()
    which sets the mode bits to rwxr-xr-x. Maybe change that to use the
    parent's directory mode bits instead?

    Link: http://lkml.kernel.org/r/20180419105556.86664-1-tmricht@linux.ibm.com

    Fixes: ad67b74d2469 ("printk: hash addresses printed with %p")
    Cc: stable@vger.kernel.org
    Cc: # v4.15+
    Cc: Ananth N Mavinakayanahalli
    Cc: Anil S Keshavamurthy
    Cc: David S Miller
    Cc: Masami Hiramatsu
    Cc: acme@kernel.org

    Signed-off-by: Thomas Richter
    Signed-off-by: Steven Rostedt (VMware)

    Thomas Richter
     

16 Feb, 2018

2 commits

  • Improve error handling when disarming ftrace-based kprobes. Like with
    arm_kprobe_ftrace(), propagate any errors from disarm_kprobe_ftrace() so
    that we do not disable/unregister kprobes that are still armed. In other
    words, unregister_kprobe() and disable_kprobe() should not report success
    if the kprobe could not be disarmed.

    disarm_all_kprobes() keeps its current behavior and attempts to
    disarm all kprobes. It returns the last encountered error and gives a
    warning if not all probes could be disarmed.

    This patch is based on Petr Mladek's original patchset (patches 2 and 3)
    back in 2015, which improved kprobes error handling, found here:

    https://lkml.org/lkml/2015/2/26/452

    However, further work on this had been paused since then and the patches
    were not upstreamed.

    Based-on-patches-by: Petr Mladek
    Signed-off-by: Jessica Yu
    Acked-by: Masami Hiramatsu
    Cc: Ananth N Mavinakayanahalli
    Cc: Anil S Keshavamurthy
    Cc: David S . Miller
    Cc: Jiri Kosina
    Cc: Joe Lawrence
    Cc: Josh Poimboeuf
    Cc: Linus Torvalds
    Cc: Miroslav Benes
    Cc: Peter Zijlstra
    Cc: Petr Mladek
    Cc: Steven Rostedt
    Cc: Thomas Gleixner
    Cc: live-patching@vger.kernel.org
    Link: http://lkml.kernel.org/r/20180109235124.30886-3-jeyu@kernel.org
    Signed-off-by: Ingo Molnar

    Jessica Yu
     
  • Improve error handling when arming ftrace-based kprobes. Specifically, if
    we fail to arm a ftrace-based kprobe, register_kprobe()/enable_kprobe()
    should report an error instead of success. Previously, this has lead to
    confusing situations where register_kprobe() would return 0 indicating
    success, but the kprobe would not be functional if ftrace registration
    during the kprobe arming process had failed. We should therefore take any
    errors returned by ftrace into account and propagate this error so that we
    do not register/enable kprobes that cannot be armed. This can happen if,
    for example, register_ftrace_function() finds an IPMODIFY conflict (since
    kprobe_ftrace_ops has this flag set) and returns an error. Such a conflict
    is possible since livepatches also set the IPMODIFY flag for their ftrace_ops.

    arm_all_kprobes() keeps its current behavior and attempts to arm all
    kprobes. It returns the last encountered error and gives a warning if
    not all probes could be armed.

    This patch is based on Petr Mladek's original patchset (patches 2 and 3)
    back in 2015, which improved kprobes error handling, found here:

    https://lkml.org/lkml/2015/2/26/452

    However, further work on this had been paused since then and the patches
    were not upstreamed.

    Based-on-patches-by: Petr Mladek
    Signed-off-by: Jessica Yu
    Acked-by: Masami Hiramatsu
    Cc: Ananth N Mavinakayanahalli
    Cc: Anil S Keshavamurthy
    Cc: David S . Miller
    Cc: Jiri Kosina
    Cc: Joe Lawrence
    Cc: Josh Poimboeuf
    Cc: Linus Torvalds
    Cc: Miroslav Benes
    Cc: Peter Zijlstra
    Cc: Petr Mladek
    Cc: Steven Rostedt
    Cc: Thomas Gleixner
    Cc: live-patching@vger.kernel.org
    Link: http://lkml.kernel.org/r/20180109235124.30886-2-jeyu@kernel.org
    Signed-off-by: Ingo Molnar

    Jessica Yu
     

20 Oct, 2017

2 commits

  • Disable the jprobes APIs and comment out the jprobes API function
    code. This is in preparation of removing all jprobes related
    code (including kprobe's break_handler).

    Nowadays ftrace and other tracing features are mature enough
    to replace jprobes use-cases. Users can safely use ftrace and
    perf probe etc. for their use cases.

    Signed-off-by: Masami Hiramatsu
    Cc: Alexei Starovoitov
    Cc: Ananth N Mavinakayanahalli
    Cc: Anil S Keshavamurthy
    Cc: David S . Miller
    Cc: Ian McDonald
    Cc: Kees Cook
    Cc: Linus Torvalds
    Cc: Paul E . McKenney
    Cc: Peter Zijlstra
    Cc: Stephen Hemminger
    Cc: Steven Rostedt
    Cc: Thomas Gleixner
    Cc: Vlad Yasevich
    Link: http://lkml.kernel.org/r/150724527741.5014.15465541485637899227.stgit@devbox
    Signed-off-by: Ingo Molnar

    Masami Hiramatsu
     
  • We want to wait for all potentially preempted kprobes trampoline
    execution to have completed. This guarantees that any freed
    trampoline memory is not in use by any task in the system anymore.
    synchronize_rcu_tasks() gives such a guarantee, so use it.

    Also, this guarantees to wait for all potentially preempted tasks
    on the instructions which will be replaced with a jump.

    Since this becomes a problem only when CONFIG_PREEMPT=y, enable
    CONFIG_TASKS_RCU=y for synchronize_rcu_tasks() in that case.

    Signed-off-by: Masami Hiramatsu
    Acked-by: Paul E. McKenney
    Cc: Ananth N Mavinakayanahalli
    Cc: Linus Torvalds
    Cc: Naveen N . Rao
    Cc: Paul E . McKenney
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/150845661962.5443.17724352636247312231.stgit@devbox
    Signed-off-by: Ingo Molnar

    Masami Hiramatsu
     

18 Oct, 2017

1 commit

  • This reverts commit:

    e863d539614641 ("kprobes: Warn if optprobe handler tries to change execution path")

    On PowerPC, we place a probe at kretprobe_trampoline to catch function
    returns and with CONFIG_OPTPROBES=y, this probe gets optimized. This
    works for us due to the way we handle the optprobe as described in
    commit:

    762df10bad6954 ("powerpc/kprobes: Optimize kprobe in kretprobe_trampoline()")

    With the above commit, we end up with a warning. As such, revert this change.

    Reported-by: Michael Ellerman
    Signed-off-by: Naveen N. Rao
    Cc: Ananth N Mavinakayanahalli
    Cc: Linus Torvalds
    Cc: Masami Hiramatsu
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/20171017081834.3629-1-naveen.n.rao@linux.vnet.ibm.com
    Signed-off-by: Ingo Molnar

    Naveen N. Rao
     

28 Sep, 2017

2 commits

  • Warn if optprobe handler tries to change execution path.
    As described in Documentation/kprobes.txt, with optprobe
    user handler can not change instruction pointer. In that
    case user must avoid optimizing the kprobes by setting
    post_handler or break_handler.

    Signed-off-by: Masami Hiramatsu
    Cc: Alexei Starovoitov
    Cc: Alexei Starovoitov
    Cc: Ananth N Mavinakayanahalli
    Cc: Linus Torvalds
    Cc: Paul E . McKenney
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/150581521955.32348.3615624715034787365.stgit@devbox
    Signed-off-by: Ingo Molnar

    Masami Hiramatsu
     
  • Make insn buffer always ROX and use text_poke() to write
    the copied instructions instead of set_memory_*().
    This makes instruction buffer stronger against other
    kernel subsystems because there is no window time
    to modify the buffer.

    Suggested-by: Ingo Molnar
    Signed-off-by: Masami Hiramatsu
    Cc: Ananth N Mavinakayanahalli
    Cc: Anil S Keshavamurthy
    Cc: David S . Miller
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/150304463032.17009.14195368040691676813.stgit@devbox
    Signed-off-by: Ingo Molnar

    Masami Hiramatsu
     

08 Jul, 2017

3 commits

  • Similar to commit 90ec5e89e393c ("kretprobes: Ensure probe location is
    at function entry"), ensure that the jprobe probepoint is at function
    entry.

    Signed-off-by: Naveen N. Rao
    Cc: Ananth N Mavinakayanahalli
    Cc: Linus Torvalds
    Cc: Masami Hiramatsu
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/a4525af6c5a42df385efa31251246cf7cca73598.1499443367.git.naveen.n.rao@linux.vnet.ibm.com
    Signed-off-by: Ingo Molnar

    Naveen N. Rao
     
  • Re-factor jprobe registration functions as the current version is
    getting too unwieldy. Move the actual jprobe registration to
    register_jprobe() and re-organize code accordingly.

    Suggested-by: Ingo Molnar
    Signed-off-by: Naveen N. Rao
    Cc: Ananth N Mavinakayanahalli
    Cc: Linus Torvalds
    Cc: Masami Hiramatsu
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/089cae4bfe73767f765291ee0e6fb0c3d240e5f1.1499443367.git.naveen.n.rao@linux.vnet.ibm.com
    Signed-off-by: Ingo Molnar

    Naveen N. Rao
     
  • Rename function_offset_within_entry() to scope it to kprobe namespace by
    using kprobe_ prefix, and to also simplify it.

    Suggested-by: Ingo Molnar
    Suggested-by: Masami Hiramatsu
    Signed-off-by: Naveen N. Rao
    Cc: Ananth N Mavinakayanahalli
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/3aa6c7e2e4fb6e00f3c24fa306496a66edb558ea.1499443367.git.naveen.n.rao@linux.vnet.ibm.com
    Signed-off-by: Ingo Molnar

    Naveen N. Rao
     

04 Jul, 2017

1 commit

  • Pull SMP hotplug updates from Thomas Gleixner:
    "This update is primarily a cleanup of the CPU hotplug locking code.

    The hotplug locking mechanism is an open coded RWSEM, which allows
    recursive locking. The main problem with that is the recursive nature
    as it evades the full lockdep coverage and hides potential deadlocks.

    The rework replaces the open coded RWSEM with a percpu RWSEM and
    establishes full lockdep coverage that way.

    The bulk of the changes fix up recursive locking issues and address
    the now fully reported potential deadlocks all over the place. Some of
    these deadlocks have been observed in the RT tree, but on mainline the
    probability was low enough to hide them away."

    * 'smp-hotplug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (37 commits)
    cpu/hotplug: Constify attribute_group structures
    powerpc: Only obtain cpu_hotplug_lock if called by rtasd
    ARM/hw_breakpoint: Fix possible recursive locking for arch_hw_breakpoint_init
    cpu/hotplug: Remove unused check_for_tasks() function
    perf/core: Don't release cred_guard_mutex if not taken
    cpuhotplug: Link lock stacks for hotplug callbacks
    acpi/processor: Prevent cpu hotplug deadlock
    sched: Provide is_percpu_thread() helper
    cpu/hotplug: Convert hotplug locking to percpu rwsem
    s390: Prevent hotplug rwsem recursion
    arm: Prevent hotplug rwsem recursion
    arm64: Prevent cpu hotplug rwsem recursion
    kprobes: Cure hotplug lock ordering issues
    jump_label: Reorder hotplug lock and jump_label_lock
    perf/tracing/cpuhotplug: Fix locking order
    ACPI/processor: Use cpu_hotplug_disable() instead of get_online_cpus()
    PCI: Replace the racy recursion prevention
    PCI: Use cpu_hotplug_disable() instead of get_online_cpus()
    perf/x86/intel: Drop get_online_cpus() in intel_snb_check_microcode()
    x86/perf: Drop EXPORT of perf_check_microcode
    ...

    Linus Torvalds
     

27 May, 2017

1 commit

  • Fix kprobes to set(recover) RWX bits correctly on trampoline
    buffer before releasing it. Releasing readonly page to
    module_memfree() crash the kernel.

    Without this fix, if kprobes user register a bunch of kprobes
    in function body (since kprobes on function entry usually
    use ftrace) and unregister it, kernel hits a BUG and crash.

    Link: http://lkml.kernel.org/r/149570868652.3518.14120169373590420503.stgit@devbox

    Signed-off-by: Masami Hiramatsu
    Fixes: d0381c81c2f7 ("kprobes/x86: Set kprobes pages read-only")
    Signed-off-by: Steven Rostedt (VMware)

    Masami Hiramatsu
     

26 May, 2017

1 commit

  • Converting the cpu hotplug locking to a percpu rwsem unearthed hidden lock
    ordering problems.

    There is a wide range of locks involved in this: kprobe_mutex,
    jump_label_mutex, ftrace_lock, text_mutex, event_mutex, module_mutex,
    func_hash->regex_lock and a gazillion of lock order permutations with
    nested get_online_cpus() calls.

    Some of those permutations are potential deadlocks even with the current
    nesting hotplug locking scheme, but they can't be discovered by lockdep.

    The conversion of the hotplug locking to a percpu rwsem requires to prevent
    nested locking, so it's required to take the hotplug rwsem early in the
    call chain and establish a proper lock order.

    After quite some analysis and going down the wrong road severa times the
    following lock order has been chosen:

    kprobe_mutex -> cpus_rwsem -> jump_label_mutex -> text_mutex

    For kprobes which hook on an ftrace function trace point, it's required to
    drop cpus_rwsem before calling into the ftrace code to avoid a deadlock on
    the func_hash->regex_lock.

    [ Steven: Ftrace interaction fixes ]

    Signed-off-by: Thomas Gleixner
    Signed-off-by: Steven Rostedt
    Signed-off-by: Thomas Gleixner
    Acked-by: Ingo Molnar
    Acked-by: Masami Hiramatsu
    Cc: Paul E. McKenney
    Cc: Peter Zijlstra
    Cc: Sebastian Siewior
    Link: http://lkml.kernel.org/r/20170524081549.104864779@linutronix.de

    Thomas Gleixner
     

18 May, 2017

2 commits

  • Thomas discovered a bug where the kprobe trace tests had a race
    condition where the kprobe_optimizer called from a delayed work queue
    that does the optimizing and "unoptimizing" of a kprobe, can try to
    modify the text after it has been freed by the init code.

    The kprobe trace selftest is a special case, and Thomas and myself
    investigated to see if there's a chance that this could also be a bug
    with module unloading, as the code is not obvious to how it handles
    this. After adding lots of printks, I figured it out. Thomas suggested
    that this should be commented so that others will not have to go
    through this exercise again.

    Link: http://lkml.kernel.org/r/20170516145835.3827d3aa@gandalf.local.home

    Acked-by: Masami Hiramatsu
    Suggested-by: Thomas Gleixner
    Signed-off-by: Steven Rostedt (VMware)

    Steven Rostedt (VMware)
     
  • Enabling the tracer selftest triggers occasionally the warning in
    text_poke(), which warns when the to be modified page is not marked
    reserved.

    The reason is that the tracer selftest installs kprobes on functions marked
    __init for testing. These probes are removed after the tests, but that
    removal schedules the delayed kprobes_optimizer work, which will do the
    actual text poke. If the work is executed after the init text is freed,
    then the warning triggers. The bug can be reproduced reliably when the work
    delay is increased.

    Flush the optimizer work and wait for the optimizing/unoptimizing lists to
    become empty before returning from the kprobes tracer selftest. That
    ensures that all operations which were queued due to the probes removal
    have completed.

    Link: http://lkml.kernel.org/r/20170516094802.76a468bb@gandalf.local.home

    Signed-off-by: Thomas Gleixner
    Acked-by: Masami Hiramatsu
    Cc: stable@vger.kernel.org
    Fixes: 6274de498 ("kprobes: Support delayed unoptimizing")
    Signed-off-by: Steven Rostedt (VMware)

    Thomas Gleixner
     

06 May, 2017

1 commit

  • Pull powerpc updates from Michael Ellerman:
    "Highlights include:

    - Larger virtual address space on 64-bit server CPUs. By default we
    use a 128TB virtual address space, but a process can request access
    to the full 512TB by passing a hint to mmap().

    - Support for the new Power9 "XIVE" interrupt controller.

    - TLB flushing optimisations for the radix MMU on Power9.

    - Support for CAPI cards on Power9, using the "Coherent Accelerator
    Interface Architecture 2.0".

    - The ability to configure the mmap randomisation limits at build and
    runtime.

    - Several small fixes and cleanups to the kprobes code, as well as
    support for KPROBES_ON_FTRACE.

    - Major improvements to handling of system reset interrupts,
    correctly treating them as NMIs, giving them a dedicated stack and
    using a new hypervisor call to trigger them, all of which should
    aid debugging and robustness.

    - Many fixes and other minor enhancements.

    Thanks to: Alastair D'Silva, Alexey Kardashevskiy, Alistair Popple,
    Andrew Donnellan, Aneesh Kumar K.V, Anshuman Khandual, Anton
    Blanchard, Balbir Singh, Ben Hutchings, Benjamin Herrenschmidt,
    Bhupesh Sharma, Chris Packham, Christian Zigotzky, Christophe Leroy,
    Christophe Lombard, Daniel Axtens, David Gibson, Gautham R. Shenoy,
    Gavin Shan, Geert Uytterhoeven, Guilherme G. Piccoli, Hamish Martin,
    Hari Bathini, Kees Cook, Laurent Dufour, Madhavan Srinivasan, Mahesh J
    Salgaonkar, Mahesh Salgaonkar, Masami Hiramatsu, Matt Brown, Matthew
    R. Ochs, Michael Neuling, Naveen N. Rao, Nicholas Piggin, Oliver
    O'Halloran, Pan Xinhui, Paul Mackerras, Rashmica Gupta, Russell
    Currey, Sukadev Bhattiprolu, Thadeu Lima de Souza Cascardo, Tobin C.
    Harding, Tyrel Datwyler, Uma Krishnan, Vaibhav Jain, Vipin K Parashar,
    Yang Shi"

    * tag 'powerpc-4.12-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux: (214 commits)
    powerpc/64s: Power9 has no LPCR[VRMASD] field so don't set it
    powerpc/powernv: Fix TCE kill on NVLink2
    powerpc/mm/radix: Drop support for CPUs without lockless tlbie
    powerpc/book3s/mce: Move add_taint() later in virtual mode
    powerpc/sysfs: Move #ifdef CONFIG_HOTPLUG_CPU out of the function body
    powerpc/smp: Document irq enable/disable after migrating IRQs
    powerpc/mpc52xx: Don't select user-visible RTAS_PROC
    powerpc/powernv: Document cxl dependency on special case in pnv_eeh_reset()
    powerpc/eeh: Clean up and document event handling functions
    powerpc/eeh: Avoid use after free in eeh_handle_special_event()
    cxl: Mask slice error interrupts after first occurrence
    cxl: Route eeh events to all drivers in cxl_pci_error_detected()
    cxl: Force context lock during EEH flow
    powerpc/64: Allow CONFIG_RELOCATABLE if COMPILE_TEST
    powerpc/xmon: Teach xmon oops about radix vectors
    powerpc/mm/hash: Fix off-by-one in comment about kernel contexts ids
    powerpc/pseries: Enable VFIO
    powerpc/powernv: Fix iommu table size calculation hook for small tables
    powerpc/powernv: Check kzalloc() return value in pnv_pci_table_alloc
    powerpc: Add arch/powerpc/tools directory
    ...

    Linus Torvalds
     

20 Apr, 2017

3 commits

  • commit 239aeba76409 ("perf powerpc: Fix kprobe and kretprobe handling with
    kallsyms on ppc64le") changed how we use the offset field in struct kprobe on
    ABIv2. perf now offsets from the global entry point if an offset is specified
    and otherwise chooses the local entry point.

    Fix the same in kernel for kprobe API users. We do this by extending
    kprobe_lookup_name() to accept an additional parameter to indicate the offset
    specified with the kprobe registration. If offset is 0, we return the local
    function entry and return the global entry point otherwise.

    With:
    # cd /sys/kernel/debug/tracing/
    # echo "p _do_fork" >> kprobe_events
    # echo "p _do_fork+0x10" >> kprobe_events

    before this patch:
    # cat ../kprobes/list
    c0000000000d0748 k _do_fork+0x8 [DISABLED]
    c0000000000d0758 k _do_fork+0x18 [DISABLED]
    c0000000000412b0 k kretprobe_trampoline+0x0 [OPTIMIZED]

    and after:
    # cat ../kprobes/list
    c0000000000d04c8 k _do_fork+0x8 [DISABLED]
    c0000000000d04d0 k _do_fork+0x10 [DISABLED]
    c0000000000412b0 k kretprobe_trampoline+0x0 [OPTIMIZED]

    Acked-by: Ananth N Mavinakayanahalli
    Signed-off-by: Naveen N. Rao
    Signed-off-by: Michael Ellerman

    Naveen N. Rao
     
  • The macro is now pretty long and ugly on powerpc. In the light of further
    changes needed here, convert it to a __weak variant to be over-ridden with a
    nicer looking function.

    Suggested-by: Masami Hiramatsu
    Acked-by: Masami Hiramatsu
    Signed-off-by: Naveen N. Rao
    Signed-off-by: Michael Ellerman

    Naveen N. Rao
     
  • Skip preparing optprobe if the probe is ftrace-based, since anyway, it
    must not be optimized (or already optimized by ftrace).

    Tested-by: Naveen N. Rao
    Signed-off-by: Masami Hiramatsu
    Signed-off-by: Michael Ellerman

    Masami Hiramatsu
     

16 Mar, 2017

1 commit

  • perf specifies an offset from _text and since this offset is fed
    directly into the arch-specific helper, kprobes tracer rejects
    installation of kretprobes through perf. Fix this by looking up the
    actual offset from a function for the specified sym+offset.

    Refactor and reuse existing routines to limit code duplication -- we
    repurpose kprobe_addr() for determining final kprobe address and we
    split out the function entry offset determination into a separate
    generic helper.

    Before patch:

    naveen@ubuntu:~/linux/tools/perf$ sudo ./perf probe -v do_open%return
    probe-definition(0): do_open%return
    symbol:do_open file:(null) line:0 offset:0 return:1 lazy:(null)
    0 arguments
    Looking at the vmlinux_path (8 entries long)
    Using /boot/vmlinux for symbols
    Open Debuginfo file: /boot/vmlinux
    Try to find probe point from debuginfo.
    Matched function: do_open [2d0c7ff]
    Probe point found: do_open+0
    Matched function: do_open [35d76dc]
    found inline addr: 0xc0000000004ba9c4
    Failed to find "do_open%return",
    because do_open is an inlined function and has no return point.
    An error occurred in debuginfo analysis (-22).
    Trying to use symbols.
    Opening /sys/kernel/debug/tracing//README write=0
    Opening /sys/kernel/debug/tracing//kprobe_events write=1
    Writing event: r:probe/do_open _text+4469776
    Failed to write event: Invalid argument
    Error: Failed to add events. Reason: Invalid argument (Code: -22)
    naveen@ubuntu:~/linux/tools/perf$ dmesg | tail

    [ 33.568656] Given offset is not valid for return probe.

    After patch:

    naveen@ubuntu:~/linux/tools/perf$ sudo ./perf probe -v do_open%return
    probe-definition(0): do_open%return
    symbol:do_open file:(null) line:0 offset:0 return:1 lazy:(null)
    0 arguments
    Looking at the vmlinux_path (8 entries long)
    Using /boot/vmlinux for symbols
    Open Debuginfo file: /boot/vmlinux
    Try to find probe point from debuginfo.
    Matched function: do_open [2d0c7d6]
    Probe point found: do_open+0
    Matched function: do_open [35d76b3]
    found inline addr: 0xc0000000004ba9e4
    Failed to find "do_open%return",
    because do_open is an inlined function and has no return point.
    An error occurred in debuginfo analysis (-22).
    Trying to use symbols.
    Opening /sys/kernel/debug/tracing//README write=0
    Opening /sys/kernel/debug/tracing//kprobe_events write=1
    Writing event: r:probe/do_open _text+4469808
    Writing event: r:probe/do_open_1 _text+4956344
    Added new events:
    probe:do_open (on do_open%return)
    probe:do_open_1 (on do_open%return)

    You can now use it in all perf tools, such as:

    perf record -e probe:do_open_1 -aR sleep 1

    naveen@ubuntu:~/linux/tools/perf$ sudo cat /sys/kernel/debug/kprobes/list
    c000000000041370 k kretprobe_trampoline+0x0 [OPTIMIZED]
    c0000000004ba0b8 r do_open+0x8 [DISABLED]
    c000000000443430 r do_open+0x0 [DISABLED]

    Signed-off-by: Naveen N. Rao
    Acked-by: Masami Hiramatsu
    Cc: Ananth N Mavinakayanahalli
    Cc: Michael Ellerman
    Cc: Steven Rostedt
    Cc: linuxppc-dev@lists.ozlabs.org
    Link: http://lkml.kernel.org/r/d8cd1ef420ec22e3643ac332fdabcffc77319a42.1488961018.git.naveen.n.rao@linux.vnet.ibm.com
    Signed-off-by: Arnaldo Carvalho de Melo

    Naveen N. Rao
     

15 Mar, 2017

1 commit

  • commit fc62d0207ae0 ("kprobes: Introduce weak variant of
    kprobe_exceptions_notify()") used the __kprobes annotation to exclude
    kprobe_exceptions_notify from being probed. Since NOKPROBE_SYMBOL() is a
    better way to do this enabling the symbol to be discovered as being
    blacklisted, change over to using NOKPROBE_SYMBOL().

    Signed-off-by: Naveen N. Rao
    Acked-by: Masami Hiramatsu
    Cc: Ananth N Mavinakayanahalli
    Link: http://lkml.kernel.org/r/3f25bf400da5c222cd9b10eec6ded2d6b58209f8.1488991670.git.naveen.n.rao@linux.vnet.ibm.com
    Signed-off-by: Arnaldo Carvalho de Melo

    Naveen N. Rao
     

04 Mar, 2017

1 commit

  • kretprobes can be registered by specifying an absolute address or by
    specifying offset to a symbol. However, we need to ensure this falls at
    function entry so as to be able to determine the return address.

    Validate the same during kretprobe registration. By default, there
    should not be any offset from a function entry, as determined through a
    kallsyms_lookup(). Introduce arch_function_offset_within_entry() as a
    way for architectures to override this.

    Signed-off-by: Naveen N. Rao
    Acked-by: Masami Hiramatsu
    Cc: Ananth N Mavinakayanahalli
    Cc: Michael Ellerman
    Cc: Steven Rostedt
    Cc: linuxppc-dev@lists.ozlabs.org
    Link: http://lkml.kernel.org/r/f1583bc4839a3862cfc2acefcc56f9c8837fa2ba.1487770934.git.naveen.n.rao@linux.vnet.ibm.com
    Signed-off-by: Arnaldo Carvalho de Melo

    Naveen N. Rao
     

23 Feb, 2017

1 commit

  • Pull powerpc updates from Michael Ellerman:
    "Highlights include:

    - Support for direct mapped LPC on POWER9, giving Linux direct access
    to devices that may be on there such as a UART.

    - Memory hotplug support for the Power9 Radix MMU.

    - Add new AUX vectors describing the processor's cache geometry, to
    be used by glibc.

    - The ability for a guest to ask the hypervisor to resize the guest's
    hash table, and in addition support for doing so automatically when
    memory is hotplugged into/out-of the guest. This allows the hash
    table to be sized based on the current memory usage of the guest,
    rather than the maximum possible memory usage.

    - Implementation of optprobes (kprobe optimisation) for powerpc.

    In addition there's the topic branch shared with the KVM tree, which
    includes support for guests to use the Radix MMU on Power9.

    Thanks to:
    Alistair Popple, Andrew Donnellan, Aneesh Kumar K.V, Anju T, Anton
    Blanchard, Benjamin Herrenschmidt, Chris Packham, Daniel Axtens,
    Daniel Borkmann, David Gibson, Finn Thain, Gautham R. Shenoy, Gavin
    Shan, Greg Kurz, Joel Stanley, John Allen, Madhavan Srinivasan,
    Mahesh Salgaonkar, Markus Elfring, Michael Neuling, Nathan Fontenot,
    Naveen N. Rao, Nicholas Piggin, Paul Mackerras, Ravi Bangoria, Reza
    Arbab, Shailendra Singh, Vaibhav Jain, Wei Yongjun"

    * tag 'powerpc-4.11-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux: (129 commits)
    powerpc/mm/radix: Skip ptesync in pte update helpers
    powerpc/mm/radix: Use ptep_get_and_clear_full when clearing pte for full mm
    powerpc/mm/radix: Update pte update sequence for pte clear case
    powerpc/mm: Update PROTFAULT handling in the page fault path
    powerpc/xmon: Fix data-breakpoint
    powerpc/mm: Fix build break with BOOK3S_64=n and MEMORY_HOTPLUG=y
    powerpc/mm: Fix build break when CMA=n && SPAPR_TCE_IOMMU=y
    powerpc/mm: Fix build break with RADIX=y & HUGETLBFS=n
    powerpc/pseries: Fix typo in parameter description
    powerpc/kprobes: Remove kprobe_exceptions_notify()
    kprobes: Introduce weak variant of kprobe_exceptions_notify()
    powerpc/ftrace: Fix confusing help text for DISABLE_MPROFILE_KERNEL
    powerpc/powernv: Fix opal_exit tracepoint opcode
    powerpc: Add a prototype for mcount() so it can be versioned
    powerpc: Drop GPL from of_node_to_nid() export to match other arches
    powerpc/kprobes: Optimize kprobe in kretprobe_trampoline()
    powerpc/kprobes: Implement Optprobes
    powerpc/kprobes: Fixes for kprobe_lookup_name() on BE
    powerpc: Add helper to check if offset is within relative branch range
    powerpc/bpf: Introduce __PPC_SH64()
    ...

    Linus Torvalds
     

10 Feb, 2017

1 commit


14 Jan, 2017

1 commit

  • Improve __kernel_text_address()/kernel_text_address() to return
    true if the given address is on a kprobe's instruction slot
    trampoline.

    This can help stacktraces to determine the address is on a
    text area or not.

    To implement this atomically in is_kprobe_*_slot(), also change
    the insn_cache page list to an RCU list.

    This changes timings a bit (it delays page freeing to the RCU garbage
    collection phase), but none of that is in the hot path.

    Note: this change can add small overhead to stack unwinders because
    it adds 2 additional checks to __kernel_text_address(). However, the
    impact should be very small, because kprobe_insn_pages list has 1 entry
    per 256 probes(on x86, on arm/arm64 it will be 1024 probes),
    and kprobe_optinsn_pages has 1 entry per 32 probes(on x86).
    In most use cases, the number of kprobe events may be less
    than 20, which means that is_kprobe_*_slot() will check just one entry.

    Tested-by: Josh Poimboeuf
    Signed-off-by: Masami Hiramatsu
    Acked-by: Peter Zijlstra
    Cc: Alexander Shishkin
    Cc: Ananth N Mavinakayanahalli
    Cc: Andrew Morton
    Cc: Andrey Konovalov
    Cc: Arnaldo Carvalho de Melo
    Cc: Jiri Olsa
    Cc: Linus Torvalds
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/148388747896.6869.6354262871751682264.stgit@devbox
    [ Improved the changelog and coding style. ]
    Signed-off-by: Ingo Molnar

    Masami Hiramatsu
     

25 Dec, 2016

1 commit


12 Oct, 2016

1 commit

  • asm-generic headers are generic implementations for architecture specific
    code and should not be included by common code. Thus use the asm/ version
    of sections.h to get at the linker sections.

    Link: http://lkml.kernel.org/r/1473602302-6208-1-git-send-email-hch@lst.de
    Signed-off-by: Christoph Hellwig
    Acked-by: Masami Hiramatsu
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Christoph Hellwig
     

04 Aug, 2015

1 commit

  • Code on the kprobe blacklist doesn't want unexpected int3
    exceptions. It probably doesn't want unexpected debug exceptions
    either. Be safe: disallow breakpoints in nokprobes code.

    On non-CONFIG_KPROBES kernels, there is no kprobe blacklist. In
    that case, disallow kernel breakpoints entirely.

    It will be particularly important to keep hw breakpoints out of the
    entry and NMI code once we move debug exceptions off the IST stack.

    Signed-off-by: Andy Lutomirski
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Borislav Petkov
    Cc: Brian Gerst
    Cc: Linus Torvalds
    Cc: Masami Hiramatsu
    Cc: Peter Zijlstra
    Cc: Steven Rostedt
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/e14b152af99640448d895e3c2a8c2d5ee19a1325.1438312874.git.luto@kernel.org
    Signed-off-by: Ingo Molnar

    Andy Lutomirski
     

14 Feb, 2015

2 commits

  • debugfs/kprobes/enabled doesn't work correctly on optimized kprobes.
    Masami Hiramatsu has a test report on x86_64 platform:

    https://lkml.org/lkml/2015/1/19/274

    This patch forces it to unoptimize kprobe if kprobes_all_disarmed is set.
    It also checks the flag in unregistering path for skipping unneeded
    disarming process when kprobes globally disarmed.

    Signed-off-by: Wang Nan
    Signed-off-by: Masami Hiramatsu
    Cc: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Wang Nan
     
  • In original code, the probed instruction doesn't get optimized after

    echo 0 > /sys/kernel/debug/kprobes/enabled
    echo 1 > /sys/kernel/debug/kprobes/enabled

    This is because original code checks kprobes_all_disarmed in
    optimize_kprobe(), but this flag is turned off after calling that
    function. Therefore, optimize_kprobe() will see kprobes_all_disarmed ==
    true and doesn't do the optimization.

    This patch simply turns off kprobes_all_disarmed earlier to enable
    optimization.

    Signed-off-by: Wang Nan
    Signed-off-by: Masami Hiramatsu
    Cc: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Wang Nan
     

13 Feb, 2015

1 commit

  • Pull ARM updates from Russell King:

    - clang assembly fixes from Ard

    - optimisations and cleanups for Aurora L2 cache support

    - efficient L2 cache support for secure monitor API on Exynos SoCs

    - debug menu cleanup from Daniel Thompson to allow better behaviour for
    multiplatform kernels

    - StrongARM SA11x0 conversion to irq domains, and pxa_timer

    - kprobes updates for older ARM CPUs

    - move probes support out of arch/arm/kernel to arch/arm/probes

    - add inline asm support for the rbit (reverse bits) instruction

    - provide an ARM mode secondary CPU entry point (for Qualcomm CPUs)

    - remove the unused ARMv3 user access code

    - add driver_override support to AMBA Primecell bus

    * 'for-linus' of git://ftp.arm.linux.org.uk/~rmk/linux-arm: (55 commits)
    ARM: 8256/1: driver coamba: add device binding path 'driver_override'
    ARM: 8301/1: qcom: Use secondary_startup_arm()
    ARM: 8302/1: Add a secondary_startup that assumes ARM mode
    ARM: 8300/1: teach __asmeq that r11 == fp and r12 == ip
    ARM: kprobes: Fix compilation error caused by superfluous '*'
    ARM: 8297/1: cache-l2x0: optimize aurora range operations
    ARM: 8296/1: cache-l2x0: clean up aurora cache handling
    ARM: 8284/1: sa1100: clear RCSR_SMR on resume
    ARM: 8283/1: sa1100: collie: clear PWER register on machine init
    ARM: 8282/1: sa1100: use handle_domain_irq
    ARM: 8281/1: sa1100: move GPIO-related IRQ code to gpio driver
    ARM: 8280/1: sa1100: switch to irq_domain_add_simple()
    ARM: 8279/1: sa1100: merge both GPIO irqdomains
    ARM: 8278/1: sa1100: split irq handling for low GPIOs
    ARM: 8291/1: replace magic number with PAGE_SHIFT macro in fixup_pv code
    ARM: 8290/1: decompressor: fix a wrong comment
    ARM: 8286/1: mm: Fix dma_contiguous_reserve comment
    ARM: 8248/1: pm: remove outdated comment
    ARM: 8274/1: Fix DEBUG_LL for multi-platform kernels (without PL01X)
    ARM: 8273/1: Seperate DEBUG_UART_PHYS from DEBUG_LL on EP93XX
    ...

    Linus Torvalds
     

20 Jan, 2015

1 commit

  • Nothing needs the module pointer any more, and the next patch will
    call it from RCU, where the module itself might no longer exist.
    Removing the arg is the safest approach.

    This just codifies the use of the module_alloc/module_free pattern
    which ftrace and bpf use.

    Signed-off-by: Rusty Russell
    Acked-by: Alexei Starovoitov
    Cc: Mikael Starvik
    Cc: Jesper Nilsson
    Cc: Ralf Baechle
    Cc: Ley Foon Tan
    Cc: Benjamin Herrenschmidt
    Cc: Chris Metcalf
    Cc: Steven Rostedt
    Cc: x86@kernel.org
    Cc: Ananth N Mavinakayanahalli
    Cc: Anil S Keshavamurthy
    Cc: Masami Hiramatsu
    Cc: linux-cris-kernel@axis.com
    Cc: linux-kernel@vger.kernel.org
    Cc: linux-mips@linux-mips.org
    Cc: nios2-dev@lists.rocketboards.org
    Cc: linuxppc-dev@lists.ozlabs.org
    Cc: sparclinux@vger.kernel.org
    Cc: netdev@vger.kernel.org

    Rusty Russell