Skip to contentSkip to conversation

IB/srp: Add RDMA/CM support

PATCH RESEND Superseded Bart Van Assche 3 participants 20 messages Jan 4, 2018 – Jan 5, 2018 11 messages not in the archive

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover IB/srp: Add RDMA/CM support

Hello Jason,

The four patches in this series add RDMA/CM support to the SRP initiator. Please consider these patches for kernel v4.16.

Thanks,

Bart.

Bart Van Assche (4):
IB/srp: Use kstrtoull() instead of simple_strtoull() IB/srp: Make the path record query error message more informative IB/srp: Refactor srp_send_req()
IB/srp: Add RDMA/CM support

 drivers/infiniband/ulp/srp/ib_srp.c | 744 ++++++++++++++++++++++++++++--------
 drivers/infiniband/ulp/srp/ib_srp.h |  41 +-
 include/scsi/srp.h                  |  17 +
 3 files changed, 636 insertions(+), 166 deletions(-)
Signature · 6 lines
2.15.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

PATCH RESEND 1/4 IB/srp: Use kstrtoull() instead of simple_strtoull()

In reply to a message not in the archive

Use kstrtoull() since simple_strtoull() is deprecated. This patch improves error checking but otherwise does not change any functionality.

---
 drivers/infiniband/ulp/srp/ib_srp.c | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)
drivers/infiniband/ulp/srp/ib_srp.c +29 -4
index 62d88212c1b0..39b3e43efbbe 100644
@@ -3111,6 +3111,7 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
 	char *options, *sep_opt;
 	char *p;
 	substring_t args[MAX_OPT_ARGS];
+	unsigned long long ull;
 	int opt_mask = 0;
 	int token;
 	int ret = -EINVAL;
@@ -3135,7 +3136,13 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
 				ret = -ENOMEM;
 				goto out;
 			}
-			target->id_ext = cpu_to_be64(simple_strtoull(p, NULL, 16));
+			ret = kstrtoull(p, 16, &ull);
+			if (ret) {
+				pr_warn("invalid id_ext parameter '%s'\n", p);
+				kfree(p);
+				goto out;
+			}
+			target->id_ext = cpu_to_be64(ull);
 			kfree(p);
 			break;
 
@@ -3145,7 +3152,13 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
 				ret = -ENOMEM;
 				goto out;
 			}
-			target->ioc_guid = cpu_to_be64(simple_strtoull(p, NULL, 16));
+			ret = kstrtoull(p, 16, &ull);
+			if (ret) {
+				pr_warn("invalid ioc_guid parameter '%s'\n", p);
+				kfree(p);
+				goto out;
+			}
+			target->ioc_guid = cpu_to_be64(ull);
 			kfree(p);
 			break;
 
@@ -3181,7 +3194,13 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
 				ret = -ENOMEM;
 				goto out;
 			}
-			target->service_id = cpu_to_be64(simple_strtoull(p, NULL, 16));
+			ret = kstrtoull(p, 16, &ull);
+			if (ret) {
+				pr_warn("bad service_id parameter '%s'\n", p);
+				kfree(p);
+				goto out;
+			}
+			target->service_id = cpu_to_be64(ull);
 			kfree(p);
 			break;
 
@@ -3235,7 +3254,13 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
 				ret = -ENOMEM;
 				goto out;
 			}
-			target->initiator_ext = cpu_to_be64(simple_strtoull(p, NULL, 16));
+			ret = kstrtoull(p, 16, &ull);
+			if (ret) {
+				pr_warn("bad initiator_ext value '%s'\n", p);
+				kfree(p);
+				goto out;
+			}
+			target->initiator_ext = cpu_to_be64(ull);
 			kfree(p);
 			break;
 
Signature · 6 lines
2.15.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

PATCH RESEND 2/4 IB/srp: Make the path record query error message more informative

In reply to a message not in the archive

Show all path record query parameters if a path record query fails.

---
 drivers/infiniband/ulp/srp/ib_srp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/infiniband/ulp/srp/ib_srp.c +4 -1
index 39b3e43efbbe..fec6e800adf4 100644
@@ -702,7 +702,10 @@ static int srp_lookup_path(struct srp_rdma_ch *ch)
 	ret = ch->status;
 	if (ret < 0)
 		shost_printk(KERN_WARNING, target->scsi_host,
-			     PFX "Path record query failed\n");
+			     PFX "Path record query failed: sgid %pI6, dgid %pI6, pkey %#04x, service_id %#16llx\n",
+			     ch->path.sgid.raw, ch->path.dgid.raw,
+			     be16_to_cpu(target->pkey),
+			     be64_to_cpu(target->service_id));
 
 put:
 	scsi_host_put(target->scsi_host);
Signature · 6 lines
2.15.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

PATCH RESEND 3/4 IB/srp: Refactor srp_send_req()

In reply to a message not in the archive

This patch does not change any functionality but makes the next patch in this series easier to read.

---
 drivers/infiniband/ulp/srp/ib_srp.c | 65 +++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 31 deletions(-)
drivers/infiniband/ulp/srp/ib_srp.c +34 -31
index fec6e800adf4..9472f5989d27 100644
@@ -738,35 +738,21 @@ static int srp_send_req(struct srp_rdma_ch *ch, bool multich)
 		struct ib_cm_req_param param;
 		struct srp_login_req   priv;
 	} *req = NULL;
+	char *ipi, *tpi;
 	int status;
-	u8 subnet_timeout;
-
-	subnet_timeout = srp_get_subnet_timeout(target->srp_host);
 
 	req = kzalloc(sizeof *req, GFP_KERNEL);
 	if (!req)
 		return -ENOMEM;
 
-	req->param.primary_path		      = &ch->path;
-	req->param.alternate_path 	      = NULL;
-	req->param.service_id 		      = target->service_id;
-	req->param.qp_num		      = ch->qp->qp_num;
-	req->param.qp_type		      = ch->qp->qp_type;
-	req->param.private_data 	      = &req->priv;
-	req->param.private_data_len 	      = sizeof req->priv;
 	req->param.flow_control 	      = 1;
-
-	get_random_bytes(&req->param.starting_psn, 4);
-	req->param.starting_psn 	     &= 0xffffff;
+	req->param.retry_count                = target->tl_retry_count;
 
 	/*
 	 * Pick some arbitrary defaults here; we could make these
 	 * module parameters if anyone cared about setting them.
 	 */
 	req->param.responder_resources	      = 4;
-	req->param.remote_cm_response_timeout = subnet_timeout + 2;
-	req->param.local_cm_response_timeout  = subnet_timeout + 2;
-	req->param.retry_count                = target->tl_retry_count;
 	req->param.rnr_retry_count 	      = 7;
 	req->param.max_cm_retries 	      = 15;
 
@@ -777,6 +763,28 @@ static int srp_send_req(struct srp_rdma_ch *ch, bool multich)
 					      SRP_BUF_FORMAT_INDIRECT);
 	req->priv.req_flags	= (multich ? SRP_MULTICHAN_MULTI :
 				   SRP_MULTICHAN_SINGLE);
+
+	{
+		u8 subnet_timeout;
+
+		subnet_timeout = srp_get_subnet_timeout(target->srp_host);
+
+		req->param.primary_path = &ch->path;
+		req->param.alternate_path = NULL;
+		req->param.service_id = target->service_id;
+		get_random_bytes(&req->param.starting_psn, 4);
+		req->param.starting_psn &= 0xffffff;
+		req->param.qp_num = ch->qp->qp_num;
+		req->param.qp_type = ch->qp->qp_type;
+		req->param.local_cm_response_timeout = subnet_timeout + 2;
+		req->param.remote_cm_response_timeout = subnet_timeout + 2;
+		req->param.private_data = &req->priv;
+		req->param.private_data_len = sizeof(req->priv);
+
+		ipi = req->priv.initiator_port_id;
+		tpi = req->priv.target_port_id;
+	}
+
 	/*
 	 * In the published SRP specification (draft rev. 16a), the
 	 * port identifier format is 8 bytes of ID extension followed
@@ -787,19 +795,15 @@ static int srp_send_req(struct srp_rdma_ch *ch, bool multich)
 	 * recognized by the I/O Class they report.
 	 */
 	if (target->io_class == SRP_REV10_IB_IO_CLASS) {
-		memcpy(req->priv.initiator_port_id,
-		       &target->sgid.global.interface_id, 8);
-		memcpy(req->priv.initiator_port_id + 8,
-		       &target->initiator_ext, 8);
-		memcpy(req->priv.target_port_id,     &target->ioc_guid, 8);
-		memcpy(req->priv.target_port_id + 8, &target->id_ext, 8);
+		memcpy(ipi,     &target->sgid.global.interface_id, 8);
+		memcpy(ipi + 8, &target->initiator_ext, 8);
+		memcpy(tpi,     &target->ioc_guid, 8);
+		memcpy(tpi + 8, &target->id_ext, 8);
 	} else {
-		memcpy(req->priv.initiator_port_id,
-		       &target->initiator_ext, 8);
-		memcpy(req->priv.initiator_port_id + 8,
-		       &target->sgid.global.interface_id, 8);
-		memcpy(req->priv.target_port_id,     &target->id_ext, 8);
-		memcpy(req->priv.target_port_id + 8, &target->ioc_guid, 8);
+		memcpy(ipi,     &target->initiator_ext, 8);
+		memcpy(ipi + 8, &target->sgid.global.interface_id, 8);
+		memcpy(tpi,     &target->id_ext, 8);
+		memcpy(tpi + 8, &target->ioc_guid, 8);
 	}
 
 	/*
@@ -812,9 +816,8 @@ static int srp_send_req(struct srp_rdma_ch *ch, bool multich)
 			     PFX "Topspin/Cisco initiator port ID workaround "
 			     "activated for target GUID %016llx\n",
 			     be64_to_cpu(target->ioc_guid));
-		memset(req->priv.initiator_port_id, 0, 8);
-		memcpy(req->priv.initiator_port_id + 8,
-		       &target->srp_host->srp_dev->dev->node_guid, 8);
+		memset(ipi, 0, 8);
+		memcpy(ipi + 8, &target->srp_host->srp_dev->dev->node_guid, 8);
 	}
 
 	status = ib_send_cm_req(ch->cm_id, &req->param);
Signature · 6 lines
2.15.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw

PATCH RESEND 4/4 IB/srp: Add RDMA/CM support

In reply to a message not in the archive

Since the SRP_LOGIN_REQ defined in the SRP standard is larger than what fits in the RDMA/CM login request private data, introduce a new login request format for the RDMA/CM. Add a kernel module parameter to the ib_srp kernel driver that allows to specify the port on which to listen for RDMA/CM connections. The default value for this kernel module parameter is 0, which means not to listen for RDMA/CM connections.

Note: since srp_daemon and ibsrpdm rely on the subnet manager and since there is no equivalent of the IB subnet manager in non-IB networks, login has to be performed manually for non-IB networks.

---
 drivers/infiniband/ulp/srp/ib_srp.c | 683 ++++++++++++++++++++++++++++--------
 drivers/infiniband/ulp/srp/ib_srp.h |  41 ++-
 include/scsi/srp.h                  |  17 +
 3 files changed, 590 insertions(+), 151 deletions(-)
drivers/infiniband/ulp/srp/ib_srp.c +539 -144
index 9472f5989d27..6f59bf715a0d 100644
@@ -41,6 +41,7 @@
 #include <linux/random.h>
 #include <linux/jiffies.h>
 #include <linux/lockdep.h>
+#include <linux/inet.h>
 #include <rdma/ib_cache.h>
 
 #include <linux/atomic.h>
@@ -144,7 +145,9 @@ static void srp_remove_one(struct ib_device *device, void *client_data);
 static void srp_recv_done(struct ib_cq *cq, struct ib_wc *wc);
 static void srp_handle_qp_err(struct ib_cq *cq, struct ib_wc *wc,
 		const char *opname);
-static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event);
+static int srp_ib_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event);
+static int srp_rdma_cm_handler(struct rdma_cm_id *cm_id,
+			       struct rdma_cm_event *event);
 
 static struct scsi_transport_template *ib_srp_transport_template;
 static struct workqueue_struct *srp_remove_wq;
@@ -265,8 +268,8 @@ static void srp_qp_event(struct ib_event *event, void *context)
 		 ib_event_msg(event->event), event->event);
 }
 
-static int srp_init_qp(struct srp_target_port *target,
-		       struct ib_qp *qp)
+static int srp_init_ib_qp(struct srp_target_port *target,
+			  struct ib_qp *qp)
 {
 	struct ib_qp_attr *attr;
 	int ret;
@@ -277,7 +280,7 @@ static int srp_init_qp(struct srp_target_port *target,
 
 	ret = ib_find_cached_pkey(target->srp_host->srp_dev->dev,
 				  target->srp_host->port,
-				  be16_to_cpu(target->pkey),
+				  be16_to_cpu(target->ib_cm.pkey),
 				  &attr->pkey_index);
 	if (ret)
 		goto out;
@@ -298,32 +301,110 @@ static int srp_init_qp(struct srp_target_port *target,
 	return ret;
 }
 
-static int srp_new_cm_id(struct srp_rdma_ch *ch)
+static int srp_new_ib_cm_id(struct srp_rdma_ch *ch)
 {
 	struct srp_target_port *target = ch->target;
 	struct ib_cm_id *new_cm_id;
 
 	new_cm_id = ib_create_cm_id(target->srp_host->srp_dev->dev,
-				    srp_cm_handler, ch);
+				    srp_ib_cm_handler, ch);
 	if (IS_ERR(new_cm_id))
 		return PTR_ERR(new_cm_id);
 
-	if (ch->cm_id)
-		ib_destroy_cm_id(ch->cm_id);
-	ch->cm_id = new_cm_id;
+	if (ch->ib_cm.cm_id)
+		ib_destroy_cm_id(ch->ib_cm.cm_id);
+	ch->ib_cm.cm_id = new_cm_id;
 	if (rdma_cap_opa_ah(target->srp_host->srp_dev->dev,
 			    target->srp_host->port))
-		ch->path.rec_type = SA_PATH_REC_TYPE_OPA;
+		ch->ib_cm.path.rec_type = SA_PATH_REC_TYPE_OPA;
 	else
-		ch->path.rec_type = SA_PATH_REC_TYPE_IB;
-	ch->path.sgid = target->sgid;
-	ch->path.dgid = target->orig_dgid;
-	ch->path.pkey = target->pkey;
-	ch->path.service_id = target->service_id;
+		ch->ib_cm.path.rec_type = SA_PATH_REC_TYPE_IB;
+	ch->ib_cm.path.sgid = target->sgid;
+	ch->ib_cm.path.dgid = target->ib_cm.orig_dgid;
+	ch->ib_cm.path.pkey = target->ib_cm.pkey;
+	ch->ib_cm.path.service_id = target->ib_cm.service_id;
 
 	return 0;
 }
 
+static const char *inet_ntop(const void *sa, char *dst, unsigned int size)
+{
+	switch (((struct sockaddr *)sa)->sa_family) {
+	case AF_INET:
+		snprintf(dst, size, "%pI4",
+			 &((struct sockaddr_in *)sa)->sin_addr);
+		break;
+	case AF_INET6:
+		snprintf(dst, size, "%pI6",
+			 &((struct sockaddr_in6 *)sa)->sin6_addr);
+		break;
+	default:
+		snprintf(dst, size, "???");
+		break;
+	}
+	return dst;
+}
+
+static int srp_new_rdma_cm_id(struct srp_rdma_ch *ch)
+{
+	struct srp_target_port *target = ch->target;
+	struct rdma_cm_id *new_cm_id;
+	char src_addr[64], dst_addr[64];
+	int ret;
+
+	new_cm_id = rdma_create_id(&init_net, srp_rdma_cm_handler, ch,
+				   RDMA_PS_TCP, IB_QPT_RC);
+	if (IS_ERR(new_cm_id)) {
+		ret = PTR_ERR(new_cm_id);
+		new_cm_id = NULL;
+		goto out;
+	}
+
+	init_completion(&ch->done);
+	ret = rdma_resolve_addr(new_cm_id, target->rdma_cm.src_specified ?
+				(struct sockaddr *)&target->rdma_cm.src : NULL,
+				(struct sockaddr *)&target->rdma_cm.dst,
+				SRP_PATH_REC_TIMEOUT_MS);
+	if (ret) {
+		pr_err("No route available from %s to %s (%d)\n",
+		       target->rdma_cm.src_specified ?
+		       inet_ntop(&target->rdma_cm.src, src_addr,
+				 sizeof(src_addr)) : "(any)",
+		       inet_ntop(&target->rdma_cm.dst, dst_addr,
+				 sizeof(dst_addr)),
+		       ret);
+		goto out;
+	}
+	ret = wait_for_completion_interruptible(&ch->done);
+	if (ret < 0)
+		goto out;
+
+	ret = ch->status;
+	if (ret) {
+		pr_err("Resolving address %s failed (%d)\n",
+		       inet_ntop(&target->rdma_cm.dst, dst_addr,
+				 sizeof(dst_addr)),
+		       ret);
+		goto out;
+	}
+
+	swap(ch->rdma_cm.cm_id, new_cm_id);
+
+out:
+	if (new_cm_id)
+		rdma_destroy_id(new_cm_id);
+
+	return ret;
+}
+
+static int srp_new_cm_id(struct srp_rdma_ch *ch)
+{
+	struct srp_target_port *target = ch->target;
+
+	return target->using_rdma_cm ? srp_new_rdma_cm_id(ch) :
+		srp_new_ib_cm_id(ch);
+}
+
 static struct ib_fmr_pool *srp_alloc_fmr_pool(struct srp_target_port *target)
 {
 	struct srp_device *dev = target->srp_host->srp_dev;
@@ -521,16 +602,25 @@ static int srp_create_ch_ib(struct srp_rdma_ch *ch)
 	init_attr->send_cq             = send_cq;
 	init_attr->recv_cq             = recv_cq;
 
-	qp = ib_create_qp(dev->pd, init_attr);
-	if (IS_ERR(qp)) {
-		ret = PTR_ERR(qp);
+	if (target->using_rdma_cm) {
+		ret = rdma_create_qp(ch->rdma_cm.cm_id, dev->pd, init_attr);
+		qp = ch->rdma_cm.cm_id->qp;
+	} else {
+		qp = ib_create_qp(dev->pd, init_attr);
+		if (!IS_ERR(qp)) {
+			ret = srp_init_ib_qp(target, qp);
+			if (ret)
+				ib_destroy_qp(qp);
+		} else {
+			ret = PTR_ERR(qp);
+		}
+	}
+	if (ret) {
+		pr_err("QP creation failed for dev %s: %d\n",
+		       dev_name(&dev->dev->dev), ret);
 		goto err_send_cq;
 	}
 
-	ret = srp_init_qp(target, qp);
-	if (ret)
-		goto err_qp;
-
 	if (dev->use_fast_reg) {
 		fr_pool = srp_alloc_fr_pool(target);
 		if (IS_ERR(fr_pool)) {
@@ -574,7 +664,10 @@ static int srp_create_ch_ib(struct srp_rdma_ch *ch)
 	return 0;
 
 err_qp:
-	ib_destroy_qp(qp);
+	if (target->using_rdma_cm)
+		rdma_destroy_qp(ch->rdma_cm.cm_id);
+	else
+		ib_destroy_qp(qp);
 
 err_send_cq:
 	ib_free_cq(send_cq);
@@ -600,9 +693,16 @@ static void srp_free_ch_ib(struct srp_target_port *target,
 	if (!ch->target)
 		return;
 
-	if (ch->cm_id) {
-		ib_destroy_cm_id(ch->cm_id);
-		ch->cm_id = NULL;
+	if (target->using_rdma_cm) {
+		if (ch->rdma_cm.cm_id) {
+			rdma_destroy_id(ch->rdma_cm.cm_id);
+			ch->rdma_cm.cm_id = NULL;
+		}
+	} else {
+		if (ch->ib_cm.cm_id) {
+			ib_destroy_cm_id(ch->ib_cm.cm_id);
+			ch->ib_cm.cm_id = NULL;
+		}
 	}
 
 	/* If srp_new_cm_id() succeeded but srp_create_ch_ib() not, return. */
@@ -658,16 +758,16 @@ static void srp_path_rec_completion(int status,
 		shost_printk(KERN_ERR, target->scsi_host,
 			     PFX "Got failed path rec status %d\n", status);
 	else
-		ch->path = *pathrec;
+		ch->ib_cm.path = *pathrec;
 	complete(&ch->done);
 }
 
-static int srp_lookup_path(struct srp_rdma_ch *ch)
+static int srp_ib_lookup_path(struct srp_rdma_ch *ch)
 {
 	struct srp_target_port *target = ch->target;
 	int ret = -ENODEV;
 
-	ch->path.numb_path = 1;
+	ch->ib_cm.path.numb_path = 1;
 
 	init_completion(&ch->done);
 
@@ -678,10 +778,10 @@ static int srp_lookup_path(struct srp_rdma_ch *ch)
 	if (!scsi_host_get(target->scsi_host))
 		goto out;
 
-	ch->path_query_id = ib_sa_path_rec_get(&srp_sa_client,
+	ch->ib_cm.path_query_id = ib_sa_path_rec_get(&srp_sa_client,
 					       target->srp_host->srp_dev->dev,
 					       target->srp_host->port,
-					       &ch->path,
+					       &ch->ib_cm.path,
 					       IB_SA_PATH_REC_SERVICE_ID |
 					       IB_SA_PATH_REC_DGID	 |
 					       IB_SA_PATH_REC_SGID	 |
@@ -690,8 +790,8 @@ static int srp_lookup_path(struct srp_rdma_ch *ch)
 					       SRP_PATH_REC_TIMEOUT_MS,
 					       GFP_KERNEL,
 					       srp_path_rec_completion,
-					       ch, &ch->path_query);
-	ret = ch->path_query_id;
+					       ch, &ch->ib_cm.path_query);
+	ret = ch->ib_cm.path_query_id;
 	if (ret < 0)
 		goto put;
 
@@ -703,9 +803,9 @@ static int srp_lookup_path(struct srp_rdma_ch *ch)
 	if (ret < 0)
 		shost_printk(KERN_WARNING, target->scsi_host,
 			     PFX "Path record query failed: sgid %pI6, dgid %pI6, pkey %#04x, service_id %#16llx\n",
-			     ch->path.sgid.raw, ch->path.dgid.raw,
-			     be16_to_cpu(target->pkey),
-			     be64_to_cpu(target->service_id));
+			     ch->ib_cm.path.sgid.raw, ch->ib_cm.path.dgid.raw,
+			     be16_to_cpu(target->ib_cm.pkey),
+			     be64_to_cpu(target->ib_cm.service_id));
 
 put:
 	scsi_host_put(target->scsi_host);
