From: Damien Le Moal <dlemoal@kernel.org>
To: Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
Keith Busch <kbusch@kernel.org>, Sagi Grimberg <sagi@grimberg.me>
Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org
Subject: Re: [PATCH 3/4] nvme: fix max_discard_sectors calculation
Date: Mon, 10 Jul 2023 12:57:56 +0900 [thread overview]
Message-ID: <06da81f9-dbdd-f706-0e26-afcfb89cfe32@kernel.org> (raw)
In-Reply-To: <20230707094616.108430-4-hch@lst.de>
On 7/7/23 18:46, Christoph Hellwig wrote:
> ctrl->max_discard_sectors stores a value that is potentially based of
> the DMRSL field in Identify Controller, which is in units of LBAs and
> thus dependent on the Format of a namespace.
>
> Fix this by moving the calculation of max_discard_sectors entirely
> into nvme_config_discard and replacing the ctrl->max_discard_sectors
> value with a local variable so that the calculation is always
I do not see a local variable replacement... May be you meant direct calls to
blk_queue_max_discard_sectors() ?
Other than that, looks OK to me.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
> namespace-specific.
>
> Fixes: 1a86924e4f46 ("nvme: fix interpretation of DMRSL")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> drivers/nvme/host/core.c | 22 ++++++++++------------
> drivers/nvme/host/nvme.h | 1 -
> 2 files changed, 10 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 2d6c1f4ad7f5c8..05372bec3b7aff 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -1721,20 +1721,21 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
> struct request_queue *queue = disk->queue;
> u32 size = queue_logical_block_size(queue);
>
> - if (ctrl->dmrsl && ctrl->dmrsl <= nvme_sect_to_lba(ns, UINT_MAX))
> - ctrl->max_discard_sectors = nvme_lba_to_sect(ns, ctrl->dmrsl);
> + BUILD_BUG_ON(PAGE_SIZE / sizeof(struct nvme_dsm_range) <
> + NVME_DSM_MAX_RANGES);
>
> - if (ctrl->max_discard_sectors == 0) {
> + if (ctrl->dmrsl && ctrl->dmrsl <= nvme_sect_to_lba(ns, UINT_MAX)) {
> + blk_queue_max_discard_sectors(queue,
> + nvme_lba_to_sect(ns, ctrl->dmrsl));
> + } else if (ctrl->oncs & NVME_CTRL_ONCS_DSM) {
> + blk_queue_max_discard_sectors(queue, UINT_MAX);
> + } else {
> blk_queue_max_discard_sectors(queue, 0);
> return;
> }
>
> - BUILD_BUG_ON(PAGE_SIZE / sizeof(struct nvme_dsm_range) <
> - NVME_DSM_MAX_RANGES);
> -
> queue->limits.discard_granularity = size;
>
> - blk_queue_max_discard_sectors(queue, ctrl->max_discard_sectors);
> blk_queue_max_discard_segments(queue, ctrl->max_discard_segments);
>
> if (ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES)
> @@ -2870,13 +2871,10 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)
> struct nvme_id_ctrl_nvm *id;
> int ret;
>
> - if (ctrl->oncs & NVME_CTRL_ONCS_DSM) {
> - ctrl->max_discard_sectors = UINT_MAX;
> + if (ctrl->oncs & NVME_CTRL_ONCS_DSM)
> ctrl->max_discard_segments = NVME_DSM_MAX_RANGES;
> - } else {
> - ctrl->max_discard_sectors = 0;
> + else
> ctrl->max_discard_segments = 0;
> - }
>
> /*
> * Even though NVMe spec explicitly states that MDTS is not applicable
> diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
> index f35647c470afad..d59ed2ba1c37ca 100644
> --- a/drivers/nvme/host/nvme.h
> +++ b/drivers/nvme/host/nvme.h
> @@ -296,7 +296,6 @@ struct nvme_ctrl {
> u32 max_hw_sectors;
> u32 max_segments;
> u32 max_integrity_segments;
> - u32 max_discard_sectors;
> u32 max_discard_segments;
> u32 max_zeroes_sectors;
> #ifdef CONFIG_BLK_DEV_ZONED
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2023-07-10 3:58 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-07 9:46 fix discard limits Christoph Hellwig
2023-07-07 9:46 ` [PATCH 1/4] block: don't unconditionally set max_discard_sectors in blk_queue_max_discard_sectors Christoph Hellwig
2023-07-10 3:53 ` Damien Le Moal
2023-07-10 9:29 ` Sagi Grimberg
2023-07-10 10:42 ` Ming Lei
2023-07-12 16:23 ` Christoph Hellwig
2023-07-12 16:38 ` Keith Busch
2023-07-10 15:01 ` Keith Busch
2023-07-07 9:46 ` [PATCH 2/4] nvme: update discard limits in nvme_config_discard Christoph Hellwig
2023-07-10 3:54 ` Damien Le Moal
2023-07-10 9:29 ` Sagi Grimberg
2023-07-07 9:46 ` [PATCH 3/4] nvme: fix max_discard_sectors calculation Christoph Hellwig
2023-07-10 3:57 ` Damien Le Moal [this message]
2023-07-10 6:39 ` Christoph Hellwig
2023-07-10 9:31 ` Sagi Grimberg
2023-07-07 9:46 ` [PATCH 4/4] nvme: simplify the max_discard_segments calculation Christoph Hellwig
2023-07-10 9:32 ` Sagi Grimberg
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=06da81f9-dbdd-f706-0e26-afcfb89cfe32@kernel.org \
--to=dlemoal@kernel.org \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).