From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796248483; b=WzVYc1m/b9il7Mo0gS3gftmznYbZ9bJZuCOhs46kUT12s/a8gGD1Ne5IIG+7YZh3lXcW ZEi/1FJALpDrlZvhXOmVtUhqB9fc9BNu67yvsMQmmj+R7ZXN987yFVXKhpYFkeWrAL6U4 TnyfLDjdihW9M4nf+BQkd5yc8fRyWypiS6bkDSqzoDTtcKZEe6Gzgdoaypt1G3Q7UicTJ +OE5BbjXHmYOuOkqpyWW9WOiCwmDOZbGL5rxWC5Ne3oG3E+F68t2pWaoMhVDsNmYPPouT o4Cw2FZnyjCLNxxC32Mz1RifoT1BRC3R7ayEs2xiC9f8zNF0l6YIRIMKVSwiZbtfxXw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796248483; 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=dTktzK+/89hWuiGz0KCJZyfoeRHNN420Otm5sYHG4P8=; b=VDQnjdbXjD8DXazM/rEVeRgG+WVYeC00LlrEi7Ndp6vlRfuThRNYtuCDFN37sXeTaiuQ fVThXhFTh/ZkdN6V5vZm5VRtFRJYE/TwqcMfRLb864ZcvPVXAeWRuKf5yiE1cePFjryQN 0v586lP25Y8AKHLbOfNaMJW82/bX918qgXI3tKfq5WOnHLvPTuGfMdTAa6rB2IxcuP6t1 g9UdTMEXqoCNHonTodJKEdD8HjwzYukzrRYVdRTWExv8FCEeI03Jj0W/9//c6sxMh/O2C Sgxw94101UtQhYqIhVkWXPAwzZfKZHVeYe2HGik0aszWjWJ6268VcEsrfpTWqUTEedA== 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=MBsKFbTN; arc=none smtp.remote-ip=209.85.128.43 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 9C68D606A32F for ; Wed, 2 Dec 2026 21:54:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9C68D606A32F 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=MBsKFbTN Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4bba5e17728so70716985e9.2 for ; Wed, 02 Dec 2026 13:54:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796248481; x=1796853281; 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=dTktzK+/89hWuiGz0KCJZyfoeRHNN420Otm5sYHG4P8=; b=MBsKFbTNrgyPs05PQYTSLQq/+aWsh2uzIWf8Gx9Mqh0pqps8Y5H2GQ+EvkIXmY2jQC zITVvNk650NwJL2+xGMSlG97hlbpqaOshIt+w68WIEz2MpKFG5DPehTQKUVZY+dWxr6q 6f3ZyBPpZaQRC2Xc7CW/GBHweIturxlWtqo73xGRF6gOvZqFryMgAyKExxxBXzWspWyo xk1oVPo4HcHBUAayMbV1SVtsLhnyWxiMPWaCM4GyYzIfXbyzchJ/UlBb+66bicLVQem/ XmLFd3XEm/HV53Ww3jVK2AI8GGh727oYzE0AUHCuggmjNuw/vRoXWeZ4L95+xtYyOoq8 7tTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796248481; x=1796853281; 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=dTktzK+/89hWuiGz0KCJZyfoeRHNN420Otm5sYHG4P8=; b=pb2Xls3I8jgOPfiJmrbVNvVP6K7Tt95djRXEbU52Glf6TxW/xxQrvvTItN4Hy/XfVF VOQu3Q1E4ppW0cWbQaSYAQ5OM8wtnC0lGIkgaae7IGC+kikGMtFcPK4Z0tMECpc8IYTT gW7himXPFA535Hp6rAjsy1HdN7vh9MIkvPRDWWhGiI5Dy6SF0YGQSPhVJ03N5x+D8Uyb dWlfcizlbvZuZr1n5nw/nJQUcEibVWT9+C5wAAyk9JgBNcUUufCzBxb0JC/xgY22x/EQ zHSvaTsn/i7nveWlkqAUQtX6SqTQxt75F5foaXW+O565EX7M2WwPINIgkauCF3NNMzzF 3f+A== X-Forwarded-Encrypted: i=1; AL+hErFgJczIy/qOEoEPpHNQOgEjpZctIKuApBhFXbrmY5BSJzrUrzkToS1XG04MyughvT/Hl75yMf56zoU=@vger.kernel.org X-Gm-Message-State: APuU4Z94rWxn9O6bwCwf7Tn3KY/iNGRCtHT0uqdYHUvk7JBtxck9YCFJ wNX6fFAqWp8C6ItY8A15ekAhtXtTf2RKDalFr5f3hngTkJL/M2dlfTzv X-Gm-Gg: AZFdTZc5jRZ0P6N81ttpq3Yi/6KIXApvIq2LFXq8Sd3uLBmzqEz0Qd+Ppl6BgufvO8K JxJO7PX0dPyxaqsFHrvcddmyPFhnVza8PJ1FjFMg204NpXY82MtU0AiikytXTJRAMVOXuy1P/0J aRAKRU8sX7Cz+UVCnWS3QfsLsRmaFpYJ2uGGmrkflwkmgEyaGIU4uWTTkb2CjPbjvf/VBYuO5AJ l4+UbtcM3qDfF2Z5yPuf169gVOwVBF1FSCHtSwVXPGtM3fWRWirjX65ZDhDWKnx7vEfegbv3B3T JXIvBc/lzLG0189fBmpNn4mrpFdBxRpKn3LGRpF+DmGQ/FiuuDBVxQDIGdgNACRXXAd6ksYsEqs +fxbpcCEQKbP+bTOOfxP4pZHyf6YUIo/Ym6Ik/EXRrZbdLIxEnWz+DB2F+zPqF75rAs2ftjamSy GZo4iGky/tSFWjLRHG2hnwwwZ0LdhRcZ4hE97HQHlmhY3kLpnXmts7VtFxcE2O8S6GMBQ0XW7aB 6Dr3PpVHZMO9Y8lubk6B3jIryzgFFqb2ct7Q7TAKOSfYH1SWlTazzgDOJbt6GFqVdPagpKTpd94 W9MyMEtXd0D3fZXlJwqkNbMk X-Received: by 2002:a05:600d:4:b0:4bb:abe2:bbd4 with SMTP id 5b1f17b1804b1-4bbabe2bcfdmr400473925e9.19.1796248480844; Wed, 02 Dec 2026 13:54:40 -0800 (PST) Received: from infinity ([2001:b07:5d26:7a6a:365a:60ff:fe0d:cfc6]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab65cb42absm78560708f8f.1.2026.12.02.13.54.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 13:54:40 -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 v4 0/7] Add f*_xflags_{rw,ro}_mask flags to the fileattr API Date: Wed, 2 Dec 2026 22:54:20 +0100 Message-ID: <20261202215427.798262-1-koray.fra@gmail.com> X-Mailer: git-send-email 2.56.0 X-Mailing-List: linux-nfs@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. The series extends the fileattr API with xflags masks by introducing: - fa_xflags_{rw,ro}_mask fields to struct file_attr - fsx_xflags_{rw,ro}_mask fields and has_masks / use_masks / get_only_masks selectors 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 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. The series 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 FSX_FSXATTR_MASK and defined as part of the new FSX_FILEATTR_MASK group of xflags that will be used moving forward for any new xflag (like the one proposed in [2]). In addition, FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT are added (as FS_COMPR_FL and FS_ENCRYPT_FL counterparts) for fs/ntfs, which is converted to the new mask API as an example. Old programs will also get these new flags, which should be fine since xflags were made to be expandable. Documentation/filesystems/fileattr.rst explains how this API can be used by both userspace and filesystems along with 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]. A few of them can be fixed with the robot-proposed simple diff at [10], but I haven't investigated much why it works (as I also don't really understand well how overlayfs works yet). To help me develop this patch series I used Gemini 4 Hydrogen/Neon in antigravity-cli to audit the code, find edge-cases, propose possible fixes, develop and run the tests above and help with comments/language/style. Thanks, koraynilay v4 changes: - add patch 2/7 to shorten internal xflag macro names (FSX_*) and document FSX_COMMON / FSX_RDONLY_MASK; - split ntfs conversion into flags->xflags (5/7) and masks support (6/7); - add use_masks and get_only_masks selectors to struct file_kattr, and clamp FS_IOC_SETFLAGS in fileattr_set_convert() (as discussed in [9]); - rename fileattr_set_{rmw_to_mask,mask_to_rmw}() to fileattr_set_{to,from}_masks(); - reject rw_mask == 0 and clearing value attributes with non-zero values with -EINVAL; - add FSX_FSXATTR_SET_MASK and clamp unmasked new_xflags in fileattr_set_from_masks(); - add fileattr_has_invalid_fsx_masks() and use it in ntfs_fileattr_set(); - update docs per v3 review (focus on internals, reference man-pages, VER0/VER1 phrasing); - dropped all Assisted-by tags and add LLM-usage explanation above. 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; [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/vfs-masks/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/ [9]: https://lore.kernel.org/DN8RMUP6F5CI.2KSDF5TMCRO1X@gmail.com/ [10]: diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c index 92df4f5c071e..8d4753fd2d92 100644 --- a/fs/overlayfs/inode.c +++ b/fs/overlayfs/inode.c @@ -747,6 +747,9 @@ int ovl_fileattr_get(struct dentry *dentry, struct file_kattr *fa) err = ovl_real_fileattr_get(&realpath, fa); ovl_fileattr_prot_flags(inode, fa); + if (!err && fa->has_masks) + fa->get_only_masks = true; + return err; } koraynilay (7): fs: use goto out on error in vfs_fileattr_set() fs: rename FS_XFLAGS_MASK and shorten other internal macro names fs: add xflags masks to fileattr API fs: advertise COMPR/ENCRYPT xflags in file_getattr() ntfs: switch from flags to xflags in ntfs_fileattr_get/set() ntfs: support the fileattr API masks in ntfs_fileattr_get/set() docs: add fileattr API documentation Documentation/filesystems/fileattr.rst | 469 +++++++++++++++++++++++++ Documentation/filesystems/index.rst | 1 + Documentation/filesystems/vfs.rst | 19 +- fs/file_attr.c | 404 ++++++++++++++++++--- fs/ntfs/file.c | 98 +++--- fs/overlayfs/copy_up.c | 2 +- fs/overlayfs/inode.c | 2 +- include/linux/fileattr.h | 95 ++++- include/uapi/linux/fcntl.h | 6 + include/uapi/linux/fs.h | 38 +- 10 files changed, 1010 insertions(+), 124 deletions(-) create mode 100644 Documentation/filesystems/fileattr.rst base-commit: d8d9179592a52044a52591b31b914cfc0edbf36d -- 2.56.0