Re: [PATCH v5 1/9] ftrace: Add ftrace_set_filter_ips function

Jiri Olsa
2022-01-25T16:51:09Z

On Tue, Jan 25, 2022 at 11:06:59AM -0500, Steven Rostedt wrote:

SNIP

> > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> > index be5f6b32a012..39350aa38649 100644
> > --- a/kernel/trace/ftrace.c
> > +++ b/kernel/trace/ftrace.c
> > @@ -4958,7 +4958,7 @@ ftrace_notrace_write(struct file *file, const char __user *ubuf,
> > }
> >
> > static int
> > -ftrace_match_addr(struct ftrace_hash *hash, unsigned long ip, int remove)
> > +__ftrace_match_addr(struct ftrace_hash *hash, unsigned long ip, int remove)
> > {
> > struct ftrace_func_entry *entry;
> >
> > @@ -4976,9 +4976,25 @@ ftrace_match_addr(struct ftrace_hash *hash, unsigned long ip, int remove)
> > return add_hash_entry(hash, ip);
> > }
> >
> > +static int
> > +ftrace_match_addr(struct ftrace_hash *hash, unsigned long *ips,
> > + unsigned int cnt, int remove)
> > +{
> > + unsigned int i;
> > + int err;
> > +
> > + for (i = 0; i < cnt; i++) {
> > + err = __ftrace_match_addr(hash, ips[i], remove);
> > + if (err)
> > + return err;
>
> On error should we revert what was done?
>
> goto err;
> > + }
> > + return 0;
>
> err:
> for (i--; i >= 0; i--)
> __ftrace_match_addr(hash, ips[i], !remove);
> return err;
>
> Although it may not matter as it looks like it is only used on a temporary
> hash. But either it should be commented that is the case, or we do the above
> just to be more robust.

yes, that's the case.. it populates just the hash at this point
and if __ftrace_match_addr fails, the thehash is relased after
jumping to out_regex_unlock

>
> > +}
> > +
> > static int
> > ftrace_set_hash(struct ftrace_ops *ops, unsigned char *buf, int len,
> > - unsigned long ip, int remove, int reset, int enable)
> > + unsigned long *ips, unsigned int cnt,
> > + int remove, int reset, int enable)
> > {
> > struct ftrace_hash **orig_hash;
> > struct ftrace_hash *hash;
> > @@ -5008,8 +5024,8 @@ ftrace_set_hash(struct ftrace_ops *ops, unsigned char *buf, int len,
> > ret = -EINVAL;
> > goto out_regex_unlock;
> > }
> > - if (ip) {
> > - ret = ftrace_match_addr(hash, ip, remove);
> > + if (ips) {
> > + ret = ftrace_match_addr(hash, ips, cnt, remove);
> > if (ret < 0)
> > goto out_regex_unlock;
> > }
> > @@ -5026,10 +5042,10 @@ ftrace_set_hash(struct ftrace_ops *ops, unsigned char *buf, int len,
> > }
> >
> > static int
> > -ftrace_set_addr(struct ftrace_ops *ops, unsigned long ip, int remove,
> > - int reset, int enable)
> > +ftrace_set_addr(struct ftrace_ops *ops, unsigned long *ips, unsigned int cnt,
> > + int remove, int reset, int enable)
> > {
> > - return ftrace_set_hash(ops, NULL, 0, ip, remove, reset, enable);
> > + return ftrace_set_hash(ops, NULL, 0, ips, cnt, remove, reset, enable);
> > }
> >
> > #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
> > @@ -5634,10 +5650,29 @@ int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip,
> > int remove, int reset)
> > {
> > ftrace_ops_init(ops);
> > - return ftrace_set_addr(ops, ip, remove, reset, 1);
> > + return ftrace_set_addr(ops, &ip, 1, remove, reset, 1);
> > }
> > EXPORT_SYMBOL_GPL(ftrace_set_filter_ip);
> >
> > +/**
> > + * ftrace_set_filter_ips - set a functions to filter on in ftrace by addresses
>
> - set functions to filter on ...

will fix,

thanks,
jirka