Skip to content

Commit 822c115

Browse files
committed
Merge patch series "CONFIG_DEBUG_VFS at last"
Mateusz Guzik <[email protected]> says: 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. * patches from https://lore.kernel.org/r/[email protected]: vfs: use the new debug macros in inode_set_cached_link() vfs: catch invalid modes in may_open() vfs: add initial support for CONFIG_DEBUG_VFS Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
2 parents 2014c95 + 3eb7e95 commit 822c115

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed

fs/inode.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,3 +2953,18 @@ umode_t mode_strip_sgid(struct mnt_idmap *idmap,
29532953
return mode & ~S_ISGID;
29542954
}
29552955
EXPORT_SYMBOL(mode_strip_sgid);
2956+
2957+
#ifdef CONFIG_DEBUG_VFS
2958+
/*
2959+
* Dump an inode.
2960+
*
2961+
* TODO: add a proper inode dumping routine, this is a stub to get debug off the
2962+
* ground.
2963+
*/
2964+
void dump_inode(struct inode *inode, const char *reason)
2965+
{
2966+
pr_warn("%s encountered for inode %px", reason, inode);
2967+
}
2968+
2969+
EXPORT_SYMBOL(dump_inode);
2970+
#endif

fs/namei.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,6 +3415,8 @@ static int may_open(struct mnt_idmap *idmap, const struct path *path,
34153415
if ((acc_mode & MAY_EXEC) && path_noexec(path))
34163416
return -EACCES;
34173417
break;
3418+
default:
3419+
VFS_BUG_ON_INODE(1, inode);
34183420
}
34193421

34203422
error = inode_permission(idmap, inode, MAY_OPEN | acc_mode);

include/linux/fs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef _LINUX_FS_H
33
#define _LINUX_FS_H
44

5+
#include <linux/vfsdebug.h>
56
#include <linux/linkage.h>
67
#include <linux/wait_bit.h>
78
#include <linux/kdev_t.h>
@@ -791,6 +792,8 @@ struct inode {
791792

792793
static inline void inode_set_cached_link(struct inode *inode, char *link, int linklen)
793794
{
795+
VFS_WARN_ON_INODE(strlen(link) != linklen, inode);
796+
VFS_WARN_ON_INODE(inode->i_opflags & IOP_CACHED_LINK, inode);
794797
inode->i_link = link;
795798
inode->i_linklen = linklen;
796799
inode->i_opflags |= IOP_CACHED_LINK;

include/linux/vfsdebug.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef LINUX_VFS_DEBUG_H
3+
#define LINUX_VFS_DEBUG_H 1
4+
5+
#include <linux/bug.h>
6+
7+
struct inode;
8+
9+
#ifdef CONFIG_DEBUG_VFS
10+
void dump_inode(struct inode *inode, const char *reason);
11+
12+
#define VFS_BUG_ON(cond) BUG_ON(cond)
13+
#define VFS_WARN_ON(cond) (void)WARN_ON(cond)
14+
#define VFS_WARN_ON_ONCE(cond) (void)WARN_ON_ONCE(cond)
15+
#define VFS_WARN_ONCE(cond, format...) (void)WARN_ONCE(cond, format)
16+
#define VFS_WARN(cond, format...) (void)WARN(cond, format)
17+
18+
#define VFS_BUG_ON_INODE(cond, inode) ({ \
19+
if (unlikely(!!(cond))) { \
20+
dump_inode(inode, "VFS_BUG_ON_INODE(" #cond")");\
21+
BUG_ON(1); \
22+
} \
23+
})
24+
25+
#define VFS_WARN_ON_INODE(cond, inode) ({ \
26+
int __ret_warn = !!(cond); \
27+
\
28+
if (unlikely(__ret_warn)) { \
29+
dump_inode(inode, "VFS_WARN_ON_INODE(" #cond")");\
30+
WARN_ON(1); \
31+
} \
32+
unlikely(__ret_warn); \
33+
})
34+
#else
35+
#define VFS_BUG_ON(cond) BUILD_BUG_ON_INVALID(cond)
36+
#define VFS_WARN_ON(cond) BUILD_BUG_ON_INVALID(cond)
37+
#define VFS_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond)
38+
#define VFS_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond)
39+
#define VFS_WARN(cond, format...) BUILD_BUG_ON_INVALID(cond)
40+
41+
#define VFS_BUG_ON_INODE(cond, inode) VFS_BUG_ON(cond)
42+
#define VFS_WARN_ON_INODE(cond, inode) BUILD_BUG_ON_INVALID(cond)
43+
#endif /* CONFIG_DEBUG_VFS */
44+
45+
#endif

lib/Kconfig.debug

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,15 @@ config ARCH_HAS_DEBUG_VM_PGTABLE
808808
An architecture should select this when it can successfully
809809
build and run DEBUG_VM_PGTABLE.
810810

811+
config DEBUG_VFS
812+
bool "Debug VFS"
813+
depends on DEBUG_KERNEL
814+
help
815+
Enable this to turn on extended checks in the VFS layer that may impact
816+
performance.
817+
818+
If unsure, say N.
819+
811820
config DEBUG_VM_IRQSOFF
812821
def_bool DEBUG_VM && !PREEMPT_RT
813822

0 commit comments

Comments
 (0)