From nobody Fri Apr 17 00:23:19 2026 Received: from mail-ua1-f98.google.com (mail-ua1-f98.google.com [209.85.222.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 BAA7D3A7F59 for ; Tue, 24 Feb 2026 17:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953304; cv=none; b=kTxdGXr58Ldru0N4zLVNnZQUmboZyzNND1novAFgspQ/9SxEaWRuq1M2zUBFT3i/bgXX378pJjsrjloSL54lLFiYLZixiecMUbIlUN8w9SpCTh6XXnZubEaY/+VPgwlFhhwqQT7BXfrfy4v9mN2UNRfuT1WXwyHaZ5Ttlr9iVA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953304; c=relaxed/simple; bh=C1USMimgJzASCD7VPj4tIL5i173jKmiylohG9y4/etY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mYXcOb3GaG0frf/BbOYw7fyhKu1PSqggbGOvmvsp2itcNV9HpG0dpC48pkU+1+x3y8knr381sC4lwzNuTlVDGp/FQt4fkS9b/kK6Q4TJXFm7BjpbxcAsSBkd29SA7peav4TkVd7r7o2REENOVVlLG2D1HGJB1ESGZanBguU8lec= 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=fyfzAtiu; arc=none smtp.client-ip=209.85.222.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="fyfzAtiu" Received: by mail-ua1-f98.google.com with SMTP id a1e0cc1a2514c-949d888f357so171665241.2 for ; Tue, 24 Feb 2026 09:15:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1771953302; x=1772558102; 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=fyfzAtiuaGv7szAAbWLhNUu+5S7i5Dl2HVeFbvBQQTUvDkB2wSdeS2zLlmT05UA94R 8w+PweVZzEZ4gv/DIVbVUNu304rzoBXT/UrXyErcj3R4+LMmto1l+BNiZ9eQ9QgNG5ou R7BSPXPOnJFrmF6LkjIAEizpJQYjgRu15kUis4tpd8frvvJAIAsbPo6QE/2/mGPhfOsK aaI/clMrn6XBLqvRmJpPp4iZDXZCLgZwYUtStaM8DiaVxwpmnhUY86qMeOhqPbXnPE8F OXDSIWotXNydrlOKHQxlNrMEnb+fWsHbdffyUq/hCuzKHYYCsaVJR6h25RT5ykLonAhp jJnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771953302; x=1772558102; 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=YPWu+slxBBuFCiOnSC+ZIVQzAYeM/UzinXOuH4ftXAKU1dffZnWaEZVTTVf10Aabxl 86nCCpa6GvtaoahzUyWK+lsl+90hK9v3xJlcxk5DCfexjz1Lkx6Xp9OjaTbgBu4U/vjO hkR/bRNylQT+YvYb3NVT2DBSq1fQZUT1v0Pp8PguBDVLUfDP4FPqFl3fKmjyLRTtZMPE e7U2mEh5CzsqKCfXLCH/oSbL4LLKMw00lItLySoOjXn1dFor+AlRVDtvaxWlU94JvT4o rRz3tJ9JzwKaToqkY2H5hZsrE95O002IA6oAjU6YyXwzyiVTeYQuU8G5jO/G9evnLilk 3Ofw== X-Forwarded-Encrypted: i=1; AJvYcCVGwrAm5z1YP8vIhaqZ4DKW/dyiOuh0jCKkQk88R9FTx5gLmkxXDwKyxmb5sg1lFMyec6uNw1rzmEctyAg=@vger.kernel.org X-Gm-Message-State: AOJu0YzXha7uM6ugrrCpPv8q2KXmSxErP2IvzgnWHiVFcHDU8hq5BDaR SM9aKqhQ8CVk76NXG/AcjWRV76VJpYnNKpGQgp36RJ7tS6Svimy+AjYbuU9CdSVk/0EglN2ibPI sEs+RuR0ZvuO4hqr19g1Lcd/nzCUcUDqEcBJ0oJJQbF7jqk7LUTSn X-Gm-Gg: ATEYQzy0meOw0TDNQPpMbiyf/fACmGcYqyvYrRUVQk86/Z8z4tS9Srd7k/KNu+f0icY zSQyG2ox9bKW+IYM4lfdtCJrVBWlYbtJHVBbB+5JU0uasIhG6fzd2SbAr1f4t0DIMS0XCE2BhFj lQA/qZGLD2wKNf35ObGezGm8047ncwgrEXAsG6Ew5dfHj8UxiS4J65jWAE2Z+nMBxYzxpOBx4St SRCmMvs07HOhEQ2z+pt+Vi9oYL8dLoLcmsuKd2bfuNa7tS79CboVZG0ljBomv/gs2MXIMBuTekX ZyOSD2QZTFqrGhPG8oRPZ1JWMxABbS9hPlv1V9awgT2TvIHP5PNpR5IBIN87Ikngnd6DQywqVOh dbFopo0E+vjYCBV3jUHwbS+UwI+QaaL+ygQjBF0M= X-Received: by 2002:a05:6122:498c:b0:567:190c:1624 with SMTP id 71dfb90a1353d-568e4885d83mr2152145e0c.2.1771953301647; Tue, 24 Feb 2026 09:15:01 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([2620:125:9017:12:36:3:5:0]) by smtp-relay.gmail.com with ESMTPS id 71dfb90a1353d-568e58a4261sm1897823e0c.7.2026.02.24.09.15.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Feb 2026 09:15:01 -0800 (PST) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (dev-csander.dev.purestorage.com [10.112.29.101]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id E3805341B66; Tue, 24 Feb 2026 10:15:00 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id DEB7CE41254; Tue, 24 Feb 2026 10:15:00 -0700 (MST) From: Caleb Sander Mateos To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Caleb Sander Mateos Subject: [PATCH v3 1/8] nvme: add preferred I/O size fields to struct nvme_id_ns_nvm Date: Tue, 24 Feb 2026 10:14:30 -0700 Message-ID: <20260224171437.3175993-2-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260224171437.3175993-1-csander@purestorage.com> References: <20260224171437.3175993-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 Fri Apr 17 00:23:19 2026 Received: from mail-pg1-f227.google.com (mail-pg1-f227.google.com [209.85.215.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 14CBB3A7F7A for ; Tue, 24 Feb 2026 17:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.227 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953304; cv=none; b=mXNHXTz4J5eCPj0Gb7SQtMGiiMzrRKIzpKEKsdhlj8BHU4VPieX6wUyop9SG+EbRSBQ8mzB46kB8W0TngjvkY0AJk3x97nhdwmjqT8lxj+mzDPX8PmvrCgjZJPpKAK6x3fQknsM5z1GKj6gpVw1CfpifxLKk7ZIZnNM5Bsdh+l4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953304; c=relaxed/simple; bh=552bYwko8otEYpm5ebh3dNg2RT6Pd9XEkCxMlc7h/U0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GSC6W+ny4jClnXWTXPiEfOtmugKbnCmKvRBTMI0/GYH79XTw2WLL8B9E0WJG/TWqaHV4UFRMlmbbxhfioGbFPKTQoz9YykYz3n2/3dYT7aLZ7KfNoC4NuwHICmpH4jW1xWndgTZixAz3E+TDISrQAba/hro6PMSuLuiTRkxer8k= 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=YTUQVq2g; arc=none smtp.client-ip=209.85.215.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="YTUQVq2g" Received: by mail-pg1-f227.google.com with SMTP id 41be03b00d2f7-c635d5d594dso529408a12.2 for ; Tue, 24 Feb 2026 09:15:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1771953302; x=1772558102; 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=YTUQVq2g93s4qXWClZdladrRt8H0xrccDrd4mJiQgksT1JM0TQ1cvZoH4ZN1s6PoIJ 7zFfqJtKHTMgJwmqyd5EDKGB52UHsqUmN0i1KQ3TFUmXKdyuKz19av38xUVCfnP0/pUl XhN99Hlc9ewLYBD1N7EbBVGafnzfhEssb9kgQ41kSx2gPzUjygXS3ImwG4307FkrkBQy mM+ca2vbYHf8o3z3LAq6Ir+vg2FLMbaVVmbBrb7YQnyuUiYRYSFHby88HFCD7/F/psEK Xzvz9HX8rugjP8a4PixgxlXSjvaZI/2JIQmg0CHpAj2f4tbU7UZxjRMzV6O1r/94NDl9 GZ2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771953302; x=1772558102; 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=a4CsMP8E7BlcuYvQtKIlU54UNOgUDHQh/1WMcs1vH09PHMVawCzA+9HCRgFuUZvg+j CtiGyBRLH4cpPHCXQMe8L2ElCzPWHQjNIsaeMIkQJGYJaOnk6nsByjJInFD9L+uLtI31 Sc2mHN5YH/H9xYqsCy+07zVn3QlqWsQf8QvLzqNhXFLMPc6eqUyvXAfbeQgfdwFXXWNY ZtIrgzn7vmLdRUE9tMQEjt7dDbEgd2xZwqBzOVM/9/QfxKNIs3jkUViHMuycPPUh4vDV bAuSQW9jay8dGvPPm33Xu/3nZcih4TnP4D0dTQ4708rqsw6ayvfpsLMOdepREXcPM7dr z8Jw== X-Forwarded-Encrypted: i=1; AJvYcCWfnDakacU2ssz9LY3KGCyc96cQHfAhuU+253YczZmn9B340JVWirgrK49IxuTBbGx4urJIhgwKAQ2YPek=@vger.kernel.org X-Gm-Message-State: AOJu0YwMD3VmMcYouMSOSg8WgL0o3CQTg/pNfk2kTzTGE0PUFwl1rp/B TYHzJGGu1kJFIIUKg1kpvs/mF8Vq12GsLUjm/LFFFCU0+kKc+S5t8qHXe7k5t86LM+CZUAfXHBL MM0VExb7aCWEKOQ7H09IyRXiOVPvNS+6M/EK6 X-Gm-Gg: ATEYQzwYXsW1poFGR6Jowxszki5zQYuhVWzaXYxdEetoSkA0TxsuSquldPnKs1kYk0f DCp0YE950CPp20UJhtY2o0H56TXe85oYGX+v/A0eUfSXZUzFrx7WJtHxVmghGh2nOl5mPKuxIem Yyy05PViqjN2OJLClcttGaD7HXqbUcLdS9EP06vYWn7qDFWkia72xCd6WuTTtG0IdMrD3hAQrtc IzkrhxoVo6fr7K0WYspG63rCWB9yTSwVVowa3YCSeYmxy7HxDaXFznoJv9adyzJyKqGG66NjiT8 HzOQDVmswN11qSIQB0dcshXSB9TPHIMnbKcD4JR8oukqxW5MwwJtsggvE32UD0wlVB5bkB9HGMq 0TmlpVJstdmd1tnY3MlnG7Bdqmopotya4wXa77uFbfLyuw3DxqXuPHg== X-Received: by 2002:a17:90b:4b12:b0:341:88bc:7a54 with SMTP id 98e67ed59e1d1-358ae8e3753mr7245157a91.7.1771953302352; Tue, 24 Feb 2026 09:15:02 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id 98e67ed59e1d1-35900dba287sm56754a91.1.2026.02.24.09.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Feb 2026 09:15: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 1E749341D32; Tue, 24 Feb 2026 10:15:01 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 19F96E41254; Tue, 24 Feb 2026 10:15: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 v3 2/8] nvme: fold nvme_config_discard() into nvme_update_disk_info() Date: Tue, 24 Feb 2026 10:14:31 -0700 Message-ID: <20260224171437.3175993-3-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260224171437.3175993-1-csander@purestorage.com> References: <20260224171437.3175993-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 Fri Apr 17 00:23:19 2026 Received: from mail-ot1-f97.google.com (mail-ot1-f97.google.com [209.85.210.97]) (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 7E99A279DA2 for ; Tue, 24 Feb 2026 17:15:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.97 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953304; cv=none; b=BO7L7XYlP/UlifaMW2yRd3Hw0Etp9/XkxBFgispu8L0+RoHeZsVjGs1KOfR8+KHYYoaaXLROPr+CzJBPCHZikRl3DU+fx0OsKyJJXLtnJx5ynrrap6neBeIQ5A1TWAhVGXuyVgtnDhVxMCzE+1EnxR1zzNKPILr+WFsC6ABp4kI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953304; c=relaxed/simple; bh=62cRCccrSguAwwqDGJINO/15pCmBCVwknmS2odJqMIo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZYcN3WrEHqq3vvtmBMu3yw2ssNz2j4b3oSi769fYOvd5DuTcZ4pVjYgp272Lmnx60THegTRYcPSbvh+IeSBDorGd8uytk6n9LZM2fUOcBetg8I8wlghI5XdU12180UF1aQKFSrUTqSc3LvL0FDyX1XfnUvu0r8L9Y7shim25rvU= 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=Y2QeJB4H; arc=none smtp.client-ip=209.85.210.97 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="Y2QeJB4H" Received: by mail-ot1-f97.google.com with SMTP id 46e09a7af769-7d18e9fb43eso806281a34.3 for ; Tue, 24 Feb 2026 09:15:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1771953302; x=1772558102; 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=Y2QeJB4HgQu/suTVSjjEnKnO1JuK+kB0j2OWHNPVAXg6qezbaMWrnpcCAM8BBekIuV HW6jE4y3RsbnpS7MEcPQpECGACi9Kl/Wp1uMy3LR8dFB+XXzNMbyjdEpMyjnny9+XoiM v8G4QniRQ3sL9AsYneANIBJbfRIkJE+OPn8si2/DVQfFyxTjfy+Ef2aZDLsMUfbc0b19 rnT9Zdx6A373LIGmidHljsviyR2H9QafSCFyDpBzJxY7UmwrYVocNZZPOTENS8vLHrqj 9Vpix1uQGcMb07hqSETpHOTiiE/HGJFqHt3+AI7H+cAIn5VkN6SrrH2DC9qY/WKtHpyi /BAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771953302; x=1772558102; 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=re3TFAvSJHNoNqI9qTnSSwy9KggTp9EHSWx45cnZrgUCKZlxbNK7wpL5ownrKE1t19 FhdjZkB1/hk0zTA4q/uu2snL/HU79Jp5AUmGqTKclIe6u9A0kdQOrR5dj9462jUEKEUg GlscOjReTPjxR2OmgQqsogRkdcUcBFZjR39WPf9hBilV9W9eMARWo1OQNQSrsy20qIcP t5oZhbdnNxtp1vyZuNaB20z4e/7zEZ+MmBPe36exIS/BRDyy0f23aRkxtY47VnF+jt8D Xb7Y+nXJmAHrJNa5OQkrYo8vdPmrwNkfAbVZ9Ep7OFdLef3HORER/NFkW1jExyc/3C3V OOhA== X-Forwarded-Encrypted: i=1; AJvYcCV90HroAgNKxgcTviqder5mYvGYc/hf8MkJvwpJ0i7Udr3k4yWGbEgkMiKLFycMTM2I0/WhD0xth0/mHDI=@vger.kernel.org X-Gm-Message-State: AOJu0YwHGNh+TqtnELamSQM+Uqlnyfyt+gbT0qGtL720tr1T94lSmWcp me8XBnok+w6LAPgLkCIH9GiWxxYyYBPTuDsOqPDZZ2km/ky6yagtfRWjznxmgoyw4J2ez+zXnIw jpEuRZaR4ITSsBxz9bmMEd21lykDLf3iDV6uB X-Gm-Gg: AZuq6aIUGWchAlhuDlKk1U5ALJ4kXqrPOEsBKDu0XfKqoeJNbuCWdNvvfMcPALTnqZb 6SlfUyEHfxKygNKx30zG43FFFL4MnLsoaEpo2Fk4E29hYbNs2lsDBjy/F73b631lusZalOJgpQU FRYpXn5BoPIw2h1+NGBcgNbHPjvdpVGA0A3Ghk8/2MRnl86Qoav//dinkaBCk+UxfxjBOSx/z+F panQAmfJdp4fjQr0Vvc0w9H3qLYB4UBxjgm/0f/GBz0XSShyoS2XUaR7DIjXbYZg84Pis9TgFLq IsCD8Po45UiwV75h1gv4wd0+/sEWT24mIijuV4Ga5CGIuZ5p0cepJSbNKQN/HqVhDcUvyb7h1Nt ijYw6OnWkUcG8EJ6pm09c1ujgmC+caXJhuYYucANkCKEzjsI1XSPlCw== X-Received: by 2002:a05:6830:71a7:b0:7d1:4684:ea96 with SMTP id 46e09a7af769-7d52bf24219mr6568321a34.4.1771953302166; Tue, 24 Feb 2026 09:15:02 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id 46e09a7af769-7d52cf74750sm1233685a34.2.2026.02.24.09.15.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Feb 2026 09:15: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 4CB4A3420C0; Tue, 24 Feb 2026 10:15:01 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 484C1E41254; Tue, 24 Feb 2026 10:15: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 v3 3/8] nvme: update nvme_id_ns OPTPERF constants Date: Tue, 24 Feb 2026 10:14:32 -0700 Message-ID: <20260224171437.3175993-4-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260224171437.3175993-1-csander@purestorage.com> References: <20260224171437.3175993-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 Fri Apr 17 00:23:19 2026 Received: from mail-yw1-f228.google.com (mail-yw1-f228.google.com [209.85.128.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 4278F3A8FE1 for ; Tue, 24 Feb 2026 17:15:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.228 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953304; cv=none; b=mVqiBrCFCjoWJKMfUvJqYRt98GpJ/eE6Osi0IGrfDnkhyyUSEjXsF699qW2d/JUT/h1RrAgky7dqQIhsvPUyKPWhuPttEWHNOkn7Z3ENA7z3Ttc5ORJFG+oUMQWur7TeuO/d8cN+QvwuFnpOSr8Pk+hhcS9biryJqUpzy2/4PZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953304; c=relaxed/simple; bh=NdPvYIVAiaJrTIXUdUqqs5xQQgNiklVTzdScYSwE5do=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UYqfn6H+HlvqIKHzsYzeJXJB6L8VqFczwFcP16mwe4EhVS/LUPSPjiCZ6F6jH1EP3LFCrpw4X/s6UAz9lfkUyaIN1LQdEpiQA9/xv/IsBZnki8hkg+vmdeAWMyxFokrqJ046neXGVsEkMvZRwI8pIzVipBmmPZZkr7iVtt30kAo= 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=XwWanbkn; arc=none smtp.client-ip=209.85.128.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="XwWanbkn" Received: by mail-yw1-f228.google.com with SMTP id 00721157ae682-79636336576so1642947b3.0 for ; Tue, 24 Feb 2026 09:15:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1771953302; x=1772558102; 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=d5MnxCfiSl8pO88LgItQirBF6Sk69OYbyQL24d2UZK0=; b=XwWanbknJ3KmXyucrz+0x0Ps788Cly6iCgyrbbylCmiGAVxjm0umUZ9oVUhBcK72qQ oO0Pac5yu3wxoN0gpJcmFcyJwAghpLp5zu5ch29wq/5z2rWgWoHkhztc1fHgZEilmPQf toMS7InfRh1gWJYrfuZP1QCKC14M+7opfUVkDbv2GNfFIuMKCwiPUMcA5e8qG7lWltDY 0iPW4X9YYR+eBll/QH3LXi3RdK3SxVUfHDbFWTtKRkUQtclYUJhSE5Za81EFyKtjBybr NWX0OZz+RhJcuqT5CSVMeEQgX+rPEh+eeTXs0u5VlS7gOqH+Rx1nbEwviSPMGpNbwvmv IiUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771953302; x=1772558102; 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=d5MnxCfiSl8pO88LgItQirBF6Sk69OYbyQL24d2UZK0=; b=S5AM5I2fu74wCxpbQF0oNenTKpni9A60aSK0BtUJCz56eCpyQPhdsDmnooz6jES3LZ RSPLgXErnL6HJaJ4OMR328TB71Rnip1GLlpoLeq6yyhbslOE+BiXCFiPQ7pSeRGQRT/t u3gmmiDMv87GDFwIzEU2SxW5dkYf2vcT/FHbmXwycPyTHBfnwwj3sf/UQYiRLdRwQy9r q10LxFT5u3GloDtMwwS70I9k+s7K+dg17ki40BfZiCc9NknHF8FfLz5m7lGr3ENGVPXU hw+yr0VCwN8OhjLhFPKmsHUdFuABE1HQCc0hRaqcJNQWB9HsMS1iGQdYKCrCKhG1Af5l HemQ== X-Forwarded-Encrypted: i=1; AJvYcCVNyM/njsVi2w1WpFZHUR/Y3ocSF+QsWT94s7stKxx2okS9YM/8ODxa9A7wCVNW6cbHwiY0uIGVKPCnAHU=@vger.kernel.org X-Gm-Message-State: AOJu0YwXmqUF0VucybyKEiLJELEe4Im9pKAVDZetXkIwf4mDFEaxZZQ3 TaC+DfW5hmfSePxq34/Ks1gU5xToSuHtOJ6NSV2Uaxj/t6d7ucuEUq3z9/aT6/swCh8j0A8l9Nn OWdS9CykoJjx8taqiw02xTjIR+i2jRtfciwAb X-Gm-Gg: ATEYQzwSc7JIi4z+oiy014odRhaitKWjxyzYWxeJohBA/AIh7OSVd0MTPmSuFSPXqzA sj+o9DgkZMS01X2G3s5EYwwblO36qrKEv2TatbFr4Y7Qpd7Va/kdhLHbcT9MtmkLL/5bxv1isRu UHebiqA2dUEoC7vOt5olKQ0xLv5REDJz80ToYPjWru0UY0d8DO6lEAjGaoCLMCP5CmNb8u+EQXh JSRpdJusPXb2gEjn/0DexOxC2i/ZwsISGN6CxnJnS8t5/p3DIsjtDvBDaS99BOcx7c2V3yU7EwT kqDKt8DHTpENN/ZhaCjGEySIgzKJx/PON9kwgkxDHRwie6MqPrfwJTyx2Rm5KiQo1BJ2GLmc5VN Pj8EDgCq5kFRaHXnhFvdvXo+t4se/IliYfc7oDce7GCFRHuTGBA9ddw== X-Received: by 2002:a05:690c:82:b0:794:2019:29b with SMTP id 00721157ae682-79828f7233fmr100481647b3.3.1771953302220; Tue, 24 Feb 2026 09:15:02 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id 00721157ae682-7982de1ca32sm13166237b3.29.2026.02.24.09.15.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Feb 2026 09:15: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 791C934211E; Tue, 24 Feb 2026 10:15:01 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 73E66E41254; Tue, 24 Feb 2026 10:15: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 v3 4/8] nvme: always issue I/O Command Set specific Identify Namespace Date: Tue, 24 Feb 2026 10:14:33 -0700 Message-ID: <20260224171437.3175993-5-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260224171437.3175993-1-csander@purestorage.com> References: <20260224171437.3175993-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() if the controller supports NVMe version 2.0 or later. Signed-off-by: Caleb Sander Mateos Reviewed-by: Christoph Hellwig --- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index bff6f26d7bcf..2b433478f328 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2352,11 +2352,11 @@ static int nvme_update_ns_info_block(struct nvme_ns= *ns, ret =3D -ENXIO; goto out; } lbaf =3D nvme_lbaf_index(id->flbas); =20 - if (ns->ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) { + if (ns->ctrl->vs >=3D NVME_VS(2, 0, 0)) { ret =3D nvme_identify_ns_nvm(ns->ctrl, info->nsid, &nvm); if (ret < 0) goto out; } =20 --=20 2.45.2 From nobody Fri Apr 17 00:23:19 2026 Received: from mail-pj1-f98.google.com (mail-pj1-f98.google.com [209.85.216.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 85AE63A963E for ; Tue, 24 Feb 2026 17:15:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953304; cv=none; b=sH2OsGXNIw3/KXu1uid09qfIYCJzSjMX6T+RToEsTeIKIuI6yybQRnGNKe1Qpni50R+XUvJZDfq2Lz/Jis9wh60piVUOWHKbIQH5w5haewQxxZRE31NyKpVyTpWj8dCa8jLGJjDREl0of6CQtTeMVELY//umv3XpYK38ggqVJ6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953304; c=relaxed/simple; bh=rEgUCflMnbP+oeHSg611GJ51AOMqm3sC9AviUd3En14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sXUxvbrPVRHkLlf+WgL2e7FiBgpqM9AoUcXdi5FOi4pfwd77ElwYYxLnddZyAJ9/t8acNyj25vuzvTid69j0QbQ99Pl9eDAGiq2LLuf+o2JAd25p43yvZ+Jw/uIHXxewYcOKOOvyHs4aWb9ompWyW6EmiCw8OHhCahk/c5AnGyo= 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=aSNk5mzC; arc=none smtp.client-ip=209.85.216.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="aSNk5mzC" Received: by mail-pj1-f98.google.com with SMTP id 98e67ed59e1d1-358edc54276so35354a91.2 for ; Tue, 24 Feb 2026 09:15:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1771953303; x=1772558103; 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=aSNk5mzCPWOF9v9S84iyGCs0VYy8S0AULotOfv678c7SZV42irmTBGisL/yJmwLZlI m3PzSHSNRSTOM3kCE38ULUXR6Nyr909dcx3XlkFG+qitIDaoKd+UgrmFqu7EUiq2VrBV eOYlODuCLYwAC8Hx/9IA+xiwjIQ2IPIdXcFYQmY1IT068Prq24F7R8GouChd4PvF5mRH JjxbDbzjbjQlrGbRUu3f74H9kV1RJvI+zg7AvqYxPvH30bu6ZLZ4iq0/JlY65MdBkdxL XLcYohK1f0VUs81wdAgwTU/UaNArK1YGWCwIhsrQdvyP+ZVz07vZ7PJ67xUEw3h65GZo mAPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771953303; x=1772558103; 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=O1qY+ngycXOKnEKrBk492Bw283M3CE5HStuzaZcV1YgKwoodLyebV40QR+1k6fowyI TONoWlrjTTPANwiTE/b0FVhk4uq5bkscy8aorgT74ZlDWg6ZZfDxap2tdWHLuwosNjAX 3jHTKea9Wf09OL/DtipWfJpNUJQi0WwvGBpo4FBFlwKxqTzrR/4nqC1L0S8jMTubFTcv 2bVSvTQvmu3BJ+ec9SdxYxq88d9dS4SoKbzMmVi5J7MWpM9jcixKBBqm9vjXLmW2bfv9 y7ETsNR6xBYh89Dr4yRQe7o9DU4ae1KEgZfnXy1YecsbMnoXGm7mWS/vRsoTGCCmJsTQ fVtw== X-Forwarded-Encrypted: i=1; AJvYcCUFNasj8+PL8d8ZKbguz952lmD0CJH5EQBtv8mivDCw3eS1v6XTyXb82qL64Artb3RqEVnrA0pZO901wlM=@vger.kernel.org X-Gm-Message-State: AOJu0Yxa06ccY1Y2C8F32f6/zZ0/O+Zjxn50/eW4XIvOXMbT18kF+Aq/ 1UhatH1S9SNHP5KqX9ejNZiNArUXU1BUWv2YcCP2Io0Y1bvQDh1KQws07cjkf9nvaCIPKLPTepU uj4PpQ/Gz8SEdJgZjXJP3iCjIFvYjYRjiHYgA X-Gm-Gg: ATEYQzw9IXpJeihQ1vNgB8dURB+syXlr9psujoUNlB1EBLD+kTePP0lX2qUWdN/6fcc DlW3rxenm0u3Jc6zXaWrsFYCfZw6hHW3S9QDedyXS8x3PZsecr81xN0dK6Zblnb/OgNQqQcTjC4 FLt34/VfUVyVyAlU3FNKWujilJyMLXyB2+7GVcprTMSaQ2Q0ESEmLJHWoYFUMWLsnTf1Igeqd0+ BjZEE7KzdMvtPKwT1niAuw28pWcZit+7GBmXgGLkKqjaUsdKbBqPPNDYlb4nJmjMLKCO0Ai6YHm NVo5bWk9xU6W5bQrTsGfbRVZUaRifMyCXQrcAL4xzIORYM313IGHVGAG+R6J1zsXcdp2ufAPYud CAlS5VL/faT/ID6I+FM2O+Xcni71rkD5cYt/kQ2FVBAWsJsAbYFB+8A== X-Received: by 2002:a17:90b:3842:b0:356:2c88:1e77 with SMTP id 98e67ed59e1d1-358ae7c0e88mr8453615a91.1.1771953302898; Tue, 24 Feb 2026 09:15:02 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id 98e67ed59e1d1-3590203cf50sm56444a91.7.2026.02.24.09.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Feb 2026 09:15: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 A6FFC3421BC; Tue, 24 Feb 2026 10:15:01 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id A2C21E41254; Tue, 24 Feb 2026 10:15: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 v3 5/8] nvme: add from0based() helper Date: Tue, 24 Feb 2026 10:14:34 -0700 Message-ID: <20260224171437.3175993-6-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260224171437.3175993-1-csander@purestorage.com> References: <20260224171437.3175993-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 Fri Apr 17 00:23:19 2026 Received: from mail-dl1-f97.google.com (mail-dl1-f97.google.com [74.125.82.97]) (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 DE6A73A9D87 for ; Tue, 24 Feb 2026 17:15:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.97 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953305; cv=none; b=uKEmDIl11aRTpGgJif5zCYmtbd3gg02HCiZfH5E4SAWmsrhotszXFUTxjuNusf7ErM7TBZ/88srmiUAnbkuGX/LiFpK0UPMH6DfVFQqCtE57pIhcQ4XgZ2AyH2U5KWa7b5VF55ljRSqL5a6jEFxVKt7rlnsJCuUmdU9scaPXkqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953305; c=relaxed/simple; bh=fps2/8dqqO4k2Lj+C/UvTyp6DIWUCCzBx+IebxpvREo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pJ4XgoaOGFeuxx3no+BI2TY9eDWQWPQqtr06Cg17vgenlP6MvwgajaA0tcf4kb6e3vj7AB1lzFJfyt1qT7fSqdufjixvjaYRlxmA5EV3veiDzqkUUOwT3okMUSwbpn2IvMmZfLf44kFdk0WBKMw81FIuGUGrLYRIl7vFeaC4rQ0= 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=Si7E1EG2; arc=none smtp.client-ip=74.125.82.97 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="Si7E1EG2" Received: by mail-dl1-f97.google.com with SMTP id a92af1059eb24-1273882d901so318980c88.1 for ; Tue, 24 Feb 2026 09:15:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1771953303; x=1772558103; 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=3NkdLz8yeL0qjqcdMwFc/Rt+8wFzIyO9CzdhRe+Sgx0=; b=Si7E1EG2o/Og9RT/RlI0uedKKN/+FjSUr5Atoju1Fnt2XPIDZ6Pg+TKHKCRTqbE8UK 84bBf15rV24qDR0HF/8dX3HkG7X7ZFUg1I/RT19PaGpObNieazGwRr/bY2r/aTAu9plr JkaNNXvLEQICxE/LOR8ixOqpPqrNQJL9hzba234YvFUwo3Vw3H7bZxyPbmgvi0uf2msd 0jaNL0nzIzOB94kPJJpn1b8zyh8IY8PHJM+AojYPdMHevsVdJLMVy1R/fo7iriHUDivc TsQ0/ooMKL1CTJBcVixIKpRsd2JONCfmLEv4JFBM4VWIryj4WqDO2JYsZ06gWUzY1IvR nT4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771953303; x=1772558103; 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=3NkdLz8yeL0qjqcdMwFc/Rt+8wFzIyO9CzdhRe+Sgx0=; b=gpWCXQHLSCNZWBxVsvmJZLWtUZmu3F1TmQsxOuX6NbCORroxbPkylYO3325E6a36mi 8VcUDPggqbjQTx9AWo5T4ecCXNJg+OJMquHsq+rMPIIlb8O4Nob0BoIRdJdQ+goA8Grm ae5JAKLCUJg81PquojruzVPC24EKMvrsNZ5h03VBa2SZK2AXwe9su2D845qopSCwmhDI VlLi+R8l181gl8/6dWjbQUQPiFJEgpBe0kB04bjhYHvFpV9/kFgEiGlt61DVGmBOMCX8 tS+2bKStCk55eVYQAsYyHIc9uEB04X0897Ftu3TgPs2BgX5F9dx1rmztnn67/9Mq9jkI 1kqw== X-Forwarded-Encrypted: i=1; AJvYcCUkU9BXsTCuewPTO2AurODsj+86i6kIXFcqj4e8ZXeZdGToXbRoSzKjoA+oF3dgbwEQNH0k9fGaKZOWuv0=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0OicmmCH+14/34FOe/LVvkjgk4MvDiu87eaS3ySlOG+Nbjkvy fCFm2m6PJYbtZdlolSIaoPepfLG/ntkz8UysdPTCOFtlqIU+grQdu3D4IyYbKxHBiGS9/uXYMdl GjlDIpqMGMDxP9eSIFf7i9GVY4Hrh25AcWCdB X-Gm-Gg: AZuq6aKdeNfW/Aer2qSViA1x9l1e9byKQq8MzkokX3ihwNWixZYp8uK6d8VtySOCEwO SMKSoF63pAUQp6p7uDZO3h/AKECpdFJ5X5DM0eD37d42M593IzLTaWeiabOjc1oKdGYOck9i+8s 1SkZjqRyiZuwGW3azlNb712cup7a9ddm3s2Nx8ZWgaez6Q9wUoSRB6fILM73GpIli2BEQe40abi ZUCiepcuD6m/BaG7kMaUBup+Uzc6S2ELK+bVT1j87yHpZ5iCnnaffzjT6kdcjb/Lr0TH2qVBK9S t1Y19oQg8bkMUhczOTonWXD4ogyK6mUjPODahNJfvrMtHWVHXrP9N10X9G/XUuP/7Ktl94eI6zj YSbsIa0hdYiebFWbqnZdkQ6DdPau6EnyuyOBbEMn/3LEJ4GeB4x9gSQ== X-Received: by 2002:a05:7022:2589:b0:11e:332:1e01 with SMTP id a92af1059eb24-1276ad03aa3mr2503487c88.3.1771953302910; Tue, 24 Feb 2026 09:15:02 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id a92af1059eb24-1276af6346fsm1377580c88.5.2026.02.24.09.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Feb 2026 09:15: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 D4E3B340705; Tue, 24 Feb 2026 10:15:01 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id CFEBAE41254; Tue, 24 Feb 2026 10:15: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 v3 6/8] nvme: set discard_granularity from NPDG/NPDA Date: Tue, 24 Feb 2026 10:14:35 -0700 Message-ID: <20260224171437.3175993-7-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260224171437.3175993-1-csander@purestorage.com> References: <20260224171437.3175993-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 2b433478f328..a9e8936b480d 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; @@ -2380,11 +2407,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 Fri Apr 17 00:23:19 2026 Received: from mail-yw1-f226.google.com (mail-yw1-f226.google.com [209.85.128.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 A969B28467D for ; Tue, 24 Feb 2026 17:15:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953305; cv=none; b=ZZxEcPjXXGS+mJtsCVd3VqPDL6N8KALHegUPDyMFQYHsKfMU8dZuxB34QJS86ElDNqZezoIkmCM0aq1Ogp+oLePhgaA3CWflKhE/vnvARGly249vihkh72dGqJqiDSshAHKxExF4F4QIMMXbaVmJbwJ6BHuYclMuz89b5mogMV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953305; c=relaxed/simple; bh=pBiR297b8PXFueLy2tPMN9uZJGaoOz/0vV31TY2gEY8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K5kw1mwYMlveA5FGvwfL1RdDMB/9rYwY0qkYwb+wLH+XY446yLugFISlmIzu4G8V2Bl5AAM3BC4fPJKDEYoPXWBE8PmEIBmWZieWNAlhgjzpNs6WXLXy4hR48kgB29hSn62lpMghag82m1e8HVF1AqTH/Uenefy9vtoKDTmWAyw= 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=gQ9QSnOo; arc=none smtp.client-ip=209.85.128.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="gQ9QSnOo" Received: by mail-yw1-f226.google.com with SMTP id 00721157ae682-794cc7e06f0so2935257b3.2 for ; Tue, 24 Feb 2026 09:15:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1771953303; x=1772558103; 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=gQ9QSnOoZkZR1t+RRRGal0Db/KjvR+v0rkXwnhc92m699rXdp0Cen5tKx6f9Y+Q/HD poxnv+3u5TNxhh5v4K7OQT5BHumkd/Cxj1zhXOwctO+1iQjbSTN6oh3A4k0udFd/BeCq PHpQ7B3NW0Iu07blm6JCvG4VY2Js/g1pXp9bMqhRFcu7/MeMi/4wDwOMoWaw/wetPv/T EeAY78iKv63ia1Ol5Zv4yjJrqTQLhJCaE764Yn0b4AVa2bH5jfTZ7dJ9ecB09S3dnFga ioSUp3qDzSOouVAOvgcfnBIbD0YxFha/IgqV/ZZ7WMuTDWmtQXAnfT25Slpd6FVUvRAf IzHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771953303; x=1772558103; 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=qoC1B9URVIt4DhkxQxxzqG3ME2I+7+9DZNP1zDuCa0A0oz7qCVd5RBAp3n772tpJjq /uadJBTe49EFGaGrxIq46DhZLkUpHtohred4pFgkOOMt8uhTQe5gMgLV+VPSDs1ihRM8 tXhrzeFvF0DyugfSZBcWMFVEs6icooAk4niSY+sr0/MGK/BHJCIcJzG/KR4eOiKpuqhw /B+PiG7rT2qiGKQYL1jGwp4yVybl0u+8pwR3vF56KlScOT4iLmoqgqlujdn81uuvUXNW dVd0kAPhv2L2eR8n58w5K48Smo0DpdqwzovgZmEaihyjVDdLZTIVxJTSNrnQ9/+a2u4u Jl/A== X-Forwarded-Encrypted: i=1; AJvYcCWAFc5hb3sIbmHbAgehj7Kkg2N+DnP0GxHzOgVHz57OxTfvM2IzJCwnff6emhCr+IKH0LKOSJaJ5JmyNVE=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/k7fDyhreGp7nkS/06ggrrHcBLjHMaqk7Mdf00i3rx9xCJ/N/ OxvV89aJ8BVZfwp+ncWw6o57qKwYBcHQYNHhpuFdGtMUKShlcPYLbzJqYk8dFgLY6EpxueIZ6JO P1J6lpRglUMS10nQRHnvKs+R7Ohjge+6frVTQ X-Gm-Gg: ATEYQzwGsq9tKUY+Bz4mGZrlvYzSyxwgqjCX/vU5vr2knFmDQOCkgcAYWjadC3jwxCX YVs4Zzjgu+RfknunUQBpDTEG3j9tVmGvSjUfw8gozf6HYEszuTNolXIXGbZvZxpXU+k5vwz3hhr 534E4kmd4HMVAcxjgYXnQuxWZ/dg6SU4bjsC3r6NRQMC4da3qEIUDpzolPSGlChxeZLMAVXl71w sxO+NlI+FTxba9XvVgV5Q56eF3e+6ZB6xFnzdIOUx6R5Vfn9DS5dQbSe9vbdPUPwObEX1UP/gCl SWDksQu1GxeYPoLUROcwNZ9uMA900XgUEq+AYizSlayjHqvWNj52HVnB/DhxjzoB7a/IOil/oGi rm1s18wmp5VbptYWg+e7UYXEGFsC9FSMQoComhiB4agBUXg1xHJ92fw== X-Received: by 2002:a05:690c:d8a:b0:797:a52d:85cb with SMTP id 00721157ae682-7982913fd0dmr93190697b3.7.1771953302724; Tue, 24 Feb 2026 09:15:02 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id 00721157ae682-7982dc2a057sm13159437b3.13.2026.02.24.09.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Feb 2026 09:15: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 0F72B342244; Tue, 24 Feb 2026 10:15:02 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 0A695E41254; Tue, 24 Feb 2026 10:15:02 -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 v3 7/8] nvmet: use NVME_NS_FEAT_OPTPERF_SHIFT Date: Tue, 24 Feb 2026 10:14:36 -0700 Message-ID: <20260224171437.3175993-8-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260224171437.3175993-1-csander@purestorage.com> References: <20260224171437.3175993-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 Fri Apr 17 00:23:19 2026 Received: from mail-qk1-f226.google.com (mail-qk1-f226.google.com [209.85.222.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 34A083A961E for ; Tue, 24 Feb 2026 17:15:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953306; cv=none; b=NdY/yq4+bDlGhyNdJUIzl80AbCIFeud9m214veQHkkyPTgpyj7vA5tXVOnuADq9H0zXDWZ7/xSPLq5w5tFgwteZYnG8jT1r0Fc7+anjIQwo5Madtsan1RpehBwovUgEwWk78ZiSB2IaL5/nbxBk/VSOnOL/Gm6GOx8I/S65PIWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771953306; c=relaxed/simple; bh=N0sqrv6nVURelHVA7HFFhzMGt9LzqtMjQpJgL79pyMA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dPhTRfczbp/p3qgbFpHpc62Ff53pWH3tUDeNEduvpefhvZIu1SA+CVWLGVf8maolpCPLO6a86MDInXNjwj71eErnBS9BmM4KJ80W25HTmld3sfMhAm6NOwTNSKDWI6Zc2EEpGnuCwzpMFifL07LSUKzr/EirJUyxLLn/zIshxL4= 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=EKN2ET3G; arc=none smtp.client-ip=209.85.222.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="EKN2ET3G" Received: by mail-qk1-f226.google.com with SMTP id af79cd13be357-8cb403b7c75so56361085a.2 for ; Tue, 24 Feb 2026 09:15:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1771953303; x=1772558103; 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=EKN2ET3GD7HnUdCxcKTBWvc5CHv+YNLhiWBzxVUpG7IojSqBr1CsDuAjVcJcQ5XX9W BJvbxH+l8qiKBBYU36/3V5wY2z5K1o2vPvfhAioDhlUs8gvdtVPSvf+G3W/LvJQfHrLr jFF6vU6Cfe7SgHtUw9Wdxk7TKaskatbS6CeRZ7CcrnmNG3wanX+Ie1IYpp7CPBcodFSa KnBllD3kvAtuNvEHXtV14kENRibozuWfPZdAAZxWNx5f6NuflAbSzy5fuaI2vtJV5j8F 7qdFR/eOsSOJlv5RRgfX8rI3aRT8Wcv+WVDFFhGanL81Nu5rcY8sreCVRWLUSH101nkH mXGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771953303; x=1772558103; 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=P3xwUkYALsATGJm6+Y4OFbWEjcWlGnjUg5uiUS03kdAoWodN3o5IL8KKIN55rKGiA0 3QSi+FvqSsbuPhqFHlriW5szQeFbH0y+7R+UGIV37vehVxRIHI1YYXGVQOTu/9S7rVpE IS7045PIHL5lf0s/vntj/VCF70jX2Q8Icq8jTYkj9sCrfwtLM1rhPsypItQKImCoBY+Q akYKgyKcUqi/qqMXxyoMl3kzUtJ1PET8kSpFQgrp50bXBHUE4gmOOdg2b9vU7YsDHqzJ exZ0O751+xc+hb+sxpbq0JaOLlKXXTz12MFysXvKsgg5D3A/FeppMA1h0t/ps6lndcli lzNg== X-Forwarded-Encrypted: i=1; AJvYcCW8glKmFudrvk0R2+SqXrNwVtBAI1UlywoIv5A89RHn4K7xA0F/aUx/3ZLIVW97fn0SVoYOSsEzISaOF7E=@vger.kernel.org X-Gm-Message-State: AOJu0YwNavo6fx1cf3PQ/iDvfw6890bIflVcrSvIXFEqoG94I6SANUlu qfqFM9vdp1pHinGwn90sc9vLQWIuG77LAP1eRIQfUvR/Ppqg4t3F8/AV8yIitqAA8ymwN1uB7Rp 43xKFiVTdOSgcpC/EkdSVpiV7t/uwnAgO6kFrIUwT4byf6LA62zCS X-Gm-Gg: AZuq6aJbEYcv+Ohatcm2Nc1YdSUH8mN9fjfpKFBnkcXIZ0UZPmBp/ZIM7v2Pz6CRQX+ tLaC5i1bfGYcE+An8JnPjj+pclYQ2ki/zSm9bhYtjxRYw2Pau0QXsbrzcnU/+roRAB9ngsSSSKp 6NQM6h4u64kXIHJ2U3NfITx5zElfe2D+anAW3Nn470BJWCdbhuKe+PRadQonYqR+nN3A+xb9E0t 9HR51nchUYd5+jSbLkINCNQTe6SDVnlCnejym/9srLe0vfBtUxwnV83TYHhH80K4T17d1iirybB lIEdcN7so4pzXoANOpoidvz0S/RoQWQoiEIqDZlRYnShVfTKpO38VsIjGpFS3MzWq2Zemw1CJGg zxsS4rIF3CYcKROyl0tnlFY0pRM3vQIG6AzXLqOc= X-Received: by 2002:ac8:5803:0:b0:506:1c3c:9dfc with SMTP id d75a77b69052e-5070bbe6abfmr147168361cf.3.1771953302906; Tue, 24 Feb 2026 09:15:02 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([2620:125:9017:12:36:3:5:0]) by smtp-relay.gmail.com with ESMTPS id d75a77b69052e-5070d67ab59sm13815861cf.9.2026.02.24.09.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Feb 2026 09:15: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 3C883341F2A; Tue, 24 Feb 2026 10:15:02 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 370F8E41254; Tue, 24 Feb 2026 10:15:02 -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 v3 8/8] nvmet: report NPDGL and NPDAL Date: Tue, 24 Feb 2026 10:14:37 -0700 Message-ID: <20260224171437.3175993-9-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260224171437.3175993-1-csander@purestorage.com> References: <20260224171437.3175993-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