diff mbox series

[bpf-next,v3] libbpf: Fix expected_attach_type set when kernel not support

Message ID 20240914154040.276933-1-chen.dylane@gmail.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next,v3] libbpf: Fix expected_attach_type set when kernel not support | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/build_tools success Errors and warnings before: 4 this patch: 4
netdev/cc_maintainers fail 1 blamed authors not CCed: ast@kernel.org; 1 maintainers not CCed: ast@kernel.org
netdev/build_clang success Errors and warnings before: 7 this patch: 7
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch warning WARNING: line length of 85 exceeds 80 columns WARNING: line length of 89 exceeds 80 columns WARNING: line length of 91 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-17 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-18 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-7 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-8 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-11 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-15 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-13 success Logs for set-matrix

Commit Message

Tao Chen Sept. 14, 2024, 3:40 p.m. UTC
The commit "5902da6d8a52" set expected_attach_type again with
field 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 | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Change list:
- v2 -> v3:
    - update BPF_TRACE_UPROBE_MULTI both in prog and opts suggedted by
      Andrri
- v1 -> v2:
    - restore the original initialization way suggested by Jiri

Comments

Tao Chen Sept. 19, 2024, 2:05 a.m. UTC | #1
在 2024/9/14 23:40, Tao Chen 写道:
> The commit "5902da6d8a52" set expected_attach_type again with
> field 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 | 12 ++++++++----
>   1 file changed, 8 insertions(+), 4 deletions(-)
> 
> Change list:
> - v2 -> v3:
>      - update BPF_TRACE_UPROBE_MULTI both in prog and opts suggedted by
>        Andrri
> - 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..a78e24ff354b 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -7352,8 +7352,14 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog,
>   		opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
>   
>   	/* special check for usdt to use uprobe_multi link */
> -	if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK))
> +	if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK)) {
> +		/* for BPF_TRACE_KPROBE_MULTI, user might want to query exected_attach_type
> +		 * in prog, and expected_attach_type we set in kenrel is from opts, so we
> +		 * update both.
> +		 */
>   		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 +7449,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 +7481,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,

Hi, guys, please review this patch again, the previous versions:
v1:
https://lore.kernel.org/bpf/20240913121627.153898-1-chen.dylane@gmail.com/
v2:
https://lore.kernel.org/bpf/20240913164355.176021-1-chen.dylane@gmail.com/
Andrii Nakryiko Sept. 19, 2024, 4:20 a.m. UTC | #2
On Thu, Sep 19, 2024 at 4:05 AM Tao Chen <chen.dylane@gmail.com> wrote:
>
> 在 2024/9/14 23:40, Tao Chen 写道:
> > The commit "5902da6d8a52" set expected_attach_type again with
> > field 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 | 12 ++++++++----
> >   1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > Change list:
> > - v2 -> v3:
> >      - update BPF_TRACE_UPROBE_MULTI both in prog and opts suggedted by
> >        Andrri
> > - 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..a78e24ff354b 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
> > @@ -7352,8 +7352,14 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog,
> >               opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
> >
> >       /* special check for usdt to use uprobe_multi link */
> > -     if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK))
> > +     if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK)) {
> > +             /* for BPF_TRACE_KPROBE_MULTI, user might want to query exected_attach_type
> > +              * in prog, and expected_attach_type we set in kenrel is from opts, so we
> > +              * update both.
> > +              */
> >               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 +7449,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 +7481,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,
>
> Hi, guys, please review this patch again, the previous versions:

It looks good, but bpf-next is closed right now due to merge window.
I'll apply when the tree is open again.

> v1:
> https://lore.kernel.org/bpf/20240913121627.153898-1-chen.dylane@gmail.com/
> v2:
> https://lore.kernel.org/bpf/20240913164355.176021-1-chen.dylane@gmail.com/
>
> --
> Best Regards
> Dylane Chen
Tao Chen Sept. 19, 2024, 1:45 p.m. UTC | #3
在 2024/9/19 12:20, Andrii Nakryiko 写道:
> On Thu, Sep 19, 2024 at 4:05 AM Tao Chen <chen.dylane@gmail.com> wrote:
>>
>> 在 2024/9/14 23:40, Tao Chen 写道:
>>> The commit "5902da6d8a52" set expected_attach_type again with
>>> field 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 | 12 ++++++++----
>>>    1 file changed, 8 insertions(+), 4 deletions(-)
>>>
>>> Change list:
>>> - v2 -> v3:
>>>       - update BPF_TRACE_UPROBE_MULTI both in prog and opts suggedted by
>>>         Andrri
>>> - 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..a78e24ff354b 100644
>>> --- a/tools/lib/bpf/libbpf.c
>>> +++ b/tools/lib/bpf/libbpf.c
>>> @@ -7352,8 +7352,14 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog,
>>>                opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
>>>
>>>        /* special check for usdt to use uprobe_multi link */
>>> -     if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK))
>>> +     if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK)) {
>>> +             /* for BPF_TRACE_KPROBE_MULTI, user might want to query exected_attach_type
>>> +              * in prog, and expected_attach_type we set in kenrel is from opts, so we
>>> +              * update both.
>>> +              */
>>>                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 +7449,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 +7481,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,
>>
>> Hi, guys, please review this patch again, the previous versions:
> 
> It looks good, but bpf-next is closed right now due to merge window.
> I'll apply when the tree is open again.

Hi,Andrii, thank you for your response! I’ll wait for the next window.

> 
>> v1:
>> https://lore.kernel.org/bpf/20240913121627.153898-1-chen.dylane@gmail.com/
>> v2:
>> https://lore.kernel.org/bpf/20240913164355.176021-1-chen.dylane@gmail.com/
>>
>> --
>> Best Regards
>> Dylane Chen
Jiri Olsa Sept. 25, 2024, 10:28 a.m. UTC | #4
On Sat, Sep 14, 2024 at 11:40:40PM +0800, Tao Chen wrote:
> The commit "5902da6d8a52" set expected_attach_type again with
> field 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 | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> Change list:
> - v2 -> v3:
>     - update BPF_TRACE_UPROBE_MULTI both in prog and opts suggedted by
>       Andrri
> - 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..a78e24ff354b 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -7352,8 +7352,14 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog,
>  		opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
>  
>  	/* special check for usdt to use uprobe_multi link */
> -	if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK))
> +	if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK)) {
> +		/* for BPF_TRACE_KPROBE_MULTI, user might want to query exected_attach_type
> +		 * in prog, and expected_attach_type we set in kenrel is from opts, so we
> +		 * update both.
> +		 */

s/K/U/ in BPF_TRACE_KPROBE_MULTI in above comment and 'kenrel' typo

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

>  		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 +7449,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 +7481,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
>
Daniel Borkmann Sept. 25, 2024, 10:36 a.m. UTC | #5
On 9/25/24 12:28 PM, Jiri Olsa wrote:
> On Sat, Sep 14, 2024 at 11:40:40PM +0800, Tao Chen wrote:
>> The commit "5902da6d8a52" set expected_attach_type again with
>> field 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 | 12 ++++++++----
>>   1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> Change list:
>> - v2 -> v3:
>>      - update BPF_TRACE_UPROBE_MULTI both in prog and opts suggedted by
>>        Andrri
>> - 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..a78e24ff354b 100644
>> --- a/tools/lib/bpf/libbpf.c
>> +++ b/tools/lib/bpf/libbpf.c
>> @@ -7352,8 +7352,14 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog,
>>   		opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
>>   
>>   	/* special check for usdt to use uprobe_multi link */
>> -	if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK))
>> +	if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK)) {
>> +		/* for BPF_TRACE_KPROBE_MULTI, user might want to query exected_attach_type
>> +		 * in prog, and expected_attach_type we set in kenrel is from opts, so we
>> +		 * update both.
>> +		 */
> s/K/U/ in BPF_TRACE_KPROBE_MULTI in above comment and 'kenrel' typo
>
> Acked-by: Jiri Olsa <jolsa@kernel.org>
Same typo is also in commit desc, would be good to improve the commit
desc a bit if you spin v4 anyway. Thanks!
Tao Chen Sept. 25, 2024, 2:55 p.m. UTC | #6
在 2024/9/25 18:36, Daniel Borkmann 写道:
> On 9/25/24 12:28 PM, Jiri Olsa wrote:
>> On Sat, Sep 14, 2024 at 11:40:40PM +0800, Tao Chen wrote:
>>> The commit "5902da6d8a52" set expected_attach_type again with
>>> field 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 | 12 ++++++++----
>>>   1 file changed, 8 insertions(+), 4 deletions(-)
>>>
>>> Change list:
>>> - v2 -> v3:
>>>      - update BPF_TRACE_UPROBE_MULTI both in prog and opts suggedted by
>>>        Andrri
>>> - 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..a78e24ff354b 100644
>>> --- a/tools/lib/bpf/libbpf.c
>>> +++ b/tools/lib/bpf/libbpf.c
>>> @@ -7352,8 +7352,14 @@ static int libbpf_prepare_prog_load(struct 
>>> bpf_program *prog,
>>>           opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
>>>       /* special check for usdt to use uprobe_multi link */
>>> -    if ((def & SEC_USDT) && kernel_supports(prog->obj, 
>>> FEAT_UPROBE_MULTI_LINK))
>>> +    if ((def & SEC_USDT) && kernel_supports(prog->obj, 
>>> FEAT_UPROBE_MULTI_LINK)) {
>>> +        /* for BPF_TRACE_KPROBE_MULTI, user might want to query 
>>> exected_attach_type
>>> +         * in prog, and expected_attach_type we set in kenrel is 
>>> from opts, so we
>>> +         * update both.
>>> +         */
>> s/K/U/ in BPF_TRACE_KPROBE_MULTI in above comment and 'kenrel' typo
>>
>> Acked-by: Jiri Olsa <jolsa@kernel.org>
> Same typo is also in commit desc, would be good to improve the commit
> desc a bit if you spin v4 anyway. Thanks!

Hi,Dnaiel,my bad,i will fix it in v4
diff mbox series

Patch

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 219facd0e66e..a78e24ff354b 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -7352,8 +7352,14 @@  static int libbpf_prepare_prog_load(struct bpf_program *prog,
 		opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
 
 	/* special check for usdt to use uprobe_multi link */
-	if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK))
+	if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK)) {
+		/* for BPF_TRACE_KPROBE_MULTI, user might want to query exected_attach_type
+		 * in prog, and expected_attach_type we set in kenrel is from opts, so we
+		 * update both.
+		 */
 		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 +7449,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 +7481,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,