BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alan Maguire" <almagui@kernel.org>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 2/7] bpf: Support CO-RE relocation of tracing program arguments
Date: Mon, 23 Nov 2026 22:52:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-230161@kernel.org> (raw)
In-Reply-To: <20261123223227.745345-3-almagui@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] bpf: quadratic BTF type scan in bpf_core_apply() via
  bpf_core_is_func_args_type()
- [Low] bpf: non-standard multi-line comment above
  bpf_core_func_args_cand_prog()
--

commit fb7674aa7cef4ed7e344622061c7c9391f5b51c3
Author: Alan Maguire <almagui@kernel.org>

bpf: Support CO-RE relocation of tracing program arguments

This commit passes the BPF program being loaded to bpf_core_apply() so
that CO-RE relocations against function argument structs can be resolved
against the program's attach target.

> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index c4386a9a1ad41..f93ed8908d655 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -10709,11 +10709,39 @@ bpf_core_find_cands(struct bpf_core_ctx *ctx, u32 local_type_id)
>  	return populate_cand_cache(cands, module_cand_cache, MODULE_CAND_CACHE_SIZE);
>  }
>  
> +/* Function argument structs (see __bpf_func_args in libbpf's bpf_tracing.h)
> + * are matched against the parameters of the program's attach target.
> + */

[Severity: Low]
This isn't a bug, but BPF coding style puts the opening /* of a
multi-line comment on its own line.

[ ... ]

> @@ -10734,6 +10762,16 @@ int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo,
>  		return -EINVAL;
>  	}
>  
> +	if (need_cands && ctx->prog && bpf_core_is_func_args_type(ctx->btf, relo->type_id)) {
> +		/* no locking needed, prog holds a reference to attach_btf */
> +		need_cands = false;
> +		err = bpf_core_func_args_cand_prog(ctx, relo_idx, &func_args_cand);
> +		if (err)
> +			goto out;
> +		cands.cands = &func_args_cand;
> +		cands.len = 1;
> +	}

[Severity: Medium]
Does calling bpf_core_is_func_args_type() here introduce a quadratic scan
of ctx->btf across CO-RE relocations?

bpf_check_core_relo() sets ctx.prog for all program types, so
bpf_core_apply() now runs bpf_core_is_func_args_type() on every relocation
where relo->kind != BPF_CORE_TYPE_ID_LOCAL before consulting
vmlinux_cand_cache:

tools/lib/bpf/relo_core.c:bpf_core_is_func_args_type() {
    ...
	n = btf__type_cnt(btf);
	for (i = 1; i < n; i++) {
		t = btf_type_by_id(btf, i);
		if (btf_kind(t) == BTF_KIND_DECL_TAG && t->type == type_id &&
		    strcmp(btf__name_by_offset(btf, t->name_off), BPF_CORE_FUNC_ARGS_TAG) == 0)
			return true;
	}
    ...
}

Unlike libbpf's bpf_core_resolve_relo(), which checks its candidate cache
by local type ID before calling bpf_core_is_func_args_type(), this scans
all types in the program's BTF on every relocation (and btf_has_decl_tag()
does the same per matched argument), turning in-kernel CO-RE relocation
into O(nr_core_relo * btf_nr_types(ctx->btf)).  In the kernel, program BTFs
already pre-link decl tags in btf->next_tag via d01bec4218c7 ("bpf: Link
the decl tags of a type"), so walking that chain (or using
btf_find_decl_tag_value()) would keep tag lookups O(1).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123223227.745345-1-almagui@kernel.org?part=2

  reply	other threads:[~2026-11-23 22:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 22:32 [PATCH bpf-next 0/7] libbpf, bpf: Utilize CO-RE for BPF program parameter presence, ordering Alan Maguire
2026-11-23 22:32 ` [PATCH bpf-next 1/7] libbpf: Support CO-RE relocation of tracing program arguments Alan Maguire
2026-11-23 22:53   ` sashiko-bot
2026-11-23 22:32 ` [PATCH bpf-next 2/7] bpf: " Alan Maguire
2026-11-23 22:52   ` sashiko-bot [this message]
2026-11-23 22:32 ` [PATCH bpf-next 3/7] selftests/bpf: Test " Alan Maguire
2026-11-23 22:43   ` sashiko-bot
2026-11-23 22:32 ` [PATCH bpf-next 4/7] selftests/bpf: Test CO-RE relocation of BPF LSM " Alan Maguire
2026-11-23 22:41   ` sashiko-bot
2026-11-23 22:32 ` [PATCH bpf-next 5/7] libbpf: Report function argument relocation support via type existence Alan Maguire
2026-11-23 22:38   ` sashiko-bot
2026-11-23 22:32 ` [PATCH bpf-next 6/7] selftests/bpf: Test detection of function argument relocation support Alan Maguire
2026-11-23 22:36   ` sashiko-bot
2026-11-23 22:32 ` [PATCH bpf-next 7/7] Documentation/bpf: Describe CO-RE relocation of function arguments Alan Maguire

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-230161@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=almagui@kernel.org \
    --cc=bpf@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox