rdma_rxe: Stop passing AV from user space
Subsystems (2)
RFC PATCH 1/1 rdma_rxe: Stop passing AV from user space
This patch shows it is possible to replace the current method used by rdma_rxe to handle UD transport where user space creates and then passes an rxe_av *av to the kernel driver as part of each rxe_send_wqe.
Here user space passes the handle created by the call to ibv_create_ah in the send wqe. The kernel driver uses that handle to get a pointer to the 'real' rxe_av that was created in the kernel by the create ah verb.
To do this requires executing code in the driver that mimics what is done in rdma_core to convert handles to objects. This is not ideal but gets the job done. It would probably be better for rdma_core to provide a service that can do this for software drivers that have to do this.
The alternative (used by the MW code) is to create a driver private index and pass that back from the create verb to user space and then have user space use that in the send wqe.
I would like to avoid replicating work already being done by rdma core by using the handle that already exists. I don't know the relative performance of the lookup in rdma_core and the red black tree used by rxe currently.
There is a matching change to provider/rxe.
---
drivers/infiniband/core/rdma_core.c +2 -0
@@ -425,6 +425,7 @@ struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_api_object *obj,uverbs_uobject_put (uobj);return ERR_PTR (ret); } +EXPORT_SYMBOL (rdma_lookup_get_uobject);static struct ib_uobject * alloc_begin_idr_uobject(const struct uverbs_api_object *obj,
@@ -726,6 +727,7 @@ void rdma_lookup_put_uobject(struct ib_uobject *uobj,/* Pairs with the kref obtained by type->lookup_get */ uverbs_uobject_put (uobj); } +EXPORT_SYMBOL (rdma_lookup_put_uobject);void setup_ufile_idr_uobject (struct ib_uverbs_file *ufile) {
drivers/infiniband/sw/rxe/rxe_av.c +43 -4
62 lines not on this page · raw message
drivers/infiniband/sw/rxe/rxe_req.c +5 -1
@@ -380,12 +380,16 @@ static struct sk_buff *init_req_packet(struct rxe_qp *qp,/* init skb */ av =rxe_get_av (pkt); +if (!av) { +pr_warn ("unable to get av\n" ); +return NULL ; + } skb =rxe_init_packet (rxe, av, paylen, pkt);if (unlikely (!skb))return NULL ;/* init bth */ - solicited = (ibwr->send_flags &IB_SEND_SOLICITED ) && + solicited = (ibwr->send_flags &IB_SEND_SOLICITED ) && (pkt->mask &RXE_END_MASK ) && ((pkt->mask & (RXE_SEND_MASK )) || (pkt->mask & (RXE_WRITE_MASK | RXE_IMMDT_MASK)) ==
drivers/infiniband/sw/rxe/rxe_verbs.c +1 -5
@@ -506,6 +506,7 @@ static void init_send_wr(struct rxe_qp *qp, struct rxe_send_wr *wr,if (qp_type (qp) ==IB_QPT_UD ||qp_type (qp) ==IB_QPT_SMI ||qp_type (qp) ==IB_QPT_GSI ) { + wr->wr.ud.ah =ud_wr (ibwr)->ah; wr->wr.ud.remote_qpn =ud_wr (ibwr)->remote_qpn; wr->wr.ud.remote_qkey =ud_wr (ibwr)->remote_qkey;if (qp_type (qp) ==IB_QPT_GSI )
@@ -562,11 +563,6 @@ static int init_send_wqe(struct rxe_qp *qp, const struct ib_send_wr *ibwr,init_send_wr (qp, &wqe->wr, ibwr); -if (qp_type (qp) ==IB_QPT_UD || -qp_type (qp) ==IB_QPT_SMI || -qp_type (qp) ==IB_QPT_GSI ) -memcpy (&wqe->av, &to_rah (ud_wr (ibwr)->ah)->av,sizeof (wqe->av)); -if (unlikely (ibwr->send_flags &IB_SEND_INLINE )) { p = wqe->dma.inline_data;
include/uapi/rdma/rdma_user_rxe.h +4 -1
@@ -89,6 +89,10 @@ struct rxe_send_wr {__u32 reserved; } atomic;struct { +union { +__aligned_u64 ah_handle; +struct ib_ah *ah; + };__u32 remote_qpn;__u32 remote_qkey;__u16 pkey_index;
@@ -132,7 +136,6 @@ struct rxe_dma_info {struct rxe_send_wqe {struct rxe_send_wr wr; -struct rxe_av av;__u32 status;__u32 state;__aligned_u64 iova;
Signature · 1 line
2.25.1
kernel test robot
build bot[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Bob,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on linus/master]
[also build test ERROR on v5.9 next-20201016]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Bob-Pearson/rdma_rxe-Stop-passing-AV-from-user-space/20201017-011849 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 9ff9b0d392ea08090cd1780fb196f36dbb586529 config: x86_64-randconfig-a006-20201019 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/f75a164cec539c591ee97d64a896cdebe56c2660 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Bob-Pearson/rdma_rxe-Stop-passing-AV-from-user-space/20201017-011849 git checkout f75a164cec539c591ee97d64a896cdebe56c2660 # save the attached .config to linux build tree make W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "rdma_lookup_put_uobject" [drivers/infiniband/sw/rxe/rdma_rxe.ko] undefined! >> ERROR: modpost: "rdma_lookup_get_uobject" [drivers/infiniband/sw/rxe/rdma_rxe.ko] undefined!
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Jason Gunthorpe
maintainerQuoted 11 lines · Bob Pearson
drivers/infiniband/sw/rxe/rxe_av.c +10
-0+static struct ib_ah *get_ah_from_handle (struct rxe_qp *qp,u32 handle) +{ +struct ib_uverbs_file *ufile; +struct uverbs_api *uapi; +const struct uverbs_api_object *type; +struct ib_uobject *uobj; + + ufile = qp->ibqp.uobject->uevent.uobject.ufile; + uapi = ufile->device->uapi; + type =uapi_get_object (uapi,UVERBS_OBJECT_AH );
drivers/infiniband/sw/rxe/rxe_av.c void rxe_av_fill_ip_info(struct rxe_av *av, struct rdma_ah_attr *attr) · line 96
Quoted 10 lines
drivers/infiniband/sw/rxe/rxe_av.c +10
-0+if (IS_ERR (type)) +return NULL ; + uobj =rdma_lookup_get_uobject (type, ufile, (s64 )handle, +UVERBS_LOOKUP_READ ,NULL ); +if (IS_ERR (uobj)) { +pr_warn ("unable to lookup ah handle\n" ); +return NULL ; + } + +rdma_lookup_put_uobject (uobj,UVERBS_LOOKUP_READ );
It can't be put and then return the data pointer, it is a use after free:
drivers/infiniband/sw/rxe/rxe_av.c static int init_send_wqe(struct rxe_qp *qp, const struct ib_send_wr *ibwr, · line 568
Quoted 10 lines
drivers/infiniband/sw/rxe/rxe_av.c +1
-4+return uobj->object;@@ -562,11 +563,6 @@ static int init_send_wqe(struct rxe_qp *qp, const struct ib_send_wr *ibwr,init_send_wr (qp, &wqe->wr, ibwr); -if (qp_type (qp) ==IB_QPT_UD || -qp_type (qp) ==IB_QPT_SMI || -qp_type (qp) ==IB_QPT_GSI ) -memcpy (&wqe->av, &to_rah (ud_wr (ibwr)->ah)->av,sizeof (wqe->av));
It needs some kind of negotiated compat, can't just break userspace like this
Jason
Quoted 39 lines · Jason Gunthorpe
Quoted 11 lines · Bob Pearson
drivers/infiniband/sw/rxe/rxe_av.c +10
-0+static struct ib_ah *get_ah_from_handle (struct rxe_qp *qp,u32 handle) +{ +struct ib_uverbs_file *ufile; +struct uverbs_api *uapi; +const struct uverbs_api_object *type; +struct ib_uobject *uobj; + + ufile = qp->ibqp.uobject->uevent.uobject.ufile; + uapi = ufile->device->uapi; + type =uapi_get_object (uapi,UVERBS_OBJECT_AH );drivers/infiniband/sw/rxe/rxe_av.c void rxe_av_fill_ip_info(struct rxe_av *av, struct rdma_ah_attr *attr) · line 96
Quoted 10 lines
drivers/infiniband/sw/rxe/rxe_av.c +10
-0+if (IS_ERR (type)) +return NULL ; + uobj =rdma_lookup_get_uobject (type, ufile, (s64 )handle, +UVERBS_LOOKUP_READ ,NULL ); +if (IS_ERR (uobj)) { +pr_warn ("unable to lookup ah handle\n" ); +return NULL ; + } + +rdma_lookup_put_uobject (uobj,UVERBS_LOOKUP_READ );It can't be put and then return the data pointer, it is a use after free:
drivers/infiniband/sw/rxe/rxe_av.c static int init_send_wqe(struct rxe_qp *qp, const struct ib_send_wr *ibwr, · line 568
Quoted 10 lines
drivers/infiniband/sw/rxe/rxe_av.c +1
-4+return uobj->object;@@ -562,11 +563,6 @@ static int init_send_wqe(struct rxe_qp *qp, const struct ib_send_wr *ibwr,init_send_wr (qp, &wqe->wr, ibwr); -if (qp_type (qp) ==IB_QPT_UD || -qp_type (qp) ==IB_QPT_SMI || -qp_type (qp) ==IB_QPT_GSI ) -memcpy (&wqe->av, &to_rah (ud_wr (ibwr)->ah)->av,sizeof (wqe->av));It needs some kind of negotiated compat, can't just break userspace like this
Quoted 2 lines
Jason
1st point. I get it. uobj->object contains the address of one of the ib_xxx verbs objects. Normally the driver never looks at this level but presumably has a kref on that object so it makes sense to look it up. Perhaps better would be:
void *object; ... uobj = rdma_lookup_get_uobject(...); object = uobj->object; rdma_lookup_put_uobject(...); return (struct ib_ah *)object;
Here the caller has created the ib_ah but has not yet destroyed it so it must hold a kref on it.
2nd point. I also get. This suggestion imagines that there will come a day when we can change the user API. May be a rare day but must happen occasionally. The current design is just plain wrong and needs to get fixed eventually.
Thanks for looking at this.
Bob
Jason Gunthorpe
maintainerQuoted 59 lines · Bob Pearson
Quoted 39 lines · Jason Gunthorpe
Quoted 11 lines · Bob Pearson
drivers/infiniband/sw/rxe/rxe_av.c +10
-0+static struct ib_ah *get_ah_from_handle (struct rxe_qp *qp,u32 handle) +{ +struct ib_uverbs_file *ufile; +struct uverbs_api *uapi; +const struct uverbs_api_object *type; +struct ib_uobject *uobj; + + ufile = qp->ibqp.uobject->uevent.uobject.ufile; + uapi = ufile->device->uapi; + type =uapi_get_object (uapi,UVERBS_OBJECT_AH );drivers/infiniband/sw/rxe/rxe_av.c void rxe_av_fill_ip_info(struct rxe_av *av, struct rdma_ah_attr *attr) · line 96
Quoted 10 lines
drivers/infiniband/sw/rxe/rxe_av.c +10
-0+if (IS_ERR (type)) +return NULL ; + uobj =rdma_lookup_get_uobject (type, ufile, (s64 )handle, +UVERBS_LOOKUP_READ ,NULL ); +if (IS_ERR (uobj)) { +pr_warn ("unable to lookup ah handle\n" ); +return NULL ; + } + +rdma_lookup_put_uobject (uobj,UVERBS_LOOKUP_READ );It can't be put and then return the data pointer, it is a use after free:
drivers/infiniband/sw/rxe/rxe_av.c static int init_send_wqe(struct rxe_qp *qp, const struct ib_send_wr *ibwr, · line 568
Quoted 10 lines
drivers/infiniband/sw/rxe/rxe_av.c +1
-4+return uobj->object;@@ -562,11 +563,6 @@ static int init_send_wqe(struct rxe_qp *qp, const struct ib_send_wr *ibwr,init_send_wr (qp, &wqe->wr, ibwr); -if (qp_type (qp) ==IB_QPT_UD || -qp_type (qp) ==IB_QPT_SMI || -qp_type (qp) ==IB_QPT_GSI ) -memcpy (&wqe->av, &to_rah (ud_wr (ibwr)->ah)->av,sizeof (wqe->av));It needs some kind of negotiated compat, can't just break userspace like this
Quoted 2 lines
Jason
1st point. I get it.
uobj->objectcontains the address of one of theib_xxxverbs objects. Normally the driver never looks at this level but presumably has a kref on that object so it makes sense to look it up. Perhaps better would be:void *object; ... uobj = rdma_lookup_get_uobject(...); object = uobj->object; rdma_lookup_put_uobject(...); return (struct ib_ah *)object;
Quoted 1 line
Here the caller has created the
ib_ahbut has not yet destroyed it so it must hold a kref on it.
Drivers are not supposed to keep using object after it has been destroyed, so some kind of interlock is needed to prevent/defer destruction here.
The uobject layer does not provide something usable to drivers
Quoted 4 lines
2nd point. I also get. This suggestion imagines that there will come a day when we can change the user API. May be a rare day but must happen occasionally. The current design is just plain wrong and needs to get fixed eventually.
You can have some cap negotiation to switch the mode AH mode in the WQEs - 'Use WQE format 2' for instance. Most of the HW drivers have multiple WQE formats the userspace selects.
Jason