From nobody Tue Apr 7 18:45:35 2026 Received: from mail-pl1-f226.google.com (mail-pl1-f226.google.com [209.85.214.226]) (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 9E39144CAF0 for ; Thu, 26 Feb 2026 19:04:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772132673; cv=none; b=g9ivpXmlxEqLzLD/bmQ6o4VOLD8d9fbIxtFb/xfYzrS2p+7Kj5FE3qaAlDOc23lP7p7nSyd//j4udXrWTDu6lLxavA8HlFCg4oHNAN/9IszRxvuFvW7F7ihZPBxGHgLeN549QB/M1743a6fbGU8cJ9l/eZoFRmRFKeR+krzgPk0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772132673; c=relaxed/simple; bh=N0sqrv6nVURelHVA7HFFhzMGt9LzqtMjQpJgL79pyMA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pGy+ZPWTpuF8ADD59AjwO8I5OBVdpHyzc4uMkH1ZVqwv9nvlXLoKmmqJtIROY1Sue87tcZx1lFsPakuYDMc9JMxz4Iwhot+LTW8tZ1eUeBgwAzVdE744iCrHrEHwHcAiH/BDZRnovgoShXjqBkLHPwI20m5+krTevW7q7uJ0PCY= 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=IsM3RDI9; arc=none smtp.client-ip=209.85.214.226 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="IsM3RDI9" Received: by mail-pl1-f226.google.com with SMTP id d9443c01a7336-2a8720818aeso1525475ad.1 for ; Thu, 26 Feb 2026 11:04:23 -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=rLGXbc0gXctnroosx2bL2/uz0im7hCkKsBk3ALVli3I=; b=IsM3RDI9rAw8Qefgu0n/ibib5ClUMpXXLdRoA1WG+hyD7BB8UC8rB5BzOmh6vpSreN /ummb/gFLg3GXO9PZXEHYlu0L1Dc2szDwb2gfuOk+Qu2wBwWEZU987bjr1Cp0Hij3bHO liuj0Z9SKI25MvaRIlQTPIA2VmVvw78MXLiUWn7UFlyoFnRpCPeybcXPKOPi8mgi9muT n/ywxAHA5sEafx/ZxCCRIceLOn1kry1qny9xnx8EtpKIesGoLdEXyYd5MsAPNEIDJwgy 7thJ3EfUdBNcksuVo4VyYiKg4N3jY1+eLKAkOKtullQMTzXOlhWZD7i8BzV3ott/2Lel OZYw== 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=rLGXbc0gXctnroosx2bL2/uz0im7hCkKsBk3ALVli3I=; b=o2KsYZ6gEbBCkU++AwArj5Y8q4kLzFbVcMyxA/eCBvVWFdGgRLUGbyL6tRdwB+jW3u fopKxke8V6XtXaAziKarAJI81H6RysM+cr+Vt8IaC8irrbAmWxL6tMqj1Zci9rSYNsY9 luntc1I4LlzL+GmgCkW8rtElsgXJiWa7w9JH2v418lGBIECz9Fu0fJgNFFh5Jpu4pVHH IVlMzl7h7u2H0iUzxt7qLdttnuqfgCnwNwjMImxUvV1UCZjXLa6SeD4+BH0yk8DmnmM9 KxGS7qG/JA+nJVVAZwB9H4UutYe7eF3fOSGFR+2u13SyeVEepF8rCkmFX6iiIf3dy0KG syxg== X-Forwarded-Encrypted: i=1; AJvYcCVa7TRjGh2++dW+JIW5pewhKvb4n8Wb8HNLfpT7OeunjX7dsahp8u10jA0QTkxDzhKRJjDiEYRPRAasiPQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwddZEtg8C2atssDQSrlJPFE1WpRlIvcJw04S+DDeA8wJH56xC2 XEwc6YjMn4nAhYacpatvpnGWgMdxs31ZbnZVReykQdkhGDfmKyJeE5q5YBkuxNCH+oxx9KfHd5P GvdQmeaHneEUr36bvR2IBxeOgj3CaX416UFH3Cp8Gj0OrpCuPIGU7 X-Gm-Gg: ATEYQzwOcvATKMZtI9nGpuCUBkLb1YKDWdY+fj5KYbJ844a8xqqZAB/qC4k2P/yWR0P 2BIzjymKfqF8Qcz3UGpyG0xjd5kves+Zexm4TJ6u8yVDHrOckuRV8PQzyq80ghdLYeLwa2LTQlb 6YXpO11no1Kn0r+OI39oxmTR6fvrlEz7B/ej4Q4uYIs/UBH0uWxvzTFDbBd8Ez9IICkgwbEEefb Ik7Hh9YeDdYUk45RWWg2ZZQq1yMuKfBCCIcgSOReBhxWWMC5OJo/TSZeEpdSOKzEUrfnNvYitxH DTWhXu5PWZX5M5qr4JHVNe+UnGcNj1QB7FfgCCA4asLcg6cUmald/p/zPZYQcQtBQMq0KUjz9aA 5lpyqWZYqAtym978g3hKYz+IQNi6/vs/KA5O3mNo= X-Received: by 2002:a17:902:ce8b:b0:2aa:d1e1:29d8 with SMTP id d9443c01a7336-2ad745690d1mr144139165ad.6.1772132662194; Thu, 26 Feb 2026 11:04:22 -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-2adfb61600asm3394745ad.54.2026.02.26.11.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 11:04:22 -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 19AAA3402EE; Thu, 26 Feb 2026 12:04:21 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 14BBFE41254; Thu, 26 Feb 2026 12:04:21 -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 8/8] nvmet: report NPDGL and NPDAL Date: Thu, 26 Feb 2026 12:04:15 -0700 Message-ID: <20260226190416.297725-9-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" 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