Skip to contentSkip to conversation

fs: move getname and putname handlers into namei.h

PATCH In review Mateusz Guzik 2 participants 4 messages Nov 29, 2025 – Dec 1, 2025

Subsystems (17)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 fs: move getname and putname handlers into namei.h

This will enable use of runtime const machinery for namei_cachep. Existing header spaghetti makes it impossible to use while in fs.h

---

This may end up creating merge conflicts against the work which messed with audit and atomic refcounts on struct filename, but they should be trivially resolvable. Things just got moved fs.h -> namei.h

tested with allmodconfig

 drivers/base/firmware_loader/main.c |  1 +
 fs/ceph/mds_client.h                |  1 +
 fs/d_path.c                         |  1 +
 fs/exfat/dir.c                      |  1 +
 fs/f2fs/f2fs.h                      |  1 +
 fs/fat/dir.c                        |  1 +
 fs/filesystems.c                    |  1 +
 fs/ntfs3/dir.c                      |  1 +
 fs/ntfs3/fsntfs.c                   |  1 +
 fs/ntfs3/namei.c                    |  1 +
 fs/ntfs3/xattr.c                    |  1 +
 fs/smb/client/cifsproto.h           |  1 +
 fs/vboxsf/file.c                    |  1 +
 include/linux/fs.h                  | 42 +----------------------------
 include/linux/namei.h               | 41 ++++++++++++++++++++++++++++
 io_uring/statx.c                    |  1 +
 mm/huge_memory.c                    |  1 +
 security/integrity/ima/ima_api.c    |  1 +
 security/integrity/ima/ima_main.c   |  1 +
 19 files changed, 59 insertions(+), 41 deletions(-)
drivers/base/firmware_loader/main.c +1 -0
index 4ebdca9e4da4..ac5a86d7692f 100644
@@ -29,6 +29,7 @@
 #include <linux/file.h>
 #include <linux/list.h>
 #include <linux/fs.h>
+#include <linux/namei.h>
 #include <linux/async.h>
 #include <linux/pm.h>
 #include <linux/suspend.h>
fs/ceph/mds_client.h +1 -0
index 0428a5eaf28c..bc0b8da9fca2 100644
@@ -11,6 +11,7 @@
 #include <linux/refcount.h>
 #include <linux/utsname.h>
 #include <linux/ktime.h>
+#include <linux/namei.h>
 
 #include <linux/ceph/types.h>
 #include <linux/ceph/messenger.h>
fs/d_path.c +1 -0
index bb365511066b..19cde8b57771 100644
@@ -4,6 +4,7 @@
 #include <linux/uaccess.h>
 #include <linux/fs_struct.h>
 #include <linux/fs.h>
+#include <linux/namei.h>
 #include <linux/slab.h>
 #include <linux/prefetch.h>
 #include "mount.h"
fs/exfat/dir.c +1 -0
index 3045a58e124a..9d588a64e5dd 100644
@@ -7,6 +7,7 @@
 #include <linux/compat.h>
 #include <linux/bio.h>
 #include <linux/buffer_head.h>
+#include <linux/namei.h>
 
 #include "exfat_raw.h"
 #include "exfat_fs.h"
fs/f2fs/f2fs.h +1 -0
index 5f104518c414..78d97ccb646e 100644
@@ -24,6 +24,7 @@
 #include <linux/quotaops.h>
 #include <linux/part_stat.h>
 #include <linux/rw_hint.h>
+#include <linux/namei.h>
 
 #include <linux/fscrypt.h>
 #include <linux/fsverity.h>
fs/fat/dir.c +1 -0
index 92b091783966..6dd7d0f6043f 100644
@@ -18,6 +18,7 @@
 #include <linux/compat.h>
 #include <linux/uaccess.h>
 #include <linux/iversion.h>
+#include <linux/namei.h>
 #include "fat.h"
 
 /*
fs/filesystems.c +1 -0
index 95e5256821a5..fb0dac8aa916 100644
@@ -17,6 +17,7 @@
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 #include <linux/fs_parser.h>
+#include <linux/namei.h>
 
 /*
  * Handling of filesystem drivers list.
fs/ntfs3/dir.c +1 -0
index b98e95d6b4d9..5e778cac4197 100644
@@ -8,6 +8,7 @@
  */
 
 #include <linux/fs.h>
