From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.121.94.186 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796230957; b=jeFZ7K7Vg/LCAb3kpDs/YEBlTkYOFCnj4n5+yAsPH45mE5GtSL3hAlSf9hUtKMmz7n0n wQPih4XPw42IVdG8Ks+H3gT4x/QR8O+4lRLidziORaxkEmOtXc9NJczrvYux+j9DUYLPj +DYDN+QMHJuyuia+jVXkmny/1Hb2NVHBmR6/ioMAJkthMR6FjFyBxoc2sZRlDFbf+Y9s0 8MGXASSdPltPsHp5oWTQq3XfzjeBiv4zQ+6oW12meyr1SOTOHO3yVgjjYJ1ASFSP3NYMF 2eQmKMN8cczPLIXvj3P+8O0n1Rw3dZYa5j0OsE0HNiHk5IfeA2vaBqCMN77+wnGEqhw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796230957; h=DMARC-Filter:X-KPN-MessageId:Received:Received:DKIM-Signature: X-KPN-MID:X-CMASSUN:X-KPN-VerifiedSender:Received:Date:From:To:Cc: Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:X-Priority:Importance:X-Originating-IP; bh=QYrbrmkH6Z5lm7Hn4Irq4PaG9Z39v78PylmR7WpT+Uo=; b=yG3gVBbWqzUZ4IuWdFOu7zd0JL+zBD6AN8D+ztSMgfV2IYFG0g9NOP1omy2yK/Mse5I4 wfc6ttCztuh1NbFOEDvuJK3cfaAA18wxs6gpSCy0ORLJn578njdojpT25U5qQNhNdBaz0 xLqyerq0LEyGCNFXRhIm5fo+btzzBeiFN+D2uPKcPZRrXIqX2uZ/2Nf5mevmpqIfKjq8J qUu8KMZcZJVHXcwtirOlO6R3N98RY0+TQGBBjPv8/fAwJn6A7E/CBEYBflzTG7QkTExJy JMwbqCKRG0A8Ez/nae7eiFHjJ6U604Lwgv8Ykv1ShECxF0GLXM58MgSsPvhhnpWpm1w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=xs4all.nl; spf=pass smtp.mailfrom=xs4all.nl; dkim=pass header.d=xs4all.nl header.i=@xs4all.nl header.a=rsa-sha256 header.s=xs4all01 header.b=fQTQ1Wxx; arc=none smtp.remote-ip=195.121.94.186 Received: from ewsoutbound.kpnmail.nl (ewsoutbound.kpnmail.nl [195.121.94.186]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B8EE606A327 for ; Wed, 2 Dec 2026 17:02:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5B8EE606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xs4all.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xs4all.nl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=xs4all.nl header.i=@xs4all.nl header.a=rsa-sha256 header.s=xs4all01 header.b=fQTQ1Wxx X-KPN-MessageId: 2bd274c7-ee72-11f1-b88c-00505699b430 Received: from mta.kpnmail.nl (unknown [10.31.161.189]) by ewsoutbound.so.kpn.org (Halon) with ESMTPS id 2bd274c7-ee72-11f1-b88c-00505699b430; Wed, 02 Dec 2026 18:02:35 +0100 (CET) Received: from mtaoutbound.kpnmail.nl (unknown [10.128.135.190]) by mta.kpnmail.nl (Halon) with ESMTP id 2bd10abd-ee72-11f1-b7ab-0050569981f5; Wed, 02 Dec 2026 18:02:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=xs4all01; h=content-type:mime-version:subject:message-id:to:from:date; bh=QYrbrmkH6Z5lm7Hn4Irq4PaG9Z39v78PylmR7WpT+Uo=; b=fQTQ1WxxT5AUd6GLcYrCIO8au1hC9WVOy3vxVXZYoPOgzRd7c8IrJhTlcJ/EXapuIVoH60LYwkVjZ cHcRof/BbtO5MEw+N6kb/dkOfu9crkDugUjV/IoK/vZf/CCl5W4LKVRFmKlVQ1dsCllgmab8VaoC9y MZDpWl8h+ubstwGnSbvwIB/3aWCpKxIR5mOpl5U5ECYqX+NeMU8sc0T3mxuzI+/zldlkePnaQ7QIBB iAu3waz6ke4gKaQVbSgCDfWC7q2Z2jsOuBWlRHcS6fi3FLru45hQQ5GBjast7epEUVR6xZYv13M8rJ Ht0qFVXk63RRpb1xmLFkxMzVUyun7eQ== X-KPN-MID: 33|H538QPT1TGZj9qSRmrwhUYoGNsZiIvGmjvF/PBooQnXc5G6FyQtBQRxIq13DzLO gYGDrm/lMwnNn0g5/RMUWWg== X-CMASSUN: 33|rciqdbgYEjelff6OWFFGcT2uVERpK4w/TEiGqEsLr0kar0zJzTwKvcDHbdd1uar S0y/XzjJwMuvDz3orFZKHpA== X-KPN-VerifiedSender: Yes Received: from cpxoxapps-mh07 (cpxoxapps-mh07.personalcloud.so.kpn.org [10.128.135.213]) by mtaoutbound.kpnmail.nl (Halon) with ESMTPSA id 2bc1261b-ee72-11f1-94bb-005056995d6c; Wed, 02 Dec 2026 18:02:35 +0100 (CET) Date: Wed, 2 Dec 2026 18:02:35 +0100 (CET) From: Jori Koolstra To: Shakeel Butt , Christian Brauner Cc: Greg Kroah-Hartman , Tejun Heo , Ian Kent , "T . J . Mercier" , Meta kernel team , linux-fsdevel@vger.kernel.org, driver-core@lists.linux.dev, linux-kernel@vger.kernel.org Message-ID: <999416285.3598292.1796230955292@kpc.webmail.kpnmail.nl> In-Reply-To: <20261118220154.2965621-3-shakeel.butt@linux.dev> References: <20261118220154.2965621-1-shakeel.butt@linux.dev> <20261118220154.2965621-3-shakeel.butt@linux.dev> Subject: Re: [PATCH 2/6] kernfs: don't copy times and link count into the inode on refresh X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Normal > Op 18-11-2026 23:01 CET schreef Shakeel Butt : > > > Every permission check and getattr copies a node's times, if it has > iattrs, and a directory's link count into the shared inode. Since the > previous patch, getattr reports both from the node, and permission > checks use only the mode, owner and group. The only other users of a > kernfs inode's times are the mmap write fault and the atime update, > which just update the inode's copy. The inode's link count matters > only to the IN_DELETE_SELF check, which needs 0 once __kernfs_remove() > clears it. > > Copy only the mode, owner and group, which also takes work off every > permission check. Set a directory's link count when its inode is set > up. Every caller that sets up a directory inode holds kernfs_rwsem, > and __kernfs_remove() holds it for writing while it clears the count, > so the two cannot race. Assert that, and note in the kernfs_get_inode() > comment that it is not for directories; its one user outside kernfs, > cgroup_may_write(), gets a file. > > getattr fell back to the inode's link count for a directory being > removed. That count is no longer kept up to date, so report 0 instead: > KERNFS_REMOVING is never cleared, and lookups already fail. > > Signed-off-by: Shakeel Butt > --- > fs/kernfs/inode.c | 32 ++++++++++++++++++-------------- > 1 file changed, 18 insertions(+), 14 deletions(-) > > diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c > index 3616161a56cb..2d8da8b4e7da 100644 > --- a/fs/kernfs/inode.c > +++ b/fs/kernfs/inode.c > @@ -157,27 +157,23 @@ static inline void set_inode_attr(struct inode *inode, > { > inode->i_uid = attrs->ia_uid; > inode->i_gid = attrs->ia_gid; > - inode_set_atime_to_ts(inode, attrs->ia_atime); > - inode_set_mtime_to_ts(inode, attrs->ia_mtime); > - inode_set_ctime_to_ts(inode, attrs->ia_ctime); > } > > /* > - * Get the link count of a directory: its subdirectories plus two. > - * Return false for other nodes and for a directory being removed. > + * Get a directory's link count: its subdirectories plus two, or 0 once > + * its removal has started. Return false for other nodes. > */ > static bool kernfs_dir_nlink(struct kernfs_node *kn, unsigned int *nlink) > { > - if (kernfs_type(kn) != KERNFS_DIR || (kn->flags & KERNFS_REMOVING)) > + if (kernfs_type(kn) != KERNFS_DIR) > return false; > - *nlink = kn->dir.subdirs + 2; > + *nlink = (kn->flags & KERNFS_REMOVING) ? 0 : kn->dir.subdirs + 2; > return true; > } > > static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode) > { > struct kernfs_iattrs *attrs; > - unsigned int nlink; > > inode->i_mode = kn->mode; > attrs = kernfs_iattrs_noalloc(kn); > @@ -187,9 +183,6 @@ static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode) > * persistent copy in kernfs_node. > */ > set_inode_attr(inode, attrs); > - > - if (kernfs_dir_nlink(kn, &nlink)) > - set_nlink(inode, nlink); > } > > int kernfs_iop_getattr(const struct mnt_idmap *idmap, > @@ -207,8 +200,8 @@ int kernfs_iop_getattr(const struct mnt_idmap *idmap, > generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat); > > /* > - * Other refreshes may store older times or link counts in the > - * inode at the same time. Report the values from the node. > + * The inode's times and link count are not kept up to date. > + * Report them from the node. > */ > attrs = kernfs_iattrs_noalloc(kn); > if (attrs) { > @@ -225,6 +218,8 @@ int kernfs_iop_getattr(const struct mnt_idmap *idmap, > > static void kernfs_init_inode(struct kernfs_node *kn, struct inode *inode) > { > + unsigned int nlink; > + > kernfs_get(kn); > inode->i_private = kn; > inode->i_mapping->a_ops = &ram_aops; > @@ -238,6 +233,14 @@ static void kernfs_init_inode(struct kernfs_node *kn, struct inode *inode) > /* initialize inode according to type */ > switch (kernfs_type(kn)) { > case KERNFS_DIR: > + /* > + * The link count is set only here; getattr reports it from > + * the node. Holding kernfs_rwsem keeps this from racing > + * with __kernfs_remove() clearing it. > + */ > + lockdep_assert_held(&kernfs_root(kn)->kernfs_rwsem); > + if (kernfs_dir_nlink(kn, &nlink)) > + set_nlink(inode, nlink); This actual i_nlink value is not intended to mean anything anymore right? It should just set the i_nlink > 0. The current code would suggest to me that somehow there's an attempt to keep the i_nlink value to mean something, unlike the comment says. I think there is only one other user of kernfs_dir_nlink(), so you could then also get rid of that function and set some special value here. Also, the kerneldoc of kernfs_add_one() (fs/kernfs/dir.c:818) still says: This function increments nlink of the parent's inode if @kn is a directory as well. It's a bit of a nit, so anyway: Reviewed-by: Jori Koolstra (CIQ) > inode->i_op = &kernfs_dir_iops; > inode->i_fop = &kernfs_dir_fops; > if (kn->flags & KERNFS_EMPTY_DIR) > @@ -267,7 +270,8 @@ static void kernfs_init_inode(struct kernfs_node *kn, struct inode *inode) > * locked. > * > * Locking: > - * Kernel thread context (may sleep). > + * Kernel thread context (may sleep). Not for directories: kernfs > + * sets up their inodes itself, with kernfs_rwsem held. > * > * Return: > * Pointer to allocated inode on success, %NULL on failure. > -- > 2.53.1-Meta