Skip to contentSkip to conversation

selftests: cover kernfs dentry revalidation

PATCH Superseded Shakeel Butt 1 participant 2 messages Aug 29 – Sep 1

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: cover kernfs dentry revalidation

kernfs_test only exercised two xattr calls, so nothing covered the part of kernfs most exposed to userspace: the dentry cache.

kernfs nodes appear and disappear from kernel contexts with no VFS operation driving them, and removal cannot reliably unhash the cached dentries, so ->d_revalidate() is the correctness backstop. It had no test at all.

Add tests that drive kernfs from kernel context rather than through VFS create/unlink:

- writing cgroup.subtree_control makes the kernel add and remove files in every child cgroup, exercising both the negative-dentry revision check and the deactivation check,
- renaming a network interface renames the sysfs node underneath an already cached dentry,
- sysfs in a fresh network namespace must show only that namespace's interfaces, covering the KERNFS_NS tagging paths,
- lookup hammered against concurrent mkdir/rmdir must only ever see success or an errno meaning "it went away",
- removal-while-open, readdir duplicate detection and a seekdir()/telldir() round trip over kernfs_dir_pos()'s hash cookie.

Also the other direction: walking already cached dentries must not invalidate them. That is not merely a lost optimisation -- d_invalidate() calls detach_mounts(), so a revalidation that wrongly fails silently tears down any mount underneath the directory.

Both filesystems are needed: cgroup2 has no ->rename and is not namespace tagged, and sysfs cannot be mounted with a controllable set of children. The config fragment keeps a kernel built via kselftest-merge from reporting a pass while running almost nothing.

Verified the suite reacts to a broken backstop rather than passing:
stubbing kernfs_dir_changed() to return false turns 8 of the 11 tests red.

---
 MAINTAINERS                                   |   1 +
 tools/testing/selftests/filesystems/config    |   6 +
 .../selftests/filesystems/kernfs_test.c       | 657 +++++++++++++++++-
 3 files changed, 663 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/filesystems/config
MAINTAINERS +1 -0
index 549df316f487..605fd2d47788 100644
@@ -14392,6 +14392,7 @@ S:	Supported
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git
 F:	fs/kernfs/
 F:	include/linux/kernfs.h
+F:	tools/testing/selftests/filesystems/kernfs_test.c
 
 KEXEC
 M:	Andrew Morton <[email protected]>
tools/testing/selftests/filesystems/config new file +6 -0
new file mode 100644
index 000000000000..6e33f4188af4
@@ -0,0 +1,6 @@
+CONFIG_CGROUPS=y
+CONFIG_CGROUP_PIDS=y
+CONFIG_NET=y
+CONFIG_NET_NS=y
+CONFIG_INET=y
+CONFIG_SYSFS=y
tools/testing/selftests/filesystems/kernfs_test.c +656 -1

669 lines not on this page · raw message

Signature · 1 line
2.53.0-Meta
#1 lore raw
Quoted 33 lines · Shakeel Butt

kernfs_test only exercised two xattr calls, so nothing covered the part of kernfs most exposed to userspace: the dentry cache.

kernfs nodes appear and disappear from kernel contexts with no VFS operation driving them, and removal cannot reliably unhash the cached dentries, so ->d_revalidate() is the correctness backstop. It had no test at all.

Add tests that drive kernfs from kernel context rather than through VFS create/unlink:

- writing cgroup.subtree_control makes the kernel add and remove files in every child cgroup, exercising both the negative-dentry revision check and the deactivation check,
- renaming a network interface renames the sysfs node underneath an already cached dentry,
- sysfs in a fresh network namespace must show only that namespace's interfaces, covering the KERNFS_NS tagging paths,
- lookup hammered against concurrent mkdir/rmdir must only ever see success or an errno meaning "it went away",
- removal-while-open, readdir duplicate detection and a seekdir()/telldir() round trip over kernfs_dir_pos()'s hash cookie.

Also the other direction: walking already cached dentries must not invalidate them. That is not merely a lost optimisation -- d_invalidate() calls detach_mounts(), so a revalidation that wrongly fails silently tears down any mount underneath the directory.

Both filesystems are needed: cgroup2 has no ->rename and is not namespace tagged, and sysfs cannot be mounted with a controllable set of children. The config fragment keeps a kernel built via kselftest-merge from reporting a pass while running almost nothing.

Quoted 5 lines

Verified the suite reacts to a broken backstop rather than passing:
stubbing kernfs_dir_changed() to return false turns 8 of the 11 tests red.

Sashiko raised couple of issues, so I will address those and send v2.