+#include <linux/namei.h>
 #include <linux/nls.h>
 
 #include "debug.h"
fs/ntfs3/fsntfs.c +1 -0
index 5f138f715835..5099c8fbe6b2 100644
@@ -8,6 +8,7 @@
 #include <linux/blkdev.h>
 #include <linux/buffer_head.h>
 #include <linux/fs.h>
+#include <linux/namei.h>
 #include <linux/kernel.h>
 #include <linux/nls.h>
 
fs/ntfs3/namei.c +1 -0
index 3b24ca02de61..1251dae282bb 100644
@@ -6,6 +6,7 @@
  */
 
 #include <linux/fs.h>
+#include <linux/namei.h>
 #include <linux/nls.h>
 #include <linux/ctype.h>
 #include <linux/posix_acl.h>
fs/ntfs3/xattr.c +1 -0
index c93df55e98d0..1211a0859000 100644
@@ -6,6 +6,7 @@
  */
 
 #include <linux/fs.h>
+#include <linux/namei.h>
 #include <linux/posix_acl.h>
 #include <linux/posix_acl_xattr.h>
 #include <linux/xattr.h>
fs/smb/client/cifsproto.h +1 -0
index 3528c365a452..6438a2dc77c3 100644
@@ -9,6 +9,7 @@
 #define _CIFSPROTO_H
 #include <linux/nls.h>
 #include <linux/ctype.h>
+#include <linux/namei.h>
 #include "cifsglob.h"
 #include "trace.h"
 #ifdef CONFIG_CIFS_DFS_UPCALL
fs/vboxsf/file.c +1 -0
index 4bebd947314a..bb05e99c1d24 100644
@@ -10,6 +10,7 @@
 #include <linux/pagemap.h>
 #include <linux/highmem.h>
 #include <linux/sizes.h>
+#include <linux/namei.h>
 #include "vfsmod.h"
 
 struct vboxsf_handle {
include/linux/fs.h +1 -41

66 lines not on this page · raw message

include/linux/namei.h +41 -0

47 lines not on this page · raw message

io_uring/statx.c +1 -0
index 5111e9befbfe..ba6442633214 100644
@@ -2,6 +2,7 @@
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/file.h>
+#include <linux/namei.h>
 #include <linux/io_uring.h>
 
 #include <uapi/linux/io_uring.h>
mm/huge_memory.c +1 -0
index f7c565f11a98..69c1eee121a4 100644
@@ -40,6 +40,7 @@
 #include <linux/pgalloc.h>
 #include <linux/pgalloc_tag.h>
 #include <linux/pagewalk.h>
+#include <linux/namei.h>
 
 #include <asm/tlb.h>
 #include "internal.h"
security/integrity/ima/ima_api.c +1 -0
index c35ea613c9f8..7b1d73a7e7e3 100644
@@ -11,6 +11,7 @@
 #include <linux/slab.h>
 #include <linux/file.h>
 #include <linux/fs.h>
+#include <linux/namei.h>
 #include <linux/xattr.h>
 #include <linux/evm.h>
 #include <linux/fsverity.h>
security/integrity/ima/ima_main.c +1 -0
index 5770cf691912..5fd40401d89f 100644
@@ -25,6 +25,7 @@
 #include <linux/xattr.h>
 #include <linux/ima.h>
 #include <linux/fs.h>
+#include <linux/namei.h>
 #include <linux/iversion.h>
 #include <linux/evm.h>
 #include <linux/crash_dump.h>
Signature · 1 line
2.48.1
#1 lore raw

PATCH 2/2 fs: hide namei_cachep behind runtime const machinery

---
 fs/dcache.c                       |  7 ++++---
 include/asm-generic/vmlinux.lds.h |  4 +++-
 include/linux/namei.h             | 11 ++++++++++-
 3 files changed, 17 insertions(+), 5 deletions(-)
fs/dcache.c +4 -3
index 23d1752c29e6..5cdcb3d0ee3b 100644
@@ -3282,8 +3282,8 @@ static void __init dcache_init(void)
 }
 
 /* SLAB cache for __getname() consumers */
