From nobody Tue Apr 7 17:13:27 2026 Received: from mail-yx1-f98.google.com (mail-yx1-f98.google.com [74.125.224.98]) (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 3863C36BCE7 for ; Fri, 27 Feb 2026 20:24:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223843; cv=none; b=ceoReiYlmsKGg6ByqbbE1evZkYZTSpVETBnONlsasO1AXEvO7or5ExOMADt2jfgHFo9giF5pW58Fj4mZumXhFPMHLxZSnBaSp/7EI0HcWapEaSX8W/1jVB3wgGFCGYQrqSBJvOtK890tyNEA8hVzpFjIcpueXwQoxSR12wZcOmM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223843; c=relaxed/simple; bh=C1USMimgJzASCD7VPj4tIL5i173jKmiylohG9y4/etY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OKcqKkJmSVfW/QTyvS1V0KYrgIpMDxGG9P7wNKCv9OWpHCKIrc1YyCH8TLdQehO44tU0nBVly8uGmaOZTUA8V7fHGsG77gbstA+a0GP7lkvCGyZ+0G9FvYntooC1rcLpMnt7rilX7u5ZT97VTF1XGJ69gfOasNXcVAIfPMgONaw= 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=NPInV2x8; arc=none smtp.client-ip=74.125.224.98 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="NPInV2x8" Received: by mail-yx1-f98.google.com with SMTP id 956f58d0204a3-64ca49cc623so352481d50.2 for ; Fri, 27 Feb 2026 12:24:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1772223841; x=1772828641; 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=qCPUB5YteTwm4Su/ndU1zpliegenX1WCgWKjuq5aUfY=; b=NPInV2x8Qgz5LoR5aA0UDJAfaWSF7M2iqGycIpEh+uCYFrFBtqL84esoemp1k8ADT6 LKzj+OkEAF83FPbiq6LWwg/xtUK07MLiQcUCUIBWB4qYKp2DVlJ+jUUGgzpHB4Vvokpp BUVJVJosl8F524hKtJdprdoqwr7dseTYIsct/G1uir00MR5dvbfUw1fjh9TDunbtdaBs a4o26GFw6AkdrVMvF79VokETDjNm9iIUu4eNZ6OQU+f6+/uFJ2au002pvFf4Twz56lmQ 28wleT0WVKs1sY0hPC23HmtWANWqKEEjhKiUIQBGyCSTCtmgqbdltP6TI146deM3L7GG hCKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772223841; x=1772828641; 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=qCPUB5YteTwm4Su/ndU1zpliegenX1WCgWKjuq5aUfY=; b=VdUAsYSexqHjNqVBs0BGv4BZlmHMz9olorXjM9cy08CfVDD/JESpkeDNieUWUKrgnT 5p+Xn6Dp73c/uBDdIFxRrnEFcnzV7qiVXURRpFtlD8fQFU9wQ0h+88UmdZ9iSUhQS3EA y1kBYkK69U1jP+8NXEsBJpRBKLQVUG/iB42YkNtHatacas+68zO5PqkI7CVwlGn2AbKM /jJvhN/fu2yJno8ZWMHqqWXIU8FY4Yd9KbA4VcL39+quEsYskecTvG464nbTibb0Oyx3 40lmibF+XKI7hFamFwl6wzIyVbAc16d7SZduaEqHMGA3oy7APWnQ3S5LjR4ic7wEWK+E p77Q== X-Forwarded-Encrypted: i=1; AJvYcCVIrMr2ApmMy3v765fKw3nSuk/AdgjIwmk52nY1PeizC3QoSUH+m7L0t9QYJHGcdjL5CxMy7tdCyJrWmhg=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0qP8VOG3LApzy/ZE6StJnmMOzEPHJEZXEiM6GVq9e6l/Pg8FW zQXx2TcqJDD/7UhmpBZRHCgT1cmpbIlL8vqdqBKVKJ+NN4YaqsOPk9SuWJHFrY55z5Gd86NxVpZ Gg/u146R3hzBTeSrkJV9agAHdNbpifUsW0/LdOKBXV/qzjNbBbJFv X-Gm-Gg: ATEYQzzSLY31oYk/URbsRkORgLBRBWNKx3nE0wqTvSsMvkW26Y3eb8ztMmqmmekKpqW TLHTxoEA2hadmPSlWxVZPimNx6grzR+BrhjNZVvY5Q5xDXo9iISDLKt12SFPnOCdvVZJ7oxcVjo i4CTt+lBJxXGtyBRB/lx4MbZN7ZjVQZdfQAGbm7gZTPBc8uDUXgCdKA9ZRGTPFL7z2VvJEhh2P2 NA4UtstabUDIpCwi3J3kce1xGlAiEb9zibWCoHoXiLdN38xC4penFd0gH8h3DRtZOF4wMPUdb3i ORgCEG76lXdhdqWleJO2dU9TJBxjnYWQwDZQW4bnw5e+IQiJ7IlYUHrKnlbTUe2lsfEizztj24N eJcnAAMfhv2npEraqyO7m08QXUkS/ZETYzaI8aKM= X-Received: by 2002:a53:ac9c:0:b0:649:bf2a:71d with SMTP id 956f58d0204a3-64cc22be974mr3069800d50.4.1772223841189; Fri, 27 Feb 2026 12:24:01 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([2620:125:9017:12:36:3:5:0]) by smtp-relay.gmail.com with ESMTPS id 956f58d0204a3-64cb7590dccsm555012d50.5.2026.02.27.12.24.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Feb 2026 12:24:01 -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 675413404A1; Fri, 27 Feb 2026 13:24:00 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 62661E420D8; Fri, 27 Feb 2026 13:24:00 -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 v5 1/8] nvme: add preferred I/O size fields to struct nvme_id_ns_nvm Date: Fri, 27 Feb 2026 13:23:46 -0700 Message-ID: <20260227202354.1012322-2-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260227202354.1012322-1-csander@purestorage.com> References: <20260227202354.1012322-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" A subsequent change will use the NPDGL and NPDAL fields of the NVM Command Set Specific Identify Namespace structure, so add them (and the handful of intervening fields) to struct nvme_id_ns_nvm. Add an assertion that the size is still 4 KB. Signed-off-by: Caleb Sander Mateos Reviewed-by: Christoph Hellwig --- include/linux/nvme.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/linux/nvme.h b/include/linux/nvme.h index 655d194f8e72..1134e6bf2d5c 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -511,13 +511,20 @@ struct nvme_id_ctrl_zns { struct nvme_id_ns_nvm { __le64 lbstm; __u8 pic; __u8 rsvd9[3]; __le32 elbaf[64]; - __u8 rsvd268[3828]; + __le32 npdgl; + __le32 nprg; + __le32 npra; + __le32 nors; + __le32 npdal; + __u8 rsvd288[3808]; }; =20 +static_assert(sizeof(struct nvme_id_ns_nvm) =3D=3D 4096); + enum { NVME_ID_NS_NVM_STS_MASK =3D 0x7f, NVME_ID_NS_NVM_GUARD_SHIFT =3D 7, NVME_ID_NS_NVM_GUARD_MASK =3D 0x3, NVME_ID_NS_NVM_QPIF_SHIFT =3D 9, --=20 2.45.2 From nobody Tue Apr 7 17:13:27 2026 Received: from mail-vs1-f98.google.com (mail-vs1-f98.google.com [209.85.217.98]) (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 7789334252B for ; Fri, 27 Feb 2026 20:24:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223843; cv=none; b=XzHbcwcGD7wi/P372r2DFDdNLKD+fWQ7AaNjkfPUvECeLPu1JUYdV0BL1/vo7kGNsbz5/6vjbFiys/IvG3BLjUDgUnL1VAbeJKTRREi5GcfwsSbp7oOT/o5qg0KkD3n8x6k70fR9PzKCksaTIH7tp6Xbs73eK5/RZZBXY4BdI2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223843; c=relaxed/simple; bh=552bYwko8otEYpm5ebh3dNg2RT6Pd9XEkCxMlc7h/U0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OGq1lKIrYGkmkQ0pIn7+twI1ADdl1jUIAgHnVxtEO3Wo+FR7kchMqoy9tDzQTGEBJYExQcQmmJIoWehe3175sVk+OWxyScr2GMlwWIOPyEbs9FJ362upQkCEjp1blP1dMGpWu4JeEG0Ogbdog2RXO1PF7WxKpV6t0rD8cI0PHu0= 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=ddmb4c4x; arc=none smtp.client-ip=209.85.217.98 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="ddmb4c4x" Received: by mail-vs1-f98.google.com with SMTP id ada2fe7eead31-5fdfef72ad0so80613137.1 for ; Fri, 27 Feb 2026 12:24:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1772223841; x=1772828641; 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=ddmb4c4xq6/N7t40TSB7ek7wlHl19Br//ucyCGMIYRCJPD9NETJVKLnImGBFPbYJdl gjnQruhJcrh5JSxBB8spl+fokiiBoAxoa0kKJH0b2jDoligvJQPwpSvYul+wyc/Ik0SD Th6VmBiiqlahLoGTUqq+9TAVsRSQ03KVS65SNoZQO0wSsslZsUcXM35FM0Ibs8Y8tRZI tj3GYFkUDUh9oRG0dYdJCkAcxAHomZ43cqy6InNa2D/W9VF4811dQjZ+TO9zxi2tY6Nx hrgjJBKMhXoyZMXW3Wwg98qYjSX5zhA7K2QAgwzobIhRXOV7N5u+RP9Csrnm7TKuRMck lPBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772223841; x=1772828641; 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=TxLNCPEQlqDcKLG7ZxLg2MsKyvUksRE96d5UEjVBJ5dGeCp5zBxoYSOUdEOmabqlMN Wa0PZtFHgwulFrwaHUwtES4NxV/TeZEU0Bot9CurMg2L6zZT6uv89uc56sPxgJbwyp7N uARgVQ7r0hB+o3TYfsMg7Q56qtM2YEEGg8D//nQEOxpPLmylBx5kpRWGArrLUBpDcagH arQLLzThVtLEtRSi6YacrofGC/S9UEHEP+N52ZCmggSNpw5xxcypClag+hIFVX7ZlIDQ RPzJesEauJ+sUfv76w+koR38pK+3jHLFiNetRFoefrNElllRvbaw2caLDPcU2go5NukS zSRQ== X-Forwarded-Encrypted: i=1; AJvYcCXMmRLbwG5bH7af7hqAyg9RcvGKFSfBLsAiE4DyF5nifBNr1zqqEnkTdFs1FsHVH+FTlXLodrq7WcQ0H5Y=@vger.kernel.org X-Gm-Message-State: AOJu0YwsePAVd7g9Fb1n8WatMJqMekLBE8K7OPK/nap70coVUkaiwmqN 83hX1O8b12KjZztowfDbHDFywEKKdy0aTbQ6H4plkg/Z5SzurT9KAleKStO91w5j5qdf1FLH6Fw Us45hB39aiYRDOlOTkliPuxv/xWCspPGBg0m/ X-Gm-Gg: ATEYQzwvuf8zXNx/xaKIbINI5Pco3OefNneQKRuMp84QckDSD/IkStH7PybDtTMReok Z1HKuu41rCVAlI6/3lk2WcmDBCruKu37tWmyG4IBSorS45hXUVWBA+yPpEOwf/frwuXrriwFW9X w/TmvqUREyeg/akT0/UU7NFfayBJRWXH8q4cDvXoOevRKitDnPNQYX+gq2VXQ/y1OZeoLcjLkz9 WV4nHdkd+rN0l+8Uuzm6eCUShwGR7H9KzrvYidbVsRKiyCk0xgNSIW3Cfn+u/ZCEiunW0wV7XNa V8MRHgQhRBVK3zqnodwHSbg1+HlRtpHBhDUe4DcMbFx9n5nKXtcTWUUcXh/20anozCUD3EMSJsI nQbeP96WrlCIgUxvuxYKBk+d7+DMuAYn8WjIct/mQaMpZ6AFJgSNq7A== X-Received: by 2002:a05:6102:d86:b0:5f5:3a57:1e88 with SMTP id ada2fe7eead31-5ff32536282mr1200513137.6.1772223841310; Fri, 27 Feb 2026 12:24:01 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id a1e0cc1a2514c-94df6542376sm546097241.7.2026.02.27.12.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Feb 2026 12:24:01 -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 8F7C53405ED; Fri, 27 Feb 2026 13:24:00 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 8A735E420D8; Fri, 27 Feb 2026 13:24:00 -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 v5 2/8] nvme: fold nvme_config_discard() into nvme_update_disk_info() Date: Fri, 27 Feb 2026 13:23:47 -0700 Message-ID: <20260227202354.1012322-3-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260227202354.1012322-1-csander@purestorage.com> References: <20260227202354.1012322-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 From nobody Tue Apr 7 17:13:27 2026 Received: from mail-vk1-f228.google.com (mail-vk1-f228.google.com [209.85.221.228]) (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 8DB54413236 for ; Fri, 27 Feb 2026 20:24:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.228 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223844; cv=none; b=N4TQcAqzsi4r3Pwh9CfLYXB/Kxz9gVMrzdK7DInow5627JA+TC/y17fOXfPq6tn6vTSnyjYetRUxUxSqac8FLQwCN7OtHB41/dvF0JUCsvv9jnhYUnyJ8Wy8V2VIOTiF5z27tj2gT4e3MSCz+TZsVxq7cmPjcc80zG6/Z6YfyxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223844; c=relaxed/simple; bh=62cRCccrSguAwwqDGJINO/15pCmBCVwknmS2odJqMIo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WYjJv7ee8Sp//GOgNDNBHpFdyApiSNJykOsO77STpQD2IKOFCvHlIC8bMflcyw5xoD5H0kMiOhBraKTACGJe2haqJ0IlbzCYSi8rLEzwu7djAe5GnOB9AJ7ojhlnWY7T9SZ1C3JBQmEBfwTdworJAqAW9csWBU2NMDJlrUIL+rw= 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=PWVnJjZK; arc=none smtp.client-ip=209.85.221.228 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="PWVnJjZK" Received: by mail-vk1-f228.google.com with SMTP id 71dfb90a1353d-568d5c03438so150524e0c.1 for ; Fri, 27 Feb 2026 12:24:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1772223841; x=1772828641; 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=ooHjh6HrTZHmSmxByDLdiCmY2zTnKYEXcZkNLfcMiWM=; b=PWVnJjZKyax3yfd8jpdAgmtK7k9I9ZEsTuyxgHA1+RWzNrK85+gMDvp/N/0cS5sVRf E0cleb8f4zXfIJkdnjDhPQ2uLw4SxzCN8sbQlrAJfMPqw+kTCE7kGfWesLFXQhWpTj1i iccN7K4844f0nRWqOfsNS505zsPCMlB0I0X84Ao3iOn7GHUYggenDFwcYzR1kDZRwjDb KhpybD9qW1cng2vaIrnfmw9s1fzexvxnsDEodfGQOyPAUT8UXkFK481LgsJkQMWKkaIa TFEzEgdKa/I53meVq1ooBqCvIlwJLq3teYGOss9UBtDVlhLNiOR9KvNg5u1ZgVc5YslC txNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772223841; x=1772828641; 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=ooHjh6HrTZHmSmxByDLdiCmY2zTnKYEXcZkNLfcMiWM=; b=i6L4smgUikY83X+KjYAvfPZeJorsBcAUlzY9FJAalHYK4sXNqsBZZIZ0/ugL9BdnGY 57Zx6qaza78baWe4OlUcJy71h0eA4M1S2OvLU2gyYQSCFu1iPpeRWxX0kRjR1F7XrEFI ny8UOondpf6zY4L/4sGg6jHju3WctbnxOL77t2brF8Q9uKVWA+jikvywnLVYwZo0UmGe B1g8CkJC7b8MPJjYe7l7gTJZJDviqJKT3YWnfH2RAofm2LzGHZTiLWnL2l/vVwmGWa3X mmMKvVY/XOk+5U1O1LraIRyoj9gerGL0AMGuCIN1D04zTDyPJbmZD41JxWBiv9m9MfGX VJDQ== X-Forwarded-Encrypted: i=1; AJvYcCU/H77FgiyxcwCo6+ncfrkBCUf5y2sGDs0siiuPu+6eVGXuMGL0c8gNnv5I6qFZXg/AlUlf4QUg2Sz4KaA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw89xf9MFvlmWSR5R/tXh9lnO5ov8XqbIpfhGhBSgiC/jJrion4 xomEy81YM/jZYQWLZ0Ypo2qAzDW1/RpVgUVjx3o3oCunUgs7Jz7y9W3JDX6HViySMek113YGcSt 6Te3GkhdGvVZioS+nOv/7Gm0jzPvk3vt8KWZf X-Gm-Gg: ATEYQzzXfBWDS8KE5T2hFJ7wa2swlXdY3K4tTCn8bqTpXqKRGSHvYl7+9rbUPi/oey1 R3r6e587ytDq8NuOdVfV4aAQSVZATMF2/uSUOJRb/tAUMlnkMLHFlTAl+aGK2Vn2e7VUPAWXleG G1ObEFahDCjFXgMBF9Gi7K5OL2D2P3DFyR0irL0bKlR/5nuth+q2SdZkyr8q9nEk6909JFcKJRz OoBokMehn1YqtTYtYV2TW3d/wcugx9C0q2AhVgtLwOmklM4rd348vWttNGH24QovcCRQfGqOs3P gvW0wacw/hSFivlArEyTMItSBU185gnvIpGxikaVQY7CE+gGOZav+MSU92213d/6wk7Xl53dR29 P6JT5+kCvbAxSTNr+61pBznuHCtb4kQofoMqxYNR0xvGGa1ypVFKNmw== X-Received: by 2002:a05:6123:2a:b0:566:fec7:2ac3 with SMTP id 71dfb90a1353d-56aa08c75camr916564e0c.0.1772223841453; Fri, 27 Feb 2026 12:24:01 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id 71dfb90a1353d-56a9204c539sm697320e0c.8.2026.02.27.12.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Feb 2026 12:24:01 -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 B69293420BE; Fri, 27 Feb 2026 13:24:00 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id B0F46E420D8; Fri, 27 Feb 2026 13:24:00 -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 v5 3/8] nvme: update nvme_id_ns OPTPERF constants Date: Fri, 27 Feb 2026 13:23:48 -0700 Message-ID: <20260227202354.1012322-4-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260227202354.1012322-1-csander@purestorage.com> References: <20260227202354.1012322-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" In NVMe verson 2.0 and below, OPTPERF comprises only bit 4 of NSFEAT in the Identify Namespace structure. Since version 2.1, OPTPERF includes both bits 4 and 5 of NSFEAT. Replace the NVME_NS_FEAT_IO_OPT constant with NVME_NS_FEAT_OPTPERF_SHIFT, NVME_NS_FEAT_OPTPERF_MASK, and NVME_NS_FEAT_OPTPERF_MASK_2_1, representing the first bit, pre-2.1 bit width, and post-2.1 bit width of OPTPERF. Update nvme_update_disk_info() to check both OPTPERF bits for controllers that report version 2.1 or newer, as NPWG and NOWS are supported even if only bit 5 is set. Signed-off-by: Caleb Sander Mateos --- drivers/nvme/host/core.c | 8 +++++++- include/linux/nvme.h | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 8dda2fe69789..bff6f26d7bcf 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2062,10 +2062,11 @@ static bool nvme_update_disk_info(struct nvme_ns *n= s, struct nvme_id_ns *id, 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; + u8 optperf; =20 /* * The block layer can't support LBA sizes larger than the page size * or smaller than a sector size yet, so catch this early and don't * allow block I/O. @@ -2076,11 +2077,16 @@ static bool nvme_update_disk_info(struct nvme_ns *n= s, struct nvme_id_ns *id, } =20 phys_bs =3D bs; atomic_bs =3D nvme_configure_atomic_write(ns, id, lim, bs); =20 - if (id->nsfeat & NVME_NS_FEAT_IO_OPT) { + optperf =3D id->nsfeat >> NVME_NS_FEAT_OPTPERF_SHIFT; + if (ctrl->vs >=3D NVME_VS(2, 1, 0)) + optperf &=3D NVME_NS_FEAT_OPTPERF_MASK_2_1; + else + optperf &=3D NVME_NS_FEAT_OPTPERF_MASK; + if (optperf) { /* NPWG =3D Namespace Preferred Write Granularity */ phys_bs =3D bs * (1 + le16_to_cpu(id->npwg)); /* NOWS =3D Namespace Optimal Write Size */ if (id->nows) io_opt =3D bs * (1 + le16_to_cpu(id->nows)); diff --git a/include/linux/nvme.h b/include/linux/nvme.h index 1134e6bf2d5c..d840f5fe79fa 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -595,11 +595,15 @@ enum { }; =20 enum { NVME_NS_FEAT_THIN =3D 1 << 0, NVME_NS_FEAT_ATOMICS =3D 1 << 1, - NVME_NS_FEAT_IO_OPT =3D 1 << 4, + NVME_NS_FEAT_OPTPERF_SHIFT =3D 4, + /* In NVMe version 2.0 and below, OPTPERF is only bit 4 of NSFEAT */ + NVME_NS_FEAT_OPTPERF_MASK =3D 0x1, + /* Since version 2.1, OPTPERF is bits 4 and 5 of NSFEAT */ + NVME_NS_FEAT_OPTPERF_MASK_2_1 =3D 0x3, NVME_NS_ATTR_RO =3D 1 << 0, NVME_NS_FLBAS_LBA_MASK =3D 0xf, NVME_NS_FLBAS_LBA_UMASK =3D 0x60, NVME_NS_FLBAS_LBA_SHIFT =3D 1, NVME_NS_FLBAS_META_EXT =3D 0x10, --=20 2.45.2 From nobody Tue Apr 7 17:13:27 2026 Received: from mail-pl1-f228.google.com (mail-pl1-f228.google.com [209.85.214.228]) (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 BB3DB41C2ED for ; Fri, 27 Feb 2026 20:24:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.228 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223844; cv=none; b=ERY70FI9csnqiO2GwqBzhbitSnKHgRI3jQYBZNWkoJ6YCLy2K2De/eECoLgqatL8e4LJxHAMhaKlTaPzdCVCIc/ULGD0g9UA7VgYbEF+nzgCrbueJGMcIbhuF2co5e7c8UABH+RPkp9kA7epSf/4RsI73oj3dcqdiARbP3JRZ6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223844; c=relaxed/simple; bh=EVgNL5Ff+LgS27uDkBNGv73Qt0PWL7UobTeI9pnCh4g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OBTossrOwjUrqhBd82Fmap1VRt48vs0giwmF8qf+jCmxmP5GpEpqdt6E/a3puwdNQeiAlgJdZwi9JDt5z9+xjpIbIf6k3EdVmeHJdi9HCSy7zauuOFCY7E+li/0TuIj2/f5/D5reU+/UlMdo/DFc4IXaW32d41x5oZE/eNPzNX0= 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=OWxgYPon; arc=none smtp.client-ip=209.85.214.228 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="OWxgYPon" Received: by mail-pl1-f228.google.com with SMTP id d9443c01a7336-2a3e79fe2b8so3119975ad.1 for ; Fri, 27 Feb 2026 12:24:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1772223842; x=1772828642; 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=4pe4RREd+BTPRgbiC807YGAMUFduYLhwjMogn+PjJEc=; b=OWxgYPonLZ3LU2F/3JVakxflZRrlepaLXW+IMCAzNC6bfMFXL18IxqtBzjsgn8ptxk ncm7mX4tOqqAWZG0kKJkmXcfPuxy3DbvxNqGwm453RYqrMRSufdZN0x6kdM/ALs5r8Ws TrgBdc+JkvVwvRqLMFdLjXFpZ4RuXEjsaCZMJ6+MV4xy3Wq0AryUrjIlRROvb07OS3cs QmaV0DH+n6da0yS4jNjZp5aV3uS7k+xnVEmo1rUJYX+jqN2e+nE+BbDUpC7H0BzRrlOK v9au+18M0l7bCianfyao6rA4LmGWzKSjGLjzFqKQAuHl01s1B0h7clxJFZm2beCoXAbk npQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772223842; x=1772828642; 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=4pe4RREd+BTPRgbiC807YGAMUFduYLhwjMogn+PjJEc=; b=NzBaSI1xc+szVQeUVXD60Qw2LiMhBMsyWqUvvU/lYoleuUIaf81xkb0Jr9311GpHTQ w54nlFq/5+JTEOPZvmFhas60IG2oDa80gN7R8zfS8gVhHL8IQOf9RTwVzlwbx/aXSX4p r/d16zpAdOYyaQmZbujrcQJpWUsQmg1RZ1ZG2aNCtRmQIZtZBCgFxhTKbPeALyAaVw6R aoElOPqzViwMr0S69XupjqpbRoEn4hEiVhRMOweiilcts0pewpOTH6HY22Gey52UWNtM Wpg6S/jQ7fsTzAoMs5HvmGbNrHNrNhdw1uzpkb4LPnlLFYCVlH0v1S+yG2PUd52CwOWn b+zA== X-Forwarded-Encrypted: i=1; AJvYcCVlSNNpLBt8cXE610DOKtC4Fja+p996iqHmhQAtt9uKz22Dqe0vyYBZApv/uCQSe1zrs2ZYHygEDgEZrsY=@vger.kernel.org X-Gm-Message-State: AOJu0YzIK2c2u72DdvyhQgfHyFXwhi5b7gAfGypIfSEeJiAxxkUq5KAa ZA5vF4GjnJHssO4Wihz9d1z9x6rpFOaJVAfsvh9O/OcID/HlGnZKjwh0GQlOrgnyp9GkjtFCnZE RwmjhNC6w17+mL1oqNbsd3h/Y+caADSEG0joXPo1yCpjQqcqe2wFQ X-Gm-Gg: ATEYQzwBBVFveUXFeaCIp/QyCUWwDNqVn50Wlii2uEC59qRCDxixd+XCEfd+pSy/T2N iNdWU4Od/qUosL9dLYCp2KY5+qR95AIPbeogMJcq2O9pe2exwxBN7/X6fzWdCGqCw2kN1O8+gO/ 1a0Ieg6lY4iKZrAaEY597FHwo3RPpnlDnUNszXI7uHEUoidPEF+QrC/qwRblaqI7ZXRc01IQiMX xsz5JfFIirvHEIxnR4vaVSVdix1TirRt6R3XUBJcXbkuTjabINWyLDFSEXLHGPPtwWMiI9Qwh+U dZXafTejQF39U+aJFIJEowl0dN+QNQTCrGy0isPWm0Hxpd6BBdtySscHLnK5tvsUHiAJtXI4sZF NBjlraqC3lt513BECkcP7C+nhHJJV3ZBirFgO2SQ= X-Received: by 2002:a17:902:f650:b0:2ad:e300:df0f with SMTP id d9443c01a7336-2ae2e4770b7mr31860275ad.4.1772223842043; Fri, 27 Feb 2026 12:24:02 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([2620:125:9017:12:36:3:5:0]) by smtp-relay.gmail.com with ESMTPS id d9443c01a7336-2adfb267621sm7698445ad.20.2026.02.27.12.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Feb 2026 12:24: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 D8870342243; Fri, 27 Feb 2026 13:24:00 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id D3EB5E420D8; Fri, 27 Feb 2026 13:24:00 -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 v5 4/8] nvme: always issue I/O Command Set specific Identify Namespace Date: Fri, 27 Feb 2026 13:23:49 -0700 Message-ID: <20260227202354.1012322-5-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260227202354.1012322-1-csander@purestorage.com> References: <20260227202354.1012322-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" Currently, the I/O Command Set specific Identify Namespace structure is only fetched for controllers that support extended LBA formats. This is because struct nvme_id_ns_nvm is only used by nvme_configure_pi_elbas(), which is only called when the ELBAS bit is set in the CTRATT field of the Identify Controller structure. However, the I/O Command Set specific Identify Namespace structure will soon be used in nvme_update_disk_info(), so always try to obtain it in nvme_update_ns_info_block(). This Identify structure is first defined in NVMe spec version 2.0, but controllers reporting older versions could still implement it. Signed-off-by: Caleb Sander Mateos Reviewed-by: Christoph Hellwig --- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index bff6f26d7bcf..c3b24fcb2274 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2352,11 +2352,11 @@ static int nvme_update_ns_info_block(struct nvme_ns= *ns, ret =3D -ENXIO; goto out; } lbaf =3D nvme_lbaf_index(id->flbas); =20 - if (ns->ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) { + if (nvme_id_cns_ok(ns->ctrl, NVME_ID_CNS_CS_NS)) { ret =3D nvme_identify_ns_nvm(ns->ctrl, info->nsid, &nvm); if (ret < 0) goto out; } =20 --=20 2.45.2 From nobody Tue Apr 7 17:13:27 2026 Received: from mail-pl1-f225.google.com (mail-pl1-f225.google.com [209.85.214.225]) (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 E90C344D695 for ; Fri, 27 Feb 2026 20:24:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.225 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223844; cv=none; b=Ff31YnZmmD5mO89fAtbTdSHzqFEL3wYMw787EbItmYCjTXhOgYQBQNN+7QTp91R6c27DAPwwbl1hBXfhZcEXOopX1cXMRzN0deFpbHnBRdiJA0qaaBB+z1xSAw2B4PAi46yOhheQWmMdfxWqWYBxcBpwof8soOmGHQewIrXCD34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223844; c=relaxed/simple; bh=rEgUCflMnbP+oeHSg611GJ51AOMqm3sC9AviUd3En14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gOe/6ZjGgGrC8EPslSdREYIVwrPLUIGEI9IK6CUMzQ1FSUdSO36sQBPdLMfhgRCKOImLd6IvXkleKQTLYZZ8huRX5LZ2wyMkCFKkG5CWwqKW9ETLmFwY/gUfKjv6GKdjY/7XgBB8SPTi6ElpAwosxlr84rp9VdBbzDQp5sOa2oU= 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=ANgIqAN6; arc=none smtp.client-ip=209.85.214.225 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="ANgIqAN6" Received: by mail-pl1-f225.google.com with SMTP id d9443c01a7336-2ae3a007bd1so20775ad.2 for ; Fri, 27 Feb 2026 12:24:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1772223842; x=1772828642; 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=lG8nfg+ASIKQ9CbyoNXjrLj+myT10j8TFxZs8gb+75o=; b=ANgIqAN6wlGFvpSZlpia95mQqlcsb6eDAZNoBVos6YzGuqMgtG2jHEst0+Ddwmwao2 hxZ9hE1VLmleGnjkNY4oF/pBTrLl9SPrYbLqx27RqZiYnMGJ2sZbvWqT2JMcn8S9Jbcq ty0UqB7gXaG0YenH7m2/27PmOJ6qdi3Ke6e4iUztZBzhFvRtZgMIiIzlvyZPQI4qa1Ir k/3iDxcAKXMeTHFmaisNFP609PWBez5Z2UYcfCTrkCrEKJhV2NAMpLct0O6xLUK+x3Jr H7QElx72ziPWjvBmGIQ92B2p+ZnzelE5B9H6BKYm6FGq2d+GPXbeGiSmEJTqs7qapJsZ mFig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772223842; x=1772828642; 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=lG8nfg+ASIKQ9CbyoNXjrLj+myT10j8TFxZs8gb+75o=; b=JO9AaMeNpxwg67vTRbb8Eb7+mwpKE5E+Zje2iBMYoZlupU6LJSH0RiIsuqxN3dKFz1 lgotWp07Kb3sV9fO8bXw6WLUwE/9iEfruN3wYoWtj6z3JxuVvO0TPuRrBENg5XY/4Cd5 T+D3rJ/s3IGsOR9XYls2ABK4oX6UuTAX/H9N/MmX5uORyRICQkxFS7uT1ydIEhwIvKQr JLU4o1kcn3VkGOHJu0DW0RxlxFh9kooxhN+sCcjT7HfVEwM0MoMfw65l7Lru1pjzqjbg p5dPoH8fu7JMjNqiMb0Xj5FQ8Y2BOhrdaxdvAah5hJ/DLdcLVrxnn8rjpbV62Ct/QPw8 69/w== X-Forwarded-Encrypted: i=1; AJvYcCWRiYul6XxnBjr0q78njafyRBIvb87ywnSB3wm7IuOQryic6St7GOq447qIb2eaHWfcrGrX5DVZS7MMxdE=@vger.kernel.org X-Gm-Message-State: AOJu0YxqK5IQPcKI5UUwPDm0EXmTsnG65iJutArsBSdLZxzqhylvKpmf uXUsUM/UBfTB6RocqLQy8E28OedYM+ughLZg4A5GDGz9fbKBgsPpngVfBSkc9z1JBK0qdKzg50Z CmJpLs/Elw21qca5l4TZO+BSMciNQ87tz3SnhW7eelyY9Dk9Grsdi X-Gm-Gg: ATEYQzwQdkvx35ETk8Ib7btfQ4cM1NWVCIF1Av7XaPiQmz+I+5IDValkDjQ23CvWsrJ 86vEAbmglgDEFRG40jxlOcD3WVp9FtK8blsOTTnIn09wW7XN0HPob5eot01HPb8KFtS+hlk8+tz dRj77CHQE/XC6FELvXN2iRqUH/FgJljWk4wg5W8jvB12bwu8cfBuL5EgjZPxk1qbQ/3EdqUnjue iA826vhd73RL74ITFoX4VgCpqZnm5qzGibqfruZMuGtyfKapN5dExwMyOMujXRkxpEguy7PCP/n dcNHZOuhKjUwqShqzpHdXdi5j4ruuVx4PM5kIJmFreW+1TnKdmnOLKbtIH18Auo7BgeKAKNlcVY AD8kRYd1m27qIHiykr3BLh3pGVFurJh/JAbDCZ6g= X-Received: by 2002:a17:903:1c2:b0:2aa:df82:ed85 with SMTP id d9443c01a7336-2ae2e3e3cbdmr29408695ad.1.1772223842360; Fri, 27 Feb 2026 12:24:02 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([2620:125:9017:12:36:3:5:0]) by smtp-relay.gmail.com with ESMTPS id d9443c01a7336-2adfb5fbd8esm7393695ad.47.2026.02.27.12.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Feb 2026 12:24: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 0D1E3342295; Fri, 27 Feb 2026 13:24:01 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 05ED6E420D8; Fri, 27 Feb 2026 13:24: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 v5 5/8] nvme: add from0based() helper Date: Fri, 27 Feb 2026 13:23:50 -0700 Message-ID: <20260227202354.1012322-6-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260227202354.1012322-1-csander@purestorage.com> References: <20260227202354.1012322-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 NVMe specifications are big fans of "0's based"/"0-based" fields for encoding values that must be positive. The encoded value is 1 less than the value it represents. nvmet already provides a helper to0based() for encoding 0's based values, so add a corresponding helper to decode these fields on the host side. Suggested-by: Christoph Hellwig Signed-off-by: Caleb Sander Mateos --- drivers/nvme/host/nvme.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 9971045dbc05..ccd5e05dac98 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -760,10 +760,16 @@ static inline sector_t nvme_lba_to_sect(struct nvme_n= s_head *head, u64 lba) static inline u32 nvme_bytes_to_numd(size_t len) { return (len >> 2) - 1; } =20 +/* Decode a 2-byte "0's based"/"0-based" field */ +static inline u32 from0based(__le16 value) +{ + return (u32)le16_to_cpu(value) + 1; +} + static inline bool nvme_is_ana_error(u16 status) { switch (status & NVME_SCT_SC_MASK) { case NVME_SC_ANA_TRANSITION: case NVME_SC_ANA_INACCESSIBLE: --=20 2.45.2 From nobody Tue Apr 7 17:13:27 2026 Received: from mail-qt1-f225.google.com (mail-qt1-f225.google.com [209.85.160.225]) (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 33DEB44E021 for ; Fri, 27 Feb 2026 20:24:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.225 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223844; cv=none; b=Mit5RD85bRGlfA2qQQv70YK5frRCJAwtSrHr8DbjXleaR+w8DPtyUPfc/03UHgKdNcdyACfljEbrIodrGJIWsC9ebTptkWZ/andbKoFw54Pf7OY4e+I9/nBSH/6yUpAENjSUX56XQJUiwFIPms170hkXK5yp1gfOe6yXlOvylP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223844; c=relaxed/simple; bh=hO0s5OqilGDwSrUO+RiUJPS4++YRTj8YqVZzKZINga0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VfS7ZGJJ9poXPggE7YbRVWuaR/QRTaTBqGEL8Llc5Gb+WGPEHQBJoxQTuu05mndOlsG1k9jpzT7Br02U45mWskHUM437ogYDrf5RLsL5RorFyYPzJ94w2KEXqbqqApp5bK6+y1StGS2NiAc2/rADj+0XG9NgZu32+9PaXL3WapU= 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=ewtQ4h/R; arc=none smtp.client-ip=209.85.160.225 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="ewtQ4h/R" Received: by mail-qt1-f225.google.com with SMTP id d75a77b69052e-506a65d8698so2392891cf.3 for ; Fri, 27 Feb 2026 12:24:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1772223842; x=1772828642; 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=molQjRNkREdyjvwmEw0xTnEivvMWYPvHvzLTsL4IEEk=; b=ewtQ4h/R45DWTlLnOSABO0/S/M/HnK4fzH1XgxDX2trCPBmOgSYlyycqBwKncG1ddb xqF+7Fnu86+5kOOOlAw4JA229s94Rx3+0rnuxl9q5ZntPqx0RE7vJ3PGeGU+v1WRt9i/ Wp72702dclWNMLyjY1MVIcbdI89SG+7CPDrkykaHe4vBUgDQMIDJ6tJApcae41iMq5VN tKWI8X+ysXf4koxiZu4fo82tNm/m5mV60581Lca+xPEhGf24+94cnDuHvptHQJkYLO7+ QaO2JNJbc6faDrf6kS3hJ2EJ0H/9pyoV/SXa8QAXaxDFhqbJWyoB2sXZ8/kIXHN+3gEA f+Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772223842; x=1772828642; 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=molQjRNkREdyjvwmEw0xTnEivvMWYPvHvzLTsL4IEEk=; b=ObvbwXCN96vxpOlAR0u8ZqLgSGbT5le3YuWYBWdaxu+/kFKdD6eIudxbRSwRfiYTz2 7hT11xpY0u6GArtNSMe0WZuYR0++/o4VgPMiYAIg3IEyHvO/5rMJ+lObfvQXLJEA8ZyF tvk/6eNNEwySfA2CAkm6+4r15GU9irsrjffSydQQ+q3icxWwU0JOvXWOQ/lHzHL+Iyx0 kG992m5SE98pAAlKlTkMVcL3Wphuk25wAgEzle0xeHLV8+lReNsKndllJg3BXjOvwg2w BoUvjk+sUWw8aM27SAjtvgovgk7hiSFHYGngXbjloMBJrY7zTr2+DGPRLmWlD/5T9NGW g1Bg== X-Forwarded-Encrypted: i=1; AJvYcCUGB1coV5jxmc1EbQq+L5U5O2Ctl86Gb4Z/U9WuFCo2yhLyWYTQ/L+JanR8AddUp61AHNlxKRIu9MJiqG4=@vger.kernel.org X-Gm-Message-State: AOJu0YzW9xEryLCPE8o67qo0p11AVSKckvnv/rQ7I8JP4v6C9NtNiQti Yk9CPQzgv8P4G8H4WJoKTFx9VYdh6NfDEPYGtoN5YpgOoGZQfDDtfANiJloGb8zUhpHhvPIJqYS iYjREh8G7cVwPrwTk6pFmbszJ0761GD5fVZmW X-Gm-Gg: ATEYQzzbsm2cdDaQetkNnuAJyLAdo7fk2rLUyAgz8ck492MjU/uGS3JVEin5BpqS4kc 8MYLvvLVwP+dckZh5VV2OmCKhz0+lii2yfH3BzKIufFFWQfJbyjOP2ycVsWMvdWv7knlQFspu3y Nwa0c9xavHCgMXG23PzOzJy0u8YSDSGfhBbhSyD42Zb60K+1KDCoxeIXWjhUHqOtKDNrsi2qt+i nPleRPxBpT0Jaq5EU+nsl7oFrc+YzbBRhbaA94oPcBzsbc7qR01e6xKWdAaDOexkSs5ekqrH5WB 4aPhdQzG7oMjztz6zpUeKqRlRIr6eVAtvC+ESVoLOml9pw1CYNG3UewdgYT5GLe62NFkli+LebN aou127v6L0ilVxLvUSoJS4NsCD9lSe+qjrZkcDKaYHnTPNjDcYYdYhA== X-Received: by 2002:a05:622a:1907:b0:4f1:dffa:7834 with SMTP id d75a77b69052e-507529a2b84mr38843961cf.7.1772223842069; Fri, 27 Feb 2026 12:24:02 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id d75a77b69052e-50744a369d9sm7627921cf.5.2026.02.27.12.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Feb 2026 12:24: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 34BF93422B0; Fri, 27 Feb 2026 13:24:01 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 2E4D4E420D8; Fri, 27 Feb 2026 13:24: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 v5 6/8] nvme: set discard_granularity from NPDG/NPDA Date: Fri, 27 Feb 2026 13:23:51 -0700 Message-ID: <20260227202354.1012322-7-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260227202354.1012322-1-csander@purestorage.com> References: <20260227202354.1012322-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" Currently, nvme_config_discard() always sets the discard_granularity queue limit to the logical block size. However, NVMe namespaces can advertise a larger preferred discard granularity in the NPDG or NPDA field of the Identify Namespace structure or the NPDGL or NPDAL fields of the I/O Command Set Specific Identify Namespace structure. Use these fields to compute the discard_granularity limit. The logic is somewhat involved. First, the fields are optional. NPDG is only reported if the low bit of OPTPERF is set in NSFEAT. NPDA is reported if any bit of OPTPERF is set. And NPDGL and NPDAL are reported if the high bit of OPTPERF is set. NPDGL and NPDAL can also each be set to 0 to opt out of reporting a limit. I/O Command Set Specific Identify Namespace may also not be supported by older NVMe controllers. Another complication is that multiple values may be reported among NPDG, NPDGL, NPDA, and NPDAL. The spec says to prefer the values reported in the L variants. The spec says NPDG should be a multiple of NPDA and NPDGL should be a multiple of NPDAL, but it doesn't specify a relationship between NPDG and NPDAL or NPDGL and NPDA. So use the maximum of the reported NPDG(L) and NPDA(L) values as the discard_granularity. Signed-off-by: Caleb Sander Mateos --- drivers/nvme/host/core.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index c3b24fcb2274..84d7dad4aeed 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2055,16 +2055,17 @@ static void nvme_set_ctrl_limits(struct nvme_ctrl *= ctrl, lim->max_segment_size =3D UINT_MAX; lim->dma_alignment =3D 3; } =20 static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *i= d, - struct queue_limits *lim) + struct nvme_id_ns_nvm *nvm, 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; + u32 npdg =3D 1, npda =3D 1; bool valid =3D true; u8 optperf; =20 /* * The block layer can't support LBA sizes larger than the page size @@ -2113,11 +2114,39 @@ static bool nvme_update_disk_info(struct nvme_ns *n= s, struct nvme_id_ns *id, else if (ctrl->oncs & NVME_CTRL_ONCS_DSM) lim->max_hw_discard_sectors =3D UINT_MAX; else lim->max_hw_discard_sectors =3D 0; =20 - lim->discard_granularity =3D lim->logical_block_size; + /* + * NVMe namespaces advertise both a preferred deallocate granularity + * (for a discard length) and alignment (for a discard starting offset). + * However, Linux block devices advertise a single discard_granularity. + * From NVM Command Set specification 1.1 section 5.2.2, the NPDGL/NPDAL + * fields in the NVM Command Set Specific Identify Namespace structure + * are preferred to NPDG/NPDA in the Identify Namespace structure since + * they can represent larger values. However, NPDGL or NPDAL may be 0 if + * unsupported. NPDG and NPDA are 0's based. + * From Figure 115 of NVM Command Set specification 1.1, NPDGL and NPDAL + * are supported if the high bit of OPTPERF is set. NPDG is supported if + * the low bit of OPTPERF is set. NPDA is supported if either is set. + * NPDG should be a multiple of NPDA, and likewise NPDGL should be a + * multiple of NPDAL, but the spec doesn't say anything about NPDG vs. + * NPDAL or NPDGL vs. NPDA. So compute the maximum instead of assuming + * NPDG(L) is the larger. If neither NPDG, NPDGL, NPDA, nor NPDAL are + * supported, default the discard_granularity to the logical block size. + */ + if (optperf & 0x2 && nvm && nvm->npdgl) + npdg =3D le32_to_cpu(nvm->npdgl); + else if (optperf & 0x1) + npdg =3D from0based(id->npdg); + if (optperf & 0x2 && nvm && nvm->npdal) + npda =3D le32_to_cpu(nvm->npdal); + else if (optperf) + npda =3D from0based(id->npda); + if (check_mul_overflow(max(npdg, npda), lim->logical_block_size, + &lim->discard_granularity)) + lim->discard_granularity =3D lim->logical_block_size; =20 if (ctrl->dmrl) lim->max_discard_segments =3D ctrl->dmrl; else lim->max_discard_segments =3D NVME_DSM_MAX_RANGES; @@ -2380,11 +2409,11 @@ static int nvme_update_ns_info_block(struct nvme_ns= *ns, ns->head->nuse =3D le64_to_cpu(id->nuse); capacity =3D nvme_lba_to_sect(ns->head, le64_to_cpu(id->nsze)); nvme_set_ctrl_limits(ns->ctrl, &lim, false); 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)) + if (!nvme_update_disk_info(ns, id, nvm, &lim)) capacity =3D 0; =20 if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) && ns->head->ids.csi =3D=3D NVME_CSI_ZNS) nvme_update_zone_info(ns, &lim, &zi); --=20 2.45.2 From nobody Tue Apr 7 17:13:27 2026 Received: from mail-pf1-f227.google.com (mail-pf1-f227.google.com [209.85.210.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 4FAC14508F4 for ; Fri, 27 Feb 2026 20:24:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.227 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223844; cv=none; b=c1AO+uYrzuZKlqtpQ4wuvfqoZMotiCF2DcQRDE9ucmm+MU7ygzY5+ASc5egfg9MnqwCfJ+qyyvS7Lqf+jqM/fu+j5VgULYPgrlEylZtYDGryGwa6br7b7LfwiazBJI+hRNl0y5GYQNEtDd5YNMDyjBLV1siHTXH4FVsmY/DsNqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223844; c=relaxed/simple; bh=pBiR297b8PXFueLy2tPMN9uZJGaoOz/0vV31TY2gEY8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sPxH/+sXRt1ed8oyiOtdCTxwkz+zbfhlRv+jcwkscCoJOvCh5W+ZbFpxLqPPb85My7A3S12m7rgiSqi+GwGBjGYh/sjQkBG41IUldnJn3eSHgyMms0YyTz4ulJASF2K1TaI6xPwgK3JOjbSX/T3TfbfIFXzAnY0HA/G8PDB98aU= 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=Iea0VyNE; arc=none smtp.client-ip=209.85.210.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="Iea0VyNE" Received: by mail-pf1-f227.google.com with SMTP id d2e1a72fcca58-824ba13c49eso122624b3a.3 for ; Fri, 27 Feb 2026 12:24:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1772223843; x=1772828643; 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=chF3cAD1j09EpR3bM9lUaumkQDJZpAeYYRmoTp9QLII=; b=Iea0VyNEBt5PczWVYi4LbPzxq19ycIp8AgfL66mtEsjm9ipslmP4kqP5T61zu/J+V9 LXGMTHx0AzkssSO96DDO+aKsav02ZlwpX0cuW/2GnyV3D+9DqzJENbfsvQgqr7deY31q YY71WKC5HyXlt6s0MrMBbmWGu4Dye+suoViElYnLsmhQLDvGl+B0z2gkwVtiNqEIG4Tv uZJz4GSR/nGGLDjA9BDAdXR9GvRLGZRpWXcZCMwichpcJkNuOXAhI0hdyTPJZDVbUJfr iMbsVlGiIoVcDbiHZ0k7sMVTUQwbsdIlEtIPaHnAiDAYECTbIeHzyON9iL8a1J6Tg2vC VBHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772223843; x=1772828643; 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=chF3cAD1j09EpR3bM9lUaumkQDJZpAeYYRmoTp9QLII=; b=Z74Vwmd4Mym5YjbGCKLOGk5MYypmaOjobtX9aBk7Qt4lrFxH0ae++m0GVTczMT7nFl FAqX9Na1kW/qRwf4/hiXMCa/A4kWn/znqoRKVlTvTxw7NsbFjpMQwOpRZxA58fIaPxOm fM2lNGChBEcKup2faJkEE0stS7AKc4mfaUkOjg9MPuZCq4XZ+VKWrZhN/JIQHLSwYz81 bJSaAO6sNljiNOgkulbpyS8zLEWh+eha040zEHS6xkIuy57XV3pOI9yCAyT1trbEWUl0 wDSvcXlL1a46LQJHEA/tdNfng6qHVXJEpoMO1nRMngxJoEAwOpn/V8E1l4fXCODgw/f9 INMA== X-Forwarded-Encrypted: i=1; AJvYcCUuI09BM9bw8uy9PHTIvpef0OxQ5bOZLpyMoow4xbkhmqpqtxE7m3eStJ7Kd+FMqLVwV5rx+DD3omqh1Ng=@vger.kernel.org X-Gm-Message-State: AOJu0YxGvlHlqb+84WmJv4oDbLgTq4FMnd8h9JuRMZ3REKjtyJM8SN3p mGvOft+mYiziuEdiveI1VA5iZ+6ljGxgV5xJ40Oho3S2osjGIl/M4VlpMlh9qwZvpzJnhsTnO+7 HhfWPO9a0w/RRu/DpHjqWcWuLrTDsHSJ07FG6 X-Gm-Gg: ATEYQzzdqD4+IuLnEYUgWCozuaSw0JUmw8+vAjGJMsyOgyjioMJiTP0D0JDBM0Hy6E8 PIjiRon0qaOVZU4kxkcLk4H6/UN/xuFOCEIiOG5SXYo2+dw51CY8jrD/xxj9MNTMUi4jXx5MQdL zq4POv7NYF5RVXnPmJRLAblkj2xKjOTHhelNqAykNqf224X/13hEI6lLyAeX7WLgZz2JT9LX3aH c3itP17wIgzegjt1v0fh2sh4aaaxhbVhJwydz0ZjUlss1g23uJFW6wqdnhx1uz37pD+QCJ3L1Me ROYnRm3U17bJwGxhaaTx+XGQlj73/45FJgdXrtCFnbCnxGLntLRc+NHrtKlR2gZ9/fb8NjWFF34 4kRKMmFBcnrQoGUjldU4jZ4kAjskbXMXxVWRyLleUNhxaYHqLM3PVGg== X-Received: by 2002:a05:6a21:6d88:b0:38b:e7ca:9517 with SMTP id adf61e73a8af0-395c3b422bamr3131161637.7.1772223842730; Fri, 27 Feb 2026 12:24:02 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id d2e1a72fcca58-82739d70643sm670497b3a.3.2026.02.27.12.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Feb 2026 12:24: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 5A9693422C9; Fri, 27 Feb 2026 13:24:01 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 543BBE420D8; Fri, 27 Feb 2026 13:24: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 v5 7/8] nvmet: use NVME_NS_FEAT_OPTPERF_SHIFT Date: Fri, 27 Feb 2026 13:23:52 -0700 Message-ID: <20260227202354.1012322-8-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260227202354.1012322-1-csander@purestorage.com> References: <20260227202354.1012322-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" Use the NVME_NS_FEAT_OPTPERF_SHIFT constant in nvmet_bdev_set_limits() to set the OPTPERF bits of the nvme_id_ns NSFEAT field instead of the magic number 4. Signed-off-by: Caleb Sander Mateos Reviewed-by: Christoph Hellwig --- drivers/nvme/target/io-cmd-bdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd= -bdev.c index 8d246b8ca604..d94f885a56d9 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -28,15 +28,15 @@ void nvmet_bdev_set_limits(struct block_device *bdev, s= truct nvme_id_ns *id) id->nawun =3D lpp0b; id->nawupf =3D lpp0b; id->nacwu =3D lpp0b; =20 /* - * Bit 4 indicates that the fields NPWG, NPWA, NPDG, NPDA, and + * OPTPERF =3D 01b indicates that the fields NPWG, NPWA, NPDG, NPDA, and * NOWS are defined for this namespace and should be used by * the host for I/O optimization. */ - id->nsfeat |=3D 1 << 4; + id->nsfeat |=3D 0x1 << NVME_NS_FEAT_OPTPERF_SHIFT; /* NPWG =3D Namespace Preferred Write Granularity. 0's based */ id->npwg =3D to0based(bdev_io_min(bdev) / bdev_logical_block_size(bdev)); /* NPWA =3D Namespace Preferred Write Alignment. 0's based */ id->npwa =3D id->npwg; /* NPDG =3D Namespace Preferred Deallocate Granularity. 0's based */ --=20 2.45.2 From nobody Tue Apr 7 17:13:27 2026 Received: from mail-pj1-f99.google.com (mail-pj1-f99.google.com [209.85.216.99]) (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 6BED8450901 for ; Fri, 27 Feb 2026 20:24:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223844; cv=none; b=uBICuSt1NVUzquII7xeTCedH4u8Rkk/VOFjDEaCW/iW3kqCGkJjEO7L9Uoqslp+jYzHJY9IqtIk7AowNTvpqDk62NMGbn4rVQGiXpWRbb5AoFLiJQWXLmV8D8Pii0bIbz6R/mMnqGxK/5wjJkd1u4ld/jPr93nHmhE3ZSe9+Fow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772223844; c=relaxed/simple; bh=N0sqrv6nVURelHVA7HFFhzMGt9LzqtMjQpJgL79pyMA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bnzKPPPxWV6CmlIWwdWiSLxx7LMchukeSfVKytSp/VwwtrecXfKKQmPk7xanqR7lMsNTWQVFgpFSrFpOW3tqXX5MaSugpSgCEyZUXi0MZPvf2gvsj9MCDRJFB+GPK1vEWBb5gwzmzZeeWcCNJph7xMKgeTr5B8FDAFxMEyHEfn8= 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=MxBi1RQN; arc=none smtp.client-ip=209.85.216.99 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="MxBi1RQN" Received: by mail-pj1-f99.google.com with SMTP id 98e67ed59e1d1-3590de10358so181376a91.3 for ; Fri, 27 Feb 2026 12:24:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1772223843; x=1772828643; 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=rLGXbc0gXctnroosx2bL2/uz0im7hCkKsBk3ALVli3I=; b=MxBi1RQNrt/cUrroGFen6lvDJ5roqIlIewQP3n0aVHXQ+Zae8jqsMWMZuDQ4craORP tO8PJeEwLVDo+kUDsjFJLsZUN4KdMaZgfSRvnKBbW3n4oh3Hl/TW/ZF6WcKC3YJfAa8I CrmGaHXYOR/PiOcPK87InJr8dks3y3sz/AgsTuhEp6LFlGE82pYi7bXqLfcX2to4SIwR ROcyxqx9V6cT6sI13GZireEOMigyuRv3jr8sT+QWdH5un3mcelnupxNj2o5/UdqepIYo TY3b91VzOVZB4mJaTQkJ1b1lxMKu0rQ42cyrqlZaSPucm1JBwxkPY36DaDwRp3xhI2Lg trGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772223843; x=1772828643; 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=rLGXbc0gXctnroosx2bL2/uz0im7hCkKsBk3ALVli3I=; b=H451NBkh9noZfOYYo4934KITT4CNjtgR0br1gn+h0MgEzWGHELkBt4eX7jYC63hnlZ UvV5wf2M8PBGmNY3aubbCKq01XU55nocJuVw2ItCI1uicCptSTynPJJsdRpkkaAy2DZH jXUQb/zxGn+VIuAS4Axg5Cmk1Qy/wTBpQsx8BN0vnsUfSpAbVK0MNkrwX9vun9FVX92L +1rpWKcv1VRDpiIFdu6BkT+inw9qr9g7KRbSJmiRwWYcWamVwlDOfeQXGEQtiSKQ74P3 en/qRo3kjQJz4TQtKB92InD8Emx2HKCOW9YT2N2VKNN9sgtdtlmanGRZLmqgG387VmB1 xXGg== X-Forwarded-Encrypted: i=1; AJvYcCWBcacRUDqZy9cg07qACo/BFv170WCeHrA2E0ivUisHCGbrPz8yGnro/okIt44Y1u7wA+kc4FLPxhHoX9A=@vger.kernel.org X-Gm-Message-State: AOJu0YwZu1bX5oX+hxnbsGFmqJ4IIVMIBVrg0YEg4QtxVibp+XHnLnks v2uKqwpyYoMI/RGG80lX9a1r4JowU65clAXvSgq0kHqPrmqVjjcQa3echRKcXAjU3FeyQzSJHus j1HH2OR0h/feOntlajnhK6Inrk76TJWVl3w2m X-Gm-Gg: ATEYQzzxS7J0wojkldq9BnN/n9JjAPPReqENVRwsxOa6wm+kVmq0xWZLIjEHYs409SI jnd+AGHTWredYqw8m4aRXY16PFdUIwMGASunyDtLid61qC57fjDASQOuQExoqNaC0WQezaEECXi 5IoY/Iqk/+LBeoo+1tx7dv8gss7jcrVHFDKtiu+Gwjv630j/yopND6HpAiQaL7KFUOli31B2Anh 2lKr8rYP6FPgcYvKSyzTJkvyMq7hwDsuxgz2jWdjdTDZxYVxgvasLy8FdaCZjX87zyYNrcu7ket 7flbgpD07Hv4TPEyW/hcIg3JuQa+h4owEXL+bR4v40lPPOdx8iuWwVyf0WmQaS7eoLuf7beZnNa 0Z9Vvz09NtduON0CWDzgkfK00zEjGabRqoLKZ2t04FOuHvcRjuPhtKQ== X-Received: by 2002:a17:90b:5688:b0:356:1dad:1b04 with SMTP id 98e67ed59e1d1-35965ccbadfmr2604765a91.3.1772223842724; Fri, 27 Feb 2026 12:24:02 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id 98e67ed59e1d1-3593ddfa655sm758653a91.8.2026.02.27.12.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Feb 2026 12:24: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 7ECE33404A1; Fri, 27 Feb 2026 13:24:01 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 782C2E420D8; Fri, 27 Feb 2026 13:24: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 v5 8/8] nvmet: report NPDGL and NPDAL Date: Fri, 27 Feb 2026 13:23:53 -0700 Message-ID: <20260227202354.1012322-9-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260227202354.1012322-1-csander@purestorage.com> References: <20260227202354.1012322-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" A block device with a very large discard_granularity queue limit may not be able to report it in the 16-bit NPDG and NPDA fields in the Identify Namespace data structure. For this reason, version 2.1 of the NVMe specs added 32-bit fields NPDGL and NPDAL to the NVM Command Set Specific Identify Namespace structure. So report the discard_granularity there too and set OPTPERF to 11b to indicate those fields are supported. Signed-off-by: Caleb Sander Mateos Reviewed-by: Christoph Hellwig --- drivers/nvme/target/admin-cmd.c | 2 ++ drivers/nvme/target/io-cmd-bdev.c | 19 +++++++++++++++---- drivers/nvme/target/nvmet.h | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cm= d.c index 3da31bb1183e..72e733b62a2c 100644 --- a/drivers/nvme/target/admin-cmd.c +++ b/drivers/nvme/target/admin-cmd.c @@ -1056,10 +1056,12 @@ static void nvme_execute_identify_ns_nvm(struct nvm= et_req *req) id =3D kzalloc(sizeof(*id), GFP_KERNEL); if (!id) { status =3D NVME_SC_INTERNAL; goto out; } + if (req->ns->bdev) + nvmet_bdev_set_nvm_limits(req->ns->bdev, id); status =3D nvmet_copy_to_sgl(req, 0, id, sizeof(*id)); kfree(id); out: nvmet_req_complete(req, status); } diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd= -bdev.c index d94f885a56d9..485b5cd42e4f 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -28,15 +28,15 @@ void nvmet_bdev_set_limits(struct block_device *bdev, s= truct nvme_id_ns *id) id->nawun =3D lpp0b; id->nawupf =3D lpp0b; id->nacwu =3D lpp0b; =20 /* - * OPTPERF =3D 01b indicates that the fields NPWG, NPWA, NPDG, NPDA, and - * NOWS are defined for this namespace and should be used by - * the host for I/O optimization. + * OPTPERF =3D 11b indicates that the fields NPWG, NPWA, NPDG, NPDA, + * NPDGL, NPDAL, and NOWS are defined for this namespace and should be + * used by the host for I/O optimization. */ - id->nsfeat |=3D 0x1 << NVME_NS_FEAT_OPTPERF_SHIFT; + id->nsfeat |=3D 0x3 << NVME_NS_FEAT_OPTPERF_SHIFT; /* NPWG =3D Namespace Preferred Write Granularity. 0's based */ id->npwg =3D to0based(bdev_io_min(bdev) / bdev_logical_block_size(bdev)); /* NPWA =3D Namespace Preferred Write Alignment. 0's based */ id->npwa =3D id->npwg; /* NPDG =3D Namespace Preferred Deallocate Granularity. 0's based */ @@ -50,10 +50,21 @@ void nvmet_bdev_set_limits(struct block_device *bdev, s= truct nvme_id_ns *id) /* Set WZDS and DRB if device supports unmapped write zeroes */ if (bdev_write_zeroes_unmap_sectors(bdev)) id->dlfeat =3D (1 << 3) | 0x1; } =20 +void nvmet_bdev_set_nvm_limits(struct block_device *bdev, + struct nvme_id_ns_nvm *id) +{ + /* + * NPDGL =3D Namespace Preferred Deallocate Granularity Large + * NPDAL =3D Namespace Preferred Deallocate Alignment Large + */ + id->npdgl =3D id->npdal =3D cpu_to_le32(bdev_discard_granularity(bdev) / + bdev_logical_block_size(bdev)); +} + void nvmet_bdev_ns_disable(struct nvmet_ns *ns) { if (ns->bdev_file) { fput(ns->bdev_file); ns->bdev =3D NULL; diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index b664b584fdc8..3a7efd9cb81a 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -547,10 +547,12 @@ void nvmet_start_keep_alive_timer(struct nvmet_ctrl *= ctrl); void nvmet_stop_keep_alive_timer(struct nvmet_ctrl *ctrl); =20 u16 nvmet_parse_connect_cmd(struct nvmet_req *req); u32 nvmet_connect_cmd_data_len(struct nvmet_req *req); void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *i= d); +void nvmet_bdev_set_nvm_limits(struct block_device *bdev, + struct nvme_id_ns_nvm *id); u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req); u16 nvmet_file_parse_io_cmd(struct nvmet_req *req); u16 nvmet_bdev_zns_parse_io_cmd(struct nvmet_req *req); u32 nvmet_admin_cmd_data_len(struct nvmet_req *req); u16 nvmet_parse_admin_cmd(struct nvmet_req *req); --=20 2.45.2