Skip to contentSkip to conversation

shrink struct ib_send_wr

PATCH In review Christoph Hellwig 9 participants 20 messages Aug 19, 2015 – Aug 25, 2015 10 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

This series shrinks the WR size by splitting out the different WR types.

Patch number two is too large for the mailinglist, so if you didn't get it grab it here:

	http://git.infradead.org/users/hch/rdma.git/commitdiff/30e522ee6c1d7adb614d7308f09fbfd71c6d3e07

or the full git tree at:

git://git.infradead.org/users/hch/rdma.git wr-cleanup

Changes since the version sent around a couple of times:

- new patch 1 which rejects invalid opcodes. Patch 2 was doing this implicitly except for UD QPs, but I think we should a) do this explicitly and b) ensure this goes into 4.2 and -stable as I can see quite a lot of harm from submitting such malformed operations
- patch 2 now covers all drivers including those in staging to side step any sort of discussions on the staging tree.
- patch 2 now explicitly replaces the weird overloading in the mlx5 driver with an explicit embedding of struct ib_send_wr, similar to what we do for all other MRs.
- new patch to drop another unused send_wr field.

--
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 1/3 IB/uverbs: reject invalid or unknown opcodes

In reply to a message not in the archive

We have many WR opcodes that are only supported in kernel space and/or require optional information to be copied into the WR structure. Reject all those not explicitly handled so that we can't pass invalid information to drivers.

---
 drivers/infiniband/core/uverbs_cmd.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/infiniband/core/uverbs_cmd.c +8 -1
index a15318a..f9f3921 100644
@@ -2372,6 +2372,12 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
 		next->send_flags = user_wr->send_flags;
 
 		if (is_ud) {
+			if (next->opcode != IB_WR_SEND &&
+			    next->opcode != IB_WR_SEND_WITH_IMM) {
+				ret = -EINVAL;
+				goto out_put;
+			}
+
 			next->wr.ud.ah = idr_read_ah(user_wr->wr.ud.ah,
 						     file->ucontext);
 			if (!next->wr.ud.ah) {
@@ -2413,7 +2419,8 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
 				next->wr.atomic.rkey = user_wr->wr.atomic.rkey;
 				break;
 			default:
-				break;
+				ret = -EINVAL;
+				goto out_put;
 			}
 		}
 
Signature · 6 lines
1.9.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
#25 lore raw

PATCH 3/3 IB: remove xrc_remote_srq_num from struct ib_send_wr

In reply to a message not in the archive

The field is only initialized in mlx, but never used.

If we want to add proper XRC support it should be done with a new struct ib_xrc_wr.

This shrinks the various WR structures by another 4 bytes.

---
 drivers/infiniband/hw/mlx5/qp.c | 1 -
 include/rdma/ib_verbs.h         | 1 -
 2 files changed, 2 deletions(-)
