Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794844510; b=r12BtdYQzB9Q0Q/ayvp96pcdL3pq3LMjAilIbOUdxyvM6rltjlw1PGkKW+R9jIKupz+o JAtRUdtuqO4vwdgsRQ4uMeJRyZGa3J54oERW7Y+m+i2K6zNacq9sBSpmxA3qPe0RbQAN2 hNQe//FHsPahqie3ALHUms1qejVwoXAIMFZ1TRhdl0MlOzfri7pNooZYUoGgHKNnXSa1C pKdhcsfnHd32kBvjCNpznWX3KPk6mVwjHu07GcsnOBHaAQyjpgIG8jyohkJjeT6P9L2gH +tzrexKrjM4rDgiiKd2o6/VXWR1VGQJlgommemQ32ECfu8tNkSrut5NW3VUs/EipBjg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794844510; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Mime-Version:Content-Type:Date:Message-Id:Subject:From:To:Cc:X-Mailer: References:In-Reply-To; bh=040W0WtrDSqyLSlnE1PnGtn4Yj+G8VjPGcb4tUhpFSw=; b=cZGXCQEblLaXgHc9H65DcPd1ynLPz7vEwM6UqGtVHIohXqiGG94J17VSASv3oN/Fn12f 7oGQHPevBzewYkcq2D3Vjol07gPVeomH34Uh2uNKFhZB65Y8D+0YiYRGtlPgLmq30qQmE WNvzpVVKatMPwSmZCY5vK4Zvg4TXDJR8mQs6V4wYxEMO4FnXNSBL+KSqG6KHKw6cU5V6t AfYZYUYkXUsrMWW+hz/h/Qg+tKbavRX6p9H0RW24SiiGuy3r9BP0pXWxt+TOoSSLXIUA4 Xqj8Nut25jponbIo2eQw2vacFvi/DzFkgTMzAczwdIne1kCJxIgWU1WS9mzxZyYwRug== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rg4UJPzl; arc=none smtp.remote-ip=209.85.128.49 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43958606A32F for ; Mon, 16 Nov 2026 15:55:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 43958606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rg4UJPzl Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4bb666304fdso13655275e9.0 for ; Mon, 16 Nov 2026 07:55:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794844508; x=1795449308; darn=lists.linux.dev; h=in-reply-to:references:cc:to:from:subject:message-id:date :content-type:mime-version:from:to:cc:subject:date:message-id :reply-to:content-type; bh=040W0WtrDSqyLSlnE1PnGtn4Yj+G8VjPGcb4tUhpFSw=; b=rg4UJPzl71Wvxb/pBQ7N+dQrUzCd+295+b3GaM/CqmZPY1bl7GQn3R7cjRlGfx1q9Y RcXfDcQCFe/2FAjd3SU4EaOa53GsBRditw92mgIwp47Z2kGbtW4+u9p27QKMf1Cqnyfl hYR/6+3StHy6OV8wyknEuga9kUwEK1IsyOAsPBN/USp5LALt/T2YbkklBcrENPRXk77s 71LyuUlFQvYwzMkg5NTAbTJn5pZrsK1VmAMtVSE5HOMKmgKE478sYKDz6rAQfJDQ1c7r 5TWcJ+Zns/fl5YGJA2a074sWIkHe4P9+F3EDmXLJmbZlhVxs13D5cDHxtgegwMAkXQ63 1tvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794844508; x=1795449308; h=in-reply-to:references:cc:to:from:subject:message-id:date :content-type:mime-version:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=040W0WtrDSqyLSlnE1PnGtn4Yj+G8VjPGcb4tUhpFSw=; b=BG3VHULDdbJRLpV9OICHiAeTyUiz2AiyVoVpgp86yRh4UJCVbtBXaWOdYvdc/2dcio gPZyLd03/Z3r8v2e1r1ZKxixnqmWj5lg875b8qYLRZ4Ii6RGc1EYE/pZHq98s8FTxQgK CRRnxdJyPJwMcTOhwU8eI3qtXor36KRd4OrjJ+c7modU4eEhEwbMQ/7QJ5B9p4/uKO9h BR5mFDLO0eXcxPCL2dCfany6EIRh3BIWFIdgXIQeWLxY+c7uGZCDHziEG58zmvDgagm/ eUEBSMJwsqcGsxqy9MhMqXFdy4V3N2O5pJAC9bHMnX0TvBz8Ma35RESre5RKGSWjVDOy pJ4Q== X-Forwarded-Encrypted: i=1; AL+hErEcleS+FMzkM8erzbjeqb4je1wP6m1J/NY94SfkWAyRj2+ak482KevPTfwgnPe58YS8a3z27Q==@lists.linux.dev X-Gm-Message-State: APuU4Z/vKiz5iOp1Rdzi4GHX3FzY82QZW1yJWLNIm/IfkhVXZlrZ9st/ FS27e9abDmHMXSfNVtSMizY+4RrcHe3ZqYE8z4Wi1wFdeeXOxADyFwfs X-Gm-Gg: AYBFou3TbNDmXXfS179t4Hg+EK439j+GzEeT2L+loEs4YKpvzbArC+u60eZ/VTCgoCx tLbJD0hUVgGmKY+CkKhpa72kdgoAxWHAxhU6nzoeEyraVDBzTdDlcN8HsR14OD5kL6uPEi88kac dFUixQS2Hs3l8DpT/FTLuhFGWFM9O76DqoxoIixFndV6MpeBpG7Z1iMaw0i2NpM3B/79qQUAkFy Pn38/0Exa412u8OVrSobcLk0sMlOH5U2SPYDqOFZvYPhiR0f1dOtVcNfhdcK5hhvpO9dz5f2jmo mEUaxMiBz2RhEc7Wkd6jFrOx8I2muIFIlcEjCxhi+M8nngDW3uNunEeWKwdju5nLIEi5o0TukNd n9TvEOFmszmgDCe09EvC93XkZmagF1F2aIDesUiyMbuv6VfgX0VVqWgI+n6ybojTONf/z3uiS/A KutLOliqqOMvhwbL3SAr7DIRxp1XCOduGNR7L93UGC4Q/URwE3xCygcTtU0La8rm6qIcjXzIQ2G TtOK3PHkc4ocaNdaNjQ1uItJwAf3YfUH/Wcngh5Lriqb9rNAhl569gcLAe+0dN3FVa3mqvSJVhX vw8iAAh7at4m3uBLb2YvQNAp0g== X-Received: by 2002:a05:600c:1906:b0:4a1:c6f5:2450 with SMTP id 5b1f17b1804b1-4bb55ac2a34mr244783135e9.17.1794844507334; Mon, 16 Nov 2026 07:55:07 -0800 (PST) Received: from localhost ([2001:b07:5d26:7a6a:365a:60ff:fe0d:cfc6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb55ae501bsm321476945e9.10.2026.11.16.07.55.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Nov 2026 07:55:05 -0800 (PST) X-Mailing-List: exfat@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Type: multipart/signed; boundary=f93caca3b757f4039ce5a884d522f788c6958abee5364c6a1026cc96907d; micalg=pgp-sha512; protocol="application/pgp-signature" Date: Mon, 16 Nov 2026 16:55:02 +0100 Message-Id: Subject: Re: [RFC PATCH v4 06/10] vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers From: "koraynilay" To: "Amir Goldstein" , "koraynilay" Cc: "David Sterba" , "Namjae Jeon" , "Sungjong Seo" , "Alexander Viro" , "Christian Brauner" , "Trond Myklebust" , "Anna Schumaker" , "Chuck Lever" , "Jeff Layton" , "Konstantin Komarov" , "Paulo Alcantara" , "Chris Mason" , "Yuezhang Mo" , "Jan Kara" , "NeilBrown" , "Olga Kornievskaia" , "Dai Ngo" , "Tom Talpey" , "Ronnie Sahlberg" , "Shyam Prasad N" , "Bharath SM" , "Sergey Senozhatsky" , "ChenXiaoSong" , "Darrick J . Wong" , "Sean Smith" , "Andrey Albershteyn" , "Pedro Falcato" , =?utf-8?q?Pali_Roh=C3=A1r?= , , , , , , , , X-Mailer: aerc 0.22.0-0-gc2f86b7abde3 References: <20261115180343.576773-1-koray.fra@gmail.com> <20261115180343.576773-7-koray.fra@gmail.com> In-Reply-To: --f93caca3b757f4039ce5a884d522f788c6958abee5364c6a1026cc96907d Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 On Mon Nov 16, 2026 at 2:52 PM CET, Amir Goldstein wrote: > On Sun, Nov 15, 2026 at 7:04=E2=80=AFPM koraynilay = 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 >> --- >> 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 whi= le >> + * 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 den= try *dentry, >> + struct file_kattr *fa) >> +{ >> + struct inode *inode =3D d_inode(dentry); >> + struct file_kattr old_ma =3D {}; >> + int err; >> + >> + if (!inode->i_op->fileattr_set) >> + return -ENOIOCTLCMD; >> + >> + if (!inode_owner_or_capable(idmap, inode)) >> + return -EPERM; >> + >> + err =3D 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 |=3D (old_ma.fsx_xflags & FS_XFLAGS_MASK)= & >> + ~FS_XFLAG_COMMON; >> + fa->fsx_extsize =3D old_ma.fsx_extsize; >> + fa->fsx_nextents =3D old_ma.fsx_nextents; >> + fa->fsx_projid =3D old_ma.fsx_projid; >> + fa->fsx_cowextsize =3D old_ma.fsx_cowextsize; >> + fa->fsx_ptime =3D 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 =3D=3D 0 (legacy mode) >> + * this is not needed as userspace does >> + * read-modify-write already. >> + */ >> + if (fa->fsx_xflags_mask) { >> + fa->fsx_xflags |=3D 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 =3D old_ma.fsx_extsize; >> + if (!(fa->fsx_xflags_mask & FS_XFLAG_PROJID)) >> + fa->fsx_projid =3D old_ma.fsx_projid; >> + if (!(fa->fsx_xflags_mask & FS_XFLAG_COWEXTSIZE)= ) >> + fa->fsx_cowextsize =3D old_ma.fsx_cowext= size; >> + } >> + fa->flags |=3D old_ma.flags & ~FS_COMMON_FL; >> + >> + /* xflags not present in fsxattr */ >> + if (!(fa->fsx_xflags_mask & FS_XFLAG_PTIME)) >> + fa->fsx_ptime =3D old_ma.fsx_ptime; >> + } >> + >> + err =3D fileattr_set_prepare(inode, &old_ma, fa); >> + if (err) >> + return err; >> + err =3D security_inode_file_setattr(dentry, fa); >> + if (err) >> + return err; >> + err =3D 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 =3D d_inode(dentry); >> - struct file_kattr old_ma =3D {}; >> 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 =3D vfs_fileattr_get(dentry, &old_ma); >> - if (!err) { >> - /* initialize missing bits from old_ma */ >> - if (fa->flags_valid) { >> - /* FS_IOC_SETFLAGS */ >> - fa->fsx_xflags |=3D (old_ma.fsx_xflags & FS_XFLA= GS_MASK) & >> - ~FS_XFLAG_COMMON; >> - fa->fsx_extsize =3D old_ma.fsx_extsize; >> - fa->fsx_nextents =3D old_ma.fsx_nextents; >> - fa->fsx_projid =3D old_ma.fsx_projid; >> - fa->fsx_cowextsize =3D old_ma.fsx_cowextsize; >> - fa->fsx_ptime =3D old_ma.fsx_ptime; >> - } else { >> - /* >> - * Preserve unmasked xflags when running file_se= tattr() >> - * 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 =3D=3D 0 (lega= cy mode) >> - * this is not needed as userspace does >> - * read-modify-write already. >> - */ >> - if (fa->fsx_xflags_mask) { >> - fa->fsx_xflags |=3D old_ma.fsx_xflags & >> - ~fa->fsx_xflags_mask; >> - fileattr_fill_xflags(fa, fa->fsx_xflags = & >> - ~FS_XFLAG_RDONLY_MA= SK); >> - if (!(fa->fsx_xflags_mask & FS_XFLAG_EXT= SIZE)) >> - fa->fsx_extsize =3D old_ma.fsx_e= xtsize; >> - if (!(fa->fsx_xflags_mask & FS_XFLAG_PRO= JID)) >> - fa->fsx_projid =3D old_ma.fsx_pr= ojid; >> - if (!(fa->fsx_xflags_mask & FS_XFLAG_COW= EXTSIZE)) >> - fa->fsx_cowextsize =3D old_ma.fs= x_cowextsize; >> - } >> - fa->flags |=3D old_ma.flags & ~FS_COMMON_FL; >> - >> - /* xflags not present in fsxattr */ >> - if (!(fa->fsx_xflags_mask & FS_XFLAG_PTIME)) >> - fa->fsx_ptime =3D old_ma.fsx_ptime; >> - } >> - >> - err =3D fileattr_set_prepare(inode, &old_ma, fa); >> - if (err) >> - goto out; >> - err =3D security_inode_file_setattr(dentry, fa); >> - if (err) >> - goto out; >> - err =3D inode->i_op->fileattr_set(idmap, dentry, fa); >> - if (err) >> - goto out; >> - fsnotify_xattr(dentry); >> - } >> - >> -out: >> + err =3D __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 *dent= ry, >> struct file_kattr *fa); >> +int __vfs_fileattr_set_locked(const struct mnt_idmap *idmap, struct den= try *dentry, >> + struct file_kattr *fa); > > There is no reason for __ prefix here and I think it should be discourage= d 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. --f93caca3b757f4039ce5a884d522f788c6958abee5364c6a1026cc96907d Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQSgVimKafU5DQMcjcDmj22qf5IGXAUCavsnVgAKCRDmj22qf5IG XC40APwLpgC2qCi2ygC417CAeeBgnvIyXQNVw3WOnFMBGg8tUQEAsuqI0c//BtxD +1WkW5Y6mUri16pC/bv/iBr7lSbFFAs= =Rkz6 -----END PGP SIGNATURE----- --f93caca3b757f4039ce5a884d522f788c6958abee5364c6a1026cc96907d--