bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: "Daniel T. Lee" <danieltimlee@gmail.com>
Cc: "Daniel Borkmann" <daniel@iogearbox.net>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Andrii Nakryiko" <andrii@kernel.org>, brakmo <brakmo@fb.com>,
	"Jesper Dangaard Brouer" <brouer@redhat.com>,
	"Lorenzo Bianconi" <lorenzo@kernel.org>,
	"David Ahern" <dsa@cumulusnetworks.com>,
	"Yonghong Song" <yhs@fb.com>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>,
	"Ira Weiny" <ira.weiny@intel.com>, "Thomas Graf" <tgraf@suug.ch>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Martin KaFai Lau" <kafai@fb.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	bpf <bpf@vger.kernel.org>, Networking <netdev@vger.kernel.org>,
	Xdp <xdp-newbies@vger.kernel.org>
Subject: Re: [PATCH bpf-next v3 1/7] samples: bpf: refactor hbm program with libbpf
Date: Thu, 26 Nov 2020 19:40:25 -0800	[thread overview]
Message-ID: <CAEf4Bzby0AwzKfKwd5ZKXaEg1a1hpEfoPsqVLwPQVr89nAAxEA@mail.gmail.com> (raw)
In-Reply-To: <20201124090310.24374-2-danieltimlee@gmail.com>

On Tue, Nov 24, 2020 at 1:03 AM Daniel T. Lee <danieltimlee@gmail.com> wrote:
>
> This commit refactors the existing cgroup programs with libbpf
> bpf loader. Since bpf_program__attach doesn't support cgroup program
> attachment, this explicitly attaches cgroup bpf program with
> bpf_program__attach_cgroup(bpf_prog, cg1).
>
> Also, to change attach_type of bpf program, this uses libbpf's
> bpf_program__set_expected_attach_type helper to switch EGRESS to
> INGRESS. To keep bpf program attached to the cgroup hierarchy even
> after the exit, this commit uses the BPF_LINK_PINNING to pin the link
> attachment even after it is closed.
>
> Besides, this program was broken due to the typo of BPF MAP definition.
> But this commit solves the problem by fixing this from 'queue_stats' map
> struct hvm_queue_stats -> hbm_queue_stats.
>
> Fixes: 36b5d471135c ("selftests/bpf: samples/bpf: Split off legacy stuff from bpf_helpers.h")
> Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
> ---
> Changes in v2:
>  - restore read_trace_pipe2
>  - remove unnecessary return code and cgroup fd compare
>  - add static at global variable and remove unused variable
>  - change cgroup path with unified controller (/unified/)
>  - add link pinning to prevent cleaning up on process exit
>
> Changes in v3:
>  - cleanup bpf_link, bpf_object and cgroup fd both on success and error
>  - remove link NULL cleanup since __destroy() can handle
>  - fix cgroup test on cgroup fd cleanup
>
>  samples/bpf/.gitignore     |   3 +
>  samples/bpf/Makefile       |   2 +-
>  samples/bpf/do_hbm_test.sh |  32 +++++------
>  samples/bpf/hbm.c          | 111 ++++++++++++++++++++-----------------
>  samples/bpf/hbm_kern.h     |   2 +-
>  5 files changed, 78 insertions(+), 72 deletions(-)
>

Thanks for the nice clean up! I've applied the series to bpf-next. If
Martin finds any other problems, those can be fixed in a follow up
patch(es). But see also below about find_program_by_title().

> -       if (ret) {
> -               printf("ERROR: bpf_prog_load_xattr failed for: %s\n", prog);
> -               printf("  Output from verifier:\n%s\n------\n", bpf_log_buf);
> -               ret = -1;
> -       } else {
> -               ret = map_fd;
> +       bpf_prog = bpf_object__find_program_by_title(obj, "cgroup_skb/egress");

It would be good to avoid using find_program_by_title(), as it's going
to get deprecated and eventually removed. Looking up by section name
("title") is ambiguous now that libbpf supports many BPF programs per
same section. There is find_program_by_name() which looks program by
its C function name. I suggest using it.


> +       if (!bpf_prog) {
> +               printf("ERROR: finding a prog in obj file failed\n");
> +               goto err;
> +       }
> +

  reply	other threads:[~2020-11-27  3:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-24  9:03 [PATCH bpf-next v3 0/7] bpf: remove bpf_load loader completely Daniel T. Lee
2020-11-24  9:03 ` [PATCH bpf-next v3 1/7] samples: bpf: refactor hbm program with libbpf Daniel T. Lee
2020-11-27  3:40   ` Andrii Nakryiko [this message]
2020-11-24  9:03 ` [PATCH bpf-next v3 2/7] samples: bpf: refactor test_cgrp2_sock2 " Daniel T. Lee
2020-11-24  9:03 ` [PATCH bpf-next v3 3/7] samples: bpf: refactor task_fd_query " Daniel T. Lee
2020-11-24  9:03 ` [PATCH bpf-next v3 4/7] samples: bpf: refactor ibumad " Daniel T. Lee
2020-11-24  9:03 ` [PATCH bpf-next v3 5/7] samples: bpf: refactor test_overhead " Daniel T. Lee
2020-11-24  9:03 ` [PATCH bpf-next v3 6/7] samples: bpf: fix lwt_len_hist reusing previous BPF map Daniel T. Lee
2020-11-24  9:03 ` [PATCH bpf-next v3 7/7] samples: bpf: remove bpf_load loader completely Daniel T. Lee

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=CAEf4Bzby0AwzKfKwd5ZKXaEg1a1hpEfoPsqVLwPQVr89nAAxEA@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brakmo@fb.com \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=danieltimlee@gmail.com \
    --cc=dsa@cumulusnetworks.com \
    --cc=ira.weiny@intel.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kuba@kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tgraf@suug.ch \
    --cc=toke@redhat.com \
    --cc=xdp-newbies@vger.kernel.org \
    --cc=yhs@fb.com \
    /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;
as well as URLs for NNTP newsgroup(s).