From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796050949; b=Z1+tjDo0dKhiOTS9s8nPHkFoITyOE9CIsWnlIL+Y5D4a6VJi0o+6O81CaUW++C12UjKP AMm3nfi6lKlzfL5peJEEHhSuD3VXyKh4llkO+xt7VIAp2RsGfJiFwRomcbz37b1P9orTN lrI+7dLc9dFR5Icfr/G6jEJGFMcAIg1/F5td452szt65nmQ27B8qQfJprQrwb2iLVXcss kMC9wQuAqFFPKZXGrq8cM/PeD5eFj1dWDuCPFE0jjEnmMliMvZQvOBxUTeLE+g9quxqEo BUupFKvQqWKRjUuEBzUlRpIVC4Z9omIvpVtKeYYgXhraBwSNTr3CqWV2Q3bYM3el90A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796050949; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: MIME-Version:Content-Type:Content-Disposition; bh=oGSd9RxjsZJl0F3w7dM7jX39bKeaHaco2rHgZjJon+8=; b=mMKbTKJNimxSR/ABkatFjXVrQ10dvgbG4VGGr9TRC88AzD0wEQ+mousEWXAi6j1hVXYQ z1iHTTsBlAqXYsn1Ur5pUZSb/VmP7BYarM94KY0hrgMUb/CsV9piuiuCzJ2odzLLDNDhY 5o/y1ub1SethptFwysyGGrWIh8FoGziAhsJPL3rKIdgvNOsjT1lQf9Xymzsjvm3Z8AQV4 Ga37Cz6Z/JEC0J9GDLXS4zat5oQtJCa7ug/lf4yuM5lzsnM0kWfmCbr/OlShGO3ldmquX J+N1AQUDOVgNQW+A62jGYSWzMZUgaS0RSnAHU2HMvtbcYYnV7bf/sQ/GMy1hD4TIVSQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NELujW04; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A37E9606A31C; Mon, 30 Nov 2026 15:02:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NELujW04 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED1D91F000C1; Mon, 30 Nov 2026 15:02:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796050949; bh=oGSd9RxjsZJl0F3w7dM7jX39bKeaHaco2rHgZjJon+8=; h=Date:From:To:Cc:Subject; b=NELujW04VlnlB8PtY0gZNJ73BqrHZ11TLx1id4om10J/WUAoikAFTL/aVDIw9Jz0T FK+34++ilA54Q68+Ue1pujyeMWokNi7x96eFTAQH97Exjun0uPZELej0AvBVZtBnkE u7IzX8tVeVoxNcDtLPSGkVvq0lnZ7c1iIYzcq07I6nws6M/3Mjn2xr6Wioh+MrUBO9 iodLqRAv6oaEeSKL/dkGbhktYPlcX1Ipr0KgUEQzcjFsjztDLJ1D9aNWFvOQyN7Hiu FUCFmmkF8/70xEhvGeP7nUu7uBFiwmk9uISOxQQ3P5xHxD4WtKR6QESESeE1shMnPa oZp19qq3NuxhQ== Date: Mon, 30 Nov 2026 15:02:25 +0000 From: Mark Brown To: Christian Brauner Cc: Linux Kernel Mailing List , Linux Next Mailing List , Shakeel Butt Subject: linux-next: manual merge of the vfs-brauner tree with the vfs-brauner-fixes tree Message-ID: X-Mailing-List: linux-next@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="KIdQO+oQt0KUF/CG" Content-Disposition: inline --KIdQO+oQt0KUF/CG Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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") =66rom 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_R= EMOVING") 50d0569d69e09 ("kernfs: update a directory's times without kernfs_iattr_r= wsem") =66rom 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) >=3D 0; } =20 - 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; =20 + lockdep_assert_held_write(&kernfs_root(kn)->kernfs_rwsem); +=20 kn_parent =3D kernfs_parent(kn); node =3D &kn_parent->dir.children.rb_node; =20 @@@ -410,11 -412,9 +412,9 @@@ rb_insert_color(&kn->rb, &kn_parent->dir.children); =20 /* successfully added, account subdir number */ - down_write(&kernfs_root(kn)->kernfs_iattr_rwsem); if (kernfs_type(kn) =3D=3D 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); =20 return 0; } @@@ -436,15 -436,15 +436,15 @@@ static bool kernfs_unlink_sibling(struc { struct kernfs_node *kn_parent; =20 + lockdep_assert_held_write(&kernfs_root(kn)->kernfs_rwsem); +=20 if (RB_EMPTY_NODE(&kn->rb)) return false; =20 kn_parent =3D kernfs_parent(kn); - down_write(&kernfs_root(kn)->kernfs_iattr_rwsem); if (kernfs_type(kn) =3D=3D 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); =20 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 =3D 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; =20 - /* Update timestamps on the parent */ - down_write(&root->kernfs_iattr_rwsem); -=20 - ps_iattr =3D parent->iattr; - if (ps_iattr) { - ktime_get_real_ts64(&ps_iattr->ia_ctime); - ps_iattr->ia_mtime =3D ps_iattr->ia_ctime; - } -=20 - up_write(&root->kernfs_iattr_rwsem); + kernfs_dir_update_times(parent); =20 /* * 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 =3D dir->i_private; struct kernfs_node *kn; struct kernfs_root *root; - struct inode *inode =3D NULL; + struct inode *inode =3D NULL, *new; const struct ns_common *ns =3D NULL; =20 + /* allocate outside kernfs_rwsem, see kernfs_get_inode_locked() */ + new =3D new_inode(dir->i_sb); +=20 root =3D 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 =3D kernfs_get_inode(dir->i_sb, kn); + if (new) { + inode =3D kernfs_get_inode_locked(new, kn); + new =3D NULL; + } if (!inode) inode =3D 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); =20 /* 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 =3D dir->i_private; - struct kernfs_syscall_ops *scops =3D kernfs_root(parent)->syscall_ops; + struct kernfs_root *root =3D kernfs_root(parent); + struct kernfs_syscall_ops *scops =3D root->syscall_ops; + const struct ns_common *ns =3D NULL; + struct kernfs_node *kn; + struct inode *inode; int ret; =20 if (!scops || !scops->mkdir) - return ERR_PTR(-EPERM); + return ERR_PTR(-EOPNOTSUPP); =20 - if (!kernfs_get_active(parent)) + /* allocated up front so that we never fail after creating the node */ + inode =3D new_inode(dir->i_sb); + if (!inode) + return ERR_PTR(-ENOMEM); +=20 + if (!kernfs_get_active(parent)) { + iput(inode); return ERR_PTR(-ENODEV); + } =20 ret =3D scops->mkdir(parent, dentry->d_name.name, mode); =20 kernfs_put_active(parent); - return ERR_PTR(ret); + if (ret) { + iput(inode); + return ERR_PTR(ret); + } +=20 + /* + * 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 =3D kernfs_info(dir->i_sb)->ns; + kn =3D kernfs_find_ns(parent, dentry->d_name.name, ns); + if (kn) { + inode =3D kernfs_get_inode_locked(inode, kn); + } else { + iput(inode); + inode =3D NULL; + } + } + if (!inode) + return ERR_PTR(-ESTALE); +=20 + /* + * 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); } =20 static int kernfs_iop_rmdir(struct inode *dir, struct dentry *dentry) @@@ -1555,21 -1596,21 +1596,21 @@@ static void __kernfs_remove(struct kern =20 /* * 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 =3D NULL; while ((pos =3D kernfs_next_descendant_post(pos, kn))) { kernfs_clear_inode_nlink(pos); - pos->flags |=3D 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); =20 /* 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 =3D - parent ? parent->iattr : NULL; -=20 - down_write(&kernfs_root(kn)->kernfs_iattr_rwsem); -=20 - /* update timestamps on the parent */ - if (ps_iattr) { - ktime_get_real_ts64(&ps_iattr->ia_ctime); - ps_iattr->ia_mtime =3D ps_iattr->ia_ctime; - } -=20 - up_write(&kernfs_root(kn)->kernfs_iattr_rwsem); + if (parent) + kernfs_dir_update_times(parent); kernfs_put(pos); } =20 --KIdQO+oQt0KUF/CG Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAmsNkAAACgkQJNaLcl1U h9Cdowf/UN05UO7mtpozd4+HALGMYjsmnfC1sEM0ZvFl9uBL3EhEqx7lC7Gcu/FG 8YVb0/N1Ox950QLN3REhMRrLlVjuSSFahRVYrx/MQOlfKELD28tfDucdtBp/K70T 7+Lf+K189Jrep0zD1k8aapte3xVwgpEQ/rut/sKLnslOaScO7so3Jq9BN2KhYuun M3tVFCldGGadhSkxrLVU2DMj4L2hbDNb95q9O5BpWZGOM7nYNJu0kB9mpQ3BZwdc V8lxktUgDshSed9iUTOTzQ8jccEFg8LQnwJES7z/FFUenqruCZlilp9Huqk5NXEZ T8eU5hoaNJM2I0e5CWacN9Erf2mTdA== =Sh4r -----END PGP SIGNATURE----- --KIdQO+oQt0KUF/CG--