lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Thu, 25 Apr 2024 22:12:33 +0200
From: Andrea Righi <andrea.righi@...onical.com>
To: Andrii Nakryiko <andrii.nakryiko@...il.com>
Cc: Andrii Nakryiko <andrii@...nel.org>,
	Eduard Zingerman <eddyz87@...il.com>,
	Mykola Lysenko <mykolal@...com>,
	Alexei Starovoitov <ast@...nel.org>,
	Daniel Borkmann <daniel@...earbox.net>,
	Martin KaFai Lau <martin.lau@...ux.dev>, Song Liu <song@...nel.org>,
	Yonghong Song <yonghong.song@...ux.dev>,
	John Fastabend <john.fastabend@...il.com>,
	KP Singh <kpsingh@...nel.org>, Stanislav Fomichev <sdf@...gle.com>,
	Hao Luo <haoluo@...gle.com>, Jiri Olsa <jolsa@...nel.org>,
	Shuah Khan <shuah@...nel.org>, linux-kernel@...r.kernel.org,
	bpf@...r.kernel.org, linux-kselftest@...r.kernel.org
Subject: Re: [PATCH v3] selftests/bpf: Add ring_buffer__consume_n test.

On Thu, Apr 25, 2024 at 11:47:07AM -0700, Andrii Nakryiko wrote:
> On Thu, Apr 25, 2024 at 7:06 AM Andrea Righi <andrea.righi@...onical.com> wrote:
> >
> > Add a testcase for the ring_buffer__consume_n() API.
> >
> > The test produces multiple samples in a ring buffer, using a
> > sys_getpid() fentry prog, and consumes them from user-space in batches,
> > rather than consuming all of them greedily, like ring_buffer__consume()
> > does.
> >
> > Link: https://lore.kernel.org/lkml/CAEf4BzaR4zqUpDmj44KNLdpJ=Tpa97GrvzuzVNO5nM6b7oWd1w@mail.gmail.com
> > Signed-off-by: Andrea Righi <andrea.righi@...onical.com>
> > ---
> >  tools/testing/selftests/bpf/Makefile          |  2 +-
> >  .../selftests/bpf/prog_tests/ringbuf.c        | 64 +++++++++++++++++++
> >  .../selftests/bpf/progs/test_ringbuf_n.c      | 47 ++++++++++++++
> >  3 files changed, 112 insertions(+), 1 deletion(-)
> >  create mode 100644 tools/testing/selftests/bpf/progs/test_ringbuf_n.c
> >
> > ChangeLog v2 -> v3:
> >  - move skel_n inside ringbuf_n_subtest()
> >
> > ChangeLog v1 -> v2:
> >  - replace CHECK() with ASSERT_EQ()
> >  - fix skel -> skel_n
> >  - drop unused "seq" field from struct sample
> >
> 
> [...]
> 
> > +       /* Produce N_TOT_SAMPLES samples in the ring buffer by calling getpid() */
> > +       skel_n->bss->value = SAMPLE_VALUE;
> > +       for (i = 0; i < N_TOT_SAMPLES; i++)
> > +               syscall(__NR_getpgid);
> > +
> > +       /* Consume all samples from the ring buffer in batches of N_SAMPLES */
> > +       for (i = 0; i < N_TOT_SAMPLES; i += err) {
> > +               err = ring_buffer__consume_n(ringbuf, N_SAMPLES);
> > +               ASSERT_EQ(err, N_SAMPLES, "rb_consume");
> 
> if something goes wrong and err is < 0, we might end up with a very
> long loop. I changed this to:
> 
> if (!ASSERT_EQ(...))
>     goto cleanup_ringbuf;
> 
> to avoid this problem

Looks good, tested, just in case, and it works a expected.

Thanks!
-Andrea

> 
> > +       }
> > +
> > +cleanup_ringbuf:
> > +       ring_buffer__free(ringbuf);
> > +cleanup:
> > +       test_ringbuf_n_lskel__destroy(skel_n);
> > +}
> > +
> 
> [...]

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