* [PATCHv4 1/2] block: make BLK_DEF_MAX_SECTORS unsigned
2023-01-05 20:51 [PATCHv4 0/2] block: don't forget user settings Keith Busch
@ 2023-01-05 20:51 ` Keith Busch
2023-01-05 21:19 ` Bart Van Assche
` (2 more replies)
2023-01-05 20:51 ` [PATCHv4 2/2] block: save user max_sectors limit Keith Busch
2023-01-09 3:27 ` [PATCHv4 0/2] block: don't forget user settings Jens Axboe
2 siblings, 3 replies; 11+ messages in thread
From: Keith Busch @ 2023-01-05 20:51 UTC (permalink / raw)
To: linux-block, axboe; +Cc: hch, martin.petersen, Damien Le Moal, Keith Busch
From: Keith Busch <kbusch@kernel.org>
This is used as an unsigned value, so define it that way to avoid
having to cast it.
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
block/blk-settings.c | 2 +-
drivers/block/null_blk/main.c | 3 +--
include/linux/blkdev.h | 3 ++-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/block/blk-settings.c b/block/blk-settings.c
index 0477c4d527fee..9875ca131eb0c 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -135,7 +135,7 @@ 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_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS);
+ 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/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 7d28e3aa406c2..4c601ca9552a0 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -2123,8 +2123,7 @@ static int null_add_dev(struct nullb_device *dev)
blk_queue_physical_block_size(nullb->q, dev->blocksize);
if (!dev->max_sectors)
dev->max_sectors = queue_max_hw_sectors(nullb->q);
- dev->max_sectors = min_t(unsigned int, dev->max_sectors,
- BLK_DEF_MAX_SECTORS);
+ dev->max_sectors = min(dev->max_sectors, BLK_DEF_MAX_SECTORS);
blk_queue_max_hw_sectors(nullb->q, dev->max_sectors);
if (dev->virt_boundary)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 43d4e073b1115..2b85161e22561 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1095,11 +1095,12 @@ static inline bool bdev_is_partition(struct block_device *bdev)
enum blk_default_limits {
BLK_MAX_SEGMENTS = 128,
BLK_SAFE_MAX_SECTORS = 255,
- BLK_DEF_MAX_SECTORS = 2560,
BLK_MAX_SEGMENT_SIZE = 65536,
BLK_SEG_BOUNDARY_MASK = 0xFFFFFFFFUL,
};
+#define BLK_DEF_MAX_SECTORS 2560u
+
static inline unsigned long queue_segment_boundary(const struct request_queue *q)
{
return q->limits.seg_boundary_mask;
--
2.30.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCHv4 1/2] block: make BLK_DEF_MAX_SECTORS unsigned
2023-01-05 20:51 ` [PATCHv4 1/2] block: make BLK_DEF_MAX_SECTORS unsigned Keith Busch
@ 2023-01-05 21:19 ` Bart Van Assche
2023-01-08 17:13 ` Christoph Hellwig
2023-01-09 0:23 ` Martin K. Petersen
2 siblings, 0 replies; 11+ messages in thread
From: Bart Van Assche @ 2023-01-05 21:19 UTC (permalink / raw)
To: Keith Busch, linux-block, axboe
Cc: hch, martin.petersen, Damien Le Moal, Keith Busch
On 1/5/23 12:51, Keith Busch wrote:
> This is used as an unsigned value, so define it that way to avoid
> having to cast it.
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCHv4 1/2] block: make BLK_DEF_MAX_SECTORS unsigned
2023-01-05 20:51 ` [PATCHv4 1/2] block: make BLK_DEF_MAX_SECTORS unsigned Keith Busch
2023-01-05 21:19 ` Bart Van Assche
@ 2023-01-08 17:13 ` Christoph Hellwig
2023-01-09 0:23 ` Martin K. Petersen
2 siblings, 0 replies; 11+ messages in thread
From: Christoph Hellwig @ 2023-01-08 17:13 UTC (permalink / raw)
To: Keith Busch
Cc: linux-block, axboe, hch, martin.petersen, Damien Le Moal,
Keith Busch
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCHv4 1/2] block: make BLK_DEF_MAX_SECTORS unsigned
2023-01-05 20:51 ` [PATCHv4 1/2] block: make BLK_DEF_MAX_SECTORS unsigned Keith Busch
2023-01-05 21:19 ` Bart Van Assche
2023-01-08 17:13 ` Christoph Hellwig
@ 2023-01-09 0:23 ` Martin K. Petersen
2 siblings, 0 replies; 11+ messages in thread
From: Martin K. Petersen @ 2023-01-09 0:23 UTC (permalink / raw)
To: Keith Busch
Cc: linux-block, axboe, hch, martin.petersen, Damien Le Moal,
Keith Busch
Keith,
> This is used as an unsigned value, so define it that way to avoid
> having to cast it.
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCHv4 2/2] block: save user max_sectors limit
2023-01-05 20:51 [PATCHv4 0/2] block: don't forget user settings Keith Busch
2023-01-05 20:51 ` [PATCHv4 1/2] block: make BLK_DEF_MAX_SECTORS unsigned Keith Busch
@ 2023-01-05 20:51 ` Keith Busch
2023-01-05 21:28 ` Bart Van Assche
` (2 more replies)
2023-01-09 3:27 ` [PATCHv4 0/2] block: don't forget user settings Jens Axboe
2 siblings, 3 replies; 11+ messages in thread
From: Keith Busch @ 2023-01-05 20:51 UTC (permalink / raw)
To: linux-block, axboe; +Cc: hch, martin.petersen, Damien Le Moal, Keith Busch
From: Keith Busch <kbusch@kernel.org>
The user can set the max_sectors limit to any valid value via sysfs
/sys/block/<dev>/queue/max_sectors_kb attribute. If the device limits
are ever rescanned, though, the limit reverts back to the potentially
artificially low BLK_DEF_MAX_SECTORS value.
Preserve the user's setting as the max_sectors limit as long as it's
valid. The user can reset back to defaults by writing 0 to the sysfs
file.
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
Documentation/ABI/stable/sysfs-block | 3 ++-
block/blk-settings.c | 9 +++++++--
block/blk-sysfs.c | 21 +++++++++++++++------
include/linux/blkdev.h | 1 +
4 files changed, 25 insertions(+), 9 deletions(-)
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..5486b6c57f6b8 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -239,19 +239,28 @@ static ssize_t queue_zone_append_max_show(struct request_queue *q, char *page)
static ssize_t
queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
{
- unsigned long max_sectors_kb,
+ unsigned long var;
+ unsigned int max_sectors_kb,
max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1,
page_kb = 1 << (PAGE_SHIFT - 10);
- ssize_t ret = queue_var_store(&max_sectors_kb, page, count);
+ ssize_t ret = queue_var_store(&var, page, count);
if (ret < 0)
return ret;
- max_hw_sectors_kb = min_not_zero(max_hw_sectors_kb, (unsigned long)
+ max_sectors_kb = (unsigned int)var;
+ max_hw_sectors_kb = min_not_zero(max_hw_sectors_kb,
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 2b85161e22561..b87ed829ab941 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;
--
2.30.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCHv4 2/2] block: save user max_sectors limit
2023-01-05 20:51 ` [PATCHv4 2/2] block: save user max_sectors limit Keith Busch
@ 2023-01-05 21:28 ` Bart Van Assche
2023-01-05 21:36 ` Keith Busch
2023-01-08 17:13 ` Christoph Hellwig
2023-01-09 0:25 ` Martin K. Petersen
2 siblings, 1 reply; 11+ messages in thread
From: Bart Van Assche @ 2023-01-05 21:28 UTC (permalink / raw)
To: Keith Busch, linux-block, axboe
Cc: hch, martin.petersen, Damien Le Moal, Keith Busch
On 1/5/23 12:51, Keith Busch wrote:
> diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> index 93d9e9c9a6ea8..5486b6c57f6b8 100644
> --- a/block/blk-sysfs.c
> +++ b/block/blk-sysfs.c
> @@ -239,19 +239,28 @@ static ssize_t queue_zone_append_max_show(struct request_queue *q, char *page)
> static ssize_t
> queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
> {
> - unsigned long max_sectors_kb,
> + unsigned long var;
> + unsigned int max_sectors_kb,
> max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1,
> page_kb = 1 << (PAGE_SHIFT - 10);
> - ssize_t ret = queue_var_store(&max_sectors_kb, page, count);
> + ssize_t ret = queue_var_store(&var, page, count);
>
> if (ret < 0)
> return ret;
>
> - max_hw_sectors_kb = min_not_zero(max_hw_sectors_kb, (unsigned long)
> + max_sectors_kb = (unsigned int)var;
Shouldn't this function report an error if 'var' is too large to fit
into an unsigned int?
Otherwise this patch looks good to me.
Thanks,
Bart.
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCHv4 2/2] block: save user max_sectors limit
2023-01-05 21:28 ` Bart Van Assche
@ 2023-01-05 21:36 ` Keith Busch
0 siblings, 0 replies; 11+ messages in thread
From: Keith Busch @ 2023-01-05 21:36 UTC (permalink / raw)
To: Bart Van Assche
Cc: Keith Busch, linux-block, axboe, hch, martin.petersen,
Damien Le Moal
On Thu, Jan 05, 2023 at 01:28:35PM -0800, Bart Van Assche wrote:
> On 1/5/23 12:51, Keith Busch wrote:
> > diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> > index 93d9e9c9a6ea8..5486b6c57f6b8 100644
> > --- a/block/blk-sysfs.c
> > +++ b/block/blk-sysfs.c
> > @@ -239,19 +239,28 @@ static ssize_t queue_zone_append_max_show(struct request_queue *q, char *page)
> > static ssize_t
> > queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
> > {
> > - unsigned long max_sectors_kb,
> > + unsigned long var;
> > + unsigned int max_sectors_kb,
> > max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1,
> > page_kb = 1 << (PAGE_SHIFT - 10);
> > - ssize_t ret = queue_var_store(&max_sectors_kb, page, count);
> > + ssize_t ret = queue_var_store(&var, page, count);
> > if (ret < 0)
> > return ret;
> > - max_hw_sectors_kb = min_not_zero(max_hw_sectors_kb, (unsigned long)
> > + max_sectors_kb = (unsigned int)var;
>
> Shouldn't this function report an error if 'var' is too large to fit into an
> unsigned int?
Yes it should, and queue_var_store() will return -EINVAL if that
happens. That's certainly not clear just from reading this patch, but
the condition is handled.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCHv4 2/2] block: save user max_sectors limit
2023-01-05 20:51 ` [PATCHv4 2/2] block: save user max_sectors limit Keith Busch
2023-01-05 21:28 ` Bart Van Assche
@ 2023-01-08 17:13 ` Christoph Hellwig
2023-01-09 0:25 ` Martin K. Petersen
2 siblings, 0 replies; 11+ messages in thread
From: Christoph Hellwig @ 2023-01-08 17:13 UTC (permalink / raw)
To: Keith Busch
Cc: linux-block, axboe, hch, martin.petersen, Damien Le Moal,
Keith Busch
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCHv4 2/2] block: save user max_sectors limit
2023-01-05 20:51 ` [PATCHv4 2/2] block: save user max_sectors limit Keith Busch
2023-01-05 21:28 ` Bart Van Assche
2023-01-08 17:13 ` Christoph Hellwig
@ 2023-01-09 0:25 ` Martin K. Petersen
2 siblings, 0 replies; 11+ messages in thread
From: Martin K. Petersen @ 2023-01-09 0:25 UTC (permalink / raw)
To: Keith Busch
Cc: linux-block, axboe, hch, martin.petersen, Damien Le Moal,
Keith Busch
Keith,
> The user can set the max_sectors limit to any valid value via sysfs
> /sys/block/<dev>/queue/max_sectors_kb attribute. If the device limits
> are ever rescanned, though, the limit reverts back to the potentially
> artificially low BLK_DEF_MAX_SECTORS value.
>
> Preserve the user's setting as the max_sectors limit as long as it's
> valid. The user can reset back to defaults by writing 0 to the sysfs
> file.
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCHv4 0/2] block: don't forget user settings
2023-01-05 20:51 [PATCHv4 0/2] block: don't forget user settings Keith Busch
2023-01-05 20:51 ` [PATCHv4 1/2] block: make BLK_DEF_MAX_SECTORS unsigned Keith Busch
2023-01-05 20:51 ` [PATCHv4 2/2] block: save user max_sectors limit Keith Busch
@ 2023-01-09 3:27 ` Jens Axboe
2 siblings, 0 replies; 11+ messages in thread
From: Jens Axboe @ 2023-01-09 3:27 UTC (permalink / raw)
To: linux-block, Keith Busch
Cc: hch, martin.petersen, Damien Le Moal, Keith Busch
On Thu, 05 Jan 2023 12:51:44 -0800, Keith Busch wrote:
> If the user overrides the max sectors for their device (which is
> currently defaulting to quite a low value for modern hardware), their
> request is lost on a rescan. Save it and fix the weird type issues.
>
> Changes since v3: Fixed the unsigned long/unsigned int issue raised by
> clang.
>
> [...]
Applied, thanks!
[1/2] block: make BLK_DEF_MAX_SECTORS unsigned
commit: c749b9c6de40f0882d9c83c8a3780e631603eb9d
[2/2] block: save user max_sectors limit
commit: 39001023bf1dfcee0ad1602501fbdea6f0d3d3bb
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 11+ messages in thread