* [PATCH 1/2] nvme: use UINT_MAX >> SECTOR_SHIFT for maximums in number of sectors
@ 2021-08-16 18:11 Tom Yan
2021-08-16 18:11 ` [PATCH 2/2] nvme: round max_discard_sectors down against discard_granularity Tom Yan
2021-08-16 21:43 ` [PATCH 1/2] nvme: use UINT_MAX >> SECTOR_SHIFT for maximums in number of sectors Keith Busch
0 siblings, 2 replies; 3+ messages in thread
From: Tom Yan @ 2021-08-16 18:11 UTC (permalink / raw)
To: linux-nvme, hch; +Cc: Tom Yan
The block layer uses UINT_MAX for maximums in bytes.
Signed-off-by: Tom Yan <tom.ty89@gmail.com>
---
drivers/nvme/host/core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index dfd9dec0c1f6..3a1bfb45da2a 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1640,7 +1640,7 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
blk_queue_max_discard_segments(queue, ctrl->max_discard_segments);
if (ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES)
- blk_queue_max_write_zeroes_sectors(queue, UINT_MAX);
+ blk_queue_max_write_zeroes_sectors(queue, UINT_MAX >> SECTOR_SHIFT);
}
static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids)
@@ -2762,7 +2762,7 @@ static inline u32 nvme_mps_to_sectors(struct nvme_ctrl *ctrl, u32 units)
u32 page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12, val;
if (check_shl_overflow(1U, units + page_shift - 9, &val))
- return UINT_MAX;
+ return UINT_MAX >> SECTOR_SHIFT;
return val;
}
@@ -2773,7 +2773,7 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)
int ret;
if (ctrl->oncs & NVME_CTRL_ONCS_DSM) {
- ctrl->max_discard_sectors = UINT_MAX;
+ ctrl->max_discard_sectors = UINT_MAX >> SECTOR_SHIFT;
ctrl->max_discard_segments = NVME_DSM_MAX_RANGES;
} else {
ctrl->max_discard_sectors = 0;
@@ -2883,7 +2883,7 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
if (id->mdts)
max_hw_sectors = nvme_mps_to_sectors(ctrl, id->mdts);
else
- max_hw_sectors = UINT_MAX;
+ max_hw_sectors = UINT_MAX >> SECTOR_SHIFT;
ctrl->max_hw_sectors =
min_not_zero(ctrl->max_hw_sectors, max_hw_sectors);
--
2.32.0
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/2] nvme: round max_discard_sectors down against discard_granularity
2021-08-16 18:11 [PATCH 1/2] nvme: use UINT_MAX >> SECTOR_SHIFT for maximums in number of sectors Tom Yan
@ 2021-08-16 18:11 ` Tom Yan
2021-08-16 21:43 ` [PATCH 1/2] nvme: use UINT_MAX >> SECTOR_SHIFT for maximums in number of sectors Keith Busch
1 sibling, 0 replies; 3+ messages in thread
From: Tom Yan @ 2021-08-16 18:11 UTC (permalink / raw)
To: linux-nvme, hch; +Cc: Tom Yan
Signed-off-by: Tom Yan <tom.ty89@gmail.com>
---
drivers/nvme/host/core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 3a1bfb45da2a..dff165b92ff6 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1636,6 +1636,9 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
if (blk_queue_flag_test_and_set(QUEUE_FLAG_DISCARD, queue))
return;
+ ctrl->max_discard_sectors = round_down(ctrl->max_discard_sectors,
+ size >> SECTOR_SHIFT);
+
blk_queue_max_discard_sectors(queue, ctrl->max_discard_sectors);
blk_queue_max_discard_segments(queue, ctrl->max_discard_segments);
--
2.32.0
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] nvme: use UINT_MAX >> SECTOR_SHIFT for maximums in number of sectors
2021-08-16 18:11 [PATCH 1/2] nvme: use UINT_MAX >> SECTOR_SHIFT for maximums in number of sectors Tom Yan
2021-08-16 18:11 ` [PATCH 2/2] nvme: round max_discard_sectors down against discard_granularity Tom Yan
@ 2021-08-16 21:43 ` Keith Busch
1 sibling, 0 replies; 3+ messages in thread
From: Keith Busch @ 2021-08-16 21:43 UTC (permalink / raw)
To: Tom Yan; +Cc: linux-nvme, hch
On Tue, Aug 17, 2021 at 02:11:01AM +0800, Tom Yan wrote:
> The block layer uses UINT_MAX for maximums in bytes.
Nak, the code is correct as-is. A UINT_MAX number of sectors is
valid when the device doesn't have an upper limit.
> Signed-off-by: Tom Yan <tom.ty89@gmail.com>
> ---
> drivers/nvme/host/core.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index dfd9dec0c1f6..3a1bfb45da2a 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -1640,7 +1640,7 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
> blk_queue_max_discard_segments(queue, ctrl->max_discard_segments);
>
> if (ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES)
> - blk_queue_max_write_zeroes_sectors(queue, UINT_MAX);
> + blk_queue_max_write_zeroes_sectors(queue, UINT_MAX >> SECTOR_SHIFT);
> }
>
> static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids)
> @@ -2762,7 +2762,7 @@ static inline u32 nvme_mps_to_sectors(struct nvme_ctrl *ctrl, u32 units)
> u32 page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12, val;
>
> if (check_shl_overflow(1U, units + page_shift - 9, &val))
> - return UINT_MAX;
> + return UINT_MAX >> SECTOR_SHIFT;
> return val;
> }
>
> @@ -2773,7 +2773,7 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)
> int ret;
>
> if (ctrl->oncs & NVME_CTRL_ONCS_DSM) {
> - ctrl->max_discard_sectors = UINT_MAX;
> + ctrl->max_discard_sectors = UINT_MAX >> SECTOR_SHIFT;
> ctrl->max_discard_segments = NVME_DSM_MAX_RANGES;
> } else {
> ctrl->max_discard_sectors = 0;
> @@ -2883,7 +2883,7 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
> if (id->mdts)
> max_hw_sectors = nvme_mps_to_sectors(ctrl, id->mdts);
> else
> - max_hw_sectors = UINT_MAX;
> + max_hw_sectors = UINT_MAX >> SECTOR_SHIFT;
> ctrl->max_hw_sectors =
> min_not_zero(ctrl->max_hw_sectors, max_hw_sectors);
>
> --
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-08-16 21:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-16 18:11 [PATCH 1/2] nvme: use UINT_MAX >> SECTOR_SHIFT for maximums in number of sectors Tom Yan
2021-08-16 18:11 ` [PATCH 2/2] nvme: round max_discard_sectors down against discard_granularity Tom Yan
2021-08-16 21:43 ` [PATCH 1/2] nvme: use UINT_MAX >> SECTOR_SHIFT for maximums in number of sectors Keith Busch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox