From nobody Tue Apr 7 18:45:28 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