From nobody Tue Apr 7 18:46:41 2026 Received: from mail-dy1-f227.google.com (mail-dy1-f227.google.com [74.125.82.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 A4B5844CAEB for ; Thu, 26 Feb 2026 19:04:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.227 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772132672; cv=none; b=nUvMIlb66vkl3FOJ8mU9YxqMfzaSC+cVn3ttNYntdE96IxUwm4Ajl38/DlsDTJa1ovwy4DhBre3FDrXRvc6KfTcP1Bg7ubMKrs4oIY7VgfN3ajuy2WEwfbzIhYtkrc8ucYDzgTw0khTJ3d1wegOXCnffgX5bx2RwWYipvbsAjfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772132672; c=relaxed/simple; bh=552bYwko8otEYpm5ebh3dNg2RT6Pd9XEkCxMlc7h/U0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nBwSCmonZAoToo74CzGZzpi3sNgOHuNSqRXfg+PRalnqQkRc5AbwFz6u+iyMoAvuLoyUxMq2YQDY/qP8dJJUYSY7c52LLJlDt4wwDTclevZ75duSTFG7fbgAr4dfWnoFOruZnwkwR7ISHiwAx0uvzKGNxFMgIc7Uxg954Z3Esrc= 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=bU+RBnN2; arc=none smtp.client-ip=74.125.82.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="bU+RBnN2" Received: by mail-dy1-f227.google.com with SMTP id 5a478bee46e88-2bd5658b901so50726eec.3 for ; Thu, 26 Feb 2026 11:04:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1772132662; x=1772737462; 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=bU+RBnN2PPx0a3cdJQJhd9f4HsAYu86Vvt+x/huvgrPvKLbt/m0SPeRRoM2X7ZtWN5 EDMqDJIe/5KVrXfndf7RlwR5X0GhPvrsp+ttN7fJgbAiP1npjTULT5x5u/6B54H2AFOx 4MX4D/9ZMLpckzGpnr39CNxn3HsbwNNuIc6jWaSaXlVuALJBh/10/7GnzZCYy25ykC3/ 1XW4qpMhQLpdHsGPFpXoaPHFg85EeaTTiqng/duVMtzxlxuK6vrJCKz6+ZuF45wgS+aa 9njPfZ4qDgkE5jntZyWq9IfOrPgRlfZmF/GWDnmCeYXfgW0georIATqfnZx3e3u87dA+ W5ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772132662; x=1772737462; 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=d4fLRPwK59cl/BDN9o1eFsA/2VK6jEroiE1XWLFa7YwbiMOT2YS7ZN4vnUp2uzEL5x Z92lSropMRSCrm0BwSgoUJyrZJPZPJxE5K2SRBNcMUyP9waLeIxMa09nAJvwnwnQR7ni r1AxMqqIW9Eu3nEwsRnELxgq3PX80AdLar/YP+9pE/62jRGLnBxRDNPvi/Pn0jYGy0vg fUK5mk3pGDnFjjNX3D8M1NwxC5KAKdBmMfaJZSZxnTZiaBTJtdJgqPO4E9CgXSG7xxZp /GegqFPB46AAjDzQkxoAcNDkNZAUfwnOAnaMZjcnO29WEo6VWmQ4qGJEWYdOCnqVaiSZ 604w== X-Forwarded-Encrypted: i=1; AJvYcCXOouoDfxGP6ITuBULKnVyPutkZS59sVzVEFGb6T1vTh5mgq7y5WGkCfqBroB5+0Ebx7KwQiAUjfdkxPSk=@vger.kernel.org X-Gm-Message-State: AOJu0YyYUcvGa5iYeHSIR+duaa2GiR6AHxn90BrTFB6Az2lqb82wUFOG +O6aGN+1T5V5GqVOEDXAIxtqL5PYWrEaoljUQHh9kXxSwXBl/4sOczo/w+ZWrR+5WV2pwu/w90p AdSNaamrftZX25i8ezgbuX0285eUf7Vwm7cto X-Gm-Gg: ATEYQzx3O1lKa60Pc+ltDRZbqJimk2pyfUhc2+9iS3NT338Y7PcayKkfA1ZHwGAPk3P O3Ij49uT1bwviQ11k/Wf2RqWWwrPpHfcMugdFXLuFp3Mndv11OxGwPsJdAiIzfjXbY4dJ3wfTd4 jzww4qcQMdaVEYK62KjoDlM1QScuZyxJq8hcii1R0JeKU2U/s883UaJGAoAui0+YjU/VxLxgsO1 KM6cni84W0dUCnCbRVHQu3OicBb8UsCoMbR9pMMGfrftr9IXrj8XulwEbqhPXMOvTmyeal+t6t1 dN4K7PxiviYLPigo/BWaJ+UCBBLgWnuxZFbBEmo1PCuSETHH8WV7Ap+xFpHJT9gAbcL1/TChLlJ Qjr9DB635j3SnGpV21zG2o1qXdzyiu1E9M5SoUrKgeru3yB2HsKq3zg== X-Received: by 2002:a05:7022:6199:b0:11e:3e9:3e89 with SMTP id a92af1059eb24-1278fc28834mr1899c88.7.1772132661187; Thu, 26 Feb 2026 11:04:21 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id a92af1059eb24-127899d591csm386473c88.1.2026.02.26.11.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 11:04:21 -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 E369834058D; Thu, 26 Feb 2026 12:04:19 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id DEB0EE41254; Thu, 26 Feb 2026 12:04:19 -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 v4 2/8] nvme: fold nvme_config_discard() into nvme_update_disk_info() Date: Thu, 26 Feb 2026 12:04:09 -0700 Message-ID: <20260226190416.297725-3-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260226190416.297725-1-csander@purestorage.com> References: <20260226190416.297725-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: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D info->pi_offset; } return true; } =20 -static void nvme_config_discard(struct nvme_ns *ns, struct queue_limits *l= im) -{ - struct nvme_ctrl *ctrl =3D ns->ctrl; - - if (ctrl->dmrsl && ctrl->dmrsl <=3D nvme_sect_to_lba(ns->head, UINT_MAX)) - lim->max_hw_discard_sectors =3D - nvme_lba_to_sect(ns->head, ctrl->dmrsl); - else if (ctrl->oncs & NVME_CTRL_ONCS_DSM) - lim->max_hw_discard_sectors =3D UINT_MAX; - else - lim->max_hw_discard_sectors =3D 0; - - lim->discard_granularity =3D lim->logical_block_size; - - if (ctrl->dmrl) - lim->max_discard_segments =3D ctrl->dmrl; - else - lim->max_discard_segments =3D 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)) =3D=3D 0 && memcmp(&a->eui64, &b->eui64, sizeof(a->eui64)) =3D=3D 0 && @@ -2078,10 +2058,11 @@ static void nvme_set_ctrl_limits(struct nvme_ctrl *= ctrl, =20 static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *i= d, struct queue_limits *lim) { struct nvme_ns_head *head =3D ns->head; + struct nvme_ctrl *ctrl =3D ns->ctrl; u32 bs =3D 1U << head->lba_shift; u32 atomic_bs, phys_bs, io_opt =3D 0; bool valid =3D true; =20 /* @@ -2112,15 +2093,30 @@ static bool nvme_update_disk_info(struct nvme_ns *n= s, struct nvme_id_ns *id, */ lim->logical_block_size =3D bs; lim->physical_block_size =3D min(phys_bs, atomic_bs); lim->io_min =3D phys_bs; lim->io_opt =3D 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 =3D UINT_MAX; else - lim->max_write_zeroes_sectors =3D ns->ctrl->max_zeroes_sectors; + lim->max_write_zeroes_sectors =3D ctrl->max_zeroes_sectors; + + if (ctrl->dmrsl && ctrl->dmrsl <=3D nvme_sect_to_lba(ns->head, UINT_MAX)) + lim->max_hw_discard_sectors =3D + nvme_lba_to_sect(ns->head, ctrl->dmrsl); + else if (ctrl->oncs & NVME_CTRL_ONCS_DSM) + lim->max_hw_discard_sectors =3D UINT_MAX; + else + lim->max_hw_discard_sectors =3D 0; + + lim->discard_granularity =3D lim->logical_block_size; + + if (ctrl->dmrl) + lim->max_discard_segments =3D ctrl->dmrl; + else + lim->max_discard_segments =3D NVME_DSM_MAX_RANGES; return valid; } =20 static bool nvme_ns_is_readonly(struct nvme_ns *ns, struct nvme_ns_info *i= nfo) { @@ -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 =3D 0; =20 - nvme_config_discard(ns, &lim); if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) && ns->head->ids.csi =3D=3D NVME_CSI_ZNS) nvme_update_zone_info(ns, &lim, &zi); =20 if ((ns->ctrl->vwc & NVME_CTRL_VWC_PRESENT) && !info->no_vwc) --=20 2.45.2