public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 1/2] nvme: introduce nvme_check_ctrl_fabric_info helper
@ 2023-12-05  7:37 Guixin Liu
  2023-12-05  7:37 ` [PATCH 2/2] nvme-fabrics: check ioccsz and iorcsz Guixin Liu
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Guixin Liu @ 2023-12-05  7:37 UTC (permalink / raw)
  To: kbusch, axboe, hch, sagi; +Cc: linux-nvme

Inroduce nvme_check_ctrl_fabric_info helper to check
fabric ctroller info returned by target.

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

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 1be1ce5..4da6ee6 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -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);
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] nvme-fabrics: check ioccsz and iorcsz
  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
  2023-12-05 10:02   ` 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
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 8+ messages in thread
From: Guixin Liu @ 2023-12-05  7:37 UTC (permalink / raw)
  To: kbusch, axboe, hch, sagi; +Cc: linux-nvme

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



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] nvme: introduce nvme_check_ctrl_fabric_info helper
  2023-12-05  7:37 [PATCH 1/2] nvme: introduce nvme_check_ctrl_fabric_info helper Guixin Liu
  2023-12-05  7:37 ` [PATCH 2/2] nvme-fabrics: check ioccsz and iorcsz Guixin Liu
@ 2023-12-05 10:02 ` Sagi Grimberg
  2023-12-06  5:39 ` Christoph Hellwig
  2023-12-06 23:22 ` Keith Busch
  3 siblings, 0 replies; 8+ messages in thread
From: Sagi Grimberg @ 2023-12-05 10:02 UTC (permalink / raw)
  To: Guixin Liu, kbusch, axboe, hch; +Cc: linux-nvme

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] nvme-fabrics: check ioccsz and iorcsz
  2023-12-05  7:37 ` [PATCH 2/2] nvme-fabrics: check ioccsz and iorcsz Guixin Liu
@ 2023-12-05 10:02   ` Sagi Grimberg
  2023-12-06  5:39   ` Christoph Hellwig
  1 sibling, 0 replies; 8+ messages in thread
From: Sagi Grimberg @ 2023-12-05 10:02 UTC (permalink / raw)
  To: Guixin Liu, kbusch, axboe, hch; +Cc: linux-nvme

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] nvme: introduce nvme_check_ctrl_fabric_info helper
  2023-12-05  7:37 [PATCH 1/2] nvme: introduce nvme_check_ctrl_fabric_info helper Guixin Liu
  2023-12-05  7:37 ` [PATCH 2/2] nvme-fabrics: check ioccsz and iorcsz Guixin Liu
  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
  3 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2023-12-06  5:39 UTC (permalink / raw)
  To: Guixin Liu; +Cc: kbusch, axboe, hch, sagi, linux-nvme

> +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.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] nvme-fabrics: check ioccsz and iorcsz
  2023-12-05  7:37 ` [PATCH 2/2] nvme-fabrics: check ioccsz and iorcsz Guixin Liu
  2023-12-05 10:02   ` Sagi Grimberg
@ 2023-12-06  5:39   ` Christoph Hellwig
  1 sibling, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2023-12-06  5:39 UTC (permalink / raw)
  To: Guixin Liu; +Cc: kbusch, axboe, hch, sagi, linux-nvme

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] nvme: introduce nvme_check_ctrl_fabric_info helper
  2023-12-05  7:37 [PATCH 1/2] nvme: introduce nvme_check_ctrl_fabric_info helper Guixin Liu
                   ` (2 preceding siblings ...)
  2023-12-06  5:39 ` Christoph Hellwig
@ 2023-12-06 23:22 ` Keith Busch
  2023-12-06 23:26   ` Keith Busch
  3 siblings, 1 reply; 8+ messages in thread
From: Keith Busch @ 2023-12-06 23:22 UTC (permalink / raw)
  To: Guixin Liu; +Cc: axboe, hch, sagi, linux-nvme

Thanks, series applied for nvme-6.8 with the minor style suggestions for
patch 2.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] nvme: introduce nvme_check_ctrl_fabric_info helper
  2023-12-06 23:22 ` Keith Busch
@ 2023-12-06 23:26   ` Keith Busch
  0 siblings, 0 replies; 8+ messages in thread
From: Keith Busch @ 2023-12-06 23:26 UTC (permalink / raw)
  To: Guixin Liu; +Cc: axboe, hch, sagi, linux-nvme

On Wed, Dec 06, 2023 at 04:22:30PM -0700, Keith Busch wrote:
> Thanks, series applied for nvme-6.8 with the minor style suggestions for
> patch 2.

Sorry, I meant patch 1; same result.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-12-06 23:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-05  7:37 [PATCH 1/2] nvme: introduce nvme_check_ctrl_fabric_info helper Guixin Liu
2023-12-05  7:37 ` [PATCH 2/2] nvme-fabrics: check ioccsz and iorcsz Guixin Liu
2023-12-05 10:02   ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox