From nobody Tue Apr 7 17:13:26 2026 Received: from mail-vk1-f225.google.com (mail-vk1-f225.google.com [209.85.221.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 0A69144B67B for ; Thu, 26 Feb 2026 19:04:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.225 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772132669; cv=none; b=IMzeAiGlr9l5VhTQ6RIbPSuk0vvxwag5foIv8+tWK9oTQoqU+R3kqDtrfnumkbimICJOvoh+KjAG+281Z+PisrLoI2hD23VBHKffcoe8VPGHi8JfkoWAAT20uoIP6JEmQK/ILUsWvqc9TGastk4SmEUolhNSOc0vVjhKgVmAngA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772132669; c=relaxed/simple; bh=C1USMimgJzASCD7VPj4tIL5i173jKmiylohG9y4/etY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AHBJvEYPcyXAb8nqjL4BQmYs5IrbU65QP2H7bcsDbiNbwRdLaElvJTRSCIcXpclKJvj0G2+YB+cPFWqR9eAlNBqECakAMrNqJV9OryXEurncTxnRPaUGuuHUwom6gLk+mHNoZ/SegvhHYPIoxhGmRZkQiJAmXWGkymUA/mYZu/c= 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=bQGCe2So; arc=none smtp.client-ip=209.85.221.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="bQGCe2So" Received: by mail-vk1-f225.google.com with SMTP id 71dfb90a1353d-5675de6eab6so41240e0c.0 for ; Thu, 26 Feb 2026 11:04:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1772132660; x=1772737460; 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=bQGCe2So07ILxtv5SEin+wHQANCkfRmvVQ1PTyT1xtuFe+RIbfhoJcwQvjOXkDCoZX 3eCQWfSezqeW3XX01qGXU8Fd07kEuUUF/oq+880wK7fofHJqy6wn4mmB1v4camfvl5fJ 69Ou224BqE6heEQQS60SsbNFkjuAzhmQe2xnAWUI8J6h/IAaoxRKDIDWvdL5VXgi2/uv S/IOoYEIdkPRd9vw3jIs7WBBC9SO1ZaOL5BwCIwvddxOoWM3GUtIFNTtmq0Nxdjpe+PF AfNcB7UPENTkNGc76Sgx4MMPn8INugbWiBYMcNkLzKN8OuQakLc0OITgv32ZSNBF0wQp NKPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772132660; x=1772737460; 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=oLucahyL9xy/RGiHyo9OFohGuWHl8Plzc4S8Oa8Amn6Fjai6SNgeNCzfQ5J6xGKuOq Z7NsBrasbq0FHXga9l+kA4AXa3H8unLMXMgH2n6aagabSYaUrWqiZ2bhPCOJcl2XauNB lPg6zdzmv/t4LK02WW/2GH45AK6uVNN3v+3MGgczixDP5T2o7+AB8lOKAHAx/uxB46ie Io2GI/5RgHZtVouG6CV5IZ62jEescHeJJ2jtVtvfVzFI41Ny/U4efYciG7FdMicWq9DA r48itkhsObvdWWtdtGH8RKxWZKFqH58OD2qgFFcPJ+t+49cXOLY2d9FQvVy8OwEbBcGX J28A== X-Forwarded-Encrypted: i=1; AJvYcCXQZ4E8BU5tPXyZjM6dg7Pjj8tJMykekEb48xcZoiLxBSpLVnOYX1X8GWOJuptdAMLqb9g2LN3WitB1uW8=@vger.kernel.org X-Gm-Message-State: AOJu0YwGeAs8CEvbympW/tDzWqnuyGyaPesSUsj15nTvkRXyKtT06SSg dSAJd6BwZuy9924+sO7XzUPg/lxIgYcY/E0L9GJ7xtPIYJ40JDDTZp6MEq0sbL9+HibCpmRA0Pv e4a2r4VnCOwSalJ+wTyleaTh+bGUGULcsEbzU X-Gm-Gg: ATEYQzwBPA7kiL9akx4d9u5sZrndQGXHPp++IBQZJdiwsnft3i+oTXP275weD2lwaNh kxtEKZ3ek/2Z/IhJSrc6/gv53fTN0wY2RWtA9LvX7KLPEZcfXri9PwbJBzm/N9XL7WnGkmNx1eX QUbHrjjqmM7njJqQGvcEI8XbxKKEBeP3pz8d3g+FNGwnM9Hvj4yimt59U42DTGL0ExG5S7eXm2Y KOcEySaDoTBruzNDqbpMSfCEGMTs1IDolO9iK16E6i5ImlOA4rsP13whZEk1P9mV/NS6ZaL2QBJ Y/BXyqRBZ77mzhnOM4QeesaC4YkvCKP7wFwwWT+QkeagYH1MmsFgSn80aL8jc2Ky9TCx2qkJMBg BluHztYqMipxumQkFkp+n/+whAdfQ5DQFYt7aBPFPyzUwM+q7krNAtA== X-Received: by 2002:a05:6122:6b19:b0:56a:9e65:3e30 with SMTP id 71dfb90a1353d-56aa0ab35ecmr60618e0c.3.1772132660358; Thu, 26 Feb 2026 11:04:20 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id a1e0cc1a2514c-94df6577f7csm242838241.8.2026.02.26.11.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 11:04:20 -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 B53A73402EE; Thu, 26 Feb 2026 12:04:19 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id B00A6E41254; Thu, 26 Feb 2026 12:04:19 -0700 (MST) From: Caleb Sander Mateos To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Caleb Sander Mateos Subject: [PATCH v4 1/8] nvme: add preferred I/O size fields to struct nvme_id_ns_nvm Date: Thu, 26 Feb 2026 12:04:08 -0700 Message-ID: <20260226190416.297725-2-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 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:26 2026 Received: from mail-dy1-f227.google.com (mail-dy1-f227.google.com [74.125.82.227]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4B5844CAEB for ; Thu, 26 Feb 2026 19:04:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.227 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772132672; cv=none; b=nUvMIlb66vkl3FOJ8mU9YxqMfzaSC+cVn3ttNYntdE96IxUwm4Ajl38/DlsDTJa1ovwy4DhBre3FDrXRvc6KfTcP1Bg7ubMKrs4oIY7VgfN3ajuy2WEwfbzIhYtkrc8ucYDzgTw0khTJ3d1wegOXCnffgX5bx2RwWYipvbsAjfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772132672; c=relaxed/simple; bh=552bYwko8otEYpm5ebh3dNg2RT6Pd9XEkCxMlc7h/U0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nBwSCmonZAoToo74CzGZzpi3sNgOHuNSqRXfg+PRalnqQkRc5AbwFz6u+iyMoAvuLoyUxMq2YQDY/qP8dJJUYSY7c52LLJlDt4wwDTclevZ75duSTFG7fbgAr4dfWnoFOruZnwkwR7ISHiwAx0uvzKGNxFMgIc7Uxg954Z3Esrc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=bU+RBnN2; arc=none smtp.client-ip=74.125.82.227 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="bU+RBnN2" Received: by mail-dy1-f227.google.com with SMTP id 5a478bee46e88-2bd5658b901so50726eec.3 for ; Thu, 26 Feb 2026 11:04:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1772132662; x=1772737462; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iTyR51foYUPBOnnEwYMeOkSAEe5aT2w2QE+WyN/3DlE=; b=bU+RBnN2PPx0a3cdJQJhd9f4HsAYu86Vvt+x/huvgrPvKLbt/m0SPeRRoM2X7ZtWN5 EDMqDJIe/5KVrXfndf7RlwR5X0GhPvrsp+ttN7fJgbAiP1npjTULT5x5u/6B54H2AFOx 4MX4D/9ZMLpckzGpnr39CNxn3HsbwNNuIc6jWaSaXlVuALJBh/10/7GnzZCYy25ykC3/ 1XW4qpMhQLpdHsGPFpXoaPHFg85EeaTTiqng/duVMtzxlxuK6vrJCKz6+ZuF45wgS+aa 9njPfZ4qDgkE5jntZyWq9IfOrPgRlfZmF/GWDnmCeYXfgW0georIATqfnZx3e3u87dA+ W5ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772132662; x=1772737462; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=iTyR51foYUPBOnnEwYMeOkSAEe5aT2w2QE+WyN/3DlE=; b=d4fLRPwK59cl/BDN9o1eFsA/2VK6jEroiE1XWLFa7YwbiMOT2YS7ZN4vnUp2uzEL5x Z92lSropMRSCrm0BwSgoUJyrZJPZPJxE5K2SRBNcMUyP9waLeIxMa09nAJvwnwnQR7ni r1AxMqqIW9Eu3nEwsRnELxgq3PX80AdLar/YP+9pE/62jRGLnBxRDNPvi/Pn0jYGy0vg fUK5mk3pGDnFjjNX3D8M1NwxC5KAKdBmMfaJZSZxnTZiaBTJtdJgqPO4E9CgXSG7xxZp /GegqFPB46AAjDzQkxoAcNDkNZAUfwnOAnaMZjcnO29WEo6VWmQ4qGJEWYdOCnqVaiSZ 604w== X-Forwarded-Encrypted: i=1; AJvYcCXOouoDfxGP6ITuBULKnVyPutkZS59sVzVEFGb6T1vTh5mgq7y5WGkCfqBroB5+0Ebx7KwQiAUjfdkxPSk=@vger.kernel.org X-Gm-Message-State: AOJu0YyYUcvGa5iYeHSIR+duaa2GiR6AHxn90BrTFB6Az2lqb82wUFOG +O6aGN+1T5V5GqVOEDXAIxtqL5PYWrEaoljUQHh9kXxSwXBl/4sOczo/w+ZWrR+5WV2pwu/w90p AdSNaamrftZX25i8ezgbuX0285eUf7Vwm7cto X-Gm-Gg: ATEYQzx3O1lKa60Pc+ltDRZbqJimk2pyfUhc2+9iS3NT338Y7PcayKkfA1ZHwGAPk3P O3Ij49uT1bwviQ11k/Wf2RqWWwrPpHfcMugdFXLuFp3Mndv11OxGwPsJdAiIzfjXbY4dJ3wfTd4 jzww4qcQMdaVEYK62KjoDlM1QScuZyxJq8hcii1R0JeKU2U/s883UaJGAoAui0+YjU/VxLxgsO1 KM6cni84W0dUCnCbRVHQu3OicBb8UsCoMbR9pMMGfrftr9IXrj8XulwEbqhPXMOvTmyeal+t6t1 dN4K7PxiviYLPigo/BWaJ+UCBBLgWnuxZFbBEmo1PCuSETHH8WV7Ap+xFpHJT9gAbcL1/TChLlJ Qjr9DB635j3SnGpV21zG2o1qXdzyiu1E9M5SoUrKgeru3yB2HsKq3zg== X-Received: by 2002:a05:7022:6199:b0:11e:3e9:3e89 with SMTP id a92af1059eb24-1278fc28834mr1899c88.7.1772132661187; Thu, 26 Feb 2026 11:04:21 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id a92af1059eb24-127899d591csm386473c88.1.2026.02.26.11.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 11:04:21 -0800 (PST) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (dev-csander.dev.purestorage.com [10.112.29.101]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id E369834058D; Thu, 26 Feb 2026 12:04:19 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id DEB0EE41254; Thu, 26 Feb 2026 12:04:19 -0700 (MST) From: Caleb Sander Mateos To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Caleb Sander Mateos Subject: [PATCH v4 2/8] nvme: fold nvme_config_discard() into nvme_update_disk_info() Date: Thu, 26 Feb 2026 12:04:09 -0700 Message-ID: <20260226190416.297725-3-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260226190416.297725-1-csander@purestorage.com> References: <20260226190416.297725-1-csander@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The choice of what queue limits are set in nvme_update_disk_info() vs. nvme_config_discard() seems a bit arbitrary. A subsequent commit will compute the discard_granularity limit using struct nvme_id_ns, which is only passed to nvme_update_disk_info() currently. So move the logic in nvme_config_discard() to nvme_update_disk_info(). Replace several instances of ns->ctrl in nvme_update_disk_info() with the ctrl variable brought from nvme_config_discard(). Signed-off-by: Caleb Sander Mateos Reviewed-by: Christoph Hellwig --- drivers/nvme/host/core.c | 43 ++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 3a2126584a23..8dda2fe69789 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1880,30 +1880,10 @@ static bool nvme_init_integrity(struct nvme_ns_head= *head, bi->pi_offset =3D info->pi_offset; } return true; } =20 -static void nvme_config_discard(struct nvme_ns *ns, struct queue_limits *l= im) -{ - struct nvme_ctrl *ctrl =3D ns->ctrl; - - if (ctrl->dmrsl && ctrl->dmrsl <=3D nvme_sect_to_lba(ns->head, UINT_MAX)) - lim->max_hw_discard_sectors =3D - nvme_lba_to_sect(ns->head, ctrl->dmrsl); - else if (ctrl->oncs & NVME_CTRL_ONCS_DSM) - lim->max_hw_discard_sectors =3D UINT_MAX; - else - lim->max_hw_discard_sectors =3D 0; - - lim->discard_granularity =3D lim->logical_block_size; - - if (ctrl->dmrl) - lim->max_discard_segments =3D ctrl->dmrl; - else - lim->max_discard_segments =3D NVME_DSM_MAX_RANGES; -} - static bool nvme_ns_ids_equal(struct nvme_ns_ids *a, struct nvme_ns_ids *b) { return uuid_equal(&a->uuid, &b->uuid) && memcmp(&a->nguid, &b->nguid, sizeof(a->nguid)) =3D=3D 0 && memcmp(&a->eui64, &b->eui64, sizeof(a->eui64)) =3D=3D 0 && @@ -2078,10 +2058,11 @@ static void nvme_set_ctrl_limits(struct nvme_ctrl *= ctrl, =20 static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *i= d, struct queue_limits *lim) { struct nvme_ns_head *head =3D ns->head; + struct nvme_ctrl *ctrl =3D ns->ctrl; u32 bs =3D 1U << head->lba_shift; u32 atomic_bs, phys_bs, io_opt =3D 0; bool valid =3D true; =20 /* @@ -2112,15 +2093,30 @@ static bool nvme_update_disk_info(struct nvme_ns *n= s, struct nvme_id_ns *id, */ lim->logical_block_size =3D bs; lim->physical_block_size =3D min(phys_bs, atomic_bs); lim->io_min =3D phys_bs; lim->io_opt =3D io_opt; - if ((ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) && - (ns->ctrl->oncs & NVME_CTRL_ONCS_DSM)) + if ((ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) && + (ctrl->oncs & NVME_CTRL_ONCS_DSM)) lim->max_write_zeroes_sectors =3D UINT_MAX; else - lim->max_write_zeroes_sectors =3D ns->ctrl->max_zeroes_sectors; + lim->max_write_zeroes_sectors =3D ctrl->max_zeroes_sectors; + + if (ctrl->dmrsl && ctrl->dmrsl <=3D nvme_sect_to_lba(ns->head, UINT_MAX)) + lim->max_hw_discard_sectors =3D + nvme_lba_to_sect(ns->head, ctrl->dmrsl); + else if (ctrl->oncs & NVME_CTRL_ONCS_DSM) + lim->max_hw_discard_sectors =3D UINT_MAX; + else + lim->max_hw_discard_sectors =3D 0; + + lim->discard_granularity =3D lim->logical_block_size; + + if (ctrl->dmrl) + lim->max_discard_segments =3D ctrl->dmrl; + else + lim->max_discard_segments =3D NVME_DSM_MAX_RANGES; return valid; } =20 static bool nvme_ns_is_readonly(struct nvme_ns *ns, struct nvme_ns_info *i= nfo) { @@ -2381,11 +2377,10 @@ static int nvme_update_ns_info_block(struct nvme_ns= *ns, nvme_configure_metadata(ns->ctrl, ns->head, id, nvm, info); nvme_set_chunk_sectors(ns, id, &lim); if (!nvme_update_disk_info(ns, id, &lim)) capacity =3D 0; =20 - nvme_config_discard(ns, &lim); if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) && ns->head->ids.csi =3D=3D NVME_CSI_ZNS) nvme_update_zone_info(ns, &lim, &zi); =20 if ((ns->ctrl->vwc & NVME_CTRL_VWC_PRESENT) && !info->no_vwc) --=20 2.45.2 From nobody Tue Apr 7 17:13:26 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 52CDE44CAE5 for ; Thu, 26 Feb 2026 19:04:22 +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=1772132670; cv=none; b=hvf2ODB2l6YuO0WTQnFT3z4sh9HFCxDmIkZ3IOTrymxOpJWvl/rk2pV00X7t6obF9xCVtvWwWrDCmDL7vP4eS6AR13cps0xyBFDbO/gdmmvN81LJ1rN3Ye5NU8nf0bz/BL3jISPkbbqWqYg87/qNepDwmc7YXeziemJr317wWFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772132670; c=relaxed/simple; bh=62cRCccrSguAwwqDGJINO/15pCmBCVwknmS2odJqMIo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EbX+jSc1oWjrPUZxYhNop54Ok5YyU8AWdAXWDQ3BHeAAYMdwUvQRWuF+nyW2GJQwBKYZhNU4r5tG9Jdrg7GJfdzu3xtDaSoXnMHEpjs01ghoMyhmGLWndE1uytoRS12ZXmokJFzFTtHmzMgMT4VdqtfTMyZ4yW3desNvmqvgED4= 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=a+RgoX3H; 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="a+RgoX3H" Received: by mail-pl1-f225.google.com with SMTP id d9443c01a7336-2a8720818aeso1525445ad.1 for ; Thu, 26 Feb 2026 11:04:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1772132661; x=1772737461; 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=a+RgoX3H++g18PFD3+KG0R42deTH043RaCR4+5x94dUDusFFMg7eUBTBIB46UNO/44 iRBfXM50N2k3kAlTmLNAUc2ON7iMZv760xCIKq07Yw3+3hT3kHuMNg8w0T/36E+bl+3h Dd2du6oDGAm7ie10fZL9CFSODbXRkUnSBG/BtZTjfc3IdE0hDBZ+MrFIwjYsFyzcK+aM slfBAtqfXd4bx7LgZiMaSAlCldJrRFvR6kEZdbeQWWf0kaO5V2KSTidvjFMq4tH11FrE mCT8uGPw8ZW2DINkBqO0ev2lA7rrIPxR4+Z2EBO6WiL+Gy4uxpfcInxzg+fCWDhlFIjg gBUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772132661; x=1772737461; 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=wU70XZea1arQw0E/nwOQm/mXvjfzn0kWb1MpBNZNLreYsktTMKRoXeFwKT/dg/e9qy Fs2STSw6EAl2qsncAy1dMK4FwNRxUKHyfJzYIaaf+HDLyBN8Kh51gVoSEqvgE2xTNOyi MUzXwmbXrMNzWzdtfPtWDO6NAaBHszeeU/fppNiEy5DVS0AbYS6G3dMDsLmEKnCDPTPM CToOnU0V2la3UYkG6bXB0hfcQRSXF0vr9sHaUdrLTec4CrE9JlEDGOR/+HTgWFSKQBRB FhyOTvqPk6ykPb1leMQQ9JJlF61zdvGrTop6VluuZVdddX3PK4RaOjBZa7nXp1HtZ7LR kXTA== X-Forwarded-Encrypted: i=1; AJvYcCV9TKFpQ93FUJFWIMMtDX4quJTAYztzEwyW/wz+T9h/WU6xByXcb/QHuCrXsProW0Bae/fHp6VHpqLkTTk=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/khoh93IBCnU/FsPxOvhWI3OOU4+Va2C35cg1/HRyc3OkxDHA Hn8FCRJv8qTq5+o1UQedO++QlaOthXq4C3+Z0Kwb9zwSUx1U7xDv2CcDonGMgfVMpq1PK/2X+Yl 5536KKZgLsGLY4y+bqU5XedFP2M2aEONkOtkA X-Gm-Gg: ATEYQzwH0vrccmIwNBm5cSFzc5SwDas5csPHIAgWykxUoKXrPhS89KmnLsl1M5by4RC fDt3wA7OViLTy0ctVBa1n/S0X4B5zVRh8yrittOY+E//YRkjmjwkeg4C2BdyL0KCknn/Xp7GLjy /elvZL0LW6tUmLIwfaRP65VcDayftvXQcLHFHoq4SmslX4+xfCFFewIMu3d7e3FtgbHn6h7jjFB beoVWJeVfXqD8U3XC15x7UeFBetL4VHknv33Lz/kbiR56fiYHZbZS5VeBe1udGWaSFxeeM1HzTh w+sTmbEbCtg8MwMMxbo29bcrMTzTRd6MUVq7jt6fdZuT1esulAGMAAQsCCzDyM/RiBSk0ptNE8a eEtAJAno6k7IhW3VzTC0iSFkH82HX5bFyawCOVIwF+GuNaXkwFrmtPg== X-Received: by 2002:a17:903:1a4d:b0:2ad:c651:46f with SMTP id d9443c01a7336-2ae2e1322d5mr254715ad.0.1772132661273; Thu, 26 Feb 2026 11:04:21 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id d9443c01a7336-2adfb05e386sm3591335ad.1.2026.02.26.11.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 11:04:21 -0800 (PST) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (dev-csander.dev.purestorage.com [10.112.29.101]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id 1F2E63407D1; Thu, 26 Feb 2026 12:04:20 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 19D67E41254; Thu, 26 Feb 2026 12:04:20 -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 3/8] nvme: update nvme_id_ns OPTPERF constants Date: Thu, 26 Feb 2026 12:04:10 -0700 Message-ID: <20260226190416.297725-4-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" 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:26 2026 Received: from mail-oo1-f98.google.com (mail-oo1-f98.google.com [209.85.161.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 9C84A44CAE7 for ; Thu, 26 Feb 2026 19:04:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772132670; cv=none; b=AHS6HvafTVGp+p8wfTwsKjkbv4LEoC4GqzEU8EaWNssE7FrY4Jk4ST/GPmgJzJ44eZETKf4LvPSyulrOQzLf20n4+rb6vNdxzhtqhTGjQPpteM8X8RKG694MJD0063PyrPFbVQezLTie097eFDuchzIIuV+oh+z801GSIGEqw6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772132670; c=relaxed/simple; bh=LBTWfeRPdfoLnL0Unw4JDSNyHmrp0ho+YMkjp8rQRJY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pmCkLBlMWj7dJ6Fizw0olBO38oprAxWoG94s83HEb0ecZTtVzzL2fHlLQ9t4ygaV0WFtOoopyOt6/ABWbi59nm00xJvEBxZ0Ymy+tK37w8JIynja3ccNX/G6mgAv6I7AFfSSFGuHp8SDOpcJmi/a7dXp6ZSoLYNn3CxS0+9/bvw= 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=QP2WVbSx; arc=none smtp.client-ip=209.85.161.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="QP2WVbSx" Received: by mail-oo1-f98.google.com with SMTP id 006d021491bc7-678061ab66eso49044eaf.3 for ; Thu, 26 Feb 2026 11:04:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1772132661; x=1772737461; 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=qC1PH2EFy1+JEy/LIGlvD7SDeva8ogk5m5U5Vw+2yf4=; b=QP2WVbSxcxulYu6/Z6zLOB4gIlG5xNpeTz2xyqqZQHywOhXkA+oNELp4oWbtn67jSb 29F1rgmo4cLOG2nyr0LIPEOM+7Fb7aQs80mneoyGer0ZfIYp25uxUuEvve5fzw/D84lk kIGzpK6ekRJaJiYeY+73hlk+0eDMzM4+Skb4MUa+phyjYDHdx9KJDHkQh4T4750t6IH2 oMekkEkwsgL4QFTe6xzW7nNqu9rAdPKhM1Ll36BboC0JhyoOTZz/SJrlZjTsyg0PsoSM Pt9rx5l3a2dALpExiKsoQ6P3qDOtPwE+y/oaGLCU0QbXaPZgT9HTfqT5znaWgfZnPuP8 5jZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772132661; x=1772737461; 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=qC1PH2EFy1+JEy/LIGlvD7SDeva8ogk5m5U5Vw+2yf4=; b=OWhtHR7E1VeY4n6REC+mWyzh8l2C560hzgQQJ0AfEG9Z0hDvTx2OXoouUAw4+hDLkX 2sIwmWs7VTxCYnf3QgUpbgnhFMdc3FyE5VW2aCsUdyIs9EzGqaQX4V0ytwiZAg4HKGvF cBJEntzy1vgWifF5UCtUV2zwN87jf2jkqUmVtGa1mDGHAgr8vCubwgsYVEn5s4h03vla Rjnz+YuzlY3b7I94P62EHvoA5MRIFQgeqSe13RA86OoUL3bsAZd9m59DRohX1g1oZYsi HTOVx/wUyxzR1F/y81nNFg7pyNoeitAFVqA4oRqkKWuRx8QuGd7vdySGUbuHkwZMn2Mo O5MA== X-Forwarded-Encrypted: i=1; AJvYcCV1kweIffi1A/Z5bUbKrZvNpLpCJgtxOZjSwjxnqz6Cz1o6u6YH/iQclW1fBERtlUDmldz+w97PJiOG97Y=@vger.kernel.org X-Gm-Message-State: AOJu0YwxH/yWljZeemjyIj5Ux3sTWp4+e5dJq3WxA27+zC538ZTJakTe aqEUCq5T6YSHa8eWk5Ch60pKvIDbgSVE4DE1rIgNWLCGftChecrXJwLByDHQceOzfQiEEgyn73Z CeRQ4tnpZk5ewX0Dp4zl1C1mRjKu3gsUb3rmC X-Gm-Gg: ATEYQzxS7dVmExn7++0UygZk7XCpQyfROm0Y4bhDgi4mEFq1z71Z+i/eIb7kDjAZhBs 5yCwM4S6NdTMhBrX851+74bKjBHy+oAzJ8Yxvs8EV7BQ6Ai8Ip4cf0QrbZ7Hmvz1sW5P6B/7hEI es3hSpDFIyjX8Y3pwwgWwpQyDSCKyceuu7XHiSbRdMCBjUy/x/cAEQly17C3V1OngFTRY6AVNYc 8ss8R+FB/jc7knxB12mn8at2L/cD8Mm+AxP5p1R0c5rvOFOwc3R+TC4CjibcztKUk/T515pu3yt 0KHQEgnNTRTyyzEX2fkEloAOsflVrzJnOsts9AcIxaDQ1dLjpXfjGXIh4tcENFmLoqnS7TjgijD ZgBNXhEwJnoV4gCHa5OGiMhzuymD6inYoSZNUbKmvf2y/rtugWmhAsQ== X-Received: by 2002:a05:6870:fba0:b0:3e0:de76:31da with SMTP id 586e51a60fabf-41627039f55mr138150fac.4.1772132661105; Thu, 26 Feb 2026 11:04:21 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id 586e51a60fabf-4160cfd4986sm369477fac.6.2026.02.26.11.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 11:04:21 -0800 (PST) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (dev-csander.dev.purestorage.com [10.112.29.101]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id 4D21F3420BE; Thu, 26 Feb 2026 12:04:20 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 48515E41254; Thu, 26 Feb 2026 12:04:20 -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 4/8] nvme: always issue I/O Command Set specific Identify Namespace Date: Thu, 26 Feb 2026 12:04:11 -0700 Message-ID: <20260226190416.297725-5-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" 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 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index bff6f26d7bcf..14e52b260f5d 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2352,15 +2352,13 @@ 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) { - ret =3D nvme_identify_ns_nvm(ns->ctrl, info->nsid, &nvm); - if (ret < 0) - goto out; - } + ret =3D nvme_identify_ns_nvm(ns->ctrl, info->nsid, &nvm); + if (ret < 0) + goto out; =20 if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) && ns->head->ids.csi =3D=3D NVME_CSI_ZNS) { ret =3D nvme_query_zone_info(ns, lbaf, &zi); if (ret < 0) --=20 2.45.2 From nobody Tue Apr 7 17:13:26 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 40B6C38551B for ; Thu, 26 Feb 2026 19:04:23 +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=1772132675; cv=none; b=J6YgCcN+6q6zIySixSM3J8+D1Socd/EmGlAQtDn13jOWlJiIX8x33JHMjFiS1tzJSXuQqQX92xNK8gjze5ygtX2LvRLWn/jCKbmXTLhNVupekJGC3c71/wBlnEWHLtvmy0SIifEDH3e749f7O8Wwa2dPvbjSMyD3ggwAOwb6GTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772132675; c=relaxed/simple; bh=rEgUCflMnbP+oeHSg611GJ51AOMqm3sC9AviUd3En14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R5QYaq/xABM14AkoarGn4y9vFX7ceLlme95nzUklDhgr7g4G+thztaYYLcWHlA/dAiNaXJ7kxkG5TpA8YZsMP9QUK6nnLgzBUNWTU8klmtYyTsoib+y3OK/tNkrp1Sr98RsI5IRh9GRgB74DNjSijDtkRi1c/2g4BpENgBZ799c= 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=I343PEWo; 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="I343PEWo" Received: by mail-pl1-f228.google.com with SMTP id d9443c01a7336-2ab1c8fdc40so1036265ad.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=lG8nfg+ASIKQ9CbyoNXjrLj+myT10j8TFxZs8gb+75o=; b=I343PEWojgIdwOJ/KnT/nppkoomlj7SQbCErE8Tc0jAHO/4iPLgZz6czx7XpPFbver ADQMOuX1FebrCYOoS3wtDvqNbxKzcFJclXhimiiHfEE5Qn2/sUK4w6Uzd8ie3xh6qvqV Atqc+CxSg57GhLiXwMpDivV/ciyohJpErBy4sr/rcW4XdPEQo1HmqNdBBQtA73DlmQ4R yDkCkGzbFo0O9mccy65+ieTyn7bJ9AagSbIEqXK2BAkBnfaa7yGS1mLju1rjfzwktptm rEvFYGZmIA6XP2n9pR0+Dja2dcEgN7vypsSnYrml1Ykh9Im/9FthKA7R2AhFK4zyGsMJ wDKg== 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=lG8nfg+ASIKQ9CbyoNXjrLj+myT10j8TFxZs8gb+75o=; b=WCmcNvkXBrlulR7MFXjAkrcOUhsIRKr3aaqs5Rbr7mcGPL7iplM49H7YMeFx04fC76 ZElnoycvSXPVunB+7bb5ZMYgYHRcKTzTiRvlnBGf7303KUL0+YVOfEQALwm/fws9IOI3 bQxVGhAYOr9fgnwOtRPNm8c38TdI+aTaKB3zaOyTXBftGYo/hQ/0QjO01hIbcTUwBjc4 tAlNRArgY/bOiICBm+gJ9HPxuBJ0vIXHQ/dBgLSDXEOcZbVHYNDwXFONjhKZlgBgBJwA ymGoXdqUNr3hAG+rDnBOckO1KgTDoNfZjPYLga3QqW9GHSGNM/fJTLDMszcw7KTMR6/i q3mA== X-Forwarded-Encrypted: i=1; AJvYcCX3y3NM2N7dCrrtYktju+OYgLmzAHMmdMQd67y/f4O8bwdYCGGj6Ut3ctt4G0uphxwbtEt+I8jKSAMLLW8=@vger.kernel.org X-Gm-Message-State: AOJu0Yyqt2ZGB87lVuxqZUPy+3nLXgiV62+rkQnG4iFl7Y+L9SZ9YSiW HxNQ1ITvQ9l6c1SLJhm5/v8NI7JerHY05pIlTh2FDxcOvg0RQnNMXE7AmW8k9fGFAF2Rt7hffLC 6oXe5u++RaoqWvkYeaq7svx+xSsugR5IUNqyz X-Gm-Gg: ATEYQzzlw1E78LVkGQJ0e1xKWz5/DiqqoDaRYeUPrm27aw/3eqmUgeyE/OnCr5Sg+SQ bpfzXhqR97wp/QVeY3LPK6ofIeDUFe0STUvg9UorDRYp9ZZylxsg1khUQYqWGRylVP1zlm5GuaL B/FDU3DQz3KqFfkSQDNkDyfCjI2SrlHYRG8MDsveTIFOW4dsfBfDoECFBnfPAmoKhNX3rnyJC+M 6sUA3hMYqrzLuiNPT9krtdcgQa6h7r2XMYr4KI6H5VdvXfredxjU4Ztor2xjEBgVZtoyLRurOMV AvwwVSb07b5GvHYQK1sqwoSbe663nGC+QNgKnxoAORL42n9DYFAACWToD8BVf2KZqpvCwzmN1CS coP8yAh9rKvGpnSVYSjmJ1wyjmpjTZQKCavNZhcrjK8qmbqCpWDJ9dw== X-Received: by 2002:a17:902:c951:b0:2a9:5b48:2b1f with SMTP id d9443c01a7336-2ae2e035543mr267335ad.0.1772132661783; Thu, 26 Feb 2026 11:04:21 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id d9443c01a7336-2adfb2710bdsm3572105ad.21.2026.02.26.11.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 11:04:21 -0800 (PST) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (dev-csander.dev.purestorage.com [10.112.29.101]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id 7E3AA342109; Thu, 26 Feb 2026 12:04:20 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 79581E41254; Thu, 26 Feb 2026 12:04:20 -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 5/8] nvme: add from0based() helper Date: Thu, 26 Feb 2026 12:04:12 -0700 Message-ID: <20260226190416.297725-6-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260226190416.297725-1-csander@purestorage.com> References: <20260226190416.297725-1-csander@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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:26 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 ACB6444CAEF for ; Thu, 26 Feb 2026 19:04:22 +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=1772132670; cv=none; b=IDot4Cr5Peyaesm2BOhb7AUqRYDNj5O19aCqqPQxjSq3ZTNVAnZrdZttFUDCuz6WUovqlGSrcbqRYpjhcNReWnYTSOjrMusveGI+lfKmNyZjknv+Tlz7bl8DzCgKycNhJv0DsDIkptrHcIwH46rVHIwuLDbMKU3yS6MZi4+Xqts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772132670; c=relaxed/simple; bh=EZCW6O28GdqODIWRdUFqKXljk8iskdLu5cK2y6OJe5o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jgYeXyds0MipsYlM9QxJYLmcX3MFoDSvW15pPuqqFQdL5Q0OBgNtRCX97bnRVfsRnR/+iaMElLPgRLnwedQEROFm9xL53a3x76SwEeKAViKuLaKO+UUdILAg+/VP43jvl/a922yLSFJSUfkaFnYjE8S/wYpiRY4CUGguh0OHp1M= 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=RMYH9Kcp; 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="RMYH9Kcp" Received: by mail-pl1-f226.google.com with SMTP id d9443c01a7336-2a8fba89cb5so957435ad.2 for ; Thu, 26 Feb 2026 11:04:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1772132662; x=1772737462; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MCbjgYzJFkz4xvVSToR+yG/8UzWEaIR4Ya96q2o9rOo=; b=RMYH9KcpT5WLw9FvgiIj43pc4CeWCfu7fbEnvaUX6Xnd6bno1Pp+wNSFtWrIOdWe9/ QG4R9jyYgadTLctEYRecH7WRfvPkvY5aZkgNH+UAfUQgWgxmhhNhS44j9vldACVunKrk dvHJ6gy6qHqgrQC211bO9BE5nI+XxIikjsDLeioW7zhBhrppoq/RBNL4i5gNiw8bGMZq G3Xv/Hht5HaSGnhRoppiTJ2hIiXleDYGzD68eBg/HexzF9KKAwkEoDkQgguxj9TO6ueK 9gVeNlIpjhFPMFotBZa35oryAsvuhVVjSHgKcLZjemN7vVwLS2XvlLAMN8Vya9q9a7HM 7KsA== 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=MCbjgYzJFkz4xvVSToR+yG/8UzWEaIR4Ya96q2o9rOo=; b=liCWoahQPt2nILsGMc2UYdANycWKwR2eGEQfedJd+d1AAQF3Fkh0l+KT8Uj2k1l8EW p2NCv1VAIw8/fzpQqV+IKr28XHHCTLXunZOA/A9Uxm9kwfNRtNVQjm9czb1b2/DPPdbS Gj3UDQt4g3V21VcgJfIZ2aCvpXrmhjfJuDBzmUNlHx2idv0U87K4X82jC9g/UoOVA4hB HliF7mgBS3Ql3QbbQhfuGUUrLZUXkyxO2AyVZjqm/29yWRmzeNFQg7cRs+vu0+aYn/Rc fwJ1ttsS7ahRakhQWo9shbmYlldpbeoQFiQgDkreOcnmysVIHJPIFlbNTSYjZKZEbdbZ FkBQ== X-Forwarded-Encrypted: i=1; AJvYcCUkjyV4vV3Nic5tQeUDIdM1idHeLLr3A4VCC/lEcVeMWKzHnVulBydqisD9cmYnNTDATOPhAVNaPNKoZ/Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4hEkUyIsfZ/Ed51jMioIrPy6lqCq9QfeTyHiZDdI3nS3rmZ0z rrjBzjglKdAOM7Tc2yXaHYmKU04JdTtNK50TL/9YR/67gWivy+Sa1OZ2EVFuQkRQgqzVt/NrFEk obrch/I4107gVWgLNqxyCfViYDkmSDD1w+jvcfN3VCI1fywmr+b0o X-Gm-Gg: ATEYQzxEIsucX4UCmqBehzM8vtLysDj5gaySf57H0+JK/7qE+yt3cSCpjAW4d5aRnfq JMHMY52WDOzJQ7mTdWe6l0RoO2klAemgRkDwBzPFx8yFNnBkkT9kiQ1D+DqrGvMr+zSLYeKJlsZ G2YYB6TXyPyUGx2kkQQyQ4L4Wb8jfHlTwnF/SUX2O6KjCZhl5k9QxB7RZ5oC737VTh2XQCs1bzI BGUdF8ne9gIMn1V8vmcqusRXvDjal72L6TKgutJMkDvEBM0dG+zIQFUtmtmkteKrrN8ykAKecdG 2pUpQ6eE8jPhzKm8AFfQxfgyA5SZ7YR42DNiW1wM8HjNQqN7lR7UG2IGUnVzjkxJsNeOWRoTeCU 5/OKEz3bIao4EBa+qZAJSG3XyDViL8y0A/MzsU8s= X-Received: by 2002:a17:90b:2d84:b0:358:f02c:b94e with SMTP id 98e67ed59e1d1-35965ce4b48mr126053a91.6.1772132661836; Thu, 26 Feb 2026 11:04:21 -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-2adfb16ae40sm3247365ad.13.2026.02.26.11.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 11:04:21 -0800 (PST) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (dev-csander.dev.purestorage.com [10.112.29.101]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id AD6D8342161; Thu, 26 Feb 2026 12:04:20 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id A8554E41254; Thu, 26 Feb 2026 12:04:20 -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 6/8] nvme: set discard_granularity from NPDG/NPDA Date: Thu, 26 Feb 2026 12:04:13 -0700 Message-ID: <20260226190416.297725-7-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" 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 | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 14e52b260f5d..20441985cad1 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,37 @@ 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); + lim->discard_granularity =3D max(npdg, npda) * 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; @@ -2378,11 +2405,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:26 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 568703859D4 for ; Thu, 26 Feb 2026 19:04:22 +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=1772132672; cv=none; b=KCi7lfcA4CF9bhCrQURb1zZiASOEKyOfOwUjUOQruvTQe1T1SrTAiLl9uOzXZR2Av8MCzM10eqTdjpuloU0ZwNKXxKmthu7kg3uRda0LDFKfliHh//q60pHZWfdQpiV8BstIBahCN5oHf4vcSdxkk6a9YvVzIhifKIv1m5R+BAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772132672; c=relaxed/simple; bh=pBiR297b8PXFueLy2tPMN9uZJGaoOz/0vV31TY2gEY8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e+Y0TQpK2YRl9Yf1WGtyTRah7Z9D3mRfqJES3sKY6Mny+ZYJeB+g+TVlJvpqY6ydHFxVbNBAFpA57D5xattMNElZ6hPwJtpq7jA6PZ5zKs3XZSUzHk3/8JzuQvKmRbEC5ch7Sdu4DYwCKtBWCcZ0lUxn3bPUYz6NRp5lwsdPqBo= 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=QIUmYAKB; 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="QIUmYAKB" Received: by mail-qt1-f225.google.com with SMTP id d75a77b69052e-50332392929so1634891cf.2 for ; Thu, 26 Feb 2026 11:04:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1772132662; x=1772737462; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=chF3cAD1j09EpR3bM9lUaumkQDJZpAeYYRmoTp9QLII=; b=QIUmYAKBktMi5Lgw82setDs5X+sA0VKtFN+IIRphkRG07t2XlU7f8HKfRksfhbB4o4 pPoPbF2rc/J2DOjNAUOP+Y/8vczGWLXFKYgwArTxbkDuQSb/EXuEGAbXZf1AutPfa1Tc WYhGXfVG6FV3yQi6+ZC3TfgDyaINeeHmPaOYb1jCDVc0boSSCX3omvkJvhJDxXi/O3NB rDnrKsEczgnPQe27QiePVIntgMkUQSVxQoJCh3FIi/rsGc+rSY1mvW9a4wGpKd9uC+K8 Qem3ZjS3z4/IPEP0kLt+I/i9Nirfz+oVJEZW7fOU0hvgBlrX9VAYjt5X6Sq6naA8yIdS P+bw== 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=chF3cAD1j09EpR3bM9lUaumkQDJZpAeYYRmoTp9QLII=; b=bJEmyA7wGM0enOtOLdllu45AY2u1dIv0A28A337xr4DmFh0R32OM1vy+dGXU/lX8Cy LuV/jjNybr3kBayG+ykzMrj5BkdWrUfiPe3cvOkBq39jo7C/37lN6GRO5J712DWST/8/ 3LVGp6z6Ncm60O9ahIEsnSkeK03QHWk23W+NqCmiuqp5XeJEvM0b6lUHitccweqA/R0+ SeftkucT5OwT2oxwhvVCq8eY8wx6sfonhVxFFQu8Wqc/u+WLor8zsag74qWxYa7o4RL/ 49+TAYye6igSaNaDHORcBHKKRLgK0Ucq5m5I5tJZ3TveFGbcSqtaWmrUJ4vHw9NsmGcf jhCg== X-Forwarded-Encrypted: i=1; AJvYcCV7kv67lXluqEbdQ3FAHds7Z9vBWtqKME2zRf1uwBa3iPSFPWJqasjGDvaSD2jD4IDNotjVKd5nJzbOwxo=@vger.kernel.org X-Gm-Message-State: AOJu0YzfChazlvMGNNkx8VlwhCKbcsZoIXps5SHaawoZ+v2AY8xxMo1M DBiuV8J1fGaBMSpM6Xckz39YNLDctLlvdlQR1PeV6sjuE7Y4nzfgdFQleJM7U+dptWuIfazepIj iHPLQIQDIJ3BVfR23BEdeU+osYyDJoOl3mcbb X-Gm-Gg: ATEYQzyeqSOkvlE8c6Uz53hDDgQ4havZpIOcXeJEdoyC3vOrSmSihuxvkNEaI3TpyLI nUusK2ybv2vie+1Rtshz1Szr6iuqG6p65nkXqvKeqrdtAVa3z5hmwQ/KEJXFINmjakLDx2vE6vv LVzLpOvMZ8Ld6CDSa+wrw8b1lcE4/vXC+IFV8DTZKTMDU0ZdyfHkaLZFwC0LQEgqyGgAGhav2vh RZjdOzQ0PSOcjOs8kOgcjA758bQH0PLxTtD+Ja6tZ9I6gAwsSIgrrnyCj2awEhb7m6RL28+/PzM cYmA8zkuZFaNLgEE8KLJ7rCtT7UIyOLyi+MV2GK0MaPWFJAfxvrup/6pyKn4k5Ni3ben7OzYPXg gNu9E+IO+5C+h/p1RL/AP0S9JBoWcfZfliaXOUJO3qlV1SVL3QQPO+w== X-Received: by 2002:a05:622a:4c7:b0:4ee:87e:dedf with SMTP id d75a77b69052e-507528847dcmr126891cf.8.1772132661604; Thu, 26 Feb 2026 11:04:21 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id d75a77b69052e-50744a369d9sm3317611cf.5.2026.02.26.11.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 11:04:21 -0800 (PST) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (dev-csander.dev.purestorage.com [10.112.29.101]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id DB507340245; Thu, 26 Feb 2026 12:04:20 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id D652EE41254; Thu, 26 Feb 2026 12:04:20 -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 7/8] nvmet: use NVME_NS_FEAT_OPTPERF_SHIFT Date: Thu, 26 Feb 2026 12:04:14 -0700 Message-ID: <20260226190416.297725-8-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" 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:26 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