From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795920210; b=XFyAUvruzDO7thgJ4opAnZmf9331+bFwOnovHaA6/LfjOLFXBTSCjCnKathG8LgJwMZF nhFMysdMK90NzqZ56JzEWE7Slw8mZ7hHEjG+B50OdS953ZGyL8Te8eTqv8EAoG2PBKj4v Ou8UXoeOsrJZekTDEPAdfN+TshOranpbXJpFUHQ1LQpSXupCzfNRZjDTXJUTDXkbgUWIj EtXmwb21AjfxD3DTONoLKmnlE54yc1uWtgf21rE2fL9Ex5/Y0ZmcgyEfSzLvhyzX94YD5 VSe3StdUhsbp2rPSke3RHh1vTzpxZPMcJA2Pqz35kClzuxQZPcW1Htrpv/30VjCd+yA== 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=i/yw+WtgvSZ/WcEj8r1Z51T+kYSbpkxSr6TA5WdZW6TL9/9ycYOzYvs/o6FKbn7XPMfg IocGTqHrrfqDb5FXEF3cSH/R26wos3BVGGUW+l0r6nIeYFxeT+1S0KDOi1b8nPt4hecpE TZGV4VZs96kuBcyRw7t5g905/ptf0itr/kOHt0Fvl64X170A7yLo0SLgBpQJodZAjqvCj uN0IR3kTDUQmqRQerIMKF2BM+ccx6imR/2GJTRn98wnhVtGM3X5CXO/JINEJPnOx+IL8D KVaJUjMGbHiPg/GwPqurlhA9Z3nvre8UOt100QK3gSf5ihhO+KMdrCm48E+RaEtwcFg== 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.50 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 33E11606A325 for ; Sun, 29 Nov 2026 02:43:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 33E11606A325 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-f50.google.com with SMTP id ffacd0b85a97d-491846221ffso8170764f8f.3 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=Ou2/Q0bur0nnwrPC1ODpLtxug5od1tXAf+RhNu6hp+0uhNzDTsmMeT8V1vWzDTu7+6 MIILsjbmC2yP5xgrpIQS1t/W/xLq1vHJvjwpUMCykmuXPsUME5ei8nuBBKTblMmcZ6QM P0Y+ay5i6im/4eZFemqBfsaYn24KhHLsLPr085TTZ3orYo0P/mejVf6+t0eCx/zfdezB W7lx3x4heL1KnoC8oNpCNUDsd4wObyHmU5RLHBEsd8M7sVf8Cvrw32rM5zUm8EKFAPOy GYAfr6go4zGJYuY0h2otw8BSW0jshx+Oqsv282d/2TlGcoeBqBkz/yK8d5Dcr/+0bO4s sbWA== X-Forwarded-Encrypted: i=1; AL+hErEZvA2PsabNrygFv8IRcV7VdMRetzDNCoapIKti1/CMGLBIV0Exb1lbbVfAFgwYs3GsgXNG6YdDbSwDs3g=@vger.kernel.org X-Gm-Message-State: APuU4Z89QE60lU/ickz6yG4Ik5qgAtLfhdVHwgRezzS6qtjdzrG1LFM7 AXvYWyNbFIGvjZ7kd42vIEhhh60hbl8WTm7Uo+NIZ0MffVwmAngVZrTr X-Gm-Gg: AZFdTZch3K8bDG45rpI55NUhjFbUy84DxdCWaCgS8CQKNqJE2notURGLN1dMyF6Vv3R d+5BB+nXcS76eAhOeSFBMBQ8maVnxc4UoKL+fXT5lkxXFUCjwcZPSKcpQsKDxT1teQ8//Rw5vWG pThPwGwgmYW/irnQ2EZ8WpNICvg+0pMzJj6yFcIw77I4GBHYWpoNi5fcp3neR0p/Y6VSjcUKyy+ CoP2bwu6/2PM/4txjGkQnFEimmxH8mTU/TzCNMvuAS4qPmnRSJpvqWjOguArlOgPbKaLg0EECko datjf0S9DAgFIwXQTNExfVbBNLPjIJl6qPFubH/jfMm5ZRnjotLN9daGR4aYADAjNqkViVrWRSH tLId34DJQuf0wVq74XqgkvjShf5K2WRfHL/lUgmhsCP+6qMZROmVyzWiLwMEQhrDQdRU5bS8wTM WAP/TpXxCT6Z/E3qk8JQY8uSRt2TR4YloaFxg/GjDrxJWjmbVjKpNoL6xi/YuyYsLgT0tuwZhTr UBKo8vJRCbE3k/bC+tokL43ImMeMhMbFVFTtHiV6dqrshb/l38pPpObt8MKBxlzirmrIDKyGnoF JU3ea2IYkXrHWexWETj+HR5C 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-kernel@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