nvme: fix interpretation of dmrsl
PATCH 1/1 nvme: fix interpretation of dmrsl
dmrsl is in the unit of logical block, while max_discard_sectors is in the unit of "linux sector".
Signed-off-by Tom Yan <[email protected]>
--- drivers/nvme/host/core.c | 6 ++++-- drivers/nvme/host/nvme.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +4 -2
@@ -1622,6 +1622,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 ; +if (ctrl->dmrsl) + ctrl->max_discard_sectors = ctrl->dmrsl << (ilog2 (size) -9 ); +blk_queue_max_discard_sectors (queue, ctrl->max_discard_sectors);blk_queue_max_discard_segments (queue, ctrl->max_discard_segments);
@@ -2881,8 +2884,7 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)if (id->dmrl) ctrl->max_discard_segments = id->dmrl; -if (id->dmrsl) - ctrl->max_discard_sectors =le32_to_cpu (id->dmrsl); + ctrl->dmrsl =le32_to_cpu (id->dmrsl);if (id->wzsl) ctrl->max_zeroes_sectors =nvme_mps_to_sectors (ctrl, id->wzsl);
drivers/nvme/host/nvme.h +1 -0
@@ -279,6 +279,7 @@ struct nvme_ctrl {#endif u16 crdt[3 ];u16 oncs; +u32 dmrsl;u16 oacs;u16 sqsize;u32 max_namespaces;
Signature · 1 line
2.35.1
PATCH 1/1 nvme: fix interpretation of dmrsl
dmrsl is in the unit of logical block, while max_discard_sectors is in the unit of "linux sector".
Signed-off-by Tom Yan <[email protected]>
---
v2: ignore dmrsl if its sector-equivalent is larger than UINT_MAX
--- drivers/nvme/host/core.c | 8 ++++++-- drivers/nvme/host/nvme.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +6 -2
@@ -1622,6 +1622,11 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)if (blk_queue_flag_test_and_set (QUEUE_FLAG_DISCARD , queue))return ; +int lts_shift =ilog2 (size) -9 ; + +if (ctrl->dmrsl && ctrl->dmrsl <=UINT_MAX >> lts_shift) + ctrl->max_discard_sectors = ctrl->dmrsl << lts_shift; +blk_queue_max_discard_sectors (queue, ctrl->max_discard_sectors);blk_queue_max_discard_segments (queue, ctrl->max_discard_segments);
@@ -2881,8 +2886,7 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)if (id->dmrl) ctrl->max_discard_segments = id->dmrl; -if (id->dmrsl) - ctrl->max_discard_sectors =le32_to_cpu (id->dmrsl); + ctrl->dmrsl =le32_to_cpu (id->dmrsl);if (id->wzsl) ctrl->max_zeroes_sectors =nvme_mps_to_sectors (ctrl, id->wzsl);
drivers/nvme/host/nvme.h +1 -0
@@ -279,6 +279,7 @@ struct nvme_ctrl {#endif u16 crdt[3 ];u16 oncs; +u32 dmrsl;u16 oacs;u16 sqsize;u32 max_namespaces;
Signature · 1 line
2.35.1
Reviewed-by Sagi Grimberg <[email protected]>