netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	netdev@vger.kernel.org, kernel-team@meta.com,
	Amery Hung <ameryhung@gmail.com>
Subject: Re: [RFC PATCH bpf-next 10/12] selftests/bpf: Add test for bpf_list_{front,back}
Date: Fri, 25 Apr 2025 16:28:38 -0700	[thread overview]
Message-ID: <dc0bb19e-31cc-4fa1-9057-a188403dd422@linux.dev> (raw)
In-Reply-To: <CAP01T76heQ9rV1sNdssBQ_mSeDk_yxwP-Binh_j-AfTtXFVPdw@mail.gmail.com>

On 4/21/25 8:08 PM, Kumar Kartikeya Dwivedi wrote:
> On Sat, 19 Apr 2025 at 00:48, Martin KaFai Lau <martin.lau@linux.dev> wrote:
>>
>> From: Martin KaFai Lau <martin.lau@kernel.org>
>>
>> This patch adds a test for the new bpf_list_{front,back} kfunc.
>>
>> It also adds a test to ensure the non-owning node pointer cannot
>> be used after unlock.
>>
>> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
>> ---
>>   .../selftests/bpf/prog_tests/linked_list.c    |   2 +
>>   .../selftests/bpf/progs/linked_list_peek.c    | 104 ++++++++++++++++++
>>   2 files changed, 106 insertions(+)
>>   create mode 100644 tools/testing/selftests/bpf/progs/linked_list_peek.c
>>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/linked_list.c b/tools/testing/selftests/bpf/prog_tests/linked_list.c
>> index 77d07e0a4a55..559f45239a83 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/linked_list.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/linked_list.c
>> @@ -7,6 +7,7 @@
>>
>>   #include "linked_list.skel.h"
>>   #include "linked_list_fail.skel.h"
>> +#include "linked_list_peek.skel.h"
>>
>>   static char log_buf[1024 * 1024];
>>
>> @@ -804,4 +805,5 @@ void test_linked_list(void)
>>          test_linked_list_success(LIST_IN_LIST, false);
>>          test_linked_list_success(LIST_IN_LIST, true);
>>          test_linked_list_success(TEST_ALL, false);
>> +       RUN_TESTS(linked_list_peek);
>>   }
>> diff --git a/tools/testing/selftests/bpf/progs/linked_list_peek.c b/tools/testing/selftests/bpf/progs/linked_list_peek.c
>> new file mode 100644
>> index 000000000000..26c978091e5b
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/progs/linked_list_peek.c
>> @@ -0,0 +1,104 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
>> +
>> +#include <vmlinux.h>
>> +#include <bpf/bpf_helpers.h>
>> +#include "bpf_misc.h"
>> +#include "bpf_experimental.h"
>> +
>> +struct node_data {
>> +       struct bpf_list_node l;
>> +       int key;
>> +};
>> +
>> +#define private(name) SEC(".data." #name) __hidden __attribute__((aligned(8)))
>> +private(A) struct bpf_spin_lock glock;
>> +private(A) struct bpf_list_head ghead __contains(node_data, l);
>> +
>> +#define list_entry(ptr, type, member) container_of(ptr, type, member)
>> +#define NR_NODES 32
>> +
>> +int zero = 0;
>> +
>> +SEC("syscall")
>> +__failure __msg("invalid mem access 'scalar'")
>> +long list_peek_unlock_scalar_node(void *ctx)
>> +{
>> +       struct bpf_list_node *l_n;
>> +       struct node_data *n;
>> +
>> +       bpf_spin_lock(&glock);
>> +       l_n = bpf_list_front(&ghead);
>> +       bpf_spin_unlock(&glock);
>> +
>> +       if (l_n) {
>> +               n = list_entry(l_n, struct node_data, l);
>> +               if (n->key == 0)
>> +                       return __LINE__;
>> +       }
>> +
>> +       return 0;
>> +}
> 
> Would be good to have tests explicitly asserting the type is
> non-owning ref (even though we indirectly do that by touching it after
> unlock, relying on invalidation logic.).

I will try to address the test suggestions in patch 6 and 10.

Thanks for the review!



  reply	other threads:[~2025-04-25 23:28 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-18 22:46 [RFC PATCH bpf-next 00/12] bpf: A fq example similar to the kernel sch_fq.c implementation Martin KaFai Lau
2025-04-18 22:46 ` [RFC PATCH bpf-next 01/12] bpf: Check KF_bpf_rbtree_add_impl for the "case KF_ARG_PTR_TO_RB_NODE" Martin KaFai Lau
2025-04-22  1:05   ` Kumar Kartikeya Dwivedi
2025-04-18 22:46 ` [RFC PATCH bpf-next 02/12] bpf: Simplify reg0 marking for the rbtree kfuncs that return a bpf_rb_node pointer Martin KaFai Lau
2025-04-22  1:14   ` Kumar Kartikeya Dwivedi
2025-04-18 22:46 ` [RFC PATCH bpf-next 03/12] bpf: Add bpf_rbtree_{root,left,right} kfunc Martin KaFai Lau
2025-04-22  1:43   ` Kumar Kartikeya Dwivedi
2025-04-18 22:46 ` [RFC PATCH bpf-next 04/12] selftests/bpf: Adjust failure message in the rbtree_fail test Martin KaFai Lau
2025-04-22  1:44   ` Kumar Kartikeya Dwivedi
2025-04-18 22:46 ` [RFC PATCH bpf-next 05/12] bpf: Allow refcounted bpf_rb_node used in bpf_rbtree_{remove,left,right} Martin KaFai Lau
2025-04-22  2:32   ` Kumar Kartikeya Dwivedi
2025-04-18 22:46 ` [RFC PATCH bpf-next 06/12] selftests/bpf: Adjust test that does not allow refcounted node in rbtree_remove Martin KaFai Lau
2025-04-22  2:36   ` Kumar Kartikeya Dwivedi
2025-04-22  2:48     ` Kumar Kartikeya Dwivedi
2025-04-18 22:46 ` [RFC PATCH bpf-next 07/12] selftests/bpf: Add rbtree_search test Martin KaFai Lau
2025-04-22  3:03   ` Kumar Kartikeya Dwivedi
2025-04-18 22:46 ` [RFC PATCH bpf-next 08/12] bpf: Simplify reg0 marking for the list kfuncs that return a bpf_list_node pointer Martin KaFai Lau
2025-04-22  3:05   ` Kumar Kartikeya Dwivedi
2025-04-18 22:46 ` [RFC PATCH bpf-next 09/12] bpf: Add bpf_list_{front,back} kfunc Martin KaFai Lau
2025-04-22  3:07   ` Kumar Kartikeya Dwivedi
2025-04-18 22:46 ` [RFC PATCH bpf-next 10/12] selftests/bpf: Add test for bpf_list_{front,back} Martin KaFai Lau
2025-04-22  3:08   ` Kumar Kartikeya Dwivedi
2025-04-25 23:28     ` Martin KaFai Lau [this message]
2025-04-18 22:46 ` [RFC PATCH bpf-next 11/12] bpf: net: Add a qdisc kfunc to set sk_pacing_status Martin KaFai Lau
2025-04-18 22:46 ` [RFC PATCH bpf-next 12/12] selftests/bpf: A bpf fq implementation similar to the kernel sch_fq Martin KaFai Lau
2025-04-25  0:13   ` Alexei Starovoitov
2025-04-25 23:50     ` Martin KaFai Lau

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=dc0bb19e-31cc-4fa1-9057-a188403dd422@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@meta.com \
    --cc=memxor@gmail.com \
    --cc=netdev@vger.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;
as well as URLs for NNTP newsgroup(s).