* [PATCH 1/2] fs: move getname and putname handlers into namei.h
@ 2025-11-29 15:54 Mateusz Guzik
2025-11-29 15:55 ` [PATCH 2/2] fs: hide namei_cachep behind runtime const machinery Mateusz Guzik
2025-12-01 6:27 ` [PATCH 1/2] fs: move getname and putname handlers into namei.h Mateusz Guzik
0 siblings, 2 replies; 4+ messages in thread
From: Mateusz Guzik @ 2025-11-29 15:54 UTC (permalink / raw)
To: brauner; +Cc: viro, jack, linux-kernel, linux-fsdevel, Mateusz Guzik
This will enable use of runtime const machinery for namei_cachep.
Existing header spaghetti makes it impossible to use while in fs.h
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
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(-)
diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c
index 4ebdca9e4da4..ac5a86d7692f 100644
--- a/drivers/base/firmware_loader/main.c
+++ b/drivers/base/firmware_loader/main.c
@@ -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>
diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h
index 0428a5eaf28c..bc0b8da9fca2 100644
--- a/fs/ceph/mds_client.h
+++ b/fs/ceph/mds_client.h
@@ -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>
diff --git a/fs/d_path.c b/fs/d_path.c
index bb365511066b..19cde8b57771 100644
--- a/fs/d_path.c
+++ b/fs/d_path.c
@@ -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"
diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
index 3045a58e124a..9d588a64e5dd 100644
--- a/fs/exfat/dir.c
+++ b/fs/exfat/dir.c
@@ -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"
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 5f104518c414..78d97ccb646e 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -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>
diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index 92b091783966..6dd7d0f6043f 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -18,6 +18,7 @@
#include <linux/compat.h>
#include <linux/uaccess.h>
#include <linux/iversion.h>
+#include <linux/namei.h>
#include "fat.h"
/*
diff --git a/fs/filesystems.c b/fs/filesystems.c
index 95e5256821a5..fb0dac8aa916 100644
--- a/fs/filesystems.c
+++ b/fs/filesystems.c
@@ -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.
diff --git a/fs/ntfs3/dir.c b/fs/ntfs3/dir.c
index b98e95d6b4d9..5e778cac4197 100644
--- a/fs/ntfs3/dir.c
+++ b/fs/ntfs3/dir.c
@@ -8,6 +8,7 @@
*/
#include <linux/fs.h>
+#include <linux/namei.h>
#include <linux/nls.h>
#include "debug.h"
diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c
index 5f138f715835..5099c8fbe6b2 100644
--- a/fs/ntfs3/fsntfs.c
+++ b/fs/ntfs3/fsntfs.c
@@ -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>
diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c
index 3b24ca02de61..1251dae282bb 100644
--- a/fs/ntfs3/namei.c
+++ b/fs/ntfs3/namei.c
@@ -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>
diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c
index c93df55e98d0..1211a0859000 100644
--- a/fs/ntfs3/xattr.c
+++ b/fs/ntfs3/xattr.c
@@ -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>
diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h
index 3528c365a452..6438a2dc77c3 100644
--- a/fs/smb/client/cifsproto.h
+++ b/fs/smb/client/cifsproto.h
@@ -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
diff --git a/fs/vboxsf/file.c b/fs/vboxsf/file.c
index 4bebd947314a..bb05e99c1d24 100644
--- a/fs/vboxsf/file.c
+++ b/fs/vboxsf/file.c
@@ -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 {
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 04ceeca12a0d..8b6f8e373ac7 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -55,6 +55,7 @@ struct bdi_writeback;
struct bio;
struct io_comp_batch;
struct fiemap_extent_info;
+struct filename;
struct hd_geometry;
struct iovec;
struct kiocb;
@@ -2408,16 +2409,6 @@ extern struct kobject *fs_kobj;
#define MAX_RW_COUNT (INT_MAX & PAGE_MASK)
/* fs/open.c */
-struct audit_names;
-struct filename {
- const char *name; /* pointer to actual string */
- const __user char *uptr; /* original userland pointer */
- atomic_t refcnt;
- struct audit_names *aname;
- const char iname[];
-};
-static_assert(offsetof(struct filename, iname) % sizeof(long) == 0);
-
static inline struct mnt_idmap *file_mnt_idmap(const struct file *file)
{
return mnt_idmap(file->f_path.mnt);
@@ -2491,32 +2482,6 @@ static inline struct file *file_clone_open(struct file *file)
}
extern int filp_close(struct file *, fl_owner_t id);
-extern struct filename *getname_flags(const char __user *, int);
-extern struct filename *getname_uflags(const char __user *, int);
-static inline struct filename *getname(const char __user *name)
-{
- return getname_flags(name, 0);
-}
-extern struct filename *getname_kernel(const char *);
-extern struct filename *__getname_maybe_null(const char __user *);
-static inline struct filename *getname_maybe_null(const char __user *name, int flags)
-{
- if (!(flags & AT_EMPTY_PATH))
- return getname(name);
-
- if (!name)
- return NULL;
- return __getname_maybe_null(name);
-}
-extern void putname(struct filename *name);
-DEFINE_FREE(putname, struct filename *, if (!IS_ERR_OR_NULL(_T)) putname(_T))
-
-static inline struct filename *refname(struct filename *name)
-{
- atomic_inc(&name->refcnt);
- return name;
-}
-
extern int finish_open(struct file *file, struct dentry *dentry,
int (*open)(struct inode *, struct file *));
extern int finish_no_open(struct file *file, struct dentry *dentry);
@@ -2534,11 +2499,6 @@ static inline int finish_open_simple(struct file *file, int error)
extern void __init vfs_caches_init_early(void);
extern void __init vfs_caches_init(void);
-extern struct kmem_cache *names_cachep;
-
-#define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL)
-#define __putname(name) kmem_cache_free(names_cachep, (void *)(name))
-
void emergency_thaw_all(void);
extern int sync_filesystem(struct super_block *);
extern const struct file_operations def_blk_fops;
diff --git a/include/linux/namei.h b/include/linux/namei.h
index 58600cf234bc..bd4a7b058f97 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -52,6 +52,47 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT};
extern int path_pts(struct path *path);
+struct audit_names;
+struct filename {
+ const char *name; /* pointer to actual string */
+ const __user char *uptr; /* original userland pointer */
+ atomic_t refcnt;
+ struct audit_names *aname;
+ const char iname[];
+};
+static_assert(offsetof(struct filename, iname) % sizeof(long) == 0);
+
+struct filename *getname_flags(const char __user *, int);
+struct filename *getname_uflags(const char __user *, int);
+static inline struct filename *getname(const char __user *name)
+{
+ return getname_flags(name, 0);
+}
+struct filename *getname_kernel(const char *);
+struct filename *__getname_maybe_null(const char __user *);
+static inline struct filename *getname_maybe_null(const char __user *name, int flags)
+{
+ if (!(flags & AT_EMPTY_PATH))
+ return getname(name);
+
+ if (!name)
+ return NULL;
+ return __getname_maybe_null(name);
+}
+void putname(struct filename *name);
+DEFINE_FREE(putname, struct filename *, if (!IS_ERR_OR_NULL(_T)) putname(_T))
+
+static inline struct filename *refname(struct filename *name)
+{
+ atomic_inc(&name->refcnt);
+ return name;
+}
+
+extern struct kmem_cache *names_cachep;
+
+#define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL)
+#define __putname(name) kmem_cache_free(names_cachep, (void *)(name))
+
extern int user_path_at(int, const char __user *, unsigned, struct path *);
struct dentry *lookup_one_qstr_excl(const struct qstr *name,
diff --git a/io_uring/statx.c b/io_uring/statx.c
index 5111e9befbfe..ba6442633214 100644
--- a/io_uring/statx.c
+++ b/io_uring/statx.c
@@ -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>
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index f7c565f11a98..69c1eee121a4 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -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"
diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
index c35ea613c9f8..7b1d73a7e7e3 100644
--- a/security/integrity/ima/ima_api.c
+++ b/security/integrity/ima/ima_api.c
@@ -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>
diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c
index 5770cf691912..5fd40401d89f 100644
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@ -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>
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] fs: hide namei_cachep behind runtime const machinery
2025-11-29 15:54 [PATCH 1/2] fs: move getname and putname handlers into namei.h Mateusz Guzik
@ 2025-11-29 15:55 ` Mateusz Guzik
2025-12-01 6:27 ` [PATCH 1/2] fs: move getname and putname handlers into namei.h Mateusz Guzik
1 sibling, 0 replies; 4+ messages in thread
From: Mateusz Guzik @ 2025-11-29 15:55 UTC (permalink / raw)
To: brauner; +Cc: viro, jack, linux-kernel, linux-fsdevel, Mateusz Guzik
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
fs/dcache.c | 7 ++++---
include/asm-generic/vmlinux.lds.h | 4 +++-
include/linux/namei.h | 11 ++++++++++-
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/fs/dcache.c b/fs/dcache.c
index 23d1752c29e6..5cdcb3d0ee3b 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -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();
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 8ca130af301f..890250fffbe0 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -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() \
diff --git a/include/linux/namei.h b/include/linux/namei.h
index bd4a7b058f97..c167f3a852e2 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -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))
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] fs: move getname and putname handlers into namei.h
2025-11-29 15:54 [PATCH 1/2] fs: move getname and putname handlers into namei.h Mateusz Guzik
2025-11-29 15:55 ` [PATCH 2/2] fs: hide namei_cachep behind runtime const machinery Mateusz Guzik
@ 2025-12-01 6:27 ` Mateusz Guzik
2025-12-01 7:54 ` Al Viro
1 sibling, 1 reply; 4+ messages in thread
From: Mateusz Guzik @ 2025-12-01 6:27 UTC (permalink / raw)
To: brauner; +Cc: viro, jack, linux-kernel, linux-fsdevel
self-NAK, i'm going to rebase on top of
https://lore.kernel.org/linux-fsdevel/20251129170142.150639-1-viro@zeniv.linux.org.uk/
when the time comes
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] fs: move getname and putname handlers into namei.h
2025-12-01 6:27 ` [PATCH 1/2] fs: move getname and putname handlers into namei.h Mateusz Guzik
@ 2025-12-01 7:54 ` Al Viro
0 siblings, 0 replies; 4+ messages in thread
From: Al Viro @ 2025-12-01 7:54 UTC (permalink / raw)
To: Mateusz Guzik; +Cc: brauner, jack, linux-kernel, linux-fsdevel
On Mon, Dec 01, 2025 at 07:27:05AM +0100, Mateusz Guzik wrote:
> self-NAK, i'm going to rebase on top of
> https://lore.kernel.org/linux-fsdevel/20251129170142.150639-1-viro@zeniv.linux.org.uk/
> 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.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-12-01 7:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-29 15:54 [PATCH 1/2] fs: move getname and putname handlers into namei.h Mateusz Guzik
2025-11-29 15:55 ` [PATCH 2/2] fs: hide namei_cachep behind runtime const machinery Mateusz Guzik
2025-12-01 6:27 ` [PATCH 1/2] fs: move getname and putname handlers into namei.h Mateusz Guzik
2025-12-01 7:54 ` Al Viro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).