mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Christian Brauner <brauner@kernel.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux Next Mailing List <linux-next@vger.kernel.org>,
	Shakeel Butt <shakeel.butt@linux.dev>
Subject: linux-next: manual merge of the vfs-brauner tree with the vfs-brauner-fixes tree
Date: Mon, 30 Nov 2026 15:02:25 +0000	[thread overview]
Message-ID: <aw2QAZctYUarWw-4@sirena.org.uk> (raw)

[-- Attachment #1: Type: text/plain, Size: 8155 bytes --]

Hi all,

Today's linux-next merge of the vfs-brauner tree got a conflict in:

  fs/kernfs/dir.c

between commit:

  67f4cae740d65 ("kernfs: clear i_nlink before deactivating removed nodes")

from the vfs-brauner-fixes tree and commits:

  1602b6b565ad9 ("kernfs: clear i_nlink before deactivating removed nodes")
  fe3a3f046eb16 ("kernfs: don't take kernfs_iattr_rwsem to publish KERNFS_REMOVING")
  50d0569d69e09 ("kernfs: update a directory's times without kernfs_iattr_rwsem")

from the vfs-brauner tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

diff --combined fs/kernfs/dir.c
index ecdcca3608bd5,b1015d3eb8f1c..0000000000000
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@@ -37,7 -37,7 +37,7 @@@ static bool __kernfs_active(struct kern
  	return atomic_read(&kn->active) >= 0;
  }
  
- static bool kernfs_active(struct kernfs_node *kn)
+ bool kernfs_active(struct kernfs_node *kn)
  {
  	lockdep_assert_held(&kernfs_root(kn)->kernfs_rwsem);
  	return __kernfs_active(kn);
@@@ -387,6 -387,8 +387,8 @@@ static int kernfs_link_sibling(struct k
  	struct kernfs_node *kn_parent;
  	struct rb_node **node;
  
+ 	lockdep_assert_held_write(&kernfs_root(kn)->kernfs_rwsem);
+ 
  	kn_parent = kernfs_parent(kn);
  	node = &kn_parent->dir.children.rb_node;
  
@@@ -410,11 -412,9 +412,9 @@@
  	rb_insert_color(&kn->rb, &kn_parent->dir.children);
  
  	/* successfully added, account subdir number */
- 	down_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
  	if (kernfs_type(kn) == KERNFS_DIR)
- 		kn_parent->dir.subdirs++;
+ 		WRITE_ONCE(kn_parent->dir.subdirs, kn_parent->dir.subdirs + 1);
  	kernfs_inc_rev(kn_parent);
- 	up_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
  
  	return 0;
  }
@@@ -436,15 -436,15 +436,15 @@@ static bool kernfs_unlink_sibling(struc
  {
  	struct kernfs_node *kn_parent;
  
+ 	lockdep_assert_held_write(&kernfs_root(kn)->kernfs_rwsem);
+ 
  	if (RB_EMPTY_NODE(&kn->rb))
  		return false;
  
  	kn_parent = kernfs_parent(kn);
- 	down_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
  	if (kernfs_type(kn) == KERNFS_DIR)
- 		kn_parent->dir.subdirs--;
+ 		WRITE_ONCE(kn_parent->dir.subdirs, kn_parent->dir.subdirs - 1);
  	kernfs_inc_rev(kn_parent);
- 	up_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
  
  	rb_erase(&kn->rb, &kn_parent->dir.children);
  	RB_CLEAR_NODE(&kn->rb);
@@@ -825,7 -825,6 +825,6 @@@ err_unlock
  int kernfs_add_one(struct kernfs_node *kn)
  {
  	struct kernfs_root *root = kernfs_root(kn);
- 	struct kernfs_iattrs *ps_iattr;
  	struct kernfs_node *parent;
  	bool has_ns;
  	int ret;
@@@ -853,16 -852,7 +852,7 @@@
  	if (ret)
  		goto out_unlock;
  
- 	/* Update timestamps on the parent */
- 	down_write(&root->kernfs_iattr_rwsem);
- 
- 	ps_iattr = parent->iattr;
- 	if (ps_iattr) {
- 		ktime_get_real_ts64(&ps_iattr->ia_ctime);
- 		ps_iattr->ia_mtime = ps_iattr->ia_ctime;
- 	}
- 
- 	up_write(&root->kernfs_iattr_rwsem);
+ 	kernfs_dir_update_times(parent);
  
  	/*
  	 * Activate the new node unless CREATE_DEACTIVATED is requested.
@@@ -1251,9 -1241,12 +1241,12 @@@ static struct dentry *kernfs_iop_lookup
  	struct kernfs_node *parent = dir->i_private;
  	struct kernfs_node *kn;
  	struct kernfs_root *root;
- 	struct inode *inode = NULL;
+ 	struct inode *inode = NULL, *new;
  	const struct ns_common *ns = NULL;
  
+ 	/* allocate outside kernfs_rwsem, see kernfs_get_inode_locked() */
+ 	new = new_inode(dir->i_sb);
+ 
  	root = kernfs_root(parent);
  	down_read(&root->kernfs_rwsem);
  	if (kernfs_ns_enabled(parent))
@@@ -1267,9 -1260,13 +1260,13 @@@
  		 */
  		if (!kernfs_active(kn)) {
  			up_read(&root->kernfs_rwsem);
+ 			iput(new);
  			return NULL;
  		}
- 		inode = kernfs_get_inode(dir->i_sb, kn);
+ 		if (new) {
+ 			inode = kernfs_get_inode_locked(new, kn);
+ 			new = NULL;
+ 		}
  		if (!inode)
  			inode = ERR_PTR(-ENOMEM);
  	}
@@@ -1282,6 -1279,7 +1279,7 @@@
  	if (!IS_ERR(inode))
  		kernfs_set_rev(parent, dentry);
  	up_read(&root->kernfs_rwsem);
+ 	iput(new);
  
  	/* instantiate and hash (possibly negative) dentry */
  	return d_splice_alias(inode, dentry);
@@@ -1292,19 -1290,62 +1290,62 @@@ static struct dentry *kernfs_iop_mkdir(
  				       umode_t mode)
  {
  	struct kernfs_node *parent = dir->i_private;
- 	struct kernfs_syscall_ops *scops = kernfs_root(parent)->syscall_ops;
+ 	struct kernfs_root *root = kernfs_root(parent);
+ 	struct kernfs_syscall_ops *scops = root->syscall_ops;
+ 	const struct ns_common *ns = NULL;
+ 	struct kernfs_node *kn;
+ 	struct inode *inode;
  	int ret;
  
  	if (!scops || !scops->mkdir)
- 		return ERR_PTR(-EPERM);
+ 		return ERR_PTR(-EOPNOTSUPP);
  
- 	if (!kernfs_get_active(parent))
+ 	/* allocated up front so that we never fail after creating the node */
+ 	inode = new_inode(dir->i_sb);
+ 	if (!inode)
+ 		return ERR_PTR(-ENOMEM);
+ 
+ 	if (!kernfs_get_active(parent)) {
+ 		iput(inode);
  		return ERR_PTR(-ENODEV);
+ 	}
  
  	ret = scops->mkdir(parent, dentry->d_name.name, mode);
  
  	kernfs_put_active(parent);
- 	return ERR_PTR(ret);
+ 	if (ret) {
+ 		iput(inode);
+ 		return ERR_PTR(ret);
+ 	}
+ 
+ 	/*
+ 	 * Find the node that ->mkdir() created.  The parent's i_rwsem is
+ 	 * held, so only a removal from inside the kernel can make it go
+ 	 * away again, and then the open fails like one of a removed
+ 	 * directory.
+ 	 */
+ 	scoped_guard(rwsem_read, &root->kernfs_rwsem) {
+ 		if (kernfs_ns_enabled(parent))
+ 			ns = kernfs_info(dir->i_sb)->ns;
+ 		kn = kernfs_find_ns(parent, dentry->d_name.name, ns);
+ 		if (kn) {
+ 			inode = kernfs_get_inode_locked(inode, kn);
+ 		} else {
+ 			iput(inode);
+ 			inode = NULL;
+ 		}
+ 	}
+ 	if (!inode)
+ 		return ERR_PTR(-ESTALE);
+ 
+ 	/*
+ 	 * We may race with kernfs_fh_to_dentry() which calls d_obtain_alias(),
+ 	 * so the inode may already have a disconnected alias. Use
+ 	 * d_splice_alias() to move it into place, which does not accept
+ 	 * hashed dentries, so drop the negative dentry first.
+ 	 */
+ 	d_drop(dentry);
+ 	return d_splice_alias(inode, dentry);
  }
  
  static int kernfs_iop_rmdir(struct inode *dir, struct dentry *dentry)
@@@ -1555,21 -1596,21 +1596,21 @@@ static void __kernfs_remove(struct kern
  
  	/*
  	 * Prevent new usage by marking all nodes removing and deactivating.
+ 	 * KERNFS_REMOVING is only set here, under kernfs_rwsem.
+ 	 * kernfs_dir_nlink() reads it without that lock.
  	 *
  	 * Clear i_nlink before a node turns inactive.  From then on
  	 * kernfs_dop_revalidate() fails and a lookup can kill the node's
  	 * dentries, and only a dentry dying with i_nlink at 0 sends
  	 * IN_DELETE_SELF.
  	 */
- 	down_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
  	pos = NULL;
  	while ((pos = kernfs_next_descendant_post(pos, kn))) {
  		kernfs_clear_inode_nlink(pos);
- 		pos->flags |= KERNFS_REMOVING;
+ 		WRITE_ONCE(pos->flags, pos->flags | KERNFS_REMOVING);
  		if (kernfs_active(pos))
  			atomic_add(KN_DEACTIVATED_BIAS, &pos->active);
  	}
- 	up_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
  
  	/* deactivate and unlink the subtree node-by-node */
  	do {
@@@ -1590,18 -1631,8 +1631,8 @@@
  		 * to decide who's responsible for cleanups.
  		 */
  		if (!parent || kernfs_unlink_sibling(pos)) {
- 			struct kernfs_iattrs *ps_iattr =
- 				parent ? parent->iattr : NULL;
- 
- 			down_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
- 
- 			/* update timestamps on the parent */
- 			if (ps_iattr) {
- 				ktime_get_real_ts64(&ps_iattr->ia_ctime);
- 				ps_iattr->ia_mtime = ps_iattr->ia_ctime;
- 			}
- 
- 			up_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
+ 			if (parent)
+ 				kernfs_dir_update_times(parent);
  			kernfs_put(pos);
  		}
  

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

             reply	other threads:[~2026-11-30 15:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 15:02 Mark Brown [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-11-30 15:01 Mark Brown
2026-11-20 14:38 Mark Brown
2026-11-16 15:05 Mark Brown
2026-10-29 14:17 Mark Brown
2026-03-25 13:29 Mark Brown
2026-03-25 15:13 ` Darrick J. Wong
2026-03-26 13:24   ` Christian Brauner
2026-03-26 13:29     ` Mark Brown
2026-03-26  5:19 ` Christoph Hellwig
2024-06-20 11:34 Mark Brown
2024-06-20 12:50 ` Mark Brown

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=aw2QAZctYUarWw-4@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=brauner@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=shakeel.butt@linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®