BPF List
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: Eduard Zingerman <eddyz87@gmail.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jakub Sitnicki <jakub@cloudflare.com>,
	John Fastabend <john.fastabend@gmail.com>,
	kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>
Subject: Re: [PATCH bpf-next v3 5/5] selftests/bpf: Add some tests with new bpf_program__attach_sockmap() APIs
Date: Tue, 2 Apr 2024 11:56:19 -0700	[thread overview]
Message-ID: <635a4cbc-0d7b-438b-8de6-6df1bec99539@linux.dev> (raw)
In-Reply-To: <2befbceb5be18eeee6f3376a1bf5b2d795beec53.camel@gmail.com>


On 4/2/24 6:17 AM, Eduard Zingerman wrote:
> On Mon, 2024-03-25 at 19:22 -0700, Yonghong Song wrote:
>> Add a few more tests in sockmap_basic.c and sockmap_listen.c to
>> test bpf_link based APIs for SK_MSG and SK_SKB programs.
>> Link attach/detach/update are all tested.
>>
>> All tests are passed.
>>
>> Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
>> ---
> Acked-by: Eduard Zingerman <eddyz87@gmail.com>
>
> As far as I understand patch #1 there are several error conditions
> that are not covered by these tests:
> - update link using program with wrong expected attach type;
> - bpf_program__attach_sockmap() _after_ bpf_prog_attach();
> - creation of a second link between same prog and map
>    (if I understand 'link && link != progs->msg_parser_link' checks in
>     sock_map_link_lookup() correctly).
>
> Are these important enough to have a dedicated test?

All these are missed. I can add them in the next revision.

>
> [...]
>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
>> index 63fb2da7930a..b4b38f92b864 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
>> @@ -131,6 +131,40 @@ static void test_skmsg_helpers(enum bpf_map_type map_type)
>>   	test_skmsg_load_helpers__destroy(skel);
>>   }
>>   
>> +static void test_skmsg_helpers_with_link(enum bpf_map_type map_type)
>> +{
>> +	struct test_skmsg_load_helpers *skel;
>> +	struct bpf_link *link, *link2;
>> +	struct bpf_program *prog;
>> +	int err, map;
>> +
>> +	skel = test_skmsg_load_helpers__open_and_load();
>> +	if (!ASSERT_OK_PTR(skel, "test_skmsg_load_helpers__open_and_load"))
>> +		return;
>> +
>> +	prog = skel->progs.prog_msg_verdict;
>> +	map = bpf_map__fd(skel->maps.sock_map);
>> +
>> +	link = bpf_program__attach_sockmap(prog, map);
>> +	if (!ASSERT_OK_PTR(link, "bpf_program__attach_sockmap"))
>> +		goto out;
>> +
>> +	err = bpf_prog_attach(bpf_program__fd(prog), map, BPF_SK_MSG_VERDICT, 0);
>> +	if (!ASSERT_ERR(err, "bpf_prog_attach"))
>> +		goto out;
>> +
>> +	link2 = bpf_program__attach_sockmap(skel->progs.prog_msg_verdict_clone, map);
>> +	if (!ASSERT_ERR_PTR(link2, "bpf_program__attach_sockmap"))
>> +		goto out;
> Nit: should bpf_link__detach(link2) be called before 'goto out' ?

Yes, we should do this although it will auto detach when test_progs exists.

>
>> +
>> +	err = bpf_link__update_program(link, skel->progs.prog_msg_verdict_clone);
>> +	ASSERT_OK(err, "bpf_link__update_program");
>> +
>> +out:
>> +	bpf_link__detach(link);
>> +	test_skmsg_load_helpers__destroy(skel);
>> +}
>> +
>>   static void test_sockmap_update(enum bpf_map_type map_type)
>>   {
>>   	int err, prog, src;

      reply	other threads:[~2024-04-02 18:56 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-26  2:21 [PATCH bpf-next v3 0/5] bpf: Add bpf_link support for sk_msg and sk_skb progs Yonghong Song
2024-03-26  2:21 ` [PATCH bpf-next v3 1/5] " Yonghong Song
2024-04-02 17:39   ` Eduard Zingerman
2024-04-03  0:06     ` Yonghong Song
2024-04-02 17:45   ` Andrii Nakryiko
2024-04-03  1:08     ` Yonghong Song
2024-04-03 16:43       ` Andrii Nakryiko
2024-04-03 17:47         ` John Fastabend
2024-04-03 22:09           ` run bpf prog w/o sockmap [was: bpf: Add bpf_link support for sk_msg and sk_skb progs] Martin KaFai Lau
2024-04-04  1:11             ` John Fastabend
2024-04-04  3:31               ` Yonghong Song
2024-04-05  4:41                 ` John Fastabend
2024-04-06  1:10                   ` Martin KaFai Lau
2024-04-04  3:18           ` [PATCH bpf-next v3 1/5] bpf: Add bpf_link support for sk_msg and sk_skb progs Yonghong Song
2024-04-05  4:42             ` John Fastabend
2024-03-26  2:22 ` [PATCH bpf-next v3 2/5] libbpf: Add bpf_link support for BPF_PROG_TYPE_SOCKMAP Yonghong Song
2024-04-02 13:18   ` Eduard Zingerman
2024-04-02 17:46   ` Andrii Nakryiko
2024-04-03  0:07     ` Yonghong Song
2024-03-26  2:22 ` [PATCH bpf-next v3 3/5] bpftool: Add link dump support for BPF_LINK_TYPE_SOCKMAP Yonghong Song
2024-03-27 11:58   ` Quentin Monnet
2024-03-26  2:22 ` [PATCH bpf-next v3 4/5] selftests/bpf: Refactor out helper functions for a few tests Yonghong Song
2024-04-02 13:18   ` Eduard Zingerman
2024-03-26  2:22 ` [PATCH bpf-next v3 5/5] selftests/bpf: Add some tests with new bpf_program__attach_sockmap() APIs Yonghong Song
2024-04-02 13:17   ` Eduard Zingerman
2024-04-02 18:56     ` Yonghong Song [this message]

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=635a4cbc-0d7b-438b-8de6-6df1bec99539@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=jakub@cloudflare.com \
    --cc=john.fastabend@gmail.com \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@kernel.org \
    /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