public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next RESEND v2] libbpf: Fix expected_attach_type set when kernel not support
@ 2024-09-13 16:43 Tao Chen
  2024-09-13 20:46 ` Andrii Nakryiko
  0 siblings, 1 reply; 3+ messages in thread
From: Tao Chen @ 2024-09-13 16:43 UTC (permalink / raw)
  To: Andrii Nakryiko, Eduard Zingerman, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa
  Cc: bpf, linux-kernel, Tao Chen

The commit "5902da6d8a52" set expected_attach_type again with
filed of bpf_program after libpf_prepare_prog_load, which makes
expected_attach_type = 0 no sense when kenrel not support the
attach_type feature, so fix it.

Fixes: 5902da6d8a52 ("libbpf: Add uprobe multi link support to bpf_program__attach_usdt")
Suggested-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Tao Chen <chen.dylane@gmail.com>
---
 tools/lib/bpf/libbpf.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Change list:
- v1 -> v2:
    - restore the original initialization way suggested by Jiri

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 219facd0e66e..df2244397ba1 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -7353,7 +7353,7 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog,
 
 	/* special check for usdt to use uprobe_multi link */
 	if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK))
-		prog->expected_attach_type = BPF_TRACE_UPROBE_MULTI;
+		opts->expected_attach_type = BPF_TRACE_UPROBE_MULTI;
 
 	if ((def & SEC_ATTACH_BTF) && !prog->attach_btf_id) {
 		int btf_obj_fd = 0, btf_type_id = 0, err;
@@ -7443,6 +7443,7 @@ static int bpf_object_load_prog(struct bpf_object *obj, struct bpf_program *prog
 	load_attr.attach_btf_id = prog->attach_btf_id;
 	load_attr.kern_version = kern_version;
 	load_attr.prog_ifindex = prog->prog_ifindex;
+	load_attr.expected_attach_type = prog->expected_attach_type;
 
 	/* specify func_info/line_info only if kernel supports them */
 	if (obj->btf && btf__fd(obj->btf) >= 0 && kernel_supports(obj, FEAT_BTF_FUNC)) {
@@ -7474,9 +7475,6 @@ static int bpf_object_load_prog(struct bpf_object *obj, struct bpf_program *prog
 		insns_cnt = prog->insns_cnt;
 	}
 
-	/* allow prog_prepare_load_fn to change expected_attach_type */
-	load_attr.expected_attach_type = prog->expected_attach_type;
-
 	if (obj->gen_loader) {
 		bpf_gen__prog_load(obj->gen_loader, prog->type, prog->name,
 				   license, insns, insns_cnt, &load_attr,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next RESEND v2] libbpf: Fix expected_attach_type set when kernel not support
  2024-09-13 16:43 [PATCH bpf-next RESEND v2] libbpf: Fix expected_attach_type set when kernel not support Tao Chen
@ 2024-09-13 20:46 ` Andrii Nakryiko
  2024-09-14 14:29   ` Tao Chen
  0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2024-09-13 20:46 UTC (permalink / raw)
  To: Tao Chen
  Cc: Andrii Nakryiko, Eduard Zingerman, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, bpf,
	linux-kernel

On Fri, Sep 13, 2024 at 9:44 AM Tao Chen <chen.dylane@gmail.com> wrote:
>
> The commit "5902da6d8a52" set expected_attach_type again with
> filed of bpf_program after libpf_prepare_prog_load, which makes
> expected_attach_type = 0 no sense when kenrel not support the
> attach_type feature, so fix it.
>
> Fixes: 5902da6d8a52 ("libbpf: Add uprobe multi link support to bpf_program__attach_usdt")
> Suggested-by: Jiri Olsa <jolsa@kernel.org>
> Signed-off-by: Tao Chen <chen.dylane@gmail.com>
> ---
>  tools/lib/bpf/libbpf.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> Change list:
> - v1 -> v2:
>     - restore the original initialization way suggested by Jiri
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 219facd0e66e..df2244397ba1 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -7353,7 +7353,7 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog,
>
>         /* special check for usdt to use uprobe_multi link */
>         if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK))
> -               prog->expected_attach_type = BPF_TRACE_UPROBE_MULTI;
> +               opts->expected_attach_type = BPF_TRACE_UPROBE_MULTI;
>

Ok, took me a bit to understand what the issue is. But the above is
not quite correct, for the above case of setting
BPF_TRACE_UPROBE_MULTI we do want to record BPF_TRACE_UPROBE_MULTI in
prog->expected_attach_type, because user might want to query that
later.

So I agree with the part of the fix below, but here I think we need
*both* update opts' and prog's expected_attach_type, so we will have:

       prog->expected_attach_type = BPF_TRACE_UPROBE_MULTI;
       opts->expected_attach_type = BPF_TRACE_UPROBE_MULTI;

pw-bot: cr

>         if ((def & SEC_ATTACH_BTF) && !prog->attach_btf_id) {
>                 int btf_obj_fd = 0, btf_type_id = 0, err;
> @@ -7443,6 +7443,7 @@ static int bpf_object_load_prog(struct bpf_object *obj, struct bpf_program *prog
>         load_attr.attach_btf_id = prog->attach_btf_id;
>         load_attr.kern_version = kern_version;
>         load_attr.prog_ifindex = prog->prog_ifindex;
> +       load_attr.expected_attach_type = prog->expected_attach_type;
>
>         /* specify func_info/line_info only if kernel supports them */
>         if (obj->btf && btf__fd(obj->btf) >= 0 && kernel_supports(obj, FEAT_BTF_FUNC)) {
> @@ -7474,9 +7475,6 @@ static int bpf_object_load_prog(struct bpf_object *obj, struct bpf_program *prog
>                 insns_cnt = prog->insns_cnt;
>         }
>
> -       /* allow prog_prepare_load_fn to change expected_attach_type */
> -       load_attr.expected_attach_type = prog->expected_attach_type;
> -
>         if (obj->gen_loader) {
>                 bpf_gen__prog_load(obj->gen_loader, prog->type, prog->name,
>                                    license, insns, insns_cnt, &load_attr,
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next RESEND v2] libbpf: Fix expected_attach_type set when kernel not support
  2024-09-13 20:46 ` Andrii Nakryiko
