Linux Trace Kernel
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Chen Jun <chenjun102@huawei.com>
Cc: <mhiramat@kernel.org>, <mathieu.desnoyers@efficios.com>,
	<linux-kernel@vger.kernel.org>,
	<linux-trace-kernel@vger.kernel.org>,
	"sashiko-bot@kernel.org" <sashiko-bot@kernel.org>,
	"sashiko-reviews@lists.linux.dev"
	<sashiko-reviews@lists.linux.dev>
Subject: Re: [PATCH] tracing: Add "within" filter for call-stack-based event filtering
Date: Tue, 7 Jul 2026 11:20:11 -0400	[thread overview]
Message-ID: <20260707112011.7ca6f721@gandalf.local.home> (raw)
In-Reply-To: <20260608145556.94931-1-chenjun102@huawei.com>

From: https://sashiko.dev/#/patchset/20260608145556.94931-1-chenjun102%40huawei.com

> commit dfbe6e67884d4ff73b44c46b51995f1945758a89
> Author: Chen Jun <chenjun102@huawei.com>
> tracing: Add "within" filter for call-stack-based event filtering
> This commit introduces a "within" filter predicate for trace events, allowing
> users to filter events based on whether a specific function appears in the
> current call stack. It uses kallsyms_lookup_name() to resolve the function to
> an address range during setup, and stack_trace_save() to capture the stack at
> runtime to evaluate the filter condition.
>
> > diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
> > index 609325f579427..34e1a7f0b3cd0 100644
> > --- a/kernel/trace/trace_events_filter.c
> > +++ b/kernel/trace/trace_events_filter.c
> [ ... ]
> > @@ -1009,6 +1010,22 @@ static int filter_pred_function(struct filter_pred *pred, void *event)
> >  	return pred->op == OP_EQ ? ret : !ret;
> >  }
> >  
> > +/* Filter predicate for within. */
> > +static int filter_pred_within(struct filter_pred *pred, void *event)
> > +{
> > +#ifdef CONFIG_STACKTRACE
> > +	unsigned long entries[16];
> > +	unsigned int nr_entries;
> > +	int i;
> > +
> > +	nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
>
> Is an array size of 16 entries sufficient here?  Since the skipnr parameter is
> 0, several of these frames will be consumed by internal tracing and filter
> evaluation functions (such as filter_pred_within() and
> trace_event_buffer_commit()).
>
> This leaves very few slots for the actual call chain, meaning higher-level
> functions like "vfs_read" will likely be truncated from the stack trace.
> Could this cause the filter condition to evaluate to false incorrectly,
> missing the events we are trying to capture?
>

This is a current limitation that may be dealt with in the future.

> > +	for (i = 0; i < nr_entries; i++)
> > +		if (pred->val <= entries[i] && entries[i] < pred->val2)
> > +			return !pred->not;
> > +#endif
> > +	return pred->not;
> > +}
>
> [ ... ]
> > @@ -2002,10 +2021,28 @@ static int parse_pred(const char *str, void *data,
> >  
> >  		} else if (field->filter_type == FILTER_DYN_STRING) {
> >  			pred->fn_num = FILTER_PRED_FN_STRLOC;
> > -		} else if (field->filter_type == FILTER_RDYN_STRING)
> > +		} else if (field->filter_type == FILTER_RDYN_STRING) {
> >  			pred->fn_num = FILTER_PRED_FN_STRRELLOC;
> > -		else {
> > +		} else if (field->filter_type == FILTER_WITHIN) {
> > +			unsigned long func;
> > +
> > +			if (op == OP_GLOB)
> > +				goto err_free;
>
> Does this goto need a preceding call to parse_error()?  Other error paths in
> this function initialize the error state before jumping to err_free.
> Without it, users might see an unhelpful generic error message instead of a
> syntax error indicating that the glob operator isn't supported here.

This is a legitimate issue.

Chen, can you send a v2 and add a proper error message here?

Thanks,

-- Steve


> > +
> > +			pred->fn_num = FILTER_PRED_FN_WITHIN;
> > +			func = kallsyms_lookup_name(pred->regex->pattern);

      reply	other threads:[~2026-07-07 15:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-08 14:55 [PATCH] tracing: Add "within" filter for call-stack-based event filtering Chen Jun
2026-07-07 15:20 ` Steven Rostedt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260707112011.7ca6f721@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=chenjun102@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=sashiko-bot@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox