uprobes: Add uprobe_task->dup_work/dup_addr
Subsystems (2)
Oleg Nesterov
maintainerPATCH 1/1 uprobes: Add uprobe_task->dup_work/dup_addr
uprobe_task->vaddr is a bit strange. First of all it is not really needed, we can move it into arch_uprobe_task. 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. This means it is safe to reuse both in UTASK_RUNNING state.
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_addr which can be used instead ->vaddr, and ->dup_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.
--- include/linux/uprobes.h | 21 ++++++++++++++++----- kernel/events/uprobes.c | 16 ++++------------ 2 files changed, 20 insertions(+), 17 deletions(-)
include/linux/uprobes.h +16 -5
@@ -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_work; +unsigned long dup_addr; + }; + }; +struct uprobe *active_uprobe;unsigned long xol_vaddr; -unsigned long vaddr; + +struct return_instance *return_instances; +unsigned int depth; };/*
kernel/events/uprobes.c +4 -12
@@ -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_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_addr = area->vaddr; +init_task_work (&t->utask->dup_work, dup_xol_work); +task_work_add (t, &t->utask->dup_work, true); }/*
Signature · 1 line
1.5.5.1
Quoted 15 lines · Oleg Nesterov
uprobe_task->vaddris a bit strange. First of all it is not really needed, we can move it intoarch_uprobe_task. The generic code uses it only to pass the additional argument toarch_uprobe_pre_xol(), and since it is always equal toinstruction_pointer()this looks even more strange.And both
utask->vaddrand andutask->autaskhave the same scope, they only have the meaning when the task executes the probed insn out-of-line. This means it is safe to reuse both inUTASK_RUNNINGstate.OTOH, it is also used by
uprobe_copy_process()anddup_xol_work()for another purpose, this doesn't look clean and doesn't allow to move this member intoarch_uprobe_task.
Quoted 8 lines
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_addr which can be used instead ->vaddr, and ->dup_work which can be used to avoidkmalloc()and simplify the code.
Hmm, I'm not so sure about uprobes implementation so deeply. Is there no possibility to run xol preparing code (e.g. adding new uprobe?) between the task_work_add() and task_work_run()?
Quoted 4 lines
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 withcall_fetch()methods.
If those data structures are small, I think we don't need to use such union...
Thank you,
Signature · 4 lines
Masami HIRAMATSU IT Management Research Dept. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Oleg Nesterov
maintainerQuoted 22 lines · Masami Hiramatsu
Quoted 20 lines · Oleg Nesterov
uprobe_task->vaddris a bit strange. First of all it is not really needed, we can move it intoarch_uprobe_task. The generic code uses it only to pass the additional argument toarch_uprobe_pre_xol(), and since it is always equal toinstruction_pointer()this looks even more strange.And both
utask->vaddrand andutask->autaskhave the same scope, they only have the meaning when the task executes the probed insn out-of-line. This means it is safe to reuse both inUTASK_RUNNINGstate.OTOH, it is also used by
uprobe_copy_process()anddup_xol_work()for another purpose, this doesn't look clean and doesn't allow to move this member intoarch_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.
Quoted 7 lines
Quoted 3 lines
The second struct has 2 new members for
uprobe_copy_process()paths:
->dup_addr which can be used instead ->vaddr, and ->dup_work which can be used to avoidkmalloc()and simplify the code.Hmm, I'm not so sure about uprobes implementation so deeply. Is there no possibility to run xol preparing code (e.g. adding new uprobe?) between the
task_work_add()andtask_work_run()?
No, task_work_run() must be called before the new child returns to user-mode.
And it obviously can't hit the breakpoint until it returns to user mode. "adding new uprobe" doesn't matter at all, the task itself runs xol preparing code when it hits the bp first time.
Quoted 7 lines
Quoted 4 lines
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 withcall_fetch()methods.If those data structures are small, I think we don't need to use such union...
Well, I disagree. First of all, to me this patch cleanups the code but this is subjective.
Why should we blow the size of task_struct->utask if there is no reason?
For example, should we instead add utask->dup_addr outiside of this union? Or create dup_xol_struct which holds this argument along with callback_head ? I don't think so. The scope of autask/vaddr and dup_work/addr is not interactable.
The same for the new ->private (or whatever) we are going to add for FETCH_MTD_relative. It will only have a meaning inside the ->handler() paths, to me it would be strange to not reuse the "free" memory we already have.
Oleg.
Quoted 31 lines · Oleg Nesterov
Quoted 22 lines · Masami Hiramatsu
Quoted 20 lines · Oleg Nesterov
uprobe_task->vaddris a bit strange. First of all it is not really needed, we can move it intoarch_uprobe_task. The generic code uses it only to pass the additional argument toarch_uprobe_pre_xol(), and since it is always equal toinstruction_pointer()this looks even more strange.And both
utask->vaddrand andutask->autaskhave the same scope, they only have the meaning when the task executes the probed insn out-of-line. This means it is safe to reuse both inUTASK_RUNNINGstate.OTOH, it is also used by
uprobe_copy_process()anddup_xol_work()for another purpose, this doesn't look clean and doesn't allow to move this member intoarch_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.
Quoted 7 lines
Quoted 3 lines
The second struct has 2 new members for
uprobe_copy_process()paths:
->dup_addr which can be used instead ->vaddr, and ->dup_work which can be used to avoidkmalloc()and simplify the code.Hmm, I'm not so sure about uprobes implementation so deeply. Is there no possibility to run xol preparing code (e.g. adding new uprobe?) between the
task_work_add()andtask_work_run()?
Quoted 6 lines
No,
task_work_run()must be called before the new child returns to user-mode.And it obviously can't hit the breakpoint until it returns to user mode. "adding new uprobe" doesn't matter at all, the task itself runs xol preparing code when it hits the bp first time.
Ah, I misunderstood. XOL area should be placed in each process address space, thus until it hits the probe, uprobe can't create XOL code, I got it.
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
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 withcall_fetch()methods.If those data structures are small, I think we don't need to use such union...
Well, I disagree. First of all, to me this patch cleanups the code but this is subjective.
Quoted 7 lines
Why should we blow the size of
task_struct->utaskif there is no reason?For example, should we instead add
utask->dup_addroutiside of this union? Or createdup_xol_structwhich holds this argument along withcallback_head? I don't think so. The scope of autask/vaddr and dup_work/addr is not interactable.
I see your point.
Quoted 4 lines
The same for the new ->private (or whatever) we are going to add for
FETCH_MTD_relative. It will only have a meaning inside the ->handler() paths, to me it would be strange to not reuse the "free" memory we already have.
Looks nice ;)
Thank you,
Signature · 4 lines
Masami HIRAMATSU IT Management Research Dept. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Quoted 20 lines · Oleg Nesterov
uprobe_task->vaddris a bit strange. First of all it is not really needed, we can move it intoarch_uprobe_task. The generic code uses it only to pass the additional argument toarch_uprobe_pre_xol(), and since it is always equal toinstruction_pointer()this looks even more strange.And both
utask->vaddrand andutask->autaskhave the same scope, they only have the meaning when the task executes the probed insn out-of-line. This means it is safe to reuse both inUTASK_RUNNINGstate.OTOH, it is also used by
uprobe_copy_process()anddup_xol_work()for another purpose, this doesn't look clean and doesn't allow to move this member intoarch_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.
Quoted 7 lines
The second struct has 2 new members for
uprobe_copy_process()paths:
->dup_addr which can be used instead ->vaddr, and ->dup_work which can be used to avoidkmalloc()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 withcall_fetch()methods.
OK, those are used in the different phase as a scratchpad.
Quoted 1 line
Signed-off-by Oleg Nesterov <[email protected]>
Thanks!
Quoted 92 lines
--- include/linux/uprobes.h | 21 ++++++++++++++++----- kernel/events/uprobes.c | 16 ++++------------ 2 files changed, 20 insertions(+), 17 deletions(-)include/linux/uprobes.h +16
-5@@ -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_work; +unsigned long dup_addr; + }; + }; +struct uprobe *active_uprobe;unsigned long xol_vaddr; -unsigned long vaddr; + +struct return_instance *return_instances; +unsigned int depth; };/* kernel/events/uprobes.c +4
-12@@ -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_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_addr = area->vaddr; +init_task_work (&t->utask->dup_work, dup_xol_work); +task_work_add (t, &t->utask->dup_work, true); }/*
Signature · 4 lines
Masami HIRAMATSU IT Management Research Dept. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Quoted 6 lines · Oleg Nesterov
uprobe_task->vaddris a bit strange. First of all it is not really needed, we can move it intoarch_uprobe_task. The generic code uses it only to pass the additional argument toarch_uprobe_pre_xol(), and since it is always equal toinstruction_pointer()this looks even more strange.
While the code changes look good, I would disagree with the above statement. uprobe_task->vaddr is a bit strange only in uprobe_copy_process() and not in arch_uprobe_pre_xol() context. uprobe_task->vaddr was used to refer to the actual instruction pointer and do the necessary fixups after single stepping out of line.
The casual reading of this commit message, one can get an impression that vaddr is never needed. Your change still retains it. So can we modify the commit message accordingly?
Quoted 14 lines
And both
utask->vaddrand andutask->autaskhave the same scope, they only have the meaning when the task executes the probed insn out-of-line. This means it is safe to reuse both inUTASK_RUNNINGstate.OTOH, it is also used by
uprobe_copy_process()anddup_xol_work()for another purpose, this doesn't look clean and doesn't allow to move this member intoarch_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.
Quoted 7 lines
The second struct has 2 new members for
uprobe_copy_process()paths:
->dup_addr which can be used instead ->vaddr, and ->dup_work which can be used to avoidkmalloc()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 withcall_fetch()methods.
One nit below + request for change in the above commit message. Otherwise
Quoted 27 lines
Signed-off-by Oleg Nesterov <[email protected]>--- include/linux/uprobes.h | 21 ++++++++++++++++----- kernel/events/uprobes.c | 16 ++++------------ 2 files changed, 20 insertions(+), 17 deletions(-)include/linux/uprobes.h +1
-3@@ -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;
include/linux/uprobes.h enum uprobe_task_state { · line 85
Quoted 10 lines
include/linux/uprobes.h +9
-1-struct uprobe *active_uprobe; +union { +struct { +struct arch_uprobe_task autask; +unsigned long vaddr; + }; + +struct { +struct callback_head dup_work; +unsigned long dup_addr;
Nit:
Can we rename dup_addr to mean that it refers to the xol; something like dup_xol_addr or even xol_addr. So that its more clear what address it refers to.
Signature · 2 lines
Thanks and Regards Srikar Dronamraju
Oleg Nesterov
maintainerQuoted 10 lines · Srikar Dronamraju
Quoted 6 lines · Oleg Nesterov
uprobe_task->vaddris a bit strange. First of all it is not really needed, we can move it intoarch_uprobe_task. The generic code uses it only to pass the additional argument toarch_uprobe_pre_xol(), and since it is always equal toinstruction_pointer()this looks even more strange.
Quoted 4 lines
While the code changes look good, I would disagree with the above statement.
uprobe_task->vaddris a bit strange only inuprobe_copy_process()and not inarch_uprobe_pre_xol()context.uprobe_task->vaddrwas used to refer to the actual instruction pointer
Yes, and it is always equal to regs->ip when pre_ssout() is called,
Quoted 1 line
and do the necessary fixups after single stepping out of line.
Exactly. So it is write-only (and meaningless) to the generic uprobe code. We can (and perhaps should) move it into autask->saved_vaddr, arch_uprobe_pre_xol() can initialize it.
Quoted 2 lines
The casual reading of this commit message, one can get an impression that vaddr is never needed.
See above. The changelog doesn't say we can simply remove it, it says "move it".
Quoted 1 line
Your change still retains it.
Of course we can't kill utas->vaddr until we change x86/powerpc. And just in case, of course I understand that this is minor and even subjective.
But at least this patch logically "joins" autask and vaddr, and I believe this is good because they are always used together, because, well, logically vaddr belongs to autask ;)
Quoted 2 lines
So can we
modify the commit message accordingly?
Well, I'll try... but perhaps you can help? I mean, I am not sure about how I can improve it. Could you suggest a better wording?
Quoted 2 lines
Otherwise
Thanks!
Quoted 15 lines
Quoted 15 lines
include/linux/uprobes.h +6
-4@@ -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; + }; +
Quoted 8 lines
include/linux/uprobes.h enum uprobe_task_state { · line 85
Quoted 3 lines
include/linux/uprobes.h +3
-0+struct { +struct callback_head dup_work; +unsigned long dup_addr;Nit:
Can we renamedup_addrto mean that it refers to the xol; something likedup_xol_addror evenxol_addr. So that its more clear what address it refers to.
OK. How about dup_xol_work/dup_xol_vaddr ?
Oleg.
Oleg Nesterov
maintainerQuoted 9 lines · Oleg Nesterov
Quoted 5 lines · Srikar Dronamraju
Nit:
Can we renamedup_addrto mean that it refers to the xol; something likedup_xol_addror evenxol_addr. So that its more clear what address it refers to.OK. How about dup_xol_work/dup_xol_vaddr ?
I didn't notice you suggested the same naming ;) OK, will rename to dup_xol_work/addr.
Oleg.
Quoted 8 lines
Yes, and it is always equal to
regs->ipwhenpre_ssout()is called,Quoted 1 line
and do the necessary fixups after single stepping out of line.
Exactly. So it is write-only (and meaningless) to the generic uprobe code. We can (and perhaps should) move it into
autask->saved_vaddr,arch_uprobe_pre_xol()can initialize it.
Quoted 5 lines
Quoted 2 lines
The casual reading of this commit message, one can get an impression that vaddr is never needed.
See above. The changelog doesn't say we can simply remove it, it says "move it".
Okay, moving to arch_uprobe_task is fine. I probably got confused by "First of all it is not really needed,"
Quoted 6 lines
Quoted 2 lines
Your change still retains it.
OK. How about dup_xol_work/dup_xol_vaddr ?
Yes fine with me.
Signature · 2 lines
Thanks and Regards Srikar Dronamraju
Oleg Nesterov
maintainerPATCH v2 1/1 uprobes: Add uprobe_task->dup_work/dup_addr
Quoted 3 lines · Srikar Dronamraju
Okay, moving to
arch_uprobe_taskis fine. I probably got confused by "First of all it is not really needed,"
OK, this doesn't look good, I agree.
Please see v2 below, I tried to improve the changelog.
Quoted 3 lines
Quoted 1 line
OK. How about dup_xol_work/dup_xol_vaddr ?
Yes fine with me.
Done.
I added your ack optimistically, please let me know if you think I should change something else.
Oleg.
---
Subject: [PATCH] uprobes: Add uprobe_task->dup_xol_work/dup_xol_addr
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.
--- include/linux/uprobes.h | 21 ++++++++++++++++----- kernel/events/uprobes.c | 16 ++++------------ 2 files changed, 20 insertions(+), 17 deletions(-)
include/linux/uprobes.h +16 -5
@@ -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; };/*
kernel/events/uprobes.c +4 -12
@@ -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); }/*
Signature · 1 line
1.5.5.1
Quoted 9 lines · Oleg Nesterov
Quoted 3 lines · Srikar Dronamraju
Okay, moving to
arch_uprobe_taskis fine. I probably got confused by "First of all it is not really needed,"OK, this doesn't look good, I agree.
Please see v2 below, I tried to improve the changelog.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
OK. How about dup_xol_work/dup_xol_vaddr ?
Yes fine with me.
Done.
I added your ack optimistically, please let me know if you think I should change something else.
Looks nice to me.
Signature · 2 lines
Thanks and Regards Srikar Dronamraju
Ping?
Is this already pulled?
I think it is enough discussed and reviewed.
Thank you,
Quoted 148 lines · Oleg Nesterov
Quoted 3 lines · Srikar Dronamraju
Okay, moving to
arch_uprobe_taskis fine. I probably got confused by "First of all it is not really needed,"OK, this doesn't look good, I agree.
Please see v2 below, I tried to improve the changelog.
Quoted 3 lines
Quoted 1 line
OK. How about dup_xol_work/dup_xol_vaddr ?
Yes fine with me.
Done.
I added your ack optimistically, please let me know if you think I should change something else.
Oleg.
---Subject: [PATCH] uprobes: Add uprobe_task->dup_xol_work/dup_xol_addr
uprobe_task->vaddris a bit strange. The generic code uses it only to pass the additional argument toarch_uprobe_pre_xol(), and since it is always equal toinstruction_pointer()this looks even more strange.And both
utask->vaddrand andutask->autaskhave 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 inUTASK_RUNNINGstate.This all means that logically ->vaddr belongs to
arch_uprobe_taskand we should probably move it there,arch_uprobe_pre_xol()can recordinstruction_pointer()itself.OTOH, it is also used by
uprobe_copy_process()anddup_xol_work()for another purpose, this doesn't look clean and doesn't allow to move this member intoarch_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 avoidkmalloc()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 withcall_fetch()methods.Signed-off-by Oleg Nesterov <[email protected]>Reviewed-by Masami Hiramatsu <[email protected]>--- include/linux/uprobes.h | 21 ++++++++++++++++----- kernel/events/uprobes.c | 16 ++++------------ 2 files changed, 20 insertions(+), 17 deletions(-)include/linux/uprobes.h +16
-5@@ -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; };/* kernel/events/uprobes.c +4
-12@@ -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); }/*
Signature · 4 lines
Masami HIRAMATSU IT Management Research Dept. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Oleg Nesterov
maintainerQuoted 5 lines · Masami Hiramatsu
Ping?
Is this already pulled?
I think it is enough discussed and reviewed.
Yes, thanks, this is already in tip/perf/core.
Oleg.