nvmet: force reconnect when number of queue changes
Subsystems (2)
PATCH v3 1/1 nvmet: force reconnect when number of queue changes
In order to test queue number changes we need to make sure that the host reconnects. Because only when the host disconnects from the target the number of queues are allowed to change according the spec.
The initial idea was to disable and re-enable the ports and have the host wait until the KATO timer expires, triggering error recovery. Though the host would see a DNR reply when trying to reconnect. Because of the DNR bit the connection is dropped completely. There is no point in trying to reconnect with the same parameters according the spec.
We can force to reconnect the host is by deleting all controllers. The host will observe any newly posted request to fail and thus starts the error recovery but this time without the DNR bit set.
Also, the item passed into nvmet_subsys_attr_qid_max_show is not a member of struct nvmet_port, it is part of nvmet_subsys. Hence, don't try to dereference it as struct nvme_ctrl pointer.
---
v3:
- Updated Fixes tag
- Updated commit message with some additional information from the v2 discussion
v2:
- instead preventing changes, force reconnect by delete ctrls
- renamed patch
- https://lore.kernel.org/linux-nvme/[email protected]/
v1:
- initial verison
- https://lore.kernel.org/linux-nvme/[email protected]/
drivers/nvme/target/configfs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/nvme/target/configfs.c +8 -5
@@ -1290,12 +1290,10 @@ static ssize_t nvmet_subsys_attr_qid_max_show(struct config_item *item,static ssize_t nvmet_subsys_attr_qid_max_store (struct config_item *item,const char *page,size_t cnt) { -struct nvmet_port *port =to_nvmet_port (item); +struct nvmet_subsys *subsys =to_subsys (item); +struct nvmet_ctrl *ctrl;u16 qid_max; -if (nvmet_is_port_enabled (port, __func__)) -return -EACCES ; -if (sscanf (page,"%hu\n" , &qid_max) !=1 )return -EINVAL ;
@@ -1303,8 +1301,13 @@ static ssize_t nvmet_subsys_attr_qid_max_store(struct config_item *item,return -EINVAL ;down_write (&nvmet_config_sem); -to_subsys (item)->max_qid = qid_max; + subsys->max_qid = qid_max; + +/* Force reconnect */ +list_for_each_entry (ctrl, &subsys->ctrls, subsys_entry) + ctrl->ops->delete_ctrl (ctrl);up_write (&nvmet_config_sem); +return cnt; }CONFIGFS_ATTR (nvmet_subsys_, attr_qid_max);
Signature · 1 line
2.37.3
Quoted 34 lines · Daniel Wagner
In order to test queue number changes we need to make sure that the host reconnects. Because only when the host disconnects from the target the number of queues are allowed to change according the spec.
The initial idea was to disable and re-enable the ports and have the host wait until the KATO timer expires, triggering error recovery. Though the host would see a DNR reply when trying to reconnect. Because of the DNR bit the connection is dropped completely. There is no point in trying to reconnect with the same parameters according the spec.
We can force to reconnect the host is by deleting all controllers. The host will observe any newly posted request to fail and thus starts the error recovery but this time without the DNR bit set.
Also, the item passed into
nvmet_subsys_attr_qid_max_showis not a member of structnvmet_port, it is part ofnvmet_subsys. Hence, don't try to dereference it as structnvme_ctrlpointer.Fixes 3e980f5995e0 ("nvmet: Expose max queues to configfs")Reported-by Shinichiro Kawasaki <[email protected]>Signed-off-by Daniel Wagner <[email protected]>---
v3:
- Updated Fixes tag
- Updated commit message with some additional information from the v2 discussionv2:
- instead preventing changes, force reconnect by delete ctrls
- renamed patch
- https://lore.kernel.org/linux-nvme/[email protected]/
Quoted 7 lines
v1:
- initial verison
- https://lore.kernel.org/linux-nvme/[email protected]/drivers/nvme/target/configfs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Ivo Totev, Andrew Myers, Andrew McDonald, Martje Boudien Moerman
Hi Christoph,
Please consider to add the patch for the current rc phase as it fixes an invalid memory access and I would like to avoid that the code fuzzer army is going after us :)
Thanks,
Daniel
Quoted 5 lines · Daniel Wagner
Hi Christoph,
Please consider to add the patch for the current rc phase as it fixes an invalid memory access and I would like to avoid that the code fuzzer army is going after us :)
I filed this under enhancement and planned to add it to 6.2. Canyou explain the invalid memory access a bit more?
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Daniel Wagner
Hi Christoph,
Please consider to add the patch for the current rc phase as it fixes an invalid memory access and I would like to avoid that the code fuzzer army is going after us :)
I filed this under enhancement and planned to add it to 6.2. Canyou explain the invalid memory access a bit more?
I guess this would the minimal memory access fix?
---
From c881123281d429da61ebd049c0867f8520dbfcb3 Mon Sep 17 00:00:00 2001
From: Daniel Wagner <[email protected]>
Date: Fri, 7 Oct 2022 09:29:34 +0200
Subject: nvmet: fix invalid memory reference in nvmet_subsys_attr_qid_max_show
The item passed into nvmet_subsys_attr_qid_max_show is not a member of struct nvmet_port, it is part of nvmet_subsys. Hence, don't try to dereference it as struct nvme_ctrl pointer.
--- drivers/nvme/target/configfs.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/nvme/target/configfs.c +0 -4
@@ -1290,12 +1290,8 @@ static ssize_t nvmet_subsys_attr_qid_max_show(struct config_item *item,static ssize_t nvmet_subsys_attr_qid_max_store (struct config_item *item,const char *page,size_t cnt) { -struct nvmet_port *port =to_nvmet_port (item);u16 qid_max; -if (nvmet_is_port_enabled (port, __func__)) -return -EACCES ; -if (sscanf (page,"%hu\n" , &qid_max) !=1 )return -EINVAL ;
Signature · 1 line
2.30.2
Quoted 4 lines · Christoph Hellwig
Quoted 3 lines · Christoph Hellwig
Quoted 2 lines · Daniel Wagner
Hi Christoph,
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Please consider to add the patch for the current rc phase as it fixes an invalid memory access and I would like to avoid that the code fuzzer army is going after us :)
I filed this under enhancement and planned to add it to 6.2. Canyou explain the invalid memory access a bit more?
I guess this would the minimal memory access fix?
Yes, this is the correct fix. Thanks!