* [PATCH] nvme: Allow sending of admin commands to inaccessible paths
@ 2025-05-30 12:01 Hannes Reinecke
2025-06-04 8:07 ` Christoph Hellwig
0 siblings, 1 reply; 2+ messages in thread
From: Hannes Reinecke @ 2025-05-30 12:01 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Keith Busch, Sagi Grimberg, linux-nvme, Hannes Reinecke
The NVMe Base Specification (Section 8.1.1.10) specifies that admin
commands should not be affected by ANA states. So implement a function
nvme_find_admin_path() to return the first non-disabled path irrespective
of the ANA state.
Signed-off-by: Hannes Reinecke <hare@kernel.org>
---
drivers/nvme/host/ioctl.c | 33 +++++++++++++++++++------------
drivers/nvme/host/multipath.c | 37 +++++++++++++++++++++++++++++++++++
drivers/nvme/host/nvme.h | 1 +
3 files changed, 58 insertions(+), 13 deletions(-)
diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
index 5d5f8b07cdec..1cf66d8b2d7f 100644
--- a/drivers/nvme/host/ioctl.c
+++ b/drivers/nvme/host/ioctl.c
@@ -723,19 +723,22 @@ int nvme_ns_head_ioctl(struct block_device *bdev, blk_mode_t mode,
flags |= NVME_IOCTL_PARTITION;
srcu_idx = srcu_read_lock(&head->srcu);
+ if (is_ctrl_ioctl(cmd)) {
+ ns = nvme_find_admin_path(head);
+ if (!ns)
+ goto out_unlock;
+ /*
+ * Handle ioctls that apply to the controller instead of the namespace
+ * seperately and drop the ns SRCU reference early. This avoids a
+ * deadlock when deleting namespaces using the passthrough interface.
+ */
+ return nvme_ns_head_ctrl_ioctl(ns, cmd, argp, head, srcu_idx,
+ open_for_write);
+ }
ns = nvme_find_path(head);
if (!ns)
goto out_unlock;
- /*
- * Handle ioctls that apply to the controller instead of the namespace
- * seperately and drop the ns SRCU reference early. This avoids a
- * deadlock when deleting namespaces using the passthrough interface.
- */
- if (is_ctrl_ioctl(cmd))
- return nvme_ns_head_ctrl_ioctl(ns, cmd, argp, head, srcu_idx,
- open_for_write);
-
ret = nvme_ns_ioctl(ns, cmd, argp, flags, open_for_write);
out_unlock:
srcu_read_unlock(&head->srcu, srcu_idx);
@@ -754,13 +757,17 @@ long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd,
int srcu_idx, ret = -EWOULDBLOCK;
srcu_idx = srcu_read_lock(&head->srcu);
- ns = nvme_find_path(head);
- if (!ns)
- goto out_unlock;
+ if (is_ctrl_ioctl(cmd)) {
+ ns = nvme_find_admin_path(head);
+ if (!ns)
+ goto out_unlock;
- if (is_ctrl_ioctl(cmd))
return nvme_ns_head_ctrl_ioctl(ns, cmd, argp, head, srcu_idx,
open_for_write);
+ }
+ ns = nvme_find_path(head);
+ if (!ns)
+ goto out_unlock;
ret = nvme_ns_ioctl(ns, cmd, argp, 0, open_for_write);
out_unlock:
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 3fdbbe1fdbc4..d225c518a32c 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -473,6 +473,43 @@ inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head)
}
}
+inline struct nvme_ns *nvme_find_admin_path(struct nvme_ns_head *head)
+{
+ struct nvme_ns *found = NULL, *fallback = NULL, *ns;
+
+ ns = srcu_dereference(head->current_path[numa_node_id()], &head->srcu);
+ if (ns && !nvme_path_is_disabled(ns))
+ return ns;
+
+ /*
+ * Return the first optimized path or, failing that, the first non-
+ * disabled path. Processing rules for admin commands are different
+ * than those for I/O commands (NVMe Base Spec v2.2 section 8.1.1.10
+ * "Asymmetric Namespace Access States Command Processing Effects")
+ * so do not set the current path.
+ */
+ list_for_each_entry_srcu(ns, &head->list, siblings,
+ srcu_read_lock_held(&head->srcu)) {
+ if (nvme_path_is_disabled(ns))
+ continue;
+
+ switch (ns->ana_state) {
+ case NVME_ANA_OPTIMIZED:
+ return ns;
+ case NVME_ANA_NONOPTIMIZED:
+ found = ns;
+ break;
+ default:
+ fallback = ns;
+ break;
+ }
+ }
+
+ if (!found)
+ found = fallback;
+ return found;
+}
+
static bool nvme_available_path(struct nvme_ns_head *head)
{
struct nvme_ns *ns;
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 45beb701011b..1d236a7ba757 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -952,6 +952,7 @@ extern const struct block_device_operations nvme_bdev_ops;
void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl);
struct nvme_ns *nvme_find_path(struct nvme_ns_head *head);
+struct nvme_ns *nvme_find_admin_path(struct nvme_ns_head *head);
#ifdef CONFIG_NVME_MULTIPATH
static inline bool nvme_ctrl_use_ana(struct nvme_ctrl *ctrl)
{
--
2.35.3
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] nvme: Allow sending of admin commands to inaccessible paths
2025-05-30 12:01 [PATCH] nvme: Allow sending of admin commands to inaccessible paths Hannes Reinecke
@ 2025-06-04 8:07 ` Christoph Hellwig
0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2025-06-04 8:07 UTC (permalink / raw)
To: Hannes Reinecke; +Cc: Christoph Hellwig, Keith Busch, Sagi Grimberg, linux-nvme
On Fri, May 30, 2025 at 02:01:42PM +0200, Hannes Reinecke wrote:
> The NVMe Base Specification (Section 8.1.1.10) specifies that admin
> commands should not be affected by ANA states. So implement a function
> nvme_find_admin_path() to return the first non-disabled path irrespective
> of the ANA state.
Nothing in here explains why we'd want to support passthrough of admin
commans to inaccessible controllers. What problems does this solve to
justify all the extra code?
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-06-04 8:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-30 12:01 [PATCH] nvme: Allow sending of admin commands to inaccessible paths Hannes Reinecke
2025-06-04 8:07 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox