All of lore.kernel.org
 help / color / mirror / Atom feed
From: Keith Busch <kbusch@meta.com>
To: <linux-block@vger.kernel.org>, <axboe@kernel.dk>
Cc: <hch@lst.de>, <martin.petersen@oracle.com>,
	Keith Busch <kbusch@kernel.org>
Subject: [PATCH] block: save user max_sectors limit
Date: Thu, 22 Dec 2022 09:52:04 -0800	[thread overview]
Message-ID: <20221222175204.1782061-1-kbusch@meta.com> (raw)

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 kernel defined
BLK_DEF_MAX_SECTORS limit.

Preserve the user's setting for 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>
---
 block/blk-settings.c   |  9 +++++++--
 block/blk-sysfs.c      | 10 +++++++++-
 include/linux/blkdev.h |  1 +
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/block/blk-settings.c b/block/blk-settings.c
index 0477c4d527fee..e75304f853bd5 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_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS);
+
+	if (limits->max_user_sectors)
+		max_sectors = min_not_zero(max_sectors, limits->max_user_sectors);
+	else
+		max_sectors = min_t(unsigned int, 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..db5d1d908f5d9 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -250,8 +250,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)
+	if (max_sectors_kb == 0) {
+		q->limits.max_user_sectors = 0;
+		max_sectors_kb = min_t(unsigned int, 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;
+	} else {
+		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 301cf1cf4f2fa..71e97f0a87264 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


             reply	other threads:[~2022-12-22 17:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-22 17:52 Keith Busch [this message]
2022-12-23  6:00 ` [PATCH] block: save user max_sectors limit Christoph Hellwig
2022-12-27 16:49   ` Keith Busch
2022-12-27 16:53     ` Christoph Hellwig
2022-12-27  2:13 ` Damien Le Moal
  -- strict thread matches above, loose matches on Subject: below --
2022-12-21 16:27 Keith Busch
2022-12-22  8:22 ` kernel test robot
2022-12-22  8:32 ` kernel test robot
2022-12-22  8:40   ` Christoph Hellwig
2022-12-22 15:40     ` Keith Busch
2022-12-22 16:07       ` Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221222175204.1782061-1-kbusch@meta.com \
    --to=kbusch@meta.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.