From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f227.google.com (mail-pg1-f227.google.com [209.85.215.227]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14CBB3A7F7A for ; Tue, 24 Feb 2026 17:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.227 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953304; cv=none; b=mXNHXTz4J5eCPj0Gb7SQtMGiiMzrRKIzpKEKsdhlj8BHU4VPieX6wUyop9SG+EbRSBQ8mzB46kB8W0TngjvkY0AJk3x97nhdwmjqT8lxj+mzDPX8PmvrCgjZJPpKAK6x3fQknsM5z1GKj6gpVw1CfpifxLKk7ZIZnNM5Bsdh+l4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953304; c=relaxed/simple; bh=552bYwko8otEYpm5ebh3dNg2RT6Pd9XEkCxMlc7h/U0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GSC6W+ny4jClnXWTXPiEfOtmugKbnCmKvRBTMI0/GYH79XTw2WLL8B9E0WJG/TWqaHV4UFRMlmbbxhfioGbFPKTQoz9YykYz3n2/3dYT7aLZ7KfNoC4NuwHICmpH4jW1xWndgTZixAz3E+TDISrQAba/hro6PMSuLuiTRkxer8k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=YTUQVq2g; arc=none smtp.client-ip=209.85.215.227 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="YTUQVq2g" Received: by mail-pg1-f227.google.com with SMTP id 41be03b00d2f7-c635d5d594dso529408a12.2 for ; Tue, 24 Feb 2026 09:15:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1771953302; x=1772558102; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iTyR51foYUPBOnnEwYMeOkSAEe5aT2w2QE+WyN/3DlE=; b=YTUQVq2g93s4qXWClZdladrRt8H0xrccDrd4mJiQgksT1JM0TQ1cvZoH4ZN1s6PoIJ 7zFfqJtKHTMgJwmqyd5EDKGB52UHsqUmN0i1KQ3TFUmXKdyuKz19av38xUVCfnP0/pUl XhN99Hlc9ewLYBD1N7EbBVGafnzfhEssb9kgQ41kSx2gPzUjygXS3ImwG4307FkrkBQy mM+ca2vbYHf8o3z3LAq6Ir+vg2FLMbaVVmbBrb7YQnyuUiYRYSFHby88HFCD7/F/psEK Xzvz9HX8rugjP8a4PixgxlXSjvaZI/2JIQmg0CHpAj2f4tbU7UZxjRMzV6O1r/94NDl9 GZ2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771953302; x=1772558102; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=iTyR51foYUPBOnnEwYMeOkSAEe5aT2w2QE+WyN/3DlE=; b=a4CsMP8E7BlcuYvQtKIlU54UNOgUDHQh/1WMcs1vH09PHMVawCzA+9HCRgFuUZvg+j CtiGyBRLH4cpPHCXQMe8L2ElCzPWHQjNIsaeMIkQJGYJaOnk6nsByjJInFD9L+uLtI31 Sc2mHN5YH/H9xYqsCy+07zVn3QlqWsQf8QvLzqNhXFLMPc6eqUyvXAfbeQgfdwFXXWNY ZtIrgzn7vmLdRUE9tMQEjt7dDbEgd2xZwqBzOVM/9/QfxKNIs3jkUViHMuycPPUh4vDV bAuSQW9jay8dGvPPm33Xu/3nZcih4TnP4D0dTQ4708rqsw6ayvfpsLMOdepREXcPM7dr z8Jw== X-Forwarded-Encrypted: i=1; AJvYcCWfnDakacU2ssz9LY3KGCyc96cQHfAhuU+253YczZmn9B340JVWirgrK49IxuTBbGx4urJIhgwKAQ2YPek=@vger.kernel.org X-Gm-Message-State: AOJu0YwMD3VmMcYouMSOSg8WgL0o3CQTg/pNfk2kTzTGE0PUFwl1rp/B TYHzJGGu1kJFIIUKg1kpvs/mF8Vq12GsLUjm/LFFFCU0+kKc+S5t8qHXe7k5t86LM+CZUAfXHBL MM0VExb7aCWEKOQ7H09IyRXiOVPvNS+6M/EK6 X-Gm-Gg: ATEYQzwYXsW1poFGR6Jowxszki5zQYuhVWzaXYxdEetoSkA0TxsuSquldPnKs1kYk0f DCp0YE950CPp20UJhtY2o0H56TXe85oYGX+v/A0eUfSXZUzFrx7WJtHxVmghGh2nOl5mPKuxIem Yyy05PViqjN2OJLClcttGaD7HXqbUcLdS9EP06vYWn7qDFWkia72xCd6WuTTtG0IdMrD3hAQrtc IzkrhxoVo6fr7K0WYspG63rCWB9yTSwVVowa3YCSeYmxy7HxDaXFznoJv9adyzJyKqGG66NjiT8 HzOQDVmswN11qSIQB0dcshXSB9TPHIMnbKcD4JR8oukqxW5MwwJtsggvE32UD0wlVB5bkB9HGMq 0TmlpVJstdmd1tnY3MlnG7Bdqmopotya4wXa77uFbfLyuw3DxqXuPHg== X-Received: by 2002:a17:90b:4b12:b0:341:88bc:7a54 with SMTP id 98e67ed59e1d1-358ae8e3753mr7245157a91.7.1771953302352; Tue, 24 Feb 2026 09:15:02 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id 98e67ed59e1d1-35900dba287sm56754a91.1.2026.02.24.09.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Feb 2026 09:15:02 -0800 (PST) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (dev-csander.dev.purestorage.com [10.112.29.101]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id 1E749341D32; Tue, 24 Feb 2026 10:15:01 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 19F96E41254; Tue, 24 Feb 2026 10:15:01 -0700 (MST) From: Caleb Sander Mateos To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Caleb Sander Mateos Subject: [PATCH v3 2/8] nvme: fold nvme_config_discard() into nvme_update_disk_info() Date: Tue, 24 Feb 2026 10:14:31 -0700 Message-ID: <20260224171437.3175993-3-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260224171437.3175993-1-csander@purestorage.com> References: <20260224171437.3175993-1-csander@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The choice of what queue limits are set in nvme_update_disk_info() vs. nvme_config_discard() seems a bit arbitrary. A subsequent commit will compute the discard_granularity limit using struct nvme_id_ns, which is only passed to nvme_update_disk_info() currently. So move the logic in nvme_config_discard() to nvme_update_disk_info(). Replace several instances of ns->ctrl in nvme_update_disk_info() with the ctrl variable brought from nvme_config_discard(). Signed-off-by: Caleb Sander Mateos Reviewed-by: Christoph Hellwig --- drivers/nvme/host/core.c | 43 ++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 3a2126584a23..8dda2fe69789 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1880,30 +1880,10 @@ static bool nvme_init_integrity(struct nvme_ns_head *head, bi->pi_offset = info->pi_offset; } return true; } -static void nvme_config_discard(struct nvme_ns *ns, struct queue_limits *lim) -{ - struct nvme_ctrl *ctrl = ns->ctrl; - - if (ctrl->dmrsl && ctrl->dmrsl <= nvme_sect_to_lba(ns->head, UINT_MAX)) - lim->max_hw_discard_sectors = - nvme_lba_to_sect(ns->head, ctrl->dmrsl); - else if (ctrl->oncs & NVME_CTRL_ONCS_DSM) - lim->max_hw_discard_sectors = UINT_MAX; - else - lim->max_hw_discard_sectors = 0; - - lim->discard_granularity = lim->logical_block_size; - - if (ctrl->dmrl) - lim->max_discard_segments = ctrl->dmrl; - else - lim->max_discard_segments = NVME_DSM_MAX_RANGES; -} - static bool nvme_ns_ids_equal(struct nvme_ns_ids *a, struct nvme_ns_ids *b) { return uuid_equal(&a->uuid, &b->uuid) && memcmp(&a->nguid, &b->nguid, sizeof(a->nguid)) == 0 && memcmp(&a->eui64, &b->eui64, sizeof(a->eui64)) == 0 && @@ -2078,10 +2058,11 @@ static void nvme_set_ctrl_limits(struct nvme_ctrl *ctrl, static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id, struct queue_limits *lim) { struct nvme_ns_head *head = ns->head; + struct nvme_ctrl *ctrl = ns->ctrl; u32 bs = 1U << head->lba_shift; u32 atomic_bs, phys_bs, io_opt = 0; bool valid = true; /* @@ -2112,15 +2093,30 @@ static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id, */ lim->logical_block_size = bs; lim->physical_block_size = min(phys_bs, atomic_bs); lim->io_min = phys_bs; lim->io_opt = io_opt; - if ((ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) && - (ns->ctrl->oncs & NVME_CTRL_ONCS_DSM)) + if ((ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) && + (ctrl->oncs & NVME_CTRL_ONCS_DSM)) lim->max_write_zeroes_sectors = UINT_MAX; else - lim->max_write_zeroes_sectors = ns->ctrl->max_zeroes_sectors; + lim->max_write_zeroes_sectors = ctrl->max_zeroes_sectors; + + if (ctrl->dmrsl && ctrl->dmrsl <= nvme_sect_to_lba(ns->head, UINT_MAX)) + lim->max_hw_discard_sectors = + nvme_lba_to_sect(ns->head, ctrl->dmrsl); + else if (ctrl->oncs & NVME_CTRL_ONCS_DSM) + lim->max_hw_discard_sectors = UINT_MAX; + else + lim->max_hw_discard_sectors = 0; + + lim->discard_granularity = lim->logical_block_size; + + if (ctrl->dmrl) + lim->max_discard_segments = ctrl->dmrl; + else + lim->max_discard_segments = NVME_DSM_MAX_RANGES; return valid; } static bool nvme_ns_is_readonly(struct nvme_ns *ns, struct nvme_ns_info *info) { @@ -2381,11 +2377,10 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns, nvme_configure_metadata(ns->ctrl, ns->head, id, nvm, info); nvme_set_chunk_sectors(ns, id, &lim); if (!nvme_update_disk_info(ns, id, &lim)) capacity = 0; - nvme_config_discard(ns, &lim); if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) && ns->head->ids.csi == NVME_CSI_ZNS) nvme_update_zone_info(ns, &lim, &zi); if ((ns->ctrl->vwc & NVME_CTRL_VWC_PRESENT) && !info->no_vwc) -- 2.45.2