From: Yonghong Song <yhs@fb.com>
To: Andrii Nakryiko <andrii@kernel.org>, <bpf@vger.kernel.org>,
<ast@kernel.org>, <daniel@iogearbox.net>
Cc: <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 5/7] selftests/bpf: switch fexit_bpf2bpf selftest to set_attach_target() API
Date: Wed, 15 Sep 2021 21:24:22 -0700 [thread overview]
Message-ID: <b8dac642-bed3-cf84-4b21-99c7ffec07e1@fb.com> (raw)
In-Reply-To: <20210916015836.1248906-6-andrii@kernel.org>
On 9/15/21 6:58 PM, Andrii Nakryiko wrote:
> Switch fexit_bpf2bpf selftest to bpf_program__set_attach_target()
> instead of using bpf_object_open_opts.attach_prog_fd, which is going to
> be deprecated. These changes also demonstrate the new mode of
> set_attach_target() in which it allows NULL when the target is BPF
> program (attach_prog_fd != 0).
>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Ack with a minor nit below.
Acked-by: Yonghong Song <yhs@fb.com>
> ---
> .../selftests/bpf/prog_tests/fexit_bpf2bpf.c | 43 +++++++++++--------
> 1 file changed, 26 insertions(+), 17 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
> index 73b4c76e6b86..c7c1816899bf 100644
> --- a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
> +++ b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
> @@ -60,7 +60,7 @@ static void test_fexit_bpf2bpf_common(const char *obj_file,
> struct bpf_object *obj = NULL, *tgt_obj;
> __u32 retval, tgt_prog_id, info_len;
> struct bpf_prog_info prog_info = {};
> - struct bpf_program **prog = NULL;
> + struct bpf_program **prog = NULL, *p;
> struct bpf_link **link = NULL;
> int err, tgt_fd, i;
> struct btf *btf;
> @@ -69,9 +69,6 @@ static void test_fexit_bpf2bpf_common(const char *obj_file,
> &tgt_obj, &tgt_fd);
> if (!ASSERT_OK(err, "tgt_prog_load"))
> return;
> - DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts,
> - .attach_prog_fd = tgt_fd,
> - );
>
> info_len = sizeof(prog_info);
> err = bpf_obj_get_info_by_fd(tgt_fd, &prog_info, &info_len);
> @@ -89,10 +86,15 @@ static void test_fexit_bpf2bpf_common(const char *obj_file,
> if (!ASSERT_OK_PTR(prog, "prog_ptr"))
> goto close_prog;
>
> - obj = bpf_object__open_file(obj_file, &opts);
> + obj = bpf_object__open_file(obj_file, NULL);
> if (!ASSERT_OK_PTR(obj, "obj_open"))
> goto close_prog;
>
> + bpf_object__for_each_program(p, obj) {
> + err = bpf_program__set_attach_target(p, tgt_fd, NULL);
> + ASSERT_OK(err, "set_attach_target");
> + }
> +
> err = bpf_object__load(obj);
> if (!ASSERT_OK(err, "obj_load"))
> goto close_prog;
> @@ -270,7 +272,7 @@ static void test_fmod_ret_freplace(void)
> struct bpf_link *freplace_link = NULL;
> struct bpf_program *prog;
> __u32 duration = 0;
> - int err, pkt_fd;
> + int err, pkt_fd, attach_prog_fd;
>
> err = bpf_prog_load(tgt_name, BPF_PROG_TYPE_UNSPEC,
> &pkt_obj, &pkt_fd);
> @@ -278,26 +280,32 @@ static void test_fmod_ret_freplace(void)
> if (CHECK(err, "tgt_prog_load", "file %s err %d errno %d\n",
> tgt_name, err, errno))
> return;
> - opts.attach_prog_fd = pkt_fd;
>
> - freplace_obj = bpf_object__open_file(freplace_name, &opts);
> + freplace_obj = bpf_object__open_file(freplace_name, NULL);
> if (!ASSERT_OK_PTR(freplace_obj, "freplace_obj_open"))
> goto out;
>
> + prog = bpf_program__next(NULL, freplace_obj);
> + err = bpf_program__set_attach_target(prog, pkt_fd, NULL);
> + ASSERT_OK(err, "freplace__set_attach_target");
The above pattern appears 3 times. Maybe it is worthwhile to
have a small helper. But the current code is also fine,
so I won't insist.
> +
> err = bpf_object__load(freplace_obj);
> if (CHECK(err, "freplace_obj_load", "err %d\n", err))
> goto out;
>
> - prog = bpf_program__next(NULL, freplace_obj);
> freplace_link = bpf_program__attach_trace(prog);
> if (!ASSERT_OK_PTR(freplace_link, "freplace_attach_trace"))
> goto out;
>
> - opts.attach_prog_fd = bpf_program__fd(prog);
> - fmod_obj = bpf_object__open_file(fmod_ret_name, &opts);
> + fmod_obj = bpf_object__open_file(fmod_ret_name, NULL);
> if (!ASSERT_OK_PTR(fmod_obj, "fmod_obj_open"))
> goto out;
>
> + attach_prog_fd = bpf_program__fd(prog);
> + prog = bpf_program__next(NULL, fmod_obj);
> + err = bpf_program__set_attach_target(prog, attach_prog_fd, NULL);
> + ASSERT_OK(err, "fmod_ret_set_attach_target");
> +
> err = bpf_object__load(fmod_obj);
> if (CHECK(!err, "fmod_obj_load", "loading fmod_ret should fail\n"))
> goto out;
> @@ -322,14 +330,14 @@ static void test_func_sockmap_update(void)
> }
>
> static void test_obj_load_failure_common(const char *obj_file,
> - const char *target_obj_file)
> -
> + const char *target_obj_file)
> {
> /*
> * standalone test that asserts failure to load freplace prog
> * because of invalid return code.
> */
> struct bpf_object *obj = NULL, *pkt_obj;
> + struct bpf_program *prog;
> int err, pkt_fd;
> __u32 duration = 0;
>
> @@ -339,14 +347,15 @@ static void test_obj_load_failure_common(const char *obj_file,
> if (CHECK(err, "tgt_prog_load", "file %s err %d errno %d\n",
> target_obj_file, err, errno))
> return;
> - DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts,
> - .attach_prog_fd = pkt_fd,
> - );
>
> - obj = bpf_object__open_file(obj_file, &opts);
> + obj = bpf_object__open_file(obj_file, NULL);
> if (!ASSERT_OK_PTR(obj, "obj_open"))
> goto close_prog;
>
> + prog = bpf_program__next(NULL, obj);
> + err = bpf_program__set_attach_target(prog, pkt_fd, NULL);
> + ASSERT_OK(err, "set_attach_target");
> +
> /* It should fail to load the program */
> err = bpf_object__load(obj);
> if (CHECK(!err, "bpf_obj_load should fail", "err %d\n", err))
>
next prev parent reply other threads:[~2021-09-16 4:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-16 1:58 [PATCH bpf-next 0/7] Improve set_attach_target() and deprecate open_opts.attach_prog_fd Andrii Nakryiko
2021-09-16 1:58 ` [PATCH bpf-next 1/7] libbpf: use pre-setup sec_def in libbpf_find_attach_btf_id() Andrii Nakryiko
2021-09-16 2:52 ` Yonghong Song
2021-09-16 1:58 ` [PATCH bpf-next 2/7] selftests/bpf: stop using relaxed_core_relocs which has no effect Andrii Nakryiko
2021-09-16 2:57 ` Yonghong Song
2021-09-16 1:58 ` [PATCH bpf-next 3/7] libbpf: deprecated bpf_object_open_opts.relaxed_core_relocs Andrii Nakryiko
2021-09-16 2:57 ` Yonghong Song
2021-09-16 1:58 ` [PATCH bpf-next 4/7] libbpf: allow skipping attach_func_name in bpf_program__set_attach_target() Andrii Nakryiko
2021-09-16 4:17 ` Yonghong Song
2021-09-17 16:09 ` Alexei Starovoitov
2021-09-17 18:04 ` Andrii Nakryiko
2021-09-16 1:58 ` [PATCH bpf-next 5/7] selftests/bpf: switch fexit_bpf2bpf selftest to set_attach_target() API Andrii Nakryiko
2021-09-16 4:24 ` Yonghong Song [this message]
2021-09-16 17:14 ` Andrii Nakryiko
2021-09-16 1:58 ` [PATCH bpf-next 6/7] libbpf: schedule open_opts.attach_prog_fd deprecation since v0.7 Andrii Nakryiko
2021-09-16 4:26 ` Yonghong Song
2021-09-16 1:58 ` [PATCH bpf-next 7/7] libbpf: constify all high-level program attach APIs Andrii Nakryiko
2021-09-16 4:29 ` Yonghong Song
2021-09-17 16:10 ` [PATCH bpf-next 0/7] Improve set_attach_target() and deprecate open_opts.attach_prog_fd patchwork-bot+netdevbpf
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=b8dac642-bed3-cf84-4b21-99c7ffec07e1@fb.com \
--to=yhs@fb.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.