]> Pileus Git - ~andy/linux/commitdiff
uprobes: Add uprobe_task->dup_xol_work/dup_xol_addr
authorOleg Nesterov <oleg@redhat.com>
Fri, 8 Nov 2013 17:52:21 +0000 (18:52 +0100)
committerOleg Nesterov <oleg@redhat.com>
Wed, 20 Nov 2013 15:30:57 +0000 (16:30 +0100)
uprobe_task->vaddr is a bit strange. The generic code uses it only
to pass the additional argument to arch_uprobe_pre_xol(), and since
it is always equal to instruction_pointer() this looks even more
strange.

And both utask->vaddr and and utask->autask have the same scope,
they only have the meaning when the task executes the probed insn
out-of-line, so it is safe to reuse both in UTASK_RUNNING state.

This all means that logically ->vaddr belongs to arch_uprobe_task
and we should probably move it there, arch_uprobe_pre_xol() can
record instruction_pointer() itself.

OTOH, it is also used by uprobe_copy_process() and dup_xol_work()
for another purpose, this doesn't look clean and doesn't allow to
move this member into arch_uprobe_task.

This patch adds the union with 2 anonymous structs into uprobe_task.

The first struct is autask + vaddr, this way we "almost" move vaddr
into autask.

The second struct has 2 new members for uprobe_copy_process() paths:
->dup_xol_addr which can be used instead ->vaddr, and ->dup_xol_work
which can be used to avoid kmalloc() and simplify the code.

Note that this union will likely have another member(s), we need
something like "private_data_for_handlers" so that the tracing
handlers could use it to communicate with call_fetch() methods.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Acked-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
include/linux/uprobes.h
kernel/events/uprobes.c

index 319eae70fe8415f774e57c4861b98688fb81bb4c..2225542624deaa020a93453d2700e4e3468353fb 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <linux/errno.h>
 #include <linux/rbtree.h>
+#include <linux/types.h>
 
 struct vm_area_struct;
 struct mm_struct;
@@ -72,14 +73,24 @@ enum uprobe_task_state {
  */
 struct uprobe_task {
        enum uprobe_task_state          state;
-       struct arch_uprobe_task         autask;
 
-       struct return_instance          *return_instances;
-       unsigned int                    depth;
-       struct uprobe                   *active_uprobe;
+       union {
+               struct {
+                       struct arch_uprobe_task autask;
+                       unsigned long           vaddr;
+               };
+
+               struct {
+                       struct callback_head    dup_xol_work;
+                       unsigned long           dup_xol_addr;
+               };
+       };
 
+       struct uprobe                   *active_uprobe;
        unsigned long                   xol_vaddr;
-       unsigned long                   vaddr;
+
+       struct return_instance          *return_instances;
+       unsigned int                    depth;
 };
 
 /*
index 24b7d6ca871b632f2e35912e720bfc0162c939c5..df4ef0971266a3fd40cbd346dc9795286ad63471 100644 (file)
@@ -1403,12 +1403,10 @@ static void uprobe_warn(struct task_struct *t, const char *msg)
 
 static void dup_xol_work(struct callback_head *work)
 {
-       kfree(work);
-
        if (current->flags & PF_EXITING)
                return;
 
-       if (!__create_xol_area(current->utask->vaddr))
+       if (!__create_xol_area(current->utask->dup_xol_addr))
                uprobe_warn(current, "dup xol area");
 }
 
@@ -1419,7 +1417,6 @@ void uprobe_copy_process(struct task_struct *t, unsigned long flags)
 {
        struct uprobe_task *utask = current->utask;
        struct mm_struct *mm = current->mm;
-       struct callback_head *work;
        struct xol_area *area;
 
        t->utask = NULL;
@@ -1441,14 +1438,9 @@ void uprobe_copy_process(struct task_struct *t, unsigned long flags)
        if (mm == t->mm)
                return;
 
-       /* TODO: move it into the union in uprobe_task */
-       work = kmalloc(sizeof(*work), GFP_KERNEL);
-       if (!work)
-               return uprobe_warn(t, "dup xol area");
-
-       t->utask->vaddr = area->vaddr;
-       init_task_work(work, dup_xol_work);
-       task_work_add(t, work, true);
+       t->utask->dup_xol_addr = area->vaddr;
+       init_task_work(&t->utask->dup_xol_work, dup_xol_work);
+       task_work_add(t, &t->utask->dup_xol_work, true);
 }
 
 /*