BPF List
 help / color / mirror / Atom feed
From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: "Ricardo B. Marlière" <rbm@suse.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Shuah Khan" <shuah@kernel.org>,
	"Alexis Lothoré (eBPF Foundation)" <alexis.lothore@bootlin.com>,
	"Christian Brauner" <brauner@kernel.org>
Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] selftests/bpf: Fix lsm_bdev dev_t encoding mismatch
Date: Thu, 16 Jul 2026 14:11:44 -0700	[thread overview]
Message-ID: <2088b8ed-c26c-4120-a3d6-8e6dfbf89f58@linux.dev> (raw)
In-Reply-To: <20260710-selftests-bpf_fixes-v1-3-aa24dfd6f4f9@suse.com>

On 7/10/26 3:09 PM, Ricardo B. Marlière wrote:
> progs/lsm_bdev.c keys its verity_devices hashmap with the raw kernel dev_t
> read straight off bdev->bd_dev, i.e. MKDEV(major, minor) = (major << 20) |
> minor. prog_tests/lsm_bdev.c instead builds its lookup key with dev_key =
> (__u32)st.st_rdev from stat(2), but the stat(2) syscall fills st_rdev via
> the kernel's new_encode_dev(), a different bit layout: (minor & 0xff) |
> (major << 8) | ((minor & ~0xff) << 12).
> 
> For any device with a non-trivial major these two values differ, so the
> lookup can never find what the BPF program stored, and test_lsm_bdev()
> always fails with:
> 
>   test_lsm_bdev:FAIL:map lookup unexpected error: -2 (errno 2)
> 
> Reconstruct the raw kernel dev_t from the decoded major/minor instead of
> casting st_rdev directly, restoring the layout the BPF program actually
> reads.
> 
> Fixes: 96f4c251a087 ("selftests/bpf: add block device management selftests")
> Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
> ---
>  tools/testing/selftests/bpf/prog_tests/lsm_bdev.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/lsm_bdev.c b/tools/testing/selftests/bpf/prog_tests/lsm_bdev.c
> index a970798e1173..28bc4b117f41 100644
> --- a/tools/testing/selftests/bpf/prog_tests/lsm_bdev.c
> +++ b/tools/testing/selftests/bpf/prog_tests/lsm_bdev.c
> @@ -17,6 +17,7 @@
>  #include <stdlib.h>
>  #include <string.h>
>  #include <sys/stat.h>
> +#include <sys/sysmacros.h>
>  #include <sys/types.h>
>  #include <unistd.h>
>  #include "lsm_bdev.skel.h"
> @@ -172,7 +173,7 @@ void test_lsm_bdev(void)
>  	if (!ASSERT_OK(stat(DM_DEV_PATH, &st), "stat dm dev"))
>  		goto remove_dm;
>  
> -	dev_key = (__u32)st.st_rdev;
> +	dev_key = (major(st.st_rdev) << 20) | minor(st.st_rdev);

Acked-by: Ihor Solodrai <ihor.solodrai@linux.dev>

nit: I wonder if there are other tests with this bug. Have you checked?

>  
>  	/* Look up the device in the BPF map and verify. */
>  	err = bpf_map__lookup_elem(skel->maps.verity_devices,
> 


  reply	other threads:[~2026-07-16 21:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10 22:09 [PATCH 0/4] selftests/bpf: A few edge case fixes Ricardo B. Marlière
2026-07-10 22:09 ` [PATCH 1/4] selftests/bpf: Install bpftool where test_progs expects to find it Ricardo B. Marlière
2026-07-13 15:32   ` Alexis Lothoré
2026-07-15 21:40     ` Ricardo B. Marlière
2026-07-16 21:09     ` Ihor Solodrai
2026-07-10 22:09 ` [PATCH 2/4] selftests/bpf: Install resolve_btfids.test.o.BTF where the test expects it Ricardo B. Marlière
2026-07-16 21:10   ` Ihor Solodrai
2026-07-10 22:09 ` [PATCH 3/4] selftests/bpf: Fix lsm_bdev dev_t encoding mismatch Ricardo B. Marlière
2026-07-16 21:11   ` Ihor Solodrai [this message]
2026-07-10 22:09 ` [PATCH 4/4] libbpf: Search /lib64 and /lib in resolve_full_path() Ricardo B. Marlière
2026-07-10 22:58   ` bot+bpf-ci
2026-07-16 21:12   ` Ihor Solodrai
2026-07-16 21:07 ` [PATCH 0/4] selftests/bpf: A few edge case fixes Ihor Solodrai

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=2088b8ed-c26c-4120-a3d6-8e6dfbf89f58@linux.dev \
    --to=ihor.solodrai@linux.dev \
    --cc=alexis.lothore@bootlin.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=rbm@suse.com \
    --cc=shuah@kernel.org \
    --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