[PATCH 1/3] kernfs: don't look for open files of directories when draining
From: Shakeel Butt
Date: Fri Dec 04 2026 - 16:11:01 EST
kernfs_drain() calls kernfs_should_drain_open_files() for every node it
removes, directories and symlinks included, and that reads
kn->attr.open from the node's union. For a directory, the field
overlaps dir.children.rb_node, which is NULL by the time a directory is
drained, as its children are removed first. So it works, but only
because of how kernfs_elem_dir is laid out. The next patch adds a
sequence count to it, and with lockdep, attr.open then overlaps data
that is not zero.
Only files have open nodes. Check the type first.
Signed-off-by: Shakeel Butt <shakeel.butt@xxxxxxxxx>
---
fs/kernfs/file.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
index 08c29eb3f435..b141c09aadbe 100644
--- a/fs/kernfs/file.c
+++ b/fs/kernfs/file.c
@@ -837,6 +837,13 @@ bool kernfs_should_drain_open_files(struct kernfs_node *kn)
struct kernfs_open_node *on;
bool ret;
+ /*
+ * Only files have open nodes. For a directory or a symlink,
+ * @kn->attr.open would read another member of the union.
+ */
+ if (kernfs_type(kn) != KERNFS_FILE)
+ return false;
+
/*
* @kn being deactivated guarantees that @kn->attr.open can't change
* beneath us making the lockless test below safe.
--
2.53.1-Meta