linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] nvmet: configfs: use ctrl->instance to track passthru subsystems
@ 2023-12-11 21:37 Evan Burgess
  2023-12-13 13:40 ` Sagi Grimberg
  0 siblings, 1 reply; 2+ messages in thread
From: Evan Burgess @ 2023-12-11 21:37 UTC (permalink / raw)
  To: Christoph Hellwig, sagi, Chaitanya Kulkarni; +Cc: linux-nvme, linux-kernel

To prevent enabling more than one passthrough subsystem per NVMe
controller, passthru.c maintains an xarray indexed by cntlid values.
An nvmet subsystem cannot enable passthrough via configfs if its
passthru_ctrl->cntlid value is already accounted for by the xarray. 

However, according to the NVMe base spec (rev 2.0c, p.145), "The
Controller ID (CNTLID) value returned in the Identify Controller data
structure may be used to uniquely identify a controller within an NVM 
subsystem," meaning that cntlid values are not guaranteed to be
globally unique across multiple subsystems. Instead, the cntlid only 
uniquely identifies multiple controllers _within_ a subsystem.

As a result, multiple unique & valid NVMe targets can be blocked from
enabling passthrough at the same time if their controllers share cntlid
values, a behavior (seemingly) allowed by the spec. This could be
remedied by indexing the xarray with passthru_ctrl->instance values, 
which are allocated per controller by IDA and thus should act as truly
unique controller identifiers.

I have seen this issue in practice, but have found a suspicious lack of 
corroboration across this ML and elsewhere (so far). So, I am not 
discounting a possible misunderstanding of the spec and/or code here.

Signed-off-by: Evan Burgess <evan.burgess@seagate.com>
---
 drivers/nvme/target/passthru.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c
index 9fe07d7efa96..f2d963e1fe94 100644
--- a/drivers/nvme/target/passthru.c
+++ b/drivers/nvme/target/passthru.c
@@ -602,7 +602,7 @@ int nvmet_passthru_ctrl_enable(struct nvmet_subsys *subsys)
 		goto out_put_file;
 	}
 
-	old = xa_cmpxchg(&passthru_subsystems, ctrl->cntlid, NULL,
+	old = xa_cmpxchg(&passthru_subsystems, ctrl->instance, NULL,
 			 subsys, GFP_KERNEL);
 	if (xa_is_err(old)) {
 		ret = xa_err(old);
@@ -635,7 +635,7 @@ int nvmet_passthru_ctrl_enable(struct nvmet_subsys *subsys)
 static void __nvmet_passthru_ctrl_disable(struct nvmet_subsys *subsys)
 {
 	if (subsys->passthru_ctrl) {
-		xa_erase(&passthru_subsystems, subsys->passthru_ctrl->cntlid);
+		xa_erase(&passthru_subsystems, subsys->passthru_ctrl->instance);
 		module_put(subsys->passthru_ctrl->ops->module);
 		nvme_put_ctrl(subsys->passthru_ctrl);
 	}
-- 
2.34.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [RFC] nvmet: configfs: use ctrl->instance to track passthru subsystems
  2023-12-11 21:37 [RFC] nvmet: configfs: use ctrl->instance to track passthru subsystems Evan Burgess
@ 2023-12-13 13:40 ` Sagi Grimberg
  0 siblings, 0 replies; 2+ messages in thread
From: Sagi Grimberg @ 2023-12-13 13:40 UTC (permalink / raw)
  To: Evan Burgess, Christoph Hellwig, Chaitanya Kulkarni
  Cc: linux-nvme, linux-kernel


> To prevent enabling more than one passthrough subsystem per NVMe
> controller, passthru.c maintains an xarray indexed by cntlid values.
> An nvmet subsystem cannot enable passthrough via configfs if its
> passthru_ctrl->cntlid value is already accounted for by the xarray.
> 
> However, according to the NVMe base spec (rev 2.0c, p.145), "The
> Controller ID (CNTLID) value returned in the Identify Controller data
> structure may be used to uniquely identify a controller within an NVM
> subsystem," meaning that cntlid values are not guaranteed to be
> globally unique across multiple subsystems. Instead, the cntlid only
> uniquely identifies multiple controllers _within_ a subsystem.
> 
> As a result, multiple unique & valid NVMe targets can be blocked from
> enabling passthrough at the same time if their controllers share cntlid
> values, a behavior (seemingly) allowed by the spec. This could be
> remedied by indexing the xarray with passthru_ctrl->instance values,
> which are allocated per controller by IDA and thus should act as truly
> unique controller identifiers.
> 
> I have seen this issue in practice, but have found a suspicious lack of
> corroboration across this ML and elsewhere (so far). So, I am not
> discounting a possible misunderstanding of the spec and/or code here.

You are correct AFAICT.
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-12-13 13:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-11 21:37 [RFC] nvmet: configfs: use ctrl->instance to track passthru subsystems Evan Burgess
2023-12-13 13:40 ` Sagi Grimberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).