linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH rdma-next] RDMA/ucma: Return stable IB device index as identifier
@ 2020-04-30 15:29 Leon Romanovsky
  2020-05-04 11:01 ` Gal Pressman
  0 siblings, 1 reply; 4+ messages in thread
From: Leon Romanovsky @ 2020-04-30 15:29 UTC (permalink / raw)
  To: Doug Ledford, Jason Gunthorpe; +Cc: Leon Romanovsky, linux-rdma

From: Leon Romanovsky <leonro@mellanox.com>

The librdmacm uses node_guid as identifier to correlate between
IB devices and CMA devices. However FW resets cause to such
"connection" to be lost and require from the user to restart
its application.

Extend UCMA to return IB device index, which is stable identifier.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 drivers/infiniband/core/ucma.c   | 16 +++++++++-------
 include/uapi/rdma/rdma_user_cm.h |  2 ++
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index 99482dc5934b..d5723465478e 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -848,7 +848,7 @@ static ssize_t ucma_query_route(struct ucma_file *file,
 	struct sockaddr *addr;
 	int ret = 0;
 
-	if (out_len < sizeof(resp))
+	if (out_len < offsetof(struct rdma_ucm_query_route_resp, ibdev_index))
 		return -ENOSPC;
 
 	if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
@@ -872,6 +872,7 @@ static ssize_t ucma_query_route(struct ucma_file *file,
 		goto out;
 
 	resp.node_guid = (__force __u64) ctx->cm_id->device->node_guid;
+	resp.ibdev_index = ctx->cm_id->device->index;
 	resp.port_num = ctx->cm_id->port_num;
 
 	if (rdma_cap_ib_sa(ctx->cm_id->device, ctx->cm_id->port_num))
@@ -883,8 +884,8 @@ static ssize_t ucma_query_route(struct ucma_file *file,
 
 out:
 	mutex_unlock(&ctx->mutex);
-	if (copy_to_user(u64_to_user_ptr(cmd.response),
-			 &resp, sizeof(resp)))
+	if (copy_to_user(u64_to_user_ptr(cmd.response), &resp,
+			 min_t(size_t, out_len, sizeof(resp))))
 		ret = -EFAULT;
 
 	ucma_put_ctx(ctx);
@@ -898,6 +899,7 @@ static void ucma_query_device_addr(struct rdma_cm_id *cm_id,
 		return;
 
 	resp->node_guid = (__force __u64) cm_id->device->node_guid;
+	resp->ibdev_index = cm_id->device->index;
 	resp->port_num = cm_id->port_num;
 	resp->pkey = (__force __u16) cpu_to_be16(
 		     ib_addr_get_pkey(&cm_id->route.addr.dev_addr));
@@ -910,7 +912,7 @@ static ssize_t ucma_query_addr(struct ucma_context *ctx,
 	struct sockaddr *addr;
 	int ret = 0;
 
-	if (out_len < sizeof(resp))
+	if (out_len < offsetof(struct rdma_ucm_query_addr_resp, ibdev_index))
 		return -ENOSPC;
 
 	memset(&resp, 0, sizeof resp);
@@ -925,7 +927,7 @@ static ssize_t ucma_query_addr(struct ucma_context *ctx,
 
 	ucma_query_device_addr(ctx->cm_id, &resp);
 
-	if (copy_to_user(response, &resp, sizeof(resp)))
+	if (copy_to_user(response, &resp, min_t(size_t, out_len, sizeof(resp))))
 		ret = -EFAULT;
 
 	return ret;
@@ -977,7 +979,7 @@ static ssize_t ucma_query_gid(struct ucma_context *ctx,
 	struct sockaddr_ib *addr;
 	int ret = 0;
 
-	if (out_len < sizeof(resp))
+	if (out_len < offsetof(struct rdma_ucm_query_addr_resp, ibdev_index))
 		return -ENOSPC;
 
 	memset(&resp, 0, sizeof resp);
@@ -1010,7 +1012,7 @@ static ssize_t ucma_query_gid(struct ucma_context *ctx,
 						    &ctx->cm_id->route.addr.dst_addr);
 	}
 
-	if (copy_to_user(response, &resp, sizeof(resp)))
+	if (copy_to_user(response, &resp, min_t(size_t, out_len, sizeof(resp))))
 		ret = -EFAULT;
 
 	return ret;
diff --git a/include/uapi/rdma/rdma_user_cm.h b/include/uapi/rdma/rdma_user_cm.h
index e545f2de1e13..14d48b462d91 100644
--- a/include/uapi/rdma/rdma_user_cm.h
+++ b/include/uapi/rdma/rdma_user_cm.h
@@ -168,6 +168,7 @@ struct rdma_ucm_query_route_resp {
 	__u32 num_paths;
 	__u8 port_num;
 	__u8 reserved[3];
+	__u32 ibdev_index;
 };
 
 struct rdma_ucm_query_addr_resp {
@@ -179,6 +180,7 @@ struct rdma_ucm_query_addr_resp {
 	__u16 dst_size;
 	struct __kernel_sockaddr_storage src_addr;
 	struct __kernel_sockaddr_storage dst_addr;
+	__u32 ibdev_index;
 };
 
 struct rdma_ucm_query_path_resp {
-- 
2.26.2


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

* Re: [PATCH rdma-next] RDMA/ucma: Return stable IB device index as identifier
  2020-04-30 15:29 [PATCH rdma-next] RDMA/ucma: Return stable IB device index as identifier Leon Romanovsky
@ 2020-05-04 11:01 ` Gal Pressman
  2020-05-04 11:09   ` Leon Romanovsky
  0 siblings, 1 reply; 4+ messages in thread
From: Gal Pressman @ 2020-05-04 11:01 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Doug Ledford, Jason Gunthorpe, Leon Romanovsky, linux-rdma

On 30/04/2020 18:29, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@mellanox.com>
> 
> The librdmacm uses node_guid as identifier to correlate between
> IB devices and CMA devices. However FW resets cause to such
> "connection" to be lost and require from the user to restart
> its application.
> 
> Extend UCMA to return IB device index, which is stable identifier.
> 
> Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
> ---
> diff --git a/include/uapi/rdma/rdma_user_cm.h b/include/uapi/rdma/rdma_user_cm.h
> index e545f2de1e13..14d48b462d91 100644
> --- a/include/uapi/rdma/rdma_user_cm.h
> +++ b/include/uapi/rdma/rdma_user_cm.h
> @@ -168,6 +168,7 @@ struct rdma_ucm_query_route_resp {
>  	__u32 num_paths;
>  	__u8 port_num;
>  	__u8 reserved[3];
> +	__u32 ibdev_index;
>  };
>  
>  struct rdma_ucm_query_addr_resp {
> @@ -179,6 +180,7 @@ struct rdma_ucm_query_addr_resp {
>  	__u16 dst_size;
>  	struct __kernel_sockaddr_storage src_addr;
>  	struct __kernel_sockaddr_storage dst_addr;
> +	__u32 ibdev_index;
>  };

Should both these structs size be aligned to 8 bytes?

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

* Re: [PATCH rdma-next] RDMA/ucma: Return stable IB device index as identifier
  2020-05-04 11:01 ` Gal Pressman
