Re: [PATCH v6 32/36] fprobe: Rewrite fprobe on function-graph tracer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 25 Jan 2024 16:11:51 +0100
Jiri Olsa <olsajiri@xxxxxxxxx> wrote:

> On Fri, Jan 12, 2024 at 07:17:06PM +0900, Masami Hiramatsu (Google) wrote:
> 
> SNIP
> 
> >   * Register @fp to ftrace for enabling the probe on the address given by @addrs.
> > @@ -298,23 +547,27 @@ EXPORT_SYMBOL_GPL(register_fprobe);
> >   */
> >  int register_fprobe_ips(struct fprobe *fp, unsigned long *addrs, int num)
> >  {
> > -	int ret;
> > -
> > -	if (!fp || !addrs || num <= 0)
> > -		return -EINVAL;
> > -
> > -	fprobe_init(fp);
> > +	struct fprobe_hlist *hlist_array;
> > +	int ret, i;
> >  
> > -	ret = ftrace_set_filter_ips(&fp->ops, addrs, num, 0, 0);
> > +	ret = fprobe_init(fp, addrs, num);
> >  	if (ret)
> >  		return ret;
> >  
> > -	ret = fprobe_init_rethook(fp, num);
> > -	if (!ret)
> > -		ret = register_ftrace_function(&fp->ops);
> > +	mutex_lock(&fprobe_mutex);
> > +
> > +	hlist_array = fp->hlist_array;
> > +	ret = fprobe_graph_add_ips(addrs, num);
> 
> so fprobe_graph_add_ips registers the ftrace_ops and actually starts
> the tracing.. and in the code below we prepare fprobe data that is
> checked in the ftrace_ops callback.. should we do this this earlier
> before calling fprobe_graph_add_ips/register_ftrace_graph?

Good catch! but I think this is safe because fprobe_entry() checks
the fprobe_ip_table[] (insert_fprobe_node updates it) at first.
Thus until the hash table is updated, fprobe_entry() handler will
return soon.

----
static int fprobe_entry(unsigned long func, unsigned long ret_ip,
                        struct ftrace_regs *fregs, struct fgraph_ops *gops)
{
        struct fprobe_hlist_node *node, *first;
        unsigned long *fgraph_data = NULL;
        unsigned long header;
        int reserved_words;
        struct fprobe *fp;
        int used, ret;

        if (WARN_ON_ONCE(!fregs))
                return 0;

        first = node = find_first_fprobe_node(func);
        if (unlikely(!first))
                return 0;
----

The fprobe_table (add_fprobe_hash updates it) is used for return handler,
that will be used by fprobe_return().

So I think it should be safe too. Or I might missed something?

Thank you,


> 
> jirka
> 
> > +	if (!ret) {
> > +		add_fprobe_hash(fp);
> > +		for (i = 0; i < hlist_array->size; i++)
> > +			insert_fprobe_node(&hlist_array->array[i]);
> > +	}
> > +	mutex_unlock(&fprobe_mutex);
> >  
> >  	if (ret)
> >  		fprobe_fail_cleanup(fp);
> > +
> >  	return ret;
> >  }
> >  EXPORT_SYMBOL_GPL(register_fprobe_ips);
> > @@ -352,14 +605,13 @@ EXPORT_SYMBOL_GPL(register_fprobe_syms);
> 
> SNIP


-- 
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux