From: "Daniel T. Lee" <danieltimlee@gmail.com>
To: Martin KaFai Lau <kafai@fb.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>,
"Andrii Nakryiko" <andrii.nakryiko@gmail.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>,
"John Fastabend" <john.fastabend@gmail.com>,
bpf <bpf@vger.kernel.org>, netdev <netdev@vger.kernel.org>,
Xdp <xdp-newbies@vger.kernel.org>
Subject: Re: [PATCH bpf-next v2 1/7] samples: bpf: refactor hbm program with libbpf
Date: Tue, 24 Nov 2020 17:50:34 +0900 [thread overview]
Message-ID: <CAEKGpzifL18heCuioO8Qoei6a3epkrZcM=Av6qwdi2w1faTkKg@mail.gmail.com> (raw)
In-Reply-To: <20201121023405.tchtyadco4x45sf3@kafai-mbp.dhcp.thefacebook.com>
Sorry for the late reply.
On Sat, Nov 21, 2020 at 11:34 AM Martin KaFai Lau <kafai@fb.com> wrote:
>
> On Thu, Nov 19, 2020 at 03:06:11PM +0000, Daniel T. Lee wrote:
> [ ... ]
>
> > static int run_bpf_prog(char *prog, int cg_id)
> > [ ... ]
> > if (!outFlag)
> > - type = BPF_CGROUP_INET_INGRESS;
> > - if (bpf_prog_attach(bpfprog_fd, cg1, type, 0)) {
> > - printf("ERROR: bpf_prog_attach fails!\n");
> > - log_err("Attaching prog");
> > + bpf_program__set_expected_attach_type(bpf_prog, BPF_CGROUP_INET_INGRESS);
> > +
> > + link = bpf_program__attach_cgroup(bpf_prog, cg1);
> > + if (libbpf_get_error(link)) {
> > + fprintf(stderr, "ERROR: bpf_program__attach_cgroup failed\n");
> > + link = NULL;
> Again, this is not needed. bpf_link__destroy() can
> handle both NULL and error pointer. Please take a look
> at the bpf_link__destroy() in libbpf.c
>
> > + goto err;
> > + }
> > [ ... ]
> > @@ -398,10 +400,10 @@ static int run_bpf_prog(char *prog, int cg_id)
> > err:
> > rc = 1;
> >
> > - if (cg1)
> > - close(cg1);
> > + bpf_link__destroy(link);
> > + close(cg1);
> > cleanup_cgroup_environment();
> > -
> > + bpf_object__close(obj);
> The bpf_* cleanup condition still looks wrong.
>
> I can understand why it does not want to cleanup_cgroup_environment()
> on the success case because the sh script may want to run test under this
> cgroup.
>
> However, the bpf_link__destroy(), bpf_object__close(), and
> even close(cg1) should be done in both success and error
> cases.
>
> The cg1 test still looks wrong also. The cg1 should
> be init to -1 and then test for "if (cg1 == -1)".
Thanks for pointing this out.
I'll remove NULL initialize and fix this on the next patch.
--
Best,
Daniel T. Lee
next prev parent reply other threads:[~2020-11-24 8:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-19 15:06 [PATCH bpf-next v2 0/7] bpf: remove bpf_load loader completely Daniel T. Lee
2020-11-19 15:06 ` [PATCH bpf-next v2 1/7] samples: bpf: refactor hbm program with libbpf Daniel T. Lee
2020-11-21 2:34 ` Martin KaFai Lau
2020-11-21 2:42 ` Martin KaFai Lau
2020-11-24 8:50 ` Daniel T. Lee [this message]
2020-11-19 15:06 ` [PATCH bpf-next v2 2/7] samples: bpf: refactor test_cgrp2_sock2 " Daniel T. Lee
2020-11-19 15:06 ` [PATCH bpf-next v2 3/7] samples: bpf: refactor task_fd_query " Daniel T. Lee
2020-11-19 15:06 ` [PATCH bpf-next v2 4/7] samples: bpf: refactor ibumad " Daniel T. Lee
2020-11-19 15:06 ` [PATCH bpf-next v2 5/7] samples: bpf: refactor test_overhead " Daniel T. Lee
2020-11-19 15:06 ` [PATCH bpf-next v2 6/7] samples: bpf: fix lwt_len_hist reusing previous BPF map Daniel T. Lee
2020-11-19 15:06 ` [PATCH bpf-next v2 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='CAEKGpzifL18heCuioO8Qoei6a3epkrZcM=Av6qwdi2w1faTkKg@mail.gmail.com' \
--to=danieltimlee@gmail.com \
--cc=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=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).