From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795920210; b=oqADQ5L/LjWviqakgssLxfigZjx0Ll7rTphjdnO2FkEisu3jwmvLlV6LaBFfqdb8A1fC 61QyQBKkYSTAMhMG8YQgbiQmGp7773M/it778Ux7MV7fuXBi+eDgGk7V7iMn14qyWWeJu bYCVkZC8f2OgIuhIpDxhNb8eYeDOxuHIVdgYnKCDX7Dz2BSJRgjZid+C/CRB2w415BRMJ KGMauL/GmiOK2L8eYI03ivDh7cJop3vD4IT/pYqhYkpIkeU/2jljbUwkgqU4bBBa2Inwb K7UECWHFE5IbHzbiVOMqYy6gE6KAA4uqjfJVcN0tfC048Ibv9CNsuwCkKJ1N1Zw5XCg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795920210; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=3CaNphA2/6V8UNcSalG5w305ta+5iT96FUlJJg+0fBQ=; b=vxE/VQxbMQHqCDD0KEXqlASM5Gec1N6X/nbjlguokYtNs76Q0sIb0UHDnBNKeQ6y32P8 3pMLt5THWZRmQEAwbd2QCvt1fyYqKTkOmZgNAXSH9jG9L2uazM1q2tK1kRQoKFCIy45bO t1DeUt1JXICiXh5rZsj+fjQLUTNyk0LXk7aEH/28xOvEbHrjgHvzrbRqinb59lB/xRG3V lasmdZwBEu5c7FO7ZgX8lIkTNC9idXm1a8Y2Ra/nibwrx3qkspC8PrTx38XLyjQx2eQg5 foMrq8l97cMztxHn2hMUkfLMXoa7ShVDctdrsueVpa8ZUN1fs9kTLM3+D73pbGuqmfQ== 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=VVaiJiEm; arc=none smtp.remote-ip=209.85.221.49 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.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 448A6606A32D for ; Sun, 29 Nov 2026 02:43:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 448A6606A32D 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=VVaiJiEm Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-491846221ffso8170761f8f.3 for ; Sat, 28 Nov 2026 18:43:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795920208; x=1796525008; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=3CaNphA2/6V8UNcSalG5w305ta+5iT96FUlJJg+0fBQ=; b=VVaiJiEmHBwqq7G40SEwfkZyBOwo7WJ2QnOpVDDlL2vwXkAl7gf9E1Awga4fSOwINO wuPN3HMz6s/2/jBz8IejQSNJniN+wKqtBqN10aXCWwN6sgtaV25WfqrEJ2B1oQOITwf7 IWcZ47l4w+/gf4hOVgGB2IFxVwNBU4G+T/dVwr4qA2WOOYxfUw6cXTmSUI5fepzu5rJm Tu580a+0yfylxMJLb16EpXotF/xTx0UIEPC8ak5XcD2njuaq2LZQrEsT3yDqqEQT/Bda 4//OG50p2cHZl4Nqr53YGPN6dsUWLUPgEEF+Lf2vQG1biEZ0xy8kUR/jAbEkgQSb4Wfv 72AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795920208; x=1796525008; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3CaNphA2/6V8UNcSalG5w305ta+5iT96FUlJJg+0fBQ=; b=sdhXWo0kU60fwwi5hqjZAEantwWIAtaEOa1do5eiQpmUShDr6bgWk/GxVe5WaHQCsi PMX9k7RY9v3vWEokSymz1VEMvW48WIHR5VFMHE3XNhlVC+pFAgTL9j3seFxPlyui9e+h trcQd37lxuoPpgOWK1cpd+cTGBVlyJIfNwn6W34WCY9uiWtkkzf7qdFTro7220fErKlg sE62Ygi9IYOfGxKqSa3PUKGEkWf3ivVosvombYl4xCVcQLC7xYkPZv6e3ovde6FsiCy7 +QZ4unVHhAaIpvWochau5UlW8+/ZsRwjdfU45skEcW36U0c2G6u7UZzQNxK0RhHNx6+S VomQ== X-Forwarded-Encrypted: i=1; AL+hErEoYUcv6y9VPSLrq+FTwiOcwqjTzCA6kLBkk7eJRT/nh8ZBqtzgeGRlTGEBOoaBcjVmoAGEZxfLGEIqQVt9@vger.kernel.org X-Gm-Message-State: APuU4Z9dwO13yigIAs46/JTRXRhNfFRdPb5RnpBCxck7X2JQWaVYCiCb 7DSJcw/DehUzPCNPjfKq/rArDVxHfasMB5WeuGK3m1h4GMxS98zhXaZO X-Gm-Gg: AZFdTZe5XzwIcB1yo5zmEJtpNkzfOrlF/dpEaYTPhnSSY/DTRqLdM2HN0uErFN5oTBq 7iYXGl2RqSQtgSxxuFMcKX44qmXK7xMJY/8yM/lqTZH9Jxkq5Bo4SSbAqPJ+c1s78sSXPF3+Bsb atcJUy7A36gp65MelrxMJ8gVk6mzr15A6JB9MMjlhui6DraDyvdITtwIXQnx57pOEBhHgBNVOnA EbhpDUwogbXHis5o/PDWXAxUZsBd9s3fowlC6JLJko8txLc5d9roukFkSejT7VuoLp7Zrg2ir3d GhKD3+qD7JvqHjxsgjXRnk3r9gZ5VJr078TDQMy9/0uaLXt6apmNR7AN322hcLOQguHsFaElqBB 6Zvfu3VkkMQylTkhASstJxDg/qrFQvHawD49vBgzEw0qQqckbfmhRa7FRj7AgRheJyVDoZopBp7 hVIPcb8qJCxWd7JoRe0X3y/6tNBaFC7KlzARbXcRZyPdy9YQMrPsXvMSuMQUCzl3B2QlCCP6xbe MpWv6VtwHp8sW+xyIS/r0DmiuY2JCmz5nxKEccOwV212DhojnKU7+0/eYNkOz3+WJushb2Sxky4 ncK2Cg26mOC6FpbObaaS1sLO X-Received: by 2002:a05:6000:4026:b0:4c1:4d45:f5e6 with SMTP id ffacd0b85a97d-4c14d45f76cmr8517039f8f.12.1795920208339; Sat, 28 Nov 2026 18:43:28 -0800 (PST) Received: from infinity ([2001:b07:5d26:7a6a:365a:60ff:fe0d:cfc6]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6b110ba3sm46551960f8f.35.2026.11.28.18.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 18:43:27 -0800 (PST) From: koraynilay To: Namjae Jeon , Hyunchul Lee , Jonathan Corbet , Eric Biggers , "Theodore Y . Ts'o" , Jaegeuk Kim , Alexander Viro , Christian Brauner Cc: 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=20Roh=C3=A1r?= , Lauri Gates , Christoph Hellwig , Dave Chinner , linux-btrfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, ntfs@lists.linux.dev, linux-nfs@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, linux-unionfs@vger.kernel.org, koraynilay Subject: [PATCH v3 0/5] Add f*_xflags_{rw,ro}_mask flags to the fileattr API Date: Sun, 29 Nov 2026 03:42:28 +0100 Message-ID: <20261129024233.2361718-1-koray.fra@gmail.com> X-Mailer: git-send-email 2.56.0 X-Mailing-List: linux-unionfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This is a follow up patch series stemmed from [1] and [2], splitting the _mask change for the fileattr API into its own separate patch series. Patch 1 is a preparatory cleanup so that the code in the later patches can be formatted better. Patch 2 is the actual implementation, which introduces: - fa_xflags_{rw,ro}_mask fields to struct file_attr - fsx_xflags_{rw,ro}_mask fields and has_masks selector to struct file_kattr - AT_FILEATTR_MASKS at_flag for file_[gs]etattr() These masks have the following semantics: - rw_mask: * for filesystems: advertise which xflags they support changing * for userspace: specify which xflags it wants to modify - ro_mask: * for filesystems: advertise which xflags they support only reading * for userspace: ignored (More details available in Patch 5) This allows userspace to not have to do a RMW cycle when using the file_[gs]etattr() syscalls, avoiding possible race conditions and simplifying their usage. This patch also introduces the missing FS_XFLAG_PROJID flag so that programs like chattr can leverage the new mask API. FS_XFLAG_PROJID is kept out of the legacy FS_XFLAGS_MASK and so it's defined as part of a new FS_FILE_ATTR_XFLAGS_MASK group of xflags that will be used moving forward for any new xflag (like the one proposed in [2]). Patch 3 adds FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT (as FS_COMPR_FL and FS_ENCRYPT_FL counterparts), which are needed for Patch 4. This means that old programs will also get these new flags, but that should be fine since xflags were made to be expandable. Patch 4 converts fs/ntfs to this new API, to show how it can benefit filesystem drivers too. Patch 5 adds the Documentation/filesystems/fileattr.rst page that explains well how this API can be used by both userspace and by filesystems and the various semantics. (It doesn't go into *too much* detail though, since that would mean writing the code itself). The rendered page can be found at [4]. The series has been tested with custom xfstests [3] (generic/816-835, xfs/611, xfs/673) across NTFS, ext4 (project quotas), XFS (project quotas and extent size hints), Btrfs, and F2FS. Note: these tests were written by gemini and not manually checked, before sending them upstream (if needed) I'll have to review/rewrite them manually. IMPORTANT NOTE: there are quite a few bugs with overlayfs (generic/832-835 above) when using a masks filesystem, I haven't investigated them deeply yet since I would first need to understand a lot more how overlayfs works, but the robot's report is in [5]. v3 changes: - refactor the big if/else in vfs_fileattr_set() to a fileattr_set_convert() helper and simplify (hopefully?) its code; - drop fscrypt flags -> xflags patch and just use xflags_to_flags() in vfs; - add FS_XFLAG_COMPR/ENCRYPT in a separate patch instead of in the ntfs one ([6]); - move FILE_ATTR_SIZE_VER* variables from the uapi header to the internal header ([7]); - rename AT_FILE_ATTR_MASKS to AT_FILEATTR_MASKS ([8]); - change "legacy" references to "rmw" references in both comments and helper names ([8]); - add docs. v2 changes: - make fa_xflags_{rw,ro}_mask in struct file_attr __u64; - add AT_FILE_ATTR_MASKS to opt in to mask semantics instead of needing unreliable heuristics on usize and mask values; - reject intermediate sizes between VER0 and VER1; - reject non-zero masks on SET without AT_FILE_ATTR_MASKS; - add patch 2/4 for fscrypt_prepare_setflags; - add xflags_to_flags() / flags_to_xflags() and fileattr_set_{legacy_to_mask,mask_to_legacy}() to translate between legacy RMW callers/filesystems and _mask callers/filesystems; - clamp fa->fsx_xflags to rw_user_mask in file_attr_to_fileattr(); - update fileattr_set_prepare() to validate capabilities and projid changes against rw_user_mask / xflags; - move the rw_mask == 0 early-return no-op from file_setattr() into vfs_fileattr_set(); - put FS_XFLAG_COMPR in FS_XFLAG_RDONLY_MASK only (keep FS_XFLAG_ENCRYPT in both FS_XFLAG_COMMON and FS_XFLAG_RDONLY_MASK); - update ntfs_fileattr_set() to apply only bits selected in fsx_xflags_rw_mask; Thanks, koraynilay [1]: https://lore.kernel.org/CAOQ4uxg8aVcWyNiFDk8djdn-M3xJcu_7-kRxVq9jjFsbcGp1ew@mail.gmail.com/ [2]: https://lore.kernel.org/CAOQ4uxjVQ9cjV=_jBjQtNg9zCuWUEJT9KNYMKV+1jwBkHen5OA@mail.gmail.com/ [3]: https://github.com/koraynilay/xfstests/tree/patches-in-queue [4]: https://koraynilay.neocities.org/linuxdocs/fileattr [5]: https://koraynilay.neocities.org/vfs-masks/overlayfs-fileattr-bugs [6]: https://lore.kernel.org/CAOQ4uxgJjy3TaORBkMOdef-JvzX2uA5K2sbMDEcLqmpkedsESw@mail.gmail.com/ [7]: https://lore.kernel.org/CAOQ4uxi6oyFj_A9nPbgGeSufGo11L2N=QxLi2DW=ZKy25YQ5Tw@mail.gmail.com/ [8]: https://lore.kernel.org/CAOQ4uxhA+93bo5WseLxe7cAvJHJ8eQodoQHLwh=iToyEVkeXEA@mail.gmail.com/ koraynilay (5): vfs: use goto out on error in vfs_fileattr_set() vfs: add xflags masks to fileattr API vfs: add COMPR/ENCRYPT xflags from FS_COMPR_FL/FS_ENCRYPT_FL ntfs: switch to the new xflags fileattr API docs: add fileattr API documentation Documentation/filesystems/fileattr.rst | 530 +++++++++++++++++++++++++ Documentation/filesystems/index.rst | 1 + Documentation/filesystems/vfs.rst | 19 +- fs/file_attr.c | 379 +++++++++++++++--- fs/ntfs/file.c | 109 ++--- include/linux/fileattr.h | 19 +- include/uapi/linux/fcntl.h | 6 + include/uapi/linux/fs.h | 37 +- 8 files changed, 985 insertions(+), 115 deletions(-) create mode 100644 Documentation/filesystems/fileattr.rst base-commit: 3857587d9d6fa44d40d1c73bde6a39f6f7a5216c -- 2.56.0