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=1796230525; b=nLn9xVirQbd948btb+CRPrBcxfNW7ll1um/dsxDqUprRGI7IVvxBUHylkVmYuYjsvy39 i9Up47l4Ysl1GiT1aO2kyFDHUIP92nnPxr8nkpgMzTi1Aoy+MT0gj2/nX8/S6HGLbbpGD D1zWkPR/mWHVOgndG5QQE3C9C9r48z8evqVufDsmBs9Eb81jbhppRdwVguOarXtF1ZLpg mkifP/ZkcnC4nC1vM+wYonVCzXdS8u9Q2ClOskiXB0l/ELbtTMQJumkbytmbpFg4A9UK4 Lc5FAqTEbQJ6GANZzK+YAfvrjMrkegc//0XmkDzGVS0+MNq4sYoaIqpodiYcNcDWAsg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796230525; 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=vxpIVcuN8wvqRIbRuRf/opXbeabLcO8JxmwbeN+M4LQ=; b=Z2Le7jIOwU1kVou0PDtUtQQekPma0aad829wVxGjO07Qt0SNXpBnnTZuY/p0eaTUn7Tp e6Mj16ecmaZ/hsLhcp6aQhRkLoy8K+FcPiLDMZwtEn9gJp65SVTYdjtwkWFEMzSouD4Vc 4eQeTLR95os4z4Pcj3Pf5bpu6uUfTgpb9hzJmYjYIOuZkR1qmmE4mxE9REuNekNEFtK7K qgx2Oqa5+G2Mpzxbm24xJGfJxYoZJQV9MLav42cXzksZzT9+pDKy3msfr2Ep1B0SkTAJp k/+iKXA31MwINYTfjLLdrnAPPz6YCQ1l4qQfsLQLsPYDeIFt9F5KHT7aZWgwY+47eVw== 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=YWVKd5ld; 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 D6839606A31A for ; Wed, 2 Dec 2026 16:55:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D6839606A31A 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, unprotected) header.d=xs4all.nl header.i=@xs4all.nl header.a=rsa-sha256 header.s=xs4all01 header.b=YWVKd5ld X-KPN-MessageId: 294a3687-ee71-11f1-b88c-00505699b430 Received: from mta.kpnmail.nl (unknown [10.31.161.188]) by ewsoutbound.so.kpn.org (Halon) with ESMTPS id 294a3687-ee71-11f1-b88c-00505699b430; Wed, 02 Dec 2026 17:55:21 +0100 (CET) Received: from mtaoutbound.kpnmail.nl (unknown [10.128.135.189]) by mta.kpnmail.nl (Halon) with ESMTP id 294c1828-ee71-11f1-be6b-00505699693e; Wed, 02 Dec 2026 17:55:21 +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=vxpIVcuN8wvqRIbRuRf/opXbeabLcO8JxmwbeN+M4LQ=; b=YWVKd5ldzu9FwNjUzTHCAHQnUPif8CdKpgnY6xF+AtILThOCnaw7l0LlRxaHUT9rcYyEOwXrxj2mq jg2WUfKR1ah96xJlauK4d3ZeCujXIg78fXSw0kOMbzpBuseHjre+ramglBt83CH69rmvXiICseaJmN n8N4MrjON5qXAiP2sdNmqzDE5Tx8DGioGjKObfewWMlqfBtiYlkrS+Ok4s6n1c0DsaehHDeP9qbvWK WfDBgmxqcXL6bU0ayo6981VJkcrUzYb/f3F8O2yNpQijSK73B3hYxjL1LlmKku07YsB1tklZjJ7v43 XuvYFNTX4zZpP8HJ7pS5qJngm+GAt2g== X-KPN-MID: 33|nXroYpl46Tk9otwXzB6P6Ks/jhKlYzXlt2fsqfV+t2wzoZ95jIrcJtegqDD0FfS OChuA1xw/aB3nZ3+WBBXZ03ocr5EtM326E6/FWSqeSdA= X-CMASSUN: 33|LNNBNPCZ4/e9LO8VWh7Dh0dDfFgjqkqf3ATXkqZ5zagb5GSk7sdre8H02ECmCaD 0t/RHJOia0a0gtJRqxVzvrg== 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 29427fcf-ee71-11f1-acfd-00505699eff2; Wed, 02 Dec 2026 17:55:21 +0100 (CET) Date: Wed, 2 Dec 2026 17:55:21 +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: <322304529.3597187.1796230521610@kpc.webmail.kpnmail.nl> In-Reply-To: <20261118220154.2965621-2-shakeel.butt@linux.dev> References: <20261118220154.2965621-1-shakeel.butt@linux.dev> <20261118220154.2965621-2-shakeel.butt@linux.dev> Subject: Re: [PATCH 1/6] kernfs: report times and link count from the node in getattr 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 : > > > getattr and permission copy a node's attributes into its inode while > holding kernfs_iattr_rwsem for reading, so several of them can write > the same inode at once. That is safe only because every update of > these attributes takes the lock for writing, so they all write the same > values. Commit aa1d058d48f2 ("kernfs: dont take i_lock on inode attr > read") relies on this. Setting up a node's first iattrs from setxattr > does not take the lock, but a refresh that misses them writes no times. > > The next patches let a directory's times and link count change without > that lock. A slow refresh could then write an old value after a newer > one, and stat() could return a stale or torn time or link count. > > Make getattr report the times and link count from the node instead of > the inode. Permission checks use neither. Nothing changes yet, except > that a stat() racing a node's first setxattr can report the new times. > > Signed-off-by: Shakeel Butt > --- > fs/kernfs/inode.c | 32 ++++++++++++++++++++++++++++++-- > 1 file changed, 30 insertions(+), 2 deletions(-) > > diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c > index 53b1a2796e0b..3616161a56cb 100644 > --- a/fs/kernfs/inode.c > +++ b/fs/kernfs/inode.c > @@ -162,9 +162,22 @@ static inline void set_inode_attr(struct inode *inode, > 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. > + */ > +static bool kernfs_dir_nlink(struct kernfs_node *kn, unsigned int *nlink) > +{ > + if (kernfs_type(kn) != KERNFS_DIR || (kn->flags & KERNFS_REMOVING)) > + return false; > + *nlink = 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); > @@ -175,8 +188,8 @@ static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode) > */ > set_inode_attr(inode, attrs); > > - if (kernfs_type(kn) == KERNFS_DIR && !(kn->flags & KERNFS_REMOVING)) > - set_nlink(inode, kn->dir.subdirs + 2); > + if (kernfs_dir_nlink(kn, &nlink)) > + set_nlink(inode, nlink); > } > > int kernfs_iop_getattr(const struct mnt_idmap *idmap, > @@ -186,10 +199,25 @@ int kernfs_iop_getattr(const struct mnt_idmap *idmap, > struct inode *inode = d_inode(path->dentry); > struct kernfs_node *kn = inode->i_private; > struct kernfs_root *root = kernfs_root(kn); > + struct kernfs_iattrs *attrs; > + unsigned int nlink; > > down_read(&root->kernfs_iattr_rwsem); > kernfs_refresh_inode(kn, inode); > 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. > + */ > + attrs = kernfs_iattrs_noalloc(kn); > + if (attrs) { > + stat->atime = attrs->ia_atime; > + stat->mtime = attrs->ia_mtime; > + stat->ctime = attrs->ia_ctime; > + } > + if (kernfs_dir_nlink(kn, &nlink)) > + stat->nlink = nlink; > up_read(&root->kernfs_iattr_rwsem); > > return 0; > -- > 2.53.1-Meta Reviewed-by: Jori Koolstra (CIQ)