Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3403587pxf; Mon, 22 Mar 2021 05:47:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4+QHhMmp5kWguhZOr09t5bdpKv7j/evvHyxShkcL+1psH/OOSjeZvlPPI6YV95Zirc/Nt X-Received: by 2002:a17:906:4b0e:: with SMTP id y14mr18679669eju.393.1616417247761; Mon, 22 Mar 2021 05:47:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616417247; cv=none; d=google.com; s=arc-20160816; b=n/fmNwzuly9bC9q5VmKFlx7g0ByR4cdRwSV4/AoTSIVpoHXh4o7QSaRwGyZIZlEahj W1pMaWDqTlyy/MICXX6uSVdVSVH/UHEMScHLHgZV5ACU/Rc/TO394hS2KGyzoG6v8PFX 99WEFIilRWJFKSDJEf//3dsglj7Tgzz9OPOWhMXRZev6oF7M+Nwz91TSGJFEZbu1ekH/ sO8cyTEStFI3OMtE3rhWzqi+TP27TnIVMRYkEEprleSxzM0kdPWWVwtBf2nG7YtBq5Zu s2nRVMyQBVWmZSuApdyqGcPwxXfxMZDEvn4gXmVHNe9fLz77rfWXAchaUjoiRAaRRY6b yKAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TBAuxKBVsUKDfWwqGJiGIp5hPsgQw51ARum4zdJMkpI=; b=mnZmtzXX62/cdjhvvJB0yGnf2NOzvwEqifPuchY/LJeIJ2bkr68OIbaV+NlklGr71E r0nSyxN2GiXWOl5+Uhh4JF2sQ9ujrdN24+Utg8s29R+5GTk1Zr5SiBDT7mX/rvGjkbWd uzOBr+0YqoYlf4UcgYte5OMPfF1S9aURalcQd5xB4PMlFNn6+tyeyMQ0hiCHmoLy8HsV 15xSbY3HXxP19NgR3JarAeaDdfJM6sQQDGBNgmzqPrVgRuk9Mb0LagK8EWZ5aqHDP+sk S4uq3KbylWEga0HKyeM8qIDqZ4ZSHseQiA91cBhLLMvIa4zVK4KZcH6qrmNw+yAynk9D JwWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HkNfHgvF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s14si10283342edx.521.2021.03.22.05.47.04; Mon, 22 Mar 2021 05:47:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HkNfHgvF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229979AbhCVMqI (ORCPT + 99 others); Mon, 22 Mar 2021 08:46:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:56314 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231706AbhCVMi0 (ORCPT ); Mon, 22 Mar 2021 08:38:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8BBCF619B8; Mon, 22 Mar 2021 12:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616416659; bh=Yt3KVCYRO3zLQ6sob9l350U1wMzKzl2WmUHRgOHEmj8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HkNfHgvFv5YOqahleWH6b24DLKymkgmXhr/zmSDpm7C8QUHQI5h/3BZQZqN+f/JK5 U+xn79O5h7xRd9+FPfwas/P5KoGqtaGl/bOMDcsbL6OyhTrNEaguxP7Gm6X+sBcIqT 3y84hBbdt3uLQ4gtTRudWjuepJGi7u9arrZurmB8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Keith Busch , Klaus Jensen , Chaitanya Kulkarni , Himanshu Madhani Subject: [PATCH 5.10 036/157] nvme: fix Write Zeroes limitations Date: Mon, 22 Mar 2021 13:26:33 +0100 Message-Id: <20210322121934.902550534@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322121933.746237845@linuxfoundation.org> References: <20210322121933.746237845@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christoph Hellwig commit b94e8cd2e6a94fc7563529ddc82726a7e77e04de upstream. We voluntarily limit the Write Zeroes sizes to the MDTS value provided by the hardware, but currently get the units wrong, so fix that. Fixes: 6e02318eaea5 ("nvme: add support for the Write Zeroes command") Signed-off-by: Christoph Hellwig Reviewed-by: Keith Busch Tested-by: Klaus Jensen Reviewed-by: Klaus Jensen Reviewed-by: Chaitanya Kulkarni Reviewed-by: Himanshu Madhani Signed-off-by: Greg Kroah-Hartman --- drivers/nvme/host/core.c | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1894,30 +1894,18 @@ static void nvme_config_discard(struct g blk_queue_max_write_zeroes_sectors(queue, UINT_MAX); } -static void nvme_config_write_zeroes(struct gendisk *disk, struct nvme_ns *ns) -{ - u64 max_blocks; - - if (!(ns->ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) || - (ns->ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES)) - return; - /* - * Even though NVMe spec explicitly states that MDTS is not - * applicable to the write-zeroes:- "The restriction does not apply to - * commands that do not transfer data between the host and the - * controller (e.g., Write Uncorrectable ro Write Zeroes command).". - * In order to be more cautious use controller's max_hw_sectors value - * to configure the maximum sectors for the write-zeroes which is - * configured based on the controller's MDTS field in the - * nvme_init_identify() if available. - */ - if (ns->ctrl->max_hw_sectors == UINT_MAX) - max_blocks = (u64)USHRT_MAX + 1; - else - max_blocks = ns->ctrl->max_hw_sectors + 1; - - blk_queue_max_write_zeroes_sectors(disk->queue, - nvme_lba_to_sect(ns, max_blocks)); +/* + * Even though NVMe spec explicitly states that MDTS is not applicable to the + * write-zeroes, we are cautious and limit the size to the controllers + * max_hw_sectors value, which is based on the MDTS field and possibly other + * limiting factors. + */ +static void nvme_config_write_zeroes(struct request_queue *q, + struct nvme_ctrl *ctrl) +{ + if ((ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) && + !(ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES)) + blk_queue_max_write_zeroes_sectors(q, ctrl->max_hw_sectors); } static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids) @@ -2089,7 +2077,7 @@ static void nvme_update_disk_info(struct set_capacity_revalidate_and_notify(disk, capacity, false); nvme_config_discard(disk, ns); - nvme_config_write_zeroes(disk, ns); + nvme_config_write_zeroes(disk->queue, ns->ctrl); if (id->nsattr & NVME_NS_ATTR_RO) set_disk_ro(disk, true);