0: Inode based uprobes
Subsystems (9)
PATCH v2 1/20 1: mm: Move replace_page() to mm/memory.c
In reply to Srikar DronamrajuUser bkpt will use background page replacement approach to insert/delete breakpoints. Background page replacement approach is based on replace_page. Hence replace_page() loses its static attribute.
--- include/linux/mm.h | 2 ++ mm/ksm.c | 62 ---------------------------------------------------- mm/memory.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 62 deletions(-)
include/linux/mm.h +2 -0
@@ -984,6 +984,8 @@ void account_page_writeback(struct page *page);int set_page_dirty (struct page *page);int set_page_dirty_lock (struct page *page);int clear_page_dirty_for_io (struct page *page); +int replace_page (struct vm_area_struct *vma,struct page *page, +struct page *kpage,pte_t orig_pte);/* Is the vma a continuation of the stack vma above it? */ static inline int vma_stack_continue (struct vm_area_struct *vma,unsigned long addr)
mm/ksm.c +0 -62
68 lines not on this page · raw message
mm/memory.c +62 -0
68 lines not on this page · raw message
v2 cover 0: Inode based uprobes
This patchset implements Uprobes which enables you to dynamically break into any routine in a user space application and collect information non-disruptively.
This patchset resolves most of the comments from Peter on the previous posting https://lkml.org/lkml/2010/12/16/65.
Uprobes Patches
This patchset implements inode based uprobes which are specified as <file>:<offset> where offset is the offset from start of the map. The probehit overhead is around 3X times the overhead from pid based patchset.
When a uprobe is registered, Uprobes makes a copy of the probed instruction, replaces the first byte(s) of the probed instruction with a breakpoint instruction. (Uprobes uses background page replacement mechanism and ensures that the breakpoint affects only that process.)
When a CPU hits the breakpoint instruction, Uprobes gets notified of trap and finds the associated uprobe. It then executes the associated handler. Uprobes single-steps its copy of the probed instruction and resumes execution of the probed process at the instruction following the probepoint. Instruction copies to be single-stepped are stored in a per-mm "execution out of line (XOL) area". Currently XOL area is allocated as one page vma.
For previous posting: please refer: http://lkml.org/lkml/2010/8/25/165
http://lkml.org/lkml/2010/7/27/121, http://lkml.org/lkml/2010/7/12/67,
http://lkml.org/lkml/2010/7/8/239, http://lkml.org/lkml/2010/6/29/299,
http://lkml.org/lkml/2010/6/14/41, http://lkml.org/lkml/2010/3/20/107
and http://lkml.org/lkml/2010/5/18/307
This patchset is a rework based on suggestions from discussions on lkml in September, March and January 2010 (http://lkml.org/lkml/2010/1/11/92,
http://lkml.org/lkml/2010/1/27/19, http://lkml.org/lkml/2010/3/20/107
and http://lkml.org/lkml/2010/3/31/199 ). This implementation of uprobes doesnt depend on utrace.
Advantages of uprobes over conventional debugging include:
1. Non-disruptive.
Unlike current ptrace based mechanisms, uprobes tracing wouldnt involve signals, stopping threads and context switching between the tracer and tracee.
2. Much better handling of multithreaded programs because of XOL. Current ptrace based mechanisms use single stepping inline, i.e they copy back the original instruction on hitting a breakpoint. In such mechanisms tracers have to stop all the threads on a breakpoint hit or tracers will not be able to handle all hits to the location of interest. Uprobes uses execution out of line, where the instruction to be traced is analysed at the time of breakpoint insertion and a copy of instruction is stored at a different location. On breakpoint hit, uprobes jumps to that copied location and singlesteps the same instruction and does the necessary fixups post singlestepping.
3. Multiple tracers for an application.
Multiple uprobes based tracer could work in unison to trace an application. There could one tracer that could be interested in generic events for a particular set of process. While there could be another tracer that is just interested in one specific event of a particular process thats part of the previous set of process.
4. Corelating events from kernels and userspace.
Uprobes could be used with other tools like kprobes, tracepoints or as part of higher level tools like perf to give a consolidated set of events from kernel and userspace. In future we could look at a single backtrace showing application, library and kernel calls.
Here is the list of TODO Items.
- Integrating perf probe with this patchset.
- Breakpoint handling should co-exist with singlestep/blockstep from another tracer/debugger.
- Queue and dequeue signals delivered from the singlestep till completion of postprocessing.
- Prefiltering (i.e filtering at the time of probe insertion)
- Return probes.
- Support for other architectures.
- Uprobes booster.
- replace macro W with bits in inat table.
To try please fetch using
git fetch \git://git.kernel.org/pub/scm/linux/kernel/git/srikar/linux-uprobes.git \
tip_inode_uprobes_140311:tip_inode_uprobes
Please refer "[RFC] [PATCH 2.6.37-rc5-tip 20/20] 20: tracing: uprobes trace_event infrastructure" on how to use uprobe_tracer.
Please do provide your valuable comments.
Thanks in advance.
Srikar
Srikar Dronamraju(20)
0: Inode based uprobes
1: mm: Move replace_page() to mm/memory.c
2: X86 specific breakpoint definitions.
3: uprobes: Breakground page replacement.
4: uprobes: Adding and remove a uprobe in a rb tree.
5: Uprobes: register/unregister probes.
6: x86: analyze instruction and determine fixups.
7: uprobes: store/restore original instruction.
8: uprobes: mmap and fork hooks.
9: x86: architecture specific task information.
10: uprobes: task specific information.
11: uprobes: slot allocation for uprobes
12: uprobes: get the breakpoint address.
13: x86: x86 specific probe handling
14: uprobes: Handing int3 and singlestep exception.
15: x86: uprobes exception notifier for x86.
16: uprobes: register a notifier for uprobes.
17: uprobes: filter chain
18: uprobes: commonly used filters.
19: tracing: Extract out common code for kprobes/uprobes traceevents. 20: tracing: uprobes trace_event interface
arch/Kconfig | 4 + arch/x86/Kconfig | 3 + arch/x86/include/asm/thread_info.h | 2 + arch/x86/include/asm/uprobes.h | 58 ++ arch/x86/kernel/Makefile | 1 + arch/x86/kernel/signal.c | 14 + arch/x86/kernel/uprobes.c | 600 ++++++++++++++++ include/linux/mm.h | 2 + include/linux/mm_types.h | 9 + include/linux/sched.h | 3 + include/linux/uprobes.h | 183 +++++ kernel/Makefile | 1 + kernel/fork.c | 10 + kernel/trace/Kconfig | 20 + kernel/trace/Makefile | 2 + kernel/trace/trace.h | 5 + kernel/trace/trace_kprobe.c | 861 +----------------------- kernel/trace/trace_probe.c | 753 ++++++++++++++++++++ kernel/trace/trace_probe.h | 160 +++++ kernel/trace/trace_uprobe.c | 800 ++++++++++++++++++++++ kernel/uprobes.c | 1331 ++++++++++++++++++++++++++++++++++++ mm/ksm.c | 62 -- mm/memory.c | 62 ++ mm/mmap.c | 2 + 24 files changed, 4044 insertions(+), 904 deletions(-)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 2/20 2: X86 specific breakpoint definitions.
Provides definitions for the breakpoint instruction and x86 specific uprobe info structure.
--- arch/x86/Kconfig | 3 +++ arch/x86/include/asm/uprobes.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 0 deletions(-) create mode 100644 arch/x86/include/asm/uprobes.h
arch/x86/Kconfig +3 -0
@@ -237,6 +237,9 @@ config ARCH_CPU_PROBE_RELEASE def_bool y depends on HOTPLUG_CPU +config ARCH_SUPPORTS_UPROBES + def_bool y + source "init/Kconfig" source "kernel/Kconfig.freezer"
arch/x86/include/asm/uprobes.h new file +40 -0
@@ -0,0 +1,40 @@ +#ifndef _ASM_UPROBES_H +#define _ASM_UPROBES_H +/* +* Userspace Probes (UProbes) for x86 +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +* Copyright (C) IBM Corporation, 2008-2010 +* Authors: +* Srikar Dronamraju +* Jim Keniston +*/ + +typedef u8 uprobe_opcode_t ; +#define MAX_UINSN_BYTES 16 +#define UPROBES_XOL_SLOT_BYTES 128/* to keep it cache aligned */ + +#define UPROBES_BKPT_INSN 0xcc +#define UPROBES_BKPT_INSN_SIZE 1 + +#ifdef CONFIG_X86_64 +struct uprobe_arch_info { +unsigned long rip_rela_target_address; +}; +#else +struct uprobe_arch_info {}; +#endif +#endif /* _ASM_UPROBES_H */
PATCH v2 3/20 3: uprobes: Breakground page replacement.
In reply to Srikar DronamrajuProvides Background page replacement using replace_page() routine. Also provides routines to read an opcode from a given virtual address and for verifying if a instruction is a breakpoint instruction.
--- arch/Kconfig | 12 ++ include/linux/uprobes.h | 70 ++++++++++++++ kernel/Makefile | 1 kernel/uprobes.c | 230 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 313 insertions(+), 0 deletions(-) create mode 100644 include/linux/uprobes.h create mode 100644 kernel/uprobes.c
arch/Kconfig +12 -0
@@ -61,6 +61,18 @@ config OPTPROBES depends on KPROBES && HAVE_OPTPROBES depends on !PREEMPT +config UPROBES + bool "User-space probes (EXPERIMENTAL)" + depends on ARCH_SUPPORTS_UPROBES + depends on MMU + select MM_OWNER + help + Uprobes enables kernel subsystems to establish probepoints + in user applications and execute handler functions when + the probepoints are hit. + + If in doubt, say "N". + config HAVE_EFFICIENT_UNALIGNED_ACCESS bool help
include/linux/uprobes.h new file +70 -0
70 lines not on this page · raw message
kernel/Makefile +1 -0
@@ -107,6 +107,7 @@ obj-$(CONFIG_PERF_EVENTS) += perf_event.o obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o obj-$(CONFIG_PADATA) += padata.o +obj-$(CONFIG_UPROBES) += uprobes.o ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y) # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/uprobes.c new file +230 -0
230 lines not on this page · raw message
PATCH v2 4/20 4: uprobes: Adding and remove a uprobe in a rb tree.
In reply to Srikar DronamrajuProvides interfaces to add and remove uprobes from the global rb tree. Also provides definitions for uprobe_consumer, interfaces to add and remove a consumer to a uprobe. There is a unique uprobe element in the rbtree for each unique inode:offset pair.
Uprobe gets added to the global rb tree when the first consumer for that uprobe gets registered. It gets removed from the tree only when all registered consumers are unregistered.
Multiple consumers can share the same probe. Each consumer provides a filter to limit the tasks on which the handler should run, a handler that runs on probe hit and a value which helps filter callback to limit the tasks on which the handler should run.
--- include/linux/uprobes.h | 12 +++ kernel/uprobes.c | 225 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 233 insertions(+), 4 deletions(-)
include/linux/uprobes.h +12 -0
@@ -23,6 +23,7 @@* Jim Keniston */ +#include <linux/rbtree.h> #ifdef CONFIG_ARCH_SUPPORTS_UPROBES #include <asm/uprobes.h> #else
@@ -50,6 +51,17 @@ typedef u8 uprobe_opcode_t;/* Unexported functions & macros for use by arch-specific code */ #define uprobe_opcode_sz (sizeof(uprobe_opcode_t)) +struct uprobe_consumer { +int (*handler)(struct uprobe_consumer *self,struct pt_regs *regs); +/* +* filter is optional; If a filter exists, handler is run +* if and only if filter returns true. +*/ +bool (*filter)(struct uprobe_consumer *self,struct task_struct *task); + +struct uprobe_consumer *next; +}; +/* * Most architectures can use the default versions of @read_opcode(), * @set_bkpt(), @set_orig_insn(), and @is_bkpt_insn();
kernel/uprobes.c +221 -4
250 lines not on this page · raw message
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 5/20 5: Uprobes: register/unregister probes.
In reply to Srikar DronamrajuA probe is specified by a file:offset. While registering, a breakpoint is inserted for the first consumer, On subsequent probes, the consumer gets appended to the existing consumers. While unregistering a breakpoint is removed if the consumer happens to be the last consumer. All other unregisterations, the consumer is deleted from the list of consumers.
Probe specifications are maintained in a rb tree. A probe specification is converted into a uprobe before store in a rb tree. A uprobe can be shared by many consumers.
Given a inode, we get a list of mm's that have mapped the inode. However we want to limit the probes to certain processes/threads. The filtering should be at thread level. To limit the probes to a certain processes/threads, we would want to walk through the list of threads whose mm member refer to a given mm.
Here are the options that I thought of:
1. Use mm->owner and walk thro the thread_group of mm->owner, siblings of mm->owner, siblings of parent of mm->owner. This should be good list to traverse. Not sure if this is an exhaustive enough list that all tasks that have a mm set to this mm_struct are walked through.
2. Install probes on all mm's that have mapped the probes and filter only at probe hit time.
3. walk thro do_each_thread; while_each_thread; I think this will catch all tasks that have a mm set to the given mm. However this might be too heavy esp if mm corresponds to a library.
4. add a list_head element to the mm struct and update the list whenever the task->mm thread gets updated. This could mean extending the current mm->owner. However there is some maintainance overhead.
Currently we use the second approach, i.e probe all mm's that have mapped the probes and filter only at probe hit.
Also would be interested to know if there are ways to call replace_page without having to take mmap_sem.
--- include/linux/mm_types.h | 5 + include/linux/uprobes.h | 32 ++++++++ kernel/uprobes.c | 195 +++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 221 insertions(+), 11 deletions(-)
include/linux/mm_types.h +5 -0
@@ -315,6 +315,11 @@ struct mm_struct {#endif /* How many tasks sharing this mm are OOM_DISABLE */ atomic_t oom_disable_count; +#ifdef CONFIG_UPROBES +unsigned long uprobes_vaddr; +struct list_head uprobes_list; +atomic_t uprobes_count; +#endif };/* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
include/linux/uprobes.h +32 -0
@@ -31,6 +31,7 @@* ARCH_SUPPORTS_UPROBES is not defined. */ typedef u8 uprobe_opcode_t ; +struct uprobe_arch_info {};/* arch specific info*/ /* Post-execution fixups. Some architectures may define others. */ #endif /* CONFIG_ARCH_SUPPORTS_UPROBES */
@@ -62,6 +63,19 @@ struct uprobe_consumer {struct uprobe_consumer *next; }; +struct uprobe { +struct rb_node rb_node;/* node in the rb tree */ +atomic_t ref; +struct rw_semaphore consumer_rwsem; +struct uprobe_arch_info arch_info;/* arch specific info if any */ +struct uprobe_consumer *consumers; +struct inode *inode;/* Also hold a ref to inode */ +loff_t offset; +u8 insn[MAX_UINSN_BYTES ];/* orig instruction */ +u16 fixups; +int copy; +}; +/* * Most architectures can use the default versions of @read_opcode(), * @set_bkpt(), @set_orig_insn(), and @is_bkpt_insn();
@@ -79,4 +93,22 @@ struct uprobe_consumer {* You may modify @user_bkpt->insn (e.g., the x86_64 port does this * for rip-relative instructions). */ + +#ifdef CONFIG_UPROBES +extern int register_uprobe (struct inode *inode,loff_t offset, +struct uprobe_consumer *consumer); +extern void unregister_uprobe (struct inode *inode,loff_t offset, +struct uprobe_consumer *consumer); +#else /* CONFIG_UPROBES is not defined */ +static inline int register_uprobe (struct inode *inode,loff_t offset, +struct uprobe_consumer *consumer) +{ +return -ENOSYS ; +} +static inline void unregister_uprobe (struct inode *inode,loff_t offset, +struct uprobe_consumer *consumer) +{ +} + +#endif /* CONFIG_UPROBES */ #endif /* _LINUX_UPROBES_H */
kernel/uprobes.c +184 -11
204 lines not on this page · raw message
PATCH v2 6/20 6: x86: analyze instruction and determine fixups.
In reply to Srikar DronamrajuThe instruction analysis is based on x86 instruction decoder and determines if an instruction can be probed and determines the necessary fixups after singlestep. Instruction analysis is done at probe insertion time so that we avoid having to repeat the same analysis every time a probe is hit.
--- arch/x86/include/asm/uprobes.h | 2 arch/x86/kernel/Makefile | 1 arch/x86/kernel/uprobes.c | 414 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 417 insertions(+), 0 deletions(-) create mode 100644 arch/x86/kernel/uprobes.c
arch/x86/include/asm/uprobes.h +2 -0
@@ -37,4 +37,6 @@ struct uprobe_arch_info {#else struct uprobe_arch_info {};#endif +struct uprobe ; +extern int analyze_insn (struct task_struct *tsk,struct uprobe *uprobe);#endif /* _ASM_UPROBES_H */
arch/x86/kernel/Makefile +1 -0
@@ -110,6 +110,7 @@ obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o obj-$(CONFIG_SWIOTLB) += pci-swiotlb.o obj-$(CONFIG_OF) += devicetree.o +obj-$(CONFIG_UPROBES) += uprobes.o ### # 64 bit specific files
arch/x86/kernel/uprobes.c new file +414 -0
414 lines not on this page · raw message
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 7/20 7: uprobes: store/restore original instruction.
In reply to Srikar DronamrajuOn the first probe insertion, copy the original instruction and opcode. If multiple vmas map the same text area corresponding to an inode, we only need to copy the instruction just once.
The copied instruction is further copied to a designated slot on probe hit. Its also used at the time of probe removal to restore the original instruction.
opcode is used to analyze the instruction and determine the fixups. Determining fixups at probe hit time would result in doing the same operation on every probe hit. Hence Instruction analysis using the opcode is done at probe insertion time.
--- kernel/uprobes.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 105 insertions(+), 8 deletions(-)
kernel/uprobes.c +105 -8
@@ -52,11 +52,12 @@ static int write_opcode(struct task_struct *tsk, struct uprobe * uprobe, unsigned long vaddr, uprobe_opcode_t opcode) {struct page *old_page, *new_page; +struct address_space *mapping;void *vaddr_old, *vaddr_new;struct vm_area_struct *vma;spinlock_t *ptl;pte_t *orig_pte; -unsigned long addr; +loff_t addr;int ret = -EINVAL ;/* Read the page with vaddr into memory */
@@ -73,6 +74,18 @@ static int write_opcode(struct task_struct *tsk, struct uprobe * uprobe,if (!valid_vma (vma)) goto put_out; + mapping = uprobe->inode->i_mapping; +if (mapping != vma->vm_file->f_mapping) + goto put_out; + + addr = vma->vm_start + uprobe->offset; + addr -= vma->vm_pgoff <<PAGE_SHIFT ; +if (addr >ULONG_MAX ) + goto put_out; + +if (vaddr != (unsigned long ) addr) + goto put_out; +/* Allocate a page */ new_page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vaddr);if (!new_page) {
@@ -91,7 +104,6 @@ static int write_opcode(struct task_struct *tsk, struct uprobe * uprobe,memcpy (vaddr_new, vaddr_old,PAGE_SIZE );/* poke the new insn in, ASSUMES we don't cross page boundary */ - addr = vaddr; vaddr &= ~PAGE_MASK ;memcpy (vaddr_new + vaddr, &opcode, uprobe_opcode_sz);
@@ -435,24 +447,109 @@ static int del_consumer(struct uprobe *uprobe,return ret; } +static int __copy_insn (struct address_space *mapping,char *insn, +unsigned long nbytes,unsigned long offset) +{ +struct page *page; +void *vaddr; +unsigned long off1; +loff_t idx; + + idx = offset >>PAGE_CACHE_SHIFT ; + off1 = offset &= ~PAGE_MASK ; + page =grab_cache_page (mapping, (unsigned long )idx); +if (!page) +return -ENOMEM ; + + vaddr =kmap_atomic (page,KM_USER0 ); +memcpy (insn, vaddr + off1, nbytes); +kunmap_atomic (vaddr,KM_USER0 ); +unlock_page (page); +page_cache_release (page); +return 0 ; +} + +static int copy_insn (struct uprobe *uprobe,unsigned long addr) +{ +struct address_space *mapping; +int bytes; +unsigned long nbytes; + + addr &= ~PAGE_MASK ; + nbytes =PAGE_SIZE - addr; + mapping = uprobe->inode->i_mapping; + +/* Instruction at end of binary; copy only available bytes */ +if (uprobe->offset +MAX_UINSN_BYTES > uprobe->inode->i_size) + bytes = uprobe->inode->i_size - uprobe->offset; +else + bytes =MAX_UINSN_BYTES ; + +/* Instruction at the page-boundary; copy bytes in second page */ +if (nbytes < bytes) { +if (__copy_insn (mapping, uprobe->insn + nbytes, + bytes - nbytes, uprobe->offset + nbytes)) +return -ENOMEM ; + bytes = nbytes; + } +return __copy_insn (mapping, uprobe->insn, bytes, uprobe->offset); +} +static int install_uprobe (struct mm_struct *mm,struct uprobe *uprobe) { -int ret =0 ; +struct task_struct *tsk; +int ret = -EINVAL ; -/*TODO: install breakpoint */ -if (!ret) +get_task_struct (mm->owner); + tsk = mm->owner; +if (!tsk) +return ret; + +if (!uprobe->copy) { + ret =copy_insn (uprobe, mm->uprobes_vaddr); +if (ret) + goto put_return; +if (is_bkpt_insn (uprobe->insn)) { +print_insert_fail (tsk, mm->uprobes_vaddr, +"breakpoint instruction already exists" ); + ret = -EEXIST ; + goto put_return; + } + ret =analyze_insn (tsk, uprobe); +if (ret) { +print_insert_fail (tsk, mm->uprobes_vaddr, +"instruction type cannot be probed" ); + goto put_return; + } + uprobe->copy =1 ; + } + + ret =set_bkpt (tsk, uprobe, mm->uprobes_vaddr); +if (ret <0 ) +print_insert_fail (tsk, mm->uprobes_vaddr, +"failed to insert bkpt instruction" ); +else atomic_inc (&mm->uprobes_count); + +put_return: +put_task_struct (tsk);return ret; }static int remove_uprobe (struct mm_struct *mm,struct uprobe *uprobe) { -int ret =0 ; +struct task_struct *tsk; +int ret; + +get_task_struct (mm->owner); + tsk = mm->owner; +if (!tsk) +return -EINVAL ; -/*TODO: remove breakpoint */ + ret =set_orig_insn (tsk, uprobe, mm->uprobes_vaddr, true);if (!ret)atomic_dec (&mm->uprobes_count); - +put_task_struct (tsk);return ret; }
PATCH v2 8/20 8: uprobes: mmap and fork hooks.
In reply to Srikar DronamrajuProvides hooks in mmap and fork.
On fork, after the new mm is created, we need to set the count of uprobes. On mmap, check if the mmap region is an executable page and if its a executable page, walk through the rbtree and insert actual breakpoints for already registered probes corresponding to this inode.
--- include/linux/uprobes.h | 11 +++++- kernel/fork.c | 2 + kernel/uprobes.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++ mm/mmap.c | 2 + 4 files changed, 105 insertions(+), 1 deletions(-)
include/linux/uprobes.h +10 -1
@@ -66,6 +66,7 @@ struct uprobe_consumer {struct uprobe {struct rb_node rb_node;/* node in the rb tree */ atomic_t ref; +struct list_head pending_list;struct rw_semaphore consumer_rwsem;struct uprobe_arch_info arch_info;/* arch specific info if any */ struct uprobe_consumer *consumers;
@@ -99,6 +100,10 @@ extern int register_uprobe(struct inode *inode, loff_t offset, struct uprobe_consumer *consumer);extern void unregister_uprobe (struct inode *inode,loff_t offset,struct uprobe_consumer *consumer); + +struct vm_area_struct ; +extern void uprobe_mmap (struct vm_area_struct *vma); +extern void uprobe_dup_mmap (struct mm_struct *old_mm,struct mm_struct *mm);#else /* CONFIG_UPROBES is not defined */ static inline int register_uprobe (struct inode *inode,loff_t offset,struct uprobe_consumer *consumer)
@@ -109,6 +114,10 @@ static inline void unregister_uprobe(struct inode *inode, loff_t offset, struct uprobe_consumer *consumer) { } - +static inline void uprobe_dup_mmap (struct mm_struct *old_mm, +struct mm_struct *mm) +{ +} +static inline void uprobe_mmap (struct vm_area_struct *vma) { }#endif /* CONFIG_UPROBES */ #endif /* _LINUX_UPROBES_H */
kernel/fork.c +2 -0
@@ -67,6 +67,7 @@#include <linux/user-return-notifier.h> #include <linux/oom.h> #include <linux/khugepaged.h> +#include <linux/uprobes.h> #include <asm/pgtable.h> #include <asm/pgalloc.h>
@@ -418,6 +419,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) }/* a new mm has just been created */ arch_dup_mmap (oldmm, mm); +uprobe_dup_mmap (oldmm, mm); retval =0 ; out:up_write (&mm->mmap_sem);
kernel/uprobes.c +91 -0
100 lines not on this page · raw message
mm/mmap.c +2 -0
@@ -30,6 +30,7 @@#include <linux/perf_event.h> #include <linux/audit.h> #include <linux/khugepaged.h> +#include <linux/uprobes.h> #include <asm/uaccess.h> #include <asm/cacheflush.h>
@@ -1366,6 +1367,7 @@ out: mm->locked_vm += (len >>PAGE_SHIFT ); }else if ((flags &MAP_POPULATE ) && !(flags &MAP_NONBLOCK ))make_pages_present (addr, addr + len); +uprobe_mmap (vma);return addr; unmap_and_free_vma:
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 9/20 9: x86: architecture specific task information.
In reply to Srikar DronamrajuOn X86_64, we need to support rip relative instructions. Rip relative instructions are handled by saving the scratch register on probe hit and then retrieving the previously saved scratch register after single-step. This value stored at probe hit is specific to each task. Hence this is implemented as part of uprobe_task_arch_info.
Since x86_32 has no support for rip relative instructions, we dont need to bother for x86_32.
--- arch/x86/include/asm/uprobes.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
arch/x86/include/asm/uprobes.h +5 -0
@@ -34,8 +34,13 @@ typedef u8 uprobe_opcode_t;struct uprobe_arch_info {unsigned long rip_rela_target_address; }; + +struct uprobe_task_arch_info { +unsigned long saved_scratch_register; +};#else struct uprobe_arch_info {}; +struct uprobe_task_arch_info {};#endif struct uprobe ;extern int analyze_insn (struct task_struct *tsk,struct uprobe *uprobe);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 10/20 10: uprobes: task specific information.
In reply to Srikar DronamrajuUprobes needs to maintain some task specific information include if a task is currently uprobed, the currently handing uprobe, any arch specific information (for example to handle rip relative instructions), the per-task slot where the original instruction is copied to before single-stepping.
Provides routines to create/manage and free the task specific information.
--- include/linux/sched.h | 3 +++ include/linux/uprobes.h | 25 +++++++++++++++++++++++++ kernel/fork.c | 4 ++++ kernel/uprobes.c | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 0 deletions(-)
include/linux/sched.h +3 -0
@@ -1527,6 +1527,9 @@ struct task_struct { unsigned long memsw_bytes; /* uncharged mem+swap usage */ } memcg_batch;#endif +#ifdef CONFIG_UPROBES +struct uprobe_task *utask; +#endif };/* Future-safe accessor for struct task_struct's cpus_allowed. */
include/linux/uprobes.h +25 -0
@@ -26,12 +26,14 @@#include <linux/rbtree.h> #ifdef CONFIG_ARCH_SUPPORTS_UPROBES #include <asm/uprobes.h> +struct uprobe_task_arch_info ;/* arch specific task info */ #else /* * ARCH_SUPPORTS_UPROBES is not defined. */ typedef u8 uprobe_opcode_t ;struct uprobe_arch_info {};/* arch specific info*/ +struct uprobe_task_arch_info {};/* arch specific task info */ /* Post-execution fixups. Some architectures may define others. */ #endif /* CONFIG_ARCH_SUPPORTS_UPROBES */
@@ -77,6 +79,27 @@ struct uprobe {int copy; }; +enum uprobe_task_state { +UTASK_RUNNING , +UTASK_BP_HIT , +UTASK_SSTEP +}; + +/* +* uprobe_utask -- not a user-visible struct. +* Corresponds to a thread in a probed process. +* Guarded by uproc->mutex. +*/ +struct uprobe_task { +unsigned long xol_vaddr; +unsigned long vaddr; + +enum uprobe_task_state state; +struct uprobe_task_arch_info tskinfo; + +struct uprobe *active_uprobe; +}; +/* * Most architectures can use the default versions of @read_opcode(), * @set_bkpt(), @set_orig_insn(), and @is_bkpt_insn();
@@ -100,6 +123,7 @@ extern int register_uprobe(struct inode *inode, loff_t offset, struct uprobe_consumer *consumer);extern void unregister_uprobe (struct inode *inode,loff_t offset,struct uprobe_consumer *consumer); +extern void uprobe_free_utask (struct task_struct *tsk);struct vm_area_struct ;extern void uprobe_mmap (struct vm_area_struct *vma);
@@ -118,6 +142,7 @@ static inline void uprobe_dup_mmap(struct mm_struct *old_mm, struct mm_struct *mm) { } +static inline void uprobe_free_utask (struct task_struct *tsk) {}static inline void uprobe_mmap (struct vm_area_struct *vma) { }#endif /* CONFIG_UPROBES */ #endif /* _LINUX_UPROBES_H */
kernel/fork.c +4 -0
@@ -191,6 +191,7 @@ void __put_task_struct(struct task_struct *tsk)delayacct_tsk_free (tsk);put_signal_struct (tsk->signal); +uprobe_free_utask (tsk);if (!profile_handoff_task (tsk))free_task (tsk); }
@@ -1214,6 +1215,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,INIT_LIST_HEAD (&p->pi_state_list); p->pi_state_cache =NULL ;#endif +#ifdef CONFIG_UPROBES + p->utask =NULL ; +#endif /* * sigaltstack should be cleared when sharing the same VM */
kernel/uprobes.c +38 -0
@@ -806,3 +806,41 @@ mmap_out:up_read (&mm->mmap_sem);down_write (&mm->mmap_sem); } + +/* +* Called with no locks held. +* Called in context of a exiting or a exec-ing thread. +*/ +void uprobe_free_utask (struct task_struct *tsk) +{ +struct uprobe_task *utask = tsk->utask; + +if (!utask) +return ; + +if (utask->active_uprobe) +put_uprobe (utask->active_uprobe); +kfree (utask); + tsk->utask =NULL ; +} + +/* +* Allocate a uprobe_task object for the task. +* Called when the thread hits a breakpoint for the first time. +* +* Returns: +* - pointer to new uprobe_task on success +* - negative errno otherwise +*/ +static struct uprobe_task *add_utask (void ) +{ +struct uprobe_task *utask; + + utask =kzalloc (sizeof *utask,GFP_KERNEL ); +if (unlikely (utask ==NULL )) +return ERR_PTR (-ENOMEM ); + + utask->active_uprobe =NULL ; + current->utask = utask; +return utask; +}
PATCH v2 11/20 11: uprobes: slot allocation for uprobes
In reply to Srikar DronamrajuEvery task is allocated a fixed slot. When a probe is hit, the original instruction corresponding to the probe hit is copied to per-task fixed slot. Currently we allocate one page of slots for each mm. Bitmaps are used to know which slots are free. Each slot is made of 128 bytes so that its cache aligned.
TODO: On massively threaded processes (or if a huge number of processes share the same mm), there is a possiblilty of running out of slots. One alternative could be to extend the slots as when slots are required.
--- include/linux/mm_types.h | 4 + include/linux/uprobes.h | 21 ++++ kernel/fork.c | 4 + kernel/uprobes.c | 241 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 270 insertions(+), 0 deletions(-)
include/linux/mm_types.h +4 -0
@@ -12,6 +12,9 @@#include <linux/completion.h> #include <linux/cpumask.h> #include <linux/page-debug-flags.h> +#ifdef CONFIG_UPROBES +#include <linux/uprobes.h> +#endif #include <asm/page.h> #include <asm/mmu.h>
@@ -319,6 +322,7 @@ struct mm_struct {unsigned long uprobes_vaddr;struct list_head uprobes_list;atomic_t uprobes_count; +struct uprobes_xol_area *uprobes_xol_area;#endif };
include/linux/uprobes.h +21 -0
@@ -101,6 +101,25 @@ struct uprobe_task { };/* +* Every thread gets its own slot. Once it's assigned a slot, it +* keeps that slot until the thread exits. Only definite number +* of slots are allocated. +*/ + +struct uprobes_xol_area { +spinlock_t slot_lock;/* protects bitmap and slot (de)allocation*/ +unsigned long *bitmap;/* 0 = free slot */ +struct page *page; + +/* +* We keep the vma's vm_start rather than a pointer to the vma +* itself. The probed process or a naughty kernel module could make +* the vma go away, and we must handle that reasonably gracefully. +*/ +unsigned long vaddr;/* Page(s) of instruction slots */ +}; + +/* * Most architectures can use the default versions of @read_opcode(), * @set_bkpt(), @set_orig_insn(), and @is_bkpt_insn(); *
@@ -128,6 +147,7 @@ extern void uprobe_free_utask(struct task_struct *tsk);struct vm_area_struct ;extern void uprobe_mmap (struct vm_area_struct *vma);extern void uprobe_dup_mmap (struct mm_struct *old_mm,struct mm_struct *mm); +extern void uprobes_free_xol_area (struct mm_struct *mm);#else /* CONFIG_UPROBES is not defined */ static inline int register_uprobe (struct inode *inode,loff_t offset,struct uprobe_consumer *consumer)
@@ -144,5 +164,6 @@ static inline void uprobe_dup_mmap(struct mm_struct *old_mm, }static inline void uprobe_free_utask (struct task_struct *tsk) {}static inline void uprobe_mmap (struct vm_area_struct *vma) { } +static inline void uprobes_free_xol_area (struct mm_struct *mm) {}#endif /* CONFIG_UPROBES */ #endif /* _LINUX_UPROBES_H */
kernel/fork.c +4 -0
@@ -551,6 +551,7 @@ void mmput(struct mm_struct *mm)might_sleep ();if (atomic_dec_and_test (&mm->mm_users)) { +uprobes_free_xol_area (mm);exit_aio (mm);ksm_exit (mm);khugepaged_exit (mm);/* must run before exit_mmap */
@@ -677,6 +678,9 @@ struct mm_struct *dup_mm(struct task_struct *tsk)memcpy (mm, oldmm,sizeof (*mm));/* Initializing for Swap token stuff */ +#ifdef CONFIG_UPROBES + mm->uprobes_xol_area =NULL ; +#endif mm->token_priority =0 ; mm->last_interval =0 ;
kernel/uprobes.c +241 -0
273 lines not on this page · raw message
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 12/20 12: uprobes: get the breakpoint address.
In reply to Srikar DronamrajuOn a breakpoint hit, return the address where the breakpoint was hit.
--- include/linux/uprobes.h | 5 +++++ kernel/uprobes.c | 11 +++++++++++ 2 files changed, 16 insertions(+), 0 deletions(-)
include/linux/uprobes.h +5 -0
@@ -146,6 +146,7 @@ extern void uprobe_free_utask(struct task_struct *tsk);struct vm_area_struct ;extern void uprobe_mmap (struct vm_area_struct *vma); +extern unsigned long uprobes_get_bkpt_addr (struct pt_regs *regs);extern void uprobe_dup_mmap (struct mm_struct *old_mm,struct mm_struct *mm);extern void uprobes_free_xol_area (struct mm_struct *mm);#else /* CONFIG_UPROBES is not defined */
@@ -165,5 +166,9 @@ static inline void uprobe_dup_mmap(struct mm_struct *old_mm,static inline void uprobe_free_utask (struct task_struct *tsk) {}static inline void uprobe_mmap (struct vm_area_struct *vma) { }static inline void uprobes_free_xol_area (struct mm_struct *mm) {} +static inline unsigned long uprobes_get_bkpt_addr (struct pt_regs *regs) +{ +return 0 ; +}#endif /* CONFIG_UPROBES */ #endif /* _LINUX_UPROBES_H */
kernel/uprobes.c +11 -0
@@ -1044,6 +1044,17 @@ static void xol_free_insn_slot(struct task_struct *tsk, unsigned long slot_addr) __func__, slot_addr); } +/** +* uprobes_get_bkpt_addr - compute address of bkpt given post-bkpt regs +* @regs: Reflects the saved state of the task after it has hit a breakpoint +* instruction. +* Return the address of the breakpoint instruction. +*/ +unsigned long uprobes_get_bkpt_addr (struct pt_regs *regs) +{ +return instruction_pointer (regs) -UPROBES_BKPT_INSN_SIZE ; +} +/* * Called with no locks held. * Called in context of a exiting or a exec-ing thread.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 13/20 13: x86: x86 specific probe handling
In reply to Srikar DronamrajuProvides x86 specific implementations for setting the current instruction pointer, pre single-step and post-singlestep handling, enabling and disabling singlestep.
This patch also introduces TIF_UPROBE which is set by uprobes notifier code. TIF_UPROBE indicates that there is pending work that needs to be done at do_notify_resume time.
--- arch/x86/include/asm/thread_info.h | 2 arch/x86/include/asm/uprobes.h | 10 ++ arch/x86/kernel/uprobes.c | 157 ++++++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 1 deletions(-)
arch/x86/include/asm/thread_info.h +2 -0
@@ -84,6 +84,7 @@ struct thread_info {#define TIF_SECCOMP 8/* secure computing */ #define TIF_MCE_NOTIFY 10/* notify userspace of an MCE */ #define TIF_USER_RETURN_NOTIFY 11/* notify kernel of userspace return */ +#define TIF_UPROBE 12/* breakpointed or singlestepping */ #define TIF_NOTSC 16/* TSC is not accessible in userland */ #define TIF_IA32 17/* 32bit process */ #define TIF_FORK 18/* ret_from_fork */
@@ -107,6 +108,7 @@ struct thread_info {#define _TIF_SECCOMP (1 << TIF_SECCOMP)#define _TIF_MCE_NOTIFY (1 << TIF_MCE_NOTIFY)#define _TIF_USER_RETURN_NOTIFY (1 << TIF_USER_RETURN_NOTIFY) +#define _TIF_UPROBE (1 << TIF_UPROBE)#define _TIF_NOTSC (1 << TIF_NOTSC)#define _TIF_IA32 (1 << TIF_IA32)#define _TIF_FORK (1 << TIF_FORK)
arch/x86/include/asm/uprobes.h +9 -1
@@ -37,11 +37,19 @@ struct uprobe_arch_info {struct uprobe_task_arch_info {unsigned long saved_scratch_register; +int oflags; };#else struct uprobe_arch_info {}; -struct uprobe_task_arch_info {}; +struct uprobe_task_arch_info { +int oflags; +};#endif struct uprobe ;extern int analyze_insn (struct task_struct *tsk,struct uprobe *uprobe); +extern void set_ip (struct pt_regs *regs,unsigned long vaddr); +extern int pre_xol (struct uprobe *uprobe,struct pt_regs *regs); +extern int post_xol (struct uprobe *uprobe,struct pt_regs *regs); +extern void arch_uprobe_enable_sstep (struct pt_regs *regs); +extern void arch_uprobe_disable_sstep (struct pt_regs *regs);#endif /* _ASM_UPROBES_H */
arch/x86/kernel/uprobes.c +157 -0
166 lines not on this page · raw message
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 14/20 14: uprobes: Handing int3 and singlestep exception.
In reply to Srikar DronamrajuOn int3, set the TIF_UPROBE flag and if a task specific info is available, indicate the task state as breakpoint hit. Setting the TIF_UPROBE flag results in uprobe_notify_resume being called. uprobe_notify_resume walks thro the list of vmas and then matches the inode and offset corresponding to the instruction pointer to enteries in rbtree. Once a matcing uprobes is found, run the handlers for all the consumers that have registered.
On singlestep exception, perform the necessary fixups and allow the process to continue. The necessary fixups are determined at instruction analysis time.
TODO: If there is no matching uprobe, signal a trap to the process.
--- include/linux/uprobes.h | 4 + kernel/uprobes.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+), 0 deletions(-)
include/linux/uprobes.h +4 -0
@@ -149,6 +149,9 @@ extern void uprobe_mmap(struct vm_area_struct *vma);extern unsigned long uprobes_get_bkpt_addr (struct pt_regs *regs);extern void uprobe_dup_mmap (struct mm_struct *old_mm,struct mm_struct *mm);extern void uprobes_free_xol_area (struct mm_struct *mm); +extern int uprobe_post_notifier (struct pt_regs *regs); +extern int uprobe_bkpt_notifier (struct pt_regs *regs); +extern void uprobe_notify_resume (struct pt_regs *regs);#else /* CONFIG_UPROBES is not defined */ static inline int register_uprobe (struct inode *inode,loff_t offset,struct uprobe_consumer *consumer)
@@ -166,6 +169,7 @@ static inline void uprobe_dup_mmap(struct mm_struct *old_mm,static inline void uprobe_free_utask (struct task_struct *tsk) {}static inline void uprobe_mmap (struct vm_area_struct *vma) { }static inline void uprobes_free_xol_area (struct mm_struct *mm) {} +static inline void uprobe_notify_resume (struct pt_regs *regs) {}static inline unsigned long uprobes_get_bkpt_addr (struct pt_regs *regs) {return 0 ;
kernel/uprobes.c +146 -0
149 lines not on this page · raw message
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 15/20 15: x86: uprobes exception notifier for x86.
In reply to Srikar DronamrajuProvides a uprobes exception notifier for x86. This uprobes_exception notifier gets called in interrupt context and routes int3 and singlestep exception when a uprobed process encounters a INT3 or a singlestep exception.
--- arch/x86/include/asm/uprobes.h | 3 +++ arch/x86/kernel/signal.c | 14 ++++++++++++++ arch/x86/kernel/uprobes.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 0 deletions(-)
arch/x86/include/asm/uprobes.h +3 -0
@@ -22,6 +22,7 @@* Srikar Dronamraju * Jim Keniston */ +#include <linux/notifier.h> typedef u8 uprobe_opcode_t ;#define MAX_UINSN_BYTES 16
@@ -52,4 +53,6 @@ extern int pre_xol(struct uprobe *uprobe, struct pt_regs *regs);extern int post_xol (struct uprobe *uprobe,struct pt_regs *regs);extern void arch_uprobe_enable_sstep (struct pt_regs *regs);extern void arch_uprobe_disable_sstep (struct pt_regs *regs); +extern int uprobes_exception_notify (struct notifier_block *self, +unsigned long val,void *data);#endif /* _ASM_UPROBES_H */
arch/x86/kernel/signal.c +14 -0
@@ -20,6 +20,7 @@#include <linux/personality.h> #include <linux/uaccess.h> #include <linux/user-return-notifier.h> +#include <linux/uprobes.h> #include <asm/processor.h> #include <asm/ucontext.h>
@@ -848,6 +849,19 @@ do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)if (thread_info_flags & _TIF_SIGPENDING)do_signal (regs); +if (thread_info_flags & _TIF_UPROBE) { +clear_thread_flag (TIF_UPROBE ); +#ifdef CONFIG_X86_32 +/* +* On x86_32, do_notify_resume() gets called with +* interrupts disabled. Hence enable interrupts if they +* are still disabled. +*/ +local_irq_enable (); +#endif +uprobe_notify_resume (regs); + } +if (thread_info_flags & _TIF_NOTIFY_RESUME) {clear_thread_flag (TIF_NOTIFY_RESUME );tracehook_notify_resume (regs);
arch/x86/kernel/uprobes.c +29 -0
@@ -569,3 +569,32 @@ void arch_uprobe_disable_sstep(struct pt_regs *regs)clear_thread_flag (TIF_FORCED_TF ); regs->flags &= ~X86_EFLAGS_TF ; } + +/* +* Wrapper routine for handling exceptions. +*/ +int uprobes_exception_notify (struct notifier_block *self, +unsigned long val,void *data) +{ +struct die_args *args = data; +struct pt_regs *regs = args->regs; +int ret =NOTIFY_DONE ; + +/* We are only interested in userspace traps */ +if (regs && !user_mode_vm (regs)) +return NOTIFY_DONE ; + +switch (val) { +case DIE_INT3 : +/* Run your handler here */ +if (uprobe_bkpt_notifier (regs)) + ret =NOTIFY_STOP ; +break ; +case DIE_DEBUG : +if (uprobe_post_notifier (regs)) + ret =NOTIFY_STOP ; +default : +break ; + } +return ret; +}
PATCH v2 16/20 16: uprobes: register a notifier for uprobes.
In reply to Srikar DronamrajuUprobe needs to be intimated on int3 and singlestep exceptions. Hence uprobes registers a die notifier so that its notified of the events.
--- kernel/uprobes.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-)
kernel/uprobes.c +19 -0
@@ -33,6 +33,7 @@#include <linux/rmap.h> /* needed for anon_vma_prepare */ #include <linux/mman.h> /* needed for PROT_EXEC, MAP_PRIVATE */ #include <linux/file.h> /* needed for fput() */ +#include <linux/kdebug.h> /* needed for notifier mechanism */ #define UINSNS_PER_PAGE (PAGE_SIZE/UPROBES_XOL_SLOT_BYTES)#define MAX_UPROBES_XOL_SLOTS UINSNS_PER_PAGE
@@ -1242,3 +1243,21 @@ int uprobe_post_notifier(struct pt_regs *regs) }return 0 ; } + +struct notifier_block uprobes_exception_nb = { + .notifier_call = uprobes_exception_notify, + .priority =0x7ffffff0 , +}; + +static int __init init_uprobes (void ) +{ +register_die_notifier (&uprobes_exception_nb); +return 0 ; +} + +static void __exit exit_uprobes(void) +{ +} + +module_init (init_uprobes); +module_exit (exit_uprobes);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 17/20 17: uprobes: filter chain
In reply to Srikar DronamrajuLoops through the filters callbacks of currently registered consumers to see if any consumer is interested in tracing this task.
--- kernel/uprobes.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-)
kernel/uprobes.c +18 -0
@@ -428,6 +428,24 @@ static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs) }/* Acquires uprobe->consumer_rwsem */ +static bool filter_chain (struct uprobe *uprobe,struct task_struct *t) +{ +struct uprobe_consumer *consumer; +bool ret = false; + +down_read (&uprobe->consumer_rwsem); +for (consumer = uprobe->consumers; consumer; + consumer = consumer->next) { +if (!consumer->filter || consumer->filter (consumer, t)) { + ret = true; +break ; + } + } +up_read (&uprobe->consumer_rwsem); +return ret; +} + +/* Acquires uprobe->consumer_rwsem */ static void add_consumer (struct uprobe *uprobe,struct uprobe_consumer *consumer) {
PATCH v2 18/20 18: uprobes: commonly used filters.
In reply to Srikar DronamrajuProvides most commonly used filters that most users of uprobes can reuse. However this would be useful once we can dynamically associate a filter with a uprobe-event tracer.
--- include/linux/uprobes.h | 5 +++++ kernel/uprobes.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 0 deletions(-)
include/linux/uprobes.h +5 -0
@@ -65,6 +65,11 @@ struct uprobe_consumer {struct uprobe_consumer *next; }; +struct uprobe_simple_consumer { +struct uprobe_consumer consumer; +pid_t fvalue; +}; +struct uprobe {struct rb_node rb_node;/* node in the rb tree */ atomic_t ref;
kernel/uprobes.c +50 -0
56 lines not on this page · raw message
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 20/20 20: tracing: uprobes trace_event interface
In reply to Srikar DronamrajuImplements trace_event support for uprobes. In its current form it can be used to put probes at a specified offset in a file and dump the required registers when the code flow reaches the probed address.
The following example shows how to dump the instruction pointer and %ax a register at the probed text address. Here we are trying to probe zfree in /bin/zsh
# cd /sys/kernel/debug/tracing/
# cat /proc/`pgrep zsh`/maps | grep /bin/zsh | grep r-xp
00400000-0048a000 r-xp 00000000 08:03 130904 /bin/zsh
# objdump -T /bin/zsh | grep -w zfree
0000000000446420 g DF .text 0000000000000012 Base zfree
# echo 'p /bin/zsh:0x46420 %ip %ax' > uprobe_events
# cat uprobe_events
p:uprobes/p_zsh_0x46420 /bin/zsh:0x0000000000046420
# echo 1 > events/uprobes/enable
# sleep 20
# echo 0 > events/uprobes/enable
# cat trace
# tracer: nop
#
# TASK-PID CPU# TIMESTAMP FUNCTION
# | | | | |
zsh-24842 [006] 258544.995456: p_zsh_0x46420: (0x446420) arg1=446421 arg2=79
zsh-24842 [007] 258545.000270: p_zsh_0x46420: (0x446420) arg1=446421 arg2=79
zsh-24842 [002] 258545.043929: p_zsh_0x46420: (0x446420) arg1=446421 arg2=79
zsh-24842 [004] 258547.046129: p_zsh_0x46420: (0x446420) arg1=446421 arg2=79TODO: Documentation/trace/uprobetrace.txt
TODO: Connect a filter to a consumer.
--- arch/Kconfig | 10 - kernel/trace/Kconfig | 16 + kernel/trace/Makefile | 1 kernel/trace/trace.h | 5 kernel/trace/trace_kprobe.c | 4 kernel/trace/trace_probe.c | 14 + kernel/trace/trace_probe.h | 6 kernel/trace/trace_uprobe.c | 800 +++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 839 insertions(+), 17 deletions(-) create mode 100644 kernel/trace/trace_uprobe.c
arch/Kconfig +1 -9
@@ -62,16 +62,8 @@ config OPTPROBES depends on !PREEMPT config UPROBES - bool "User-space probes (EXPERIMENTAL)" - depends on ARCH_SUPPORTS_UPROBES - depends on MMU select MM_OWNER - help - Uprobes enables kernel subsystems to establish probepoints - in user applications and execute handler functions when - the probepoints are hit. - - If in doubt, say "N". + def_bool n config HAVE_EFFICIENT_UNALIGNED_ACCESS bool
kernel/trace/Kconfig +16 -0
@@ -386,6 +386,22 @@ config KPROBE_EVENT This option is also required by perf-probe subcommand of perf tools. If you want to use perf tools, this option is strongly recommended. +config UPROBE_EVENT + bool "Enable uprobes-based dynamic events" + depends on ARCH_SUPPORTS_UPROBES + depends on MMU + select UPROBES + select PROBE_EVENTS + select TRACING + default n + help + This allows the user to add tracing events on top of userspace dynamic + events (similar to tracepoints) on the fly via the traceevents interface. + Those events can be inserted wherever uprobes can probe, and record + various registers. + This option is required if you plan to use perf-probe subcommand of perf + tools on user space applications. + config PROBE_EVENTS def_bool n
kernel/trace/Makefile +1 -0
@@ -57,5 +57,6 @@ ifeq ($(CONFIG_TRACING),y) obj-$(CONFIG_KGDB_KDB) += trace_kdb.o endif obj-$(CONFIG_PROBE_EVENTS) +=trace_probe.o +obj-$(CONFIG_UPROBE_EVENT) += trace_uprobe.o libftrace-y := ftrace.o
kernel/trace/trace.h +5 -0
@@ -97,6 +97,11 @@ struct kretprobe_trace_entry_head {unsigned long ret_ip; }; +struct uprobe_trace_entry_head { +struct trace_entry ent; +unsigned long ip; +}; +/* * trace_flag_type is an enumeration that holds different * states when a trace occurs. These are:
kernel/trace/trace_kprobe.c +2 -2
@@ -374,8 +374,8 @@ static int create_trace_probe(int argc, char **argv) }/* Parse fetch argument */ - ret =traceprobe_parse_probe_arg (arg, &tp->size, &tp->args[i], - is_return); + ret =traceprobe_parse_probe_arg (arg, &tp->size, + &tp->args[i], is_return, true);if (ret) {pr_info ("Parse error at argument[%d]. (%d)\n" , i, ret); goto error;
kernel/trace/trace_probe.c +10 -4
@@ -508,13 +508,17 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t,/* Recursive argument parser */ static int parse_probe_arg (char *arg,const struct fetch_type *t, -struct fetch_param *f,bool is_return) +struct fetch_param *f,bool is_return,bool is_kprobe) {int ret =0 ;unsigned long param;long offset;char *tmp; +/* Until uprobe_events supports only reg arguments */ +if (!is_kprobe && arg[0 ] !='%' ) +return -EINVAL ; +switch (arg[0 ]) {case '$' : ret =parse_probe_vars (arg +1 , t, f, is_return);
@@ -564,7 +568,8 @@ static int parse_probe_arg(char *arg, const struct fetch_type *t,if (!dprm)return -ENOMEM ; dprm->offset = offset; - ret =parse_probe_arg (arg, t2, &dprm->orig, is_return); + ret =parse_probe_arg (arg, t2, &dprm->orig, is_return, + is_kprobe);if (ret)kfree (dprm);else {
@@ -618,7 +623,7 @@ static int __parse_bitfield_probe_arg(const char *bf,/* String length checking wrapper */ int traceprobe_parse_probe_arg (char *arg,ssize_t *size, -struct probe_arg *parg,bool is_return) +struct probe_arg *parg,bool is_return,bool is_kprobe) {const char *t;int ret;
@@ -644,7 +649,8 @@ int traceprobe_parse_probe_arg(char *arg, ssize_t *size, } parg->offset = *size; *size += parg->type->size; - ret =parse_probe_arg (arg, parg->type, &parg->fetch, is_return); + ret =parse_probe_arg (arg, parg->type, &parg->fetch, is_return, + is_kprobe);if (ret >=0 && t !=NULL ) ret =__parse_bitfield_probe_arg (t, parg->type, &parg->fetch);if (ret >=0 ) {
kernel/trace/trace_probe.h +4 -2
@@ -48,6 +48,7 @@#define FIELD_STRING_IP "__probe_ip"#define FIELD_STRING_RETIP "__probe_ret_ip"#define FIELD_STRING_FUNC "__probe_func" +#define FIELD_STRING_PID "__probe_pid"#undef DEFINE_FIELD#define DEFINE_FIELD (type, item, name, is_signed) \
@@ -64,6 +65,7 @@/* Flags for trace_probe */ #define TP_FLAG_TRACE 1#define TP_FLAG_PROFILE 2 +#define TP_FLAG_UPROBE 4/* data_rloc: data relative location, compatible with u32 */
@@ -130,7 +132,7 @@ static inline __kprobes void call_fetch(struct fetch_param *fprm, }/* Check the name is good for event/group/fields */ -static int is_good_name (const char *name) +static inline int is_good_name (const char *name) {if (!isalpha (*name) && *name !='_' )return 0 ;
@@ -142,7 +144,7 @@ static int is_good_name(const char *name) }extern int traceprobe_parse_probe_arg (char *arg,ssize_t *size, -struct probe_arg *parg,bool is_return); +struct probe_arg *parg,bool is_return,bool is_kprobe);extern int traceprobe_conflict_field_name (const char *name,struct probe_arg *args,int narg);
kernel/trace/trace_uprobe.c new file +800 -0
800 lines not on this page · raw message
PATCH v2 19/20 19: tracing: Extract out common code for kprobes/uprobes traceevents.
In reply to Srikar DronamrajuMove parts of trace_kprobe.c that can be shared with upcoming trace_uprobe.c. Common code to kernel/trace/trace_probe.h and kernel/trace/trace_probe.c.
--- kernel/trace/Kconfig | 4 kernel/trace/Makefile | 1 kernel/trace/trace_kprobe.c | 861 +------------------------------------------ kernel/trace/trace_probe.c | 747 +++++++++++++++++++++++++++++++++++++ kernel/trace/trace_probe.h | 158 ++++++++ 5 files changed, 929 insertions(+), 842 deletions(-) create mode 100644 kernel/trace/trace_probe.c create mode 100644 kernel/trace/trace_probe.h
kernel/trace/Kconfig +4 -0
@@ -373,6 +373,7 @@ config KPROBE_EVENT depends on HAVE_REGS_AND_STACK_ACCESS_API bool "Enable kprobes-based dynamic events" select TRACING + select PROBE_EVENTS default y help This allows the user to add tracing events (similar to tracepoints)
@@ -385,6 +386,9 @@ config KPROBE_EVENT This option is also required by perf-probe subcommand of perf tools. If you want to use perf tools, this option is strongly recommended. +config PROBE_EVENTS + def_bool n + config DYNAMIC_FTRACE bool "enable/disable ftrace tracepoints dynamically" depends on FUNCTION_TRACER
kernel/trace/Makefile +1 -0
@@ -56,5 +56,6 @@ obj-$(CONFIG_TRACEPOINTS) += power-traces.o ifeq ($(CONFIG_TRACING),y) obj-$(CONFIG_KGDB_KDB) += trace_kdb.o endif +obj-$(CONFIG_PROBE_EVENTS) +=trace_probe.o libftrace-y := ftrace.o
kernel/trace/trace_kprobe.c +19 -842
973 lines not on this page · raw message
kernel/trace/trace_probe.c new file +747 -0
747 lines not on this page · raw message
kernel/trace/trace_probe.h new file +158 -0
158 lines not on this page · raw message
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerRe: [PATCH v2 2.6.38-rc8-tip 1/20] 1: mm: Move replace_page() to mm/memory.c
In reply to Srikar DronamrajuQuoted 4 lines · Srikar Dronamraju
User bkpt will use background page replacement approach to insert/delete breakpoints. Background page replacement approach is based on
replace_page. Hencereplace_page()loses its static attribute.
Just a nitpick, but since replace_page() is being moved, could you specify that in the change log. Something like:
"Hence, replace_page() is moved from ksm.c into memory.c and its static attribute is removed."
I like to see in the change log "move x to y" when that is actually done, because it is hard to see if anything actually changed when code is moved. Ideally it is best to move code in one patch and make the change in another. If you do cut another version of this patch set, could you do that. This alone is not enough to require a new release.
Thanks,
-- Steve
Quoted 157 lines
Signed-off-by Srikar Dronamraju <[email protected]>Signed-off-by Ananth N Mavinakayanahalli <[email protected]>--- include/linux/mm.h | 2 ++ mm/ksm.c | 62 ---------------------------------------------------- mm/memory.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 62 deletions(-)include/linux/mm.h +2
-0@@ -984,6 +984,8 @@ void account_page_writeback(struct page *page);int set_page_dirty (struct page *page);int set_page_dirty_lock (struct page *page);int clear_page_dirty_for_io (struct page *page); +int replace_page (struct vm_area_struct *vma,struct page *page, +struct page *kpage,pte_t orig_pte);/* Is the vma a continuation of the stack vma above it? */ static inline int vma_stack_continue (struct vm_area_struct *vma,unsigned long addr)mm/ksm.c +0
-62@@ -765,68 +765,6 @@ out:return err; } -/** -* replace_page - replace page in vma by new ksm page -* @vma: vma that holds the pte pointing to page -* @page: the page we are replacing by kpage -* @kpage: the ksm page we replace page by -* @orig_pte: the original value of the pte -* -* Returns 0 on success, -EFAULT on failure. -*/ -static int replace_page (struct vm_area_struct *vma,struct page *page, -struct page *kpage,pte_t orig_pte) -{ -struct mm_struct *mm = vma->vm_mm; -pgd_t *pgd; -pud_t *pud; -pmd_t *pmd; -pte_t *ptep; -spinlock_t *ptl; -unsigned long addr; -int err = -EFAULT ; - - addr =page_address_in_vma (page, vma); -if (addr == -EFAULT ) - goto out; - - pgd =pgd_offset (mm, addr); -if (!pgd_present (*pgd)) - goto out; - - pud =pud_offset (pgd, addr); -if (!pud_present (*pud)) - goto out; - - pmd =pmd_offset (pud, addr); -BUG_ON (pmd_trans_huge (*pmd)); -if (!pmd_present (*pmd)) - goto out; - - ptep =pte_offset_map_lock (mm, pmd, addr, &ptl); -if (!pte_same (*ptep, orig_pte)) { -pte_unmap_unlock (ptep, ptl); - goto out; - } - -get_page (kpage); -page_add_anon_rmap (kpage, vma, addr); - -flush_cache_page (vma, addr,pte_pfn (*ptep)); -ptep_clear_flush (vma, addr, ptep); -set_pte_at_notify (mm, addr, ptep,mk_pte (kpage, vma->vm_page_prot)); - -page_remove_rmap (page); -if (!page_mapped (page)) -try_to_free_swap (page); -put_page (page); - -pte_unmap_unlock (ptep, ptl); - err =0 ; -out: -return err; -} -static int page_trans_compound_anon_split (struct page *page) {int ret =0 ;mm/memory.c +55
-0@@ -2669,6 +2669,68 @@ void unmap_mapping_range(struct address_space *mapping, }EXPORT_SYMBOL (unmap_mapping_range); +/** +* replace_page - replace page in vma by new ksm page +* @vma: vma that holds the pte pointing to page +* @page: the page we are replacing by kpage +* @kpage: the ksm page we replace page by +* @orig_pte: the original value of the pte +* +* Returns 0 on success, -EFAULT on failure. +*/ +int replace_page (struct vm_area_struct *vma,struct page *page, +struct page *kpage,pte_t orig_pte) +{ +struct mm_struct *mm = vma->vm_mm; +pgd_t *pgd; +pud_t *pud; +pmd_t *pmd; +pte_t *ptep; +spinlock_t *ptl; +unsigned long addr; +int err = -EFAULT ; + + addr =page_address_in_vma (page, vma); +if (addr == -EFAULT ) + goto out; + + pgd =pgd_offset (mm, addr); +if (!pgd_present (*pgd)) + goto out; + + pud =pud_offset (pgd, addr); +if (!pud_present (*pud)) + goto out; + + pmd =pmd_offset (pud, addr); +BUG_ON (pmd_trans_huge (*pmd)); +if (!pmd_present (*pmd)) + goto out; + + ptep =pte_offset_map_lock (mm, pmd, addr, &ptl); +if (!pte_same (*ptep, orig_pte)) { +pte_unmap_unlock (ptep, ptl); + goto out; + } + +get_page (kpage); +page_add_anon_rmap (kpage, vma, addr); + +flush_cache_page (vma, addr,pte_pfn (*ptep)); +ptep_clear_flush (vma, addr, ptep); +set_pte_at_notify (mm, addr, ptep,mk_pte (kpage, vma->vm_page_prot)); + +page_remove_rmap (page); +if (!page_mapped (page)) +try_to_free_swap (page); +put_page (page);
mm/memory.c void unmap_mapping_range(struct address_space *mapping, · line 2736
Quoted 10 lines
mm/memory.c +7
-0+ +pte_unmap_unlock (ptep, ptl); + err =0 ; +out: +return err; +} +int vmtruncate_range (struct inode *inode,loff_t offset,loff_t end) {struct address_space *mapping = inode->i_mapping;
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerRe: [PATCH v2 2.6.38-rc8-tip 3/20] 3: uprobes: Breakground page replacement.
In reply to Srikar DronamrajuQuoted 10 lines · Srikar Dronamraju
+/*
+ * Most architectures can use the default versions of @read_opcode(),
+ * @set_bkpt(), @set_orig_insn(), and @is_bkpt_insn();
+ *
+ * @set_ip:
+ * Set the instruction pointer in @regs to @vaddr.
+ * @analyze_insn:+ * Analyze @user_bkpt->insn. Return 0 if @user_bkpt->insn is an + * instruction you can probe, or a negative errno (typically -%EPERM) + * otherwise. Determine what sort of
sort of ... what?
-- Steve
Quoted 7 lines
+ * @pre_xol:
+ * @post_xol:+ * XOL-related fixups @post_xol() (and possibly @pre_xol()) will need + * to do for this instruction, and annotate @user_bkpt accordingly. + * You may modify @user_bkpt->insn (e.g., the x86_64 port does this + * for rip-relative instructions).+ */
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerRe: [PATCH v2 2.6.38-rc8-tip 3/20] 3: uprobes: Breakground page replacement.
In reply to Srikar DronamrajuQuoted 20 lines · Srikar Dronamraju
kernel/uprobes.c new file +20
-0+/* +* Called with tsk->mm->mmap_sem held (either for read or write and +* with a reference to tsk->mm. +*/ +static int write_opcode (struct task_struct *tsk,struct uprobe * uprobe, +unsigned long vaddr,uprobe_opcode_t opcode) +{ +struct page *old_page, *new_page; +void *vaddr_old, *vaddr_new; +struct vm_area_struct *vma; +spinlock_t *ptl; +pte_t *orig_pte; +unsigned long addr; +int ret = -EINVAL ; + +/* Read the page with vaddr into memory */ + ret =get_user_pages (tsk, tsk->mm, vaddr,1 ,1 ,1 , &old_page, &vma); +if (ret <=0 ) +return -EINVAL ; + ret = -EINVAL ;
kernel/uprobes.c line 69
Quoted 10 lines
kernel/uprobes.c new file +10
-0+ +/* +* check if the page we are interested is read-only mapped +* Since we are interested in text pages, Our pages of interest +* should be mapped read-only. +*/ +if ((vma->vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) == + (VM_READ |VM_EXEC )) + goto put_out; +
I'm confused by the above comment and code. You state we are only interested text pages mapped read-only, but then if the page is mapped read/exec we exit out? It is fine if it is anything but READ/EXEC.
I'm also curious to why we can't modify text code that is also mapped as read/write.
-- Steve
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerRe: [PATCH v2 2.6.38-rc8-tip 5/20] 5: Uprobes: register/unregister probes.
In reply to Srikar DronamrajuQuoted 5 lines · Srikar Dronamraju
kernel/uprobes.c +5
-0+/* Returns 0 if it can install one probe */ +int register_uprobe (struct inode *inode,loff_t offset, +struct uprobe_consumer *consumer) +{ +struct prio_tree_iter iter;
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 473
Quoted 10 lines
kernel/uprobes.c +10
-0+struct list_head tmp_list; +struct address_space *mapping; +struct mm_struct *mm, *tmpmm; +struct vm_area_struct *vma; +struct uprobe *uprobe; +int ret =-1 ; + +if (!inode || !consumer || consumer->next) +return -EINVAL ; + uprobe =uprobes_add (inode, offset);
What happens if uprobes_add() returns NULL?
-- Steve
Quoted 9 lines
kernel/uprobes.c +9
-0+INIT_LIST_HEAD (&tmp_list); + + mapping = inode->i_mapping; + +mutex_lock (&uprobes_mutex); +if (uprobe->consumers) { + ret =0 ; + goto consumers_add; + }
Re: [PATCH v2 2.6.38-rc8-tip 3/20] 3: uprobes: Breakground page replacement.
In reply to Srikar DronamrajuQuoted 28 lines · Srikar Dronamraju
kernel/uprobes.c new file +28
-0+/** +* read_opcode - read the opcode at a given virtual address. +* @tsk: the probed task. +* @vaddr: the virtual address to store the opcode. +* @opcode: location to store the read opcode. +* +* For task @tsk, read the opcode at @vaddr and store it in @opcode. +* Return 0 (success) or a negative errno. +*/ +int __weak read_opcode (struct task_struct *tsk,unsigned long vaddr, +uprobe_opcode_t *opcode) +{ +struct vm_area_struct *vma; +struct page *page; +void *vaddr_new; +int ret; + + ret =get_user_pages (tsk, tsk->mm, vaddr,1 ,0 ,0 , &page, &vma); +if (ret <=0 ) +return -EFAULT ; + ret = -EFAULT ; + +/* +* check if the page we are interested is read-only mapped +* Since we are interested in text pages, Our pages of interest +* should be mapped read-only. +*/ + if ((vma->vm_flags & (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)) ==
kernel/uprobes.c line 153
Quoted 10 lines
kernel/uprobes.c new file +10
-0+ (VM_READ|VM_EXEC)) + goto put_out; + +lock_page (page); + vaddr_new =kmap_atomic (page,KM_USER0 ); + vaddr &= ~PAGE_MASK ; +memcpy (&opcode, vaddr_new + vaddr, uprobe_opcode_sz); +kunmap_atomic (vaddr_new,KM_USER0 ); +unlock_page (page); + ret = uprobe_opcode_sz;
This looks wrong. We should be setting ret = 0 on success here?
Quoted 5 lines
kernel/uprobes.c new file +5
-0+ +put_out: +put_page (page);/* we did a get_page in the beginning */ +return ret; +}
Signature · 8 lines
steve -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 1/20] 1: mm: Move replace_page() to mm/memory.c
In reply to Steven RostedtQuoted 11 lines · Steven Rostedt
Quoted 4 lines · Srikar Dronamraju
User bkpt will use background page replacement approach to insert/delete breakpoints. Background page replacement approach is based on
replace_page. Hencereplace_page()loses its static attribute.Just a nitpick, but since
replace_page()is being moved, could you specify that in the change log. Something like:"Hence,
replace_page()is moved fromksm.cintomemory.cand its static attribute is removed."
Okay, Will take care to add the moved from ksm.c into memory.c in the next version of patchset.
Quoted 4 lines
I like to see in the change log "move x to y" when that is actually done, because it is hard to see if anything actually changed when code is moved. Ideally it is best to move code in one patch and make the
As discussed in IRC, moving and removing the static attribute had to be one patch so that mm/ksm.c compiles correctly. The other option we have is to remove the static attribute first and then moving the function.
Quoted 3 lines
change in another. If you do cut another version of this patch set, could you do that. This alone is not enough to require a new release.
Signature · 9 lines
Thanks and Regards Srikar -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerRe: [PATCH v2 2.6.38-rc8-tip 1/20] 1: mm: Move replace_page() to mm/memory.c
Quoted 8 lines · Srikar Dronamraju
Quoted 6 lines · Steven Rostedt
Quoted 4 lines · Srikar Dronamraju
User bkpt will use background page replacement approach to insert/delete breakpoints. Background page replacement approach is based on
replace_page. Hencereplace_page()loses its static attribute.
Quoted 8 lines
Quoted 5 lines
Just a nitpick, but since
replace_page()is being moved, could you specify that in the change log. Something like:"Hence,
replace_page()is moved fromksm.cintomemory.cand its static attribute is removed."Okay, Will take care to add the moved from
ksm.cintomemory.cin the next version of patchset.
Thanks!
Quoted 8 lines
Quoted 3 lines
I like to see in the change log "move x to y" when that is actually done, because it is hard to see if anything actually changed when code is moved. Ideally it is best to move code in one patch and make the
As discussed in IRC, moving and removing the static attribute had to be one patch so that
mm/ksm.ccompiles correctly. The other option we have is to remove the static attribute first and then moving the function.
Hmm, maybe that may be a good idea. Since it is really two changes. One is to make it global for other usages. I'm not even sure why you moved it. The change log for the move can explain that.
-- Steve
Quoted 5 lines
Quoted 4 lines
change in another. If you do cut another version of this patch set, could you do that. This alone is not enough to require a new release.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 3/20] 3: uprobes: Breakground page replacement.
In reply to Steven RostedtQuoted 27 lines · Steven Rostedt
Quoted 26 lines · Srikar Dronamraju
kernel/uprobes.c new file +26
-0+/* +* Called with tsk->mm->mmap_sem held (either for read or write and +* with a reference to tsk->mm. +*/ +static int write_opcode (struct task_struct *tsk,struct uprobe * uprobe, +unsigned long vaddr,uprobe_opcode_t opcode) +{ +struct page *old_page, *new_page; +void *vaddr_old, *vaddr_new; +struct vm_area_struct *vma; +spinlock_t *ptl; +pte_t *orig_pte; +unsigned long addr; +int ret = -EINVAL ; + +/* Read the page with vaddr into memory */ + ret =get_user_pages (tsk, tsk->mm, vaddr,1 ,1 ,1 , &old_page, &vma); +if (ret <=0 ) +return -EINVAL ; + ret = -EINVAL ; + +/* +* check if the page we are interested is read-only mapped +* Since we are interested in text pages, Our pages of interest +* should be mapped read-only. +*/
Quoted 8 lines
kernel/uprobes.c line 69
Quoted 4 lines
kernel/uprobes.c new file +4
-0+if ((vma->vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) == + (VM_READ |VM_EXEC )) + goto put_out; +I'm confused by the above comment and code. You state we are only interested text pages mapped read-only, but then if the page is mapped read/exec we exit out? It is fine if it is anything but READ/EXEC.
You are right, it should have been
if ((vma->vm_flags & (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)) != (VM_READ|VM_EXEC)) goto put_out;
Your comment applied for read_opcode function too. Will correct in the next version of the patchset.
However in the next patch, where we replace the above with valid_vma and that does the right thing.
Quoted 4 lines
I'm also curious to why we can't modify text code that is also mapped as read/write.
If text code is mapped read/write then on memory pressure the page gets written to the disk. Hence breakpoints inserted may end up being in the disk copy modifying the actual copy.
Signature · 9 lines
Thanks and Regards Srikar -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 1/20] 1: mm: Move replace_page() to mm/memory.c
In reply to Steven RostedtQuoted 10 lines
Quoted 5 lines
As discussed in IRC, moving and removing the static attribute had to be one patch so that
mm/ksm.ccompiles correctly. The other option we have is to remove the static attribute first and then moving the function.Hmm, maybe that may be a good idea. Since it is really two changes. One is to make it global for other usages. I'm not even sure why you moved it. The change log for the move can explain that.
unlike mm/memory.c; mm/ksm.c is compiled only when CONFIG_KSM is set. So if we dont move it out of ksm.c; we will have to make uprobes dependent on CONFIG_KSM. Since replace_page is the only function we are interested in, its better to move it out of ksm.c, rather than making uprobes dependent on CONFIG_KSM.
Quoted 4 lines
-- Steve
Quoted 1 line
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 3/20] 3: uprobes: Breakground page replacement.
In reply to Stephen WilsonQuoted 33 lines · Stephen Wilson
Quoted 32 lines · Srikar Dronamraju
kernel/uprobes.c new file +32
-0+/** +* read_opcode - read the opcode at a given virtual address. +* @tsk: the probed task. +* @vaddr: the virtual address to store the opcode. +* @opcode: location to store the read opcode. +* +* For task @tsk, read the opcode at @vaddr and store it in @opcode. +* Return 0 (success) or a negative errno. +*/ +int __weak read_opcode (struct task_struct *tsk,unsigned long vaddr, +uprobe_opcode_t *opcode) +{ +struct vm_area_struct *vma; +struct page *page; +void *vaddr_new; +int ret; + + ret =get_user_pages (tsk, tsk->mm, vaddr,1 ,0 ,0 , &page, &vma); +if (ret <=0 ) +return -EFAULT ; + ret = -EFAULT ; + +/* +* check if the page we are interested is read-only mapped +* Since we are interested in text pages, Our pages of interest +* should be mapped read-only. +*/ +if ((vma->vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) == + (VM_READ |VM_EXEC )) + goto put_out; + +lock_page (page);
Quoted 8 lines
kernel/uprobes.c line 153
Quoted 6 lines
kernel/uprobes.c new file +6
-0+ vaddr_new =kmap_atomic (page,KM_USER0 ); + vaddr &= ~PAGE_MASK ; +memcpy (&opcode, vaddr_new + vaddr, uprobe_opcode_sz); +kunmap_atomic (vaddr_new,KM_USER0 ); +unlock_page (page); + ret = uprobe_opcode_sz;This looks wrong. We should be setting ret = 0 on success here?
Right, I should have set ret = 0 here.
Quoted 10 lines
Quoted 6 lines
kernel/uprobes.c new file +5
-0+ +put_out: +put_page (page);/* we did a get_page in the beginning */ +return ret; +}Signature · 1 line
steve
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 5/20] 5: Uprobes: register/unregister probes.
In reply to Steven RostedtQuoted 10 lines · Steven Rostedt
Quoted 9 lines · Srikar Dronamraju
kernel/uprobes.c +9
-0+/* Returns 0 if it can install one probe */ +int register_uprobe (struct inode *inode,loff_t offset, +struct uprobe_consumer *consumer) +{ +struct prio_tree_iter iter; +struct list_head tmp_list; +struct address_space *mapping; +struct mm_struct *mm, *tmpmm; +struct vm_area_struct *vma;
Quoted 9 lines
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 473
Quoted 6 lines
kernel/uprobes.c +6
-0+struct uprobe *uprobe; +int ret =-1 ; + +if (!inode || !consumer || consumer->next) +return -EINVAL ; + uprobe =uprobes_add (inode, offset);What happens if
uprobes_add()returns NULL?
Right again, I should have added a check to see if uprobes_add hasnt returned NULL.
Signature · 2 lines
Thanks and Regards Srikar
Re: [PATCH v2 2.6.38-rc8-tip 7/20] 7: uprobes: store/restore original instruction.
In reply to Srikar Dronamrajukernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 506
Quoted 12 lines · Srikar Dronamraju
static int
install_uprobe(struct mm_struct *mm, struct uprobe *uprobe){kernel/uprobes.c +6
-3-int ret =0 ; +struct task_struct *tsk; +int ret = -EINVAL ; -/*TODO: install breakpoint */ -if (!ret) +get_task_struct (mm->owner); + tsk = mm->owner; +if (!tsk) +return ret;
I think you need to check that tsk != NULL before calling get_task_struct()...
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 547
Quoted 10 lines
static int
remove_uprobe(struct mm_struct *mm, struct uprobe *uprobe){kernel/uprobes.c +7
-1-int ret =0 ; +struct task_struct *tsk; +int ret; + +get_task_struct (mm->owner); + tsk = mm->owner; +if (!tsk) +return -EINVAL ;
And here as well.
Signature · 8 lines
steve -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerRe: [PATCH v2 2.6.38-rc8-tip 3/20] 3: uprobes: Breakground page replacement.
In reply to Srikar DronamrajuQuoted 10 lines · Srikar Dronamraju
Quoted 4 lines
I'm also curious to why we can't modify text code that is also mapped as read/write.
If text code is mapped read/write then on memory pressure the page gets written to the disk. Hence breakpoints inserted may end up being in the disk copy modifying the actual copy.
OK, could you put a comment about that too.
Thanks,
-- Steve
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerRe: [PATCH v2 2.6.38-rc8-tip 3/20] 3: uprobes: Breakground page replacement.
In reply to Srikar DronamrajuQuoted 11 lines · Srikar Dronamraju
Quoted 4 lines
I'm confused by the above comment and code. You state we are only interested text pages mapped read-only, but then if the page is mapped read/exec we exit out? It is fine if it is anything but READ/EXEC.
You are right, it should have been
if ((vma->vm_flags & (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)) != (VM_READ|VM_EXEC)) goto put_out;
Golden rule #12: When the comments do not match the code, they probably are both wrong ;)
-- Steve
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 25 lines · On Mon, 14 Mar 2011 19:04:03 +0530 Srikar Dronamraju…
Advantages of uprobes over conventional debugging include:
1. Non-disruptive.
Unlike current ptrace based mechanisms, uprobes tracing wouldnt involve signals, stopping threads and context switching between the tracer and tracee.2. Much better handling of multithreaded programs because of XOL. Current ptrace based mechanisms use single stepping inline, i.e they copy back the original instruction on hitting a breakpoint. In such mechanisms tracers have to stop all the threads on a breakpoint hit or tracers will not be able to handle all hits to the location of interest. Uprobes uses execution out of line, where the instruction to be traced is analysed at the time of breakpoint insertion and a copy of instruction is stored at a different location. On breakpoint hit, uprobes jumps to that copied location and singlesteps the same instruction and does the necessary fixups post singlestepping.
3. Multiple tracers for an application.
Multiple uprobes based tracer could work in unison to trace an application. There could one tracer that could be interested in generic events for a particular set of process. While there could be another tracer that is just interested in one specific event of a particular process thats part of the previous set of process.
Quoted 5 lines
4. Corelating events from kernels and userspace.
Uprobes could be used with other tools like kprobes, tracepoints or as part of higher level tools like perf to give a consolidated set of events from kernel and userspace. In future we could look at a single backtrace showing application, library and kernel calls.
How do you envisage these features actually get used? For example, will gdb be modified? Will other debuggers be modified or written?
IOW, I'm trying to get an understanding of how you expect this feature will actually become useful to end users - the kernel patch is only part of the story.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 3 lines
IOW, I'm trying to get an understanding of how you expect this feature will actually become useful to end users - the kernel patch is only part of the story.
One user would be systemtap for user tracing as I understand. Systemtap has a userbase (at least I use it, although not for user tracing)
Right now lots of distros apply ugly patchkits to handle this instead, which is not good (tm).
-Andi
Signature · 8 lines
[email protected] -- Speaking for myself only. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 6 lines · Andi Kleen
Quoted 3 lines
IOW, I'm trying to get an understanding of how you expect this feature will actually become useful to end users - the kernel patch is only part of the story.
One user would be systemtap for user tracing as I understand. Systemtap has a userbase (at least I use it, although not for user tracing)
That's a brilliant reason to drop it right away. systemtap is the least of our worries.
Quoted 2 lines
Right now lots of distros apply ugly patchkits to handle this instead, which is not good (tm).
s/lots of distros/some enterprise distros where the management still believes that this is a valuable feature add/
You deliberately skipped the first part of akpms question:
Quoted 2 lines
How do you envisage these features actually get used? For example, will gdb be modified? Will other debuggers be modified or written?
How about answering this question first _BEFORE_ advertising systemtap?
Thanks,
tglx
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 1 line · akpm
[...] How do you envisage these features actually get used?
Patch #20/20 in the set includes an ftrace-flavoured debugfs frontend. Previous versions of the patchset included perf front-ends too, which are probably to be seen again.
Quoted 2 lines
For example, will gdb be modified? Will other debuggers be modified or written? [...]
The code is not currently useful to gdb. Perhaps ptrace or an improved userspace ABI can get access to it in the form of a breakpoint-management interface, though this inode+offset style of uprobe addressing would require adaptation to the process-virtual-address style used by debugging APIs.
- FChE
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · Frank Ch. Eigler
Quoted 1 line · akpm
[...] How do you envisage these features actually get used?
Patch #20/20 in the set includes an ftrace-flavoured debugfs frontend.
And you really think that:
# cd /sys/kernel/debug/tracing/
# cat /proc/`pgrep zsh`/maps | grep /bin/zsh | grep r-xp 00400000-0048a000 r-xp 00000000 08:03 130904 /bin/zsh
# objdump -T /bin/zsh | grep -w zfree 0000000000446420 g DF .text 0000000000000012 Base zfree
# echo 'p /bin/zsh:0x46420 %ip %ax' > uprobe_events
# cat uprobe_events p:uprobes/p_zsh_0x46420 /bin/zsh:0x0000000000046420
Quoted 1 line
TODO:
Documentation/trace/uprobetrace.txt
without a reasonable documentation how to use that is a brilliant argument?
Quoted 2 lines
Previous versions of the patchset included perf front-ends too, which are probably to be seen again.
Ahh, probably. What does that mean?
And if that probably happens, what interface is that supposed to use?
The above magic wrapped into perf ?
Or some sensible implementation ?
Thanks,
tglx
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines
Quoted 6 lines
4. Corelating events from kernels and userspace.
Uprobes could be used with other tools like kprobes, tracepoints or as part of higher level tools like perf to give a consolidated set of events from kernel and userspace. In future we could look at a single backtrace showing application, library and kernel calls.
Quoted 7 lines
How do you envisage these features actually get used? For example, will gdb be modified? Will other debuggers be modified or written?
IOW, I'm trying to get an understanding of how you expect this feature will actually become useful to end users - the kernel patch is only part of the story.
Right, So I am looking at having perf probe for uprobes and also at having a syscall so that perf probe and other ptrace users can use this infrastructure. Ingo has already asked for a syscall for the same in one of his replies to my previous patchset. From whatever discussions I had with ptrace users, they have shown interest in using this breakpoint infrastructure.
I am still not sure if this feature should be exposed thro a new operation to ptrace syscall (something like SET_BP) or a completely new syscall or both. I would be happy if people here could give inputs on which route to go forward.
We had perf probe for uprobes implemented in few of the previous patchset. When the underlying implementation changed from a pid:vaddr to a file:offset, the way we invoke perf probe changed.
Previously we would do
"perf probe -p 3692 zfree@zsh"
Now we would be doing
"perf probe -u zfree@zsh"
The perf probe for uprobes is still WIP. Will post the patches when it is in usable fashion. This should be pretty soon.
If you have suggestions on how this infrastructure could be used above perf probe and syscall, then please do let me know.
Signature · 9 lines
Thanks and Regards Srikar -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerQuoted 7 lines · Andrew Morton
How do you envisage these features actually get used? For example, will gdb be modified? Will other debuggers be modified or written?
IOW, I'm trying to get an understanding of how you expect this feature will actually become useful to end users - the kernel patch is only part of the story.
I'm hoping it solves this question:
https://lkml.org/lkml/2011/3/10/347
-- Steve
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi Thomas,
Quoted 17 lines
Quoted 4 lines
Quoted 2 lines
[...] How do you envisage these features actually get used?
Patch #20/20 in the set includes an ftrace-flavoured debugfs frontend.
And you really think that:
# cd /sys/kernel/debug/tracing/# cat /proc/`pgrep zsh`/maps | grep /bin/zsh | grep r-xp 00400000-0048a000 r-xp 00000000 08:03 130904 /bin/zsh# objdump -T /bin/zsh | grep -w zfree 0000000000446420 g DF .text 0000000000000012 Base zfree# echo 'p /bin/zsh:0x46420 %ip %ax' > uprobe_events
Quoted 7 lines
# cat uprobe_events p:uprobes/p_zsh_0x46420 /bin/zsh:0x0000000000046420Quoted 1 line
TODO:
Documentation/trace/uprobetrace.txtwithout a reasonable documentation how to use that is a brilliant argument?
We had a fairly decent documentation for uprobes and uprobetracer. But that had to be changed with the change in underlying design of uprobes infrastructure. Since uprobetrace is one the user interface, I plan to document it soon. However it would be great if we had inputs on how we should be designing the syscall.
Quoted 10 lines
Quoted 3 lines
Previous versions of the patchset included perf front-ends too, which are probably to be seen again.
Ahh, probably. What does that mean?
And if that probably happens, what interface is that supposed to use?
The above magic wrapped into perf ?
For the initial perf probe thing, yes it would be a wrapper over uprobe_tracer. That is because we can reuse most of the current perf probe and we could prototype and show users what all can be achieved. However we plan to make perf probe depend on the syscall when the syscall takes shape.
Quoted 2 lines
Or some sensible implementation ?
Would syscall based perf probe implementation count as a sensible implementation? My current plan was to code up the perf probe for uprobes and then draft a proposal for how the syscall should look. There are still some areas on how we should be allowing the filter, and what restrictions we should place on the syscall defined handler. I would like to hear from you and others on your ideas for the same. If you have ideas on doing it other than using a syscall then please do let me know about the same.
I know that getting the user interface right is very important. However I think it kind of depends on what the infrastructure can provide too. So if we can decide on the kernel ABI and the underlying design (i.e can we use replace_page() based background page replacement, Are there issues with the Xol slot based mechanism that we are using, etc), we can work towards providing a stable User ABI that even normal users can use. For now I am concentrating on getting the underlying infrastructure correct.
Please let me know your thoughts.
Signature · 9 lines
Thanks and Regards Srikar -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 7/20] 7: uprobes: store/restore original instruction.
In reply to Stephen WilsonQuoted 7 lines · Stephen Wilson
Quoted 6 lines · Srikar Dronamraju
static int
install_uprobe(struct mm_struct *mm, struct uprobe *uprobe){kernel/uprobes.c +2
-1-int ret =0 ; +struct task_struct *tsk; +int ret = -EINVAL ;
Quoted 10 lines
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 506
Quoted 6 lines
kernel/uprobes.c +4
-2-/*TODO: install breakpoint */ -if (!ret) +get_task_struct (mm->owner); + tsk = mm->owner; +if (!tsk) +return ret;I think you need to check that tsk != NULL before calling
get_task_struct()...
Guess checking for tsk != NULL would only help if and only if we are doing within rcu. i.e we have to change to something like this
rcu_read_lock()
if (mm->owner) {
get_task_struct(mm->owner)
tsk = mm->owner;
}
rcu_read_unlock()
if (!tsk)
return ret;Agree?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · Srikar Dronamraju
Quoted 4 lines
Quoted 1 line
TODO:
Documentation/trace/uprobetrace.txtwithout a reasonable documentation how to use that is a brilliant argument?
We had a fairly decent documentation for uprobes and uprobetracer. But that had to be changed with the change in underlying design of uprobes infrastructure. Since uprobetrace is one the user interface, I plan to document it soon. However it would be great if we had inputs on how we should be designing the syscall.
Ok.
Quoted 4 lines
Quoted 1 line
Or some sensible implementation ?
Would syscall based perf probe implementation count as a sensible implementation? My current plan was to code up the perf probe for
Yes.
Quoted 6 lines
uprobes and then draft a proposal for how the syscall should look. There are still some areas on how we should be allowing the filter, and what restrictions we should place on the syscall defined handler. I would like to hear from you and others on your ideas for the same. If you have ideas on doing it other than using a syscall then please do let me know about the same.
I don't think that anything else than a proper syscall interface is going to work out.
Quoted 8 lines
I know that getting the user interface right is very important. However I think it kind of depends on what the infrastructure can provide too. So if we can decide on the kernel ABI and the underlying design (i.e can we use
replace_page()based background page replacement, Are there issues with the Xol slot based mechanism that we are using, etc), we can work towards providing a stable User ABI that even normal users can use. For now I am concentrating on getting the underlying infrastructure correct.
Fair enough. I'll go through the existing patchset and comment there.
Thanks,
tglx
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines
Quoted 7 lines
uprobes and then draft a proposal for how the syscall should look. There are still some areas on how we should be allowing the filter, and what restrictions we should place on the syscall defined handler. I would like to hear from you and others on your ideas for the same. If you have ideas on doing it other than using a syscall then please do let me know about the same.
I don't think that anything else than a proper syscall interface is going to work out.
Okay,
Quoted 10 lines
Quoted 9 lines
I know that getting the user interface right is very important. However I think it kind of depends on what the infrastructure can provide too. So if we can decide on the kernel ABI and the underlying design (i.e can we use
replace_page()based background page replacement, Are there issues with the Xol slot based mechanism that we are using, etc), we can work towards providing a stable User ABI that even normal users can use. For now I am concentrating on getting the underlying infrastructure correct.
Quoted 2 lines
Fair enough. I'll go through the existing patchset and comment there.
Thanks for taking a look at the code. Look forward for your comments.
Signature · 9 lines
Thanks and Regards Srikar -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 3/20] 3: uprobes: Breakground page replacement.
In reply to Srikar DronamrajuQuoted 3 lines · Srikar Dronamraju
+/*
+ * Called withtsk->mm->mmap_semheld (either for read or write and
+ * with a reference totsk->mm
Hmm, why is holding it for read sufficient?
.
kernel/uprobes.c line 53
Quoted 11 lines
+ */
kernel/uprobes.c new file +10
-0+static int write_opcode (struct task_struct *tsk,struct uprobe * uprobe, +unsigned long vaddr,uprobe_opcode_t opcode) +{ +struct page *old_page, *new_page; +void *vaddr_old, *vaddr_new; +struct vm_area_struct *vma; +spinlock_t *ptl; +pte_t *orig_pte; +unsigned long addr; +int ret = -EINVAL ;
That initialization is pointless.
Quoted 4 lines
kernel/uprobes.c new file +4
-0+/* Read the page with vaddr into memory */ + ret =get_user_pages (tsk, tsk->mm, vaddr,1 ,1 ,1 , &old_page, &vma); +if (ret <=0 ) +return -EINVAL ;
kernel/uprobes.c line 68
Quoted 10 lines
kernel/uprobes.c new file +10
-0+ ret = -EINVAL ; + +/* +* check if the page we are interested is read-only mapped +* Since we are interested in text pages, Our pages of interest +* should be mapped read-only. +*/ +if ((vma->vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) == + (VM_READ |VM_EXEC )) + goto put_out;
IIRC then text pages are (VM_READ|VM_EXEC)
Quoted 8 lines
kernel/uprobes.c new file +8
-0+/* Allocate a page */ + new_page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vaddr); +if (!new_page) { + ret = -ENOMEM ; + goto put_out; + } + +/*
kernel/uprobes.c line 87
Quoted 10 lines
kernel/uprobes.c new file +10
-0+* lock page will serialize against do_wp_page()'s +* PageAnon() handling +*/ +lock_page (old_page); +/* copy the page now that we've got it stable */ + vaddr_old =kmap_atomic (old_page,KM_USER0 ); + vaddr_new =kmap_atomic (new_page,KM_USER1 ); + +memcpy (vaddr_new, vaddr_old,PAGE_SIZE ); +/* poke the new insn in, ASSUMES we don't cross page boundary */
And what makes sure that we don't ?
Quoted 4 lines
kernel/uprobes.c new file +4
-0+ addr = vaddr; + vaddr &= ~PAGE_MASK ; +memcpy (vaddr_new + vaddr, &opcode, uprobe_opcode_sz); +
kernel/uprobes.c line 101
Quoted 10 lines
kernel/uprobes.c new file +10
-0+kunmap_atomic (vaddr_new,KM_USER1 ); +kunmap_atomic (vaddr_old,KM_USER0 ); + + orig_pte =page_check_address (old_page, tsk->mm, addr, &ptl,0 ); +if (!orig_pte) + goto unlock_out; +pte_unmap_unlock (orig_pte, ptl); + +lock_page (new_page); +if (!anon_vma_prepare (vma))
Why don't you get the error code of anon_vma_prepare()?
kernel/uprobes.c line 102
Quoted 1 line
kernel/uprobes.c new file +1
-0+/* flip pages, do_wp_page() will fail pte_same() and bail */
-ENOPARSE
Quoted 11 lines
kernel/uprobes.c new file +11
-0+ ret =replace_page (vma, old_page, new_page, *orig_pte); + +unlock_page (new_page); +if (ret !=0 ) +page_cache_release (new_page); +unlock_out: +unlock_page (old_page); + +put_out: +put_page (old_page);/* we did a get_page in the beginning */ +return ret;
kernel/uprobes.c line 123
Quoted 10 lines
kernel/uprobes.c new file +10
-0+} + +/** +* read_opcode - read the opcode at a given virtual address. +* @tsk: the probed task. +* @vaddr: the virtual address to store the opcode. +* @opcode: location to store the read opcode. +* +* For task @tsk, read the opcode at @vaddr and store it in @opcode. +* Return 0 (success) or a negative errno.
Wants to called with mmap_sem held as well, right ?
Quoted 12 lines
+ */
kernel/uprobes.c new file +11
-0+int __weak read_opcode (struct task_struct *tsk,unsigned long vaddr, +uprobe_opcode_t *opcode) +{ +struct vm_area_struct *vma; +struct page *page; +void *vaddr_new; +int ret; + + ret =get_user_pages (tsk, tsk->mm, vaddr,1 ,0 ,0 , &page, &vma); +if (ret <=0 ) +return -EFAULT ;
kernel/uprobes.c line 145
Quoted 10 lines
kernel/uprobes.c new file +10
-0+ ret = -EFAULT ; + +/* +* check if the page we are interested is read-only mapped +* Since we are interested in text pages, Our pages of interest +* should be mapped read-only. +*/ +if ((vma->vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) == + (VM_READ |VM_EXEC )) + goto put_out;
Same as above
kernel/uprobes.c line 153
Quoted 7 lines
kernel/uprobes.c new file +7
-0+lock_page (page); + vaddr_new =kmap_atomic (page,KM_USER0 ); + vaddr &= ~PAGE_MASK ; +memcpy (&opcode, vaddr_new + vaddr, uprobe_opcode_sz); +kunmap_atomic (vaddr_new,KM_USER0 ); +unlock_page (page); + ret = uprobe_opcode_sz;
ret = 0 ?? At least, that's what the comment above says.
kernel/uprobes.c line 159
Quoted 6 lines
kernel/uprobes.c new file +6
-0+ +put_out: +put_page (page);/* we did a get_page in the beginning */ +return ret; +} +
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 4/20] 4: uprobes: Adding and remove a uprobe in a rb tree.
In reply to Srikar DronamrajuQuoted 2 lines · Srikar Dronamraju
+static int
valid_vma(struct vm_area_struct *vma)
bool perpaps ?
kernel/uprobes.c line 52
Quoted 6 lines
kernel/uprobes.c +6
-0+{ +if (!vma->vm_file) +return 0 ; + +if ((vma->vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) == + (VM_READ |VM_EXEC ))
Looks more correct than the code it replaces :)
kernel/uprobes.c
Quoted 9 lines
kernel/uprobes.c +8
-0+return 1 ; + +return 0 ; +} + +static struct rb_root uprobes_tree =RB_ROOT ; +static DEFINE_MUTEX (uprobes_mutex); +static DEFINE_SPINLOCK (treelock);
Why do you need a mutex and a spinlock ? Also the mutex is not referenced.
Quoted 53 lines
kernel/uprobes.c +53
-0+static int match_inode (struct uprobe *uprobe,struct inode *inode, +struct rb_node **p) +{ +struct rb_node *n = *p; + +if (inode < uprobe->inode) + *p = n->rb_left; +else if (inode > uprobe->inode) + *p = n->rb_right; +else +return 1 ; +return 0 ; +} + +static int match_offset (struct uprobe *uprobe,loff_t offset, +struct rb_node **p) +{ +struct rb_node *n = *p; + +if (offset < uprobe->offset) + *p = n->rb_left; +else if (offset > uprobe->offset) + *p = n->rb_right; +else +return 1 ; +return 0 ; +} + + +/* Called with treelock held */ +static struct uprobe *__find_uprobe (struct inode * inode, +loff_t offset,struct rb_node **near_match) +{ +struct rb_node *n = uprobes_tree.rb_node; +struct uprobe *uprobe, *u =NULL ; + +while (n) { + uprobe = rb_entry(n, struct uprobe, rb_node); +if (match_inode (uprobe, inode, &n)) { +if (near_match) + *near_match = n; +if (match_offset (uprobe, offset, &n)) { +atomic_inc (&uprobe->ref); + u = uprobe; +break ; + } + } + } +return u; +} + +/* +* Find a uprobe corresponding to a given inode:offset
kernel/uprobes.c bool __weak is_bkpt_insn(u8 *insn) · line 314
Quoted 10 lines
kernel/uprobes.c +10
-0+* Acquires treelock +*/ +static struct uprobe *find_uprobe (struct inode * inode,loff_t offset) +{ +struct uprobe *uprobe; +unsigned long flags; + +spin_lock_irqsave (&treelock, flags); + uprobe =__find_uprobe (inode, offset,NULL ); +spin_unlock_irqrestore (&treelock, flags);
What's the calling context ? Do we really need a spinlock here for walking the rb tree ?
Review
Quoted 2 lines
(quoted diff) +2
-0+ +/* Should be called lock-less */
-ENOPARSE
Quoted 7 lines
kernel/uprobes.c +7
-0+static void put_uprobe (struct uprobe *uprobe) +{ +if (atomic_dec_and_test (&uprobe->ref)) +kfree (uprobe); +} + +static struct uprobe *uprobes_add (struct inode *inode,loff_t offset)
kernel/uprobes.c bool __weak is_bkpt_insn(u8 *insn) · line 377
Quoted 10 lines
kernel/uprobes.c +10
-0+{ +struct uprobe *uprobe, *cur_uprobe; + +__iget (inode); + uprobe =kzalloc (sizeof (struct uprobe ),GFP_KERNEL ); + +if (!uprobe) { +iput (inode); +return NULL ; + }
Please move the __iget() after the kzalloc()
kernel/uprobes.c bool __weak is_bkpt_insn(u8 *insn) · line 390
Quoted 13 lines
kernel/uprobes.c +13
-0+ uprobe->inode = inode; + uprobe->offset = offset; + +/* add to uprobes_tree, sorted on inode:offset */ + cur_uprobe =insert_uprobe (uprobe); + +/* a uprobe exists for this inode:offset combination*/ +if (cur_uprobe) { +kfree (uprobe); + uprobe = cur_uprobe; +iput (inode); + }else +init_rwsem (&uprobe->consumer_rwsem);
Please init stuff _before_ inserting not afterwards.
Quoted 19 lines
kernel/uprobes.c +19
-0+ +return uprobe; +} + +/* Acquires uprobe->consumer_rwsem */ +static void handler_chain (struct uprobe *uprobe,struct pt_regs *regs) +{ +struct uprobe_consumer *consumer; + +down_read (&uprobe->consumer_rwsem); + consumer = uprobe->consumers; +while (consumer) { +if (!consumer->filter || consumer->filter (consumer, current)) + consumer->handler (consumer, regs); + + consumer = consumer->next; + } +up_read (&uprobe->consumer_rwsem); +}
kernel/uprobes.c bool __weak is_bkpt_insn(u8 *insn) · line 419
Quoted 10 lines
kernel/uprobes.c +10
-0+ +/* Acquires uprobe->consumer_rwsem */ +static void add_consumer (struct uprobe *uprobe, +struct uprobe_consumer *consumer) +{ +down_write (&uprobe->consumer_rwsem); + consumer->next = uprobe->consumers; + uprobe->consumers = consumer; +up_write (&uprobe->consumer_rwsem); +return ;
pointless return
kernel/uprobes.c bool __weak is_bkpt_insn(u8 *insn) · line 395
Quoted 3 lines
kernel/uprobes.c +3
-0+} + +/* Acquires uprobe->consumer_rwsem */
I'd prefer a comment about the return code over this redundant information.
kernel/uprobes.c bool __weak is_bkpt_insn(u8 *insn) · line 425
Quoted 3 lines
kernel/uprobes.c +3
-0+static int del_consumer (struct uprobe *uprobe, +struct uprobe_consumer *consumer) +{
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerRe: [PATCH v2 2.6.38-rc8-tip 4/20] 4: uprobes: Adding and remove a uprobe in a rb tree.
Quoted 9 lines · Thomas Gleixner
kernel/uprobes.c line 52
Quoted 6 lines
kernel/uprobes.c +6
-0+{ +if (!vma->vm_file) +return 0 ; + +if ((vma->vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) == + (VM_READ |VM_EXEC ))Looks more correct than the code it replaces :)
Quoted 6 lines
kernel/uprobes.c line 57
Quoted 5 lines
kernel/uprobes.c +5
-0+return 1 ; + +return 0 ; +} +
Yeah, we had this discussion already ;)
-- Steve
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerRe: [PATCH v2 2.6.38-rc8-tip 7/20] 7: uprobes: store/restore original instruction.
In reply to Srikar DronamrajuQuoted 2 lines · Srikar Dronamraju
* Stephen Wilson <[email protected]> [2011-03-14 14:09:14]:
Nitpick:
Quoted 3 lines
Guess checking for tsk != NULL would only help if and only if we are doing within rcu. i.e we have to change to something like this
tsk = NULL;
Quoted 10 lines
rcu_read_lock() if (mm->owner) { get_task_struct(mm->owner) tsk = mm->owner; } rcu_read_unlock() if (!tsk) return ret;Agree?
Or:
rcu_read_lock(); tsk = mm->owner; if (tsk) get_task_struct(tsk); rcu_read_unlock(); if (!tsk) return ret;
Probably looks cleaner.
-- Steve
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 5/20] 5: Uprobes: register/unregister probes.
In reply to Srikar DronamrajuQuoted 5 lines · Srikar Dronamraju
kernel/uprobes.c +5
-0+/* Returns 0 if it can install one probe */ +int register_uprobe (struct inode *inode,loff_t offset, +struct uprobe_consumer *consumer) +{ +struct prio_tree_iter iter;
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 473
Quoted 10 lines
kernel/uprobes.c +10
-0+struct list_head tmp_list; +struct address_space *mapping; +struct mm_struct *mm, *tmpmm; +struct vm_area_struct *vma; +struct uprobe *uprobe; +int ret =-1 ; + +if (!inode || !consumer || consumer->next) +return -EINVAL ; + uprobe =uprobes_add (inode, offset);
Does uprobes_add() always succeed ?
Quoted 35 lines
kernel/uprobes.c +35
-0+INIT_LIST_HEAD (&tmp_list); + mapping = inode->i_mapping; + +mutex_lock (&uprobes_mutex); +if (uprobe->consumers) { + ret =0 ; + goto consumers_add; + } + +spin_lock (&mapping->i_mmap_lock); + vma_prio_tree_foreach(vma, &iter, &mapping->i_mmap, 0, 0) { +loff_t vaddr; + +if (!atomic_inc_not_zero (&vma->vm_mm->mm_users)) +continue ; + + mm = vma->vm_mm; +if (!valid_vma (vma)) { +mmput (mm); +continue ; + } + + vaddr = vma->vm_start + offset; + vaddr -= vma->vm_pgoff <<PAGE_SHIFT ; +if (vaddr >ULONG_MAX ) { +/* +* We cannot have a virtual address that is +* greater than ULONG_MAX +*/ +mmput (mm); +continue ; + } + mm->uprobes_vaddr = (unsigned long ) vaddr; +list_add (&mm->uprobes_list, &tmp_list); + }
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 519
Quoted 10 lines
kernel/uprobes.c +10
-0+spin_unlock (&mapping->i_mmap_lock); + +if (list_empty (&tmp_list)) { + ret =0 ; + goto consumers_add; + } +list_for_each_entry_safe (mm, tmpmm, &tmp_list, uprobes_list) { +down_read (&mm->mmap_sem); +if (!install_uprobe (mm, uprobe)) + ret =0 ;
Installing it once is success ?
Review
Quoted 1 line
(quoted diff) +1
-0+ list_del(&mm->uprobes_list);
Also the locking rules for mm->uprobes_list want to be documented. They are completely non obvious.
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 528
Quoted 8 lines
kernel/uprobes.c +8
-0+up_read (&mm->mmap_sem); +mmput (mm); + } + +consumers_add: +add_consumer (uprobe, consumer); +mutex_unlock (&uprobes_mutex); +put_uprobe (uprobe);
Why do we drop the refcount here?
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 611
Quoted 9 lines
kernel/uprobes.c +8
-0+return ret; +} +/* +* There could be other threads that could be spinning on +* treelock; some of these threads could be interested in this +* uprobe. Give these threads a chance to run. +*/ +synchronize_sched ();
This makes no sense at all. We are not holding treelock, we are about to acquire it. Also what does it matter when they spin on treelock and are interested in this uprobe. Either they find it before we remove it or not. So why synchronize_sched()? I find the lifetime rules of uprobe utterly confusing. Could you explain please ?
Quoted 10 lines
kernel/uprobes.c +9
-1+spin_lock_irqsave (&treelock, flags); +rb_erase (&uprobe->rb_node, &uprobes_tree); +spin_unlock_irqrestore (&treelock, flags); +iput (uprobe->inode); + +put_unlock: +mutex_unlock (&uprobes_mutex); +put_uprobe (uprobe); +} --
Quoted 5 lines
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 6/20] 6: x86: analyze instruction and determine fixups.
In reply to Srikar DronamrajuQuoted 8 lines · Srikar Dronamraju
arch/x86/kernel/uprobes.c new file +8
-0+/* +* TODO: +* - Where necessary, examine the modrm byte and allow only valid instructions +* in the different Groups and fpu instructions. +*/ + +static bool is_prefix_bad (struct insn *insn) +{
arch/x86/kernel/uprobes.c line 185
Quoted 10 lines
arch/x86/kernel/uprobes.c new file +10
-0+int i; + +for (i =0 ; i < insn->prefixes.nbytes; i++) { +switch (insn->prefixes.bytes[i]) { +case 0x26 :/*INAT_PFX_ES */ +case 0x2E :/*INAT_PFX_CS */ +case 0x36 :/*INAT_PFX_DS */ +case 0x3E :/*INAT_PFX_SS */ +case 0xF0 :/*INAT_PFX_LOCK */ +return 1 ;
true
arch/x86/kernel/uprobes.c line 188
Quoted 3 lines
arch/x86/kernel/uprobes.c new file +3
-0+ } + } +return 0 ;
false
arch/x86/kernel/uprobes.c line 219
Quoted 11 lines
arch/x86/kernel/uprobes.c new file +10
-0+} +static int validate_insn_32bits (struct uprobe *uprobe,struct insn *insn) +{ +insn_init (insn, uprobe->insn, false); + +/* Skip good instruction prefixes; reject "bad" ones. */ +insn_get_opcode (insn); +if (is_prefix_bad (insn)) { +report_bad_prefix (); +return -EPERM ;
-ENOTSUPP perhaps. That's not a permission problem
Quoted 7 lines
arch/x86/kernel/uprobes.c new file +6
-0+ } +/** +* analyze_insn - instruction analysis including validity and fixups. +* @tsk: the probed task. +* @uprobe: the probepoint information. +* Return 0 on success or a -ve number on error.
arch/x86/kernel/uprobes.c line 398
Quoted 10 lines
arch/x86/kernel/uprobes.c new file +10
-0+*/ +int analyze_insn (struct task_struct *tsk,struct uprobe *uprobe) +{ +int ret; +struct insn insn; + + uprobe->fixups =0 ; +#ifdef CONFIG_X86_64 + uprobe->arch_info.rip_rela_target_address =0x0 ; +#endif
Please get rid of this #ifdef and use inlines (empty for 32bit)
arch/x86/kernel/uprobes.c line 406
Quoted 8 lines
arch/x86/kernel/uprobes.c new file +8
-0+ +if (is_32bit_app (tsk)) + ret =validate_insn_32bits (uprobe, &insn); +else + ret =validate_insn_64bits (uprobe, &insn); +if (ret !=0 ) +return ret; +#ifdef CONFIG_X86_64
Ditto
arch/x86/kernel/uprobes.c line 410
Quoted 4 lines
arch/x86/kernel/uprobes.c new file +4
-0+ ret =handle_riprel_insn (uprobe, &insn); +if (ret ==-1 ) +/* rip-relative; can't XOL */ +return 0 ;
So we return -1 from handle_riprel_insn() and return success? Btw how deals handle_riprel_insn() with 32bit user space ?
arch/x86/kernel/uprobes.c line 413
Quoted 3 lines
arch/x86/kernel/uprobes.c new file +3
-0+#endif +prepare_fixups (uprobe, &insn); +return 0 ;
Thanks,
tglx
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 7/20] 7: uprobes: store/restore original instruction.
In reply to Srikar Dronamrajukernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 503
Quoted 9 lines · Srikar Dronamraju
static int
install_uprobe(struct mm_struct *mm, struct uprobe *uprobe){kernel/uprobes.c +3
-3-int ret =0 ; +struct task_struct *tsk; +int ret = -EINVAL ; -/*TODO: install breakpoint */ -if (!ret) +get_task_struct (mm->owner);
Increment task ref before checking for NULL ?
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 507
Quoted 4 lines
kernel/uprobes.c +4
-0+ tsk = mm->owner; +if (!tsk) +return ret; +
Thanks,
tglx
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 7/20] 7: uprobes: store/restore original instruction.
In reply to Steven RostedtQuoted 21 lines · Steven Rostedt
Quoted 10 lines
rcu_read_lock() if (mm->owner) { get_task_struct(mm->owner) tsk = mm->owner; } rcu_read_unlock() if (!tsk) return ret;Agree?
Or:
rcu_read_lock(); tsk = mm->owner; if (tsk) get_task_struct(tsk); rcu_read_unlock(); if (!tsk) return ret;
Quoted 1 line
Probably looks cleaner.
Yes, plus we should do "tsk = rcu_dereference(mm->owner);" and wrap the whole thing in a static uprobes_get_mm_owner() or similar.
Signature · 1 line
steve
Steven Rostedt
maintainerRe: [PATCH v2 2.6.38-rc8-tip 7/20] 7: uprobes: store/restore original instruction.
Quoted 2 lines · Stephen Wilson
Yes, plus we should do "tsk =
rcu_dereference(mm->owner);" and wrap the whole thing in a staticuprobes_get_mm_owner()or similar.
Ack.
-- Steve
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 7/20] 7: uprobes: store/restore original instruction.
In reply to Stephen WilsonQuoted 9 lines
Quoted 9 lines
rcu_read_lock(); tsk = mm->owner; if (tsk) get_task_struct(tsk); rcu_read_unlock(); if (!tsk) return ret;
Quoted 5 lines
Quoted 1 line
Probably looks cleaner.
Yes, plus we should do "tsk =
rcu_dereference(mm->owner);" and wrap the whole thing in a staticuprobes_get_mm_owner()or similar.
Okay, will do that.
Signature · 9 lines
Thanks and Regards Srikar -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 7/20] 7: uprobes: store/restore original instruction.
In reply to Thomas GleixnerQuoted 7 lines · Thomas Gleixner
Quoted 6 lines · Srikar Dronamraju
static int
install_uprobe(struct mm_struct *mm, struct uprobe *uprobe){kernel/uprobes.c +2
-1-int ret =0 ; +struct task_struct *tsk; +int ret = -EINVAL ;
Quoted 5 lines
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 503
Quoted 3 lines
kernel/uprobes.c +1
-2-/*TODO: install breakpoint */ -if (!ret) +get_task_struct (mm->owner);Increment task ref before checking for NULL ?
In response to earlier comments/suggestions from Stephen Wilson, we resolved to handle it this way
static uprobes_get_mm_owner() {
struct task_struct *tsk;
rcu_read_lock()
tsk = rcu_dereference(mm->owner);
if (tsk)
get_task_struct(tsk);
rcu_read_unlock();
return tsk;
}Both install_uprobe and remove_uprobe will end up calling uprobes_get_mm_owner().
Signature · 9 lines
Thanks and Regards Srikar -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 5/20] 5: Uprobes: register/unregister probes.
In reply to Thomas GleixnerQuoted 10 lines · Thomas Gleixner
Quoted 9 lines · Srikar Dronamraju
kernel/uprobes.c +9
-0+/* Returns 0 if it can install one probe */ +int register_uprobe (struct inode *inode,loff_t offset, +struct uprobe_consumer *consumer) +{ +struct prio_tree_iter iter; +struct list_head tmp_list; +struct address_space *mapping; +struct mm_struct *mm, *tmpmm; +struct vm_area_struct *vma;
Quoted 9 lines
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 473
Quoted 6 lines
kernel/uprobes.c +6
-0+struct uprobe *uprobe; +int ret =-1 ; + +if (!inode || !consumer || consumer->next) +return -EINVAL ; + uprobe =uprobes_add (inode, offset);Does
uprobes_add()always succeed ?
Steve already gave this comment. Adding a check to catch if uprobe_add returns NULL and return immediately.
Quoted 39 lines
Quoted 39 lines
kernel/uprobes.c +39
-0+INIT_LIST_HEAD (&tmp_list); + mapping = inode->i_mapping; + +mutex_lock (&uprobes_mutex); +if (uprobe->consumers) { + ret =0 ; + goto consumers_add; + } + +spin_lock (&mapping->i_mmap_lock); + vma_prio_tree_foreach(vma, &iter, &mapping->i_mmap, 0, 0) { +loff_t vaddr; + +if (!atomic_inc_not_zero (&vma->vm_mm->mm_users)) +continue ; + + mm = vma->vm_mm; +if (!valid_vma (vma)) { +mmput (mm); +continue ; + } + + vaddr = vma->vm_start + offset; + vaddr -= vma->vm_pgoff <<PAGE_SHIFT ; +if (vaddr >ULONG_MAX ) { +/* +* We cannot have a virtual address that is +* greater than ULONG_MAX +*/ +mmput (mm); +continue ; + } + mm->uprobes_vaddr = (unsigned long ) vaddr; +list_add (&mm->uprobes_list, &tmp_list); + } +spin_unlock (&mapping->i_mmap_lock); + +if (list_empty (&tmp_list)) { + ret =0 ;
Quoted 8 lines
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 519
Quoted 6 lines
kernel/uprobes.c +6
-0+ goto consumers_add; + } +list_for_each_entry_safe (mm, tmpmm, &tmp_list, uprobes_list) { +down_read (&mm->mmap_sem); +if (!install_uprobe (mm, uprobe)) + ret =0 ;Installing it once is success ?
This is a little tricky. My intention was to return success even if one install is successful. If we return error, then the caller can go ahead and free the consumer. Since we return success if there are currently no processes that have mapped this inode, I was tempted to return success on atleast one successful install.
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +1
-0+ list_del(&mm->uprobes_list);Also the locking rules for
mm->uprobes_listwant to be documented. They are completely non obvious.
Quoted 10 lines
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 528
Quoted 8 lines
kernel/uprobes.c +8
-0+up_read (&mm->mmap_sem); +mmput (mm); + } + +consumers_add: +add_consumer (uprobe, consumer); +mutex_unlock (&uprobes_mutex); +put_uprobe (uprobe);Why do we drop the refcount here?
The first time uprobe_add gets called for a unique inode:offset pair, it sets the refcount to 2 (One for the uprobe creation and the other for register activity). From next time onwards it increments the refcount by (for register activity) 1. The refcount dropped here corresponds to the register activity.
Similarly unregister takes a refcount thro find_uprobe and drops it thro del_consumer(). However it drops the creation refcount if and if there are no more consumers.
I thought of just taking the refcount just for the first register and decrement for the last unregister. However register/unregister can race with each other causing the refcount to be zero and free the uprobe structure even though we were still registering the probe.
Quoted 4 lines
Quoted 3 lines
(quoted diff) +2
-0+ return ret; +}
Quoted 12 lines
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 611
Quoted 6 lines
kernel/uprobes.c +6
-0+/* +* There could be other threads that could be spinning on +* treelock; some of these threads could be interested in this +* uprobe. Give these threads a chance to run. +*/ +synchronize_sched ();This makes no sense at all. We are not holding treelock, we are about to acquire it. Also what does it matter when they spin on treelock and are interested in this uprobe. Either they find it before we remove it or not. So why
synchronize_sched()? I find the lifetime rules of uprobe utterly confusing. Could you explain please ?
There could be threads that have hit the breakpoint and are entering the notifier code(interrupt context) and then do_notify_resume(task context) and trying to acquire the treelock. (treelock is held by the breakpoint hit threads in uprobe_notify_resume which gets called in do_notify_resume()) The current thread that is removing the uprobe from the rb_tree can race with these threads and might acquire the treelock before some of the breakpoint hit threads. If this happens the interrupted threads have to re-read the opcode to see if the breakpoint location no more has the breakpoint instruction and retry the instruction. However before it can detect and retry, some other thread might insert a breakpoint at that location. This can go in a loop.
The other option would be for the interrupted threads to turn that into a signal. However I am not sure if this is a good option at all esp since we already have the breakpoint removed.
To avoid this, I am planning to give some __extra__ time for the breakpoint hit threads to compete and win the race for spinlock with the unregistering thread.
Signature · 2 lines
Thanks and Regards Srikar
Quoted 6 lines
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 616
Quoted 6 lines
kernel/uprobes.c +5
-0+spin_lock_irqsave (&treelock, flags); +rb_erase (&uprobe->rb_node, &uprobes_tree); +spin_unlock_irqrestore (&treelock, flags); +iput (uprobe->inode); +
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 4/20] 4: uprobes: Adding and remove a uprobe in a rb tree.
In reply to Thomas GleixnerQuoted 5 lines · Thomas Gleixner
Quoted 2 lines · Srikar Dronamraju
+static int
valid_vma(struct vm_area_struct *vma)bool perpaps ?
Okay,
Quoted 9 lines
kernel/uprobes.c line 52
Quoted 7 lines
kernel/uprobes.c +6
-0+{ +if (!vma->vm_file) +return 0 ; + +if ((vma->vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) == + (VM_READ |VM_EXEC ))Looks more correct than the code it replaces :)
Yes, Steven Rostedt has already pointed this out.
Quoted 7 lines
Quoted 6 lines
kernel/uprobes.c +5
-0+return 1 ; + +return 0 ; +} +
Quoted 6 lines
kernel/uprobes.c bool __weak is_bkpt_insn(u8 *insn) · line 250
Quoted 3 lines
kernel/uprobes.c +3
-0+static struct rb_root uprobes_tree =RB_ROOT ; +static DEFINE_MUTEX (uprobes_mutex); +static DEFINE_SPINLOCK (treelock);Why do you need a mutex and a spinlock ? Also the mutex is not referenced.
We can move the mutex to the next patch, (i.e register/unregister patch), where it gets used. mutex for now serializes register_uprobe/unregister_uprobe/mmap_uprobe.
This mutex is the one that guards mm->uprobes_list.
Quoted 17 lines
kernel/uprobes.c bool __weak is_bkpt_insn(u8 *insn) · line 314
Quoted 13 lines
kernel/uprobes.c +12
-0+/* +* Find a uprobe corresponding to a given inode:offset +* Acquires treelock +*/ +static struct uprobe *find_uprobe (struct inode * inode,loff_t offset) +{ +struct uprobe *uprobe; +unsigned long flags; + +spin_lock_irqsave (&treelock, flags); + uprobe =__find_uprobe (inode, offset,NULL ); +spin_unlock_irqrestore (&treelock, flags);What's the calling context ? Do we really need a spinlock here for walking the rb tree ?
find_uprobe() gets called from unregister_uprobe and on probe hit from uprobe_notify_resume. I am not sure if its a good idea to walk the tree as and when the tree is changing either because of a insertion or deletion of a probe.
Quoted 16 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ +/* Should be called lock-less */
-ENOPARSEQuoted 11 lines
kernel/uprobes.c +11
-0+static void put_uprobe (struct uprobe *uprobe) +{ +if (atomic_dec_and_test (&uprobe->ref)) +kfree (uprobe); +} + +static struct uprobe *uprobes_add (struct inode *inode,loff_t offset) +{ +struct uprobe *uprobe, *cur_uprobe; + +__iget (inode);
Quoted 8 lines
kernel/uprobes.c bool __weak is_bkpt_insn(u8 *insn) · line 377
Quoted 6 lines
kernel/uprobes.c +6
-0+ uprobe =kzalloc (sizeof (struct uprobe ),GFP_KERNEL ); + +if (!uprobe) { +iput (inode); +return NULL ; + }Please move the
__iget()after thekzalloc()
Okay.
Quoted 16 lines
Quoted 4 lines
kernel/uprobes.c +3
-0+ uprobe->inode = inode; + uprobe->offset = offset; +kernel/uprobes.c bool __weak is_bkpt_insn(u8 *insn) · line 390
Quoted 10 lines
kernel/uprobes.c +10
-0+/* add to uprobes_tree, sorted on inode:offset */ + cur_uprobe =insert_uprobe (uprobe); + +/* a uprobe exists for this inode:offset combination*/ +if (cur_uprobe) { +kfree (uprobe); + uprobe = cur_uprobe; +iput (inode); + }else +init_rwsem (&uprobe->consumer_rwsem);Please init stuff _before_ inserting not afterwards.
Okay.
Quoted 24 lines
Quoted 24 lines
kernel/uprobes.c +23
-0+ +return uprobe; +} + +/* Acquires uprobe->consumer_rwsem */ +static void handler_chain (struct uprobe *uprobe,struct pt_regs *regs) +{ +struct uprobe_consumer *consumer; + +down_read (&uprobe->consumer_rwsem); + consumer = uprobe->consumers; +while (consumer) { +if (!consumer->filter || consumer->filter (consumer, current)) + consumer->handler (consumer, regs); + + consumer = consumer->next; + } +up_read (&uprobe->consumer_rwsem); +} + +/* Acquires uprobe->consumer_rwsem */ +static void add_consumer (struct uprobe *uprobe, +struct uprobe_consumer *consumer)
Quoted 8 lines
kernel/uprobes.c bool __weak is_bkpt_insn(u8 *insn) · line 419
Quoted 6 lines
kernel/uprobes.c +6
-0+{ +down_write (&uprobe->consumer_rwsem); + consumer->next = uprobe->consumers; + uprobe->consumers = consumer; +up_write (&uprobe->consumer_rwsem); +return ;pointless return
Okay,
Quoted 8 lines
kernel/uprobes.c bool __weak is_bkpt_insn(u8 *insn) · line 395
Quoted 4 lines
kernel/uprobes.c +3
-0+} + +/* Acquires uprobe->consumer_rwsem */ I'd prefer a comment about the return code over this redundant information.
Okay,
Quoted 3 lines
kernel/uprobes.c bool __weak is_bkpt_insn(u8 *insn) · line 425
Quoted 3 lines
kernel/uprobes.c +3
-0+static int del_consumer (struct uprobe *uprobe, +struct uprobe_consumer *consumer) +{
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerRe: [PATCH v2 2.6.38-rc8-tip 5/20] 5: Uprobes: register/unregister probes.
In reply to Srikar DronamrajuQuoted 6 lines · Srikar Dronamraju
Quoted 6 lines
Quoted 5 lines
kernel/uprobes.c +5
-0+ } +list_for_each_entry_safe (mm, tmpmm, &tmp_list, uprobes_list) { +down_read (&mm->mmap_sem); +if (!install_uprobe (mm, uprobe)) + ret =0 ;
Quoted 7 lines
Quoted 1 line
Installing it once is success ?
This is a little tricky. My intention was to return success even if one install is successful. If we return error, then the caller can go ahead and free the consumer. Since we return success if there are currently no processes that have mapped this inode, I was tempted to return success on atleast one successful install.
What about an all or nothing approach. If one fails, remove all that were installed, and give up.
-- Steve
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Peter Zijlstra
maintainerRe: [PATCH v2 2.6.38-rc8-tip 5/20] 5: Uprobes: register/unregister probes.
Quoted 9 lines · Steven Rostedt
Quoted 8 lines · Srikar Dronamraju
Quoted 7 lines
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 519
Quoted 5 lines
kernel/uprobes.c +5
-0+ } +list_for_each_entry_safe (mm, tmpmm, &tmp_list, uprobes_list) { +down_read (&mm->mmap_sem); +if (!install_uprobe (mm, uprobe)) + ret =0 ;Installing it once is success ?
Quoted 8 lines
Quoted 5 lines
This is a little tricky. My intention was to return success even if one install is successful. If we return error, then the caller can go ahead and free the consumer. Since we return success if there are currently no processes that have mapped this inode, I was tempted to return success on atleast one successful install.
What about an all or nothing approach. If one fails, remove all that were installed, and give up.
That sounds like a much saner semantic and is what we generally do in the kernel.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 3/20] 3: uprobes: Breakground page replacement.
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
Quoted 3 lines · Srikar Dronamraju
+/*
+ * Called withtsk->mm->mmap_semheld (either for read or write and
+ * with a reference totsk->mmHmm, why is holding it for read sufficient?
We are not adding a new vma to the mm; but just replacing a page with another after holding the locks for the pages. Existing routines doing close to similar things like the access_process_vm/get_user_pages seem to be taking the read_lock. Do you see a resaon why readlock wouldnt suffice?
Quoted 14 lines
.
kernel/uprobes.c line 53
Quoted 11 lines
+ */
kernel/uprobes.c new file +10
-0+static int write_opcode (struct task_struct *tsk,struct uprobe * uprobe, +unsigned long vaddr,uprobe_opcode_t opcode) +{ +struct page *old_page, *new_page; +void *vaddr_old, *vaddr_new; +struct vm_area_struct *vma; +spinlock_t *ptl; +pte_t *orig_pte; +unsigned long addr; +int ret = -EINVAL ;That initialization is pointless.
Okay,
Quoted 17 lines
Quoted 5 lines
kernel/uprobes.c new file +4
-0+/* Read the page with vaddr into memory */ + ret =get_user_pages (tsk, tsk->mm, vaddr,1 ,1 ,1 , &old_page, &vma); +if (ret <=0 ) +return -EINVAL ;kernel/uprobes.c line 68
Quoted 10 lines
kernel/uprobes.c new file +10
-0+ ret = -EINVAL ; + +/* +* check if the page we are interested is read-only mapped +* Since we are interested in text pages, Our pages of interest +* should be mapped read-only. +*/ +if ((vma->vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) == + (VM_READ |VM_EXEC )) + goto put_out;IIRC then text pages are (VM_READ|VM_EXEC)
Steven Rostedt already pointed this out.
Quoted 13 lines
Quoted 13 lines
kernel/uprobes.c new file +12
-0+/* Allocate a page */ + new_page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vaddr); +if (!new_page) { + ret = -ENOMEM ; + goto put_out; + } + +/* +* lock page will serialize against do_wp_page()'s +* PageAnon() handling +*/ +lock_page (old_page);
Quoted 8 lines
kernel/uprobes.c line 87
Quoted 6 lines
kernel/uprobes.c new file +6
-0+/* copy the page now that we've got it stable */ + vaddr_old =kmap_atomic (old_page,KM_USER0 ); + vaddr_new =kmap_atomic (new_page,KM_USER1 ); + +memcpy (vaddr_new, vaddr_old,PAGE_SIZE ); +/* poke the new insn in, ASSUMES we don't cross page boundary */ And what makes sure that we don't ?
We are expecting the breakpoint instruction to be the minimum size instruction for that architecture. This wouldnt be a problem for architectures that have fixed length instructions.
For architectures which have variable size instructions, I am hoping that the opcode size will be small enuf that it will always not cross boundary. Something like 0xCC on x86. If and when we support architectures that have variable length instructions whose breakpoint instruction can span across page boundary, we have to add more meat to take care of the case.
Quoted 17 lines
Quoted 5 lines
kernel/uprobes.c new file +4
-0+ addr = vaddr; + vaddr &= ~PAGE_MASK ; +memcpy (vaddr_new + vaddr, &opcode, uprobe_opcode_sz); +kernel/uprobes.c line 101
Quoted 10 lines
kernel/uprobes.c new file +10
-0+kunmap_atomic (vaddr_new,KM_USER1 ); +kunmap_atomic (vaddr_old,KM_USER0 ); + + orig_pte =page_check_address (old_page, tsk->mm, addr, &ptl,0 ); +if (!orig_pte) + goto unlock_out; +pte_unmap_unlock (orig_pte, ptl); + +lock_page (new_page); +if (!anon_vma_prepare (vma))Why don't you get the error code of
anon_vma_prepare()?
Okay, will capture the error_code of anon_vma_prepare.
Quoted 20 lines
kernel/uprobes.c line 102
Quoted 2 lines
kernel/uprobes.c new file +1
-0+/* flip pages, do_wp_page() will fail pte_same() and bail */
-ENOPARSEQuoted 15 lines
kernel/uprobes.c new file +15
-0+ ret =replace_page (vma, old_page, new_page, *orig_pte); + +unlock_page (new_page); +if (ret !=0 ) +page_cache_release (new_page); +unlock_out: +unlock_page (old_page); + +put_out: +put_page (old_page);/* we did a get_page in the beginning */ +return ret; +} + +/** +* read_opcode - read the opcode at a given virtual address.
Quoted 8 lines
Quoted 6 lines
+ * @tsk: the probed task.
+ * @vaddr: the virtual address to store the opcode.
+ * @opcode: location to store the read opcode.
+ *
+ * For task @tsk, read the opcode at @vaddr and store it in @opcode.
+ * Return 0 (success) or a negative errno.Wants to called with
mmap_semheld as well, right ?
Yes, will document.
Quoted 26 lines
Quoted 13 lines
+ */
kernel/uprobes.c new file +11
-0+int __weak read_opcode (struct task_struct *tsk,unsigned long vaddr, +uprobe_opcode_t *opcode) +{ +struct vm_area_struct *vma; +struct page *page; +void *vaddr_new; +int ret; + + ret =get_user_pages (tsk, tsk->mm, vaddr,1 ,0 ,0 , &page, &vma); +if (ret <=0 ) +return -EFAULT ;kernel/uprobes.c line 145
Quoted 10 lines
kernel/uprobes.c new file +10
-0+ ret = -EFAULT ; + +/* +* check if the page we are interested is read-only mapped +* Since we are interested in text pages, Our pages of interest +* should be mapped read-only. +*/ +if ((vma->vm_flags & (VM_READ |VM_WRITE |VM_EXEC |VM_SHARED )) == + (VM_READ |VM_EXEC )) + goto put_out;Same as above
Quoted 9 lines
kernel/uprobes.c line 153
Quoted 7 lines
kernel/uprobes.c new file +7
-0+lock_page (page); + vaddr_new =kmap_atomic (page,KM_USER0 ); + vaddr &= ~PAGE_MASK ; +memcpy (&opcode, vaddr_new + vaddr, uprobe_opcode_sz); +kunmap_atomic (vaddr_new,KM_USER0 ); +unlock_page (page); + ret = uprobe_opcode_sz;ret = 0 ?? At least, that's what the comment above says.
Has been already been pointed out by Stephen Wilson. setting ret = 0 here.
Quoted 7 lines
kernel/uprobes.c line 159
Quoted 7 lines
kernel/uprobes.c new file +6
-0+ +put_out: +put_page (page);/* we did a get_page in the beginning */ +return ret; +} +
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Peter Zijlstra
maintainerRe: [PATCH v2 2.6.38-rc8-tip 7/20] 7: uprobes: store/restore original instruction.
In reply to Srikar DronamrajuQuoted 23 lines · Srikar Dronamraju
Quoted 7 lines · Stephen Wilson
Quoted 6 lines · Srikar Dronamraju
static int
install_uprobe(struct mm_struct *mm, struct uprobe *uprobe){kernel/uprobes.c +2
-1-int ret =0 ; +struct task_struct *tsk; +int ret = -EINVAL ;Quoted 10 lines
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 506
Quoted 6 lines
kernel/uprobes.c +4
-2-/*TODO: install breakpoint */ -if (!ret) +get_task_struct (mm->owner); + tsk = mm->owner; +if (!tsk) +return ret;I think you need to check that tsk != NULL before calling
get_task_struct()...Guess checking for tsk != NULL would only help if and only if we are doing within rcu. i.e we have to change to something like this
Quoted 8 lines
rcu_read_lock()
if (mm->owner) {
get_task_struct(mm->owner)
tsk = mm->owner;
}
rcu_read_unlock()
if (!tsk)
return ret;so the whole mm->owner semantics seem vague, memcontrol.c doesn't seem consistent in itself, one site uses rcu_dereference() the other site doesn't.
Also, the assignments in kernel/fork.c and kernel/exit.c don't use rcu_assign_pointer() and therefore lack the needed write barrier.
Git blames Balbir for this.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 3/20] 3: uprobes: Breakground page replacement.
In reply to Srikar DronamrajuQuoted 7 lines · Srikar Dronamraju
Quoted 5 lines · Thomas Gleixner
Quoted 3 lines · Srikar Dronamraju
+/*
+ * Called withtsk->mm->mmap_semheld (either for read or write and
+ * with a reference totsk->mm
Quoted 7 lines
Quoted 1 line
Hmm, why is holding it for read sufficient?
We are not adding a new vma to the mm; but just replacing a page with another after holding the locks for the pages. Existing routines doing close to similar things like the access_process_vm/get_user_pages seem to be taking the
read_lock. Do you see a resaon why readlock wouldnt suffice?
No, I just was confused by the comment. Probably should have asked why you want to call it write locked.
Thanks,
tglx
Hi Thomas,
Quoted 2 lines
That's a brilliant reason to drop it right away. systemtap is the least of our worries.
Feeling defensive about something?
Quoted 6 lines
Quoted 3 lines
How do you envisage these features actually get used? For example, will gdb be modified? Will other debuggers be modified or written?
How about answering this question first _BEFORE_ advertising systemtap?
I thought this was obvious. systemtap is essentially a script driven debugger.
-Andi
Signature · 8 lines
[email protected] -- Speaking for myself only. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 5/20] 5: Uprobes: register/unregister probes.
In reply to Peter ZijlstraQuoted 16 lines · Peter Zijlstra
Quoted 15 lines · Steven Rostedt
Quoted 13 lines · Srikar Dronamraju
Quoted 7 lines
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 519
Quoted 5 lines
kernel/uprobes.c +5
-0+ } +list_for_each_entry_safe (mm, tmpmm, &tmp_list, uprobes_list) { +down_read (&mm->mmap_sem); +if (!install_uprobe (mm, uprobe)) + ret =0 ;Installing it once is success ?
This is a little tricky. My intention was to return success even if one install is successful. If we return error, then the caller can go ahead and free the consumer. Since we return success if there are currently no processes that have mapped this inode, I was tempted to return success on atleast one successful install.
Quoted 5 lines
Quoted 2 lines
What about an all or nothing approach. If one fails, remove all that were installed, and give up.
That sounds like a much saner semantic and is what we generally do in the kernel.
One of the install_uprobe could be failing because the process was almost exiting, something like there was no mm->owner. Also lets assume that the first few install_uprobes go thro and the last install_uprobe fails. There could be breakpoint hits corresponding to the already installed uprobes that get displayed. i.e all breakpoint hits from the first install_uprobe to the time we detect a failed a install_uprobe and revert all inserted breakpoints will be shown as being captured.
Also register_uprobe will only install probes for processes that are actively and have mapped the inode. However install_uprobe called from uprobe_mmap which also registers the probe can fail. Now should we take the same yardstick and remove all the probes corresponding to the successful register_uprobe?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 3/20] 3: uprobes: Breakground page replacement.
In reply to Thomas GleixnerQuoted 11 lines · Thomas Gleixner
Quoted 9 lines · Srikar Dronamraju
Quoted 6 lines · Thomas Gleixner
Quoted 3 lines · Srikar Dronamraju
+/*
+ * Called withtsk->mm->mmap_semheld (either for read or write and
+ * with a reference totsk->mmHmm, why is holding it for read sufficient?
Quoted 8 lines
Quoted 5 lines
We are not adding a new vma to the mm; but just replacing a page with another after holding the locks for the pages. Existing routines doing close to similar things like the access_process_vm/get_user_pages seem to be taking the
read_lock. Do you see a resaon why readlock wouldnt suffice?No, I just was confused by the comment. Probably should have asked why you want to call it write locked.
We no more call it write locked. So we can drop the reference to write lock.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Peter Zijlstra
maintainerRe: [PATCH v2 2.6.38-rc8-tip 5/20] 5: Uprobes: register/unregister probes.
In reply to Srikar DronamrajuQuoted 24 lines · Srikar Dronamraju
Quoted 16 lines · Peter Zijlstra
Quoted 15 lines · Steven Rostedt
Quoted 13 lines · Srikar Dronamraju
Quoted 7 lines
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 519
Quoted 5 lines
kernel/uprobes.c +5
-0+ } +list_for_each_entry_safe (mm, tmpmm, &tmp_list, uprobes_list) { +down_read (&mm->mmap_sem); +if (!install_uprobe (mm, uprobe)) + ret =0 ;Installing it once is success ?
This is a little tricky. My intention was to return success even if one install is successful. If we return error, then the caller can go ahead and free the consumer. Since we return success if there are currently no processes that have mapped this inode, I was tempted to return success on atleast one successful install.
Quoted 5 lines
Quoted 2 lines
What about an all or nothing approach. If one fails, remove all that were installed, and give up.
That sounds like a much saner semantic and is what we generally do in the kernel.
Quoted 8 lines
One of the
install_uprobecould be failing because the process was almost exiting, something like there was nomm->owner. Also lets assume that the first fewinstall_uprobesgo thro and the lastinstall_uprobefails. There could be breakpoint hits corresponding to the already installed uprobes that get displayed. i.e all breakpoint hits from the firstinstall_uprobeto the time we detect a failed ainstall_uprobeand revert all inserted breakpoints will be shown as being captured.
I think you can gracefully deal with the exit case and simply ignore that one. But you cannot let arbitrary installs fail and still report success, that gives very weak and nearly useless semantics.
Quoted 5 lines
Also
register_uprobewill only install probes for processes that are actively and have mapped the inode. Howeverinstall_uprobecalled fromuprobe_mmapwhich also registers the probe can fail. Now should we take the same yardstick and remove all the probes corresponding to the successfulregister_uprobe?
No, if uprobe_mmap() fails we should fail the mmap(), that also guarantees consistency.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 5/20] 5: Uprobes: register/unregister probes.
In reply to Srikar DronamrajuQuoted 8 lines · Srikar Dronamraju
Quoted 6 lines · Thomas Gleixner
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 519
Quoted 4 lines
kernel/uprobes.c +4
-0+list_for_each_entry_safe (mm, tmpmm, &tmp_list, uprobes_list) { +down_read (&mm->mmap_sem); +if (!install_uprobe (mm, uprobe)) + ret =0 ;Installing it once is success ?
Quoted 5 lines
This is a little tricky. My intention was to return success even if one install is successful. If we return error, then the caller can go ahead and free the consumer. Since we return success if there are currently no processes that have mapped this inode, I was tempted to return success on atleast one successful install.
Ok. Wants to be documented in a comment.
Quoted 23 lines
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +1
-0+ list_del(&mm->uprobes_list);Also the locking rules for
mm->uprobes_listwant to be documented. They are completely non obvious.Quoted 10 lines
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 528
Quoted 8 lines
kernel/uprobes.c +8
-0+up_read (&mm->mmap_sem); +mmput (mm); + } + +consumers_add: +add_consumer (uprobe, consumer); +mutex_unlock (&uprobes_mutex); +put_uprobe (uprobe);Why do we drop the refcount here?
The first time
uprobe_addgets called for a unique inode:offset pair, it sets the refcount to 2 (One for the uprobe creation and the other for register activity). From next time onwards it increments the refcount by (for register activity) 1. The refcount dropped here corresponds to the register activity.
Quoted 3 lines
Similarly unregister takes a refcount thro
find_uprobeand drops it throdel_consumer(). However it drops the creation refcount if and if there are no more consumers.
Ok. That wants a few comments perhaps. It's not really obvious.
Quoted 4 lines
I thought of just taking the refcount just for the first register and decrement for the last unregister. However register/unregister can race with each other causing the refcount to be zero and free the uprobe structure even though we were still registering the probe.
Right, that won't work.
Quoted 17 lines
Quoted 4 lines
Quoted 3 lines
(quoted diff) +2
-0+ return ret; +}Quoted 12 lines
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 611
Quoted 6 lines
kernel/uprobes.c +6
-0+/* +* There could be other threads that could be spinning on +* treelock; some of these threads could be interested in this +* uprobe. Give these threads a chance to run. +*/ +synchronize_sched ();This makes no sense at all. We are not holding treelock, we are about to acquire it. Also what does it matter when they spin on treelock and are interested in this uprobe. Either they find it before we remove it or not. So why
synchronize_sched()? I find the lifetime rules of uprobe utterly confusing. Could you explain please ?
Quoted 12 lines
There could be threads that have hit the breakpoint and are entering the notifier code(interrupt context) and then
do_notify_resume(task context)and trying to acquire the treelock. (treelock is held by the breakpoint hit threads inuprobe_notify_resumewhich gets called indo_notify_resume()) The current thread that is removing the uprobe from therb_treecan race with these threads and might acquire the treelock before some of the breakpoint hit threads. If this happens the interrupted threads have to re-read the opcode to see if the breakpoint location no more has the breakpoint instruction and retry the instruction. However before it can detect and retry, some other thread might insert a breakpoint at that location. This can go in a loop.
Ok, that makes sense, but you want to put a lenghty explanation into the comment above the synchronize_sched() call.
Thanks,
tglx
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 7/20] 7: uprobes: store/restore original instruction.
In reply to Peter ZijlstraQuoted 33 lines · Peter Zijlstra
Quoted 23 lines · Srikar Dronamraju
Quoted 7 lines · Stephen Wilson
Quoted 6 lines · Srikar Dronamraju
static int
install_uprobe(struct mm_struct *mm, struct uprobe *uprobe){kernel/uprobes.c +2
-1-int ret =0 ; +struct task_struct *tsk; +int ret = -EINVAL ;Quoted 10 lines
kernel/uprobes.c static int del_consumer(struct uprobe *uprobe, · line 506
Quoted 6 lines
kernel/uprobes.c +4
-2-/*TODO: install breakpoint */ -if (!ret) +get_task_struct (mm->owner); + tsk = mm->owner; +if (!tsk) +return ret;I think you need to check that tsk != NULL before calling
get_task_struct()...Guess checking for tsk != NULL would only help if and only if we are doing within rcu. i.e we have to change to something like this
Quoted 8 lines
rcu_read_lock() if (mm->owner) { get_task_struct(mm->owner) tsk = mm->owner; } rcu_read_unlock() if (!tsk) return ret;
Quoted 4 lines
so the whole
mm->ownersemantics seem vague,memcontrol.cdoesn't seem consistent in itself, one site usesrcu_dereference()the other site doesn't.
mm->owner should be under rcu_read_lock, unless the task is exiting and mm_count is 1. mm->owner is updated under task_lock().
Quoted 3 lines
Also, the assignments in
kernel/fork.candkernel/exit.cdon't usercu_assign_pointer()and therefore lack the needed write barrier.
Those are paths when the only context using the mm->owner is single
Quoted 1 line
Git blames Balbir for this.
I accept the blame and am willing to fix anything incorrect found in the code.
Signature · 2 lines
Three Cheers, Balbir
Re: [PATCH v2 2.6.38-rc8-tip 11/20] 11: uprobes: slot allocation for uprobes
In reply to Srikar DronamrajuJust a couple of minor notes while I was looking at this code...
kernel/uprobes.c mmap_out: · line 906
Quoted 10 lines
kernel/uprobes.c +10
-0+static struct uprobes_xol_area *xol_alloc_area (void ) +{ +struct uprobes_xol_area *area =NULL ; + + area =kzalloc (sizeof (*area),GFP_USER ); +if (unlikely (!area)) +return NULL ; + + area->bitmap =kzalloc (BITS_TO_LONGS (UINSNS_PER_PAGE ) *sizeof (long ), +GFP_USER );
Why GFP_USER? That causes extra allocation limits to be enforced. Given that in part 14 you have:
+/* Prepare to single-step probed instruction out of line. */ +static int pre_ssout(struct uprobe *uprobe, struct pt_regs *regs,
+ unsigned long vaddr)
+{
+ xol_get_insn_slot(uprobe, vaddr);
+ BUG_ON(!current->utask->xol_vaddr);
It seems to me that you really don't want those allocations to fail.
back to xol_alloc_area():
Quoted 10 lines
kernel/uprobes.c +10
-0+if (!area->bitmap) + goto fail; + +spin_lock_init (&area->slot_lock); +if (!xol_add_vma (area) && !current->mm->uprobes_xol_area) { +task_lock (current); +if (!current->mm->uprobes_xol_area) { + current->mm->uprobes_xol_area = area; +task_unlock (current); +return area;
kernel/uprobes.c mmap_out: · line 927
Quoted 10 lines
kernel/uprobes.c +10
-0+ } +task_unlock (current); + } + +fail: +if (area) { +if (area->bitmap) +kfree (area->bitmap); +kfree (area); + }
You've already checked area against NULL, and kfree() can handle null pointers, so both of those tests are unneeded.
Review
Quoted 2 lines
(quoted diff) +2
-0+ return current->mm->uprobes_xol_area; +}
jon
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Peter Zijlstra
maintainerRe: [PATCH v2 2.6.38-rc8-tip 7/20] 7: uprobes: store/restore original instruction.
In reply to Balbir SinghQuoted 8 lines · Balbir Singh
mm->ownershould be underrcu_read_lock, unless the task is exiting andmm_countis 1.mm->owneris updated undertask_lock().Quoted 3 lines
Also, the assignments in
kernel/fork.candkernel/exit.cdon't usercu_assign_pointer()and therefore lack the needed write barrier.
Quoted 6 lines
Those are paths when the only context using the
mm->owneris singleQuoted 1 line
Git blames Balbir for this.
I accept the blame and am willing to fix anything incorrect found in the code.
:-), ok sounds right, just wasn't entirely obvious when having a quick look.
Steven Rostedt
maintainerRe: [PATCH v2 2.6.38-rc8-tip 7/20] 7: uprobes: store/restore original instruction.
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Balbir Singh
I accept the blame and am willing to fix anything incorrect found in the code.
:-), ok sounds right, just wasn't entirely obvious when having a quick look.
Does that mean we should be adding a comment there?
-- Steve
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 4/20] 4: uprobes: Adding and remove a uprobe in a rb tree.
In reply to Srikar DronamrajuQuoted 18 lines · Srikar Dronamraju
Quoted 7 lines · Thomas Gleixner
Quoted 7 lines
kernel/uprobes.c +7
-0+/* +* Find a uprobe corresponding to a given inode:offset +* Acquires treelock +*/ +static struct uprobe *find_uprobe (struct inode * inode,loff_t offset) +{ +struct uprobe *uprobe;Quoted 9 lines
kernel/uprobes.c bool __weak is_bkpt_insn(u8 *insn) · line 314
Quoted 5 lines
kernel/uprobes.c +5
-0+unsigned long flags; + +spin_lock_irqsave (&treelock, flags); + uprobe =__find_uprobe (inode, offset,NULL ); +spin_unlock_irqrestore (&treelock, flags);What's the calling context ? Do we really need a spinlock here for walking the rb tree ?
Quoted 4 lines
find_uprobe()gets called fromunregister_uprobeand on probe hit fromuprobe_notify_resume. I am not sure if its a good idea to walk the tree as and when the tree is changing either because of a insertion or deletion of a probe.
I know that you cannot walk the tree lockless except you would use some rcu based container for your probes.
Though my question is more whether this needs to be a spinlock or if that could be replaced by a mutex. At least there is no reason to disable interrupts. You cannot trap into a probe from the thread in which you are installing/removing it.
Thanks,
tglx
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Peter Zijlstra
maintainerRe: [PATCH v2 2.6.38-rc8-tip 4/20] 4: uprobes: Adding and remove a uprobe in a rb tree.
Quoted 6 lines · Thomas Gleixner
I am not sure if its a good idea to walk the tree
Quoted 2 lines
as and when the tree is changing either because of a insertion or deletion of a probe.
I know that you cannot walk the tree lockless except you would use some rcu based container for your probes.
You can in fact combine a seqlock, rb-trees and RCU to do lockless walks.
https://lkml.org/lkml/2010/10/20/160
and
https://lkml.org/lkml/2010/10/20/437
But doing that would be an optimization best done once we get all this working nicely.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 17/20] 17: uprobes: filter chain
In reply to Srikar DronamrajuQuoted 3 lines · Srikar Dronamraju
Loops through the filters callbacks of currently registered consumers to see if any consumer is interested in tracing this task.
Should this be part of the series? It is not currently used.
kernel/uprobes.c static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs) · line 439
Quoted 10 lines
/* Acquires
uprobe->consumer_rwsem*/kernel/uprobes.c +9
-0+static bool filter_chain (struct uprobe *uprobe,struct task_struct *t) +{ +struct uprobe_consumer *consumer; +bool ret = false; + +down_read (&uprobe->consumer_rwsem); +for (consumer = uprobe->consumers; consumer; + consumer = consumer->next) { +if (!consumer->filter || consumer->filter (consumer, t)) {
The implementation does not seem to match the changelog description. Should this not be:
if (consumer->filter && consumer->filter(consumer, t))
?
Quoted 8 lines
kernel/uprobes.c +8
-0+ ret = true; +break ; + } + } +up_read (&uprobe->consumer_rwsem); +return ret; +} +
Signature · 8 lines
steve -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 16/20] 16: uprobes: register a notifier for uprobes.
In reply to Srikar Dronamrajukernel/uprobes.c int uprobe_post_notifier(struct pt_regs *regs) · line 1257
Quoted 6 lines · Srikar Dronamraju
kernel/uprobes.c +6
-0+static int __init init_uprobes (void ) +{ +register_die_notifier (&uprobes_exception_nb); +return 0 ; +} +
Although not currently needed, perhaps it would be best to return the result of register_die_notifier() ?
Signature · 1 line
steve
Steven Rostedt
maintainerQuoted 10 lines · Thomas Gleixner
Quoted 8 lines · Andi Kleen
Quoted 5 lines
Quoted 2 lines
How do you envisage these features actually get used? For example, will gdb be modified? Will other debuggers be modified or written?
How about answering this question first _BEFORE_ advertising systemtap?
I thought this was obvious. systemtap is essentially a script driven debugger.
Quoted 7 lines
Oh thanks for the clarification. I always wondered why a computer would need a tap.
And it does not matter at all whether systemtap can use this or not. If the main debuggers used like gdb are not going to use it then it's a complete waste. We don't need another debugging interface just for a single esoteric use case.
The question is, can we have a tracing interface? I don't care about a debugging interface as PTRACE (although the ABI sucks) is fine for that. But any type of live tracing it really sucks for.
Hopefully this will allow perf (and yes even LTTng and systemtap) to be finally able to do seamless tracing between userspace and kernel space. The only other thing we have now is PTRACE, and if you think that's sufficient, then spend a day programming with it.
-- Steve
Quoted 8 lines · Andi Kleen
Quoted 5 lines
Quoted 2 lines
How do you envisage these features actually get used? For example, will gdb be modified? Will other debuggers be modified or written?
How about answering this question first _BEFORE_ advertising systemtap?
I thought this was obvious. systemtap is essentially a script driven debugger.
Oh thanks for the clarification. I always wondered why a computer would need a tap.
And it does not matter at all whether systemtap can use this or not. If the main debuggers used like gdb are not going to use it then it's a complete waste. We don't need another debugging interface just for a single esoteric use case.
Thanks,
tglx
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 19 lines · Steven Rostedt
Quoted 10 lines · Thomas Gleixner
Quoted 8 lines · Andi Kleen
Quoted 5 lines
Quoted 2 lines
How do you envisage these features actually get used? For example, will gdb be modified? Will other debuggers be modified or written?
How about answering this question first _BEFORE_ advertising systemtap?
I thought this was obvious. systemtap is essentially a script driven debugger.
Quoted 7 lines
Oh thanks for the clarification. I always wondered why a computer would need a tap.
And it does not matter at all whether systemtap can use this or not. If the main debuggers used like gdb are not going to use it then it's a complete waste. We don't need another debugging interface just for a single esoteric use case.
Quoted 8 lines
The question is, can we have a tracing interface? I don't care about a debugging interface as PTRACE (although the ABI sucks) is fine for that. But any type of live tracing it really sucks for.
Hopefully this will allow perf (and yes even LTTng and systemtap) to be finally able to do seamless tracing between userspace and kernel space. The only other thing we have now is PTRACE, and if you think that's sufficient, then spend a day programming with it.
I didn't say that ptrace rocks.
All I'm saying is that we want a better argument than a single user which is - and yes i tried it more than once - assbackwards beyond all imagination.
If gdb, perf, trace can and will make use of it then we have sensible arguments enough to go there. If systemtap can use it as well then I have no problem with that..
Thanks,
tglx
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 11/20] 11: uprobes: slot allocation for uprobes
In reply to Srikar DronamrajuQuoted 13 lines · Srikar Dronamraju
kernel/fork.c +1
-0@@ -551,6 +551,7 @@ void mmput(struct mm_struct *mm)might_sleep ();if (atomic_dec_and_test (&mm->mm_users)) { +uprobes_free_xol_area (mm);exit_aio (mm);ksm_exit (mm);khugepaged_exit (mm);/* must run before exit_mmap */
kernel/fork.c struct mm_struct *dup_mm(struct task_struct *tsk) · line 685
Quoted 8 lines
kernel/fork.c +3
-0@@ -677,6 +678,9 @@ struct mm_struct *dup_mm(struct task_struct *tsk)memcpy (mm, oldmm,sizeof (*mm));/* Initializing for Swap token stuff */ +#ifdef CONFIG_UPROBES + mm->uprobes_xol_area =NULL ; +#endif mm->token_priority =0 ; mm->last_interval =0 ;
Perhaps move the uprobes_xol_area initialization away from that comment? A few lines down beside the hugepage #ifdef would read a bit better.
Signature · 8 lines
steve -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerQuoted 9 lines · Thomas Gleixner
On Tue, 15 Mar 2011, Steven Rostedt wrote:
I didn't say that ptrace rocks.
All I'm saying is that we want a better argument than a single user which is - and yes i tried it more than once - assbackwards beyond all imagination.
If gdb, perf, trace can and will make use of it then we have sensible
I'm more interested in the perf/trace than gdb, as the way gdb is mostly used (at least now) to debug problems in the code with a big hammer (single step, look at registers/variables). That is, gdb is usually very interactive and its best to "stop the code" from running to examine what has happened. gdb is not something you will run on an application that is being used by others.
With perf/trace things are different, as you want the task to be as little affected by the tracer as it runs, perhaps even in a production environment. This is a completely different paradigm.
If gdb uses it, great, but I don't think we should bend over backwards to make it usable by gdb. Debugging and tracing are different, with different requirements and needs.
Quoted 2 lines
arguments enough to go there. If systemtap can use it as well then I have no problem with that..
Fair enough.
-- Steve
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 4/20] 4: uprobes: Adding and remove a uprobe in a rb tree.
In reply to Peter ZijlstraLe mardi 15 mars 2011 A 20:48 +0100, Peter Zijlstra a A(C)crit :
Quoted 11 lines · Thomas Gleixner
Quoted 6 lines
I am not sure if its a good idea to walk the tree
Quoted 2 lines
as and when the tree is changing either because of a insertion or deletion of a probe.
I know that you cannot walk the tree lockless except you would use some rcu based container for your probes.
You can in fact combine a seqlock, rb-trees and RCU to do lockless walks.
Quoted 9 lines
https://lkml.org/lkml/2010/10/20/160
and
https://lkml.org/lkml/2010/10/20/437
But doing that would be an optimization best done once we get all this working nicely.
We have such schem in net/ipv4/inetpeer.c function inet_getpeer() (using a seqlock on latest net-next-2.6 tree), but we added a counter to make sure a reader could not enter an infinite loop while traversing tree (AVL tree in inetpeer case).
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 11/20] 11: uprobes: slot allocation for uprobes
In reply to Stephen WilsonQuoted 17 lines · Stephen Wilson
Quoted 15 lines · Srikar Dronamraju
kernel/fork.c +1
-0@@ -551,6 +551,7 @@ void mmput(struct mm_struct *mm)might_sleep ();if (atomic_dec_and_test (&mm->mm_users)) { +uprobes_free_xol_area (mm);exit_aio (mm);ksm_exit (mm);khugepaged_exit (mm);/* must run before exit_mmap */ @@ -677,6 +678,9 @@ struct mm_struct *dup_mm(struct task_struct *tsk)memcpy (mm, oldmm,sizeof (*mm));
Quoted 9 lines
kernel/fork.c struct mm_struct *dup_mm(struct task_struct *tsk) · line 685
Quoted 6 lines
kernel/fork.c +3
-0/* Initializing for Swap token stuff */ +#ifdef CONFIG_UPROBES + mm->uprobes_xol_area =NULL ; +#endif mm->token_priority =0 ; mm->last_interval =0 ;Perhaps move the
uprobes_xol_areainitialization away from that comment? A few lines down beside the hugepage #ifdef would read a bit better.
Okay, Will do.
Signature · 9 lines
Thanks and Regards Srikar -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 11/20] 11: uprobes: slot allocation for uprobes
In reply to Jonathan CorbetQuoted 15 lines · Jonathan Corbet
Just a couple of minor notes while I was looking at this code...
kernel/uprobes.c mmap_out: · line 906
Quoted 10 lines
kernel/uprobes.c +10
-0+static struct uprobes_xol_area *xol_alloc_area (void ) +{ +struct uprobes_xol_area *area =NULL ; + + area =kzalloc (sizeof (*area),GFP_USER ); +if (unlikely (!area)) +return NULL ; + + area->bitmap =kzalloc (BITS_TO_LONGS (UINSNS_PER_PAGE ) *sizeof (long ), +GFP_USER );Why
GFP_USER? That causes extra allocation limits to be enforced. Given that in part 14 you have:
Okay, Will use GFP_KERNEL.
We used GFP_USER because we thought its going to represent part of process address space;
Quoted 27 lines
(quoted diff) +6
-0+/* Prepare to single-step probed instruction out of line. */ +static int pre_ssout(struct uprobe *uprobe, struct pt_regs *regs, + unsigned long vaddr) +{ + xol_get_insn_slot(uprobe, vaddr); + BUG_ON(!current->utask->xol_vaddr);It seems to me that you really don't want those allocations to fail.
back to
xol_alloc_area():Quoted 15 lines
kernel/uprobes.c +15
-0+if (!area->bitmap) + goto fail; + +spin_lock_init (&area->slot_lock); +if (!xol_add_vma (area) && !current->mm->uprobes_xol_area) { +task_lock (current); +if (!current->mm->uprobes_xol_area) { + current->mm->uprobes_xol_area = area; +task_unlock (current); +return area; + } +task_unlock (current); + } + +fail:
Quoted 8 lines
kernel/uprobes.c mmap_out: · line 927
Quoted 5 lines
kernel/uprobes.c +5
-0+if (area) { +if (area->bitmap) +kfree (area->bitmap); +kfree (area); + }You've already checked area against NULL, and
kfree()can handle null pointers, so both of those tests are unneeded.
Okay,
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ return current->mm->uprobes_xol_area; +}jon
Signature · 9 lines
Thanks and Regards Srikar -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 7/20] 7: uprobes: store/restore original instruction.
In reply to Steven RostedtQuoted 11 lines · Steven Rostedt
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Balbir Singh
I accept the blame and am willing to fix anything incorrect found in the code.
:-), ok sounds right, just wasn't entirely obvious when having a quick look.
Does that mean we should be adding a comment there?
This is what the current documentation looks like.
#ifdef CONFIG_MM_OWNER
/*
* "owner" points to a task that is regarded as the canonical
* user/owner of this mm. All of the following must be true in
* order for it to be changed:
*
* current == mm->owner
* current->mm != mm
* new_owner->mm == mm
* new_owner->alloc_lock is held
*/
struct task_struct __rcu *owner;
#endif
Do you want me to document the fork/exit case?
Signature · 9 lines
Three Cheers, Balbir -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Peter Zijlstra
maintainerRe: [PATCH v2 2.6.38-rc8-tip 4/20] 4: uprobes: Adding and remove a uprobe in a rb tree.
In reply to Eric DumazetQuoted 18 lines · Eric Dumazet
Le mardi 15 mars 2011 A 20:48 +0100, Peter Zijlstra a A(C)crit :
Quoted 17 lines · Thomas Gleixner
Quoted 6 lines
I am not sure if its a good idea to walk the tree
Quoted 2 lines
as and when the tree is changing either because of a insertion or deletion of a probe.
I know that you cannot walk the tree lockless except you would use some rcu based container for your probes.
You can in fact combine a seqlock, rb-trees and RCU to do lockless walks.
https://lkml.org/lkml/2010/10/20/160
and
Quoted 7 lines
Quoted 3 lines
But doing that would be an optimization best done once we get all this working nicely.
We have such schem in
net/ipv4/inetpeer.cfunctioninet_getpeer()(using a seqlock on latest net-next-2.6 tree), but we added a counter to make sure a reader could not enter an infinite loop while traversing tree
Right, Linus suggested a single lockless iteration, but a limited count works too.
Quoted 1 line
(AVL tree in inetpeer case).
Ooh, there's an AVL implementation in the kernel? I have to ask, why not use the RB-tree? (I know AVL has a slightly stronger balancing condition which reduces the max depth from 2*log(n) to 1+log(n)).
Also, if it does make sense to have both and AVL and RB implementation, does it then also make sense to lift the AVL thing to generic code into lib/ ?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 3 lines
Quoted 3 lines
If gdb, perf, trace can and will make use of it then we have sensible arguments enough to go there. If systemtap can use it as well then I have no problem with that..
Yes, gdb would be able to use it.
I don't know of anybody working on it at present.
Tom
Steve> I'm more interested in the perf/trace than gdb, as the way gdb is mostly Steve> used (at least now) to debug problems in the code with a big hammer Steve> (single step, look at registers/variables). That is, gdb is usually very Steve> interactive and its best to "stop the code" from running to examine what Steve> has happened. gdb is not something you will run on an application that Steve> is being used by others.
It depends. People do in fact do this stuff. In recent years gdb got its own implementation of "always inserted" breakpoints (basically the same idea as uprobes) to support some trickier multi-thread debugging scenarios.
Tom
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerRe: [PATCH v2 2.6.38-rc8-tip 7/20] 7: uprobes: store/restore original instruction.
In reply to Balbir SinghQuoted 30 lines · Balbir Singh
Quoted 11 lines · Steven Rostedt
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Balbir Singh
I accept the blame and am willing to fix anything incorrect found in the code.
:-), ok sounds right, just wasn't entirely obvious when having a quick look.
Does that mean we should be adding a comment there?
This is what the current documentation looks like.
#ifdef
CONFIG_MM_OWNER
/*
* "owner" points to a task that is regarded as the canonical
* user/owner of this mm. All of the following must be true in
* order for it to be changed:
*
* current ==mm->owner
*current->mm!= mm
*new_owner->mm== mm
*new_owner->alloc_lockis held
*/
structtask_struct__rcu*owner;
#endif
Quoted 2 lines
Do you want me to document the fork/exit case?
Ah, looking at the code, I guess comments are not needed.
Thanks,
-- Steve
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerQuoted 11 lines · Tom Tromey
Steve> I'm more interested in the perf/trace than gdb, as the way gdb is mostly Steve> used (at least now) to debug problems in the code with a big hammer Steve> (single step, look at registers/variables). That is, gdb is usually very Steve> interactive and its best to "stop the code" from running to examine what Steve> has happened. gdb is not something you will run on an application that Steve> is being used by others.
It depends. People do in fact do this stuff. In recent years gdb got its own implementation of "always inserted" breakpoints (basically the same idea as uprobes) to support some trickier multi-thread debugging scenarios.
Like I said, if it helps out gdb then great! My concern is that we will want it to replace ptrace, where it may not be designed to, then people will start NAKing it.
I hope that gdb uses it, and we don't add another interface that nobody uses. But I don't see that happening with uprobes.
-- Steve
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 6/20] 6: x86: analyze instruction and determine fixups.
In reply to Thomas GleixnerQuoted 7 lines
arch/x86/kernel/uprobes.c line 410
Quoted 5 lines
arch/x86/kernel/uprobes.c new file +4
-0+ ret =handle_riprel_insn (uprobe, &insn); +if (ret ==-1 ) +/* rip-relative; can't XOL */ +return 0 ;So we return -1 from
handle_riprel_insn()and return success?
handle_riprel_insn() returns 0 if the instruction is not rip-relative returns 1 if its rip-relative but can use XOL slots. returns -1 if its rip-relative but cannot use XOL.
We dont see any instructions that are rip-relative and cannot use XOL. so the check and return are redundant and I will remove that in the next patch.
Btw how
Quoted 2 lines
deals
handle_riprel_insn()with 32bit user space ?
handle_riprel_insn() calls insn_rip_relative() which fails if instruction isnot rip-relative and handle_riprel_insn returns immediately.
The rest of your suggestions for this patch are taken.
Quoted 4 lines
Quoted 3 lines
arch/x86/kernel/uprobes.c new file +3
-0+#endif +prepare_fixups (uprobe, &insn); +return 0 ;
Signature · 2 lines
Thanks and Regards Srikar
Re: [PATCH v2 2.6.38-rc8-tip 6/20] 6: x86: analyze instruction and determine fixups.
Quoted 7 lines
handle_riprel_insn()returns 0 if the instruction is not rip-relative returns 1 if its rip-relative but can use XOL slots. returns -1 if its rip-relative but cannot use XOL.We dont see any instructions that are rip-relative and cannot use XOL. so the check and return are redundant and I will remove that in the next patch.
How is that? You can only adjust a rip-relative instruction correctly if the instruction copy is within 2GB of the original target address, which cannot be presumed to always be the case in user address space layout (unlike the kernel).
Thanks,
Roland
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 6/20] 6: x86: analyze instruction and determine fixups.
Quoted 4 lines · Roland McGrath
Quoted 4 lines
handle_riprel_insn()returns 0 if the instruction is not rip-relative returns 1 if its rip-relative but can use XOL slots. returns -1 if its rip-relative but cannot use XOL.
Quoted 9 lines
Quoted 3 lines
We dont see any instructions that are rip-relative and cannot use XOL. so the check and return are redundant and I will remove that in the next patch.
How is that? You can only adjust a rip-relative instruction correctly if the instruction copy is within 2GB of the original target address, which cannot be presumed to always be the case in user address space layout (unlike the kernel).
So we rewrite the copy of instruction (stored in XOL) such that it accesses its memory operand indirectly thro a scratch register. The contents of the scratch register are stored before singlestep and restored later.
Can you please tell us if this doesnt work?
Signature · 9 lines
Thanks and Regards Srikar -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 5/20] 5: Uprobes: register/unregister probes.
In reply to Peter ZijlstraQuoted 10 lines
Quoted 9 lines
One of the
install_uprobecould be failing because the process was almost exiting, something like there was nomm->owner. Also lets assume that the first fewinstall_uprobesgo thro and the lastinstall_uprobefails. There could be breakpoint hits corresponding to the already installed uprobes that get displayed. i.e all breakpoint hits from the firstinstall_uprobeto the time we detect a failed ainstall_uprobeand revert all inserted breakpoints will be shown as being captured.
Quoted 3 lines
I think you can gracefully deal with the exit case and simply ignore that one. But you cannot let arbitrary installs fail and still report success, that gives very weak and nearly useless semantics.
If there are more than one instance of a process running and if one instance of a process has a probe thro ptrace, install_uprobe would fail for that process with -EEXIST since we dont want to probe locations that have breakpoints already. Should we then act similar to the exit case, do we also deal gracefully?
Signature · 9 lines
Thanks and Regards Srikar -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 6/20] 6: x86: analyze instruction and determine fixups.
In reply to Srikar DronamrajuQuoted 4 lines
So we rewrite the copy of instruction (stored in XOL) such that it accesses its memory operand indirectly thro a scratch register. The contents of the scratch register are stored before singlestep and restored later.
I see. That should work fine in principle, assuming you use a register that is not otherwise involved, of course. I hope you arrange to restore the register if the copied instruction is never run because of a signal or suchlike. In that case, it's important that the signal context get the original register and original PC rather than the fiddled state for running the copy. Likewise, if anyone is inspecting the registers right after the step.
Thanks,
Roland
Re: [PATCH v2 2.6.38-rc8-tip 6/20] 6: x86: analyze instruction and determine fixups.
In reply to Srikar DronamrajuQuoted 16 lines · Srikar Dronamraju
Quoted 4 lines · Roland McGrath
Quoted 4 lines
handle_riprel_insn()returns 0 if the instruction is not rip-relative returns 1 if its rip-relative but can use XOL slots. returns -1 if its rip-relative but cannot use XOL.Quoted 9 lines
Quoted 3 lines
We dont see any instructions that are rip-relative and cannot use XOL. so the check and return are redundant and I will remove that in the next patch.
How is that? You can only adjust a rip-relative instruction correctly if the instruction copy is within 2GB of the original target address, which cannot be presumed to always be the case in user address space layout (unlike the kernel).
Quoted 7 lines
So we rewrite the copy of instruction (stored in XOL) such that it accesses its memory operand indirectly thro a scratch register. The contents of the scratch register are stored before singlestep and restored later.
Can you please tell us if this doesnt work?
Infact we have tested using rip-relative addresses and it has worked very well. So we have verified that it does work. Can you please tell us why you dont think this works?
Signature · 9 lines
Thanks and Regards Srikar -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 17/20] 17: uprobes: filter chain
In reply to Stephen WilsonQuoted 24 lines · Stephen Wilson
Quoted 3 lines · Srikar Dronamraju
Loops through the filters callbacks of currently registered consumers to see if any consumer is interested in tracing this task.
Should this be part of the series? It is not currently used.
kernel/uprobes.c static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs) · line 439
Quoted 10 lines
/* Acquires
uprobe->consumer_rwsem*/kernel/uprobes.c +9
-0+static bool filter_chain (struct uprobe *uprobe,struct task_struct *t) +{ +struct uprobe_consumer *consumer; +bool ret = false; + +down_read (&uprobe->consumer_rwsem); +for (consumer = uprobe->consumers; consumer; + consumer = consumer->next) { +if (!consumer->filter || consumer->filter (consumer, t)) {The implementation does not seem to match the changelog description. Should this not be:
Quoted 3 lines
if (consumer->filter && consumer->filter(consumer, t))?
filter is optional; if filter is present, then it means that the tracer is interested in a specific set of processes that maps this inode. If there is no filter; it means that it is interested in all processes that map this filter.
filter_chain() should return true if any consumer is interested in
tracing this task.
if there is a consumer who hasnt defined a filter then we dont need to loop thro remaining consumers.
Hence
if (!consumer->filter || consumer->filter(consumer, t)) {
seems better suited to me.
Signature · 9 lines
Thanks and Regards Srikar -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 16/20] 16: uprobes: register a notifier for uprobes.
In reply to Stephen WilsonQuoted 11 lines · Stephen Wilson
kernel/uprobes.c int uprobe_post_notifier(struct pt_regs *regs) · line 1257
Quoted 6 lines · Srikar Dronamraju
kernel/uprobes.c +6
-0+static int __init init_uprobes (void ) +{ +register_die_notifier (&uprobes_exception_nb); +return 0 ; +} +Although not currently needed, perhaps it would be best to return the result of
register_die_notifier()?
Okay, I can do that but notifier_chain_register() that gets called from register_die_notifier() always return 0.
Signature · 9 lines
Thanks and Regards Srikar -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 2.6.38-rc8-tip 17/20] 17: uprobes: filter chain
In reply to Srikar DronamrajuQuoted 7 lines · Srikar Dronamraju
Quoted 7 lines
kernel/uprobes.c static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs) · line 439
Quoted 3 lines
kernel/uprobes.c +3
-0+for (consumer = uprobe->consumers; consumer; + consumer = consumer->next) { +if (!consumer->filter || consumer->filter (consumer, t)) {The implementation does not seem to match the changelog description. Should this not be:
Quoted 8 lines
Quoted 3 lines
if (consumer->filter && consumer->filter(consumer, t))?
filter is optional; if filter is present, then it means that the tracer is interested in a specific set of processes that maps this inode. If there is no filter; it means that it is interested in all processes that map this filter.
Ah OK. That does make sense then. Thanks!
Quoted 9 lines
filter_chain()should return true if any consumer is interested in tracing this task. if there is a consumer who hasnt defined a filter then we dont need to loop thro remaining consumers.Hence
if (!consumer->filter ||
consumer->filter(consumer, t)) {seems better suited to me.
Signature · 8 lines
steve -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>