[PATCH] nvmet: check that host sqsize does not exceed ctrl MQES

amit.engel at dell.com amit.engel at dell.com
Sun Jul 25 22:25:35 PDT 2021


From: Amit Engel <amit.engel at dell.com>

Check that host sqsize is not greater-than
Maximum Queue Entries Supported (MQES) by the ctrl

Signed-off-by: Amit Engel <amit.engel at dell.com>
---
 drivers/nvme/target/fabrics-cmd.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/nvme/target/fabrics-cmd.c b/drivers/nvme/target/fabrics-cmd.c
index 7d0f3523fdab..bc9407525d2c 100644
--- a/drivers/nvme/target/fabrics-cmd.c
+++ b/drivers/nvme/target/fabrics-cmd.c
@@ -109,6 +109,7 @@ static u16 nvmet_install_queue(struct nvmet_ctrl *ctrl, struct nvmet_req *req)
 	u16 qid = le16_to_cpu(c->qid);
 	u16 sqsize = le16_to_cpu(c->sqsize);
 	struct nvmet_ctrl *old;
+	u16 mqes = ctrl->cap & 0xffff;
 	u16 ret;
 
 	old = cmpxchg(&req->sq->ctrl, NULL, ctrl);
@@ -123,6 +124,13 @@ static u16 nvmet_install_queue(struct nvmet_ctrl *ctrl, struct nvmet_req *req)
 		ret = NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR;
 		goto err;
 	}
+	/* sqsize is not allowed to exceed Maximum Queue Entries Supported (MQES) */
+	if (sqsize > mqes) {
+		pr_warn("sqsize %u is larger than MQES supported %u cntlid %d\n",
+				sqsize, mqes, ctrl->cntlid);
+		req->error_loc = offsetof(struct nvmf_connect_command, sqsize);
+		return NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR;
+	}
 
 	/* note: convert queue size from 0's-based value to 1's-based value */
 	nvmet_cq_setup(ctrl, req->cq, qid, sqsize + 1);
-- 
2.18.2




More information about the Linux-nvme mailing list