Linux Trace Kernel
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Leon Hwang <leon.hwang@linux.dev>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	Quentin Monnet <qmo@kernel.org>, Shuah Khan <shuah@kernel.org>,
	Mykyta Yatsenko <yatsenko@meta.com>,
	Avinash Duduskar <avinash.duduskar@gmail.com>,
	Anton Protopopov <a.s.protopopov@gmail.com>,
	Amery Hung <ameryhung@gmail.com>, Jordan Rife <jordan@jrife.io>,
	Rong Tao <rongtao@cestc.cn>, Eyal Birger <eyal.birger@gmail.com>,
	Pu Lehui <pulehui@huawei.com>,
	Jingguo Tan <tanjingguo@huawei.com>, Lin Ma <malin89@huawei.com>,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 11/21] bpf: Add tracing_multi link support for bpf progs
Date: Wed, 14 Oct 2026 23:45:07 +0200	[thread overview]
Message-ID: <as_349cckxgUQM2U@krava> (raw)
In-Reply-To: <20261012154024.29423-12-leon.hwang@linux.dev>

On Mon, Oct 12, 2026 at 11:40:13PM +0800, Leon Hwang wrote:

SNIP

> @@ -3787,64 +3796,129 @@ static const struct bpf_link_ops bpf_tracing_multi_link_lops = {
>  #endif
>  };
>  
> -static int ids_cmp_r(const void *pa, const void *pb, const void *priv __maybe_unused)
> +struct tracing_multi_sort_data {
> +	u64 *keys;
> +	struct bpf_prog **progs;
> +	u32 *ids;
> +	u64 *cookies;
> +};
> +
> +static int keys_cmp_r(const void *pa, const void *pb, const void *priv __maybe_unused)
>  {
> -	u32 a = *(u32 *) pa;
> -	u32 b = *(u32 *) pb;

I think you could just s/32/64/ and keep the rest in here and have simpler diff

> +	const u64 *key_a = pa, *key_b = pb;
>  
> -	return (a > b) - (a < b);
> +	return (*key_a > *key_b) - (*key_a < *key_b);
>  }
>  
> -static void ids_swap_r(void *a, void *b, int size __maybe_unused,
> -		       const void *priv __maybe_unused)
> +static void keys_swap_r(void *a, void *b, int size __maybe_unused,
> +			const void *priv __maybe_unused)
>  {
> +	const struct tracing_multi_sort_data *data = priv;
> +	struct bpf_prog **prog_a, **prog_b;
>  	u64 *cookie_a, *cookie_b, *cookies;
> -	u32 *id_a = a, *id_b = b, *ids;
> -	void **data = (void **) priv;
> +	u64 *key_a = a, *key_b = b, *keys;
> +	u32 *id_a, *id_b, *ids;
> +
> +	keys    = data->keys;
> +	ids     = data->ids;
> +	cookies = data->cookies;
> +	id_a    = ids + (key_a - keys);
> +	id_b    = ids + (key_b - keys);
>  
> -	ids     = data[0];
> -	cookies = data[1];
> +	if (data->progs) {

nit, let's unify with the rest of the code and have progs variable for data->progs ?

SNIP

> -	err = check_dup_ids(ids, cookies, cnt);
> +	keys = kvmalloc_objs(*keys, cnt);
> +	if (!keys) {
> +		err = -ENOMEM;
> +		goto error;
> +	}
> +
> +	for (int i = 0; i < cnt; i++)
> +		keys[i] = bpf_trampoline_compute_key(progs ? progs[i] : NULL, btf, ids[i]);
> +
> +	err = check_dup_keys(keys, progs, ids, cookies, cnt);
>  	if (err)
>  		goto error;
>  
> @@ -3908,19 +4022,32 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
>  	link->nodes_cnt = cnt;
>  	link->cookies = cookies;
>  	link->fexits = fexits;
> +	link->tgt_progs = progs;
> +	link->pokes = pokes;
>  
> -	err = bpf_trampoline_multi_attach(prog, ids, link);
> +	if (progs)
> +		err = bpf_trampoline_multi_prog_attach(prog, ids, keys, link);

you need keys computed ahead for dups check, so let's the above
bpf_trampoline_compute_key calls be the single place we compute keys
and pass keys to bpf_trampoline_multi_attach below as well?

> +	else
> +		err = bpf_trampoline_multi_attach(prog, ids, link);

nit, let's add empty line in here?

>  	kvfree(ids);
> +	kvfree(keys);
> +	kvfree(fds);
>  	if (err) {
> +		bpf_put_progs(progs, cnt);
>  		bpf_link_cleanup(&link_primer);
>  		return err;
>  	}
>  	return bpf_link_settle(&link_primer);

thanks,
jirka

  parent reply	other threads:[~2026-10-14 21:45 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 15:40 [PATCH bpf-next v2 00/21] bpf: Add tracing_multi link support for bpf progs Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 01/21] bpf: Initialize ftrace_managed in bpf_trampoline_get() Leon Hwang
2026-10-14 21:43   ` Jiri Olsa
2026-10-12 15:40 ` [PATCH bpf-next v2 02/21] bpf: Drop unnecessary ftrace_location() in register/unregister/modify_fentry_multi() Leon Hwang
2026-10-14 21:43   ` Jiri Olsa
2026-10-12 15:40 ` [PATCH bpf-next v2 03/21] bpf, x86: Factor out bpf_arch_text_poke_prepare_insns() helper on x86_64 Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 04/21] bpf, x86: Factor out bpf_arch_text_poke_check_ip() " Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 05/21] bpf, x86: Introduce bpf_arch_text_poke_batch() " Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 06/21] bpf: Add bpf_text_poke_batch() helper in trampoline Leon Hwang
2026-10-12 16:11   ` bot+bpf-ci
2026-10-12 15:40 ` [PATCH bpf-next v2 07/21] bpf: Check tgt_prog before is_tracing_multi_id() in verifier Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 08/21] bpf: Move helpers out of CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS guard in trampoline Leon Hwang
2026-10-12 16:11   ` bot+bpf-ci
2026-10-12 15:40 ` [PATCH bpf-next v2 09/21] bpf: Add bpf_trampoline_multi_prog_attach/detach() Leon Hwang
2026-10-12 16:16   ` sashiko-bot
2026-10-12 16:33   ` bot+bpf-ci
2026-10-14 21:43   ` Jiri Olsa
2026-10-12 15:40 ` [PATCH bpf-next v2 10/21] bpf: Shrink CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS guard scope for bpf_tracing_multi_attach() Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 11/21] bpf: Add tracing_multi link support for bpf progs Leon Hwang
2026-10-12 16:33   ` bot+bpf-ci
2026-10-14 21:45   ` Jiri Olsa [this message]
2026-10-12 15:40 ` [PATCH bpf-next v2 12/21] libbpf: " Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 13/21] bpf: Add tracing_multi link fdinfo " Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 14/21] bpf: Add tracing_multi link info " Leon Hwang
2026-10-12 16:33   ` bot+bpf-ci
2026-10-12 16:36   ` sashiko-bot
2026-10-14 21:43   ` Jiri Olsa
2026-10-15  0:24   ` kernel test robot
2026-10-12 15:40 ` [PATCH bpf-next v2 15/21] selftests/bpf: Add tracing_multi bpf prog attach test Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 16/21] selftests/bpf: Add tracing_multi bpf prog attach failure tests Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 17/21] selftests/bpf: Add tracing_multi bpf prog cookie test Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 18/21] selftests/bpf: Add tracing_multi bpf prog rollback test Leon Hwang
2026-10-12 16:46   ` sashiko-bot
2026-10-14 21:44   ` Jiri Olsa
2026-10-12 15:40 ` [PATCH bpf-next v2 19/21] selftests/bpf: Add tracing_multi bpf prog link info test Leon Hwang
2026-10-12 16:11   ` bot+bpf-ci
2026-10-12 16:43   ` sashiko-bot
2026-10-12 15:40 ` [PATCH bpf-next v2 20/21] selftests/bpf: Test tailcall with fentry.multi Leon Hwang
2026-10-12 15:40 ` [PATCH bpf-next v2 21/21] selftests/bpf: Benchmark tracing_multi bpf progs attachment Leon Hwang
2026-10-12 16:33   ` bot+bpf-ci
2026-10-12 16:52   ` sashiko-bot
2026-10-14 21:59 ` [PATCH bpf-next v2 00/21] bpf: Add tracing_multi link support for bpf progs Jiri Olsa
2026-10-15  1:48   ` Leon Hwang

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=as_349cckxgUQM2U@krava \
    --to=olsajiri@gmail.com \
    --cc=a.s.protopopov@gmail.com \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=avinash.duduskar@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=eyal.birger@gmail.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jordan@jrife.io \
    --cc=leon.hwang@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=malin89@huawei.com \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=pulehui@huawei.com \
    --cc=qmo@kernel.org \
    --cc=rongtao@cestc.cn \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=tanjingguo@huawei.com \
    --cc=yatsenko@meta.com \
    --cc=yonghong.song@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