public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: Sun Jian <sun.jian.kdev@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Shuah Khan <shuah@kernel.org>
Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>
Subject: Re: [PATCH 2/2] selftests/bpf: Skip bpffs debug iter checks when unavailable in test_bpffs
Date: Thu, 12 Mar 2026 14:44:37 -0700	[thread overview]
Message-ID: <9f1acc68-823d-4003-a177-face6cdcc950@linux.dev> (raw)
In-Reply-To: <20260310102145.857810-2-sun.jian.kdev@gmail.com>



On 3/10/26 3:21 AM, Sun Jian wrote:
> maps.debug/progs.debug may be inaccessible or absent (EPERM/EACCES/ENOENT)
> in some environments, which used to abort test_bpffs before it exercised

In which situation these two files have issues? This already root
access. If file operation failed, that must be due to your special
situation.

> the pin and rename checks. Treat these errors as "iter unavailable", log
> an INFO message, and continue with the core bpffs tests.
>
> Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
> ---
>   .../selftests/bpf/prog_tests/test_bpffs.c     | 43 ++++++++++++++++---
>   1 file changed, 36 insertions(+), 7 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/test_bpffs.c b/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
> index e8021ff0581c..95a7d2582ba7 100644
> --- a/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
> +++ b/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
> @@ -11,15 +11,18 @@
>   /* TDIR must be in a location we can create a directory in. */
>   #define TDIR "/tmp/test_bpffs_testdir"
>   
> -static int read_iter(char *file)
> +static int read_iter(const char *file, int *save_errno)
>   {
>   	/* 1024 should be enough to get contiguous 4 "iter" letters at some point */
>   	char buf[1024];
>   	int fd, len;
>   
>   	fd = open(file, O_RDONLY);
> -	if (fd < 0)
> +	if (fd < 0) {
> +		if (save_errno)
> +			*save_errno = errno;
>   		return -1;
> +	}
>   	while ((len = read(fd, buf, sizeof(buf) - 1)) > 0) {
>   		buf[len] = '\0';
>   		if (strstr(buf, "iter")) {
> @@ -27,10 +30,33 @@ static int read_iter(char *file)
>   			return 0;
>   		}
>   	}
> +	if (save_errno)
> +		*save_errno = (len < 0) ? errno : 0;
>   	close(fd);
>   	return -1;
>   }
>   
> +static bool is_iter_skip_err(int err, int serrno)
> +{
> +	return err && (serrno == EPERM || serrno == EACCES || serrno == ENOENT);
> +}
> +
> +static int read_iter_or_skip(const char *file)
> +{
> +	int serrno = 0;
> +	int err = read_iter(file, &serrno);
> +
> +	if (is_iter_skip_err(err, serrno)) {
> +		fprintf(stderr,
> +			"INFO: %s unavailable (%d), skipping iter check\n",
> +			file,
> +			serrno);
> +		return 0;
> +	}
> +
> +	return err;
> +}
> +
>   static int fn(void)
>   {
>   	struct stat a, b, c;
> @@ -69,13 +95,16 @@ static int fn(void)
>   	if (!ASSERT_OK(err, "mount bpffs " TDIR "/fs2"))
>   		goto out;
>   
> -	err = read_iter(TDIR "/fs1/maps.debug");
> -	if (!ASSERT_OK(err, "reading " TDIR "/fs1/maps.debug"))
> +	err = read_iter_or_skip(TDIR "/fs1/maps.debug");
> +	if (err) {
> +		ASSERT_OK(err, "reading " TDIR "/fs1/maps.debug");
>   		goto out;
> -	err = read_iter(TDIR "/fs2/progs.debug");
> -	if (!ASSERT_OK(err, "reading " TDIR "/fs2/progs.debug"))
> +	}
> +	err = read_iter_or_skip(TDIR "/fs2/progs.debug");
> +	if (err) {
> +		ASSERT_OK(err, "reading " TDIR "/fs2/progs.debug");
>   		goto out;
> -
> +	}
>   	err = mkdir(TDIR "/fs1/a", 0777);
>   	if (!ASSERT_OK(err, "creating " TDIR "/fs1/a"))
>   		goto out;


  parent reply	other threads:[~2026-03-12 21:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10 10:21 [PATCH 1/2] selftests/bpf: Fix read_iter buffer termination in test_bpffs Sun Jian
2026-03-10 10:21 ` [PATCH 2/2] selftests/bpf: Skip bpffs debug iter checks when unavailable " Sun Jian
2026-03-10 12:32   ` Viktor Malik
2026-03-11  7:55     ` sun jian
2026-03-11 10:31       ` Viktor Malik
2026-03-12 21:44   ` Yonghong Song [this message]
2026-03-13  2:49     ` sun jian
2026-03-10 12:28 ` [PATCH 1/2] selftests/bpf: Fix read_iter buffer termination " Viktor Malik
2026-03-11  6:47   ` sun jian
2026-03-11 10:38     ` Viktor Malik
2026-03-12 21:41 ` Yonghong Song

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=9f1acc68-823d-4003-a177-face6cdcc950@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=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=sun.jian.kdev@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