Message ID | 20221227191009.2277326-2-kbusch@meta.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [PATCHv3,1/2] block: make BLK_DEF_MAX_SECTORS unsigned | expand |
On Wed, Dec 28, 2022 at 10:04:16AM +0800, kernel test robot wrote:
> >> block/blk-sysfs.c:254:20: warning: comparison of distinct pointer types ('typeof (max_hw_sectors_kb) *' (aka 'unsigned long *') and 'typeof (2560U >> 1) *' (aka 'unsigned int *')) [-Wcompare-distinct-pointer-types]
Seems like the local max_sectors_kb variable also needs to be turned
into an unsigned int from the current unsigned long.
And btw, while I'm getting philosophical during my early morning
coffee here, I wonder if we need to actually get rid of or at least
bump BLK_DEF_MAX_SECTORS. It's pretty ridiculous for modern devices,
and with CDL support that defintion would also include hard drives
eventually.
On Wed, Dec 28, 2022 at 04:51:11PM +0100, Christoph Hellwig wrote: > On Wed, Dec 28, 2022 at 10:04:16AM +0800, kernel test robot wrote: > > >> block/blk-sysfs.c:254:20: warning: comparison of distinct pointer types ('typeof (max_hw_sectors_kb) *' (aka 'unsigned long *') and 'typeof (2560U >> 1) *' (aka 'unsigned int *')) [-Wcompare-distinct-pointer-types] > > Seems like the local max_sectors_kb variable also needs to be turned > into an unsigned int from the current unsigned long. Yeah, and gcc didn't complain about it, so looks like I need to add clang to my dev setup. > And btw, while I'm getting philosophical during my early morning > coffee here, I wonder if we need to actually get rid of or at least > bump BLK_DEF_MAX_SECTORS. It's pretty ridiculous for modern devices, > and with CDL support that defintion would also include hard drives > eventually. It looks like there's a bit of history around that value. I was hoping we could just get rid of it entirely and let drivers choose their own defaults.
diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stable/sysfs-block index cd14ecb3c9a5a..ac1e519272aa2 100644 --- a/Documentation/ABI/stable/sysfs-block +++ b/Documentation/ABI/stable/sysfs-block @@ -432,7 +432,8 @@ Contact: linux-block@vger.kernel.org Description: [RW] This is the maximum number of kilobytes that the block layer will allow for a filesystem request. Must be smaller than - or equal to the maximum size allowed by the hardware. + or equal to the maximum size allowed by the hardware. Write 0 + to use default kernel settings. What: /sys/block/<disk>/queue/max_segment_size diff --git a/block/blk-settings.c b/block/blk-settings.c index 9875ca131eb0c..9c9713c9269cc 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -40,7 +40,7 @@ void blk_set_default_limits(struct queue_limits *lim) lim->virt_boundary_mask = 0; lim->max_segment_size = BLK_MAX_SEGMENT_SIZE; lim->max_sectors = lim->max_hw_sectors = BLK_SAFE_MAX_SECTORS; - lim->max_dev_sectors = 0; + lim->max_user_sectors = lim->max_dev_sectors = 0; lim->chunk_sectors = 0; lim->max_write_zeroes_sectors = 0; lim->max_zone_append_sectors = 0; @@ -135,7 +135,12 @@ void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_secto limits->max_hw_sectors = max_hw_sectors; max_sectors = min_not_zero(max_hw_sectors, limits->max_dev_sectors); - max_sectors = min(max_sectors, BLK_DEF_MAX_SECTORS); + + if (limits->max_user_sectors) + max_sectors = min(max_sectors, limits->max_user_sectors); + else + max_sectors = min(max_sectors, BLK_DEF_MAX_SECTORS); + max_sectors = round_down(max_sectors, limits->logical_block_size >> SECTOR_SHIFT); limits->max_sectors = max_sectors; diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 93d9e9c9a6ea8..e67acd859d072 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -249,9 +249,16 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count) max_hw_sectors_kb = min_not_zero(max_hw_sectors_kb, (unsigned long) q->limits.max_dev_sectors >> 1); - - if (max_sectors_kb > max_hw_sectors_kb || max_sectors_kb < page_kb) - return -EINVAL; + if (max_sectors_kb == 0) { + q->limits.max_user_sectors = 0; + max_sectors_kb = min(max_hw_sectors_kb, + BLK_DEF_MAX_SECTORS >> 1); + } else { + if (max_sectors_kb > max_hw_sectors_kb || + max_sectors_kb < page_kb) + return -EINVAL; + q->limits.max_user_sectors = max_sectors_kb << 1; + } spin_lock_irq(&q->queue_lock); q->limits.max_sectors = max_sectors_kb << 1; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 69f7199d38da8..8f5bb00d12ece 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -288,6 +288,7 @@ struct queue_limits { unsigned int max_dev_sectors; unsigned int chunk_sectors; unsigned int max_sectors; + unsigned int max_user_sectors; unsigned int max_segment_size; unsigned int physical_block_size; unsigned int logical_block_size;