CONFIG_VFS_DEBUG at last
Subsystems (2)
v3 cover CONFIG_VFS_DEBUG at last
This adds a super basic version just to get the mechanism going, along with sample usage.
The macro set is incomplete (e.g., lack of locking macros) and dump_inode routine fails to dump any state yet, to be implemented(tm).
I think despite the primitive state this is complete enough to start sprinkling asserts as necessary.
v3:
- move dump_inode to fs/inode.c
- s/failed/encountered/
- pr_warn instead of pr_crit, matches dump_mapping
v2:
- correct may_open
- fixed up condition reporting:
before:
VFS_WARN_ON_INODE(__builtin_choose_expr((sizeof(int) == sizeof(*(8 ? ((void *)((long)(__builtin_strlen(link)) * 0l)) : (int *)8))), __builtin_strlen(link), __fortify_strlen(link)) != linklen) failed for inode ff32f7c350c8aec8
after:VFS_WARN_ON_INODE(strlen(link) != linklen) failed for inode ff2b81ddca13f338
Mateusz Guzik (3):
vfs: add initial support for CONFIG_VFS_DEBUG
vfs: catch invalid modes in may_open()
vfs: use the new debug macros in inode_set_cached_link()
fs/inode.c | 12 +++++++++++ fs/namei.c | 2 ++ include/linux/fs.h | 16 +++----------- include/linux/vfsdebug.h | 45 ++++++++++++++++++++++++++++++++++++++++ lib/Kconfig.debug | 9 ++++++++ 5 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 include/linux/vfsdebug.h
Signature · 1 line
2.43.0
PATCH v3 1/3 vfs: add initial support for CONFIG_VFS_DEBUG
Small collection of macros taken from mmdebug.h
--- fs/inode.c | 12 +++++++++++ include/linux/fs.h | 1 + include/linux/vfsdebug.h | 45 ++++++++++++++++++++++++++++++++++++++++ lib/Kconfig.debug | 9 ++++++++ 4 files changed, 67 insertions(+) create mode 100644 include/linux/vfsdebug.h
fs/inode.c +12 -0
@@ -2953,3 +2953,15 @@ umode_t mode_strip_sgid(struct mnt_idmap *idmap,return mode & ~S_ISGID ; }EXPORT_SYMBOL (mode_strip_sgid); + +#ifdef CONFIG_DEBUG_VFS +/* +* Dump an inode. +* +* TODO: add a proper inode dumping routine, this is a stub to get debug off the +* ground. +*/ +void dump_inode (struct inode *inode,const char *reason) { +pr_warn ("%s encountered for inode %px" , reason, inode); +} +#endif
include/linux/fs.h +1 -0
@@ -2,6 +2,7 @@#ifndef _LINUX_FS_H#define _LINUX_FS_H +#include <linux/vfsdebug.h> #include <linux/linkage.h> #include <linux/wait_bit.h> #include <linux/kdev_t.h>
include/linux/vfsdebug.h new file +45 -0
45 lines not on this page · raw message
lib/Kconfig.debug +9 -0
@@ -808,6 +808,15 @@ config ARCH_HAS_DEBUG_VM_PGTABLE An architecture should select this when it can successfully build and run DEBUG_VM_PGTABLE. +config DEBUG_VFS + bool "Debug VFS" + depends on DEBUG_KERNEL + help + Enable this to turn on extended checks in the VFS layer that may impact + performance. + + If unsure, say N. + config DEBUG_VM_IRQSOFF def_bool DEBUG_VM && !PREEMPT_RT
Signature · 1 line
2.43.0
PATCH v3 2/3 vfs: catch invalid modes in may_open()
In reply to Mateusz Guzik--- fs/namei.c | 2 ++ 1 file changed, 2 insertions(+)
fs/namei.c +2 -0
@@ -3415,6 +3415,8 @@ static int may_open(struct mnt_idmap *idmap, const struct path *path,if ((acc_mode &MAY_EXEC ) &&path_noexec (path))return -EACCES ;break ; +default : +VFS_BUG_ON_INODE (1 , inode); } error =inode_permission (idmap, inode,MAY_OPEN | acc_mode);
Signature · 1 line
2.43.0
PATCH v3 3/3 vfs: use the new debug macros in inode_set_cached_link()
In reply to Mateusz Guzik--- include/linux/fs.h | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
include/linux/fs.h +2 -13
@@ -792,19 +792,8 @@ struct inode {static inline void inode_set_cached_link (struct inode *inode,char *link,int linklen) { -int testlen; - -/* -* TODO: patch it into a debug-only check if relevant macros show up. -* In the meantime, since we are suffering strlen even on production kernels -* to find the right length, do a fixup if the wrong value got passed. -*/ - testlen =strlen (link); -if (testlen != linklen) { -WARN_ONCE (1 ,"bad length passed for symlink [%s] (got %d, expected %d)" , - link, linklen, testlen); - linklen = testlen; - } +VFS_WARN_ON_INODE (strlen (link) != linklen, inode); +VFS_WARN_ON_INODE (inode->i_opflags &IOP_CACHED_LINK , inode); inode->i_link = link; inode->i_linklen = linklen; inode->i_opflags |=IOP_CACHED_LINK ;
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH v3 3/3] vfs: use the new debug macros in inode_set_cached_link()
kernel test robot noticed the following build errors:
Hi Mateusz,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on next-20250207]
[cannot apply to brauner-vfs/vfs.all viro-vfs/for-next akpm-mm/mm-nonmm-unstable v6.14-rc1] [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/vfs-add-initial-support-for-CONFIG_VFS_DEBUG/20250209-002857 base: linus/master patch link: https://lore.kernel.org/r/20250208162611.628145-4-mjguzik%40gmail.com patch subject: [PATCH v3 3/3] vfs: use the new debug macros in inode_set_cached_link() config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20250210/[email protected]/config) compiler: m68k-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250210/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "dump_inode" [fs/ext4/ext4.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v3 3/3] vfs: use the new debug macros in inode_set_cached_link()
In reply to Mateusz GuzikHi Mateusz,
Quoted 1 line · Mateusz Guzik
Signed-off-by Mateusz Guzik <[email protected]>
Thanks for your patch!
Quoted 8 lines
include/linux/fs.h +0
-2@@ -792,19 +792,8 @@ struct inode {static inline void inode_set_cached_link (struct inode *inode,char *link,int linklen) { -int testlen; -
include/linux/fs.h struct inode { · line 806
Quoted 10 lines
include/linux/fs.h +0
-10-/* -* TODO: patch it into a debug-only check if relevant macros show up. -* In the meantime, since we are suffering strlen even on production kernels -* to find the right length, do a fixup if the wrong value got passed. -*/ - testlen =strlen (link); -if (testlen != linklen) { -WARN_ONCE (1 ,"bad length passed for symlink [%s] (got %d, expected %d)" , - link, linklen, testlen); - linklen = testlen;
This is a (undocumented) change in behavior.
include/linux/fs.h struct inode { · line 795
Quoted 2 lines
include/linux/fs.h +1
-1- } +VFS_WARN_ON_INODE (strlen (link) != linklen, inode);
This change matches the one-line patch summary.
include/linux/fs.h struct inode { · line 796
Quoted 1 line
include/linux/fs.h +1
-0+VFS_WARN_ON_INODE (inode->i_opflags &IOP_CACHED_LINK , inode);
This (unrelated?) change is not described in the patch description.
include/linux/fs.h struct inode { · line 799
Quoted 3 lines
include/linux/fs.h +0
-0inode->i_link = link; inode->i_linklen = linklen; inode->i_opflags |=IOP_CACHED_LINK ;
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds