Suggested-by: Niklas Cassel <cassel@kernel.org>
Add capability to connect to an administrative controller by
preventing ioq creation for admin-controllers.
* Add helper nvme_admin_ctrl() to check for an administrative controller
* Add helper nvme_override_prohibited_io_queues() to override
queue_count in nvme_ctrl
Reference: NVMe Base rev 2.2, sec 3.1.3.4, fig 28.
Signed-off-by: Kamaljit Singh <kamaljit.singh1@wdc.com>
---
drivers/nvme/host/core.c | 21 +++++++++++++++++++++
drivers/nvme/host/nvme.h | 1 +
drivers/nvme/host/rdma.c | 2 ++
drivers/nvme/host/tcp.c | 2 ++
4 files changed, 26 insertions(+)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index e533d791955d..a1155fb8d5be 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3149,6 +3149,22 @@ static inline bool nvme_discovery_ctrl(struct nvme_ctrl *ctrl)
return ctrl->opts && ctrl->opts->discovery_nqn;
}
+static inline bool nvme_admin_ctrl(struct nvme_ctrl *ctrl)
+{
+ return (ctrl->cntrltype == NVME_CTRL_ADMIN);
+}
+
+/*
+ * An admin controller has one admin queue, but no I/O queues.
+ * Override queue_count so it only creates an admin queue.
+ */
+void nvme_override_prohibited_io_queues(struct nvme_ctrl *ctrl)
+{
+ if (nvme_admin_ctrl(ctrl))
+ ctrl->queue_count = 1;
+}
+EXPORT_SYMBOL_GPL(nvme_override_prohibited_io_queues);
+
static bool nvme_validate_cntlid(struct nvme_subsystem *subsys,
struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
{
@@ -3215,6 +3231,11 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
kfree(subsys);
return -EINVAL;
}
+ if (nvme_admin_ctrl(ctrl))
+ dev_info(ctrl->device,
+ "Subsystem %s is an administrative controller",
+ subsys->subnqn);
+
nvme_mpath_default_iopolicy(subsys);
subsys->dev.class = &nvme_subsys_class;
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 7df2ea21851f..5e07ba634e97 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -1212,6 +1212,7 @@ struct nvme_ctrl *nvme_ctrl_from_file(struct file *file);
struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid);
bool nvme_get_ns(struct nvme_ns *ns);
void nvme_put_ns(struct nvme_ns *ns);
+void nvme_override_prohibited_io_queues(struct nvme_ctrl *ctrl);
static inline bool nvme_multi_css(struct nvme_ctrl *ctrl)
{
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index 9bd3646568d0..7d50a2f31c3a 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -1026,6 +1026,8 @@ static int nvme_rdma_setup_ctrl(struct nvme_rdma_ctrl *ctrl, bool new)
goto destroy_admin;
}
+ nvme_override_prohibited_io_queues(&ctrl->ctrl);
+
if (ctrl->ctrl.opts->queue_size > ctrl->ctrl.sqsize + 1) {
dev_warn(ctrl->ctrl.device,
"queue_size %zu > ctrl sqsize %u, clamping down\n",
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index d924008c3949..bfb52a487c45 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -2381,6 +2381,8 @@ static int nvme_tcp_setup_ctrl(struct nvme_ctrl *ctrl, bool new)
goto destroy_admin;
}
+ nvme_override_prohibited_io_queues(ctrl);
+
if (opts->queue_size > ctrl->sqsize + 1)
dev_warn(ctrl->device,
"queue_size %zu > ctrl sqsize %u, clamping down\n",
--
2.43.0
On 7/2/25 02:58, Kamaljit Singh wrote: > Suggested-by: Niklas Cassel <cassel@kernel.org> > > Add capability to connect to an administrative controller by > preventing ioq creation for admin-controllers. > > * Add helper nvme_admin_ctrl() to check for an administrative controller > * Add helper nvme_override_prohibited_io_queues() to override > queue_count in nvme_ctrl > > Reference: NVMe Base rev 2.2, sec 3.1.3.4, fig 28. > > Signed-off-by: Kamaljit Singh <kamaljit.singh1@wdc.com> > --- > drivers/nvme/host/core.c | 21 +++++++++++++++++++++ > drivers/nvme/host/nvme.h | 1 + > drivers/nvme/host/rdma.c | 2 ++ > drivers/nvme/host/tcp.c | 2 ++ > 4 files changed, 26 insertions(+) > > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c > index e533d791955d..a1155fb8d5be 100644 > --- a/drivers/nvme/host/core.c > +++ b/drivers/nvme/host/core.c > @@ -3149,6 +3149,22 @@ static inline bool nvme_discovery_ctrl(struct nvme_ctrl *ctrl) > return ctrl->opts && ctrl->opts->discovery_nqn; > } > > +static inline bool nvme_admin_ctrl(struct nvme_ctrl *ctrl) > +{ > + return (ctrl->cntrltype == NVME_CTRL_ADMIN); > +} > + > +/* > + * An admin controller has one admin queue, but no I/O queues. > + * Override queue_count so it only creates an admin queue. > + */ > +void nvme_override_prohibited_io_queues(struct nvme_ctrl *ctrl) > +{ > + if (nvme_admin_ctrl(ctrl)) > + ctrl->queue_count = 1; > +} > +EXPORT_SYMBOL_GPL(nvme_override_prohibited_io_queues); > + > static bool nvme_validate_cntlid(struct nvme_subsystem *subsys, > struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) > { > @@ -3215,6 +3231,11 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) > kfree(subsys); > return -EINVAL; > } > + if (nvme_admin_ctrl(ctrl)) > + dev_info(ctrl->device, > + "Subsystem %s is an administrative controller", > + subsys->subnqn); > + Bzzt. A subsystem is a subsystem, a controller is a controller. Better issue a message when connecting the controller. > nvme_mpath_default_iopolicy(subsys); > > subsys->dev.class = &nvme_subsys_class; > diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h > index 7df2ea21851f..5e07ba634e97 100644 > --- a/drivers/nvme/host/nvme.h > +++ b/drivers/nvme/host/nvme.h > @@ -1212,6 +1212,7 @@ struct nvme_ctrl *nvme_ctrl_from_file(struct file *file); > struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid); > bool nvme_get_ns(struct nvme_ns *ns); > void nvme_put_ns(struct nvme_ns *ns); > +void nvme_override_prohibited_io_queues(struct nvme_ctrl *ctrl); > > static inline bool nvme_multi_css(struct nvme_ctrl *ctrl) > { > diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c > index 9bd3646568d0..7d50a2f31c3a 100644 > --- a/drivers/nvme/host/rdma.c > +++ b/drivers/nvme/host/rdma.c > @@ -1026,6 +1026,8 @@ static int nvme_rdma_setup_ctrl(struct nvme_rdma_ctrl *ctrl, bool new) > goto destroy_admin; > } > > + nvme_override_prohibited_io_queues(&ctrl->ctrl); > + > if (ctrl->ctrl.opts->queue_size > ctrl->ctrl.sqsize + 1) { > dev_warn(ctrl->ctrl.device, > "queue_size %zu > ctrl sqsize %u, clamping down\n", > diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c > index d924008c3949..bfb52a487c45 100644 > --- a/drivers/nvme/host/tcp.c > +++ b/drivers/nvme/host/tcp.c > @@ -2381,6 +2381,8 @@ static int nvme_tcp_setup_ctrl(struct nvme_ctrl *ctrl, bool new) > goto destroy_admin; > } > > + nvme_override_prohibited_io_queues(ctrl); > + > if (opts->queue_size > ctrl->sqsize + 1) > dev_warn(ctrl->device, > "queue_size %zu > ctrl sqsize %u, clamping down\n", And that is a bit convoluted. Why not add a check in 'nvme_set_queue_count' and reduce the number of queues to '1' there? (Then you also have a place to put your message about the admin controller ...) Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
On 7/2/25 09:58, Kamaljit Singh wrote: > Suggested-by: Niklas Cassel <cassel@kernel.org> > > Add capability to connect to an administrative controller by > preventing ioq creation for admin-controllers. > > * Add helper nvme_admin_ctrl() to check for an administrative controller > * Add helper nvme_override_prohibited_io_queues() to override > queue_count in nvme_ctrl > > Reference: NVMe Base rev 2.2, sec 3.1.3.4, fig 28. > > Signed-off-by: Kamaljit Singh <kamaljit.singh1@wdc.com> > --- > drivers/nvme/host/core.c | 21 +++++++++++++++++++++ > drivers/nvme/host/nvme.h | 1 + > drivers/nvme/host/rdma.c | 2 ++ > drivers/nvme/host/tcp.c | 2 ++ > 4 files changed, 26 insertions(+) > > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c > index e533d791955d..a1155fb8d5be 100644 > --- a/drivers/nvme/host/core.c > +++ b/drivers/nvme/host/core.c > @@ -3149,6 +3149,22 @@ static inline bool nvme_discovery_ctrl(struct nvme_ctrl *ctrl) > return ctrl->opts && ctrl->opts->discovery_nqn; > } > > +static inline bool nvme_admin_ctrl(struct nvme_ctrl *ctrl) > +{ > + return (ctrl->cntrltype == NVME_CTRL_ADMIN); No need for the parenthesis. > +} > + > +/* > + * An admin controller has one admin queue, but no I/O queues. > + * Override queue_count so it only creates an admin queue. > + */ > +void nvme_override_prohibited_io_queues(struct nvme_ctrl *ctrl) > +{ > + if (nvme_admin_ctrl(ctrl)) > + ctrl->queue_count = 1; > +} > +EXPORT_SYMBOL_GPL(nvme_override_prohibited_io_queues); Why not have this done in nvme_init_subsystem() ? That would avoid needing to call this in all fabrics drivers. > + > static bool nvme_validate_cntlid(struct nvme_subsystem *subsys, > struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) > { > @@ -3215,6 +3231,11 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) > kfree(subsys); > return -EINVAL; > } > + if (nvme_admin_ctrl(ctrl)) > + dev_info(ctrl->device, > + "Subsystem %s is an administrative controller", > + subsys->subnqn); We do not print an equivalent message for other subsystem controller types. So drop this. > + > nvme_mpath_default_iopolicy(subsys); > > subsys->dev.class = &nvme_subsys_class; -- Damien Le Moal Western Digital Research
© 2016 - 2025 Red Hat, Inc.