@ 2024-09-14 14:29   ` Tao Chen
  0 siblings, 0 replies; 3+ messages in thread
From: Tao Chen @ 2024-09-14 14:29 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Andrii Nakryiko, Eduard Zingerman, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, bpf,
	linux-kernel

在 2024/9/14 04:46, Andrii Nakryiko 写道:
> On Fri, Sep 13, 2024 at 9:44 AM Tao Chen <chen.dylane@gmail.com> wrote:
>>
>> The commit "5902da6d8a52" set expected_attach_type again with
>> filed of bpf_program after libpf_prepare_prog_load, which makes
>> expected_attach_type = 0 no sense when kenrel not support the
>> attach_type feature, so fix it.
>>
>> Fixes: 5902da6d8a52 ("libbpf: Add uprobe multi link support to bpf_program__attach_usdt")
>> Suggested-by: Jiri Olsa <jolsa@kernel.org>
>> Signed-off-by: Tao Chen <chen.dylane@gmail.com>
>> ---
>>   tools/lib/bpf/libbpf.c | 6 ++----
>>   1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> Change list:
>> - v1 -> v2:
>>      - restore the original initialization way suggested by Jiri
>>
>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> index 219facd0e66e..df2244397ba1 100644
>> --- a/tools/lib/bpf/libbpf.c
>> +++ b/tools/lib/bpf/libbpf.c
>> @@ -7353,7 +7353,7 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog,
>>
>>          /* special check for usdt to use uprobe_multi link */
>>          if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK))
>> -               prog->expected_attach_type = BPF_TRACE_UPROBE_MULTI;
>> +               opts->expected_attach_type = BPF_TRACE_UPROBE_MULTI;
>>
> 
> Ok, took me a bit to understand what the issue is. But the above is
> not quite correct, for the above case of setting
> BPF_TRACE_UPROBE_MULTI we do want to record BPF_TRACE_UPROBE_MULTI in
> prog->expected_attach_type, because user might want to query that
> later.
> 
> So I agree with the part of the fix below, but here I think we need
> *both* update opts' and prog's expected_attach_type, so we will have:
> 
>         prog->expected_attach_type = BPF_TRACE_UPROBE_MULTI;
>         opts->expected_attach_type = BPF_TRACE_UPROBE_MULTI;
> 
> pw-bot: cr
> 
>>          if ((def & SEC_ATTACH_BTF) && !prog->attach_btf_id) {
>>                  int btf_obj_fd = 0, btf_type_id = 0, err;
>> @@ -7443,6 +7443,7 @@ static int bpf_object_load_prog(struct bpf_object *obj, struct bpf_program *prog
>>          load_attr.attach_btf_id = prog->attach_btf_id;
>>          load_attr.kern_version = kern_version;
>>          load_attr.prog_ifindex = prog->prog_ifindex;
>> +       load_attr.expected_attach_type = prog->expected_attach_type;
>>
>>          /* specify func_info/line_info only if kernel supports them */
>>          if (obj->btf && btf__fd(obj->btf) >= 0 && kernel_supports(obj, FEAT_BTF_FUNC)) {
>> @@ -7474,9 +7475,6 @@ static int bpf_object_load_prog(struct bpf_object *obj, struct bpf_program *prog
>>                  insns_cnt = prog->insns_cnt;
>>          }
>>
>> -       /* allow prog_prepare_load_fn to change expected_attach_type */
>> -       load_attr.expected_attach_type = prog->expected_attach_type;
>> -
>>          if (obj->gen_loader) {
>>                  bpf_gen__prog_load(obj->gen_loader, prog->type, prog->name,
>>                                     license, insns, insns_cnt, &load_attr,
>> --
>> 2.25.1
>>

Hi, Andrii, thank you for your reply. I will send v3 as you suggested.

-- 
Best Regards
Dylane Chen

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-09-14 14:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-13 16:43 [PATCH bpf-next RESEND v2] libbpf: Fix expected_attach_type set when kernel not support Tao Chen
2024-09-13 20:46 ` Andrii Nakryiko
2024-09-14 14:29   ` Tao Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox