public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
From: Guixin Liu <kanie@linux.alibaba.com>
To: kbusch@kernel.org, axboe@kernel.dk, hch@lst.de, sagi@grimberg.me
Cc: linux-nvme@lists.infradead.org
Subject: [PATCH 2/2] nvme-fabrics: check ioccsz and iorcsz
Date: Tue,  5 Dec 2023 15:37:40 +0800	[thread overview]
Message-ID: <1701761860-17623-2-git-send-email-kanie@linux.alibaba.com> (raw)
In-Reply-To: <1701761860-17623-1-git-send-email-kanie@linux.alibaba.com>

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.

Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
 drivers/nvme/host/core.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 4da6ee6..87db4a9 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3043,6 +3043,20 @@ static int nvme_check_ctrl_fabric_info(struct nvme_ctrl *ctrl, struct nvme_id_ct
 		return -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;
 }
 
-- 
1.8.3.1



  reply	other threads:[~2023-12-05  7:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-05  7:37 [PATCH 1/2] nvme: introduce nvme_check_ctrl_fabric_info helper Guixin Liu
2023-12-05  7:37 ` Guixin Liu [this message]
2023-12-05 10:02   ` [PATCH 2/2] nvme-fabrics: check ioccsz and iorcsz Sagi Grimberg
2023-12-06  5:39   ` Christoph Hellwig
2023-12-05 10:02 ` [PATCH 1/2] nvme: introduce nvme_check_ctrl_fabric_info helper Sagi Grimberg
2023-12-06  5:39 ` Christoph Hellwig
2023-12-06 23:22 ` Keith Busch
2023-12-06 23:26   ` Keith Busch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1701761860-17623-2-git-send-email-kanie@linux.alibaba.com \
    --to=kanie@linux.alibaba.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox