All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v3 4/6] perf bpf-filter: Extend lock_held() to support RCU, Tasks Trace RCU, and SRCU
Date: Sun, 18 Oct 2026 05:51:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-175958@kernel.org> (raw)
In-Reply-To: <20261018053710.2572636-5-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf bpf-filter: btf_has_task_field() misses anon struct under RANDSTRUCT
--

commit 5ff446ff868169d426bb172f1b13dc459b646352
Author: Ian Rogers <irogers@google.com>

perf bpf-filter: Extend lock_held() to support RCU, Tasks Trace RCU, and SRCU

This commit extends the lock_held(<lock>) BPF sample filter to support RCU,
Tasks Trace RCU, and SRCU locks. For RCU and Tasks Trace RCU read-side
critical sections, it inspects task_struct nesting fields via CO-RE, while
attaching fentry/fexit hooks for SRCU and RCU synchronize/barrier waits.

> diff --git a/tools/perf/util/bpf-filter.c b/tools/perf/util/bpf-filter.c
> index 0c133b31b5d54..4a5ef78e26900 100644
> --- a/tools/perf/util/bpf-filter.c
> +++ b/tools/perf/util/bpf-filter.c

[ ... ]

> @@ -847,16 +913,54 @@ static bool find_slab_cache(struct sample_filter_bpf *skel, const char *name,
>  	return false;
>  }
>  
> +static u64 rcu_min_depth(struct evsel *evsel)
> +{
> +	if (evsel && evsel->core.attr.type == PERF_TYPE_SOFTWARE &&
> +	    evsel->core.attr.config != PERF_COUNT_SW_CPU_CLOCK &&
> +	    evsel->core.attr.config != PERF_COUNT_SW_TASK_CLOCK)
> +		return 2;
> +	return 1;
> +}
> +
> +static bool btf_has_task_field(struct btf *btf, const char *field_name)
> +{
> +	const struct btf_type *t;
> +	const struct btf_member *m;
> +	s32 id;
> +	u16 i, vlen;
> +
> +	if (!btf)
> +		return false;
> +
> +	id = btf__find_by_name_kind(btf, "task_struct", BTF_KIND_STRUCT);
> +	if (id < 0)
> +		return false;
> +
> +	t = btf__type_by_id(btf, id);
> +	if (!t)
> +		return false;
> +
> +	m = btf_members(t);
> +	vlen = btf_vlen(t);
> +	for (i = 0; i < vlen; i++, m++) {
> +		const char *name = btf__name_by_offset(btf, m->name_off);
> +
> +		if (name && !strcmp(name, field_name))
> +			return true;
> +	}
> +	return false;
> +}

[Severity: Medium]
In include/linux/sched.h, both rcu_read_lock_nesting and trc_reader_nesting
are declared inside the randomized_struct_fields_start /
randomized_struct_fields_end block of struct task_struct:

include/linux/sched.h:
    struct task_struct {
        ...
        randomized_struct_fields_start
        ...
    #ifdef CONFIG_PREEMPT_RCU
        int rcu_read_lock_nesting;
        ...
    #endif
    #ifdef CONFIG_TASKS_TRACE_RCU
        int trc_reader_nesting;
        ...
    #endif
        ...
        randomized_struct_fields_end
    };

When CONFIG_RANDSTRUCT is enabled, randomized_struct_fields_start wraps those
fields inside an anonymous struct member of task_struct, which appears in
vmlinux BTF as a member with m->name_off == 0 pointing to an inner
BTF_KIND_STRUCT.

While libbpf CO-RE in sample_filter.bpf.c recursively descends into anonymous
structs and unions, btf_has_task_field() only iterates over the direct
top-level members of task_struct.

Will btf_has_task_field() return false on CONFIG_RANDSTRUCT kernels, causing
resolve_lock_expr() to reject lock_held(rcu) and lock_held(rcu-trace) with
-EOPNOTSUPP?

[ ... ]

> @@ -929,6 +1033,48 @@ static int resolve_lock_expr(struct sample_filter_bpf *skel,
>  		return 0;
>  	}
>  
> +	if (!strcmp(base, "rcu_read_lock")) {
> +		if (mode == PBF_LOCK_MODE_WRITE) {
> +			pr_err("Error: Lock '%s' only supports read/shared mode\n", name);
> +			return -EINVAL;
> +		}
> +		if (btf && !btf_has_task_field(btf, "rcu_read_lock_nesting")) {
> +			pr_err("Error: lock_held(rcu) requires CONFIG_PREEMPT_RCU\n");
> +			return -EOPNOTSUPP;
> +		}
> +		entry->part = PBF_LOCK_RCU | PBF_LOCK_MODE_READ;
> +		entry->target = rcu_min_depth(evsel);
> +		return 0;
> +	}

[ ... ]

—
🤖 Generated by Linux Kernel Patch Reviewer (Model: gemini-3.1-pro-preview)

 Prompts used:
 - bpf.md (https://raw.githubusercontent.com/masoncl/review-prompts/main/bpf.md)
 - btf.md (https://raw.githubusercontent.com/masoncl/review-prompts/main/btf.md)
 - inline-template.md (https://raw.githubusercontent.com/masoncl/review-prompts/main/inline-template.md)
 - libbpf.md (https://raw.githubusercontent.com/masoncl/review-prompts/main/libbpf.md)
 - perf.md (https://raw.githubusercontent.com/masoncl/review-prompts/main/perf.md)
 - rcu.md (https://raw.githubusercontent.com/masoncl/review-prompts/main/rcu.md)
 - tracing.md (https://raw.githubusercontent.com/masoncl/review-prompts/main/tracing.md)

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261018053710.2572636-1-irogers@google.com?part=4

  reply	other threads:[~2026-10-18  5:51 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-17  5:45 [PATCH v1 0/5] perf bpf-filter / lock contention: Add lock_held() sample filter and RCU/SRCU support Ian Rogers
2026-10-17  5:45 ` [PATCH v1 1/5] perf lock contention: Share common BPF and lock type definitions in lock_data.h Ian Rogers
2026-10-17  5:52   ` sashiko-bot
2026-10-17  5:45 ` [PATCH v1 2/5] perf bpf-filter: Add lock_held() sample filter Ian Rogers
2026-10-17  6:09   ` sashiko-bot
2026-10-17  5:45 ` [PATCH v1 3/5] perf test: Add tests for lock_held() BPF " Ian Rogers
2026-10-17  5:49   ` sashiko-bot
2026-10-17  5:45 ` [PATCH v1 4/5] perf bpf-filter: Extend lock_held() to support RCU, Tasks Trace RCU, and SRCU Ian Rogers
2026-10-17  5:56   ` sashiko-bot
2026-10-17  5:45 ` [PATCH v1 5/5] perf lock contention: Extend BPF lock contention to RCU " Ian Rogers
2026-10-17  6:08   ` sashiko-bot
2026-10-17 17:14 ` [PATCH v2 0/6] perf bpf-filter / lock contention: Add lock_held() sample filter and RCU/SRCU support Ian Rogers
2026-10-17 17:14   ` [PATCH v2 1/6] perf lock contention: Share common BPF and lock type definitions in lock_data.h Ian Rogers
2026-10-17 17:31     ` sashiko-bot
2026-10-17 17:14   ` [PATCH v2 2/6] perf bpf-filter: Add lock_held() sample filter Ian Rogers
2026-10-17 17:35     ` sashiko-bot
2026-10-17 17:14   ` [PATCH v2 3/6] perf test: Add tests for lock_held() BPF " Ian Rogers
2026-10-17 17:17     ` sashiko-bot
2026-10-17 17:14   ` [PATCH v2 4/6] perf bpf-filter: Extend lock_held() to support RCU, Tasks Trace RCU, and SRCU Ian Rogers
2026-10-17 17:25     ` sashiko-bot
2026-10-17 17:14   ` [PATCH v2 5/6] perf lock contention: Extend BPF lock contention to RCU " Ian Rogers
2026-10-17 17:30     ` sashiko-bot
2026-10-17 17:14   ` [PATCH v2 6/6] perf lock contention: Filter events before creating lock_stat Ian Rogers
2026-10-17 17:17     ` sashiko-bot
2026-10-18  5:37   ` [PATCH v3 0/6] perf bpf-filter / lock contention: Add lock_held() sample filter and RCU/SRCU support Ian Rogers
2026-10-18  5:37     ` [PATCH v3 1/6] perf lock contention: Share common BPF and lock type definitions in lock_data.h Ian Rogers
2026-10-18  5:50       ` sashiko-bot
2026-10-18  5:37     ` [PATCH v3 2/6] perf bpf-filter: Add lock_held() sample filter Ian Rogers
2026-10-18  6:12       ` sashiko-bot
2026-10-18  5:37     ` [PATCH v3 3/6] perf test: Add tests for lock_held() BPF " Ian Rogers
2026-10-18  5:41       ` sashiko-bot
2026-10-18  5:37     ` [PATCH v3 4/6] perf bpf-filter: Extend lock_held() to support RCU, Tasks Trace RCU, and SRCU Ian Rogers
2026-10-18  5:51       ` sashiko-bot [this message]
2026-10-18  5:37     ` [PATCH v3 5/6] perf lock contention: Extend BPF lock contention to RCU " Ian Rogers
2026-10-18  5:48       ` sashiko-bot
2026-10-18  5:37     ` [PATCH v3 6/6] perf lock contention: Filter events before creating lock_stat Ian Rogers
2026-10-18  5:40       ` sashiko-bot

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=sashiko-outbox-175958@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=irogers@google.com \
    --cc=linux-perf-users@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.