]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
xfs: conditionally allow FS_XFLAG_REALTIME changes if S_DAX is set
authorDarrick J. Wong <djwong@kernel.org>
Wed, 11 Jun 2025 21:01:23 +0000 (14:01 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2025 10:07:20 +0000 (11:07 +0100)
[ Upstream commit 8d16762047c627073955b7ed171a36addaf7b1ff ]

If a file has the S_DAX flag (aka fsdax access mode) set, we cannot
allow users to change the realtime flag unless the datadev and rtdev
both support fsdax access modes.  Even if there are no extents allocated
to the file, the setattr thread could be racing with another thread
that has already started down the write code paths.

Fixes: ba23cba9b3bdc ("fs: allow per-device dax status checking for filesystems")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
Signed-off-by: Leah Rumancik <leah.rumancik@gmail.com>
Acked-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/xfs/xfs_ioctl.c

index 1afb1b1b831ea3938e20deeb78d29ed2a222b883..ef3dc0778566902c183ea5ebdee380d8b1a30f88 100644 (file)
@@ -1128,6 +1128,17 @@ xfs_ioctl_setattr_xflags(
                /* Can't change realtime flag if any extents are allocated. */
                if (ip->i_df.if_nextents || ip->i_delayed_blks)
                        return -EINVAL;
+
+               /*
+                * If S_DAX is enabled on this file, we can only switch the
+                * device if both support fsdax.  We can't update S_DAX because
+                * there might be other threads walking down the access paths.
+                */
+               if (IS_DAX(VFS_I(ip)) &&
+                   (mp->m_ddev_targp->bt_daxdev == NULL ||
+                    (mp->m_rtdev_targp &&
+                     mp->m_rtdev_targp->bt_daxdev == NULL)))
+                       return -EINVAL;
        }
 
        if (rtflag) {