bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	 John Fastabend <john.fastabend@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	 Martin KaFai Lau <martin.lau@linux.dev>,
	Eddy Z <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	 Yonghong Song <yonghong.song@linux.dev>,
	KP Singh <kpsingh@kernel.org>,
	 Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>,  bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next 2/2] selftests/bpf: Add selftest for bits iter
Date: Fri, 23 Feb 2024 10:29:50 +0800	[thread overview]
Message-ID: <CALOAHbCSXrX-igGH0TJTWcKSGg7u6KOfGQrqpwymxf4y1+f2kQ@mail.gmail.com> (raw)
In-Reply-To: <CAADnVQKYWm0PrkZH05q133FwaD5zrDSuBH1sJ5aXxGrVua2SsQ@mail.gmail.com>

On Fri, Feb 23, 2024 at 1:36 AM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Sun, Feb 18, 2024 at 3:49 AM Yafang Shao <laoar.shao@gmail.com> wrote:
> >
> > Add selftests for the newly added bits iter.
> > - bits_iter_success
> >   - The number of CPUs should be expected when iterating over a cpumask
> >   - percpu data extracted from the percpu struct should be expected
> >   - RCU lock is not required
> >   - It is fine without calling bpf_iter_cpumask_next()
> >   - It can work as expected when invalid arguments are passed
> >
> > - bits_iter_failure
> >   - bpf_iter_bits_destroy() is required after calling
> >     bpf_iter_bits_new()
> >   - bpf_iter_bits_destroy() can only destroy an initialized iter
> >   - bpf_iter_bits_next() must use an initialized iter
> >
> > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > ---
> >  tools/testing/selftests/bpf/config            |   1 +
> >  .../selftests/bpf/prog_tests/bits_iter.c      | 180 ++++++++++++++++++
> >  .../bpf/progs/test_bits_iter_failure.c        |  53 ++++++
> >  .../bpf/progs/test_bits_iter_success.c        | 146 ++++++++++++++
> >  4 files changed, 380 insertions(+)
> >  create mode 100644 tools/testing/selftests/bpf/prog_tests/bits_iter.c
> >  create mode 100644 tools/testing/selftests/bpf/progs/test_bits_iter_failure.c
> >  create mode 100644 tools/testing/selftests/bpf/progs/test_bits_iter_success.c
> >
> > diff --git a/tools/testing/selftests/bpf/config b/tools/testing/selftests/bpf/config
> > index 01f241ea2c67..dd4b0935e35f 100644
> > --- a/tools/testing/selftests/bpf/config
> > +++ b/tools/testing/selftests/bpf/config
> > @@ -78,6 +78,7 @@ CONFIG_NF_CONNTRACK_MARK=y
> >  CONFIG_NF_DEFRAG_IPV4=y
> >  CONFIG_NF_DEFRAG_IPV6=y
> >  CONFIG_NF_NAT=y
> > +CONFIG_PSI=y
> >  CONFIG_RC_CORE=y
> >  CONFIG_SECURITY=y
> >  CONFIG_SECURITYFS=y
> > diff --git a/tools/testing/selftests/bpf/prog_tests/bits_iter.c b/tools/testing/selftests/bpf/prog_tests/bits_iter.c
> > new file mode 100644
> > index 000000000000..778a7c942dba
> > --- /dev/null
> > +++ b/tools/testing/selftests/bpf/prog_tests/bits_iter.c
> > @@ -0,0 +1,180 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/* Copyright (c) 2024 Yafang Shao <laoar.shao@gmail.com> */
> > +
> > +#define _GNU_SOURCE
> > +#include <sched.h>
> > +
> > +#include <test_progs.h>
> > +#include "test_bits_iter_success.skel.h"
> > +#include "test_bits_iter_failure.skel.h"
> > +#include "cgroup_helpers.h"
> > +
> > +static const char * const positive_testcases[] = {
> > +       "cpumask_iter",
> > +};
> > +
> > +static const char * const negative_testcases[] = {
> > +       "null_pointer",
> > +       "zero_bit",
> > +       "no_mem",
> > +       "invalid_bits"
> > +};
> > +
> > +static int read_percpu_data(struct bpf_link *link, int nr_cpu_exp, int nr_running_exp)
> > +{
> > +       int iter_fd, len, item, nr_running, psi_running, nr_cpus, err = -1;
> > +       char buf[128];
> > +       size_t left;
> > +       char *p;
> > +
> > +       iter_fd = bpf_iter_create(bpf_link__fd(link));
> > +       if (!ASSERT_GE(iter_fd, 0, "iter_fd"))
> > +               return -1;
> > +
> > +       memset(buf, 0, sizeof(buf));
> > +       left = ARRAY_SIZE(buf);
> > +       p = buf;
> > +       while ((len = read(iter_fd, p, left)) > 0) {
> > +               p += len;
> > +               left -= len;
> > +       }
> > +
> > +       item = sscanf(buf, "nr_running %u nr_cpus %u psi_running %u\n",
> > +                     &nr_running, &nr_cpus, &psi_running);
> > +       if (!ASSERT_EQ(item, 3, "seq_format"))
> > +               goto out;
> > +       if (!ASSERT_EQ(nr_cpus, nr_cpu_exp, "nr_cpus"))
> > +               goto out;
> > +       if (!ASSERT_GE(nr_running, nr_running_exp, "nr_running"))
> > +               goto out;
> > +       if (!ASSERT_GE(psi_running, nr_running_exp, "psi_running"))
> > +               goto out;
> > +
> > +       err = 0;
> > +out:
> > +       close(iter_fd);
> > +       return err;
> > +}
>
> ..
> > +
> > +       /* Case 1): Enable all possible CPUs */
> > +       CPU_ZERO(&set);
> > +       for (i = 0; i < nr_cpus; i++)
> > +               CPU_SET(i, &set);
> > +       err = sched_setaffinity(skel->bss->pid, sizeof(set), &set);
> > +       if (!ASSERT_OK(err, "setaffinity_all_cpus"))
> > +               goto free_link;
> > +       err = read_percpu_data(link, nr_cpus, 1);
> > +       if (!ASSERT_OK(err, "read_percpu_data"))
> > +               goto free_link;
>
> The patch 1 looks good, but this test fails on s390.
>
> read_percpu_data:FAIL:nr_cpus unexpected nr_cpus: actual 0 != expected 2
> verify_iter_success:FAIL:read_percpu_data unexpected error: -1 (errno 95)
>
> Please see CI.
>
> So either add it to DENYLIST.s390x in the same commit or make it work.
>
> pw-bot: cr

