Skip to content

Commit a64e5a5

Browse files
mcgrofbrauner
authored andcommitted
bdev: add back PAGE_SIZE block size validation for sb_set_blocksize()
The commit titled "block/bdev: lift block size restrictions to 64k" lifted the block layer's max supported block size to 64k inside the helper blk_validate_block_size() now that we support large folios. However in lifting the block size we also removed the silly use cases many filesystems have to use sb_set_blocksize() to *verify* that the block size <= PAGE_SIZE. The call to sb_set_blocksize() was used to check the block size <= PAGE_SIZE since historically we've always supported userspace to create for example 64k block size filesystems even on 4k page size systems, but what we didn't allow was mounting them. Older filesystems have been using the check with sb_set_blocksize() for years. While, we could argue that such checks should be filesystem specific, there are much more users of sb_set_blocksize() than LBS enabled filesystem on upstream, so just do the easier thing and bring back the PAGE_SIZE check for sb_set_blocksize() users and only skip it for LBS enabled filesystems. This will ensure that tests such as generic/466 when run in a loop against say, ext4, won't try to try to actually mount a filesystem with a block size larger than your filesystem supports given your PAGE_SIZE and in the worst case crash. Cc: Kent Overstreet <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Kent Overstreet <[email protected]> Reviewed-by: "Darrick J. Wong" <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 29d1280 commit a64e5a5

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

block/bdev.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ EXPORT_SYMBOL(set_blocksize);
181181

182182
int sb_set_blocksize(struct super_block *sb, int size)
183183
{
184+
if (!(sb->s_type->fs_flags & FS_LBS) && size > PAGE_SIZE)
185+
return 0;
184186
if (set_blocksize(sb->s_bdev_file, size))
185187
return 0;
186188
/* If we get here, we know size is validated */

fs/bcachefs/fs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2396,7 +2396,7 @@ static struct file_system_type bcache_fs_type = {
23962396
.name = "bcachefs",
23972397
.init_fs_context = bch2_init_fs_context,
23982398
.kill_sb = bch2_kill_sb,
2399-
.fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
2399+
.fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_LBS,
24002400
};
24012401

24022402
MODULE_ALIAS_FS("bcachefs");

fs/xfs/xfs_super.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2118,7 +2118,8 @@ static struct file_system_type xfs_fs_type = {
21182118
.init_fs_context = xfs_init_fs_context,
21192119
.parameters = xfs_fs_parameters,
21202120
.kill_sb = xfs_kill_sb,
2121-
.fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME,
2121+
.fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME |
2122+
FS_LBS,
21222123
};
21232124
MODULE_ALIAS_FS("xfs");
21242125

include/linux/fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,6 +2604,7 @@ struct file_system_type {
26042604
#define FS_DISALLOW_NOTIFY_PERM 16 /* Disable fanotify permission events */
26052605
#define FS_ALLOW_IDMAP 32 /* FS has been updated to handle vfs idmappings. */
26062606
#define FS_MGTIME 64 /* FS uses multigrain timestamps */
2607+
#define FS_LBS 128 /* FS supports LBS */
26072608
#define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */
26082609
int (*init_fs_context)(struct fs_context *);
26092610
const struct fs_parameter_spec *parameters;

0 commit comments

Comments
 (0)