From: Tom Yan <tom.ty89@gmail.com>
To: linux-nvme@lists.infradead.org, kbusch@kernel.org,
hch@infradead.org, sagi@grimberg.me
Cc: Tom Yan <tom.ty89@gmail.com>
Subject: [PATCH v4] nvme: fix interpretation of dmrsl
Date: Fri, 29 Apr 2022 12:52:43 +0800 [thread overview]
Message-ID: <20220429045243.324403-1-tom.ty89@gmail.com> (raw)
In-Reply-To: <YmrMSGDDn3UMnJ8t@kbusch-mbp.dhcp.thefacebook.com>
dmrsl is in the unit of logical block, while max_discard_sectors is
in the unit of "linux sector".
Signed-off-by: Tom Yan <tom.ty89@gmail.com>
---
v2: ignore dmrsl if its sector-equivalent is larger than UINT_MAX
v3: put the lts_shift declaration before code
v4: make use of nvme_sect_to_lba() and nvme_lba_to_sect()
---
drivers/nvme/host/core.c | 6 ++++--
drivers/nvme/host/nvme.h | 1 +
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index efb85c6d8e2d..8e06a6d675ef 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -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->dmrsl <= nvme_sect_to_lba(ns, UINT_MAX))
+ ctrl->max_discard_sectors = nvme_lba_to_sect(ns, ctrl->dmrsl);
+
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);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 1393bbf82d71..1c85edcf7dbb 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -279,6 +279,7 @@ struct nvme_ctrl {
#endif
u16 crdt[3];
u16 oncs;
+ u32 dmrsl;
u16 oacs;
u16 sqsize;
u32 max_namespaces;
--
2.36.0
next prev parent reply other threads:[~2022-04-29 4:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-21 8:48 [PATCH v2] nvme: fix interpretation of dmrsl Tom Yan
2022-04-28 15:10 ` Christoph Hellwig
2022-04-28 16:50 ` [PATCH v3] " Tom Yan
2022-04-28 17:18 ` Keith Busch
2022-04-29 4:52 ` Tom Yan [this message]
2022-04-29 5:01 ` [PATCH v4] " Tom Yan
2022-05-10 6:04 ` Christoph Hellwig
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=20220429045243.324403-1-tom.ty89@gmail.com \
--to=tom.ty89@gmail.com \
--cc=hch@infradead.org \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/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.