The reason for the failure on s390x architecture is currently unclear.
One plausible explanation is that total_nr_cpus remains 0 when
executing the following code:

    bpf_for_each(bits, cpu, p->cpus_ptr, total_nr_cpus)

This is despite setting total_nr_cpus to the value obtained from
libbpf_num_possible_cpus():

    skel->bss->total_nr_cpus = libbpf_num_possible_cpus();

A potential workaround could involve using a hardcoded number of CPUs,
such as 8192, instead of relying on total_nr_cpus. This approach might
mitigate the issue temporarily.

-- 
Regards
Yafang

  reply	other threads:[~2024-02-23  2:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-18 11:48 [PATCH bpf-next 0/2] bpf: Add a generic bits iterator Yafang Shao
2024-02-18 11:48 ` [PATCH bpf-next 1/2] bpf: Add " Yafang Shao
2024-02-26 23:21   ` John Fastabend
2024-02-27  0:20     ` Alexei Starovoitov
2024-02-27  0:34       ` John Fastabend
2024-02-18 11:48 ` [PATCH bpf-next 2/2] selftests/bpf: Add selftest for bits iter Yafang Shao
2024-02-22 17:36   ` Alexei Starovoitov
2024-02-23  2:29     ` Yafang Shao [this message]
2024-02-23 11:52       ` Eduard Zingerman
2024-02-25  2:29         ` Yafang Shao
2024-02-25 19:38   ` kernel test robot

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=CALOAHbCSXrX-igGH0TJTWcKSGg7u6KOfGQrqpwymxf4y1+f2kQ@mail.gmail.com \
    --to=laoar.shao@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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).