nvmet: allow setting model_number once
Subsystems (2)
PATCH 1/1 nvmet: allow setting model_number once
In case we have already established connection to nvmf target, it shouldn't be allowed to change the model_number. E.g. if someone will identify ctrl and get model_number of "my_model" later on will change the model_numbel via configfs to "my_new_model" this will break the NVM specification for "Get Log Page – Persistent Event Log" that refers to Model Number as: "This field contains the same value as reported in the Model Number field of the Identify Controller data structure, bytes 63:24."
Although it doesn't mentioned explicitly that this field can't be changed, we can assume it.
So allow setting this field only once: using configfs or in the first identify ctrl operation.
--- drivers/nvme/target/admin-cmd.c | 33 +++++++++++++------ drivers/nvme/target/configfs.c | 57 ++++++++++++++++++--------------- drivers/nvme/target/core.c | 2 +- drivers/nvme/target/nvmet.h | 7 +--- 4 files changed, 57 insertions(+), 42 deletions(-)
drivers/nvme/target/admin-cmd.c +23 -10
@@ -319,18 +319,25 @@ static void nvmet_execute_get_log_page(struct nvmet_req *req)nvmet_req_complete (req,NVME_SC_INVALID_FIELD |NVME_SC_DNR ); } -static void nvmet_id_set_model_number (struct nvme_id_ctrl *id, +static int nvmet_id_set_model_number (struct nvme_id_ctrl *id,struct nvmet_subsys *subsys) { -const char *model =NVMET_DEFAULT_CTRL_MODEL ; -struct nvmet_subsys_model *subsys_model; +int ret =0 ; -rcu_read_lock (); - subsys_model =rcu_dereference (subsys->model); -if (subsys_model) - model = subsys_model->number; -memcpy_and_pad (id->mn,sizeof (id->mn), model,strlen (model),' ' ); -rcu_read_unlock (); +mutex_lock (&subsys->lock); +if (!subsys->model_number) { + subsys->model_number =kstrdup (NVMET_DEFAULT_CTRL_MODEL , +GFP_KERNEL ); +if (!subsys->model_number) { + ret = -ENOMEM ; + goto out_unlock; + } + } +memcpy_and_pad (id->mn,sizeof (id->mn), subsys->model_number, +strlen (subsys->model_number),' ' ); +out_unlock: +mutex_unlock (&subsys->lock); +return ret; }static void nvmet_execute_identify_ctrl (struct nvmet_req *req)
@@ -339,6 +346,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)struct nvme_id_ctrl *id;u32 cmd_capsule_size;u16 status =0 ; +int ret; id =kzalloc (sizeof (*id),GFP_KERNEL );if (!id) {
@@ -353,7 +361,11 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)memset (id->sn,' ' ,sizeof (id->sn));bin2hex (id->sn, &ctrl->subsys->serial,min (sizeof (ctrl->subsys->serial),sizeof (id->sn) /2 )); -nvmet_id_set_model_number (id, ctrl->subsys); + ret =nvmet_id_set_model_number (id, ctrl->subsys); +if (ret) { + status =NVME_SC_INTERNAL ; + goto out_free; + }memcpy_and_pad (id->fr,sizeof (id->fr),UTS_RELEASE ,strlen (UTS_RELEASE ),' ' );
@@ -461,6 +473,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req) status =nvmet_copy_to_sgl (req,0 , id,sizeof (*id)); +out_free:kfree (id); out:nvmet_req_complete (req, status);
drivers/nvme/target/configfs.c +32 -25
88 lines not on this page · raw message
drivers/nvme/target/core.c +1 -1
@@ -1521,7 +1521,7 @@ static void nvmet_subsys_free(struct kref *ref)nvmet_passthru_subsys_free (subsys);kfree (subsys->subsysnqn); -kfree_rcu (subsys->model, rcuhead); +kfree (subsys->model_number);kfree (subsys); }
drivers/nvme/target/nvmet.h +1 -6
@@ -208,11 +208,6 @@ struct nvmet_ctrl {bool pi_support; }; -struct nvmet_subsys_model { -struct rcu_head rcuhead; -char number[]; -}; -struct nvmet_subsys {enum nvme_subsys_type type;
@@ -242,7 +237,7 @@ struct nvmet_subsys {struct config_group namespaces_group;struct config_group allowed_hosts_group; -struct nvmet_subsys_model __rcu *model; +char *model_number;#ifdef CONFIG_NVME_TARGET_PASSTHRU struct nvme_ctrl *passthru_ctrl;
Signature · 7 lines
2.25.4 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Max,
Quoted 8 lines · Max Gurtovoy
In case we have already established connection to nvmf target, it shouldn't be allowed to change the
model_number. E.g. if someone will identify ctrl and getmodel_numberof "my_model" later on will change themodel_numbelvia configfs to "my_new_model" this will break the NVM specification for "Get Log Page – Persistent Event Log" that refers to Model Number as: "This field contains the same value as reported in the Model Number field of the Identify Controller data structure, bytes 63:24."
We don't support persistent event log page since there is no use case for target to have human readable format with timestamps, instead we do maintain the error log page which has information about the errors if user wants.
I'll let Christoph/Sagi decide if we really need to implement Persistent Event (PE) log and so does this behavior.
Regarding preventing from changing the model_number when subsys is connected to the host, that needs a fix and I sent a patch for that.
We can ignore that patch if we decide to go with this patch with PR log page.
Quoted 5 lines
Although it doesn't mentioned explicitly that this field can't be changed, we can assume it.
So allow setting this field only once: using configfs or in the first identify ctrl operation.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 16 lines · Chaitanya Kulkarni
Max,
Quoted 8 lines · Max Gurtovoy
In case we have already established connection to nvmf target, it shouldn't be allowed to change the
model_number. E.g. if someone will identify ctrl and getmodel_numberof "my_model" later on will change themodel_numbelvia configfs to "my_new_model" this will break the NVM specification for "Get Log Page – Persistent Event Log" that refers to Model Number as: "This field contains the same value as reported in the Model Number field of the Identify Controller data structure, bytes 63:24."We don't support persistent event log page since there is no use case for target to have human readable format with timestamps, instead we do maintain the error log page which has information about the errors if user wants.
Quoted 8 lines
I'll let Christoph/Sagi decide if we really need to implement Persistent Event (PE) log and so does this behavior.
Regarding preventing from changing the
model_numberwhen subsys is connected to the host, that needs a fix and I sent a patch for that.We can ignore that patch if we decide to go with this patch with PR log page.
what is wrong with this patch ?
why you need the rcu logic in the driver and why do you want to preserve a case that initiator A connect to subsystem "my_sub" and see MN == Linux and after disconnect and re-connect it might see MN = New_Linux ?
Quoted 11 lines
Quoted 6 lines
Although it doesn't mentioned explicitly that this field can't be changed, we can assume it.
So allow setting this field only once: using configfs or in the first identify ctrl operation.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerSo looking at this and Chaitanya patch I think this version simplifies things quite nicely, and it also happens to get rid of the RCU annotation sparse warnings.
Let me know what you think of the incremental cleanup and micro-opimization below, though:
drivers/nvme/target/admin-cmd.c +22 -20
@@ -313,34 +313,40 @@ static void nvmet_execute_get_log_page(struct nvmet_req *req)nvmet_req_complete (req,NVME_SC_INVALID_FIELD |NVME_SC_DNR ); } -static int nvmet_id_set_model_number (struct nvme_id_ctrl *id, -struct nvmet_subsys *subsys) +static u16 nvmet_set_model_number (struct nvme_id_ctrl *id, +struct nvmet_subsys *subsys) { -int ret =0 ; +u16 status =0 ;mutex_lock (&subsys->lock);if (!subsys->model_number) { - subsys->model_number =kstrdup (NVMET_DEFAULT_CTRL_MODEL , -GFP_KERNEL ); -if (!subsys->model_number) { - ret = -ENOMEM ; - goto out_unlock; - } + subsys->model_number = +kstrdup (NVMET_DEFAULT_CTRL_MODEL ,GFP_KERNEL ); +if (!subsys->model_number) + status =NVME_SC_INTERNAL ; } -memcpy_and_pad (id->mn,sizeof (id->mn), subsys->model_number, -strlen (subsys->model_number),' ' ); -out_unlock:mutex_unlock (&subsys->lock); -return ret; + +return status; }static void nvmet_execute_identify_ctrl (struct nvmet_req *req) {struct nvmet_ctrl *ctrl = req->sq->ctrl; +struct nvmet_subsys *subsys = ctrl->subsys;struct nvme_id_ctrl *id;u32 cmd_capsule_size;u16 status =0 ; -int ret; + +/* +* If there is no model number yet, so it now. It will then remain +* stable for the life time of the subsystem. +*/ +if (!subsys->model_number) { + status =nvmet_set_model_number (id, subsys); +if (status) + goto out; + } id =kzalloc (sizeof (*id),GFP_KERNEL );if (!id) {
@@ -355,11 +361,8 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)memset (id->sn,' ' ,sizeof (id->sn));bin2hex (id->sn, &ctrl->subsys->serial,min (sizeof (ctrl->subsys->serial),sizeof (id->sn) /2 )); - ret =nvmet_id_set_model_number (id, ctrl->subsys); -if (ret) { - status =NVME_SC_INTERNAL ; - goto out_free; - } +memcpy_and_pad (id->mn,sizeof (id->mn), subsys->model_number, +strlen (subsys->model_number),' ' );memcpy_and_pad (id->fr,sizeof (id->fr),UTS_RELEASE ,strlen (UTS_RELEASE ),' ' );
@@ -467,7 +470,6 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req) status =nvmet_copy_to_sgl (req,0 , id,sizeof (*id)); -out_free:kfree (id); out:nvmet_req_complete (req, status);
drivers/nvme/target/configfs.c +23 -34
90 lines not on this page · raw message
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 51 lines · Christoph Hellwig
So looking at this and Chaitanya patch I think this version simplifies things quite nicely, and it also happens to get rid of the RCU annotation sparse warnings.
Let me know what you think of the incremental cleanup and micro-opimization below, though:
drivers/nvme/target/admin-cmd.c +10
-13@@ -313,34 +313,40 @@ static void nvmet_execute_get_log_page(struct nvmet_req *req)nvmet_req_complete (req,NVME_SC_INVALID_FIELD |NVME_SC_DNR ); } -static int nvmet_id_set_model_number (struct nvme_id_ctrl *id, -struct nvmet_subsys *subsys) +static u16 nvmet_set_model_number (struct nvme_id_ctrl *id, +struct nvmet_subsys *subsys) { -int ret =0 ; +u16 status =0 ;mutex_lock (&subsys->lock);if (!subsys->model_number) { - subsys->model_number =kstrdup (NVMET_DEFAULT_CTRL_MODEL , -GFP_KERNEL ); -if (!subsys->model_number) { - ret = -ENOMEM ; - goto out_unlock; - } + subsys->model_number = +kstrdup (NVMET_DEFAULT_CTRL_MODEL ,GFP_KERNEL ); +if (!subsys->model_number) + status =NVME_SC_INTERNAL ; } -memcpy_and_pad (id->mn,sizeof (id->mn), subsys->model_number, -strlen (subsys->model_number),' ' ); -out_unlock:mutex_unlock (&subsys->lock); -return ret; + +return status; }static void nvmet_execute_identify_ctrl (struct nvmet_req *req) {struct nvmet_ctrl *ctrl = req->sq->ctrl; +struct nvmet_subsys *subsys = ctrl->subsys;struct nvme_id_ctrl *id;
drivers/nvme/target/admin-cmd.c static void nvmet_execute_get_log_page(struct nvmet_req *req) · line 346
Quoted 10 lines
drivers/nvme/target/admin-cmd.c +7
-1u32 cmd_capsule_size;u16 status =0 ; -int ret; + +/* +* If there is no model number yet, so it now. It will then remain +* stable for the life time of the subsystem. +*/ +if (!subsys->model_number) { + status =nvmet_set_model_number (id, subsys);
you don't need the id argument here.
Otherwise looks good and it can be squashed to my patch.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerQuoted 3 lines · Max Gurtovoy
you don't need the id argument here.
Otherwise looks good and it can be squashed to my patch.
Can you resend it with the updates?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 5 lines · Christoph Hellwig
Quoted 3 lines · Max Gurtovoy
you don't need the id argument here.
Otherwise looks good and it can be squashed to my patch.
Can you resend it with the updates?
Yes.
What is the target branch ?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerQuoted 1 line · Max Gurtovoy
What is the target branch ?
nvme-5.12 as just pushed out.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 3 lines · Christoph Hellwig
Quoted 1 line · Max Gurtovoy
What is the target branch ?
nvme-5.12 as just pushed out.
See attached.
From bcdf33f3995417aff47e55d4d06c7fc61a68cf9f Mon Sep 17 00:00:00 2001
From: Max Gurtovoy <[email protected]>
Date: Wed, 17 Feb 2021 17:19:40 +0000
Subject: [PATCH 1/1] nvmet: allow setting model_number once
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
In case we have already established connection to nvmf target, it shouldn't be allowed to change the model_number. E.g. if someone will identify ctrl and get model_number of "my_model" later on will change the model_numbel via configfs to "my_new_model" this will break the NVM specification for "Get Log Page – Persistent Event Log" that refers to Model Number as: "This field contains the same value as reported in the Model Number field of the Identify Controller data structure, bytes 63:24."
Although it doesn't mentioned explicitly that this field can't be changed, we can assume it.
So allow setting this field only once: using configfs or in the first identify ctrl operation.
--- drivers/nvme/target/admin-cmd.c | 36 ++++++++++++++++-------- drivers/nvme/target/configfs.c | 50 +++++++++++++++------------------ drivers/nvme/target/core.c | 2 +- drivers/nvme/target/nvmet.h | 7 +---- 4 files changed, 50 insertions(+), 45 deletions(-)
drivers/nvme/target/admin-cmd.c +25 -11
@@ -313,27 +313,40 @@ static void nvmet_execute_get_log_page(struct nvmet_req *req)nvmet_req_complete (req,NVME_SC_INVALID_FIELD |NVME_SC_DNR ); } -static void nvmet_id_set_model_number (struct nvme_id_ctrl *id, -struct nvmet_subsys *subsys) +static u16 nvmet_set_model_number (struct nvmet_subsys *subsys) { -const char *model =NVMET_DEFAULT_CTRL_MODEL ; -struct nvmet_subsys_model *subsys_model; +u16 status =0 ; + +mutex_lock (&subsys->lock); +if (!subsys->model_number) { + subsys->model_number = +kstrdup (NVMET_DEFAULT_CTRL_MODEL ,GFP_KERNEL ); +if (!subsys->model_number) + status =NVME_SC_INTERNAL ; + } +mutex_unlock (&subsys->lock); -rcu_read_lock (); - subsys_model =rcu_dereference (subsys->model); -if (subsys_model) - model = subsys_model->number; -memcpy_and_pad (id->mn,sizeof (id->mn), model,strlen (model),' ' ); -rcu_read_unlock (); +return status; }static void nvmet_execute_identify_ctrl (struct nvmet_req *req) {struct nvmet_ctrl *ctrl = req->sq->ctrl; +struct nvmet_subsys *subsys = ctrl->subsys;struct nvme_id_ctrl *id;u32 cmd_capsule_size;u16 status =0 ; +/* +* If there is no model number yet, set it now. It will then remain +* stable for the life time of the subsystem. +*/ +if (!subsys->model_number) { + status =nvmet_set_model_number (subsys); +if (status) + goto out; + } + id =kzalloc (sizeof (*id),GFP_KERNEL );if (!id) { status =NVME_SC_INTERNAL ;
@@ -347,7 +360,8 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)memset (id->sn,' ' ,sizeof (id->sn));bin2hex (id->sn, &ctrl->subsys->serial,min (sizeof (ctrl->subsys->serial),sizeof (id->sn) /2 )); -nvmet_id_set_model_number (id, ctrl->subsys); +memcpy_and_pad (id->mn,sizeof (id->mn), subsys->model_number, +strlen (subsys->model_number),' ' );memcpy_and_pad (id->fr,sizeof (id->fr),UTS_RELEASE ,strlen (UTS_RELEASE ),' ' );
drivers/nvme/target/configfs.c +23 -27
81 lines not on this page · raw message
drivers/nvme/target/core.c +1 -1
@@ -1532,7 +1532,7 @@ static void nvmet_subsys_free(struct kref *ref)nvmet_passthru_subsys_free (subsys);kfree (subsys->subsysnqn); -kfree_rcu (subsys->model, rcuhead); +kfree (subsys->model_number);kfree (subsys); }
drivers/nvme/target/nvmet.h +1 -6
@@ -208,11 +208,6 @@ struct nvmet_ctrl {bool pi_support; }; -struct nvmet_subsys_model { -struct rcu_head rcuhead; -char number[]; -}; -struct nvmet_subsys {enum nvme_subsys_type type;
@@ -242,7 +237,7 @@ struct nvmet_subsys {struct config_group namespaces_group;struct config_group allowed_hosts_group; -struct nvmet_subsys_model __rcu *model; +char *model_number;#ifdef CONFIG_NVME_TARGET_PASSTHRU struct nvme_ctrl *passthru_ctrl;
Signature · 1 line
2.18.2
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme