From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795920210; b=hBNcwNcJf0tbyU2Mjv7QkFlIh4SJ+pI1ApgF7KhvqxAluPoSzP2g8y0FPlwo3I/i0gj2 fH+4QzK7yddvd8Ojl/BvuRTaBeuFuZd3T8yUBb5UflhCpdGIRv+gl9B40DHil5SIfzbLd yo97QJp/19fyys3DnvAr3/XMcgyHQHyd/trWTWe/jDpP9jUl+QotF0snDBSnRRYVeRUqG 5nG/TFjtbf95xlZmn/nXPkvV1O1vMZnKbheglfWd9i5E1CgZEvVSkVqeydsz/4tl/4xhY N90JXqLK+5fGomc5y7KxKA92LyqwCFWIowKJ0G7Viq91teLWaBe8KVdYYk2aFwwzJYA== 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=eFjjtBYzwpVC+oOzjpwPPtEAfKJwA8RIeJ/3cFKlN/VQtGmRQSStI4xFUUeLaUslRIKs HZxakg/yTbbUZEJzJBu6R2K0B45L3OuJ0cccmFI4vc4E1znsCzvSzsoqQtUzCeDF02Jry 2p8g1VjQrJrw9msyL1JT2h7q0WIouWMxkVZS0Gj5FK5xs9KSxYp8ILdx1XbeJSvfuEMHy 5+K44i/vyPWdm9KZa7QT04ghPX3gFxXWXpvtn8qsOJRc2u1LwiaLMEVUMs02hF2SQ8g5t JsMv8Db9UrWst+pkW7CcmP08B5hgdK7dGq2Kt2b6SoYwIEzCCog2xZVlYrHMyLew5mQ== 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.43 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.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 43536606A32C for ; Sun, 29 Nov 2026 02:43:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 43536606A32C 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-f43.google.com with SMTP id ffacd0b85a97d-4a42b34e930so8211973f8f.2 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=MZa4xk9g1pXGZ2iaJf2Fc65TXUnKBiM1/25c3nxrQKGBHNUq105PEyeumd08qVmnI5 sA2/1ewLZdglg2y+KoO423SiuQUJwwOatcDO6gscPQy06H7IXriTRpZuHj4fhGNjvU8b BwjOw8LQiaEhsR1IAh5nskI2nJShB2Si4KZUCs/qarcaxW+dXIwyzFLcHXfm3p6Xs4Xg 5v9KPDp5/6EanUaIk+L2oZnTReODnotD13dKzn6LvLE3UULLEidyAWKJu1P/JHar9n0Y LaCQGd3cs0oWvx8vjvl7ze2TSNcMcVdnOxVt678la5BcmiNg7tJTmMPhBPdJeBA2WBdn k03Q== X-Forwarded-Encrypted: i=1; AL+hErG5UjYIAVfXX+Bu4VGpcmBS8SIHgYyDO350o8Zud4yHg/vG1ive90wa53JaOSO8XVa/L8bxuZuah/c=@vger.kernel.org X-Gm-Message-State: APuU4Z94VGlhbHRIXq5wNyIHQn9h6TXGSQWsf2hs+tPPHuUyiZ1djnfb LFWaaQF+wrVt0jM337LhPIkJG/qmXRXfbevkFpSl2aeGQFCioaPmRM/P X-Gm-Gg: AZFdTZcr2HNn60VWaknBRE8jNVuQ3ku9K4zXw/ksFFTz6BRPziKC3zasJFBdlZDCCX4 ZfKyVeEu1W7JyhxC3oW4GSHRwSlpZCMPDIifnx/Ua4cjjWNDisvgJyWMXPFpIYHc4gHSj/In99u EIsRX2GWENi0WJsrPWEL4Dbn6HY5BaakyisOU29KmSeGJKJqpLUs9ZFuZ8ijNkyh1Dq5EynY/Gy bF3F9KszuXNo+5EQ6z+Z5Vc6AXZbb8px3lVsDcSVNIxtJ56rAx/yv8b3iGxkxMVGQKji4hlpUdL uNOyFDMPxzNmZF4EkwhFbU8yqDtG5rGYLSFMLMXtO4D8hUMs/ujDJ1ORGOpDF9YJCBzrXLVrgn+ rbkhso124001p5mllW3aRn4hanGSdSiDGh3ahPTQmQkavspNbhPUvjQoqSBIF7fbjBk84NWWCzq J2Xvdz6CHpPFzDRs4a59Oy9JG4gvDQpfYW2wykKzoYZGCRvv0bpzEAx5cbmkMUHXNJzkA0xjkDA Tpe9j5bvFPuJ6OGjDIx2315afEycA0favFXIrb5tZjP/ObWQHUxD8hgXJvQIwCogGKP0qCMoHkm YUpDPcRXXyKI2o25PJuoPImX 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-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. 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