@ 2020-05-04 11:09   ` Leon Romanovsky
  2020-05-04 11:13     ` Leon Romanovsky
  0 siblings, 1 reply; 4+ messages in thread
From: Leon Romanovsky @ 2020-05-04 11:09 UTC (permalink / raw)
  To: Gal Pressman; +Cc: Doug Ledford, Jason Gunthorpe, linux-rdma

On Mon, May 04, 2020 at 02:01:23PM +0300, Gal Pressman wrote:
> On 30/04/2020 18:29, Leon Romanovsky wrote:
> > From: Leon Romanovsky <leonro@mellanox.com>
> >
> > The librdmacm uses node_guid as identifier to correlate between
> > IB devices and CMA devices. However FW resets cause to such
> > "connection" to be lost and require from the user to restart
> > its application.
> >
> > Extend UCMA to return IB device index, which is stable identifier.
> >
> > Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
> > ---
> > diff --git a/include/uapi/rdma/rdma_user_cm.h b/include/uapi/rdma/rdma_user_cm.h
> > index e545f2de1e13..14d48b462d91 100644
> > --- a/include/uapi/rdma/rdma_user_cm.h
> > +++ b/include/uapi/rdma/rdma_user_cm.h
> > @@ -168,6 +168,7 @@ struct rdma_ucm_query_route_resp {
> >  	__u32 num_paths;
> >  	__u8 port_num;
> >  	__u8 reserved[3];
> > +	__u32 ibdev_index;
> >  };
> >
> >  struct rdma_ucm_query_addr_resp {
> > @@ -179,6 +180,7 @@ struct rdma_ucm_query_addr_resp {
> >  	__u16 dst_size;
> >  	struct __kernel_sockaddr_storage src_addr;
> >  	struct __kernel_sockaddr_storage dst_addr;
> > +	__u32 ibdev_index;
> >  };
>
> Should both these structs size be aligned to 8 bytes?

Are you asking about 8 bytes or 64 bytes?
Because u32 is aligned to 8 bytes.

Thanks

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

* Re: [PATCH rdma-next] RDMA/ucma: Return stable IB device index as identifier
  2020-05-04 11:09   ` Leon Romanovsky
@ 2020-05-04 11:13     ` Leon Romanovsky
  0 siblings, 0 replies; 4+ messages in thread
From: Leon Romanovsky @ 2020-05-04 11:13 UTC (permalink / raw)
  To: Gal Pressman; +Cc: Doug Ledford, Jason Gunthorpe, linux-rdma

On Mon, May 04, 2020 at 02:09:29PM +0300, Leon Romanovsky wrote:
> On Mon, May 04, 2020 at 02:01:23PM +0300, Gal Pressman wrote:
> > On 30/04/2020 18:29, Leon Romanovsky wrote:
> > > From: Leon Romanovsky <leonro@mellanox.com>
> > >
> > > The librdmacm uses node_guid as identifier to correlate between
> > > IB devices and CMA devices. However FW resets cause to such
> > > "connection" to be lost and require from the user to restart
> > > its application.
> > >
> > > Extend UCMA to return IB device index, which is stable identifier.
> > >
> > > Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
> > > ---
> > > diff --git a/include/uapi/rdma/rdma_user_cm.h b/include/uapi/rdma/rdma_user_cm.h
> > > index e545f2de1e13..14d48b462d91 100644
> > > --- a/include/uapi/rdma/rdma_user_cm.h
> > > +++ b/include/uapi/rdma/rdma_user_cm.h
> > > @@ -168,6 +168,7 @@ struct rdma_ucm_query_route_resp {
> > >  	__u32 num_paths;
> > >  	__u8 port_num;
> > >  	__u8 reserved[3];
> > > +	__u32 ibdev_index;
> > >  };
> > >
> > >  struct rdma_ucm_query_addr_resp {
> > > @@ -179,6 +180,7 @@ struct rdma_ucm_query_addr_resp {
> > >  	__u16 dst_size;
> > >  	struct __kernel_sockaddr_storage src_addr;
> > >  	struct __kernel_sockaddr_storage dst_addr;
> > > +	__u32 ibdev_index;
> > >  };
> >
> > Should both these structs size be aligned to 8 bytes?
>
> Are you asking about 8 bytes or 64 bytes?
> Because u32 is aligned to 8 bytes.

Sorry, of course, you are right.

>
> Thanks

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

end of thread, other threads:[~2020-05-04 11:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-30 15:29 [PATCH rdma-next] RDMA/ucma: Return stable IB device index as identifier Leon Romanovsky
2020-05-04 11:01 ` Gal Pressman
2020-05-04 11:09   ` Leon Romanovsky
2020-05-04 11:13     ` Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).