Re: [PATCH] fgraph: Convert ret_stack tasklist scanning to rcu
From: Oleg Nesterov
Date: Sat Sep 19 2020 - 07:25:53 EST
On 09/18, Steven Rostedt wrote:
> On Mon, 7 Sep 2020 13:43:02 +0200
> Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> > Afaics, with or without this change alloc_retstack_tasklist() can race
> > with copy_process() and miss the new child; ftrace_graph_init_task()
> > can't help, ftrace_graph_active can be set right after the check and
> > for_each_process_thread() can't see the new process yet.
> There's a call in copy_process(): ftrace_graph_init_task() that initializes
> a new tasks ret_stack,
Only if ftrace_graph_active != 0.
register_ftrace_graph() can increment ftrace_graph_active and call
alloc_retstack_tasklist() right after ftrace_graph_init_task() checks
> and this loop will ignore it
and this loop won't see it unless the forking process finishes copy_process()
and does list_add_tail_rcu(&p->tasks, &init_task.tasks) which makes it
visible to for_each_process(). Yes, this is very unlikely.
> > Looks like, ftrace_graph_exit_task() was called by the exiting task
> > in the past? Indeed, see 65afa5e603d50 ("tracing/function-return-tracer:
> > free the return stack on free_task()"). I think it makes sense to
> > simplify this function now, it can simply do kfree(t->ret_stack) and
> > nothing more.
> Ah, yeah, then you are right. If it can't be called on a running task then
> it can be simplified. Probably need a:
> just to make sure this never happens.
Well, ftrace_graph_exit_task(t) is called by free_task(t), right before
> > ACK, but ...
> > > @@ -387,8 +387,8 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
> > > }
> > > }
> > >
> > > - read_lock(&tasklist_lock);
> > then you should probably rename alloc_retstack_tasklist() ?
> tasklist, process thead? Is there a difference?
Aah, please ignore. Somehow I misinterpreted the _tasklist suffix, as if it
refers to tasklist_lock.