From patchwork Fri Jul 7 09:46:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13304645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F91AC0015E for ; Fri, 7 Jul 2023 09:46:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231674AbjGGJqd (ORCPT ); Fri, 7 Jul 2023 05:46:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229555AbjGGJqd (ORCPT ); Fri, 7 Jul 2023 05:46:33 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EC8BFF for ; Fri, 7 Jul 2023 02:46:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=bFNjkpFVsr0wX1IV59D92iuCTOU9SUmgiQChjqVJEPc=; b=obTgho+S4+Lljrco8JLmiY2oi9 f3DZwV0FkvGkUzi4jVg6U34s3cnUla0ewA5QrnzHSyMh2U9Luyuii0G9jCz2qfAN31fwPOyNZk7nT soVMXd6VB/tYwOhixK8nvbc9fYTmzYM1pvDKz8ikYK/xVJZs+fPE5fO+mj3DWcQH6rWW14IsHoNur PmYktIDT7DTAaZPjuGi9zzIS0r2ragnPjJ/W6Kuc+OOL/MFWgfx/e47g2iiUbY5VNp+cp/NTyiHrh KkfAEBqHBBe0BoEqvvQy5AvRDqokQxh0K96KXFIBuoB0b2z+ia2V1Q13OBjtRzbZ78ReHsDpm5DKY ZceqJp+Q==; Received: from [89.144.223.112] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qHi2o-0049h8-2h; Fri, 07 Jul 2023 09:46:31 +0000 From: Christoph Hellwig To: Jens Axboe , Keith Busch , Sagi Grimberg Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Subject: [PATCH 1/4] block: don't unconditionally set max_discard_sectors in blk_queue_max_discard_sectors Date: Fri, 7 Jul 2023 11:46:13 +0200 Message-Id: <20230707094616.108430-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230707094616.108430-1-hch@lst.de> References: <20230707094616.108430-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org max_discard_sectors is split into a hardware and a tunable value, but blk_queue_max_discard_sectors sets both unconditionally, thus dropping any user stored value on a rescan. Fix blk_queue_max_discard_sectors to only set max_discard_sectors if it either wasn't set, or the new hardware limit is smaller than the previous user limit. Fixes: 0034af036554 ("block: make /sys/block//queue/discard_max_bytes writeable") Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Sagi Grimberg --- block/blk-settings.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/blk-settings.c b/block/blk-settings.c index 0046b447268f91..978d2e1fd67a51 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -179,7 +179,9 @@ void blk_queue_max_discard_sectors(struct request_queue *q, unsigned int max_discard_sectors) { q->limits.max_hw_discard_sectors = max_discard_sectors; - q->limits.max_discard_sectors = max_discard_sectors; + if (!q->limits.max_discard_sectors || + q->limits.max_discard_sectors > max_discard_sectors) + q->limits.max_discard_sectors = max_discard_sectors; } EXPORT_SYMBOL(blk_queue_max_discard_sectors); From patchwork Fri Jul 7 09:46:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13304646 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFBC5C0015E for ; Fri, 7 Jul 2023 09:46:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229555AbjGGJqh (ORCPT ); Fri, 7 Jul 2023 05:46:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231756AbjGGJqg (ORCPT ); Fri, 7 Jul 2023 05:46:36 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 088241BE9 for ; Fri, 7 Jul 2023 02:46:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=AC7vG1A2pMZEGPxwZG9McURvrIvQLWC1/NGcjUkvtzc=; b=RDgf71d7Rm6yD0myzPlz8fAG8V 9JtFH2PIyFqhIhxY8s1sbggLlNgpdGLHiU7l8jwHRlSCzSdgIEVBo504E+S+fsfsZ0r+pzKjXMgeq rHKPk1QZHtt2pcQ1z0q2G44ecIAz/VMPlSfJQwWyqYRR+tXZyWt+8PFSC2BfUvB9OK0+DFjmWExeg RJIdHUiDbVWVgLa4a/hrP/IW3vJneo7VWqyf8KzboU7POPFwof9nRoCcxWxu8jWbHtm78F0gdXAdK yhnqYuNLsrG3XieQX02qXVvuSknXcbEvrQIHwHBe0aqC640Geox1AA3KqGkePS5+gf/OI0KBziEVm dtG5wDNg==; Received: from [89.144.223.112] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qHi2s-0049hq-14; Fri, 07 Jul 2023 09:46:34 +0000 From: Christoph Hellwig To: Jens Axboe , Keith Busch , Sagi Grimberg Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Subject: [PATCH 2/4] nvme: update discard limits in nvme_config_discard Date: Fri, 7 Jul 2023 11:46:14 +0200 Message-Id: <20230707094616.108430-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230707094616.108430-1-hch@lst.de> References: <20230707094616.108430-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org nvme_config_discard currently skips updating the discard limits if they were set before because blk_queue_max_discard_sectors used to update the configurable max_discard_sectors limit unconditionally. Now that this has been fixed we can update the discard limits even if they were set to deal with the case of a reset changing the limits after e.g. a firmware update. Fixes: 3831761eb859 ("nvme: only reconfigure discard if necessary") Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Sagi Grimberg --- drivers/nvme/host/core.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 47d7ba2827ff29..2d6c1f4ad7f5c8 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1734,10 +1734,6 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns) queue->limits.discard_granularity = size; - /* If discard is already enabled, don't reset queue limits */ - if (queue->limits.max_discard_sectors) - return; - blk_queue_max_discard_sectors(queue, ctrl->max_discard_sectors); blk_queue_max_discard_segments(queue, ctrl->max_discard_segments); From patchwork Fri Jul 7 09:46:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13304647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1EC4EB64DA for ; Fri, 7 Jul 2023 09:46:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232428AbjGGJqk (ORCPT ); Fri, 7 Jul 2023 05:46:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231756AbjGGJqk (ORCPT ); Fri, 7 Jul 2023 05:46:40 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C8022108 for ; Fri, 7 Jul 2023 02:46:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=K4bMg5yZliyiqY8nRi1CjsjKBI5RC4P8/ENNcWprmTg=; b=qWgEq9tE4rPqm3loJHWgH8ZDW2 YxsCmOca6jtyU19TzYzTnGbOI6Q8SB/qj9LyFh0DrPVmL7xNFIxVxzcIV7/Y/Yf4jmVQmbVqGzGOf KpV03wS2Xf1E0QhZxUBTNJar3uy2Vwu9/66CXKkwJC9OTtVsSvxyY1og7Y+/2pYNnA85YibpI58t6 p/HFzV4V7F3GIR5f9tGCBCod87kj6tH04A65Mh5vHBtyjBTF6ErDrd4FVVHWqAUvzS3LYoTK3OVO/ PRL8xG64HHmMiPXqgR89h+DWK57VSkfgI67tqcYj+701GroWYFTWBBoBvA/NlXO+4lUkyNHXMaaJc Y5X1n56g==; Received: from [89.144.223.112] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qHi2v-0049j3-1f; Fri, 07 Jul 2023 09:46:38 +0000 From: Christoph Hellwig To: Jens Axboe , Keith Busch , Sagi Grimberg Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Subject: [PATCH 3/4] nvme: fix max_discard_sectors calculation Date: Fri, 7 Jul 2023 11:46:15 +0200 Message-Id: <20230707094616.108430-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230707094616.108430-1-hch@lst.de> References: <20230707094616.108430-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org 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 namespace-specific. Fixes: 1a86924e4f46 ("nvme: fix interpretation of DMRSL") Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Sagi Grimberg --- 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 From patchwork Fri Jul 7 09:46:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13304648 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C31C0EB64DA for ; Fri, 7 Jul 2023 09:46:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232290AbjGGJqq (ORCPT ); Fri, 7 Jul 2023 05:46:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231566AbjGGJqn (ORCPT ); Fri, 7 Jul 2023 05:46:43 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D8862108 for ; Fri, 7 Jul 2023 02:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=W9wqhqcVRSC12HSYXQvLbxd5dDfHbmUbpvwa4VvkkrM=; b=TMMm0i24Jr+mXHSCnkQQQszL+o Vwml+j6qZwq7EuUQEo7ZZVYz2H7UptnqNQf5/c3ev+O2NhnJvpsF/2oE5DBUMUYpn+wh1yRV5/8GT DF8HigEIjeX0aIfvoa62jmbeWTr75eQhfZR7Xaobfb2/G+muzhWfbz/JraKTwBFaWSIxYbcqfFAGv +jQfbpZxGBZeAqMzL2V7h/b/38Eu18Z/DqtGjZjpudRLm1K7zaMxAsn54dsUz0iq6nzzQveOCF+Lz qyNCFoBXU44cMV2uwTrOHZeZ7VwojZbqybtUhakHRASMOR7wFZg/GVI3Rsq5obkQTw6fj5GPAcI2W KNjAkAgQ==; Received: from [89.144.223.112] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qHi2y-0049kf-2h; Fri, 07 Jul 2023 09:46:41 +0000 From: Christoph Hellwig To: Jens Axboe , Keith Busch , Sagi Grimberg Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Subject: [PATCH 4/4] nvme: simplify the max_discard_segments calculation Date: Fri, 7 Jul 2023 11:46:16 +0200 Message-Id: <20230707094616.108430-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230707094616.108430-1-hch@lst.de> References: <20230707094616.108430-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Just stash away the DMRL value in the nvme_ctrl struture, and leave all interpretation to nvme_config_discard, where we know DSM is supported by the time we're configuring the number of segments. Signed-off-by: Christoph Hellwig Reviewed-by: Sagi Grimberg --- drivers/nvme/host/core.c | 13 +++++-------- drivers/nvme/host/nvme.h | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 05372bec3b7aff..f5814aa1b33910 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1736,7 +1736,10 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns) queue->limits.discard_granularity = size; - blk_queue_max_discard_segments(queue, ctrl->max_discard_segments); + if (ctrl->dmrl) + blk_queue_max_discard_segments(queue, ctrl->dmrl); + else + blk_queue_max_discard_segments(queue, NVME_DSM_MAX_RANGES); if (ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) blk_queue_max_write_zeroes_sectors(queue, UINT_MAX); @@ -2871,11 +2874,6 @@ 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_segments = NVME_DSM_MAX_RANGES; - else - ctrl->max_discard_segments = 0; - /* * Even though NVMe spec explicitly states that MDTS is not applicable * to the write-zeroes, we are cautious and limit the size to the @@ -2905,8 +2903,7 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl) if (ret) goto free_data; - if (id->dmrl) - ctrl->max_discard_segments = id->dmrl; + ctrl->dmrl = id->dmrl; 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 d59ed2ba1c37ca..1bfe172f9268a0 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -296,13 +296,13 @@ struct nvme_ctrl { u32 max_hw_sectors; u32 max_segments; u32 max_integrity_segments; - u32 max_discard_segments; u32 max_zeroes_sectors; #ifdef CONFIG_BLK_DEV_ZONED u32 max_zone_append; #endif u16 crdt[3]; u16 oncs; + u8 dmrl; u32 dmrsl; u16 oacs; u16 sqsize;