From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796064242; b=KYwYiV4n/ySWGGd7UqK/prgfFM3qpglsmzho9Y7YOdPHvvBuzyehKcKRhAhE9Cny8bFX elxfY0YxxMoWU+sQAfIEq4q6ZN1W+9N0adzw3jsAyRXKY3FLLOrD7DT6ZJY7WsQANGjQr e9BPZ1wX+IChQbKs6ERcUiFaIkKCZCF+r6wbVA2SzihHoFocxBYULly3A/7KvR2VgvTxr g8Xbu9eNajidUEYz3fRbnXZ+Ft9iTWBcdmzTk/MfPz/oEerEBKF8t80HdVg6HrwuuJq+x c95rIggjTxVDYTxTouhjSp+XZJCaB/gQ8AawqdCuf92HyvaGuyatqgqJRj3u5FdgdYQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796064242; 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:Cc:Subject:From:To:X-Mailer: References:In-Reply-To; bh=qvbtBV35HWQm2hd7I01hwbUdUMt81RNttscVV6vzlL4=; b=h/P428+AXfaoSAOT6e/482BNKWRmyoGIkjGnL6Da0Sv9veV1DmXKIRhYaxXApssW2Nsv mdJOTaADDWKn4WeixySFkFLUp0xnvhaP/W0gJQaTEOixTLNhhOhdDLsX/tbVlIh3ph4Qm yQs9Jy6qVr0FD0HHimaF8vjX4fflvCJfDx7J4AfI4byNNFN8eJN68j2CTV8fQmaOplwlB X/iwBN7iLKqWq05ARo9kpuUgBEceR/JjASpQ/JQdiXVXPLl09JZ9vvdTcGdPrww9dKys2 n7EfjQb9j9afYDPLWj8HewtIRoO5ZSiCfDcAN2+5rLMCvZ5is4xfDuw+XmfkIUZhqlw== 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=mV343aQj; arc=none smtp.remote-ip=209.85.128.54 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 3743C606A325 for ; Mon, 30 Nov 2026 18:44:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3743C606A325 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=mV343aQj Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4a35a60499eso83641405e9.0 for ; Mon, 30 Nov 2026 10:44:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796064239; x=1796669039; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-type:mime-version:from:to:cc:subject:date:message-id :reply-to:content-type; bh=qvbtBV35HWQm2hd7I01hwbUdUMt81RNttscVV6vzlL4=; b=mV343aQjFUX+OKuwVe1M8M0OORDNyzyEIWm9P8HYFdIMvmAhCJi6VPmFbcmBFbKrPk 4v0Thwm8iESyJ+LmxLtoPpgzdpf3BFZFyycnYKdkbFZ0DFLs6GaaLBwVZ43/4izi4/pw 5VBljsERlddAL+N0ZbhWIKRfNr0dGkZ7SNgnqWdxO+kh7X2jTuyYEwTisEZhZSiVM/gQ KuFrCsRxfY2j1D3T9MeH9q3J8fxcnFZs8MJsEgbWD+x+jeXwMmWP3J+GPoHY1gqyf1Tz JJt+csY+qbQ6ofS6TTak/TUFB7CjPzrIgbF+in/qF/Clp0pc2mvrOUFjdsIWvypDi4rW DUXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796064239; x=1796669039; h=in-reply-to:references:to:from:subject:cc: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=qvbtBV35HWQm2hd7I01hwbUdUMt81RNttscVV6vzlL4=; b=RyQm7sJO4B+dmChyr9b0e4XvrLmF1iD97+BjnEGEvslNh8iY1uOXlyKnVszGb81vKb yv5ouHxKGwioaOKZULcyWo83oNqXca7OAJ+3Z2DZ/ozbmTt/YfIMdxMh1pgzYssbh+Wc 3Flp4x5PRwQcjeBaWGHZcmxb9LlYsrKY7qulxCn5VvzMjHpjmFwKcG9dK3d72I2daDJ6 ag2aR6pjDqA10Z7Z97sDdnEiN0LKDMQ+NKzXYM2/z6DT1OVyRhlWLjGRY+/ewVKpOjpK 5nb4bXT/vCXIF5AHmNjKJiBUhVTgB2CtcdPnZCFQ8ZDK4VZkvR7R++MenSDvf1DOy5GF yNWA== X-Forwarded-Encrypted: i=1; AL+hErFRSxy0BfKmH++QQibRkOBOd34KM+sLyAkpef06rMG43MXDwYkNfcwC/d6gce9ejK4zrOs37x48aAo=@vger.kernel.org X-Gm-Message-State: APuU4Z8DLJMjl7UO430zbd6nBn5kipLSsH5ODVWthXMvjc7YVyki34iF sVmtyNE09qYZRCfQ7A1HSH8/sUF4KQ3yv50boA0ZJdTa0K51xBuYVRx4 X-Gm-Gg: AZFdTZfP5ANzMpW/jaSExxLzlnMCuGLmtNpHJnuo0yZ07FaSmzowuGZTD8I+N2ESTWF Tw7fzE0Qb9UM7diXsunB/LhLuHwWl5EoChw6KATRyv+Qy+SKRaOC+nnYGE/nQfLAuw0W60rSc03 Bxy1QIBgPig1jWH5xdscO3KOooBhgAiME9mUMVoX1oHmyPewlbhje3IckYVUkE0GwKrOolVykpO UftZNM7YAfKyMtNkXywxtt2Jky6a7KjdPe11jqy0grkcKOyySy6yVpyBzC1Y7xqCpvPZ4KAzZ7i +bDcqbFLXBJGO7XX7fCFxL602tkBUs0AtPqyBTNwXcTZS+Ves6C8k5Xhm3tBtfnD/UZ+GXgeI3b ov2SccBU0T0cGXbF8u4hqObX6VEqbACwjGJsV1Z0ShaCkifyUc45TNi7F6NBrExCn/essCNDGzo wx6aQGbHvjhAH56CZeCQxWAi8L9HnFc/aWqhX6tRTDYCTQmrUaaD6QUd1ADmZaAKvTboHCw3e6E tLB6XbPMWlL110qrn9bY65AqCwypmUxHygrNUOfLMiYs3dbmBVzxOeDuFLEFpcNV4qiO7KPPYZ2 39XQ4y2zZd++k85OcK3h62RjQw== X-Received: by 2002:a05:600c:4514:b0:4bb:6823:3d3c with SMTP id 5b1f17b1804b1-4bb888169d0mr749210255e9.20.1796064239290; Mon, 30 Nov 2026 10:43:59 -0800 (PST) Received: from localhost ([2001:b07:5d26:7a6a:365a:60ff:fe0d:cfc6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884a3a3dsm942731355e9.10.2026.11.30.10.43.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2026 10:43:58 -0800 (PST) X-Mailing-List: linux-doc@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; boundary=a9523d465d7ea64351e8a32f07497c28f3038ae69c08a6b11f05ac1ff95d; micalg=pgp-sha512; protocol="application/pgp-signature" Date: Mon, 30 Nov 2026 19:43:54 +0100 Message-Id: Cc: "Namjae Jeon" , "Hyunchul Lee" , "Jonathan Corbet" , "Eric Biggers" , "Theodore Y . Ts'o" , "Jaegeuk Kim" , "Alexander Viro" , "Christian Brauner" , "Shuah Khan" , "Randy Dunlap" , "Chuck Lever" , "Jeff Layton" , "Jan Kara" , "Alexander Aring" , "Darrick J . Wong" , "Andrey Albershteyn" , "Amir Goldstein" , "Miklos Szeredi" , =?utf-8?q?Pali_Roh=C3=A1r?= , "Christoph Hellwig" , "Dave Chinner" , , , , , , , , , Subject: Re: [PATCH v3 2/5] vfs: add xflags masks to fileattr API From: "koraynilay" To: "Lauri Gates" , "koraynilay" X-Mailer: aerc 0.22.0-0-gc2f86b7abde3 References: <20261129024233.2361718-3-koray.fra@gmail.com> <20261129131024.92875-1-lauri.gates@gmail.com> In-Reply-To: <20261129131024.92875-1-lauri.gates@gmail.com> --a9523d465d7ea64351e8a32f07497c28f3038ae69c08a6b11f05ac1ff95d Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 On Sun Nov 29, 2026 at 2:10 PM CET, Lauri Gates wrote: > On Sun, Nov 29, 2026 at 03:42:30AM +0100, koraynilay wrote: >> + if (fa->flags_valid) { >> + /* >> + * Assume that if the filesystem supports masks it supports its >> + * writable FS_*_FL flags via FS_XFLAG_* and fsx_xflags_rw_mask. >> + */ >> + changed =3D fa->flags ^ old_ma->flags; >> + if (changed & ~xflags_to_flags(old_ma->fsx_xflags_rw_mask)) >> + return -EOPNOTSUPP; > > I would like to ask for a change here before v4: let FS_IOC_SETFLAGS > keep working for flags that the rw mask cannot express, instead of > failing with EOPNOTSUPP. A sketch and the reason follow; would you take > something like it? > > I ran into this assumption while putting the may-share flag from the > FIEMAP thread [1] on top of v3, in a series I have not posted yet. The > flag is read-only, so it is reported through fa_xflags_ro_mask, which > the VFS fills only when the filesystem sets has_masks. My series > therefore sets has_masks for ocfs2 as well as xfs. On ocfs2 that broke > FS_IOC_SETFLAGS for six flags it accepts today. Five have no FS_XFLAG_* > counterpart: SECRM, UNRM and NOTAIL on files, DIRSYNC and TOPDIR on > directories. The sixth is COMPR, whose xflag from 3/5 is read-only, so > it can never be in fsx_xflags_rw_mask. Each set failed with EOPNOTSUPP > (QEMU, v7.4-rc1 plus v3 1-3 and my series); without my series all six > work. > > ocfs2 is only the first case. Of the filesystems in v3 only ntfs sets > has_masks, but ext4 (DIRSYNC, TOPDIR, JOURNAL_DATA, EXTENTS) and btrfs > (DIRSYNC, NOCOW) have the same kind of flags, so neither could set it > without losing chattr for them. COMPR on btrfs is the case Amir asked to > footnote in 5/5 as "RW only via SETFLAGS": with masks, chattr +c would > fail the same way, and the footnote would no longer be true. With the > fallback below it stays true. FS_IOC_FSSETXATTR is not affected, since > it has never been able to set these flags. > > The sketch, against v3 2/5: when an FS_IOC_SETFLAGS call changes a flag > that the rw mask cannot express, give the filesystem the full > read-modify-write request it got before masks. The check quoted above > can then never fire, so the sketch removes it: > > --- a/fs/file_attr.c > +++ b/fs/file_attr.c > @@ static int fileattr_set_rmw_to_mask(struct file_kattr *fa, > if (fa->flags_valid) { > - /* > - * Assume that if the filesystem supports masks it supports its > - * writable FS_*_FL flags via FS_XFLAG_* and fsx_xflags_rw_mask. > - */ > - changed =3D fa->flags ^ old_ma->flags; > - if (changed & ~xflags_to_flags(old_ma->fsx_xflags_rw_mask)) > - return -EOPNOTSUPP; > - > - changed =3D flags_to_xflags(changed); > + changed =3D flags_to_xflags(fa->flags ^ old_ma->flags); > } else { /* if (fa->fsx_valid) */ > @@ static int fileattr_set_convert(struct file_kattr *fa, > - if (old_ma->has_masks) > + /* > + * A masked request names only flags with an FS_XFLAG_* counterpart. > + * FS_IOC_SETFLAGS changing any other flag (e.g. FS_DIRSYNC_FL) gets > + * the full request below, which the filesystem handled before masks. > + */ > + if (old_ma->has_masks && > + !(fa->flags_valid && ((fa->flags ^ old_ma->flags) & > + ~xflags_to_flags(old_ma->fsx_xflags_rw_mask)))) > return fileattr_set_rmw_to_mask(fa, old_ma); > > With it, all six ocfs2 flags set and clear again, and nothing else in my > xfs, ocfs2 and overlayfs checks changes. The cost is in the contract: a > filesystem that sets has_masks must still accept a full, unmasked > request from FS_IOC_SETFLAGS. Every ->fileattr_set() does today, because > has_masks on set is new in this series, but the documentation in 5/5 > would need to say so. The other way I can see is to keep the masked > request and pass the unmapped FS_*_FL changes beside it, which needs a > second mask. That seems like more API than the case needs, so I would go > with the fallback. Hi, can you try with this diff and setting both get_only_masks and has_masks to true in ocfs2's code? (to set only get_only_masks and leave has_masks as false, we'd need to also add || fa->get_only_masks in the clamping of vfs_fileattr_get and mask population in fileattr_to_file_attr, which I think wouldn't be as clean) Thanks, koraynilay (WIP, it will be cleaned up for v4) diff --git a/fs/file_attr.c b/fs/file_attr.c index 2b3fe36bbab9..a6f6d59eb649 100644 --- a/fs/file_attr.c +++ b/fs/file_attr.c @@ -185,7 +185,7 @@ static int file_attr_to_fileattr(const struct file_attr= *fattr, if (fattr->fa_xflags & ~mask) return -EINVAL; =20 - if (fa->has_masks) { + if (fa->use_masks && fa->has_masks) { u64 rw_user_mask =3D fattr->fa_xflags_rw_mask; =20 if (rw_user_mask & ~FS_FILE_ATTR_XFLAGS_MASK) @@ -301,6 +301,7 @@ static int fileattr_set_rmw_to_mask(struct file_kattr *= fa, fa->fsx_xflags =3D new_xflags; fa->fsx_xflags_rw_mask =3D new_rw_mask; fa->has_masks =3D true; + fa->use_masks =3D true; =20 fa->fsx_valid =3D true; fa->flags_valid =3D false; @@ -374,6 +375,7 @@ static int fileattr_set_mask_to_rmw(struct file_kattr *= fa, fa->fsx_xflags =3D new_xflags; fa->fsx_xflags_rw_mask =3D 0; fa->has_masks =3D false; + fa->use_masks =3D false; =20 fa->fsx_valid =3D true; fa->flags_valid =3D false; @@ -389,15 +391,17 @@ static int fileattr_set_mask_to_rmw(struct file_kattr= *fa, static int fileattr_set_convert(struct file_kattr *fa, const struct file_kattr *old_ma) { + bool fs_has_masks =3D old_ma->has_masks && !old_ma->get_only_masks; + if (fa->has_masks) { - if (!old_ma->has_masks) + if (!fs_has_masks) return fileattr_set_mask_to_rmw(fa, old_ma); =20 /* Both have masks, pass the request through. */ return 0; } =20 - if (old_ma->has_masks) + if (fs_has_masks) return fileattr_set_rmw_to_mask(fa, old_ma); =20 fa->fsx_xflags_rw_mask =3D 0; @@ -543,6 +547,16 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, st= ruct dentry *dentry, if (!inode_owner_or_capable(idmap, inode)) return -EPERM; =20 + if (fa->use_masks && !fa->has_masks) + return -EINVAL; + + /* This comes from an older call or caller wanted VER0 RMW semantics */ + if (!fa->use_masks) + fa->has_masks =3D false; + + // also try this, it should be the same as above but less readable + //fa->has_masks =3D fa->use_masks; + if (fa->has_masks && !fa->fsx_xflags_rw_mask) return -EINVAL; =20 @@ -754,8 +768,10 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __u= ser *, filename, return error; } =20 - if (at_flags & AT_FILEATTR_MASKS) + if (at_flags & AT_FILEATTR_MASKS) { fa.has_masks =3D true; + fa.use_masks =3D true; + } =20 error =3D file_attr_to_fileattr(&fattr, &fa); if (error) diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h index ad77febe8c76..59353a5240f6 100644 --- a/include/linux/fileattr.h +++ b/include/linux/fileattr.h @@ -64,7 +64,15 @@ struct file_kattr { /* selectors: */ bool flags_valid:1; bool fsx_valid:1; - bool has_masks:1; + bool has_masks:1; /* struct has valid masks */ + bool use_masks:1; /* equivalent to AT_FILEATTR_MASKS but for + in-kernel calls (set, only in) */ + bool get_only_masks:1;/* Transitional. Filesystem doesn't actually + support masks yet, but wants to support + read-only / get-only xflags like + MAYSHAREEXTENT or BTIME */ + /* Transitional: filesystem doesn't support rw_mask for set, + but supports ro_mask on get */ }; =20 int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __use= r *ufa); --a9523d465d7ea64351e8a32f07497c28f3038ae69c08a6b11f05ac1ff95d Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQSgVimKafU5DQMcjcDmj22qf5IGXAUCaw3D6gAKCRDmj22qf5IG XFcCAP9tNj/OAlzvR7+E7QrqwEB45c1yJshEBDCPXlVa1iXwJQEAhl6Iv+OSiR/I T2IKz79rU+jp9fG3+TtIIcl1bd799wQ= =tVsP -----END PGP SIGNATURE----- --a9523d465d7ea64351e8a32f07497c28f3038ae69c08a6b11f05ac1ff95d--