From: "koraynilay" <koray.fra@gmail.com>
To: "Amir Goldstein" <amir73il@gmail.com>,
"koraynilay" <koray.fra@gmail.com>
Cc: "David Sterba" <dsterba@suse.com>,
"Namjae Jeon" <linkinjeon@kernel.org>,
"Sungjong Seo" <sj1557.seo@samsung.com>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Christian Brauner" <brauner@kernel.org>,
"Trond Myklebust" <trondmy@kernel.org>,
"Anna Schumaker" <anna@kernel.org>,
"Chuck Lever" <cel@kernel.org>,
"Jeff Layton" <jlayton@kernel.org>,
"Konstantin Komarov" <almaz.alexandrovich@paragon-software.com>,
"Paulo Alcantara" <pc@manguebit.org>,
"Chris Mason" <mason@kernel.org>,
"Yuezhang Mo" <yuezhang.mo@sony.com>, "Jan Kara" <jack@suse.cz>,
NeilBrown <neil@brown.name>,
"Olga Kornievskaia" <okorniev@redhat.com>,
"Dai Ngo" <Dai.Ngo@oracle.com>, "Tom Talpey" <tom@talpey.com>,
"Ronnie Sahlberg" <ronniesahlberg@gmail.com>,
"Shyam Prasad N" <sprasad@microsoft.com>,
"Bharath SM" <bharathsm@microsoft.com>,
"Sergey Senozhatsky" <senozhatsky@chromium.org>,
ChenXiaoSong <chenxiaosong@chenxiaosong.com>,
"Darrick J . Wong" <djwong@kernel.org>,
"Sean Smith" <defendthedisabled@gmail.com>,
"Andrey Albershteyn" <aalbersh@kernel.org>,
"Pedro Falcato" <pfalcato@suse.de>,
"Pali Rohár" <pali@kernel.org>,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, exfat@lists.linux.dev,
ntfs3@lists.linux.dev, linux-cifs@vger.kernel.org,
linux-nfs@vger.kernel.org, linux-api@vger.kernel.org
Subject: Re: [RFC PATCH v4 06/10] vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers
Date: Mon, 16 Nov 2026 16:55:02 +0100 [thread overview]
Message-ID: <DMWR9XOQTPOK.3IDTXWG0BB6CG@gmail.com> (raw)
In-Reply-To: <CAOQ4uxgm+JEu2MGnqQrJ00nTJ45S2ECQ7CBOC2QrgniOfkLYAQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 9268 bytes --]
On Mon Nov 16, 2026 at 2:52 PM CET, Amir Goldstein wrote:
> On Sun, Nov 15, 2026 at 7:04 PM koraynilay <koray.fra@gmail.com> wrote:
>>
>> Currently there is no way for a caller to invoke vfs_fileattr_set()
>> while holding an inode lock without having the kernel go into deadlock.
>>
>> Fix this by moving the vfs_fileattr_set() logic into
>> __vfs_fileattr_set_locked() and making vfs_fileattr_set() a simple
>> wrapper that only handles the inode lock.
>>
>> Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.7
>> Signed-off-by: koraynilay <koray.fra@gmail.com>
>> ---
>> fs/file_attr.c | 139 +++++++++++++++++++++++----------------
>> include/linux/fileattr.h | 2 +
>> 2 files changed, 86 insertions(+), 55 deletions(-)
>>
>> diff --git a/fs/file_attr.c b/fs/file_attr.c
>> index 12610fb6a751..063c81fbfa6a 100644
>> --- a/fs/file_attr.c
>> +++ b/fs/file_attr.c
>> @@ -288,6 +288,89 @@ static int fileattr_set_prepare(struct inode *inode,
>> return 0;
>> }
>>
>> +/**
>> + * __vfs_fileattr_set_locked - change miscellaneous file attributes while
>> + * holding the inode lock
>> + *
>> + * @idmap: idmap of the mount
>> + * @dentry: the object to change
>> + * @fa: fileattr pointer
>> + *
>> + * Same as vfs_fileattr_set(), but caller must hold the inode lock.
>> + *
>> + * Return: 0 on success, or a negative error on failure.
>> + */
>> +int __vfs_fileattr_set_locked(const struct mnt_idmap *idmap, struct dentry *dentry,
>> + struct file_kattr *fa)
>> +{
>> + struct inode *inode = d_inode(dentry);
>> + struct file_kattr old_ma = {};
>> + int err;
>> +
>> + if (!inode->i_op->fileattr_set)
>> + return -ENOIOCTLCMD;
>> +
>> + if (!inode_owner_or_capable(idmap, inode))
>> + return -EPERM;
>> +
>> + err = vfs_fileattr_get(dentry, &old_ma);
>> + if (err)
>> + return err;
>> +
>> + /* initialize missing bits from old_ma */
>> + if (fa->flags_valid) {
>> + /* FS_IOC_SETFLAGS */
>> + fa->fsx_xflags |= (old_ma.fsx_xflags & FS_XFLAGS_MASK) &
>> + ~FS_XFLAG_COMMON;
>> + fa->fsx_extsize = old_ma.fsx_extsize;
>> + fa->fsx_nextents = old_ma.fsx_nextents;
>> + fa->fsx_projid = old_ma.fsx_projid;
>> + fa->fsx_cowextsize = old_ma.fsx_cowextsize;
>> + fa->fsx_ptime = old_ma.fsx_ptime;
>> + } else {
>> + /*
>> + * Preserve unmasked xflags when running file_setattr()
>> + * with a mask, which doesn't need a read-modify-write
>> + * so these attributes would be set to 0.
>> + *
>> + * With FS_IOC_FSSETXATTR or mask == 0 (legacy mode)
>> + * this is not needed as userspace does
>> + * read-modify-write already.
>> + */
>> + if (fa->fsx_xflags_mask) {
>> + fa->fsx_xflags |= old_ma.fsx_xflags &
>> + ~fa->fsx_xflags_mask;
>> + fileattr_fill_xflags(fa, fa->fsx_xflags &
>> + ~FS_XFLAG_RDONLY_MASK);
>> + if (!(fa->fsx_xflags_mask & FS_XFLAG_EXTSIZE))
>> + fa->fsx_extsize = old_ma.fsx_extsize;
>> + if (!(fa->fsx_xflags_mask & FS_XFLAG_PROJID))
>> + fa->fsx_projid = old_ma.fsx_projid;
>> + if (!(fa->fsx_xflags_mask & FS_XFLAG_COWEXTSIZE))
>> + fa->fsx_cowextsize = old_ma.fsx_cowextsize;
>> + }
>> + fa->flags |= old_ma.flags & ~FS_COMMON_FL;
>> +
>> + /* xflags not present in fsxattr */
>> + if (!(fa->fsx_xflags_mask & FS_XFLAG_PTIME))
>> + fa->fsx_ptime = old_ma.fsx_ptime;
>> + }
>> +
>> + err = fileattr_set_prepare(inode, &old_ma, fa);
>> + if (err)
>> + return err;
>> + err = security_inode_file_setattr(dentry, fa);
>> + if (err)
>> + return err;
>> + err = inode->i_op->fileattr_set(idmap, dentry, fa);
>> + if (err)
>> + return err;
>> + fsnotify_xattr(dentry);
>> +
>> + return 0;
>> +}
>> +EXPORT_SYMBOL(__vfs_fileattr_set_locked);
>> +
>> /**
>> * vfs_fileattr_set - change miscellaneous file attributes
>> * @idmap: idmap of the mount
>> @@ -308,7 +391,6 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
>> struct file_kattr *fa)
>> {
>> struct inode *inode = d_inode(dentry);
>> - struct file_kattr old_ma = {};
>> int err;
>>
>> if (!inode->i_op->fileattr_set)
>> @@ -318,60 +400,7 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
>> return -EPERM;
>>
>> inode_lock(inode);
>> - err = vfs_fileattr_get(dentry, &old_ma);
>> - if (!err) {
>> - /* initialize missing bits from old_ma */
>> - if (fa->flags_valid) {
>> - /* FS_IOC_SETFLAGS */
>> - fa->fsx_xflags |= (old_ma.fsx_xflags & FS_XFLAGS_MASK) &
>> - ~FS_XFLAG_COMMON;
>> - fa->fsx_extsize = old_ma.fsx_extsize;
>> - fa->fsx_nextents = old_ma.fsx_nextents;
>> - fa->fsx_projid = old_ma.fsx_projid;
>> - fa->fsx_cowextsize = old_ma.fsx_cowextsize;
>> - fa->fsx_ptime = old_ma.fsx_ptime;
>> - } else {
>> - /*
>> - * Preserve unmasked xflags when running file_setattr()
>> - * with a mask, which doesn't need a read-modify-write
>> - * so these attributes would be set to 0.
>> - *
>> - * With FS_IOC_FSSETXATTR or mask == 0 (legacy mode)
>> - * this is not needed as userspace does
>> - * read-modify-write already.
>> - */
>> - if (fa->fsx_xflags_mask) {
>> - fa->fsx_xflags |= old_ma.fsx_xflags &
>> - ~fa->fsx_xflags_mask;
>> - fileattr_fill_xflags(fa, fa->fsx_xflags &
>> - ~FS_XFLAG_RDONLY_MASK);
>> - if (!(fa->fsx_xflags_mask & FS_XFLAG_EXTSIZE))
>> - fa->fsx_extsize = old_ma.fsx_extsize;
>> - if (!(fa->fsx_xflags_mask & FS_XFLAG_PROJID))
>> - fa->fsx_projid = old_ma.fsx_projid;
>> - if (!(fa->fsx_xflags_mask & FS_XFLAG_COWEXTSIZE))
>> - fa->fsx_cowextsize = old_ma.fsx_cowextsize;
>> - }
>> - fa->flags |= old_ma.flags & ~FS_COMMON_FL;
>> -
>> - /* xflags not present in fsxattr */
>> - if (!(fa->fsx_xflags_mask & FS_XFLAG_PTIME))
>> - fa->fsx_ptime = old_ma.fsx_ptime;
>> - }
>> -
>> - err = fileattr_set_prepare(inode, &old_ma, fa);
>> - if (err)
>> - goto out;
>> - err = security_inode_file_setattr(dentry, fa);
>> - if (err)
>> - goto out;
>> - err = inode->i_op->fileattr_set(idmap, dentry, fa);
>> - if (err)
>> - goto out;
>> - fsnotify_xattr(dentry);
>> - }
>> -
>> -out:
>> + err = __vfs_fileattr_set_locked(idmap, dentry, fa);
>> inode_unlock(inode);
>> return err;
>> }
>> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
>> index ba7ed3b387d8..7ff62ee27e58 100644
>> --- a/include/linux/fileattr.h
>> +++ b/include/linux/fileattr.h
>> @@ -97,6 +97,8 @@ static inline bool fileattr_has_fsx(const struct file_kattr *fa)
>> int vfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
>> int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
>> struct file_kattr *fa);
>> +int __vfs_fileattr_set_locked(const struct mnt_idmap *idmap, struct dentry *dentry,
>> + struct file_kattr *fa);
>
> There is no reason for __ prefix here and I think it should be discouraged for
> global scope if possible.
Ah ok, I copied what had been done for __vfs_setxattr_locked() /
vfs_setxattr() and __vfs_removexattr_locked() / vfs_removexattr(), but I
agree that __ makes it more "internal", I'll change it for v5.
Thanks,
koraynilay
> Thanks,
> Amir.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-11-16 15:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 18:03 [RFC PATCH v4 00/10] add provenance time (ptime) koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 01/10] vfs: " koraynilay
2026-11-16 20:10 ` Amir Goldstein
2026-11-16 20:53 ` koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 02/10] vfs: add fileattr_has_fsx_mask() koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 03/10] ntfs3: make crtime user-settable using ptime koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 04/10] exfat: " koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 05/10] btrfs: add provenance time (ptime) koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 06/10] vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers koraynilay
2026-11-16 13:52 ` Amir Goldstein
2026-11-16 15:55 ` koraynilay [this message]
2026-11-15 18:03 ` [RFC PATCH v4 07/10] nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 08/10] nfs: " koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 09/10] ksmbd: add provenance time (ptime) and map it to CreationTime koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 10/10] cifs: add provenance time (ptime) and map it to SMB's CreationTime koraynilay
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=DMWR9XOQTPOK.3IDTXWG0BB6CG@gmail.com \
--to=koray.fra@gmail.com \
--cc=Dai.Ngo@oracle.com \
--cc=aalbersh@kernel.org \
--cc=almaz.alexandrovich@paragon-software.com \
--cc=amir73il@gmail.com \
--cc=anna@kernel.org \
--cc=bharathsm@microsoft.com \
--cc=brauner@kernel.org \
--cc=cel@kernel.org \
--cc=chenxiaosong@chenxiaosong.com \
--cc=defendthedisabled@gmail.com \
--cc=djwong@kernel.org \
--cc=dsterba@suse.com \
--cc=exfat@lists.linux.dev \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=linkinjeon@kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=mason@kernel.org \
--cc=neil@brown.name \
--cc=ntfs3@lists.linux.dev \
--cc=okorniev@redhat.com \
--cc=pali@kernel.org \
--cc=pc@manguebit.org \
--cc=pfalcato@suse.de \
--cc=ronniesahlberg@gmail.com \
--cc=senozhatsky@chromium.org \
--cc=sj1557.seo@samsung.com \
--cc=sprasad@microsoft.com \
--cc=tom@talpey.com \
--cc=trondmy@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=yuezhang.mo@sony.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox