Fix DM DAX handling
Subsystems (9)
cover Fix DM DAX handling
This is a v4.17-stable backport of my "Fix DM DAX handling" series which had backport collisions.
Greg, please let me know if I need to adjust anything in my backport formatting.
Darrick J. Wong (1):
fs: allow per-device dax status checking for filesystems
Dave Jiang (1):
dax: change bdev_dax_supported() to support boolean returns
Ross Zwisler (3):
pmem: only set QUEUE_FLAG_DAX for fsdax mode
dax: bdev_dax_supported() check for QUEUE_FLAG_DAX
dm: prevent DAX mounts if not supported
drivers/dax/super.c | 48 ++++++++++++++++++++++++++++-------------------- drivers/md/dm-table.c | 7 ++++--- drivers/md/dm.c | 3 +-- drivers/nvdimm/pmem.c | 3 ++- fs/ext2/super.c | 3 +-- fs/ext4/super.c | 3 +-- fs/xfs/xfs_ioctl.c | 3 ++- fs/xfs/xfs_iops.c | 30 +++++++++++++++++++++++++----- fs/xfs/xfs_super.c | 10 ++++++++-- include/linux/dax.h | 11 ++++++----- 10 files changed, 78 insertions(+), 43 deletions(-)
Signature · 1 line
2.14.4
PATCH 1/5 fs: allow per-device dax status checking for filesystems
From: "Darrick J. Wong" <[email protected]>
Commit ba23cba9b3bd upstream.
Change bdev_dax_supported so it takes a bdev parameter. This enables multi-device filesystems like xfs to check that a dax device can work for the particular filesystem. Once that's in place, actually fix all the parts of XFS where we need to be able to distinguish between datadev and rtdev.
This patch fixes the problem where we screw up the dax support checking in xfs if the datadev and rtdev have different dax capabilities.
--- drivers/dax/super.c | 26 +++++++++++++------------- fs/ext2/super.c | 2 +- fs/ext4/super.c | 2 +- fs/xfs/xfs_ioctl.c | 3 ++- fs/xfs/xfs_iops.c | 30 +++++++++++++++++++++++++----- fs/xfs/xfs_super.c | 10 ++++++++-- include/linux/dax.h | 9 +++++---- 7 files changed, 55 insertions(+), 27 deletions(-)
drivers/dax/super.c +13 -13
@@ -74,7 +74,7 @@ EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev);/** * __bdev_dax_supported() - Check if the device supports dax for filesystem -* @sb: The superblock of the device +* @bdev: block device to check * @blocksize: The block size of the device * * This is a library function for filesystems to check if the block device
@@ -82,33 +82,33 @@ EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev);* * Return: negative errno if unsupported, 0 if supported. */ -int __bdev_dax_supported (struct super_block *sb,int blocksize) +int __bdev_dax_supported (struct block_device *bdev,int blocksize) { -struct block_device *bdev = sb->s_bdev;struct dax_device *dax_dev;pgoff_t pgoff;int err, id;void *kaddr;pfn_t pfn;long len; +char buf[BDEVNAME_SIZE ];if (blocksize !=PAGE_SIZE ) { -pr_debug ("VFS (%s): error: unsupported blocksize for dax\n" , - sb->s_id); +pr_debug ("%s: error: unsupported blocksize for dax\n" , +bdevname (bdev, buf));return -EINVAL ; } err =bdev_dax_pgoff (bdev,0 ,PAGE_SIZE , &pgoff);if (err) { -pr_debug ("VFS (%s): error: unaligned partition for dax\n" , - sb->s_id); +pr_debug ("%s: error: unaligned partition for dax\n" , +bdevname (bdev, buf));return err; } dax_dev =dax_get_by_host (bdev->bd_disk->disk_name);if (!dax_dev) { -pr_debug ("VFS (%s): error: device does not support dax\n" , - sb->s_id); +pr_debug ("%s: error: device does not support dax\n" , +bdevname (bdev, buf));return -EOPNOTSUPP ; }
@@ -119,8 +119,8 @@ int __bdev_dax_supported(struct super_block *sb, int blocksize)put_dax (dax_dev);if (len <1 ) { -pr_debug ("VFS (%s): error: dax access failed (%ld)\n" , - sb->s_id, len); +pr_debug ("%s: error: dax access failed (%ld)\n" , +bdevname (bdev, buf), len);return len <0 ? len : -EIO ; }
@@ -137,8 +137,8 @@ int __bdev_dax_supported(struct super_block *sb, int blocksize) }else if (pfn_t_devmap (pfn)) {/* pass */ ; }else { -pr_debug ("VFS (%s): error: dax support not enabled\n" , - sb->s_id); +pr_debug ("%s: error: dax support not enabled\n" , +bdevname (bdev, buf));return -EOPNOTSUPP ; }
fs/ext2/super.c +1 -1
@@ -961,7 +961,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent) blocksize =BLOCK_SIZE <<le32_to_cpu (sbi->s_es->s_log_block_size);if (sbi->s_mount_opt &EXT2_MOUNT_DAX ) { - err =bdev_dax_supported (sb, blocksize); + err =bdev_dax_supported (sb->s_bdev, blocksize);if (err) {ext2_msg (sb,KERN_ERR ,"DAX unsupported by block device. Turning off DAX." );
fs/ext4/super.c +1 -1
@@ -3732,7 +3732,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) " that may contain inline data"); sbi->s_mount_opt &= ~EXT4_MOUNT_DAX ; } - err =bdev_dax_supported (sb, blocksize); + err =bdev_dax_supported (sb->s_bdev, blocksize);if (err) {ext4_msg (sb,KERN_ERR ,"DAX unsupported by block device. Turning off DAX." );
fs/xfs/xfs_ioctl.c +2 -1
@@ -1103,7 +1103,8 @@ xfs_ioctl_setattr_dax_invalidate(if (fa->fsx_xflags &FS_XFLAG_DAX ) {if (!(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode)))return -EINVAL ; -if (bdev_dax_supported (sb, sb->s_blocksize) <0 ) +if (bdev_dax_supported (xfs_find_bdev_for_inode (VFS_I (ip)), + sb->s_blocksize) <0 )return -EINVAL ; }
fs/xfs/xfs_iops.c +25 -5
@@ -1195,6 +1195,30 @@ static const struct inode_operations xfs_inline_symlink_inode_operations = { .update_time = xfs_vn_update_time, }; +/* Figure out if this file actually supports DAX. */ +static bool +xfs_inode_supports_dax ( +struct xfs_inode *ip) +{ +struct xfs_mount *mp = ip->i_mount; + +/* Only supported on non-reflinked files. */ +if (!S_ISREG (VFS_I (ip)->i_mode) ||xfs_is_reflink_inode (ip)) +return false; + +/* DAX mount option or DAX iflag must be set. */ +if (!(mp->m_flags &XFS_MOUNT_DAX ) && + !(ip->i_d.di_flags2 &XFS_DIFLAG2_DAX )) +return false; + +/* Block size must match page size */ +if (mp->m_sb.sb_blocksize !=PAGE_SIZE ) +return false; + +/* Device has to support DAX too. */ +return xfs_find_daxdev_for_inode (VFS_I (ip)) !=NULL ; +} + STATIC void xfs_diflags_to_iflags( struct inode *inode,
@@ -1213,11 +1237,7 @@ xfs_diflags_to_iflags( inode->i_flags |=S_SYNC ;if (flags &XFS_DIFLAG_NOATIME ) inode->i_flags |=S_NOATIME ; -if (S_ISREG (inode->i_mode) && - ip->i_mount->m_sb.sb_blocksize ==PAGE_SIZE && - !xfs_is_reflink_inode (ip) && - (ip->i_mount->m_flags &XFS_MOUNT_DAX || - ip->i_d.di_flags2 &XFS_DIFLAG2_DAX )) +if (xfs_inode_supports_dax (ip)) inode->i_flags |=S_DAX ; }
fs/xfs/xfs_super.c +8 -2
@@ -1690,11 +1690,17 @@ xfs_fs_fill_super( sb->s_flags |=SB_I_VERSION ;if (mp->m_flags &XFS_MOUNT_DAX ) { +int error2 =0 ; +xfs_warn (mp,"DAX enabled. Warning: EXPERIMENTAL, use at your own risk" ); - error =bdev_dax_supported (sb, sb->s_blocksize); -if (error) { + error =bdev_dax_supported (mp->m_ddev_targp->bt_bdev, + sb->s_blocksize); +if (mp->m_rtdev_targp) + error2 =bdev_dax_supported (mp->m_rtdev_targp->bt_bdev, + sb->s_blocksize); +if (error && error2) {xfs_alert (mp,"DAX unsupported by block device. Turning off DAX." ); mp->m_flags &= ~XFS_MOUNT_DAX ;
include/linux/dax.h +5 -4
@@ -64,10 +64,10 @@ static inline bool dax_write_cache_enabled(struct dax_device *dax_dev)struct writeback_control ;int bdev_dax_pgoff (struct block_device *,sector_t ,size_t ,pgoff_t *pgoff);#if IS_ENABLED (CONFIG_FS_DAX ) -int __bdev_dax_supported (struct super_block *sb,int blocksize); -static inline int bdev_dax_supported (struct super_block *sb,int blocksize) +int __bdev_dax_supported (struct block_device *bdev,int blocksize); +static inline int bdev_dax_supported (struct block_device *bdev,int blocksize) { -return __bdev_dax_supported (sb, blocksize); +return __bdev_dax_supported (bdev, blocksize); }static inline struct dax_device *fs_dax_get_by_host (const char *host)
@@ -84,7 +84,8 @@ struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev);int dax_writeback_mapping_range (struct address_space *mapping,struct block_device *bdev,struct writeback_control *wbc);#else -static inline int bdev_dax_supported (struct super_block *sb,int blocksize) +static inline int bdev_dax_supported (struct block_device *bdev, +int blocksize) {return -EOPNOTSUPP ; }
Signature · 1 line
2.14.4
PATCH 2/5 dax: change bdev_dax_supported() to support boolean returns
In reply to Ross ZwislerFrom: Dave Jiang <[email protected]>
Commit 80660f20252d upstream.
The function return values are confusing with the way the function is named. We expect a true or false return value but it actually returns 0/-errno. This makes the code very confusing. Changing the return values to return a bool where if DAX is supported then return true and no DAX support returns false.
--- drivers/dax/super.c | 16 ++++++++-------- fs/ext2/super.c | 3 +-- fs/ext4/super.c | 3 +-- fs/xfs/xfs_ioctl.c | 4 ++-- fs/xfs/xfs_super.c | 12 ++++++------ include/linux/dax.h | 8 ++++---- 6 files changed, 22 insertions(+), 24 deletions(-)
drivers/dax/super.c +8 -8
@@ -80,9 +80,9 @@ EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev);* This is a library function for filesystems to check if the block device * can be mounted with dax option. * -* Return: negative errno if unsupported, 0 if supported. +* Return: true if supported, false if unsupported */ -int __bdev_dax_supported (struct block_device *bdev,int blocksize) +bool __bdev_dax_supported (struct block_device *bdev,int blocksize) {struct dax_device *dax_dev;pgoff_t pgoff;
@@ -95,21 +95,21 @@ int __bdev_dax_supported(struct block_device *bdev, int blocksize)if (blocksize !=PAGE_SIZE ) {pr_debug ("%s: error: unsupported blocksize for dax\n" ,bdevname (bdev, buf)); -return -EINVAL ; +return false; } err =bdev_dax_pgoff (bdev,0 ,PAGE_SIZE , &pgoff);if (err) {pr_debug ("%s: error: unaligned partition for dax\n" ,bdevname (bdev, buf)); -return err; +return false; } dax_dev =dax_get_by_host (bdev->bd_disk->disk_name);if (!dax_dev) {pr_debug ("%s: error: device does not support dax\n" ,bdevname (bdev, buf)); -return -EOPNOTSUPP ; +return false; } id =dax_read_lock ();
@@ -121,7 +121,7 @@ int __bdev_dax_supported(struct block_device *bdev, int blocksize)if (len <1 ) {pr_debug ("%s: error: dax access failed (%ld)\n" ,bdevname (bdev, buf), len); -return len <0 ? len : -EIO ; +return false; }if (IS_ENABLED (CONFIG_FS_DAX_LIMITED ) &&pfn_t_special (pfn)) {
@@ -139,10 +139,10 @@ int __bdev_dax_supported(struct block_device *bdev, int blocksize) } else {pr_debug ("%s: error: dax support not enabled\n" ,bdevname (bdev, buf)); -return -EOPNOTSUPP ; +return false; } -return 0 ; +return true; }EXPORT_SYMBOL_GPL (__bdev_dax_supported);#endif
fs/ext2/super.c +1 -2
@@ -961,8 +961,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent) blocksize =BLOCK_SIZE <<le32_to_cpu (sbi->s_es->s_log_block_size);if (sbi->s_mount_opt &EXT2_MOUNT_DAX ) { - err =bdev_dax_supported (sb->s_bdev, blocksize); -if (err) { +if (!bdev_dax_supported (sb->s_bdev, blocksize)) {ext2_msg (sb,KERN_ERR ,"DAX unsupported by block device. Turning off DAX." ); sbi->s_mount_opt &= ~EXT2_MOUNT_DAX ;
fs/ext4/super.c +1 -2
@@ -3732,8 +3732,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) " that may contain inline data"); sbi->s_mount_opt &= ~EXT4_MOUNT_DAX ; } - err =bdev_dax_supported (sb->s_bdev, blocksize); -if (err) { +if (!bdev_dax_supported (sb->s_bdev, blocksize)) {ext4_msg (sb,KERN_ERR ,"DAX unsupported by block device. Turning off DAX." ); sbi->s_mount_opt &= ~EXT4_MOUNT_DAX ;
fs/xfs/xfs_ioctl.c +2 -2
@@ -1103,8 +1103,8 @@ xfs_ioctl_setattr_dax_invalidate(if (fa->fsx_xflags &FS_XFLAG_DAX ) {if (!(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode)))return -EINVAL ; -if (bdev_dax_supported (xfs_find_bdev_for_inode (VFS_I (ip)), - sb->s_blocksize) <0 ) +if (!bdev_dax_supported (xfs_find_bdev_for_inode (VFS_I (ip)), + sb->s_blocksize))return -EINVAL ; }
fs/xfs/xfs_super.c +6 -6
@@ -1690,17 +1690,17 @@ xfs_fs_fill_super( sb->s_flags |=SB_I_VERSION ;if (mp->m_flags &XFS_MOUNT_DAX ) { -int error2 =0 ; +bool rtdev_is_dax = false, datadev_is_dax;xfs_warn (mp,"DAX enabled. Warning: EXPERIMENTAL, use at your own risk" ); - error =bdev_dax_supported (mp->m_ddev_targp->bt_bdev, - sb->s_blocksize); + datadev_is_dax =bdev_dax_supported (mp->m_ddev_targp->bt_bdev, + sb->s_blocksize);if (mp->m_rtdev_targp) - error2 =bdev_dax_supported (mp->m_rtdev_targp->bt_bdev, - sb->s_blocksize); -if (error && error2) { + rtdev_is_dax =bdev_dax_supported ( + mp->m_rtdev_targp->bt_bdev, sb->s_blocksize); +if (!rtdev_is_dax && !datadev_is_dax) {xfs_alert (mp,"DAX unsupported by block device. Turning off DAX." ); mp->m_flags &= ~XFS_MOUNT_DAX ;
include/linux/dax.h +4 -4
@@ -64,8 +64,8 @@ static inline bool dax_write_cache_enabled(struct dax_device *dax_dev)struct writeback_control ;int bdev_dax_pgoff (struct block_device *,sector_t ,size_t ,pgoff_t *pgoff);#if IS_ENABLED (CONFIG_FS_DAX ) -int __bdev_dax_supported (struct block_device *bdev,int blocksize); -static inline int bdev_dax_supported (struct block_device *bdev,int blocksize) +bool __bdev_dax_supported (struct block_device *bdev,int blocksize); +static inline bool bdev_dax_supported (struct block_device *bdev,int blocksize) {return __bdev_dax_supported (bdev, blocksize); }
@@ -84,10 +84,10 @@ struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev);int dax_writeback_mapping_range (struct address_space *mapping,struct block_device *bdev,struct writeback_control *wbc);#else -static inline int bdev_dax_supported (struct block_device *bdev, +static inline bool bdev_dax_supported (struct block_device *bdev,int blocksize) { -return -EOPNOTSUPP ; +return false; }static inline struct dax_device *fs_dax_get_by_host (const char *host)
Signature · 1 line
2.14.4
PATCH 3/5 pmem: only set QUEUE_FLAG_DAX for fsdax mode
In reply to Ross ZwislerCommit b5b10ca931ab upstream.
QUEUE_FLAG_DAX is an indication that a given block device supports filesystem DAX and should not be set for PMEM namespaces which are in "raw" mode. These namespaces lack struct page and are prevented from participating in filesystem DAX as of commit 569d0365f571 "dax: require 'struct page' by default for filesystem dax".
--- drivers/nvdimm/pmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvdimm/pmem.c +2 -1
@@ -388,7 +388,8 @@ static int pmem_attach_disk(struct device *dev,blk_queue_logical_block_size (q,pmem_sector_size (ndns));blk_queue_max_hw_sectors (q,UINT_MAX );blk_queue_flag_set (QUEUE_FLAG_NONROT , q); -blk_queue_flag_set (QUEUE_FLAG_DAX , q); +if (pmem->pfn_flags &PFN_MAP ) +blk_queue_flag_set (QUEUE_FLAG_DAX , q); q->queuedata = pmem; disk =alloc_disk_node (0 , nid);
Signature · 1 line
2.14.4
PATCH 4/5 dax: bdev_dax_supported() check for QUEUE_FLAG_DAX
In reply to Ross ZwislerCommit 7abad3ff2030 upstream.
Add an explicit check for QUEUE_FLAG_DAX to __bdev_dax_supported(). This is needed for DM configurations where the first element in the dm-linear or dm-stripe target supports DAX, but other elements do not. Without this check __bdev_dax_supported() will pass for such devices, letting a filesystem on that device mount with the DAX option.
--- drivers/dax/super.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/dax/super.c +8 -0
@@ -85,6 +85,7 @@ EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev);bool __bdev_dax_supported (struct block_device *bdev,int blocksize) {struct dax_device *dax_dev; +struct request_queue *q;pgoff_t pgoff;int err, id;void *kaddr;
@@ -98,6 +99,13 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize)return false; } + q =bdev_get_queue (bdev); +if (!q || !blk_queue_dax (q)) { +pr_debug ("%s: error: request queue doesn't support dax\n" , +bdevname (bdev, buf)); +return false; + } + err =bdev_dax_pgoff (bdev,0 ,PAGE_SIZE , &pgoff);if (err) { pr_debug("%s: error: unaligned partition for dax\n",
Signature · 1 line
2.14.4
PATCH 5/5 dm: prevent DAX mounts if not supported
In reply to Ross ZwislerCommit ebad6343229a upstream.
Currently device_supports_dax() just checks to see if the QUEUE_FLAG_DAX flag is set on the device's request queue to decide whether or not the device supports filesystem DAX. Really we should be using bdev_dax_supported() like filesystems do at mount time. This performs other tests like checking to make sure the dax_direct_access() path works.
We also explicitly clear QUEUE_FLAG_DAX on the DM device's request queue if any of the underlying devices do not support DAX. This makes the handling of QUEUE_FLAG_DAX consistent with the setting/clearing of most other flags in dm_table_set_restrictions().
Now that bdev_dax_supported() explicitly checks for QUEUE_FLAG_DAX, this will ensure that filesystems built upon DM devices will only be able to mount with DAX if all underlying devices also support DAX.
--- drivers/md/dm-table.c | 7 ++++--- drivers/md/dm.c | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/md/dm-table.c +4 -3
@@ -885,9 +885,7 @@ EXPORT_SYMBOL_GPL(dm_table_set_type);static int device_supports_dax (struct dm_target *ti,struct dm_dev *dev,sector_t start,sector_t len,void *data) { -struct request_queue *q =bdev_get_queue (dev->bdev); - -return q &&blk_queue_dax (q); +return bdev_dax_supported (dev->bdev,PAGE_SIZE ); }static bool dm_table_supports_dax (struct dm_table *t)
@@ -1907,6 +1905,9 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,if (dm_table_supports_dax (t))blk_queue_flag_set (QUEUE_FLAG_DAX , q); +else +blk_queue_flag_clear (QUEUE_FLAG_DAX , q); +if (dm_table_supports_dax_write_cache (t))dax_write_cache (t->md->dax_dev, true);
drivers/md/dm.c +1 -2
@@ -1056,8 +1056,7 @@ static long dm_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,if (len <1 ) goto out; nr_pages =min (len, nr_pages); -if (ti->type->direct_access) - ret = ti->type->direct_access (ti, pgoff, nr_pages, kaddr, pfn); + ret = ti->type->direct_access (ti, pgoff, nr_pages, kaddr, pfn); out:dm_put_live_table (md, srcu_idx);
Signature · 1 line
2.14.4
Quoted 5 lines · Ross Zwisler
This is a v4.17-stable backport of my "Fix DM DAX handling" series which had backport collisions.
Greg, please let me know if I need to adjust anything in my backport formatting.
Oops, just noticed that one of the commit IDs I referenced was from a dev branch and not upstream. I'll fix that up, correct my upstream commit ID formatting and sent out a v2.