From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795920210; b=AfZ4DrWpo1YdbfHH1tSh1yz5ofLq4dIbNCylMroDLvQl+NnzknzB09GPGnL9oBkapbX0 D9yB5o8NDaLXYxj16fkj1ZTNMPq83W8+1HC5kbEj6ak+wd1bRgCnizlNSgFEno7Fozlxh jQVV0ZOtzZpnBLMrU8wMskv4dzn6232MfZuqR5HGo6Lkw4l1r0uVRYyCJX+jRv/CuOIu4 Bi6hsUUBdsB/SYRP4tQIwk9234qtzqrmRsxwlHQoderi8O64Oi1fAuNtbOAdv8NUljrIm 51Hesein5KGXkrwxKbMIf9XkKRd5S2olFA2YmJBM2GkDZL0uHeMpoNSH3VkEzwblUAw== 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=ZcyqTXTBfT+j7d15GjidK3GkPVoTna0Jm2cVNU2SjBeyeOC2Nk51fB1bWh93AABhpVbP TrXREL8RJC1cwIBLALOG7fo0GuymzCLLNzd3HjFpUtCc+Pgq5+ONGfyWDY6cF79OT4Bvq 3b/UEbs63YRWY4ednodCkTv+X465EtgBcSGoO/CyEbdeF9o43T3ipE6rZ/JFN8zhbHj4z xU+mutkne90VEnu+4LNdMGhB8JXjgBWIZGeB9mXw7MJZXMN2thADKTtKr5rwx9+bsDnHz Rcyt8Gx5gmtA8of98NTmXa2j8B3F60M3RCxoNRn1DOJKaxoA+XCILwS+M/ihIjGHAhg== 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.46 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 38AB7606A326 for ; Sun, 29 Nov 2026 02:43:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 38AB7606A326 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-f46.google.com with SMTP id ffacd0b85a97d-49465892f7bso6826903f8f.1 for ; Sat, 28 Nov 2026 18:43:30 -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=HvHDadW6epwHDUzqjGTudxNN3J9juZglV3KlgWbyYpGKf2NKO9W5mXSx+zgNb4P/xq l7v3rZTLmhISkiwC62Y8VXtELdiOv+BE2FjNyKYvqslpNJJHAqZSCs9x+NvIiggW8HE1 aViI5MmnjDeNL/5vjMtC96Bibfs1OMw8RCDH9l6Bbz+lwwtYXz4nwTALELn84pIRYUF8 Q/nVBqN/UHspvMWYHaWOK+9mUvT7qBGS2fqJRZ6eqpn27ms7bHGQ0o37WpVJby/4R8nh Tgz7cGuTZOhrqH1L8d4TpZyP4iIboiIxaPN7qeJXFw1ZWUPKyK9YdQTakV+FlnTR2xSj 7glw== X-Forwarded-Encrypted: i=1; AL+hErEf0trAweZ9g17/NtiznIS8Pgt5a5jHE0Gv0iwh3tcGcxjdstCbKKAxWaUeVNTDDj5JqNqUM/kKZdQ=@vger.kernel.org X-Gm-Message-State: APuU4Z+1WJn82XyDi8oEWmwUgliZ6JEm60O08BQgihIze4oQwWTlFx7v 5OK66YqdNEIEYojzbfpvxRbAqQbtXSY3M6tZNendY6AWi7o+jy2VjTDH X-Gm-Gg: AZFdTZcXPWe3QyiW108VzuSQIEn+IaB05BmhG9RMYFK7UfSyQ57g/L9TQc5QNQV2SEF dkrvc18sQMit/AOZ7JMmIsm0wnmvCktt+WqMrSR2BSj5cH0ICR/NA6IL3Cc9eTG+Y3apls7jBYt tiuwBbz8RQA3z4jk3d80Xkky2+iHWZHphA2snGOlcz2v88lbZY6YwSYjS/9AVUC/fI/KRYFTDF0 JRteqvZ97xR7X7FBteWzzGtsVhTirv6jhj1aEhQY69Zhwf5Y4HHJn+f0LuA9IdJfI0uijDSU57p g3mZgL2z7cbaD7/+iWRWZwDYfOa6cqCuGkRrgKutZthMDYJbts43bKEyBdBdXZQVt5hnJqy/yRc kn39uAnGPhxJCuojUTy6+BLVTMBkRnavljSAP+K12Yqji4gdkZbSSOX1aPhNFamnLIqvUoOFCjR nX9ZzykJJGXIB1tZrDfD/4+k1Yrqiy5Vyr6sQtjKQWafx9LKCrzRDxFr/QJEKFpgx7j15MIibNr nLnSHHRlnpD0zSNglaVwTkbMXX0mwDyuXawVhKkyLmK4aVr5U9cMFa9V3l6qi8osjUcAWvVuRkG L0Y98Np8RGRLrAfiUhv8UxxE 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-xfs@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