The var is used twice for every path lookup, while the cache is
initialized early and stays valid for the duration.
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
fs/dcache.c | 1 +
include/asm-generic/vmlinux.lds.h | 3 ++-
include/linux/fs.h | 17 +++++++++++++++--
3 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/fs/dcache.c b/fs/dcache.c
index de3e4e9777ea..1afef6cf16b7 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -3259,6 +3259,7 @@ void __init vfs_caches_init(void)
{
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 dcdbd962abd6..c7d85c80111c 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -939,7 +939,8 @@
#define RUNTIME_CONST_VARIABLES \
RUNTIME_CONST(shift, d_hash_shift) \
- RUNTIME_CONST(ptr, dentry_hashtable)
+ RUNTIME_CONST(ptr, dentry_hashtable) \
+ 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/fs.h b/include/linux/fs.h
index 947d7958eb72..bf0606ace221 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -50,6 +50,10 @@
#include <linux/unicode.h>
#include <asm/byteorder.h>
+#ifndef MODULE
+#include <asm/runtime-const-accessors.h>
+#endif
+
#include <uapi/linux/fs.h>
struct backing_dev_info;
@@ -3044,8 +3048,17 @@ 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))
+/*
+ * XXX The runtime_const machinery does not support modules at the moment.
+ */
+#ifdef MODULE
+#define __names_cachep_accessor names_cachep
+#else
+#define __names_cachep_accessor runtime_const_ptr(names_cachep)
+#endif
+
+#define __getname() kmem_cache_alloc(__names_cachep_accessor, GFP_KERNEL)
+#define __putname(name) kmem_cache_free(__names_cachep_accessor, (void *)(name))
extern struct super_block *blockdev_superblock;
static inline bool sb_is_blkdev_sb(struct super_block *sb)
--
2.34.1
Hi Mateusz,
kernel test robot noticed the following build warnings:
[auto build test WARNING on arnd-asm-generic/master]
[also build test WARNING on linus/master brauner-vfs/vfs.all v6.18-rc3 next-20251031]
[cannot apply to linux/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mateusz-Guzik/x86-fix-access_ok-and-valid_user_address-using-wrong-USER_PTR_MAX-in-modules/20251101-054539
base: https://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git master
patch link: https://lore.kernel.org/r/20251031174220.43458-4-mjguzik%40gmail.com
patch subject: [PATCH 3/3] fs: hide names_cachep behind runtime access machinery
config: i386-randconfig-061-20251101 (https://download.01.org/0day-ci/archive/20251102/202511020147.47PufBIR-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251102/202511020147.47PufBIR-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511020147.47PufBIR-lkp@intel.com/
sparse warnings: (new ones prefixed by >>)
fs/smb/client/link.c: note: in included file:
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
fs/smb/client/cifsproto.h:77:17: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
--
fs/smb/client/dir.c: note: in included file:
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
fs/smb/client/cifsproto.h:77:17: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
--
fs/smb/client/misc.c: note: in included file:
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
fs/smb/client/cifsproto.h:77:17: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
--
fs/smb/client/cifsfs.c: note: in included file:
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
fs/smb/client/cifsproto.h:77:17: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
--
fs/smb/client/ioctl.c: note: in included file:
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
fs/smb/client/cifsproto.h:77:17: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
--
fs/smb/client/inode.c: note: in included file:
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
fs/smb/client/cifsproto.h:77:17: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
--
fs/smb/client/file.c: note: in included file:
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
fs/smb/client/cifsproto.h:77:17: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
--
fs/smb/client/readdir.c: note: in included file:
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
fs/smb/client/cifsproto.h:77:17: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
--
fs/smb/client/namespace.c: note: in included file:
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
fs/smb/client/cifsproto.h:77:17: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
--
fs/smb/client/smb2ops.c: note: in included file:
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
>> fs/smb/client/cifsproto.h:71:16: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
fs/smb/client/cifsproto.h:77:17: sparse: sparse: cast truncates bits from constant value (123456789abcdef becomes 89abcdef)
vim +71 fs/smb/client/cifsproto.h
b6b38f704a8193 fs/cifs/cifsproto.h Joe Perches 2010-04-21 48
6d5786a34d98bf fs/cifs/cifsproto.h Pavel Shilovsky 2012-06-20 49 #define free_xid(curr_xid) \
b6b38f704a8193 fs/cifs/cifsproto.h Joe Perches 2010-04-21 50 do { \
6d5786a34d98bf fs/cifs/cifsproto.h Pavel Shilovsky 2012-06-20 51 _free_xid(curr_xid); \
a0a3036b81f1f6 fs/cifs/cifsproto.h Joe Perches 2020-04-14 52 cifs_dbg(FYI, "VFS: leaving %s (xid = %u) rc = %d\n", \
b6b38f704a8193 fs/cifs/cifsproto.h Joe Perches 2010-04-21 53 __func__, curr_xid, (int)rc); \
d683bcd3e5d157 fs/cifs/cifsproto.h Steve French 2018-05-19 54 if (rc) \
d683bcd3e5d157 fs/cifs/cifsproto.h Steve French 2018-05-19 55 trace_smb3_exit_err(curr_xid, __func__, (int)rc); \
d683bcd3e5d157 fs/cifs/cifsproto.h Steve French 2018-05-19 56 else \
d683bcd3e5d157 fs/cifs/cifsproto.h Steve French 2018-05-19 57 trace_smb3_exit_done(curr_xid, __func__); \
b6b38f704a8193 fs/cifs/cifsproto.h Joe Perches 2010-04-21 58 } while (0)
4d79dba0e00749 fs/cifs/cifsproto.h Shirish Pargaonkar 2011-04-27 59 extern int init_cifs_idmap(void);
4d79dba0e00749 fs/cifs/cifsproto.h Shirish Pargaonkar 2011-04-27 60 extern void exit_cifs_idmap(void);
b74cb9a80268be fs/cifs/cifsproto.h Sachin Prabhu 2016-05-17 61 extern int init_cifs_spnego(void);
b74cb9a80268be fs/cifs/cifsproto.h Sachin Prabhu 2016-05-17 62 extern void exit_cifs_spnego(void);
f6a9bc336b600e fs/cifs/cifsproto.h Al Viro 2021-03-05 63 extern const char *build_path_from_dentry(struct dentry *, void *);
7ad54b98fc1f14 fs/cifs/cifsproto.h Paulo Alcantara 2022-12-18 64 char *__build_path_from_dentry_optional_prefix(struct dentry *direntry, void *page,
7ad54b98fc1f14 fs/cifs/cifsproto.h Paulo Alcantara 2022-12-18 65 const char *tree, int tree_len,
7ad54b98fc1f14 fs/cifs/cifsproto.h Paulo Alcantara 2022-12-18 66 bool prefix);
268a635d414df4 fs/cifs/cifsproto.h Aurelien Aptel 2017-02-13 67 extern char *build_path_from_dentry_optional_prefix(struct dentry *direntry,
f6a9bc336b600e fs/cifs/cifsproto.h Al Viro 2021-03-05 68 void *page, bool prefix);
f6a9bc336b600e fs/cifs/cifsproto.h Al Viro 2021-03-05 69 static inline void *alloc_dentry_path(void)
f6a9bc336b600e fs/cifs/cifsproto.h Al Viro 2021-03-05 70 {
f6a9bc336b600e fs/cifs/cifsproto.h Al Viro 2021-03-05 @71 return __getname();
f6a9bc336b600e fs/cifs/cifsproto.h Al Viro 2021-03-05 72 }
f6a9bc336b600e fs/cifs/cifsproto.h Al Viro 2021-03-05 73
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Mateusz,
kernel test robot noticed the following build errors:
[auto build test ERROR on arnd-asm-generic/master]
[also build test ERROR on linus/master brauner-vfs/vfs.all v6.18-rc3 next-20251031]
[cannot apply to linux/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mateusz-Guzik/x86-fix-access_ok-and-valid_user_address-using-wrong-USER_PTR_MAX-in-modules/20251101-054539
base: https://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git master
patch link: https://lore.kernel.org/r/20251031174220.43458-4-mjguzik%40gmail.com
patch subject: [PATCH 3/3] fs: hide names_cachep behind runtime access machinery
config: arm-allnoconfig (https://download.01.org/0day-ci/archive/20251101/202511010704.D6l8wp63-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project d1c086e82af239b245fe8d7832f2753436634990)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251101/202511010704.D6l8wp63-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511010704.D6l8wp63-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from arch/arm/kernel/asm-offsets.c:12:
In file included from include/linux/mm.h:1016:
In file included from include/linux/huge_mm.h:7:
>> include/linux/fs.h:54:10: fatal error: 'asm/runtime-const-accessors.h' file not found
54 | #include <asm/runtime-const-accessors.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[3]: *** [scripts/Makefile.build:182: arch/arm/kernel/asm-offsets.s] Error 1
make[3]: Target 'prepare' not remade because of errors.
make[2]: *** [Makefile:1282: prepare0] Error 2
make[2]: Target 'prepare' not remade because of errors.
make[1]: *** [Makefile:248: __sub-make] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
vim +54 include/linux/fs.h
51
52 #include <asm/byteorder.h>
53 #ifndef MODULE
> 54 #include <asm/runtime-const-accessors.h>
55 #endif
56
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Mateusz,
kernel test robot noticed the following build errors:
[auto build test ERROR on arnd-asm-generic/master]
[also build test ERROR on linus/master brauner-vfs/vfs.all v6.18-rc3 next-20251031]
[cannot apply to linux/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mateusz-Guzik/x86-fix-access_ok-and-valid_user_address-using-wrong-USER_PTR_MAX-in-modules/20251101-054539
base: https://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git master
patch link: https://lore.kernel.org/r/20251031174220.43458-4-mjguzik%40gmail.com
patch subject: [PATCH 3/3] fs: hide names_cachep behind runtime access machinery
config: alpha-allnoconfig (https://download.01.org/0day-ci/archive/20251101/202511010706.nuASkMjZ-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251101/202511010706.nuASkMjZ-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511010706.nuASkMjZ-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from include/linux/huge_mm.h:7,
from include/linux/mm.h:1016,
from include/linux/pid_namespace.h:7,
from include/linux/ptrace.h:10,
from arch/alpha/kernel/asm-offsets.c:11:
>> include/linux/fs.h:54:10: fatal error: asm/runtime-const-accessors.h: No such file or directory
54 | #include <asm/runtime-const-accessors.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[3]: *** [scripts/Makefile.build:182: arch/alpha/kernel/asm-offsets.s] Error 1
make[3]: Target 'prepare' not remade because of errors.
make[2]: *** [Makefile:1282: prepare0] Error 2
make[2]: Target 'prepare' not remade because of errors.
make[1]: *** [Makefile:248: __sub-make] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
vim +54 include/linux/fs.h
51
52 #include <asm/byteorder.h>
53 #ifndef MODULE
> 54 #include <asm/runtime-const-accessors.h>
55 #endif
56
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Mateusz,
kernel test robot noticed the following build warnings:
[auto build test WARNING on arnd-asm-generic/master]
[also build test WARNING on linus/master brauner-vfs/vfs.all v6.18-rc3 next-20251031]
[cannot apply to linux/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mateusz-Guzik/x86-fix-access_ok-and-valid_user_address-using-wrong-USER_PTR_MAX-in-modules/20251101-054539
base: https://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git master
patch link: https://lore.kernel.org/r/20251031174220.43458-4-mjguzik%40gmail.com
patch subject: [PATCH 3/3] fs: hide names_cachep behind runtime access machinery
config: um-allnoconfig (https://download.01.org/0day-ci/archive/20251101/202511010731.B5nbGjbm-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project d1c086e82af239b245fe8d7832f2753436634990)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251101/202511010731.B5nbGjbm-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511010731.B5nbGjbm-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from fs/dcache.c:38:
In file included from ./arch/um/include/generated/asm/runtime-const.h:1:
>> include/asm-generic/runtime-const.h:11:9: warning: 'runtime_const_ptr' macro redefined [-Wmacro-redefined]
11 | #define runtime_const_ptr(sym) (sym)
| ^
arch/x86/include/asm/runtime-const-accessors.h:21:9: note: previous definition is here
21 | #define runtime_const_ptr(sym) ({ \
| ^
In file included from fs/dcache.c:38:
In file included from ./arch/um/include/generated/asm/runtime-const.h:1:
>> include/asm-generic/runtime-const.h:12:9: warning: 'runtime_const_shift_right_32' macro redefined [-Wmacro-redefined]
12 | #define runtime_const_shift_right_32(val, sym) ((u32)(val)>>(sym))
| ^
arch/x86/include/asm/runtime-const-accessors.h:35:9: note: previous definition is here
35 | #define runtime_const_shift_right_32(val, sym) ({ \
| ^
2 warnings generated.
vim +/runtime_const_ptr +11 include/asm-generic/runtime-const.h
e78298556ee5d8 Linus Torvalds 2024-06-04 4
e78298556ee5d8 Linus Torvalds 2024-06-04 5 /*
e78298556ee5d8 Linus Torvalds 2024-06-04 6 * This is the fallback for when the architecture doesn't
e78298556ee5d8 Linus Torvalds 2024-06-04 7 * support the runtime const operations.
e78298556ee5d8 Linus Torvalds 2024-06-04 8 *
e78298556ee5d8 Linus Torvalds 2024-06-04 9 * We just use the actual symbols as-is.
e78298556ee5d8 Linus Torvalds 2024-06-04 10 */
e78298556ee5d8 Linus Torvalds 2024-06-04 @11 #define runtime_const_ptr(sym) (sym)
e78298556ee5d8 Linus Torvalds 2024-06-04 @12 #define runtime_const_shift_right_32(val, sym) ((u32)(val)>>(sym))
e78298556ee5d8 Linus Torvalds 2024-06-04 13 #define runtime_const_init(type,sym) do { } while (0)
e78298556ee5d8 Linus Torvalds 2024-06-04 14
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2026 Red Hat, Inc.