Maintain a per-mm counter (number of uprobes that are inserted onthis process address space). This counter can be used at probe hittime to determine if we need a lookup in the uprobes rbtree.Everytime a probe gets inserted successfully, the probe count isincremented and everytime a probe gets removed, the probe count isdecremented.

The new uprobe_munmap hook ensures the count is correct on a unmapor remap of a region. We expect that once a uprobe_munmap() iscalled, the vma goes away. So uprobe_unregister() finding a probeto unregister would either mean unmap event hasnt occurred yet or ammap event on the same executable file occured after a unmap event.

Additionally, uprobe_mmap hook now also gets called:a. on every executable vma that is COWed at fork.b. a vma of interest is newly mapped; breakpoint insertion also happens at the required address.

On process creation, make sure the probes count in the child is setcorrectly.

Special cases that are taken care include:a. mremapb. VM_DONTCOPY vmas on fork()c. insertion/removal races in the parent during fork().

Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>---Changelog:(v7)- Move mm->mm_uprobes_count to mm->uprobes_state.count.- Separate this patch from the patch that implements uprobe_mmap.- Increment counter only after verifying that the probe lies underneath.

(v5)- While forking, handle vma's that have VM_DONTCOPY.- While forking, handle race of new breakpoints being inserted / removed in the parent process.

uprobe->flags |= UPROBE_COPY_INSN; }++ /*+ * Ideally, should be updating the probe count after the breakpoint+ * has been successfully inserted. However a thread could hit the+ * breakpoint we just inserted even before the probe count is+ * incremented. If this is the first breakpoint placed, breakpoint+ * notifier might ignore uprobes and pass the trap to the thread.+ * Hence increment before and decrement on failure.+ */+ atomic_inc(&mm->uprobes_state.count); ret = set_swbp(&uprobe->arch, mm, addr);+ if (ret)+ atomic_dec(&mm->uprobes_state.count);