selftests/bpf: Use memfd_create instead of mkstemp in d_path
Subsystems (3)
PATCH 1/1 selftests/bpf: Use memfd_create instead of mkstemp in d_path
check_mem_access currently creates a temp file in /dev/shm, which isn't mounted under vmtest.sh in local runs. This causes mkstemp to fail with ENOENT. The fix is similar to
commit 47687a29b2c3 ("selftests/bpf: Use memfd_create instead of shm_open in cgroup_iter_memcg") where memfd_create gives a shmem-backed file with no mount needed while still reaching vfs_fallocate.
--- tools/testing/selftests/bpf/prog_tests/d_path.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/prog_tests/d_path.c +3 -4
@@ -4,6 +4,7 @@#include <sys/stat.h> #include <linux/sched.h> #include <sys/syscall.h> +#include <sys/mman.h> #define MAX_PATH_LEN 128#define MAX_FILES 7
@@ -220,7 +221,6 @@ static void test_d_path_check_types(void)static void test_d_path_mem_access (void ) {int localfd =-1 ; -char path_template[] ="/dev/shm/d_path_loadgen.XXXXXX" ;struct test_d_path__bss *bss;struct test_d_path *skel;
@@ -230,13 +230,12 @@ static void test_d_path_mem_access(void) bss = skel->bss; - localfd =mkstemp (path_template); -if (CHECK (localfd <0 ,"trigger" ,"mkstemp failed\n" )) + localfd =memfd_create ("d_path_loadgen" ,0 ); +if (CHECK (localfd <0 ,"trigger" ,"memfd_create failed\n" )) goto cleanup;if (CHECK (fallocate (localfd,0 ,0 ,1024 ) <0 ,"trigger" ,"fallocate failed\n" )) goto cleanup; -remove (path_template);if (CHECK (!bss->path_match_fallocate,"check" ,"failed to read fallocate path" ))
---
base-commit: a30c772627b2ef4bc715332b1b04938a914556cd
change-id: 20261102-d-path-memfd-981879bcd3d7
Best regards,
Signature · 1 line
Jonathan Bastari Thamrin <[email protected]>
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] selftests/bpf: deprecated CHECK() used in test_d_path_mem_access() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] selftests/bpf: deprecated CHECK() used in test_d_path_mem_access() --
commit 70ec4540d31dab1fed0411808b9f6ef87d380925
Author: Jonathan Bastari Thamrin <[email protected]>
selftests/bpf: Use memfd_create instead of mkstemp in d_path
This commit replaces mkstemp() in /dev/shm with memfd_create() in test_d_path_mem_access() so the check_mem_access subtest can run under vmtest.sh when /dev/shm is not mounted.
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/d_path.c +0
-0
[ ... ]
tools/testing/selftests/bpf/prog_tests/d_path.c static void test_d_path_mem_access(void) · line 235
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/d_path.c +2
-2@@ -230,13 +230,12 @@ static void test_d_path_mem_access(void) bss = skel->bss; - localfd =mkstemp (path_template); -if (CHECK (localfd <0 ,"trigger" ,"mkstemp failed\n" )) + localfd =memfd_create ("d_path_loadgen" ,0 ); +if (CHECK (localfd <0 ,"trigger" ,"memfd_create failed\n" )) goto cleanup;
[Severity: Low]
This isn't a bug, but since CHECK() is deprecated in BPF selftests, should this updated check in test_d_path_mem_access() use ASSERT_OK_FD() from tools/testing/selftests/bpf/test_progs.h instead (similar to commit 47687a29b2c3 ("selftests/bpf: Use memfd_create instead of shm_open in cgroup_iter_memcg"))?
if (!ASSERT_OK_FD(localfd, "memfd_create")) goto cleanup;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 38 lines · On Sun, Nov 1, 2026 at 8:23 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] selftests/bpf: deprecatedCHECK()used intest_d_path_mem_access()--commit
70ec4540d31dab1fed0411808b9f6ef87d380925
Author: Jonathan Bastari Thamrin <[email protected]>selftests/bpf: Use
memfd_createinstead of mkstemp ind_pathThis commit replaces
mkstemp()in/dev/shmwithmemfd_create()intest_d_path_mem_access()so thecheck_mem_accesssubtest can run undervmtest.shwhen/dev/shmis not mounted.Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/d_path.c +0
-0[ ... ]
tools/testing/selftests/bpf/prog_tests/d_path.c static void test_d_path_mem_access(void) · line 235
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/d_path.c +2
-2@@ -230,13 +230,12 @@ static void test_d_path_mem_access(void) bss = skel->bss; - localfd =mkstemp (path_template); -if (CHECK (localfd <0 ,"trigger" ,"mkstemp failed\n" )) + localfd =memfd_create ("d_path_loadgen" ,0 ); +if (CHECK (localfd <0 ,"trigger" ,"memfd_create failed\n" )) goto cleanup;[Severity: Low]
This isn't a bug, but sinceCHECK()is deprecated in BPF selftests, should this updated check intest_d_path_mem_access()useASSERT_OK_FD()fromtools/testing/selftests/bpf/test_progs.hinstead (similar to commit47687a29b2c3("selftests/bpf: Usememfd_createinstead ofshm_openincgroup_iter_memcg"))?
Quoted 1 line
if (!ASSERT_OK_FD(localfd, "memfd_create"))
yes, let's please switch away from CHECK please
pw-bot: cr
Quoted 5 lines
goto cleanup;--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1