drivers/infiniband/hw/mlx5/qp.c +0 -1
index 04df156..83a290f 100644
@@ -2634,7 +2634,6 @@ int mlx5_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
 		switch (ibqp->qp_type) {
 		case IB_QPT_XRC_INI:
 			xrc = seg;
-			xrc->xrc_srqn = htonl(wr->xrc_remote_srq_num);
 			seg += sizeof(*xrc);
 			size += sizeof(*xrc) / 16;
 			/* fall through */
include/rdma/ib_verbs.h +0 -1
index 9b29c78..b855189 100644
@@ -1100,7 +1100,6 @@ struct ib_send_wr {
 		__be32		imm_data;
 		u32		invalidate_rkey;
 	} ex;
-	u32			xrc_remote_srq_num;	/* XRC TGT QPs only */
 };
 
 struct ib_rdma_wr {
Signature · 6 lines
1.9.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
Reviewed-by
#4 lore raw

Re: [PATCH 1/3] IB/uverbs: reject invalid or unknown opcodes

In reply to a message not in the archive
Quoted 9 lines · Christoph Hellwig

We have many WR opcodes that are only supported in kernel space and/or require optional information to be copied into the WR structure. Reject all those not explicitly handled so that we can't pass invalid information to drivers.

 drivers/infiniband/core/uverbs_cmd.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Oh yes, this is absolutely needed for -stable.

AFAIK, this path is rarely (never?) actually used. I think all the drivers we have can post directly from userspace.

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

#5 lore raw

Re: [PATCH 1/3] IB/uverbs: reject invalid or unknown opcodes

Quoted 4 lines · Jason Gunthorpe

AFAIK, this path is rarely (never?) actually used. I think all the drivers we have can post directly from userspace.

Oh, interesting. Is there any chance to deprecate it? Not having to care for the uvers command would really help with some of the upcoming changes I have in my mind.

Reviewed-by
#27 lore raw

Re: [PATCH 3/3] IB: remove xrc_remote_srq_num from struct ib_send_wr

In reply to a message not in the archive
Quoted 6 lines · Christoph Hellwig

The field is only initialized in mlx, but never used.

If we want to add proper XRC support it should be done with a new struct ib_xrc_wr.

This shrinks the various WR structures by another 4 bytes.

I've never really been entirely clear on how much of this stuff needs to be kernel side. Even the switch doesn't really make alot of sense..

drivers/infiniband/hw/mlx5/qp.c int mlx5_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr, · line 2637

Quoted 6 lines

+++ b/drivers/infiniband/hw/mlx5/qp.c

drivers/infiniband/hw/mlx5/qp.c +0 -1
@@ -2634,7 +2634,6 @@ int mlx5_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
 		switch (ibqp->qp_type) {
 		case IB_QPT_XRC_INI:
 			xrc = seg;
-			xrc->xrc_srqn = htonl(wr->xrc_remote_srq_num);

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

#7 lore raw

Re: [PATCH 1/3] IB/uverbs: reject invalid or unknown opcodes

In reply to a message not in the archive
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · Jason Gunthorpe

AFAIK, this path is rarely (never?) actually used. I think all the drivers we have can post directly from userspace.

Oh, interesting. Is there any chance to deprecate it? Not having to care for the uvers command would really help with some of the upcoming changes I have in my mind.

Hmm, we'd need a survey of the userspace side to see if it is rarely or never...

And we'd have to talk to the soft XXX guys to see if they plan to use it..

I always like to see cruft go away, especially if it is broken cruft..

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

#13 lore raw

RE: [PATCH 1/3] IB/uverbs: reject invalid or unknown opcodes

In reply to a message not in the archive
Quoted 2 lines

AFAIK, this path is rarely (never?) actually used. I think all the drivers we have can post directly from userspace.

I didn't think the ipath or qib drivers post from userspace. --
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

#9 lore raw

Re: [PATCH 1/3] IB/uverbs: reject invalid or unknown opcodes

In reply to a message not in the archive
Quoted 11 lines · Jason Gunthorpe
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · Jason Gunthorpe

AFAIK, this path is rarely (never?) actually used. I think all the drivers we have can post directly from userspace.

Oh, interesting. Is there any chance to deprecate it? Not having to care for the uvers command would really help with some of the upcoming changes I have in my mind.

Quoted 5 lines

Hmm, we'd need a survey of the userspace side to see if it is rarely or never...

And we'd have to talk to the soft XXX guys to see if they plan to use it..

Checked in librxe (user-space softroce). Looks like posts are going via this path...

Reviewed-by on v1 1/3
#15 lore raw

Re: [PATCH 1/3] IB/uverbs: reject invalid or unknown opcodes

In reply to Christoph Hellwig
Quoted 30 lines · Christoph Hellwig

We have many WR opcodes that are only supported in kernel space and/or require optional information to be copied into the WR structure. Reject all those not explicitly handled so that we can't pass invalid information to drivers.

---
  drivers/infiniband/core/uverbs_cmd.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
drivers/infiniband/core/uverbs_cmd.c +6 -0
index a15318a..f9f3921 100644
@@ -2372,6 +2372,12 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
  		next->send_flags = user_wr->send_flags;
 
  		if (is_ud) {
+			if (next->opcode != IB_WR_SEND &&
+			    next->opcode != IB_WR_SEND_WITH_IMM) {
+				ret = -EINVAL;
+				goto out_put;
+			}
+
  			next->wr.ud.ah = idr_read_ah(user_wr->wr.ud.ah,
  						     file->ucontext);
  			if (!next->wr.ud.ah) {

drivers/infiniband/core/uverbs_cmd.c ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file, · line 2426

Quoted 9 lines
drivers/infiniband/core/uverbs_cmd.c +2 -1
@@ -2413,7 +2419,8 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
  				next->wr.atomic.rkey = user_wr->wr.atomic.rkey;
  				break;
  			default:
-				break;
+				ret = -EINVAL;
+				goto out_put;
  			}
  		}
 

Haggai, can you also have a look?

Reviewed-by
#28 lore raw

Re: [PATCH 3/3] IB: remove xrc_remote_srq_num from struct ib_send_wr

In reply to a message not in the archive
Quoted 31 lines · Christoph Hellwig

The field is only initialized in mlx, but never used.

If we want to add proper XRC support it should be done with a new struct ib_xrc_wr.

This shrinks the various WR structures by another 4 bytes.

---
  drivers/infiniband/hw/mlx5/qp.c | 1 -
  include/rdma/ib_verbs.h         | 1 -
  2 files changed, 2 deletions(-)
drivers/infiniband/hw/mlx5/qp.c +0 -1
index 04df156..83a290f 100644
@@ -2634,7 +2634,6 @@ int mlx5_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  		switch (ibqp->qp_type) {
  		case IB_QPT_XRC_INI:
  			xrc = seg;
-			xrc->xrc_srqn = htonl(wr->xrc_remote_srq_num);
  			seg += sizeof(*xrc);
  			size += sizeof(*xrc) / 16;
  			/* fall through */
include/rdma/ib_verbs.h +0 -0
index 9b29c78..b855189 100644

include/rdma/ib_verbs.h struct ib_send_wr { · line 1105

Quoted 7 lines
include/rdma/ib_verbs.h +0 -1
@@ -1100,7 +1100,6 @@ struct ib_send_wr {
  		__be32		imm_data;
  		u32		invalidate_rkey;
  	} ex;
-	u32			xrc_remote_srq_num;	/* XRC TGT QPs only */
  };
 
  struct ib_rdma_wr {

Looks OK to me,

This will need Eli's ack though...
--
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
Quoted 3 lines

- patch 2 now explicitly replaces the weird overloading in the mlx5 driver with an explicit embedding of struct ib_send_wr, similar to what we do for all other MRs.

This is on the user-space memory registration path.

Haggai, can you grab it for a Tested-by tag?
--
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

Re: [PATCH 1/3] IB/uverbs: reject invalid or unknown opcodes

In reply to Hefty, Sean
Quoted 4 lines · Sean
Quoted 2 lines

AFAIK, this path is rarely (never?) actually used. I think all the drivers we have can post directly from userspace.

I didn't think the ipath or qib drivers post from userspace.

Makes sense with their software IB stack. Guess the idea to get rid of this path is dead, would have been too nice..

#11 lore raw

Re: [PATCH 1/3] IB/uverbs: reject invalid or unknown opcodes

In reply to a message not in the archive
Quoted 12 lines · Sagi Grimberg
Quoted 11 lines · Jason Gunthorpe
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · Jason Gunthorpe

AFAIK, this path is rarely (never?) actually used. I think all the drivers we have can post directly from userspace.

Oh, interesting. Is there any chance to deprecate it? Not having to care for the uvers command would really help with some of the upcoming changes I have in my mind.

Quoted 8 lines
Quoted 5 lines

Hmm, we'd need a survey of the userspace side to see if it is rarely or never...

And we'd have to talk to the soft XXX guys to see if they plan to use it..

Checked in librxe (user-space softroce). Looks like posts are going via this path...

Ditto for the soft iWARP stack, which is still out-of-linux.

#17 lore raw

Re: [PATCH 1/3] IB/uverbs: reject invalid or unknown opcodes

In reply to a message not in the archive
Quoted 43 lines · On Thursday, August 20, 2015 11:52 AM, linux-rdma-owner-u79uwXL29TY76Z2rM5mHXA@…
Quoted 30 lines · Christoph Hellwig

We have many WR opcodes that are only supported in kernel space and/or require optional information to be copied into the WR structure. Reject all those not explicitly handled so that we can't pass invalid information to drivers.

---
  drivers/infiniband/core/uverbs_cmd.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
drivers/infiniband/core/uverbs_cmd.c +6 -0
index a15318a..f9f3921 100644
@@ -2372,6 +2372,12 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
              next->send_flags = user_wr->send_flags;
 
              if (is_ud) {
+                     if (next->opcode != IB_WR_SEND &&
+                         next->opcode != IB_WR_SEND_WITH_IMM) {
+                             ret = -EINVAL;
+                             goto out_put;
+                     }
+
                      next->wr.ud.ah = idr_read_ah(user_wr->wr.ud.ah,
                                                   file->ucontext);
                      if (!next->wr.ud.ah) {

drivers/infiniband/core/uverbs_cmd.c ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file, · line 2426

Quoted 9 lines
drivers/infiniband/core/uverbs_cmd.c +2 -1
@@ -2413,7 +2419,8 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
                              next->wr.atomic.rkey = user_wr->wr.atomic.rkey;
                              break;
                      default:
-                             break;
+                             ret = -EINVAL;
+                             goto out_put;
                      }
              }
 
Quoted 1 line

Haggai, can you also have a look?

It looks like the default case in the non-UD branch is currently used to handle plain IB_WR_SEND operations, so the patch would cause these to return an error.

Haggai--
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

Re: [PATCH 1/3] IB/uverbs: reject invalid or unknown opcodes

Quoted 1 line · Haggai Eran

It looks like the default case in the non-UD branch is currently used to handle plain IB_WR_SEND operations, so the patch would cause these to return an error.

Indeed. It's handled fine in patch 2 which splits up the case, but will be incorrectly rejected with just this patch applied.

#19 lore raw

Re: [PATCH 1/3] IB/uverbs: reject invalid or unknown opcodes

Quoted 5 lines · Christoph Hellwig
Quoted 1 line · Haggai Eran

It looks like the default case in the non-UD branch is currently used to handle plain IB_WR_SEND operations, so the patch would cause these to return an error.

Indeed. It's handled fine in patch 2 which splits up the case, but will be incorrectly rejected with just this patch applied.

Okay. Maybe you can just add a case for IB_WR_SEND in this patch to avoid hurting bisectability.

Looking at the uverbs part in patch 2, I think the changes are okay. I noticed there's a (__be32 __force) cast of the immediate data from userspace (it was already in the existing code). I wonder, why not define the field in the uapi struct as __be32 in the first place?

Haggai

#21 lore raw

Re: [PATCH 1/3] IB/uverbs: reject invalid or unknown opcodes

In reply to a message not in the archive
Quoted 2 lines · Haggai Eran

Okay. Maybe you can just add a case for IB_WR_SEND in this patch to avoid hurting bisectability.

I've done this already, just waiting for more feedback before resending:

http://git.infradead.org/users/hch/rdma.git/commitdiff/20f34ca8ecac302984f3a92b9ad29f5f4b41780d

Quoted 4 lines

Looking at the uverbs part in patch 2, I think the changes are okay. I noticed there's a (__be32 __force) cast of the immediate data from userspace (it was already in the existing code). I wonder, why not define the field in the uapi struct as __be32 in the first place?

It looks odd to me as well, but it's not really something I want to change in this series. Note that sparse annoted types like __be32 aren't really common in userspace, but with a bit of effort they can be supported. We have them and regularly run sparse for xfsprogs for example.
--
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

#23 lore raw

Re: [PATCH 1/3] IB/uverbs: reject invalid or unknown opcodes

In reply to a message not in the archive
Quoted 7 lines · Christoph Hellwig
Quoted 2 lines · Haggai Eran

Okay. Maybe you can just add a case for IB_WR_SEND in this patch to avoid hurting bisectability.

I've done this already, just waiting for more feedback before resending:

http://git.infradead.org/users/hch/rdma.git/commitdiff/20f34ca8ecac302984f3a92b9ad29f5f4b41780d

Great.

Quoted 10 lines
Quoted 4 lines

Looking at the uverbs part in patch 2, I think the changes are okay. I noticed there's a (__be32 __force) cast of the immediate data from userspace (it was already in the existing code). I wonder, why not define the field in the uapi struct as __be32 in the first place?

It looks odd to me as well, but it's not really something I want to change in this series. Note that sparse annoted types like __be32 aren't really common in userspace, but with a bit of effort they can be supported. We have them and regularly run sparse for xfsprogs for example.

I have to try it with libibverbs sometime. It doesn't use uapi yet though IIRC - it has its own version of the header files.

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

#24 lore raw

Re: [PATCH 1/3] IB/uverbs: reject invalid or unknown opcodes

Quoted 8 lines · Haggai Eran
Quoted 5 lines

It looks odd to me as well, but it's not really something I want to change in this series. Note that sparse annoted types like __be32 aren't really common in userspace, but with a bit of effort they can be supported. We have them and regularly run sparse for xfsprogs for example.

I have to try it with libibverbs sometime. It doesn't use uapi yet though IIRC - it has its own version of the header files.

Yes, I noticed that. And the WR opcodes aren't even exported in the uapi header, and use a shared namespace with the in-kernel only ones.

It's all a giant mess unfortunately.