-struct kmem_cache *names_cachep __ro_after_init;
-EXPORT_SYMBOL(names_cachep);
+struct kmem_cache *__names_cachep __ro_after_init;
+EXPORT_SYMBOL(__names_cachep);
 
 void __init vfs_caches_init_early(void)
 {
@@ -3298,8 +3298,9 @@ void __init vfs_caches_init_early(void)
 
 void __init vfs_caches_init(void)
 {
-	names_cachep = kmem_cache_create_usercopy("names_cache", PATH_MAX, 0,
+	__names_cachep = kmem_cache_create_usercopy("names_cache", PATH_MAX, 0,
 			SLAB_HWCACHE_ALIGN|SLAB_PANIC, 0, PATH_MAX, NULL);
+	runtime_const_init(ptr, __names_cachep);
 
 	dcache_init();
 	inode_init();
include/asm-generic/vmlinux.lds.h +3 -1
index 8ca130af301f..890250fffbe0 100644
@@ -972,7 +972,9 @@
 #define RUNTIME_CONST_VARIABLES						\
 		RUNTIME_CONST(shift, d_hash_shift)			\
 		RUNTIME_CONST(ptr, dentry_hashtable)			\
-		RUNTIME_CONST(ptr, __dentry_cache)
+		RUNTIME_CONST(ptr, __dentry_cache)			\
+		RUNTIME_CONST(ptr, __names_cachep)
+
 
 /* Alignment must be consistent with (kunit_suite *) in include/kunit/test.h */
 #define KUNIT_TABLE()							\
include/linux/namei.h +10 -1
index bd4a7b058f97..c167f3a852e2 100644
@@ -9,6 +9,10 @@
 #include <linux/errno.h>
 #include <linux/fs_struct.h>
 
+#ifndef MODULE
+#include <asm/runtime-const.h>
+#endif
+
 enum { MAX_NESTED_LINKS = 8 };
 
 #define MAXSYMLINKS 40
@@ -88,7 +92,12 @@ static inline struct filename *refname(struct filename *name)
 	return name;
 }
 
-extern struct kmem_cache *names_cachep;
+extern struct kmem_cache *__names_cachep;
+#ifdef MODULE
+#define names_cachep __names_cachep
+#else
+#define names_cachep runtime_const_ptr(__names_cachep)
+#endif
 
 #define __getname()		kmem_cache_alloc(names_cachep, GFP_KERNEL)
 #define __putname(name)		kmem_cache_free(names_cachep, (void *)(name))
Signature · 1 line
2.48.1
maintainer
#3 lore raw
Quoted 3 lines · Mateusz Guzik

self-NAK, i'm going to rebase on top of
https://lore.kernel.org/linux-fsdevel/[email protected]/
when the time comes

FWIW, I'm putting together struct filename-related
branches for the next cycle (trying to figure out what's the best way to linearize the mess I've got).

If you throw a patch on top of the series I've posted
on Friday (and it should shrink a whole lot - the damn thing is static in fs/namei.c now, with cache initialization done in the same place) I would be glad to apply it.

Other series around struct filename for the next
cycle:

* DEFINE_CLASS(filename, struct filename *, putname(_T), getname(p), const char __user *p) EXTEND_CLASS(filename, _kernel, getname_kernel(p), const char *p) EXTEND_CLASS(filename, _flags, getname_flags(p, f), const char *p, unsigned int f) EXTEND_CLASS(filename, _uflags, getname_uflags(p, f), const char *p, unsigned int f) EXTEND_CLASS(filename, _maybe_null, getname_maybe_null(p, f), const char *p, unsigned int f) EXTEND_CLASS(filename, _consume, no_free_ptr(p), struct filename *p)
and an bunch of conversions making use of that. Generally I dislike RAII patterns, but uses of struct filename make a reasonably good fit.

* change of calling conventions for do_filp_open() - let it DTRT when it's given ERR_PTR() for name. Surprising amount of error handling in the callers (and callers of callers, etc.) folds into that. One thing that is very tempting is s/do_filp_open/do_file_open/, while we are at it...

* killing pointless checks for IS_ERR() before calling filename_lookup() and vfs_path_parent_lookup() - those already treat ERR_PTR() for name as "bail out immediately".

* [currently very tentative] dealing with __audit_inode(). It's a surprisingly convoluted series, and it's not quite finished yet. Not sure if that one won't end up slipping past 6.20...

Linearizing that stuff into something that would not be a hell wrt merges is... interesting.