nvme: introduce nvme_check_ctrl_fabric_info helper
PATCH 1/2 nvme: introduce nvme_check_ctrl_fabric_info helper
Inroduce nvme_check_ctrl_fabric_info helper to check fabric ctroller info returned by target.
--- drivers/nvme/host/core.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-)
drivers/nvme/host/core.c +24 -18
@@ -3024,6 +3024,28 @@ static int nvme_init_effects(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)return 0 ; } +static int nvme_check_ctrl_fabric_info (struct nvme_ctrl *ctrl,struct nvme_id_ctrl *id) +{ +/* +* In fabrics we need to verify the cntlid matches the +* admin connect +*/ +if (ctrl->cntlid !=le16_to_cpu (id->cntlid)) { +dev_err (ctrl->device, +"Mismatching cntlid: Connect %u vs Identify %u, rejecting\n" , + ctrl->cntlid,le16_to_cpu (id->cntlid)); +return -EINVAL ; + } + +if (!nvme_discovery_ctrl (ctrl) && !ctrl->kas) { +dev_err (ctrl->device, +"keep-alive support is mandatory for fabrics\n" ); +return -EINVAL ; + } + +return 0 ; +} +static int nvme_init_identify (struct nvme_ctrl *ctrl) {struct nvme_id_ctrl *id;
@@ -3136,25 +3158,9 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl) ctrl->iorcsz =le32_to_cpu (id->iorcsz); ctrl->maxcmd =le16_to_cpu (id->maxcmd); -/* -* In fabrics we need to verify the cntlid matches the -* admin connect -*/ -if (ctrl->cntlid !=le16_to_cpu (id->cntlid)) { -dev_err (ctrl->device, -"Mismatching cntlid: Connect %u vs Identify " -"%u, rejecting\n" , - ctrl->cntlid,le16_to_cpu (id->cntlid)); - ret = -EINVAL ; - goto out_free; - } - -if (!nvme_discovery_ctrl (ctrl) && !ctrl->kas) { -dev_err (ctrl->device, -"keep-alive support is mandatory for fabrics\n" ); - ret = -EINVAL ; + ret =nvme_check_ctrl_fabric_info (ctrl, id); +if (ret) goto out_free; - } }else { ctrl->hmpre =le32_to_cpu (id->hmpre); ctrl->hmmin =le32_to_cpu (id->hmmin);
Signature · 1 line
1.8.3.1
PATCH 2/2 nvme-fabrics: check ioccsz and iorcsz
Make sure that ioccsz and iorcsz returned by target are correct before use it.
Per 2.0a base NVMe spec:
I/O Queue Command Capsule Supported Size (IOCCSZ): This field defines the maximum I/O command capsule size in 16 byte units. The minimum value that shall be indicated is 4 corresponding to 64 bytes.
I/O Queue Response Capsule Supported Size (IORCSZ): This field defines the maximum I/O response capsule size in 16 byte units. The minimum value that shall be indicated is 1 corresponding to 16 bytes.
--- drivers/nvme/host/core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/nvme/host/core.c +14 -0
@@ -3043,6 +3043,20 @@ static int nvme_check_ctrl_fabric_info(struct nvme_ctrl *ctrl, struct nvme_id_ctreturn -EINVAL ; } +if (ctrl->ioccsz <4 ) { +dev_err (ctrl->device, +"I/O queue command capsule supported size %d < 4\n" , + ctrl->ioccsz); +return -EINVAL ; + } + +if (ctrl->iorcsz <1 ) { +dev_err (ctrl->device, +"I/O queue response capsule supported size %d < 1\n" , + ctrl->iorcsz); +return -EINVAL ; + } +return 0 ; }
Signature · 1 line
1.8.3.1
Re: [PATCH 2/2] nvme-fabrics: check ioccsz and iorcsz
Re: [PATCH 2/2] nvme-fabrics: check ioccsz and iorcsz
In reply to Guixin LiuLooks good:
Christoph Hellwig
maintainerQuoted 1 line
+static int
nvme_check_ctrl_fabric_info(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
Overly long line.
I'd also rename this to something like nvmf_validate_identify_ctrl.
Otherwise this looks good.
Keith Busch
maintainerThanks, series applied for nvme-6.8 with the minor style suggestions for patch 2.
Keith Busch
maintainerQuoted 2 lines · Keith Busch
Thanks, series applied for nvme-6.8 with the minor style suggestions for patch 2.
Sorry, I meant patch 1; same result.