@@ -714,6 +814,34 @@ static int srp_lookup_path(struct srp_rdma_ch *ch)
 	return ret;
 }
 
+static int srp_rdma_lookup_path(struct srp_rdma_ch *ch)
+{
+	struct srp_target_port *target = ch->target;
+	int ret;
+
+	init_completion(&ch->done);
+
+	ret = rdma_resolve_route(ch->rdma_cm.cm_id, SRP_PATH_REC_TIMEOUT_MS);
+	if (ret)
+		return ret;
+
+	wait_for_completion_interruptible(&ch->done);
+
+	if (ch->status != 0)
+		shost_printk(KERN_WARNING, target->scsi_host,
+			     PFX "Path resolution failed\n");
+
+	return ch->status;
+}
+
+static int srp_lookup_path(struct srp_rdma_ch *ch)
+{
+	struct srp_target_port *target = ch->target;
+
+	return target->using_rdma_cm ? srp_rdma_lookup_path(ch) :
+		srp_ib_lookup_path(ch);
+}
+
 static u8 srp_get_subnet_timeout(struct srp_host *host)
 {
 	struct ib_port_attr attr;
@@ -735,8 +863,10 @@ static int srp_send_req(struct srp_rdma_ch *ch, bool multich)
 {
 	struct srp_target_port *target = ch->target;
 	struct {
-		struct ib_cm_req_param param;
-		struct srp_login_req   priv;
+		struct rdma_conn_param	  rdma_param;
+		struct srp_login_req_rdma rdma_req;
+		struct ib_cm_req_param	  ib_param;
+		struct srp_login_req	  ib_req;
 	} *req = NULL;
 	char *ipi, *tpi;
 	int status;
@@ -745,44 +875,62 @@ static int srp_send_req(struct srp_rdma_ch *ch, bool multich)
 	if (!req)
 		return -ENOMEM;
 
-	req->param.flow_control 	      = 1;
-	req->param.retry_count                = target->tl_retry_count;
+	req->ib_param.flow_control = 1;
+	req->ib_param.retry_count = target->tl_retry_count;
 
 	/*
 	 * Pick some arbitrary defaults here; we could make these
 	 * module parameters if anyone cared about setting them.
 	 */
-	req->param.responder_resources	      = 4;
-	req->param.rnr_retry_count 	      = 7;
-	req->param.max_cm_retries 	      = 15;
-
-	req->priv.opcode     	= SRP_LOGIN_REQ;
-	req->priv.tag        	= 0;
-	req->priv.req_it_iu_len = cpu_to_be32(target->max_iu_len);
-	req->priv.req_buf_fmt 	= cpu_to_be16(SRP_BUF_FORMAT_DIRECT |
+	req->ib_param.responder_resources = 4;
+	req->ib_param.rnr_retry_count = 7;
+	req->ib_param.max_cm_retries = 15;
+
+	req->ib_req.opcode = SRP_LOGIN_REQ;
+	req->ib_req.tag = 0;
+	req->ib_req.req_it_iu_len = cpu_to_be32(target->max_iu_len);
+	req->ib_req.req_buf_fmt	= cpu_to_be16(SRP_BUF_FORMAT_DIRECT |
 					      SRP_BUF_FORMAT_INDIRECT);
-	req->priv.req_flags	= (multich ? SRP_MULTICHAN_MULTI :
-				   SRP_MULTICHAN_SINGLE);
-
-	{
+	req->ib_req.req_flags = (multich ? SRP_MULTICHAN_MULTI :
+				 SRP_MULTICHAN_SINGLE);
+
+	if (target->using_rdma_cm) {
+		req->rdma_param.flow_control = req->ib_param.flow_control;
+		req->rdma_param.responder_resources =
+			req->ib_param.responder_resources;
+		req->rdma_param.initiator_depth = req->ib_param.initiator_depth;
+		req->rdma_param.retry_count = req->ib_param.retry_count;
+		req->rdma_param.rnr_retry_count = req->ib_param.rnr_retry_count;
+		req->rdma_param.private_data = &req->rdma_req;
+		req->rdma_param.private_data_len = sizeof(req->rdma_req);
+
+		req->rdma_req.opcode = req->ib_req.opcode;
+		req->rdma_req.tag = req->ib_req.tag;
+		req->rdma_req.req_it_iu_len = req->ib_req.req_it_iu_len;
+		req->rdma_req.req_buf_fmt = req->ib_req.req_buf_fmt;
+		req->rdma_req.req_flags	= req->ib_req.req_flags;
+
+		ipi = req->rdma_req.initiator_port_id;
+		tpi = req->rdma_req.target_port_id;
+	} else {
 		u8 subnet_timeout;
 
 		subnet_timeout = srp_get_subnet_timeout(target->srp_host);
 
-		req->param.primary_path = &ch->path;
-		req->param.alternate_path = NULL;
-		req->param.service_id = target->service_id;
-		get_random_bytes(&req->param.starting_psn, 4);
-		req->param.starting_psn &= 0xffffff;
-		req->param.qp_num = ch->qp->qp_num;
-		req->param.qp_type = ch->qp->qp_type;
-		req->param.local_cm_response_timeout = subnet_timeout + 2;
-		req->param.remote_cm_response_timeout = subnet_timeout + 2;
-		req->param.private_data = &req->priv;
-		req->param.private_data_len = sizeof(req->priv);
-
-		ipi = req->priv.initiator_port_id;
-		tpi = req->priv.target_port_id;
+		req->ib_param.primary_path = &ch->ib_cm.path;
+		req->ib_param.alternate_path = NULL;
+		req->ib_param.service_id = target->ib_cm.service_id;
+		get_random_bytes(&req->ib_param.starting_psn, 4);
+		req->ib_param.starting_psn &= 0xffffff;
+		req->ib_param.qp_num = ch->qp->qp_num;
+		req->ib_param.qp_type = ch->qp->qp_type;
+		req->ib_param.local_cm_response_timeout = subnet_timeout + 2;
+		req->ib_param.remote_cm_response_timeout = subnet_timeout + 2;
+		req->ib_param.private_data = &req->ib_req;
+		req->ib_param.private_data_len = sizeof(req->ib_req);
+
+		ipi = req->ib_req.initiator_port_id;
+		tpi = req->ib_req.target_port_id;
 	}
 
 	/*
@@ -820,7 +968,10 @@ static int srp_send_req(struct srp_rdma_ch *ch, bool multich)
 		memcpy(ipi + 8, &target->srp_host->srp_dev->dev->node_guid, 8);
 	}
 
-	status = ib_send_cm_req(ch->cm_id, &req->param);
+	if (target->using_rdma_cm)
+		status = rdma_connect(ch->rdma_cm.cm_id, &req->rdma_param);
+	else
+		status = ib_send_cm_req(ch->ib_cm.cm_id, &req->ib_param);
 
 	kfree(req);
 
@@ -847,14 +998,23 @@ static bool srp_queue_remove_work(struct srp_target_port *target)
 static void srp_disconnect_target(struct srp_target_port *target)
 {
 	struct srp_rdma_ch *ch;
-	int i;
+	int i, ret;
 
 	/* XXX should send SRP_I_LOGOUT request */
 
 	for (i = 0; i < target->ch_count; i++) {
 		ch = &target->ch[i];
 		ch->connected = false;
-		if (ch->cm_id && ib_send_cm_dreq(ch->cm_id, NULL, 0)) {
+		ret = 0;
+		if (target->using_rdma_cm) {
+			if (ch->rdma_cm.cm_id)
+				rdma_disconnect(ch->rdma_cm.cm_id);
+		} else {
+			if (ch->ib_cm.cm_id)
+				ret = ib_send_cm_dreq(ch->ib_cm.cm_id,
+						      NULL, 0);
+		}
+		if (ret < 0) {
 			shost_printk(KERN_DEBUG, target->scsi_host,
 				     PFX "Sending CM DREQ failed\n");
 		}
@@ -2355,7 +2515,7 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id,
 	struct srp_target_port *target = ch->target;
 	struct ib_qp_attr *qp_attr = NULL;
 	int attr_mask = 0;
-	int ret;
+	int ret = 0;
 	int i;
 
 	if (lrsp->opcode == SRP_LOGIN_RSP) {
@@ -2385,40 +2545,42 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id,
 			goto error;
 	}
 
-	ret = -ENOMEM;
-	qp_attr = kmalloc(sizeof *qp_attr, GFP_KERNEL);
-	if (!qp_attr)
-		goto error;
-
-	qp_attr->qp_state = IB_QPS_RTR;
-	ret = ib_cm_init_qp_attr(cm_id, qp_attr, &attr_mask);
-	if (ret)
-		goto error_free;
-
-	ret = ib_modify_qp(ch->qp, qp_attr, attr_mask);
-	if (ret)
-		goto error_free;
-
 	for (i = 0; i < target->queue_size; i++) {
 		struct srp_iu *iu = ch->rx_ring[i];
 
 		ret = srp_post_recv(ch, iu);
 		if (ret)
-			goto error_free;
+			goto error;
 	}
 
-	qp_attr->qp_state = IB_QPS_RTS;
-	ret = ib_cm_init_qp_attr(cm_id, qp_attr, &attr_mask);
-	if (ret)
-		goto error_free;
+	if (!target->using_rdma_cm) {
+		ret = -ENOMEM;
+		qp_attr = kmalloc(sizeof(*qp_attr), GFP_KERNEL);
+		if (!qp_attr)
+			goto error;
 
-	target->rq_tmo_jiffies = srp_compute_rq_tmo(qp_attr, attr_mask);
+		qp_attr->qp_state = IB_QPS_RTR;
+		ret = ib_cm_init_qp_attr(cm_id, qp_attr, &attr_mask);
+		if (ret)
+			goto error_free;
 
-	ret = ib_modify_qp(ch->qp, qp_attr, attr_mask);
-	if (ret)
-		goto error_free;
+		ret = ib_modify_qp(ch->qp, qp_attr, attr_mask);
+		if (ret)
+			goto error_free;
+
+		qp_attr->qp_state = IB_QPS_RTS;
+		ret = ib_cm_init_qp_attr(cm_id, qp_attr, &attr_mask);
+		if (ret)
+			goto error_free;
 
-	ret = ib_send_cm_rtu(cm_id, NULL, 0);
+		target->rq_tmo_jiffies = srp_compute_rq_tmo(qp_attr, attr_mask);
+
+		ret = ib_modify_qp(ch->qp, qp_attr, attr_mask);
+		if (ret)
+			goto error_free;
+
+		ret = ib_send_cm_rtu(cm_id, NULL, 0);
+	}
 
 error_free:
 	kfree(qp_attr);
@@ -2427,41 +2589,43 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id,
 	ch->status = ret;
 }
 
-static void srp_cm_rej_handler(struct ib_cm_id *cm_id,
-			       struct ib_cm_event *event,
-			       struct srp_rdma_ch *ch)
+static void srp_ib_cm_rej_handler(struct ib_cm_id *cm_id,
+				  struct ib_cm_event *event,
+				  struct srp_rdma_ch *ch)
 {
 	struct srp_target_port *target = ch->target;
 	struct Scsi_Host *shost = target->scsi_host;
 	struct ib_class_port_info *cpi;
 	int opcode;
+	u16 dlid;
 
 	switch (event->param.rej_rcvd.reason) {
 	case IB_CM_REJ_PORT_CM_REDIRECT:
 		cpi = event->param.rej_rcvd.ari;
-		sa_path_set_dlid(&ch->path, ntohs(cpi->redirect_lid));
-		ch->path.pkey = cpi->redirect_pkey;
+		dlid = be16_to_cpu(cpi->redirect_lid);
+		sa_path_set_dlid(&ch->ib_cm.path, dlid);
+		ch->ib_cm.path.pkey = cpi->redirect_pkey;
 		cm_id->remote_cm_qpn = be32_to_cpu(cpi->redirect_qp) & 0x00ffffff;
-		memcpy(ch->path.dgid.raw, cpi->redirect_gid, 16);
+		memcpy(ch->ib_cm.path.dgid.raw, cpi->redirect_gid, 16);
 
-		ch->status = sa_path_get_dlid(&ch->path) ?
-			SRP_DLID_REDIRECT : SRP_PORT_REDIRECT;
+		ch->status = dlid ? SRP_DLID_REDIRECT : SRP_PORT_REDIRECT;
 		break;
 
 	case IB_CM_REJ_PORT_REDIRECT:
 		if (srp_target_is_topspin(target)) {
+			union ib_gid *dgid = &ch->ib_cm.path.dgid;
+
 			/*
 			 * Topspin/Cisco SRP gateways incorrectly send
 			 * reject reason code 25 when they mean 24
 			 * (port redirect).
 			 */
-			memcpy(ch->path.dgid.raw,
-			       event->param.rej_rcvd.ari, 16);
+			memcpy(dgid->raw, event->param.rej_rcvd.ari, 16);
 
 			shost_printk(KERN_DEBUG, shost,
 				     PFX "Topspin/Cisco redirect to target port GID %016llx%016llx\n",
-				     be64_to_cpu(ch->path.dgid.global.subnet_prefix),
-				     be64_to_cpu(ch->path.dgid.global.interface_id));
+				     be64_to_cpu(dgid->global.subnet_prefix),
+				     be64_to_cpu(dgid->global.interface_id));
 
 			ch->status = SRP_PORT_REDIRECT;
 		} else {
@@ -2490,7 +2654,8 @@ static void srp_cm_rej_handler(struct ib_cm_id *cm_id,
 				shost_printk(KERN_WARNING, shost, PFX
 					     "SRP LOGIN from %pI6 to %pI6 REJECTED, reason 0x%08x\n",
 					     target->sgid.raw,
-					     target->orig_dgid.raw, reason);
+					     target->ib_cm.orig_dgid.raw,
+					     reason);
 		} else
 			shost_printk(KERN_WARNING, shost,
 				     "  REJ reason: IB_CM_REJ_CONSUMER_DEFINED,"
@@ -2510,7 +2675,7 @@ static void srp_cm_rej_handler(struct ib_cm_id *cm_id,
 	}
 }
 
-static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
+static int srp_ib_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
 {
 	struct srp_rdma_ch *ch = cm_id->context;
 	struct srp_target_port *target = ch->target;
@@ -2533,7 +2698,7 @@ static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
 		shost_printk(KERN_DEBUG, target->scsi_host, PFX "REJ received\n");
 		comp = 1;
 
-		srp_cm_rej_handler(cm_id, event, ch);
+		srp_ib_cm_rej_handler(cm_id, event, ch);
 		break;
 
 	case IB_CM_DREQ_RECEIVED:
@@ -2571,6 +2736,135 @@ static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
 	return 0;
 }
 
+static void srp_rdma_cm_rej_handler(struct srp_rdma_ch *ch,
+				    struct rdma_cm_event *event)
+{
+	struct srp_target_port *target = ch->target;
+	struct Scsi_Host *shost = target->scsi_host;
+	int opcode;
+
+	switch (event->status) {
+	case IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID:
+		shost_printk(KERN_WARNING, shost,
+			    "  REJ reason: IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID\n");
+		ch->status = -ECONNRESET;
+		break;
+
+	case IB_CM_REJ_CONSUMER_DEFINED:
+		opcode = *(u8 *) event->param.conn.private_data;
+		if (opcode == SRP_LOGIN_REJ) {
+			struct srp_login_rej *rej =
+				(struct srp_login_rej *)
+				event->param.conn.private_data;
+			u32 reason = be32_to_cpu(rej->reason);
+
+			if (reason == SRP_LOGIN_REJ_REQ_IT_IU_LENGTH_TOO_LARGE)
+				shost_printk(KERN_WARNING, shost,
+					     PFX "SRP_LOGIN_REJ: requested max_it_iu_len too large\n");
+			else
+				shost_printk(KERN_WARNING, shost,
+					    PFX "SRP LOGIN REJECTED, reason 0x%08x\n", reason);
+		} else {
+			shost_printk(KERN_WARNING, shost,
+				     "  REJ reason: IB_CM_REJ_CONSUMER_DEFINED, opcode 0x%02x\n",
+				     opcode);
+		}
+		ch->status = -ECONNRESET;
+		break;
+
+	case IB_CM_REJ_STALE_CONN:
+		shost_printk(KERN_WARNING, shost,
+			     "  REJ reason: stale connection\n");
+		ch->status = SRP_STALE_CONN;
+		break;
+
+	default:
+		shost_printk(KERN_WARNING, shost, "  REJ reason 0x%x\n",
+			     event->status);
+		ch->status = -ECONNRESET;
+		break;
+	}
+}
+
+static int srp_rdma_cm_handler(struct rdma_cm_id *cm_id,
+			       struct rdma_cm_event *event)
+{
+	struct srp_rdma_ch *ch = cm_id->context;
+	struct srp_target_port *target = ch->target;
+	int comp = 0;
+
+	switch (event->event) {
+	case RDMA_CM_EVENT_ADDR_RESOLVED:
+		ch->status = 0;
+		comp = 1;
+		break;
+
+	case RDMA_CM_EVENT_ADDR_ERROR:
+		ch->status = -ENXIO;
+		comp = 1;
+		break;
+
+	case RDMA_CM_EVENT_ROUTE_RESOLVED:
+		ch->status = 0;
+		comp = 1;
+		break;
+
+	case RDMA_CM_EVENT_ROUTE_ERROR:
+	case RDMA_CM_EVENT_UNREACHABLE:
+		ch->status = -EHOSTUNREACH;
+		comp = 1;
+		break;
+
+	case RDMA_CM_EVENT_CONNECT_ERROR:
+		shost_printk(KERN_DEBUG, target->scsi_host,
+			     PFX "Sending CM REQ failed\n");
+		comp = 1;
+		ch->status = -ECONNRESET;
+		break;
+
+	case RDMA_CM_EVENT_ESTABLISHED:
+		comp = 1;
+		srp_cm_rep_handler(NULL, event->param.conn.private_data, ch);
+		break;
+
+	case RDMA_CM_EVENT_REJECTED:
+		shost_printk(KERN_DEBUG, target->scsi_host, PFX "REJ received\n");
+		comp = 1;
+
+		srp_rdma_cm_rej_handler(ch, event);
+		break;
+
+	case RDMA_CM_EVENT_DISCONNECTED:
+		if (ch->connected) {
+			shost_printk(KERN_WARNING, target->scsi_host,
+				     PFX "received DREQ\n");
+			rdma_disconnect(ch->rdma_cm.cm_id);
+			comp = 1;
+			ch->status = 0;
+			queue_work(system_long_wq, &target->tl_err_work);
+		}
+		break;
+
+	case RDMA_CM_EVENT_TIMEWAIT_EXIT:
+		shost_printk(KERN_ERR, target->scsi_host,
+			     PFX "connection closed\n");
+
+		comp = 1;
+		ch->status = 0;
+		break;
+
+	default:
+		shost_printk(KERN_WARNING, target->scsi_host,
+			     PFX "Unhandled CM event %d\n", event->event);
+		break;
+	}
+
+	if (comp)
+		complete(&ch->done);
+
+	return 0;
+}
+
 /**
  * srp_change_queue_depth - setting device queue depth
  * @sdev: scsi device struct
@@ -2772,7 +3066,10 @@ static ssize_t show_service_id(struct device *dev,
 {
 	struct srp_target_port *target = host_to_target(class_to_shost(dev));
 
-	return sprintf(buf, "0x%016llx\n", be64_to_cpu(target->service_id));
+	if (target->using_rdma_cm)
+		return -ENOENT;
+	return sprintf(buf, "0x%016llx\n",
+		       be64_to_cpu(target->ib_cm.service_id));
 }
 
 static ssize_t show_pkey(struct device *dev, struct device_attribute *attr,
@@ -2780,7 +3077,9 @@ static ssize_t show_pkey(struct device *dev, struct device_attribute *attr,
 {
 	struct srp_target_port *target = host_to_target(class_to_shost(dev));
 
-	return sprintf(buf, "0x%04x\n", be16_to_cpu(target->pkey));
+	if (target->using_rdma_cm)
+		return -ENOENT;
+	return sprintf(buf, "0x%04x\n", be16_to_cpu(target->ib_cm.pkey));
 }
 
 static ssize_t show_sgid(struct device *dev, struct device_attribute *attr,
@@ -2797,7 +3096,9 @@ static ssize_t show_dgid(struct device *dev, struct device_attribute *attr,
 	struct srp_target_port *target = host_to_target(class_to_shost(dev));
 	struct srp_rdma_ch *ch = &target->ch[0];
 
-	return sprintf(buf, "%pI6\n", ch->path.dgid.raw);
+	if (target->using_rdma_cm)
+		return -ENOENT;
+	return sprintf(buf, "%pI6\n", ch->ib_cm.path.dgid.raw);
 }
 
 static ssize_t show_orig_dgid(struct device *dev,
@@ -2805,7 +3106,9 @@ static ssize_t show_orig_dgid(struct device *dev,
 {
 	struct srp_target_port *target = host_to_target(class_to_shost(dev));
 
-	return sprintf(buf, "%pI6\n", target->orig_dgid.raw);
+	if (target->using_rdma_cm)
+		return -ENOENT;
+	return sprintf(buf, "%pI6\n", target->ib_cm.orig_dgid.raw);
 }
 
 static ssize_t show_req_lim(struct device *dev,
@@ -3050,6 +3353,9 @@ static bool srp_conn_unique(struct srp_host *host,
 		if (t != target &&
 		    target->id_ext == t->id_ext &&
 		    target->ioc_guid == t->ioc_guid &&
+		    (!target->using_rdma_cm ||
+		     memcmp(&target->rdma_cm.dst, &t->rdma_cm.dst,
+			    sizeof(target->rdma_cm.dst)) == 0) &&
 		    target->initiator_ext == t->initiator_ext) {
 			ret = false;
 			break;
@@ -3066,6 +3372,9 @@ static bool srp_conn_unique(struct srp_host *host,
  *
  *     id_ext=<SRP ID ext>,ioc_guid=<SRP IOC GUID>,dgid=<dest GID>,
  *     pkey=<P_Key>,service_id=<service ID>
+ * or
+ *     id_ext=<SRP ID ext>,ioc_guid=<SRP IOC GUID>,
+ *     [src=<IPv4 address>,]dest=<IPv4 address>:<port number>
  *
  * to the add_target sysfs attribute.
  */
@@ -3086,11 +3395,19 @@ enum {
 	SRP_OPT_COMP_VECTOR	= 1 << 12,
 	SRP_OPT_TL_RETRY_COUNT	= 1 << 13,
 	SRP_OPT_QUEUE_SIZE	= 1 << 14,
-	SRP_OPT_ALL		= (SRP_OPT_ID_EXT	|
-				   SRP_OPT_IOC_GUID	|
-				   SRP_OPT_DGID		|
-				   SRP_OPT_PKEY		|
-				   SRP_OPT_SERVICE_ID),
+	SRP_OPT_IP_SRC		= 1 << 15,
+	SRP_OPT_IP_DEST		= 1 << 16,
+};
+
+static unsigned int srp_opt_mandatory[] = {
+	SRP_OPT_ID_EXT		|
+	SRP_OPT_IOC_GUID	|
+	SRP_OPT_DGID		|
+	SRP_OPT_PKEY		|
+	SRP_OPT_SERVICE_ID,
+	SRP_OPT_ID_EXT		|
+	SRP_OPT_IOC_GUID	|
+	SRP_OPT_IP_DEST,
 };
 
 static const match_table_t srp_opt_tokens = {
@@ -3109,9 +3426,25 @@ static const match_table_t srp_opt_tokens = {
 	{ SRP_OPT_COMP_VECTOR,		"comp_vector=%u"	},
 	{ SRP_OPT_TL_RETRY_COUNT,	"tl_retry_count=%u"	},
 	{ SRP_OPT_QUEUE_SIZE,		"queue_size=%d"		},
+	{ SRP_OPT_IP_SRC,		"src=%s"		},
+	{ SRP_OPT_IP_DEST,		"dest=%s"		},
 	{ SRP_OPT_ERR,			NULL 			}
 };
 
+static int srp_parse_in(struct sockaddr_storage *sa, const char *addr_port_str)
+{
+	char *addr = kstrdup(addr_port_str, GFP_KERNEL);
+	char *port_str = addr;
+	int ret;
+
+	if (!addr)
+		return -ENOMEM;
+	strsep(&port_str, ":");
+	ret = inet_pton_with_scope(&init_net, AF_UNSPEC, addr, port_str, sa);
+	kfree(addr);
+	return ret;
+}
+
 static int srp_parse_options(const char *buf, struct srp_target_port *target)
 {
 	char *options, *sep_opt;
@@ -3180,7 +3513,7 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
 				goto out;
 			}
 
-			ret = hex2bin(target->orig_dgid.raw, p, 16);
+			ret = hex2bin(target->ib_cm.orig_dgid.raw, p, 16);
 			kfree(p);
 			if (ret < 0)
 				goto out;
@@ -3191,7 +3524,7 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
 				pr_warn("bad P_Key parameter '%s'\n", p);
 				goto out;
 			}
-			target->pkey = cpu_to_be16(token);
+			target->ib_cm.pkey = cpu_to_be16(token);
 			break;
 
 		case SRP_OPT_SERVICE_ID:
@@ -3206,7 +3539,39 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
 				kfree(p);
 				goto out;
 			}
-			target->service_id = cpu_to_be64(ull);
+			target->ib_cm.service_id = cpu_to_be64(ull);
+			kfree(p);
+			break;
+
+		case SRP_OPT_IP_SRC:
+			p = match_strdup(args);
+			if (!p) {
+				ret = -ENOMEM;
+				goto out;
+			}
+			ret = srp_parse_in(&target->rdma_cm.src.ss, p);
+			if (ret < 0) {
+				pr_warn("bad source parameter '%s'\n", p);
+				kfree(p);
+				goto out;
+			}
+			target->rdma_cm.src_specified = true;
+			kfree(p);
+			break;
+
+		case SRP_OPT_IP_DEST:
+			p = match_strdup(args);
+			if (!p) {
+				ret = -ENOMEM;
+				goto out;
+			}
+			ret = srp_parse_in(&target->rdma_cm.dst.ss, p);
+			if (ret < 0) {
+				pr_warn("bad dest parameter '%s'\n", p);
+				kfree(p);
+				goto out;
+			}
+			target->using_rdma_cm = true;
 			kfree(p);
 			break;
 
@@ -3321,14 +3686,14 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
 		}
 	}
 
-	if ((opt_mask & SRP_OPT_ALL) == SRP_OPT_ALL)
-		ret = 0;
-	else
-		for (i = 0; i < ARRAY_SIZE(srp_opt_tokens); ++i)
-			if ((srp_opt_tokens[i].token & SRP_OPT_ALL) &&
-			    !(srp_opt_tokens[i].token & opt_mask))
-				pr_warn("target creation request is missing parameter '%s'\n",
-					srp_opt_tokens[i].pattern);
+	for (i = 0; i < ARRAY_SIZE(srp_opt_mandatory); i++) {
+		if ((opt_mask & srp_opt_mandatory[i]) == srp_opt_mandatory[i]) {
+			ret = 0;
+			break;
+		}
+	}
+	if (ret)
+		pr_warn("target creation request is missing one or more parameters\n");
 
 	if (target->scsi_host->cmd_per_lun > target->scsi_host->can_queue
 	    && (opt_mask & SRP_OPT_MAX_CMD_PER_LUN))
@@ -3397,11 +3762,22 @@ static ssize_t srp_create_target(struct device *dev,
 	target->req_ring_size = target->queue_size - SRP_TSK_MGMT_SQ_SIZE;
 
 	if (!srp_conn_unique(target->srp_host, target)) {
-		shost_printk(KERN_INFO, target->scsi_host,
-			     PFX "Already connected to target port with id_ext=%016llx;ioc_guid=%016llx;initiator_ext=%016llx\n",
-			     be64_to_cpu(target->id_ext),
-			     be64_to_cpu(target->ioc_guid),
-			     be64_to_cpu(target->initiator_ext));
+		if (target->using_rdma_cm) {
+			char dst_addr[64];
+
+			shost_printk(KERN_INFO, target->scsi_host,
+				     PFX "Already connected to target port with id_ext=%016llx;ioc_guid=%016llx;dest=%s\n",
+				     be64_to_cpu(target->id_ext),
+				     be64_to_cpu(target->ioc_guid),
+				     inet_ntop(&target->rdma_cm.dst, dst_addr,
+					       sizeof(dst_addr)));
+		} else {
+			shost_printk(KERN_INFO, target->scsi_host,
+				     PFX "Already connected to target port with id_ext=%016llx;ioc_guid=%016llx;initiator_ext=%016llx\n",
+				     be64_to_cpu(target->id_ext),
+				     be64_to_cpu(target->ioc_guid),
+				     be64_to_cpu(target->initiator_ext));
+		}
 		ret = -EEXIST;
 		goto out;
 	}
@@ -3502,11 +3878,18 @@ static ssize_t srp_create_target(struct device *dev,
 
 			ret = srp_connect_ch(ch, multich);
 			if (ret) {
+				char dst[64];
+
+				if (target->using_rdma_cm)
+					inet_ntop(&target->rdma_cm.dst, dst,
+						  sizeof(dst));
+				else
+					snprintf(dst, sizeof(dst), "%pI6",
+						 target->ib_cm.orig_dgid.raw);
 				shost_printk(KERN_ERR, target->scsi_host,
-					     PFX "Connection %d/%d to %pI6 failed\n",
+					     PFX "Connection %d/%d to %s failed\n",
 					     ch_start + cpu_idx,
-					     target->ch_count,
-					     ch->target->orig_dgid.raw);
+					     target->ch_count, dst);
 				if (node_idx == 0 && cpu_idx == 0) {
 					goto free_ch;
 				} else {
@@ -3531,13 +3914,25 @@ static ssize_t srp_create_target(struct device *dev,
 		goto err_disconnect;
 
 	if (target->state != SRP_TARGET_REMOVED) {
-		shost_printk(KERN_DEBUG, target->scsi_host, PFX
-			     "new target: id_ext %016llx ioc_guid %016llx pkey %04x service_id %016llx sgid %pI6 dgid %pI6\n",
-			     be64_to_cpu(target->id_ext),
-			     be64_to_cpu(target->ioc_guid),
-			     be16_to_cpu(target->pkey),
-			     be64_to_cpu(target->service_id),
-			     target->sgid.raw, target->orig_dgid.raw);
+		if (target->using_rdma_cm) {
+			char dst[64];
+
+			inet_ntop(&target->rdma_cm.dst, dst, sizeof(dst));
+			shost_printk(KERN_DEBUG, target->scsi_host, PFX
+				     "new target: id_ext %016llx ioc_guid %016llx sgid %pI6 dest %s\n",
+				     be64_to_cpu(target->id_ext),
+				     be64_to_cpu(target->ioc_guid),
+				     target->sgid.raw, dst);
+		} else {
+			shost_printk(KERN_DEBUG, target->scsi_host, PFX
+				     "new target: id_ext %016llx ioc_guid %016llx pkey %04x service_id %016llx sgid %pI6 dgid %pI6\n",
+				     be64_to_cpu(target->id_ext),
+				     be64_to_cpu(target->ioc_guid),
+				     be16_to_cpu(target->ib_cm.pkey),
+				     be64_to_cpu(target->ib_cm.service_id),
+				     target->sgid.raw,
+				     target->ib_cm.orig_dgid.raw);
+		}
 	}
 
 	ret = count;
drivers/infiniband/ulp/srp/ib_srp.h +34 -7

66 lines not on this page · raw message

include/scsi/srp.h +17 -0
index 5be834de491a..c16a3c9a4d9b 100644
@@ -129,6 +129,23 @@ struct srp_login_req {
 	u8	target_port_id[16];
 };
 
+/**
+ * struct srp_login_req_rdma - RDMA/CM login parameters.
+ *
+ * RDMA/CM over InfiniBand can only carry 92 - 36 = 56 bytes of private
+ * data. The %srp_login_req_rdma structure contains the same information as
+ * %srp_login_req but with the reserved data removed.
+ */
+struct srp_login_req_rdma {
+	u64	tag;
+	__be16	req_buf_fmt;
+	u8	req_flags;
+	u8	opcode;
+	__be32	req_it_iu_len;
+	u8	initiator_port_id[16];
+	u8	target_port_id[16];
+};
+
 /*
  * The SRP spec defines the size of the LOGIN_RSP structure to be 52
  * bytes, so it needs to be packed to avoid having it padded to 56
Signature · 6 lines
2.15.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw
In reply to a message not in the archive
Quoted 3 lines · Bart Van Assche

Since the SRP_LOGIN_REQ defined in the SRP standard is larger than what fits in the RDMA/CM login request private data, introduce a new login request format for the RDMA/CM.

Ok up to here...

Quoted 2 lines

Add a kernel module parameter
to the ib_srp kernel driver

Unless I missed it, there is no new ib_srp kernel module parameter here.
Furthermore, if there were, I would probably think that was a bad idea.

Quoted 2 lines

that allows to specify the port on which
to listen for RDMA/CM connections.

Obviously, a kernel module parameter for the listen port would be an ib_srpt option, not an ib_srp option, so that makes sense why it's not in the patch. The commit log message needs updated. But, a kernel module parameter instead of a config file option for a listen port that we set with the target infrastructure sounds wrong anyway.

Quoted 3 lines

The default value for this kernel
module parameter is 0, which means not to listen for RDMA/CM connections.

Again, doesn't belong in this commit log.

Quoted 6 lines
drivers/infiniband/ulp/srp/ib_srp.c +4 -0
+static int srp_parse_in(struct sockaddr_storage *sa, const char *addr_port_str)
+{
+	char *addr = kstrdup(addr_port_str, GFP_KERNEL);
+	char *port_str = addr;

drivers/infiniband/ulp/srp/ib_srp.c static const match_table_t srp_opt_tokens = { · line 3447

Quoted 10 lines
drivers/infiniband/ulp/srp/ib_srp.c +10 -0
+	int ret;
+
+	if (!addr)
+		return -ENOMEM;
+	strsep(&port_str, ":");
+	ret = inet_pton_with_scope(&init_net, AF_UNSPEC, addr, port_str, sa);
+	kfree(addr);
+	return ret;
+}
+

This particular function is problematic in that it adds new namespace unaware code. The namespace code in the RDMA stack is in a limbo state of partially implemented, partially not. I'm loathe to add any more code that is not fully namespace aware as that just worsens the hysteresis in the stack. So we need to figure out how to do this in a namespace aware manner. I haven't previously been thinking about this specific namespace issue, so I'm not prepared to even make suggestions for a fix for this yet...

Signature · 3 lines
Doug Ledford <[email protected]>
    GPG KeyID: B826A3330E572FDD
    Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD
#30 lore raw
In reply to a message not in the archive
Quoted 15 lines · Bart Van Assche

Hello Jason,

The four patches in this series add RDMA/CM support to the SRP initiator. Please consider these patches for kernel v4.16.

Thanks,

Bart.

Bart Van Assche (4):
IB/srp: Use kstrtoull() instead of simple_strtoull() IB/srp: Make the path record query error message more informative IB/srp: Refactor srp_send_req()
IB/srp: Add RDMA/CM support

Quoted 5 lines
 drivers/infiniband/ulp/srp/ib_srp.c | 744 ++++++++++++++++++++++++++++--------
 drivers/infiniband/ulp/srp/ib_srp.h |  41 +-
 include/scsi/srp.h                  |  17 +
 3 files changed, 636 insertions(+), 166 deletions(-)

The first three patches are fine, the fourth presents problems. Would you prefer I take the first three while you think about the fourth, or do you want to keep the series intact?

Signature · 3 lines
Doug Ledford <[email protected]>
    GPG KeyID: B826A3330E572FDD
    Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD
#9 lore raw
In reply to a message not in the archive
Quoted 15 lines · Doug Ledford
Quoted 4 lines
drivers/infiniband/ulp/srp/ib_srp.c +4 -0
+static int srp_parse_in(struct sockaddr_storage *sa, const char *addr_port_str)
+{
+	char *addr = kstrdup(addr_port_str, GFP_KERNEL);
+	char *port_str = addr;

drivers/infiniband/ulp/srp/ib_srp.c static const match_table_t srp_opt_tokens = { · line 3447

Quoted 10 lines
drivers/infiniband/ulp/srp/ib_srp.c +10 -0
+	int ret;
+
+	if (!addr)
+		return -ENOMEM;
+	strsep(&port_str, ":");
+	ret = inet_pton_with_scope(&init_net, AF_UNSPEC, addr, port_str, sa);
+	kfree(addr);
+	return ret;
+}
+
Quoted 8 lines

This particular function is problematic in that it adds new namespace unaware code. The namespace code in the RDMA stack is in a limbo state of partially implemented, partially not. I'm loathe to add any more code that is not fully namespace aware as that just worsens the hysteresis in the stack. So we need to figure out how to do this in a namespace aware manner. I haven't previously been thinking about this specific namespace issue, so I'm not prepared to even make suggestions for a fix for this yet...

Do the userspace daemon's still manage the connection to SRP?

If yes, then the networking information should be relative to the namespace of the thing that wrote to the sysfs file..

Also, are there srp_daemon patches for this too? I've been asking to see the userspace side for new uAPI features before accepting the kernel part so that everything can be well understood. If yes, please send, even if it is RFCish..

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#29 lore raw
In reply to a message not in the archive

T24gRnJpLCAyMDE4LTAxLTA1IGF0IDEyOjIxIC0wNTAwLCBEb3VnIExlZGZvcmQgd3JvdGU6DQo+ IE9uIFRodSwgMjAxOC0wMS0wNCBhdCAxNDoyOCAtMDgwMCwgQmFydCBWYW4gQXNzY2hlIHdyb3Rl Og0KPiA+IEFkZCBhIGtlcm5lbCBtb2R1bGUgcGFyYW1ldGVyIHRvIHRoZSBpYl9zcnAga2VybmVs IGRyaXZlcg0KPiANCj4gVW5sZXNzIEkgbWlzc2VkIGl0LCB0aGVyZSBpcyBubyBuZXcgaWJfc3Jw IGtlcm5lbCBtb2R1bGUgcGFyYW1ldGVyIGhlcmUuDQoNClRoYXQncyByaWdodC4gSSB3aWxsIHJl bW92ZSB0aGF0IHBhcnQgZnJvbSB0aGUgcGF0Y2ggZGVzY3JpcHRpb24uDQoNCkJhcnQu --
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#11 lore raw
In reply to a message not in the archive

T24gRnJpLCAyMDE4LTAxLTA1IGF0IDEwOjM0IC0wNzAwLCBKYXNvbiBHdW50aG9ycGUgd3JvdGU6 DQo+IE9uIEZyaSwgSmFuIDA1LCAyMDE4IGF0IDEyOjIxOjEwUE0gLTA1MDAsIERvdWcgTGVkZm9y ZCB3cm90ZToNCj4gDQo+ID4gPiArc3RhdGljIGludCBzcnBfcGFyc2VfaW4oc3RydWN0IHNvY2th ZGRyX3N0b3JhZ2UgKnNhLCBjb25zdCBjaGFyICphZGRyX3BvcnRfc3RyKQ0KPiA+ID4gK3sNCj4g PiA+ICsJY2hhciAqYWRkciA9IGtzdHJkdXAoYWRkcl9wb3J0X3N0ciwgR0ZQX0tFUk5FTCk7DQo+ ID4gPiArCWNoYXIgKnBvcnRfc3RyID0gYWRkcjsNCj4gPiA+ICsJaW50IHJldDsNCj4gPiA+ICsN Cj4gPiA+ICsJaWYgKCFhZGRyKQ0KPiA+ID4gKwkJcmV0dXJuIC1FTk9NRU07DQo+ID4gPiArCXN0 cnNlcCgmcG9ydF9zdHIsICI6Iik7DQo+ID4gPiArCXJldCA9IGluZXRfcHRvbl93aXRoX3Njb3Bl KCZpbml0X25ldCwgQUZfVU5TUEVDLCBhZGRyLCBwb3J0X3N0ciwgc2EpOw0KPiA+ID4gKwlrZnJl ZShhZGRyKTsNCj4gPiA+ICsJcmV0dXJuIHJldDsNCj4gPiA+ICt9DQo+ID4gPiArDQo+ID4gDQo+ ID4gVGhpcyBwYXJ0aWN1bGFyIGZ1bmN0aW9uIGlzIHByb2JsZW1hdGljIGluIHRoYXQgaXQgYWRk cyBuZXcgbmFtZXNwYWNlDQo+ID4gdW5hd2FyZSBjb2RlLiAgVGhlIG5hbWVzcGFjZSBjb2RlIGlu IHRoZSBSRE1BIHN0YWNrIGlzIGluIGEgbGltYm8gc3RhdGUNCj4gPiBvZiBwYXJ0aWFsbHkgaW1w bGVtZW50ZWQsIHBhcnRpYWxseSBub3QuICBJJ20gbG9hdGhlIHRvIGFkZCBhbnkgbW9yZQ0KPiA+ IGNvZGUgdGhhdCBpcyBub3QgZnVsbHkgbmFtZXNwYWNlIGF3YXJlIGFzIHRoYXQganVzdCB3b3Jz ZW5zIHRoZQ0KPiA+IGh5c3RlcmVzaXMgaW4gdGhlIHN0YWNrLiAgU28gd2UgbmVlZCB0byBmaWd1 cmUgb3V0IGhvdyB0byBkbyB0aGlzIGluIGENCj4gPiBuYW1lc3BhY2UgYXdhcmUgbWFubmVyLiAg SSBoYXZlbid0IHByZXZpb3VzbHkgYmVlbiB0aGlua2luZyBhYm91dCB0aGlzDQo+ID4gc3BlY2lm aWMgbmFtZXNwYWNlIGlzc3VlLCBzbyBJJ20gbm90IHByZXBhcmVkIHRvIGV2ZW4gbWFrZSBzdWdn ZXN0aW9ucw0KPiA+IGZvciBhIGZpeCBmb3IgdGhpcyB5ZXQuLi4NCj4gDQo+IERvIHRoZSB1c2Vy c3BhY2UgZGFlbW9uJ3Mgc3RpbGwgbWFuYWdlIHRoZSBjb25uZWN0aW9uIHRvIFNSUD8NCg0Kc3Jw X2RhZW1vbiB1c2VzIG1hbmFnZW1lbnQgZGF0YWdyYW1zIHRvIGRpc2NvdmVyIFNSUCB0YXJnZXRz IGFuZCB0aGVzZSBNQURzDQpkaXNjb3ZlciB0aGUgR0lEIG9mIHRoZSB0YXJnZXQgcG9ydCBpbnN0 ZWFkIG9mIHRoZSBJUCBhZGRyZXNzLiBTbyBJIGhhdmUgbm90DQpldmVuIHRyaWVkIHRvIGFkZCBS RE1BL0NNIHN1cHBvcnQgdG8gc3JwX2RhZW1vbi4gSWYgYXV0b21hdGljIGxvZ2luIHdvdWxkIGJl DQppbXBsZW1lbnRlZCBmb3IgU1JQIGFuZCBSRE1BL0NNIEkgdGhpbmsgd2Ugc2hvdWxkIGRlZmlu ZSBhIG5ldyBkaXNjb3ZlcnkNCm1lY2hhbmlzbSBiYXNlZCBvbiB0aGUgSW50ZXJuZXQgUHJvdG9j b2wuDQoNCj4gSWYgeWVzLCB0aGVuIHRoZSBuZXR3b3JraW5nIGluZm9ybWF0aW9uIHNob3VsZCBi ZSByZWxhdGl2ZSB0byB0aGUNCj4gbmFtZXNwYWNlIG9mIHRoZSB0aGluZyB0aGF0IHdyb3RlIHRv IHRoZSBzeXNmcyBmaWxlLi4NCg0KTG9naW4gb2NjdXJzIGJ5IHdyaXRpbmcgaW50byBhIHN5c2Zz IGZpbGUgY3JlYXRlZCBieSB0aGUgU1JQIGluaXRpYXRvci4gSG93DQphYm91dCB1c2luZyB0aGUg bmV0d29ya2luZyBuYW1lc3BhY2Ugb2YgdGhlIHByb2Nlc3MgdGhhdCB3cml0ZXMgaW50byB0aGF0 DQpzeXNmcyBmaWxlPw0KDQo+IEFsc28sIGFyZSB0aGVyZSBzcnBfZGFlbW9uIHBhdGNoZXMgZm9y IHRoaXMgdG9vPyBJJ3ZlIGJlZW4gYXNraW5nIHRvDQo+IHNlZSB0aGUgdXNlcnNwYWNlIHNpZGUg Zm9yIG5ldyB1QVBJIGZlYXR1cmVzIGJlZm9yZSBhY2NlcHRpbmcgdGhlDQo+IGtlcm5lbCBwYXJ0 IHNvIHRoYXQgZXZlcnl0aGluZyBjYW4gYmUgd2VsbCB1bmRlcnN0b29kLiBJZiB5ZXMsIHBsZWFz ZQ0KPiBzZW5kLCBldmVuIGlmIGl0IGlzIFJGQ2lzaC4uDQoNCkFzIGV4cGxhaW5lZCBhYm92ZSB0 aGVyZSBhcmUgbm8gY29ycmVzcG9uZGluZyBzcnBfZGFlbW9uIHBhdGNoZXMuIEJ1dCBpdCBtYXkN CmJlIGludGVyZXN0aW5nIHRvIGhhdmUgYSBsb29rIGF0IHRoZSBzcnAtdGVzdCBzb3VyY2UgY29k ZSBzaW5jZSBJIHVzZWQgdGhhdA0Kc29mdHdhcmUgdG8gdGVzdCBSRE1BL0NNIHN1cHBvcnQuIFNl ZSBhbHNvIGh0dHBzOi8vZ2l0aHViLmNvbS9idmFuYXNzY2hlL3NycC10ZXN0Lg0KDQpCYXJ0Lg== --
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw
In reply to a message not in the archive
Quoted 6 lines · Bart Van Assche
Quoted 2 lines

If yes, then the networking information should be relative to the namespace of the thing that wrote to the sysfs file..

Login occurs by writing into a sysfs file created by the SRP initiator. How about using the networking namespace of the process that writes into that sysfs file?

Sounds right to me.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#14 lore raw
In reply to a message not in the archive
Quoted 26 lines · Jason Gunthorpe
Quoted 15 lines · Doug Ledford
Quoted 4 lines
drivers/infiniband/ulp/srp/ib_srp.c +4 -0
+static int srp_parse_in(struct sockaddr_storage *sa, const char *addr_port_str)
+{
+	char *addr = kstrdup(addr_port_str, GFP_KERNEL);
+	char *port_str = addr;

drivers/infiniband/ulp/srp/ib_srp.c static const match_table_t srp_opt_tokens = { · line 3447

Quoted 10 lines
drivers/infiniband/ulp/srp/ib_srp.c +10 -0
+	int ret;
+
+	if (!addr)
+		return -ENOMEM;
+	strsep(&port_str, ":");
+	ret = inet_pton_with_scope(&init_net, AF_UNSPEC, addr, port_str, sa);
+	kfree(addr);
+	return ret;
+}
+
Quoted 8 lines

This particular function is problematic in that it adds new namespace unaware code. The namespace code in the RDMA stack is in a limbo state of partially implemented, partially not. I'm loathe to add any more code that is not fully namespace aware as that just worsens the hysteresis in the stack. So we need to figure out how to do this in a namespace aware manner. I haven't previously been thinking about this specific namespace issue, so I'm not prepared to even make suggestions for a fix for this yet...

Quoted 4 lines

Do the userspace daemon's still manage the connection to SRP?

If yes, then the networking information should be relative to the namespace of the thing that wrote to the sysfs file..

Maybe, maybe not. It depends on the implementation. IIRC you get one daemon per port, not one daemon per mount. In that situation, it's conceivable that you might want to allow the init_net namespace to host a master daemon that mounts all mounts on a specific port under a variety of namespaces and then you don't need to run a separate daemon in the namespace itself. You can reduce the privilege level of applications in the namespace this way. But, that's an implementation detail.

Quoted 4 lines

Also, are there srp_daemon patches for this too? I've been asking to see the userspace side for new uAPI features before accepting the kernel part so that everything can be well understood. If yes, please send, even if it is RFCish..

No, the target code is likewise clueless about namespaces. I suspect (although I haven't looked) that the target code's Add RDMACM support patch will have the same problem.

And, FWIW, the iser/isert code also has this same namespace issue.

And this is all complicated by the fact that the block devices created by the SRP code might be mounted filesystems, or might be presented as raw block devices to apps. If it's a filesystem, then we get a pass as the filesystem layer will determine if any given read/write should go through based upon the bind mounts of the filesystem and the namespace of the application accessing the filesystem. But if the block device is directly accessed by a user space application, like maybe a database writing directly to the block device or even just mkfs/fsck, then we need to enforce namespaces ourselves. For that we need to know what namespace(s) the device is created in, and what namespace the app opening the device is in.

Signature · 3 lines
Doug Ledford <[email protected]>
    GPG KeyID: B826A3330E572FDD
    Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD
#16 lore raw
In reply to a message not in the archive

T24gRnJpLCAyMDE4LTAxLTA1IGF0IDEzOjA2IC0wNTAwLCBEb3VnIExlZGZvcmQgd3JvdGU6DQo+ IE5vLCB0aGUgdGFyZ2V0IGNvZGUgaXMgbGlrZXdpc2UgY2x1ZWxlc3MgYWJvdXQgbmFtZXNwYWNl cy4gIEkgc3VzcGVjdA0KPiAoYWx0aG91Z2ggSSBoYXZlbid0IGxvb2tlZCkgdGhhdCB0aGUgdGFy Z2V0IGNvZGUncyBBZGQgUkRNQUNNIHN1cHBvcnQNCj4gcGF0Y2ggd2lsbCBoYXZlIHRoZSBzYW1l IHByb2JsZW0uDQoNCkhlbGxvIERvdWcsDQoNClRoZSB0YXJnZXQgY29kZSBhbHJlYWR5IGFsbG93 cyB0byBjb25maWd1cmUgQUNMIChhY2Nlc3MgY29udHJvbCBsaXN0cykgdGhhdA0KY29udHJvbCB3 aGljaCBpbml0aWF0b3Igc3lzdGVtcyBhcmUgYWxsb3dlZCB0byBsb2cgaW4gYW5kIHdoaWNoIG9u ZXMgbm90LiBBcmUNCnlvdSBzdXJlIHRoYXQgaXQgd2lsbCBiZSB2YWx1YWJsZSB0byBhZGQgbmV0 d29yayBuYW1lc3BhY2Ugc3VwcG9ydCB0byB0aGUNClJETUEvQ00gY29kZSBpbiB0aGUgU1JQIHRh cmdldCBkcml2ZXI/DQoNClRoYW5rcywNCg0KQmFydC4=
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#18 lore raw
In reply to a message not in the archive
Quoted 11 lines · Bart Van Assche
Quoted 3 lines · Doug Ledford

No, the target code is likewise clueless about namespaces. I suspect (although I haven't looked) that the target code's Add RDMACM support patch will have the same problem.

Hello Doug,

The target code already allows to configure ACL (access control lists) that control which initiator systems are allowed to log in and which ones not. Are you sure that it will be valuable to add network namespace support to the RDMA/CM code in the SRP target driver?

I haven't really thought about it much. My comment wasn't that I thought it should be implemented, just that my quick grep of init_net in the drivers/infiniband directory showed me that the srpt driver doesn't distinguish any namespaces (while the isert driver does), so I suspect adding rdmacm support will add a new init_net usage.

Signature · 3 lines
Doug Ledford <[email protected]>
    GPG KeyID: B826A3330E572FDD
    Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD
#19 lore raw
In reply to a message not in the archive
Quoted 7 lines · Doug Ledford
Quoted 4 lines

Do the userspace daemon's still manage the connection to SRP?

If yes, then the networking information should be relative to the namespace of the thing that wrote to the sysfs file..

Maybe, maybe not. It depends on the implementation. IIRC you get one daemon per port, not one daemon per mount.

I don't think it depends - if we expose this sysfs file to a container then anything less than using the contain'd net namespace sounds like it is a path to allow the container to escape its net namespace.

The complication here is that sysfs creates a device, and that device is currently created in the host namespace.

So from a security perspective containers shouldn't even have access to this thing at all without more work to ensure that the created block device is also restriced inside the container.

Since it is a sysfs file, and most container systems mount syfs ro, we can probably get away with ignoring namespaces for now?

But using the current process namespace is also a good choice.

In princinple there can be multiple srp_daemons if they can coordinate which ones do which. For instance a container could run its own srp_daemon restricted to the pkeys the container has access to. If the device stuff above was fixed then this would even make some sense...

Otherwise srp_daemon has to run in the host namespace, where the created devices end up and it rightly should not see the netdevices that are assigned to other namespaces.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#21 lore raw
In reply to a message not in the archive
Quoted 10 lines · Jason Gunthorpe
Quoted 7 lines · Doug Ledford
Quoted 4 lines

Do the userspace daemon's still manage the connection to SRP?

If yes, then the networking information should be relative to the namespace of the thing that wrote to the sysfs file..

Maybe, maybe not. It depends on the implementation. IIRC you get one daemon per port, not one daemon per mount.

I don't think it depends - if we expose this sysfs file to a container

Who says we have to do that? We could make the sysfs file only visible in the init namespace and let the init namespace daemon control what namespaces have what views. That was my point, the implementation can be flexible. And actually, if most containers mount sysfs ro as you say below, then the init namespace daemon would need to create the namespace views anyway. We could just make that mandatory by refusing to create devices from anything other than init_net namespace. Then even if someone does mount sysfs rw in a container, we're still good.

Quoted 2 lines

then anything less than using the contain'd net namespace sounds like it is a path to allow the container to escape its net namespace.

I'm a little concerned that this is a problem now regardless.

Quoted 2 lines

The complication here is that sysfs creates a device, and that device is currently created in the host namespace.

Let's assume, for the sake of what I'm writing below, that we modify the srp daemon so that every line in the srp_daemon.conf file can optionally specify a namespace, and when present, the daemon will pass that to the kernel, and when present the kernel code creates the *device* file for that device in that specific namespace (which is really the only thing we care about...for a filesystem based access as opposed to direct device access, you want to create the device file in the init_net namespace and mount the device in the init_net namespace and then follow the typical filesystem namespace rules for determining what the client namespaces can see, and in that situation the client need know nothing about SRP, it is only using a filesystem in a namespace).

Quoted 3 lines

So from a security perspective containers shouldn't even have access to this thing at all without more work to ensure that the created block device is also restriced inside the container.

This isn't sufficient. The block device created must be constrained within the container, but if we allow direct device access to the underlying LUN on the target, then that target LUN must be exclusively owned by the container. No other container, nor the host, can be allowed to have any access of any sort or it becomes a message passing bypass around containerization. It becomes easier then to allow the init_net daemon to create all of the devices, and once it creates a single mapping to any LUN, that LUN can not be reused for any other mapping. So, a LUN can be either A) a mounted filesystem in the init_net namespace with other namespaces carved out of the filesystem as appropriate or B) a direct access device that is accessible in exactly one namespace only. We can't actually rely on the srp_daemon to enforce this, we have to do it at the kernel level, but I think that's what we need to do (if we don't simply bar direct device access from a container, period). The only difficulty I see here is multipath. You still want to support it, especially for the host OS, but at the same time, you can't allow a container to get one path and a different container to get another path to the same device.

Quoted 5 lines

Since it is a sysfs file, and most container systems mount syfs ro, we can probably get away with ignoring namespaces for now?

But using the current process namespace is also a good choice.

Quoted 8 lines

In princinple there can be multiple srp_daemons if they can coordinate which ones do which. For instance a container could run its own srp_daemon restricted to the pkeys the container has access to. If the device stuff above was fixed then this would even make some sense...

Otherwise srp_daemon has to run in the host namespace, where the created devices end up and it rightly should not see the netdevices that are assigned to other namespaces.

This problem is made more difficult by the fact that there is persistent storage at the other end of the connection. It doesn't really matter what netdevice we access a target through. If the accesses go to the same physical media at the other end, then they can't be shared across namespaces without creating a containerization leak. With netdevices we have a unique MAC/vlan/IP tuple of data, and remote systems only know us by that and our containerized code can't reach beyond those boundaries. But with disks, the issue is different. If we allow direct device access in the container, then (as best we can, there may be problems we simply can't solve) we need the container bubble to extend all the way around the physical media we are allowing access to on the remote target system.

We might just have to turn off all direct device file access in containers for iser and srp and nvmeof...

Signature · 3 lines
Doug Ledford <[email protected]>
    GPG KeyID: B826A3330E572FDD
    Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD
#23 lore raw
In reply to a message not in the archive
Quoted 7 lines · Doug Ledford
Quoted 6 lines · Jason Gunthorpe
Quoted 5 lines · Doug Ledford
Quoted 4 lines

Do the userspace daemon's still manage the connection to SRP?

If yes, then the networking information should be relative to the namespace of the thing that wrote to the sysfs file..

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Maybe, maybe not. It depends on the implementation. IIRC you get one daemon per port, not one daemon per mount.

I don't think it depends - if we expose this sysfs file to a container

Who says we have to do that? We could make the sysfs file only visible in the init namespace and let the init namespace daemon control what namespaces have what views.

What 'views'? It is a sysfs file controlled by the kernel - srp_daemon has no control ove rit.

Quoted 3 lines

views anyway. We could just make that mandatory by refusing to create devices from anything other than init_net namespace. Then even if someone does mount sysfs rw in a container, we're still good.

Usually we don't put that kind if policy in the kernel.

Someone could run a priviledged container with full device access and expect this stuff to work right. In that case it is certainly correct for the srp_daemon and kernel to be in the namespace of the calling process.

Quoted 8 lines
Quoted 3 lines

So from a security perspective containers shouldn't even have access to this thing at all without more work to ensure that the created block device is also restriced inside the container.

This isn't sufficient. The block device created must be constrained within the container, but if we allow direct device access to the underlying LUN on the target, then that target LUN must be exclusively owned by the container.

Yes. That is done on the storage controller via ACLs of that LUN. The container's net namespace would be restricted in some way that the ACL can uniquely identify it - and the srp_daemon could run inside the container.

Otherwise the LUN has to be ACL'd to the host and the srp_daemon running on the host creates the device and orchestartion sends it into the contiainer.

Quoted 3 lines

No other container, nor the host, can be allowed to have any access of any sort or it becomes a message passing bypass around containerization.

But maybe that is the user-intent. shared storage between VMs is a real thing. We can't put that kind of policy choice in the kernel.

Quoted 3 lines

This problem is made more difficult by the fact that there is persistent storage at the other end of the connection. It doesn't really matter what netdevice we access a target through.

Well, it does. The netdevice is part of the ACL system the target uses. It is actually super important that the right netdevice be used..

Anyhow. Bart should look at what iscsi does for namespaces and copy that.. No sense in inventing something unique for RDMA.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#25 lore raw
In reply to a message not in the archive

T24gRnJpLCAyMDE4LTAxLTA1IGF0IDEzOjM1IC0wNzAwLCBKYXNvbiBHdW50aG9ycGUgd3JvdGU6 DQo+IEFueWhvdy4gQmFydCBzaG91bGQgbG9vayBhdCB3aGF0IGlzY3NpIGRvZXMgZm9yIG5hbWVz cGFjZXMgYW5kIGNvcHkNCj4gdGhhdC4uIE5vIHNlbnNlIGluIGludmVudGluZyBzb21ldGhpbmcg dW5pcXVlIGZvciBSRE1BLg0KDQpVbmxlc3MgaWYgSSBtaXNzZWQgc29tZXRoaW5nLCBuZXR3b3Jr IG5hbWVzcGFjZSBzdXBwb3J0IHNlZW1zIHRvIGJlIG1pc3NpbmcNCmZyb20gdGhlIGlTQ1NJIGFu ZCBGQ29FIGluaXRpYXRvciBkcml2ZXJzOg0KDQokIGdpdCBncmVwIC1uSCAnc3RydWN0IG5ldFte WzphbG51bTpdX10nICovc2NzaQ0KJCBnaXQgZ3JlcCAtbkggJ2luaXRfbmV0JyAqL3Njc2kNCmRy aXZlcnMvc2NzaS9jeGdiaS9saWJjeGdiaS5jOjU5MzoJcnQgPSBpcF9yb3V0ZV9vdXRwdXRfcG9y dHMoJmluaXRfbmV0LCBmbDQsIE5VTEwsIGRhZGRyLCBzYWRkciwNCmRyaXZlcnMvc2NzaS9jeGdi aS9saWJjeGdiaS5jOjY0MjoJCW5kZXYgPSBpcF9kZXZfZmluZCgmaW5pdF9uZXQsIGRhZGRyLT5z aW5fYWRkci5zX2FkZHIpOw0KZHJpdmVycy9zY3NpL2N4Z2JpL2xpYmN4Z2JpLmM6NzA4OglyZXR1 cm4gKHN0cnVjdCBydDZfaW5mbyAqKWlwNl9yb3V0ZV9vdXRwdXQoJmluaXRfbmV0LCBOVUxMLCAm ZmwpOw0KZHJpdmVycy9zY3NpL2N4Z2JpL2xpYmN4Z2JpLmM6NzkwOgkJZXJyID0gaXB2Nl9kZXZf Z2V0X3NhZGRyKCZpbml0X25ldCwgaWRldiA/IGlkZXYtPmRldiA6IE5VTEwsDQpkcml2ZXJzL3Nj c2kvZmNvZS9mY29lLmM6MTgxNToJbmV0ZGV2ID0gZGV2X2dldF9ieV9pbmRleCgmaW5pdF9uZXQs IGVudHJ5LT5pZmluZGV4KTsNCmRyaXZlcnMvc2NzaS9mY29lL2Zjb2VfdHJhbnNwb3J0LmM6NzI3 OgkJcmV0dXJuIGRldl9nZXRfYnlfbmFtZSgmaW5pdF9uZXQsIGlmbmFtZSk7DQpkcml2ZXJzL3Nj c2kvc2NzaV9uZXRsaW5rLmM6MTMzOglzY3NpX25sX3NvY2sgPSBuZXRsaW5rX2tlcm5lbF9jcmVh dGUoJmluaXRfbmV0LCBORVRMSU5LX1NDU0lUUkFOU1BPUlQsDQpkcml2ZXJzL3Njc2kvc2NzaV90 cmFuc3BvcnRfaXNjc2kuYzo0NTMzOglubHMgPSBuZXRsaW5rX2tlcm5lbF9jcmVhdGUoJmluaXRf bmV0LCBORVRMSU5LX0lTQ1NJLCAmY2ZnKTsNCg0KQmFydC4=
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#26 lore raw
In reply to a message not in the archive
Quoted 11 lines · Jason Gunthorpe
Quoted 10 lines · Doug Ledford
Quoted 9 lines · Jason Gunthorpe
Quoted 7 lines · Doug Ledford
Quoted 4 lines

Do the userspace daemon's still manage the connection to SRP?

If yes, then the networking information should be relative to the namespace of the thing that wrote to the sysfs file..

Maybe, maybe not. It depends on the implementation. IIRC you get one daemon per port, not one daemon per mount.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I don't think it depends - if we expose this sysfs file to a container

Who says we have to do that? We could make the sysfs file only visible in the init namespace and let the init namespace daemon control what namespaces have what views.

What 'views'? It is a sysfs file controlled by the kernel - srp_daemon has no control ove rit.

Ok, allow me to clarify: restrict the sysfs file to create mappings to only the init_net namespace, and by views I meant allow the host srp_daemon to create a mapping with a specific namespace and that would then create a device file in that namespace, not a sysfs file.

Quoted 5 lines
Quoted 3 lines

views anyway. We could just make that mandatory by refusing to create devices from anything other than init_net namespace. Then even if someone does mount sysfs rw in a container, we're still good.

Usually we don't put that kind if policy in the kernel.

No, we normally don't. However....

Quoted 9 lines

Someone could run a priviledged container with full device access and expect this stuff to work right. In that case it is certainly correct for the srp_daemon and kernel to be in the namespace of the calling process.

Quoted 4 lines
Quoted 3 lines

So from a security perspective containers shouldn't even have access to this thing at all without more work to ensure that the created block device is also restriced inside the container.

Quoted 6 lines
Quoted 4 lines

This isn't sufficient. The block device created must be constrained within the container, but if we allow direct device access to the underlying LUN on the target, then that target LUN must be exclusively owned by the container.

Yes. That is done on the storage controller via ACLs of that LUN.

But we broke that already...

Quoted 4 lines

The
container's net namespace would be restricted in some way that the ACL can uniquely identify it - and the srp_daemon could run inside the container.

When we arguing over namespaces, especially as they related to IPoIB devices, we decided to allow the tuple to be p_key/qp/gid so that you can have to separate containers on the same p_key and gid with the differentiating factor being only the qp. If we then use that to target our SRP RDMACM connection, we've gone into an area where the target can't differentiate our container.

So, yes, I think the storage target should control the ACLs too, but I'm concerned that we've gone down a path where that can't currently be done
and changes will be required on the target for things to work.

Signature · 3 lines
Doug Ledford <[email protected]>
    GPG KeyID: B826A3330E572FDD
    Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD
#28 lore raw
In reply to a message not in the archive
Quoted 4 lines · Doug Ledford

Ok, allow me to clarify: restrict the sysfs file to create mappings to only the init_net namespace, and by views I meant allow the host srp_daemon to create a mapping with a specific namespace and that would then create a device file in that namespace, not a sysfs file.

I'm not familiar enough with the status of the 'device namespace' stuff, but..

AFAIK a today this works with the orchestation software just putting the device nodes it wants the container to have in /dev/ tmpfs and then the kernel prevents the container from creating new device nodes.

So, in that configuration plugging new block devices into the container is a userspace problem, not the kernel, and you'd never run something like srp_daemon inside a container..

Quoted 3 lines

When we arguing over namespaces, especially as they related to IPoIB devices, we decided to allow the tuple to be p_key/qp/gid so that you can have to separate containers on the same p_key and gid with the

Well, the PKey and GID is supposed to be the differentiator for ACL like purposes.

And in roce we can have a full MAC address assigned to the container (for iser and what not)

So it isn't broken, it is just limited. (ie by the gid table size)

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html