summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Arapov <anton@redhat.com>2012-11-01 00:00:00 +0200
committerAnton Arapov <anton@redhat.com>2012-11-01 13:42:41 +0100
commitbb46fb09dc6fc12927b21f3dce909b6f69dc8247 (patch)
treebe743ff176977b384a0e18804b1b3ba0b132d000
parent64f2f461a27d90509299071c5d60cc3a0b7d6f38 (diff)
downloadkernel-uprobes-bb46fb09dc6fc12927b21f3dce909b6f69dc8247.zip
kernel-uprobes-bb46fb09dc6fc12927b21f3dce909b6f69dc8247.tar.gz
kernel-uprobes-bb46fb09dc6fc12927b21f3dce909b6f69dc8247.tar.xz
uretprobes: trampoline implementation
The first time a uprobe corresponding to a uretprobe is hit for a process, a trampoline slot is obtained in the uprobes_xol_area and initialized with a breakpoint instruction. This slot is subsequently used by all uretprobes. Signed-off-by: Anithra P Janakiraman <anithra@linux.vnet.ibm.com> Signed-off-by: Anton Arapov <anton@redhat.com>
-rw-r--r--include/linux/uprobes.h1
-rw-r--r--kernel/events/uprobes.c42
2 files changed, 43 insertions, 0 deletions
diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h
index 2459457..ffb1984 100644
--- a/include/linux/uprobes.h
+++ b/include/linux/uprobes.h
@@ -84,6 +84,7 @@ struct xol_area {
* the vma go away, and we must handle that reasonably gracefully.
*/
unsigned long vaddr; /* Page(s) of instruction slots */
+ unsigned long uretprobe_trampoline_addr; /* addr of trampolines */
};
struct uprobes_state {
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index c92651d..29c73d7 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -99,6 +99,7 @@ struct uprobe {
};
/*
+static struct xol_area *get_xol_area(struct mm_struct *mm);
* valid_vma: Verify if the specified vma is an executable vma
* Relax restrictions while unregistering: vm_flags might have
* changed after breakpoint was inserted.
@@ -1238,6 +1239,47 @@ static void xol_free_insn_slot(struct task_struct *tsk)
}
}
+/* xol_get_trampoline_slot - A trampoline slot is obtained the first
+ * time a uprobe corresponding to a uretprobe is hit for a process. We
+ * use one trampoline slot for all probes pertaining to a process, i.e
+ * one per uprobes_xol_area.
+ */
+static unsigned long xol_get_trampoline_slot(void)
+{
+ struct mm_struct *mm = current->mm;
+ struct xol_area *area;
+ unsigned long xol_trampoline_addr = 0;
+ unsigned long offset;
+ void *vaddr;
+ uprobe_opcode_t bp_insn = UPROBE_SWBP_INSN;
+
+ area = get_xol_area(mm);
+ if (!area) {
+ area = xol_alloc_area();
+ if (!area)
+ return 0;
+ }
+
+ xol_trampoline_addr = area->uretprobe_trampoline_addr;
+ if (!xol_trampoline_addr) {
+ xol_trampoline_addr = xol_take_insn_slot(area);
+ area->uretprobe_trampoline_addr = xol_trampoline_addr;
+ }
+
+ /* Initialize the slot if trampoline_addr points to valid
+ * instruction slot.
+ */
+ if (unlikely(!xol_trampoline_addr))
+ return 0;
+
+ offset = xol_trampoline_addr & ~PAGE_MASK;
+ vaddr = kmap_atomic(area->page);
+ memcpy(vaddr + offset, &bp_insn, UPROBE_SWBP_INSN_SIZE);
+ kunmap_atomic(vaddr);
+
+ return area->uretprobe_trampoline_addr;
+}
+
/**
* uprobe_get_swbp_addr - compute address of swbp given post-swbp regs
* @regs: Reflects the saved state of the task after it has hit a breakpoint