From nobody Sun Apr 5 13:04:13 2026 Received: from mail-oa1-f98.google.com (mail-oa1-f98.google.com [209.85.160.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 55B902BEC4A for ; Fri, 20 Feb 2026 03:28:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771558099; cv=none; b=UgTpYJvr0mQa3+Q/1DMA4OOwKoUF7HJ13AGqeAhiW9rdZWqzjyDrTRo7FCW0VgwJLg2YYf/oXjRL0VcMZq6/Z+js/l/rP+mEojzNIjQrRUJkl3jasxsnt8/sQZaZ7dvfQWipfjjkBl39EqPHvXKtrWRjIXZLmXC/iZRYD+YL0Pg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771558099; c=relaxed/simple; bh=LV5733WF2Amrq7TZbrAkujCFMKLuo+5jXT+GVMP94K0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YmYvA98Z1NfROxX4nmYZaSv7gjGmhf1XoFXkqU6Xe8Jh7ypkNiIWKGKFqyCrfbGql4iWPnUlXq3p8rhHXIjEhMLKJ+eKGNCBJ9xeV/8nIHtLJn8xnTybAUaXVFj06yw0yYxXg0ldoLfozbvsJMJ2PHlhHgFamwbf2xPhfnfFTkY= 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=EFqfsL0C; arc=none smtp.client-ip=209.85.160.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="EFqfsL0C" Received: by mail-oa1-f98.google.com with SMTP id 586e51a60fabf-41392f596ceso128155fac.1 for ; Thu, 19 Feb 2026 19:28:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1771558097; x=1772162897; 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=0AEEfE6xiusQnEvNeZM84fhKgvDhfLyCCrKC1bZTQl0=; b=EFqfsL0C9MVVvBbhjZKBsOFHowWb9ng/t4B9UHS/LIwhfa6PYcJb/qdmQyyvqYNino tNbviuyR+b4fx4EtIhU8jhfIVpEea4CHQQJiG+M+8pU9IeBp/I+idK9mb85M6l5LUZok NiAqGV2bkLMybxGL3v1gaUHsVMngAYGZrh2tPXzuk2la2Fdtt2/ieRDBEOWRWO/BQfql T1RjZkMSQiMB7ewMLfF353/zu9cGp/TeEnHiVbINgOZ2msxBsw8la6ZZ+QgcvmNUpyiI C2cZ4BlsHaIJf2fMzpOmTehVUoCX0mW9zIlLkxvc0a1ESIXad++n8zdv8HVdGId9RjTZ TljA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771558097; x=1772162897; 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=0AEEfE6xiusQnEvNeZM84fhKgvDhfLyCCrKC1bZTQl0=; b=N7axRCZoYxxlxnpOIkbfAgEogXBfpdLiozddwf9NBk01n3dR3Sgfcqog1SnhXjnxbF 3gTqFvLoJX2OpArk7VPzEj06P/ZigIBz09vcHwazmUx7FxCOw6wSgYza/1LcCHsm5cgu LhSkYYpoL2+TMXarMYLRJ9mK9bJPKXaj87YBvR3nKAHoguVLlB2au9EVIgbL8g2yeDjN bUzA5TtaUZXu8ysEXmc0u11vENaSI2/jDb2F4YMy/3JGchjLXKf4gbuWiEIlrRtIwQ6Y HQOi1+4StI4Dy85rbPgAa0eTso6Nf/TyoMxuu/LoDoWU7d2VlnD+PqTGVNtSYl2l4gCN YV0Q== X-Forwarded-Encrypted: i=1; AJvYcCWJoSewlZru067mY3KLo+gYLDDvcBXXSDMESRf/D93hLEbAHeUQ/Drl0evVasRnLCdAFM27yVUnGSqiPWo=@vger.kernel.org X-Gm-Message-State: AOJu0YzrJcUtWJkrF+ndgAsqV434RcYAIBN2c1bMIZTn8vdvk25SUrTb SEGRR2HxTb8D35LbJwgr+IpDp0pXS/ks/LgvIFzCjtYU+ISTrjy4vMXW4ldn10JFtKzALrXI19T dwgTXGINzIuvdZpmQB9F2wtoqtfsCAbKeavyE X-Gm-Gg: AZuq6aJMOPsQVPN1tH5EiL1AI6W8vojeC+6HNAQ66zPD7PBgmHMPDp6mot+zz7rJpJO Z8Wm+ZHs+M+X2dJQMDoSMwCVfaVcmEYD64G+fvXITZaPPSW7yxYaciLsk3sxbxkq8QIxg6HNOlx k78MMTK6QeQTD5uOo6MeIRmdJ2btFi2ZNknZsiEk82qFxdHgBdC6kABiQUUgVTBWW1H0pLGygC7 r9Qm86LIx8BwkzXUFC0oUxdup2v5vtir7XVn2CGT6HL0gWR7fHurp1Gzt6E4Sm3Xav5n2fe9p/l gB9aiYdpSCKkJXkyeMBxTW+aen3C7x0JdjbyujalC6WzP8irm8t1Y5HIY1SimP1liitm7r5IoQk CQC7c77tTUkUq1kRqC49HgXYy3KuGC7DHC2l1mmEMinySMIK4ApRCoQ== X-Received: by 2002:a05:6870:14cb:b0:3fd:c70c:3f0b with SMTP id 586e51a60fabf-40eee7fc0fbmr11112425fac.1.1771558097095; Thu, 19 Feb 2026 19:28:17 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id 586e51a60fabf-40f18d151c8sm3221341fac.8.2026.02.19.19.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Feb 2026 19:28:17 -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 9ACF1341D32; Thu, 19 Feb 2026 20:28:16 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 977F0E420F8; Thu, 19 Feb 2026 20:28:16 -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 6/6] nvmet: report NPDGL and NPDAL Date: Thu, 19 Feb 2026 20:28:09 -0700 Message-ID: <20260220032809.758089-7-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260220032809.758089-1-csander@purestorage.com> References: <20260220032809.758089-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 --- 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