BPF List
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>
Subject: Re: [PATCH bpf v2 3/3] selftests/bpf: Add test for prealloc_lru_pop bug
Date: Tue, 9 Aug 2022 09:01:29 -0700	[thread overview]
Message-ID: <47cc7999-bfff-bd34-6c46-6ff5cd09f8e1@fb.com> (raw)
In-Reply-To: <20220809140615.21231-4-memxor@gmail.com>



On 8/9/22 7:06 AM, Kumar Kartikeya Dwivedi wrote:
> Add a regression test to check against invalid check_and_init_map_value
> call inside prealloc_lru_pop.
> 
> To actually observe a kind of problem this can cause, set debug to 1
> when running the test locally without the fix. Then, just observe the
> refcount which keeps increasing on each run of the test. With timers or
> spin locks, it would cause unpredictable results when racing.
> 
> ...
> 
> bash-5.1# ./test_progs -t lru_bug
>        test_progs-192     [000] d..21   354.838821: bpf_trace_printk: ref: 4
>        test_progs-192     [000] d..21   354.842824: bpf_trace_printk: ref: 5
> bash-5.1# ./test_progs -t lru_bug
>        test_progs-193     [000] d..21   356.722813: bpf_trace_printk: ref: 5
>        test_progs-193     [000] d..21   356.727071: bpf_trace_printk: ref: 6
> 
> ... and so on.
> 
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>

Ack with a minor nit below.

Acked-by: Yonghong Song <yhs@fb.com>

> ---
>   .../selftests/bpf/prog_tests/lru_bug.c        | 19 ++++++
>   tools/testing/selftests/bpf/progs/lru_bug.c   | 67 +++++++++++++++++++
>   2 files changed, 86 insertions(+)
>   create mode 100644 tools/testing/selftests/bpf/prog_tests/lru_bug.c
>   create mode 100644 tools/testing/selftests/bpf/progs/lru_bug.c
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/lru_bug.c b/tools/testing/selftests/bpf/prog_tests/lru_bug.c
> new file mode 100644
> index 000000000000..3bcb5bc62d5a
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/lru_bug.c
> @@ -0,0 +1,19 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <test_progs.h>
> +
> +#include "lru_bug.skel.h"
> +
> +void serial_test_lru_bug(void)
> +{
> +	struct lru_bug *skel;
> +	int ret;
> +
> +	skel = lru_bug__open_and_load();
> +	if (!ASSERT_OK_PTR(skel, "lru_bug__open_and_load"))
> +		return;
> +	ret = lru_bug__attach(skel);
> +	if (!ASSERT_OK(ret, "lru_bug__attach"))
> +		return;

If not ASSERT_OK, should go to lru_bug__destroy(skel).

> +	usleep(1);
> +	ASSERT_OK(skel->data->result, "prealloc_lru_pop doesn't call check_and_init_map_value");

Missing
	lru_bug__destroy(skel);
.

> +}
[...]

  reply	other threads:[~2022-08-09 16:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-09 14:06 [PATCH bpf v2 0/3] Don't reinit map value in prealloc_lru_pop Kumar Kartikeya Dwivedi
2022-08-09 14:06 ` [PATCH bpf v2 1/3] bpf: Allow calling bpf_prog_test kfuncs in tracing programs Kumar Kartikeya Dwivedi
2022-08-09 15:12   ` Yonghong Song
2022-08-09 14:06 ` [PATCH bpf v2 2/3] bpf: Don't reinit map value in prealloc_lru_pop Kumar Kartikeya Dwivedi
2022-08-09 14:06 ` [PATCH bpf v2 3/3] selftests/bpf: Add test for prealloc_lru_pop bug Kumar Kartikeya Dwivedi
2022-08-09 16:01   ` Yonghong Song [this message]
2022-08-09 20:03     ` Kumar Kartikeya Dwivedi
2022-08-09 18:49 ` [PATCH bpf v2 0/3] Don't reinit map value in prealloc_lru_pop Alexei Starovoitov
2022-08-09 20:04   ` Kumar Kartikeya Dwivedi

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=47cc7999-bfff-bd34-6c46-6ff5cd09f8e1@fb.com \
    --to=yhs@fb.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kafai@fb.com \
    --cc=memxor@gmail.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