All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shakeel Butt <shakeel.butt@linux.dev>
To: Christian Brauner <brauner@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Tejun Heo <tj@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Ian Kent <raven@themaw.net>, Jori Koolstra <jkoolstra@xs4all.nl>,
	"T . J . Mercier" <tjmercier@google.com>,
	Meta kernel team <kernel-team@meta.com>,
	cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	driver-core@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] kernfs: don't look for open files of directories when draining
Date: Fri,  4 Dec 2026 13:10:30 -0800	[thread overview]
Message-ID: <20261204211034.3436390-2-shakeel.butt@linux.dev> (raw)
In-Reply-To: <20261204211034.3436390-1-shakeel.butt@linux.dev>

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@linux.dev>
---
 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


  reply	other threads:[~2026-12-04 21:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 21:10 [PATCH 0/3] kernfs: list directories without kernfs_rwsem Shakeel Butt
2026-12-04 21:10 ` Shakeel Butt [this message]
2026-12-04 21:10 ` [PATCH 2/3] kernfs: add a sequence count to directories Shakeel Butt
2026-12-04 21:10 ` [PATCH 3/3] kernfs: list directories without kernfs_rwsem Shakeel Butt
2026-12-05  9:01 ` [PATCH 0/3] " Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204211034.3436390-2-shakeel.butt@linux.dev \
    --to=shakeel.butt@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=jkoolstra@xs4all.nl \
    --cc=kernel-team@meta.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=raven@themaw.net \
    --cc=tj@kernel.org \
    --cc=tjmercier@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.