Skip to content

Commit 35d13f8

Browse files
committed
perf bpf-filter: Fix a parsing error with comma
The previous change to support cgroup filters introduced a bug that pathname can include commas. It confused the lexer to treat an item and the trailing comma as a single token. And it resulted in a parse error: $ sudo perf record -e cycles:P --filter 'period > 0, ip > 64' -- true perf_bpf_filter: Error: Unexpected item: 0, perf_bpf_filter: syntax error, unexpected BFT_ERROR, expecting BFT_NUM Usage: perf record [<options>] [<command>] or: perf record [<options>] -- <command> [<options>] --filter <filter> event filter It should get "0" and "," separately. An easiest fix would be to remove "," from the possible pathname characters. As it's for cgroup names, probably ok to assume it won't have commas in the pathname. I found that the existing BPF filtering test didn't have any complex filter condition with commas. Let's update the group filter test which is supposed to test filter combinations like this. Link: https://lore.kernel.org/r/20250307220922.434319-1-namhyung@kernel.org Fixes: 91e8843 ("perf bpf-filter: Support filtering on cgroups") Reported-by: Sally Shi <sshii@google.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
1 parent 9daa05c commit 35d13f8

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

tools/perf/tests/shell/record_bpf_filter.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ test_bpf_filter_fail() {
8989
test_bpf_filter_group() {
9090
echo "Group bpf-filter test"
9191

92-
if ! perf record -e task-clock --filter 'period > 1000 || ip > 0' \
92+
if ! perf record -e task-clock --filter 'period > 1000, ip > 0' \
9393
-o /dev/null true 2>/dev/null
9494
then
9595
echo "Group bpf-filter test [Failed should succeed]"
9696
err=1
9797
return
9898
fi
9999

100-
if ! perf record -e task-clock --filter 'cpu > 0 || ip > 0' \
100+
if ! perf record -e task-clock --filter 'period > 1000 , cpu > 0 || ip > 0' \
101101
-o /dev/null true 2>&1 | grep -q PERF_SAMPLE_CPU
102102
then
103103
echo "Group bpf-filter test [Failed forbidden CPU]"

tools/perf/util/bpf-filter.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static int path_or_error(void)
7676
num_dec [0-9]+
7777
num_hex 0[Xx][0-9a-fA-F]+
7878
space [ \t]+
79-
path [^ \t\n]+
79+
path [^ \t\n,]+
8080
ident [_a-zA-Z][_a-zA-Z0-9]+
8181

8282
%%

0 commit comments

Comments
 (0)